From: Melissa LeBlanc-Williams Date: Wed, 29 Apr 2020 15:35:56 +0000 (-0700) Subject: Added Rock Pi S X-Git-Tag: 4.7.0^2~1 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/80a2f37a06c217e101373df892bf4a083c03012a Added Rock Pi S --- diff --git a/requirements.txt b/requirements.txt index 8aa587a..f126dd3 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -Adafruit-PlatformDetect>=2.6.0 -Adafruit-PureIO>=1.1.4 +Adafruit-PlatformDetect>=2.8.0 +Adafruit-PureIO>=1.1.5 Jetson.GPIO; platform_machine=='aarch64' RPi.GPIO; platform_machine=='armv7l' or platform_machine=='armv6l' rpi_ws281x>=4.0.0; platform_machine=='armv7l' or platform_machine=='armv6l' diff --git a/setup.py b/setup.py index de421f4..35c7c82 100755 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( "adafruit_blinka.microcontroller.bcm283x.pulseio": ["libgpiod_pulsein"] }, install_requires=[ - "Adafruit-PlatformDetect>=2.7.0", + "Adafruit-PlatformDetect>=2.8.0", "Adafruit-PureIO>=1.1.5", "sysv_ipc; platform_system != 'Windows' and platform_machine != 'mips'", "pyftdi>=0.40.0", diff --git a/src/adafruit_blinka/board/radxa/__init__.py b/src/adafruit_blinka/board/radxa/__init__.py new file mode 100644 index 0000000..b1b4b8c --- /dev/null +++ b/src/adafruit_blinka/board/radxa/__init__.py @@ -0,0 +1 @@ +"""Rock Pi Boards definition from Radxa""" diff --git a/src/adafruit_blinka/board/radxa/rockpis.py b/src/adafruit_blinka/board/radxa/rockpis.py new file mode 100644 index 0000000..e11574f --- /dev/null +++ b/src/adafruit_blinka/board/radxa/rockpis.py @@ -0,0 +1,49 @@ +"""Pin definitions for the Rock Pi S.""" + +from adafruit_blinka.microcontroller.rockchip.rk3308 import pin + +D2 = pin.GPIO0_B3 +D3 = pin.GPIO0_B4 +D4 = pin.GPIO2_A4 +D8 = pin.GPIO1_D1 +D9 = pin.GPIO1_C6 +D10 = pin.GPIO1_C7 +D11 = pin.GPIO1_D0 +D14 = pin.GPIO2_A1 +D15 = pin.GPIO2_A0 +D17 = pin.GPIO0_B7 +D18 = pin.GPIO2_A5 +D22 = pin.GPIO0_C1 +D23 = pin.GPIO2_B2 +D24 = pin.GPIO2_B1 +D25 = pin.GPIO2_A7 +D27 = pin.GPIO0_C0 + +SDA = pin.I2C1_SDA +SCL = pin.I2C1_SCL + +SCL2 = pin.I2C2_SCL +SDA2 = pin.I2C2_SDA + +SCL3 = pin.I2C3_SCL +SDA3 = pin.I2C3_SDA + +SCLK = pin.SPI2_SCLK +MOSI = pin.SPI2_MOSI +MISO = pin.SPI2_MISO +CS = pin.SPI2_CS +SCK = SCLK + +UART_TX = pin.UART0_TX +UART_RX = pin.UART0_RX + +UART1_TX = pin.UART1_TX +UART1_RX = pin.UART1_RX + +UART2_TX = pin.UART2_TX +UART2_RX = pin.UART2_RX + +PWM2 = pin.PWM2 +PWM3 = pin.PWM3 + +ADC_IN0 = pin.ADC_IN0 diff --git a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogin.py b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogin.py new file mode 100644 index 0000000..bf6988b --- /dev/null +++ b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogin.py @@ -0,0 +1,95 @@ +""" +`analogio` - Analog input control +================================================= +Read the SysFS ADC using IIO (Industrial Input/Output) and return the value + +See `CircuitPython:analogio` in CircuitPython for more details. +* Author(s): Melissa LeBlanc-Williams +""" + +import os +from adafruit_blinka import ContextManaged + +try: + from microcontroller.pin import analogIns +except ImportError: + raise RuntimeError("No Analog Inputs defined for this board") + + +class AnalogIn(ContextManaged): + """Analog Input Class""" + + # Sysfs paths + _sysfs_path = "/sys/bus/iio/devices/" + _device_path = "iio:device{}" + + # Channel paths + _channel_path = "in_voltage{}_raw" + _scale_path = "in_voltage_scale" + + def __init__(self, adc_id): + """Instantiate an AnalogIn object and verify the sysfs IIO + corresponding to the specified channel and pin. + + Args: + adc_id (int): Analog Input ID as defined in microcontroller.pin + + Returns: + AnalogIn: AnalogIn object. + + Raises: + TypeError: if `channel` or `pin` types are invalid. + ValueError: if AnalogIn channel does not exist. + + """ + + self.id = adc_id + self._device = None + self._channel = None + self._open(adc_id) + + def __enter__(self): + return self + + def _open(self, adc_id): + self._device = None + for adcpair in analogIns: + if adcpair[0] == adc_id: + self._device = adcpair[1] + self._channel = adcpair[2] + + if self._device is None: + raise RuntimeError("No AnalogIn device found for the given ID") + + device_path = os.path.join( + self._sysfs_path, self._device_path.format(self._device) + ) + + if not os.path.isdir(device_path): + raise ValueError( + "AnalogIn device does not exist, check that the required modules are loaded." + ) + + @property + def value(self): + """Read the ADC and return the value as an integer""" + path = os.path.join( + self._sysfs_path, + self._device_path.format(self._device), + self._channel_path.format(self._channel), + ) + + with open(path, "r") as analog_in: + return int(analog_in.read().strip()) + + # pylint: disable=no-self-use + @value.setter + def value(self, value): + # emulate what CircuitPython does + raise AttributeError("'AnalogIn' object has no attribute 'value'") + + # pylint: enable=no-self-use + + def deinit(self): + self._device = None + self._channel = None diff --git a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogout.py b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogout.py new file mode 100644 index 0000000..ec8b6c6 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogout.py @@ -0,0 +1,93 @@ +""" +`analogio` - Analog output control +================================================= +Write the SysFS DAC using IIO (Industrial Input/Output) + +See `CircuitPython:analogio` in CircuitPython for more details. +* Author(s): Melissa LeBlanc-Williams +""" + +import os +from adafruit_blinka import ContextManaged + +try: + from microcontroller.pin import analogOuts +except ImportError: + raise RuntimeError("No Analog Outputs defined for this board") + + +class AnalogOut(ContextManaged): + """Analog Output Class""" + + # Sysfs paths + _sysfs_path = "/sys/bus/iio/devices/" + _device_path = "iio:device{}" + + # Channel paths + _channel_path = "out_voltage{}_raw" + _scale_path = "out_voltage_scale" + + def __init__(self, dac_id): + """Instantiate an AnalogOut object and verify the sysfs IIO + corresponding to the specified channel and pin. + + Args: + dac_id (int): Analog Output ID as defined in microcontroller.pin + + Returns: + AnalogOut: AnalogOut object. + + Raises: + TypeError: if `channel` or `pin` types are invalid. + ValueError: if AnalogOut channel does not exist. + + """ + + self.id = dac_id + self._device = None + self._channel = None + self._open(dac_id) + + def __enter__(self): + return self + + def _open(self, dac_id): + self._device = None + for dacpair in analogOuts: + if dacpair[0] == dac_id: + self._device = dacpair[1] + self._channel = dacpair[2] + + if self._device is None: + raise RuntimeError("No AnalogOut device found for the given ID") + + device_path = os.path.join( + self._sysfs_path, self._device_path.format(self._device) + ) + + if not os.path.isdir(device_path): + raise ValueError( + "AnalogOut device does not exist, check that the required modules are loaded." + ) + + @property + def value(self): + """Return an error. This is output only.""" + # emulate what CircuitPython does + raise AttributeError("unreadable attribute") + + @value.setter + def value(self, value): + """Write to the DAC""" + path = os.path.join( + self._sysfs_path, + self._device_path.format(self._device), + self._channel_path.format(self._channel), + ) + + with open(path, "w") as analog_out: + return analog_out.write(value + "\n") + + def deinit(self): + self._device = None + self._channel = None diff --git a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py new file mode 100644 index 0000000..c5b56e6 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py @@ -0,0 +1,325 @@ +""" +Much code from https://github.com/vsergeev/python-periphery/blob/master/periphery/gpio.py +Copyright (c) 2015-2019 vsergeev / Ivan (Vanya) A. Sergeev +License: MIT +""" + +import os +import errno +import time + +# pylint: disable=unnecessary-pass +class GPIOError(IOError): + """Base class for GPIO errors.""" + + pass + + +# pylint: enable=unnecessary-pass + + +class Pin: + """SysFS GPIO Pin Class""" + + # Number of retries to check for GPIO export or direction write on open + GPIO_OPEN_RETRIES = 10 + # Delay between check for GPIO export or direction write on open (100ms) + GPIO_OPEN_DELAY = 0.1 + + IN = "in" + OUT = "out" + LOW = 0 + HIGH = 1 + PULL_NONE = 0 + PULL_UP = 1 + PULL_DOWN = 2 + + id = None + _value = LOW + _mode = IN + + # Sysfs paths + _sysfs_path = "/sys/class/gpio/" + _channel_path = "gpiochip{}" + + # Channel paths + _export_path = "export" + _unexport_path = "unexport" + _pin_path = "gpio{}" + + def __init__(self, pin_id): + """Instantiate a Pin object and open the sysfs GPIO with the specified + pin number. + + Args: + pin_id (int): GPIO pin number. + + Returns: + SysfsGPIO: GPIO object. + + Raises: + GPIOError: if an I/O or OS error occurs. + TypeError: if `line` or `direction` types are invalid. + ValueError: if `direction` value is invalid. + TimeoutError: if waiting for GPIO export times out. + + """ + + if not isinstance(pin_id, int): + raise TypeError("Invalid Pin ID, should be integer.") + + self.id = pin_id + self._fd = None + self._line = None + self._path = None + + def __del__(self): + self._close() + + def __enter__(self): + return self + + def __exit__(self, t, value, traceback): + self._close() + + def init(self, mode=IN, pull=None): + """Initialize the Pin""" + if mode is not None: + if mode == self.IN: + self._mode = self.IN + self._open(self.IN) + elif mode == self.OUT: + self._mode = self.OUT + self._open(self.OUT) + else: + raise RuntimeError("Invalid mode for pin: %s" % self.id) + + if pull is not None: + if pull == self.PULL_UP: + raise NotImplementedError( + "Internal pullups not supported in periphery, " + "use physical resistor instead!" + ) + if pull == self.PULL_DOWN: + raise NotImplementedError( + "Internal pulldowns not supported in periphery, " + "use physical resistor instead!" + ) + raise RuntimeError("Invalid pull for pin: %s" % self.id) + + def value(self, val=None): + """Set or return the Pin Value""" + if val is not None: + if val == self.LOW: + self._value = val + self._write(False) + return None + if val == self.HIGH: + self._value = val + self._write(True) + return None + raise RuntimeError("Invalid value for pin") + return self.HIGH if self._read() else self.LOW + + # pylint: disable=too-many-branches + def _open(self, direction): + if not isinstance(direction, str): + raise TypeError("Invalid direction type, should be string.") + if direction.lower() not in ["in", "out", "high", "low"]: + raise ValueError('Invalid direction, can be: "in", "out", "high", "low".') + gpio_path = "/sys/class/gpio/gpio{:d}".format(self.id) + + if not os.path.isdir(gpio_path): + # Export the line + try: + with open("/sys/class/gpio/export", "w") as f_export: + f_export.write("{:d}\n".format(self.id)) + except IOError as e: + raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror) + + # Loop until GPIO is exported + exported = False + for i in range(self.GPIO_OPEN_RETRIES): + if os.path.isdir(gpio_path): + exported = True + break + + time.sleep(self.GPIO_OPEN_DELAY) + + if not exported: + raise TimeoutError( + 'Exporting GPIO: waiting for "{:s}" timed out'.format(gpio_path) + ) + + # Write direction, looping in case of EACCES errors due to delayed udev + # permission rule application after export + for i in range(self.GPIO_OPEN_RETRIES): + try: + with open(os.path.join(gpio_path, "direction"), "w") as f_direction: + f_direction.write(direction.lower() + "\n") + break + except IOError as e: + if e.errno != errno.EACCES or ( + e.errno == errno.EACCES and i == self.GPIO_OPEN_RETRIES - 1 + ): + raise GPIOError( + e.errno, "Setting GPIO direction: " + e.strerror + ) + + time.sleep(self.GPIO_OPEN_DELAY) + else: + # Write direction + try: + with open(os.path.join(gpio_path, "direction"), "w") as f_direction: + f_direction.write(direction.lower() + "\n") + except IOError as e: + raise GPIOError(e.errno, "Setting GPIO direction: " + e.strerror) + + # Open value + try: + self._fd = os.open(os.path.join(gpio_path, "value"), os.O_RDWR) + except OSError as e: + raise GPIOError(e.errno, "Opening GPIO: " + e.strerror) + + self._path = gpio_path + + # pylint: enable=too-many-branches + + def _close(self): + if self._fd is None: + return + + try: + os.close(self._fd) + except OSError as e: + raise GPIOError(e.errno, "Closing GPIO: " + e.strerror) + + self._fd = None + + # Unexport the line + try: + unexport_fd = os.open("/sys/class/gpio/unexport", os.O_WRONLY) + os.write(unexport_fd, "{:d}\n".format(self.id).encode()) + os.close(unexport_fd) + except OSError as e: + raise GPIOError(e.errno, "Unexporting GPIO: " + e.strerror) + + def _read(self): + # Read value + try: + buf = os.read(self._fd, 2) + except OSError as e: + raise GPIOError(e.errno, "Reading GPIO: " + e.strerror) + + # Rewind + try: + os.lseek(self._fd, 0, os.SEEK_SET) + except OSError as e: + raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror) + + if buf[0] == b"0"[0]: + return False + if buf[0] == b"1"[0]: + return True + + raise GPIOError(None, "Unknown GPIO value: {}".format(buf)) + + def _write(self, value): + if not isinstance(value, bool): + raise TypeError("Invalid value type, should be bool.") + + # Write value + try: + if value: + os.write(self._fd, b"1\n") + else: + os.write(self._fd, b"0\n") + except OSError as e: + raise GPIOError(e.errno, "Writing GPIO: " + e.strerror) + + # Rewind + try: + os.lseek(self._fd, 0, os.SEEK_SET) + except OSError as e: + raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror) + + @property + def chip_name(self): + """Return the Chip Name""" + gpio_path = os.path.join(self._path, "device") + + gpiochip_path = os.readlink(gpio_path) + + if "/" not in gpiochip_path: + raise GPIOError( + None, + 'Reading gpiochip name: invalid device symlink "{:s}"'.format( + gpiochip_path + ), + ) + + return gpiochip_path.split("/")[-1] + + @property + def chip_label(self): + """Return the Chip Label""" + gpio_path = "/sys/class/gpio/{:s}/label".format(self.chip_name) + + try: + with open(gpio_path, "r") as f_label: + label = f_label.read() + except (GPIOError, IOError) as e: + if isinstance(e, IOError): + raise GPIOError(e.errno, "Reading gpiochip label: " + e.strerror) + + raise GPIOError(None, "Reading gpiochip label: " + e.strerror) + + return label.strip() + + # Mutable properties + + def _get_direction(self): + # Read direction + try: + with open(os.path.join(self._path, "direction"), "r") as f_direction: + direction = f_direction.read() + except IOError as e: + raise GPIOError(e.errno, "Getting GPIO direction: " + e.strerror) + + return direction.strip() + + def _set_direction(self, direction): + if not isinstance(direction, str): + raise TypeError("Invalid direction type, should be string.") + if direction.lower() not in ["in", "out", "high", "low"]: + raise ValueError('Invalid direction, can be: "in", "out", "high", "low".') + + # Write direction + try: + with open(os.path.join(self._path, "direction"), "w") as f_direction: + f_direction.write(direction.lower() + "\n") + except IOError as e: + raise GPIOError(e.errno, "Setting GPIO direction: " + e.strerror) + + direction = property(_get_direction, _set_direction) + + def __str__(self): + try: + str_direction = self.direction + except GPIOError: + str_direction = "" + + try: + str_chip_name = self.chip_name + except GPIOError: + str_chip_name = "" + + try: + str_chip_label = self.chip_label + except GPIOError: + str_chip_label = "" + + output = "Pin {:d} (dev={:s}, fd={:d}, dir={:s}, chip_name='{:s}', chip_label='{:s}')" + return output.format( + self.id, self._path, self._fd, str_direction, str_chip_name, str_chip_label + ) diff --git a/src/adafruit_blinka/microcontroller/mcp2221/analogio.py b/src/adafruit_blinka/microcontroller/mcp2221/analogio.py new file mode 100644 index 0000000..3025202 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/mcp2221/analogio.py @@ -0,0 +1,54 @@ +""" +`analogio` - Analog input and output control +================================================= +See `CircuitPython:analogio` in CircuitPython for more details. +* Author(s): Carter Nelson +""" + +from adafruit_blinka.microcontroller.mcp2221.pin import Pin +from adafruit_blinka import ContextManaged + + +class AnalogIn(ContextManaged): + """Analog Input Class""" + + def __init__(self, pin): + self._pin = Pin(pin.id) + self._pin.init(mode=Pin.ADC) + + @property + def value(self): + """Read the ADC and return the value""" + return self._pin.value() + + # pylint: disable=no-self-use + @value.setter + def value(self, value): + # emulate what CircuitPython does + raise AttributeError("'AnalogIn' object has no attribute 'value'") + + # pylint: enable=no-self-use + + def deinit(self): + del self._pin + + +class AnalogOut(ContextManaged): + """Analog Output Class""" + + def __init__(self, pin): + self._pin = Pin(pin.id) + self._pin.init(mode=Pin.DAC) + + @property + def value(self): + """Return an error. This is output only.""" + # emulate what CircuitPython does + raise AttributeError("unreadable attribute") + + @value.setter + def value(self, value): + self._pin.value(value) + + def deinit(self): + del self._pin diff --git a/src/adafruit_blinka/microcontroller/rockchip/__init__.py b/src/adafruit_blinka/microcontroller/rockchip/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/adafruit_blinka/microcontroller/rockchip/rk3308/__init__.py b/src/adafruit_blinka/microcontroller/rockchip/rk3308/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/adafruit_blinka/microcontroller/rockchip/rk3308/pin.py b/src/adafruit_blinka/microcontroller/rockchip/rk3308/pin.py new file mode 100644 index 0000000..80c5c76 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/rockchip/rk3308/pin.py @@ -0,0 +1,179 @@ +"""A Pin class for use with Rockchip RK3308.""" + +from adafruit_blinka.microcontroller.generic_linux.sysfs_pin import Pin + +GPIO0_A0 = Pin(0) +GPIO0_A1 = Pin(1) +GPIO0_A2 = Pin(2) +GPIO0_A3 = Pin(3) +GPIO0_A4 = Pin(4) +GPIO0_A5 = Pin(5) +GPIO0_A6 = Pin(6) +GPIO0_A7 = Pin(7) +GPIO0_B0 = Pin(8) +GPIO0_B1 = Pin(9) +GPIO0_B2 = Pin(10) +GPIO0_B3 = Pin(11) +GPIO0_B4 = Pin(12) +GPIO0_B5 = Pin(13) +GPIO0_B6 = Pin(14) +GPIO0_B7 = Pin(15) +GPIO0_C0 = Pin(16) +GPIO0_C1 = Pin(17) +GPIO0_C2 = Pin(18) +GPIO0_C3 = Pin(19) +GPIO0_C4 = Pin(20) +GPIO0_C5 = Pin(21) +GPIO0_C6 = Pin(22) +GPIO0_C7 = Pin(23) +GPIO0_D0 = Pin(24) +GPIO0_D1 = Pin(25) +GPIO0_D2 = Pin(26) +GPIO0_D3 = Pin(27) +GPIO0_D4 = Pin(28) +GPIO0_D5 = Pin(29) +GPIO0_D6 = Pin(30) +GPIO0_D7 = Pin(31) +GPIO1_A0 = Pin(32) +GPIO1_A1 = Pin(33) +GPIO1_A2 = Pin(34) +GPIO1_A3 = Pin(35) +GPIO1_A4 = Pin(36) +GPIO1_A5 = Pin(37) +GPIO1_A6 = Pin(38) +GPIO1_A7 = Pin(39) +GPIO1_B0 = Pin(40) +GPIO1_B1 = Pin(41) +GPIO1_B2 = Pin(42) +GPIO1_B3 = Pin(43) +GPIO1_B4 = Pin(44) +GPIO1_B5 = Pin(45) +GPIO1_B6 = Pin(46) +GPIO1_B7 = Pin(47) +GPIO1_C0 = Pin(48) +GPIO1_C1 = Pin(49) +GPIO1_C2 = Pin(50) +GPIO1_C3 = Pin(51) +GPIO1_C4 = Pin(52) +GPIO1_C5 = Pin(53) +GPIO1_C6 = Pin(54) +GPIO1_C7 = Pin(55) +GPIO1_D0 = Pin(56) +GPIO1_D1 = Pin(57) +GPIO1_D2 = Pin(58) +GPIO1_D3 = Pin(59) +GPIO1_D4 = Pin(60) +GPIO1_D5 = Pin(61) +GPIO1_D6 = Pin(62) +GPIO1_D7 = Pin(63) +GPIO2_A0 = Pin(64) +GPIO2_A1 = Pin(65) +GPIO2_A2 = Pin(66) +GPIO2_A3 = Pin(67) +GPIO2_A4 = Pin(68) +GPIO2_A5 = Pin(69) +GPIO2_A6 = Pin(70) +GPIO2_A7 = Pin(71) +GPIO2_B0 = Pin(72) +GPIO2_B1 = Pin(73) +GPIO2_B2 = Pin(74) +GPIO2_B3 = Pin(75) +GPIO2_B4 = Pin(76) +GPIO2_B5 = Pin(77) +GPIO2_B6 = Pin(78) +GPIO2_B7 = Pin(79) +GPIO2_C0 = Pin(80) +GPIO2_C1 = Pin(81) +GPIO2_C2 = Pin(82) +GPIO2_C3 = Pin(83) +GPIO2_C4 = Pin(84) +GPIO2_C5 = Pin(85) +GPIO2_C6 = Pin(86) +GPIO2_C7 = Pin(87) +GPIO2_D0 = Pin(88) +GPIO2_D1 = Pin(89) +GPIO2_D2 = Pin(90) +GPIO2_D3 = Pin(91) +GPIO2_D4 = Pin(92) +GPIO2_D5 = Pin(93) +GPIO2_D6 = Pin(94) +GPIO2_D7 = Pin(95) +GPIO3_A0 = Pin(96) +GPIO3_A1 = Pin(97) +GPIO3_A2 = Pin(98) +GPIO3_A3 = Pin(99) +GPIO3_A4 = Pin(100) +GPIO3_A5 = Pin(101) +GPIO3_A6 = Pin(102) +GPIO3_A7 = Pin(103) +GPIO3_B0 = Pin(104) +GPIO3_B1 = Pin(105) +GPIO3_B2 = Pin(106) +GPIO3_B3 = Pin(107) +GPIO3_B4 = Pin(108) +GPIO3_B5 = Pin(109) +GPIO3_B6 = Pin(110) +GPIO3_B7 = Pin(111) +GPIO3_C0 = Pin(112) +GPIO3_C1 = Pin(113) +GPIO3_C2 = Pin(114) +GPIO3_C3 = Pin(115) +GPIO3_C4 = Pin(116) +GPIO3_C5 = Pin(117) +GPIO3_C6 = Pin(118) +GPIO3_C7 = Pin(119) +GPIO3_D0 = Pin(120) +GPIO3_D1 = Pin(121) +GPIO3_D2 = Pin(122) +GPIO3_D3 = Pin(123) +GPIO3_D4 = Pin(124) +GPIO3_D5 = Pin(125) +GPIO3_D6 = Pin(126) +GPIO3_D7 = Pin(127) +ADC_IN0 = 1 + + +# I2C +I2C1_SDA = GPIO0_B3 +I2C1_SCL = GPIO0_B4 +I2C2_SDA = GPIO1_D0 +I2C2_SCL = GPIO1_D1 +I2C3_SDA = GPIO0_B7 +I2C3_SCL = GPIO0_C0 + +# SPI +SPI2_CS = GPIO1_D1 +SPI2_SCLK = GPIO1_D0 +SPI2_MISO = GPIO1_C6 +SPI2_MOSI = GPIO1_C7 + +# UART +UART0_TX = GPIO2_A1 +UART0_RX = GPIO2_A0 +UART1_TX = GPIO1_D1 +UART1_RX = GPIO1_D0 +UART2_TX = GPIO1_C7 +UART2_RX = GPIO1_C6 + +# PWM +PWM2 = GPIO0_B7 +PWM3 = GPIO0_C0 + +# ordered as i2cId, SCL, SDA +i2cPorts = ( + (1, I2C1_SCL, I2C1_SDA), + (2, I2C2_SCL, I2C2_SDA), + (3, I2C3_SCL, I2C3_SDA), +) + +# ordered as spiId, sckId, mosiId, misoId +spiPorts = ((2, SPI2_SCLK, SPI2_MOSI, SPI2_MISO),) + +# SysFS pwm outputs, pwm channel and pin in first tuple +pwmOuts = ( + ((1, 0), PWM2), + ((2, 0), PWM3), +) + +# SysFS analog inputs, Ordered as analog analogInId, device, and channel +analogIns = ((ADC_IN0, 0, 0),) diff --git a/src/analogio.py b/src/analogio.py index 35a40ac..4bfcb36 100644 --- a/src/analogio.py +++ b/src/analogio.py @@ -2,7 +2,7 @@ `analogio` - Analog input and output control ================================================= See `CircuitPython:analogio` in CircuitPython for more details. -* Author(s): Carter Nelson +* Author(s): Carter Nelson, Melissa LeBlanc-Williams """ from adafruit_blinka.agnostic import board_id, detector @@ -10,44 +10,9 @@ from adafruit_blinka.agnostic import board_id, detector # pylint: disable=ungrouped-imports,wrong-import-position if detector.board.microchip_mcp2221: - from adafruit_blinka.microcontroller.mcp2221.pin import Pin + from adafruit_blinka.microcontroller.mcp2221.analogio import AnalogIn + from adafruit_blinka.microcontroller.mcp2221.analogio import AnalogOut +elif detector.chip.RK3308: + from adafruit_blinka.microcontroller.generic_linux.sysfs_analogin import AnalogIn else: raise NotImplementedError("analogio not supported for this board.") - -from adafruit_blinka import ContextManaged - - -class AnalogIn(ContextManaged): - def __init__(self, pin): - self._pin = Pin(pin.id) - self._pin.init(mode=Pin.ADC) - - @property - def value(self): - return self._pin.value() - - @value.setter - def value(self, value): - # emulate what CircuitPython does - raise AttributeError("'AnalogIn' object has no attribute 'value'") - - def deinit(self): - del self._pin - - -class AnalogOut(ContextManaged): - def __init__(self, pin): - self._pin = Pin(pin.id) - self._pin.init(mode=Pin.DAC) - - @property - def value(self): - # emulate what CircuitPython does - raise AttributeError("unreadable attribute") - - @value.setter - def value(self, value): - self._pin.value(value) - - def deinit(self): - del self._pin diff --git a/src/board.py b/src/board.py index 9f0f161..ace49f5 100755 --- a/src/board.py +++ b/src/board.py @@ -146,6 +146,9 @@ elif board_id == ap_board.CLOCKWORK_CPI3: elif board_id == ap_board.ONION_OMEGA2: from adafruit_blinka.board.onion.omega2 import * +elif board_id == ap_board.ROCK_PI_S: + from adafruit_blinka.board.radxa.rockpis import * + elif "sphinx" in sys.modules: pass diff --git a/src/busio.py b/src/busio.py index e95a44e..a5dc856 100755 --- a/src/busio.py +++ b/src/busio.py @@ -198,6 +198,9 @@ class SPI(Lockable): elif board_id == ap_board.JETSON_NX: from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI from adafruit_blinka.microcontroller.tegra.t194.pin import Pin + elif detector.board.ROCK_PI_S: + from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI + from adafruit_blinka.microcontroller.rockchip.rk3308.pin import Pin elif detector.board.SIFIVE_UNLEASHED: from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI from adafruit_blinka.microcontroller.hfu540.pin import Pin diff --git a/src/digitalio.py b/src/digitalio.py index ad76452..73f93cf 100755 --- a/src/digitalio.py +++ b/src/digitalio.py @@ -43,6 +43,8 @@ elif detector.chip.A33: from adafruit_blinka.microcontroller.allwinner.a33.pin import Pin elif detector.chip.MIPS24KEC: from adafruit_blinka.microcontroller.mips24kec.pin import Pin +elif detector.chip.RK3308: + from adafruit_blinka.microcontroller.rockchip.rk3308.pin import Pin elif detector.board.ftdi_ft232h: from adafruit_blinka.microcontroller.ft232h.pin import Pin elif detector.board.binho_nova: diff --git a/src/microcontroller/__init__.py b/src/microcontroller/__init__.py index 135ea36..29b25f8 100755 --- a/src/microcontroller/__init__.py +++ b/src/microcontroller/__init__.py @@ -62,6 +62,8 @@ elif chip_id == ap_chip.A64: from adafruit_blinka.microcontroller.allwinner.a64.pin import * elif chip_id == ap_chip.A33: from adafruit_blinka.microcontroller.allwinner.a33.pin import * +elif chip_id == ap_chip.RK3308: + from adafruit_blinka.microcontroller.rockchip.rk3308.pin import * elif chip_id == ap_chip.IMX8MX: from adafruit_blinka.microcontroller.nxp_imx8m import * elif chip_id == ap_chip.HFU540: diff --git a/src/microcontroller/pin.py b/src/microcontroller/pin.py index 8d0b8b0..cad4bfa 100755 --- a/src/microcontroller/pin.py +++ b/src/microcontroller/pin.py @@ -46,6 +46,8 @@ elif chip_id == ap_chip.A64: from adafruit_blinka.microcontroller.allwinner.a64.pin import * elif chip_id == ap_chip.A33: from adafruit_blinka.microcontroller.allwinner.a33.pin import * +elif chip_id == ap_chip.RK3308: + from adafruit_blinka.microcontroller.rockchip.rk3308.pin import * elif chip_id == ap_chip.MIPS24KC: from adafruit_blinka.microcontroller.atheros.ar9331.pin import * elif chip_id == ap_chip.MIPS24KEC: diff --git a/src/pulseio.py b/src/pulseio.py index 239a4ba..e1f7aab 100644 --- a/src/pulseio.py +++ b/src/pulseio.py @@ -8,5 +8,7 @@ if detector.board.any_giant_board: from adafruit_blinka.microcontroller.generic_linux.sysfs_pwmout import PWMOut if detector.board.any_beaglebone: from adafruit_blinka.microcontroller.am335x.sysfs_pwmout import PWMOut +if detector.board.any_rock_pi_board: + from adafruit_blinka.microcontroller.generic_linux.sysfs_pwmout import PWMOut if detector.board.binho_nova: from adafruit_blinka.microcontroller.nova.pwmout import PWMOut