1 import RPi.GPIO as GPIO
 
   4 # Pins dont exist in CPython so...lets make our own!
 
  18     def __init__(self, bcm_number):
 
  24     def __eq__(self, other):
 
  25         return self.id == other
 
  27     def init(self, mode=IN, pull=None):
 
  31                 GPIO.setup(self.id, GPIO.IN)
 
  32             elif mode == self.OUT:
 
  34                 GPIO.setup(self.id, GPIO.OUT)
 
  36                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  38             if self._mode != self.IN:
 
  39                 raise RuntimeError("Cannot set pull resistor on output")
 
  40             if pull == self.PULL_UP:
 
  41                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
  42             elif pull == self.PULL_DOWN:
 
  43                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
 
  45                 raise RuntimeError("Invalid pull for pin: %s" % self.id)       
 
  47     def value(self, val=None):
 
  51                 GPIO.output(self.id, val)
 
  52             elif val == self.HIGH:
 
  54                 GPIO.output(self.id, val)
 
  56                 raise RuntimeError("Invalid value for pin")
 
  58             return GPIO.input(self.id)
 
  88 # ordered as spiId, sckId, mosiId, misoId
 
  89 spiPorts = ((0, SCLK, MOSI, MISO), (1, SCLK_2, MOSI_2, MISO_2))
 
  91 # ordered as uartId, txId, rxId