1 """Broadcom BCM283x pin names"""
 
   2 import RPi.GPIO as GPIO
 
   4 GPIO.setmode(GPIO.BCM)  # Use BCM pins D4 = GPIO #4
 
   5 GPIO.setwarnings(False)  # shh!
 
   9     """Pins dont exist in CPython so...lets make our own!"""
 
  23     def __init__(self, bcm_number):
 
  29     def __eq__(self, other):
 
  30         return self.id == other
 
  32     def init(self, mode=IN, pull=None):
 
  33         """Initialize the Pin"""
 
  37                 GPIO.setup(self.id, GPIO.IN)
 
  38             elif mode == self.OUT:
 
  40                 GPIO.setup(self.id, GPIO.OUT)
 
  42                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  44             if self._mode != self.IN:
 
  45                 raise RuntimeError("Cannot set pull resistor on output")
 
  46             if pull == self.PULL_UP:
 
  47                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
  48             elif pull == self.PULL_DOWN:
 
  49                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
 
  51                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
 
  53     def value(self, val=None):
 
  54         """Set or return the Pin Value"""
 
  58                 GPIO.output(self.id, val)
 
  59             elif val == self.HIGH:
 
  61                 GPIO.output(self.id, val)
 
  63                 raise RuntimeError("Invalid value for pin")
 
  65         return GPIO.input(self.id)
 
  90 SCLK = Pin(11)  # Raspberry Pi naming
 
  91 SCK = Pin(11)  # CircuitPython naming
 
 140 # ordered as spiId, sckId, mosiId, misoId
 
 142     (0, SCLK, MOSI, MISO),
 
 143     (1, SCLK_1, MOSI_1, MISO_1),
 
 144     (2, SCLK_2, MOSI_2, MISO_2),
 
 147 # ordered as uartId, txId, rxId
 
 148 uartPorts = ((1, TXD, RXD),)
 
 153     (0, D1, D0),  # both pi 1 and pi 2 i2c ports!