1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
 
   3 # SPDX-License-Identifier: MIT
 
   4 """Broadcom BCM283x pin names"""
 
   7 GPIO.setmode(GPIO.BCM)  # Use BCM pins D4 = GPIO #4
 
   8 GPIO.setwarnings(False)  # shh!
 
  12     """Pins dont exist in CPython so...lets make our own!"""
 
  26     def __init__(self, bcm_number):
 
  32     def __eq__(self, other):
 
  33         return self.id == other
 
  35     def init(self, mode=IN, pull=None):
 
  36         """Initialize the Pin"""
 
  40                 GPIO.setup(self.id, GPIO.IN)
 
  41             elif mode == self.OUT:
 
  43                 GPIO.setup(self.id, GPIO.OUT)
 
  45                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  47             if self._mode != self.IN:
 
  48                 raise RuntimeError("Cannot set pull resistor on output")
 
  49             if pull == self.PULL_UP:
 
  50                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
  51             elif pull == self.PULL_DOWN:
 
  52                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
 
  54                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
 
  56     def value(self, val=None):
 
  57         """Set or return the Pin Value"""
 
  61                 GPIO.output(self.id, val)
 
  62             elif val == self.HIGH:
 
  64                 GPIO.output(self.id, val)
 
  66                 raise RuntimeError("Invalid value for pin")
 
  68         return GPIO.input(self.id)
 
  93 SCLK = Pin(11)  # Raspberry Pi naming
 
  94 SCK = Pin(11)  # CircuitPython naming
 
 143 # ordered as spiId, sckId, mosiId, misoId
 
 145     (0, SCLK, MOSI, MISO),
 
 146     (1, SCLK_1, MOSI_1, MISO_1),
 
 147     (2, SCLK_2, MOSI_2, MISO_2),
 
 150 # ordered as uartId, txId, rxId
 
 151 uartPorts = ((1, TXD, RXD),)
 
 153 # These are the known hardware I2C ports / pins.
 
 154 # For software I2C ports created with the i2c-gpio overlay, see:
 
 155 #     https://github.com/adafruit/Adafruit_Python_Extended_Bus
 
 158     (0, D1, D0),  # both pi 1 and pi 2 i2c ports!