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('GPIO_SEN9')
 
  70 SCL = Pin('GPIO_SEN8')
 
  71 SDA_1 = Pin('GEN1_I2C_SDA')
 
  72 SCL_1 = Pin('GEN1_I2C_SCL')
 
  75 J06 = Pin('GPIO_AUD1')
 
  76 AA02 = Pin('CAN_GPIO2')
 
  77 N06 = Pin('GPIO_CAM7')
 
  78 N04 = Pin('GPIO_CAM5')
 
  79 N05 = Pin('GPIO_CAM6')
 
  80 N03 = Pin('GPIO_CAM4')
 
  81 AA01 = Pin('CAN_GPIO1')
 
  83 T03 = Pin('UART1_CTS')
 
  84 T02 = Pin('UART1_RTS')
 
  85 J00 = Pin('DAP1_SCLK')
 
  88 J01 = Pin('DAP1_DOUT')
 
  89 P17 = Pin('GPIO_EXP_P17')
 
  90 AA00 = Pin('CAN0_GPIO0')
 
  91 Y01 = Pin('GPIO_MDM2')
 
  92 P16 = Pin('GPIO_EXP_P16')
 
  94 J05 = Pin('GPIO_AUD0')
 
  97     (1, SCL, SDA), (0, SCL_1, SDA_1),
 
 100 # ordered as spiId, sckId, mosiId, misoId
 
 101 spiPorts = ((3, N03, N05, N04), )