1 # SPDX-FileCopyrightText: 2024 Vladimir Shtarev, Jetbrains Research
 
   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, number):
 
  32     def __eq__(self, other):
 
  33         return self.id == other
 
  35     def init(self, mode=IN, pull=None):
 
  36         """Initialize the Pin"""
 
  41                 GPIO.setup(self.id, GPIO.IN)
 
  42             elif mode == self.OUT:
 
  44                 GPIO.setup(self.id, GPIO.OUT)
 
  46                 raise RuntimeError("Invalid mode for pin: %s" % self.id)
 
  48             if self._mode != self.IN:
 
  49                 raise RuntimeError("Cannot set pull resistor on output")
 
  50             if pull == self.PULL_UP:
 
  51                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
  52             elif pull == self.PULL_DOWN:
 
  53                 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
 
  55                 raise RuntimeError("Invalid pull for pin: %s" % self.id)
 
  57     def value(self, val=None):
 
  58         """Set or return the Pin Value"""
 
  62                 GPIO.output(self.id, val)
 
  63             elif val == self.HIGH:
 
  65                 GPIO.output(self.id, val)
 
  67                 raise RuntimeError("Invalid value for pin")
 
  69         return GPIO.input(self.id)
 
 104 # PWM, does not support pwmio
 
 108 # ordered as i2cId, SCL, SDA
 
 109 i2cPorts = ((0, I2C_SCL, I2C_SDA),)
 
 111 # ordered as spiId, sckId, mosiId, misoId
 
 112 spiPorts = ((0, SPI_SCLK, SPI_MOSI, SPI_MISO),)
 
 114 # ordered as uartId, txId, rxId
 
 115 uartPorts = ((0, UART_TX, UART_RX),)