3 import Jetson.GPIO as GPIO
 
   4 GPIO.setmode(GPIO.TEGRA_SOC)
 
   5 GPIO.setwarnings(False)   # shh!
 
   7 # Pins dont exist in CPython so...lets make our own!
 
  21     def __init__(self, bcm_number):
 
  27     def __eq__(self, other):
 
  28         return self.id == other
 
  30     def init(self, mode=IN, pull=None):
 
  34                 GPIO.setup(self.id, GPIO.IN)
 
  35             elif mode == self.OUT:
 
  37                 GPIO.setup(self.id, GPIO.OUT)
 
  39                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  41             if self._mode != self.IN:
 
  42                 raise RuntimeError("Cannot set pull resistor on output")
 
  43             if pull == self.PULL_UP:
 
  44                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
  45             elif pull == self.PULL_DOWN:
 
  46                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
 
  48                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
 
  50     def value(self, val=None):
 
  54                 GPIO.output(self.id, val)
 
  55             elif val == self.HIGH:
 
  57                 GPIO.output(self.id, val)
 
  59                 raise RuntimeError("Invalid value for pin")
 
  61             return GPIO.input(self.id)
 
  65         print("Exiting... \nCleaning up pins")
 
  68 # Cannot be used as GPIO
 
  69 SDA = Pin('GEN1_I2C_SDA')
 
  70 SCL = Pin('GEN1_I2C_SCL')
 
  71 SDA_1 = Pin('GEN2_I2C_SDA')
 
  72 SCL_1 = Pin('GEN2_I2C_SCL')
 
  74 # These pins are native to TX1
 
  75 BB03 = Pin('GPIO_X1_AUD')
 
  76 X02 = Pin('MOTION_INT')
 
  77 H07 = Pin('AP_WAKE_NFC')
 
  78 E04 = Pin('DMIC3_CLK')
 
  79 U03 = Pin('UART1_CTS')
 
  80 U02 = Pin('UART1_RTS')
 
  81 B03 = Pin('DAP1_SCLK')
 
  84 B02 = Pin('DAP1_DOUT')
 
  85 P17 = Pin('GPIO_EXP_P17')
 
  86 E05 = Pin('DMIC3_DAT')
 
  87 X00 = Pin('MODEM_WAKE_AP')
 
  88 P16 = Pin('GPIO_EXP_P16')
 
  89 X03 = Pin('ALS_PROX_INT')
 
  91 # These pins are native to NANO
 
  92 S05 = Pin('CAM_AF_EN')
 
  94 V00 = Pin('LCD_BL_PW')
 
  95 G03 = Pin('UART2_CTS')
 
  96 G02 = Pin('UART2_RTS')
 
  97 J07 = Pin('DAP4_SCLK')
 
 100 J06 = Pin('DAP4_DOUT')
 
 102 DD00 = Pin('SPI2_CS1')
 
 103 B07 = Pin('SPI2_CS0')
 
 104 B05 = Pin('SPI2_MISO')
 
 105 B04 = Pin('SPI2_MOSI')
 
 106 B06 = Pin('SPI2_SCK')
 
 108 # These pins are shared across T210
 
 109 BB00 = Pin('AUD_MCLK')
 
 110 C04 = Pin('SPI1_CS1')
 
 111 C03 = Pin('SPI1_CS0')
 
 112 C01 = Pin('SPI1_MISO')
 
 113 C00 = Pin('SPI1_MOSI')
 
 114 C02 = Pin('SPI1_SCK')
 
 115 E06 = Pin('GPIO_PE6')
 
 118     (0, SCL, SDA), (1, SCL_1, SDA_1),
 
 121 # ordered as spiId, sckId, mosiId, misoId
 
 122 spiPorts = ((0, C02, C00, C01), (1, B06, B04, B05))