]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Added Rock Pi S
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Wed, 29 Apr 2020 15:35:56 +0000 (08:35 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Wed, 29 Apr 2020 15:35:56 +0000 (08:35 -0700)
18 files changed:
requirements.txt
setup.py
src/adafruit_blinka/board/radxa/__init__.py [new file with mode: 0644]
src/adafruit_blinka/board/radxa/rockpis.py [new file with mode: 0644]
src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogin.py [new file with mode: 0644]
src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogout.py [new file with mode: 0644]
src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py [new file with mode: 0644]
src/adafruit_blinka/microcontroller/mcp2221/analogio.py [new file with mode: 0644]
src/adafruit_blinka/microcontroller/rockchip/__init__.py [new file with mode: 0644]
src/adafruit_blinka/microcontroller/rockchip/rk3308/__init__.py [new file with mode: 0644]
src/adafruit_blinka/microcontroller/rockchip/rk3308/pin.py [new file with mode: 0644]
src/analogio.py
src/board.py
src/busio.py
src/digitalio.py
src/microcontroller/__init__.py
src/microcontroller/pin.py
src/pulseio.py

index 8aa587abdfedd4a5df0db78850b16a42d601d896..f126dd3686db1cdea885e7603d9684d63125b1bd 100755 (executable)
@@ -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'
index de421f4848fb9fa026b84e10b4f0a53e7b2b106f..35c7c82a54a5689b8ffb327cc7e82eb080ee7172 100755 (executable)
--- 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 (file)
index 0000000..b1b4b8c
--- /dev/null
@@ -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 (file)
index 0000000..e11574f
--- /dev/null
@@ -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 (file)
index 0000000..bf6988b
--- /dev/null
@@ -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 (file)
index 0000000..ec8b6c6
--- /dev/null
@@ -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 (file)
index 0000000..c5b56e6
--- /dev/null
@@ -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 = "<error>"
+
+        try:
+            str_chip_name = self.chip_name
+        except GPIOError:
+            str_chip_name = "<error>"
+
+        try:
+            str_chip_label = self.chip_label
+        except GPIOError:
+            str_chip_label = "<error>"
+
+        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 (file)
index 0000000..3025202
--- /dev/null
@@ -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 (file)
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 (file)
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 (file)
index 0000000..80c5c76
--- /dev/null
@@ -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),)
index 35a40ac03018d657eb9089c97c20f50e52c9d283..4bfcb36543aaa2c10cfdaf13b683f5f82fe7474d 100644 (file)
@@ -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
index 9f0f1618c0bb9477508d7b467bfcfd75008542fb..ace49f5aeb756767be86cf5555763f23baca3f24 100755 (executable)
@@ -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
 
index e95a44e2adde156e4590654f767091b97c49fa52..a5dc856afb841ed191ed9a1f7e3aa546231f2aa2 100755 (executable)
@@ -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
index ad76452ea1d2601c6e8b52f51c6a1073d87d01a9..73f93cf39e252e04efa48963344de24bad87cbca 100755 (executable)
@@ -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:
index 135ea36c3dd5b38af43db374593ce3301e47d275..29b25f8f37ceeb02280fd7f334d4d73dde944d17 100755 (executable)
@@ -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:
index 8d0b8b0660443a3efbdd7e449aa33c57fdf5b4df..cad4bfac1496e296c19498bba8a213fc1015b515 100755 (executable)
@@ -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:
index 239a4ba1dd6b3feb7c27dd0f1d3defcb711b10ac..e1f7aab09257dba7c03ddf576dcd87ad7eeaf214 100644 (file)
@@ -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