1 import Adafruit_BBIO.GPIO as GPIO
 
   3 # Pins dont exist in CPython so...lets make our own!
 
  17     def __init__(self, pin_name):
 
  23     def __eq__(self, other):
 
  24         return self.id == other
 
  26     def init(self, mode=IN, pull=None):
 
  30                 GPIO.setup(self.id, GPIO.IN)
 
  31             elif mode == self.OUT:
 
  33                 GPIO.setup(self.id, GPIO.OUT)
 
  35                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  37             if self._mode != self.IN:
 
  38                 raise RuntimeError("Cannot set pull resistor on output")
 
  39             if pull == self.PULL_UP:
 
  40                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
  41             elif pull == self.PULL_DOWN:
 
  42                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
 
  44                 raise RuntimeError("Invalid pull for pin: %s" % self.id)       
 
  46     def value(self, val=None):
 
  50                 GPIO.output(self.id, val)
 
  51             elif val == self.HIGH:
 
  53                 GPIO.output(self.id, val)
 
  55                 raise RuntimeError("Invalid value for pin")
 
  57             return GPIO.input(self.id)
 
 135 # Refer to header default pin modes
 
 136 # http://beagleboard.org/static/images/cape-headers.png
 
 138 # P9_17 (SPI0_CSO => CE0) enables peripheral device
 
 139 # P9_18 (SPI0_D1 => MOSI) outputs data to peripheral device
 
 140 # P9_21 (SPIO_DO => MISO) receives data from peripheral device
 
 141 # P9_22 (SPI0_SCLK => SCLK) outputs clock signal
 
 143 # Use config-pin to set pin mode for SPI pins
 
 144 # https://github.com/beagleboard/bb.org-overlays/tree/master/tools/beaglebone-universal-io
 
 145 # config-pin p9.17 spi_cs
 
 146 # config-pin p9.18 spi
 
 147 # config-pin p9.21 spi
 
 148 # config-pin p9.22 spi_sclk
 
 154 #CircuitPython naming convention for SPI Clock
 
 159 # http://beagleboard.org/static/images/cape-headers-spi.png
 
 162 # MISO_1 P9.29 SPI1_D0
 
 163 # MOSI_1 P9.30 SPI1_D1
 
 164 # SCLK_1 P9.31 SPI_SCLK
 
 166 # SPI1 conflicts with HDMI Audio (McASP)
 
 169 # https://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
 
 171 # To Disable HDMI AUDIO, uncomment this line in /boot/uEnv.txt:
 
 172 # disable_uboot_overlay_audio=1
 
 174 # Set pin modes for SPI1 with:
 
 176 # config-pin p9.28 spi1_cs
 
 177 # config-pin p9.29 spi1
 
 178 # config-pin p9.30 spi1
 
 179 # config-pin p9.31 spi_sclk
 
 181 MOSI_1 = Pin('P9_29')
 
 182 MISO_1 = Pin('P9_30')
 
 183 SCLK_1 = Pin('P9_31')
 
 184 #CircuitPython naming convention for SPI Clock
 
 187 # ordered as spiId, sckId, mosiId, misoId
 
 188 spiPorts = ((0, SCLK, MOSI, MISO), (1, SCLK_1, MOSI_1, MISO_1))
 
 190 # ordered as uartId, txId, rxId