1 # SPDX-FileCopyrightText: 2024 Vladimir Shtarev
3 # SPDX-License-Identifier: MIT
4 """A Pin class for use with StarFive JH7110."""
6 import VisionFive.gpio as GPIO
8 GPIO.setmode(GPIO.BOARD)
12 """Pins don't 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)
112 # ordered as i2cId, SCL, SDA
113 i2cPorts = ((0, SCL, SDA),)
115 # ordered as spiId, sckId, mosiId, misoId
116 spiPorts = ((0, SPI_SCLK, SPI_MOSI, SPI_MISO),)
118 # ordered as uartId, txId, rxId
119 uartPorts = ((0, UART_TX, UART_RX),)