package SBC.Odroid;

import SBC.BasicSBCInfo;
import anywheresoftware.b4a.BA;


@BA.ShortName("Odroid_N2_Pin")

/**
 * Source : https://wiki.odroid.com/odroid-n2/hardware/expansion_connectors
 * @author rdkartono
 *
 */
public class N2_Pin extends BasicSBCInfo{
	
	public N2_Pin() {
		super();
	}
	
	public final int pin03 = 493;
	public final int pin05 = 494;
	public final int pin07 = 473;
	public final int pin11 = 479;
	public final int pin13 = 480;
	public final int pin15 = 483;
	public final int pin19 = 484;
	public final int pin21 = 485;
	public final int pin23 = 487;
	public final int pin27 = 474;
	public final int pin29 = 490;
	public final int pin31 = 491;
	public final int pin33 = 481;
	public final int pin35 = 482;
	public final int pin08 = 488;
	public final int pin10 = 489;
	public final int pin12 = 492;
	public final int pin16 = 476;
	public final int pin18 = 477;
	public final int pin22 = 478;
	public final int pin24 = 486;
	public final int pin26 = 464;
	public final int pin28 = 475;
	public final int pin32 = 472;
	public final int pin36 = 495;
	
	// Source : https://wiki.odroid.com/odroid-n2/software/gpio_register_map
	// for use in "/dev/gpiomem"
	// Example : https://wiki.odroid.com/odroid-n2/application_note/gpio/memory_mapped_gpio
	public final long GPIO_BASE_ADDRESS = 0xFF634400;
	// GPIO_X is 20 pin , numbered 0 to 19
	public final long GPIO_X_SET_DIRECTION_REGISTER = GPIO_BASE_ADDRESS + (0x16 * 4);	// [19 : 0] , '0' = Output, '1' = Input
	public final long GPIO_X_WRITE_REGISTER = GPIO_BASE_ADDRESS + (0x17 * 4);			// [19 : 0] , '0' = Low, '1' = High
	public final long GPIO_X_READ_REGISTER = GPIO_BASE_ADDRESS + (0x18 * 4);			// [19 : 0] , 
	public final long GPIO_X_ENABLE_PULL_REGISTER = GPIO_BASE_ADDRESS + (0x4A * 4);		// [19 : 0] , '0' = Disable Pull-Mode, '1' = Enable Pull-Mode
	public final long GPIO_X_MODE_PULL_REGISTER = GPIO_BASE_ADDRESS + (0x3C * 4);		// [19 : 0] , '0' = Pull-Down , '1' = Pull-Up
	
	// GPIO_A is 11 pin, numbered 0 to 5, and 11 to 15
	public final long GPIO_A_SET_DIRECTION_REGISTER = GPIO_BASE_ADDRESS + (0x20 * 4);	// [15 : 0] , '0' = Output, '1' = Input
	public final long GPIO_A_WRITE_REGISTER = GPIO_BASE_ADDRESS + (0x21 * 4);			// [15 : 0] , '0' = Low, '1' = High
	public final long GPIO_A_READ_REGISTER = GPIO_BASE_ADDRESS + (0x22 * 4);			// [19 : 0] ,
	public final long GPIO_A_ENABLE_PULL_REGISTER = GPIO_BASE_ADDRESS + (0x4D * 4);		// [19 : 0] , '0' = Disable Pull-Mode, '1' = Enable Pull-Mode
	public final long GPIO_A_MODE_PULL_REGISTER = GPIO_BASE_ADDRESS + (0x3F * 4);		// [19 : 0] , '0' = Pull-Down , '1' = Pull-Up
	
	
	// I2C
	// Source : https://wiki.odroid.com/odroid-n2/application_note/gpio/i2c
	//	Net Name	I2C Register	PCB Location	SDA(#GPIO)		SCL(#GPIO)		Default Speed	Device Node
	//	I2C-2		0xFFD1D000		J2 (2×20 pins)	GPIOX.17(#493)	GPIOX.18(#494)	400 KHz			/dev/i2c-2
	//	I2C-3		0xFFD1C000		J2 (2×20 pins)	GPIOA.14(#474)	GPIOA.15(#475)	100 KHz			/dev/i2c-3
	public final String i2c_2 = "/dev/i2c-2";
	public final String i2c_3 = "/dev/i2c-3";
	
	public void Initialize(BA bax, Object callerobject,  String event) {
		
		setup_events(bax, callerobject, event, this);
		
	}
	
	
	/**
	 * Belum tau caranya
	 * selalu return 0
	 */
	@Override
	public double Get_CPU_CoreVolt() {
		// TODO belum tau caranya
		return 0;
	}
}
