1 """Broadcom BCM283x pin names"""
2 import RPi.GPIO as GPIO
3 from adafruit_blinka.agnostic import detector
5 GPIO.setmode(GPIO.BCM) # Use BCM pins D4 = GPIO #4
6 GPIO.setwarnings(False) # shh!
10 """Pins dont exist in CPython so...lets make our own!"""
24 def __init__(self, bcm_number):
30 def __eq__(self, other):
31 return self.id == other
33 def init(self, mode=IN, pull=None):
34 """Initialize the Pin"""
38 GPIO.setup(self.id, GPIO.IN)
39 elif mode == self.OUT:
41 GPIO.setup(self.id, GPIO.OUT)
43 raise RuntimeError("Invalid mode for pin: %s" % self.id)
45 if self._mode != self.IN:
46 raise RuntimeError("Cannot set pull resistor on output")
47 if pull == self.PULL_UP:
48 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
49 elif pull == self.PULL_DOWN:
50 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
52 raise RuntimeError("Invalid pull for pin: %s" % self.id)
54 def value(self, val=None):
55 """Set or return the Pin Value"""
59 GPIO.output(self.id, val)
60 elif val == self.HIGH:
62 GPIO.output(self.id, val)
64 raise RuntimeError("Invalid value for pin")
66 return GPIO.input(self.id)
91 SCLK = Pin(11) # Raspberry Pi naming
92 SCK = Pin(11) # CircuitPython naming
141 # ordered as spiId, sckId, mosiId, misoId
143 (0, SCLK, MOSI, MISO),
144 (1, SCLK_1, MOSI_1, MISO_1),
145 (2, SCLK_2, MOSI_2, MISO_2),
148 # ordered as uartId, txId, rxId
149 uartPorts = ((1, TXD, RXD),)
151 # These are the known hardware I2C ports / pins.
152 # For software I2C ports created with the i2c-gpio overlay, see:
153 # https://github.com/adafruit/Adafruit_Python_Extended_Bus
156 (0, D1, D0), # both pi 1 and pi 2 i2c ports!