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
157 # ordered as spiId, sckId, mosiId, misoId
158 #spiPorts = ((0, SCLK, MOSI, MISO), (1, SCLK_1, MOSI_1, MISO_1))
159 spiPorts = ((0, SCLK, MOSI, MISO), (1, SCLK, MOSI, MISO))
161 # ordered as uartId, txId, rxId