--- /dev/null
+"""Raspberry Pi Pico pin names"""
+
+from adafruit_blinka.microcontroller.rp2040 import pin
+
+GP0 = pin.GP0
+GP1 = pin.GP1
+GP2 = pin.GP2
+GP3 = pin.GP3
+GP4 = pin.GP4
+GP5 = pin.GP5
+GP6 = pin.GP6
+GP7 = pin.GP7
+GP8 = pin.GP8
+GP9 = pin.GP9
+GP10 = pin.GP10
+GP11 = pin.GP11
+GP12 = pin.GP12
+GP13 = pin.GP13
+GP14 = pin.GP14
+GP15 = pin.GP15
+GP16 = pin.GP16
+GP17 = pin.GP17
+GP18 = pin.GP18
+GP19 = pin.GP19
+GP20 = pin.GP20
+GP21 = pin.GP21
+GP22 = pin.GP22
+GP23 = pin.GP23
+GP24 = pin.GP24
+GP25 = pin.GP25
+GP26 = pin.GP26
+GP27 = pin.GP27
+GP28 = pin.GP28
+LED = GP25
+SMPS_MODE = GP23
+VBUS_SENSE = GP24
+A0 = GP26
+A1 = GP27
+A2 = GP28
+A3 = pin.GP29
+VOLTAGE_MONITOR = pin.GP29
TOUT = Pin("TOUT")
# ordered as spiId, sckId, mosiId, misoId
-SPI_PORTS = (1, GPIO14, GPIO13, GPIO12)
+spiPorts = (1, GPIO14, GPIO13, GPIO12)
# ordered as uartId, txId, rxId
-UART_PORTS = (
+uartPorts = (
(0, GPIO1, GPIO3),
# TODO secondary pins for UART0 configurable from Micropython? How to flag?
# (0, GPIO15, GPIO13)
(1, GPIO2, None),
)
-I2C_PORTS = ()
+i2cPorts = ()
"""I2C Class for FT232H"""
from adafruit_blinka.microcontroller.ft232h.pin import Pin
+from adafruit_blinka.microcontroller.ft232h.url import get_ftdi_url
class I2C:
# pylint: enable=import-outside-toplevel
self._i2c = I2cController()
- self._i2c.configure("ftdi://ftdi:ft232h/1", frequency=frequency)
+ self._i2c.configure(get_ftdi_url(), frequency=frequency)
Pin.ft232h_gpio = self._i2c.get_gpio()
def scan(self):
"""FT232H pin names"""
+from adafruit_blinka.microcontroller.ft232h.url import get_ftdi_url
+
class Pin:
"""A basic Pin class for use with FT232H."""
# pylint: enable=import-outside-toplevel
i2c = I2cController()
- i2c.configure("ftdi://ftdi:ft232h/1")
+ i2c.configure(get_ftdi_url())
Pin.ft232h_gpio = i2c.get_gpio()
# check if pin is valid
if pin_id:
"""SPI Class for FT232H"""
from adafruit_blinka.microcontroller.ft232h.pin import Pin
+from adafruit_blinka.microcontroller.ft232h.url import get_ftdi_url
# pylint: disable=protected-access
class SPI:
# pylint: enable=import-outside-toplevel
self._spi = SpiController(cs_count=1)
- self._spi.configure("ftdi://ftdi:ft232h/1")
+ self._spi.configure(get_ftdi_url())
self._port = self._spi.get_port(0)
self._port.set_frequency(100000)
self._port._cpol = 0
--- /dev/null
+"""Support for getting the URL from the BLINKA_FT232H variable."""
+
+import os
+
+
+def get_ftdi_url():
+ """
+ Return the FTDI url to use. If BLINKA_FT232H starts with ftdi:, returns
+ that. Otherwise, returns a default value.
+ """
+
+ url = os.environ.get("BLINKA_FT232H", "1")
+
+ if url.startswith("ftdi:"):
+ return url
+
+ return "ftdi://ftdi:ft232h/1"
--- /dev/null
+"""I2C Class for Generic MicroPython"""
+from machine import I2C as _I2C
+
+
+class I2C:
+ """I2C Class for Generic MicroPython"""
+
+ MASTER = 0
+
+ # pylint: disable=unused-argument
+ def __init__(self, portId, *, mode=MASTER, baudrate=100000):
+ self._i2c = _I2C(portId, freq=baudrate)
+
+ def scan(self):
+ """Perform an I2C Device Scan"""
+ return self._i2c.scan()
+
+ def writeto(self, address, buffer, *, stop=True):
+ """Write the data from the buffer to the address"""
+ return self._i2c.writeto(address, buffer)
+
+ def readfrom_into(self, address, buffer, *, stop=True):
+ """Read data from an address and into the buffer"""
+ return self._i2c.readfrom_into(address, buffer)
+
+ def writeto_then_readfrom(
+ self,
+ address,
+ buffer_out,
+ buffer_in,
+ *,
+ out_start=0,
+ out_end=None,
+ in_start=0,
+ in_end=None,
+ stop=False
+ ):
+ """Write data from buffer_out to an address and then
+ read data from an address and into buffer_in
+ """
+ self._i2c.writeto_then_readfrom(
+ address,
+ buffer_out,
+ buffer_in,
+ out_start=out_start,
+ out_end=out_end,
+ in_start=in_start,
+ in_end=in_end,
+ )
+
+ # pylint: enable=unused-argument
--- /dev/null
+"""SPI Class for Generic MicroPython"""
+from machine import SPI as _SPI
+
+# pylint: disable=protected-access, no-self-use
+class SPI:
+ """SPI Class for Generic MicroPython"""
+
+ MSB = _SPI.MSB
+ LSB = _SPI.LSB
+
+ def __init__(self, portId, baudrate=100000):
+ self._frequency = baudrate
+ self._spi = _SPI(portId)
+
+ # pylint: disable=too-many-arguments,unused-argument
+ def init(
+ self,
+ baudrate=1000000,
+ polarity=0,
+ phase=0,
+ bits=8,
+ firstbit=_SPI.MSB,
+ ):
+ """Initialize the Port"""
+ self._frequency = baudrate
+ self._spi.init(
+ baudrate=baudrate,
+ polarity=polarity,
+ phase=phase,
+ bits=bits,
+ firstbit=firstbit,
+ mode=_SPI.MASTER,
+ )
+
+ # pylint: enable=too-many-arguments
+
+ @property
+ def frequency(self):
+ """Return the current frequency"""
+ return self._frequency
+
+ def write(self, buf, start=0, end=None):
+ """Write data from the buffer to SPI"""
+ self._spi.write(buf)
+
+ def readinto(self, buf, start=0, end=None, write_value=0):
+ """Read data from SPI and into the buffer"""
+ self._spi.readinto(buf)
+
+ # pylint: disable=too-many-arguments
+ def write_readinto(
+ self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
+ ):
+ """Perform a half-duplex write from buffer_out and then
+ read data into buffer_in
+ """
+ self._spi.write_readinto(
+ buffer_out,
+ buffer_in,
+ out_start=out_start,
+ out_end=out_end,
+ in_start=in_start,
+ in_end=in_end,
+ )
+
+ # pylint: enable=too-many-arguments
--- /dev/null
+"""I2C Class for RP2040"""
+from machine import I2C as _I2C
+from machine import Pin
+from microcontroller.pin import i2cPorts
+
+
+class I2C:
+ """Custom I2C Class for RP2040"""
+
+ def __init__(self, scl, sda, *, frequency=100000):
+ for portId, portScl, portSda in i2cPorts:
+ try:
+ if scl == portScl and sda == portSda:
+ self._i2c = _I2C(
+ portId, sda=Pin(sda.id), scl=Pin(scl.id), freq=frequency
+ )
+ break
+ except RuntimeError:
+ pass
+ else:
+ raise ValueError(
+ "No Hardware I2C on (scl,sda)={}\nValid I2C ports: {}".format(
+ (scl, sda), i2cPorts
+ )
+ )
+
+ def scan(self):
+ """Perform an I2C Device Scan"""
+ return self._i2c.scan()
+
+ # pylint: disable=unused-argument
+ def writeto(self, address, buffer, *, stop=True):
+ "Write data to the address from the buffer"
+ return self._i2c.writeto(address, buffer)
+
+ def readfrom_into(self, address, buffer, *, stop=True):
+ """Read data from an address and into the buffer"""
+ return self._i2c.readfrom_into(address, buffer)
+
+ def writeto_then_readfrom(
+ self,
+ address,
+ buffer_out,
+ buffer_in,
+ *,
+ out_start=0,
+ out_end=None,
+ in_start=0,
+ in_end=None,
+ stop=False
+ ):
+ """Write data from buffer_out to an address and then
+ read data from an address and into buffer_in
+ """
+ self._i2c.writeto_then_readfrom(
+ address,
+ buffer_out,
+ buffer_in,
+ out_start=out_start,
+ out_end=out_end,
+ in_start=in_start,
+ in_end=in_end,
+ )
+
+ # pylint: enable=unused-argument
--- /dev/null
+"""RP2040 pins"""
+
+from microcontroller import Pin
+
+GP0 = Pin(0)
+GP1 = Pin(1)
+GP2 = Pin(2)
+GP3 = Pin(3)
+GP4 = Pin(4)
+GP5 = Pin(5)
+GP6 = Pin(6)
+GP7 = Pin(7)
+GP8 = Pin(8)
+GP9 = Pin(9)
+GP10 = Pin(10)
+GP11 = Pin(11)
+GP12 = Pin(12)
+GP13 = Pin(13)
+GP14 = Pin(14)
+GP15 = Pin(15)
+GP16 = Pin(16)
+GP17 = Pin(17)
+GP18 = Pin(18)
+GP19 = Pin(19)
+GP20 = Pin(20)
+GP21 = Pin(21)
+GP22 = Pin(22)
+GP23 = Pin(23)
+GP24 = Pin(24)
+GP25 = Pin(25)
+GP26 = Pin(26)
+GP27 = Pin(27)
+GP28 = Pin(28)
+GP29 = Pin(29)
+
+# ordered as spiId, sckId, mosiId (tx), misoId (rx)
+spiPorts = (
+ (0, GP2, GP3, GP0),
+ (0, GP2, GP3, GP4),
+ (0, GP2, GP7, GP0),
+ (0, GP2, GP7, GP4),
+ (0, GP6, GP3, GP0),
+ (0, GP6, GP3, GP4),
+ (0, GP6, GP7, GP0),
+ (0, GP6, GP7, GP4),
+ (1, GP10, GP11, GP8),
+ (1, GP10, GP11, GP12),
+ (1, GP10, GP15, GP8),
+ (1, GP10, GP15, GP12),
+ (1, GP14, GP11, GP8),
+ (1, GP14, GP11, GP12),
+ (1, GP14, GP15, GP8),
+ (1, GP14, GP15, GP12),
+)
+
+# ordered as uartId, txId, rxId
+uartPorts = (
+ (0, GP0, GP1),
+ (0, GP0, GP13),
+ (0, GP12, GP1),
+ (0, GP12, GP13),
+ (1, GP4, GP5),
+ (1, GP4, GP9),
+ (1, GP8, GP5),
+ (1, GP8, GP9),
+)
+
+# ordered as scl, sda
+i2cPorts = (
+ (0, GP1, GP0),
+ (0, GP1, GP4),
+ (0, GP1, GP8),
+ (0, GP1, GP12),
+ (0, GP5, GP0),
+ (0, GP5, GP4),
+ (0, GP5, GP8),
+ (0, GP5, GP12),
+ (0, GP9, GP0),
+ (0, GP9, GP4),
+ (0, GP9, GP8),
+ (0, GP9, GP12),
+ (0, GP13, GP0),
+ (0, GP13, GP4),
+ (0, GP13, GP8),
+ (0, GP13, GP12),
+ (1, GP3, GP2),
+ (1, GP3, GP6),
+ (1, GP3, GP10),
+ (1, GP3, GP14),
+ (1, GP7, GP2),
+ (1, GP7, GP6),
+ (1, GP7, GP10),
+ (1, GP7, GP14),
+ (1, GP11, GP2),
+ (1, GP11, GP6),
+ (1, GP11, GP10),
+ (1, GP11, GP14),
+ (1, GP15, GP2),
+ (1, GP15, GP6),
+ (1, GP15, GP10),
+ (1, GP15, GP14),
+)
--- /dev/null
+"""SPI Class for RP2040"""
+from machine import SPI as _SPI
+from machine import Pin
+from microcontroller.pin import spiPorts
+
+# pylint: disable=protected-access, no-self-use
+class SPI:
+ """Custom SPI Class for RP2040"""
+
+ def __init__(self, clock, MOSI=None, MISO=None, *, baudrate=1000000):
+ self._frequency = baudrate
+ for portId, portSck, portMosi, portMiso in spiPorts:
+ if (
+ (clock == portSck)
+ and MOSI in (portMosi, None) # Clock is required!
+ and MISO in (portMiso, None) # But can do with just output
+ ): # Or just input
+ mosiPin = Pin(portMosi.id) if MOSI else None
+ misoPin = Pin(portMiso.id) if MISO else None
+ self._spi = _SPI(
+ portId,
+ sck=Pin(portSck.id),
+ mosi=mosiPin,
+ miso=misoPin,
+ baudrate=baudrate,
+ )
+ break
+ else:
+ raise ValueError(
+ "No Hardware SPI on (SCLK, MOSI, MISO)={}\nValid SPI ports:{}".format(
+ (clock, MOSI, MISO), spiPorts
+ )
+ )
+
+ # pylint: disable=too-many-arguments,unused-argument
+ def init(
+ self,
+ baudrate=1000000,
+ polarity=0,
+ phase=0,
+ bits=8,
+ firstbit=_SPI.MSB,
+ sck=None,
+ mosi=None,
+ miso=None,
+ ):
+ """Initialize the Port"""
+ self._frequency = baudrate
+ self._spi.init(
+ baudrate=baudrate,
+ polarity=polarity,
+ phase=phase,
+ bits=bits,
+ firstbit=firstbit,
+ )
+
+ # pylint: enable=too-many-arguments
+
+ @property
+ def frequency(self):
+ """Return the current frequency"""
+ return self._frequency
+
+ def write(self, buf, start=0, end=None):
+ """Write data from the buffer to SPI"""
+ self._spi.write(buf)
+
+ def readinto(self, buf, start=0, end=None, write_value=0):
+ """Read data from SPI and into the buffer"""
+ self._spi.readinto(buf)
+
+ # pylint: disable=too-many-arguments
+ def write_readinto(
+ self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
+ ):
+ """Perform a half-duplex write from buffer_out and then
+ read data into buffer_in
+ """
+ self._spi.write_readinto(
+ buffer_out,
+ buffer_in,
+ out_start=out_start,
+ out_end=out_end,
+ in_start=in_start,
+ in_end=in_end,
+ )
+
+ # pylint: enable=too-many-arguments
--- /dev/null
+"""UART Class for RP2040"""
+from machine import UART as _UART
+from machine import Pin
+from microcontroller.pin import uartPorts
+
+# pylint: disable=protected-access, no-self-use
+class UART:
+ """Custom UART Class for RP2040"""
+
+ # pylint: disable=too-many-arguments
+ def __init__(self, tx, rx, baudrate=9600, bits=8, parity=None, stop=1):
+ # check tx and rx have hardware support
+ for portId, txPin, rxPin in uartPorts:
+ if txPin == tx and rxPin == rx:
+ self._uart = _UART(
+ portId,
+ baudrate,
+ bits=bits,
+ parity=parity,
+ stop=stop,
+ tx=Pin(txPin.id),
+ rx=Pin(rxPin.id),
+ )
+ break
+ else:
+ raise ValueError(
+ "No Hardware UART on (tx,rx)={}\nValid UART ports: {}".format(
+ (tx.id, rx.id), uartPorts
+ )
+ )
+
+ # pylint: enable=too-many-arguments
+
+ def read(self, nbytes=None):
+ """Read from the UART"""
+ return self._uart.read(nbytes)
+
+ def readinto(self, buf, nbytes=None):
+ """Read from the UART into a buffer"""
+ return self._uart.readinto(buf, nbytes)
+
+ def readline(self):
+ """Read a line of characters up to a newline charater from the UART"""
+ return self._uart.readline()
+
+ def write(self, buf):
+ """Write to the UART from a buffer"""
+ return self._uart.write(buf)
D2 = Pin("D2")
# ordered as spiId, sckId, mosiId, misoId
-SPI_PORTS = ((1, B13, B15, B14), (2, A5, A6, A7))
+spiPorts = ((1, B13, B15, B14), (2, A5, A7, A6))
# ordered as uartId, txId, rxId
-UART_PORTS = (
+uartPorts = (
(1, B6, B7),
(2, A2, A3),
(3, B10, B11),
(6, C6, C7),
)
-I2C_PORTS = (
+i2cPorts = (
(1, B6, B7),
(2, B10, B11),
)
elif board_id == ap_board.PYBOARD:
from adafruit_blinka.board.pyboard import *
+elif board_id == ap_board.RASPBERRY_PI_PICO:
+ from adafruit_blinka.board.raspberrypi.pico import *
+
elif detector.board.any_raspberry_pi_40_pin:
from adafruit_blinka.board.raspberrypi.raspi_40pin import *
else:
raise NotImplementedError("Board not supported {}".format(board_id))
+if "SCL" in locals() and "SDA" in locals():
+
+ def I2C():
+ """The singleton I2C interface"""
+ import busio
-def I2C():
- """The singleton I2C interface"""
- import busio
+ return busio.I2C(SCL, SDA)
- return busio.I2C(SCL, SDA)
+if "SCLK" in locals() and "MOSI" in locals() and "MISO" in locals():
-def SPI():
- """The singleton SPI interface"""
- import busio
+ def SPI():
+ """The singleton SPI interface"""
+ import busio
- return busio.SPI(SCLK, MOSI, MISO)
+ return busio.SPI(SCLK, MOSI, MISO)
from adafruit_blinka.agnostic import board_id, detector
# pylint: disable=import-outside-toplevel,too-many-branches,too-many-statements
-# pylint: disable=too-many-arguments,too-many-function-args, consider-using-with
+# pylint: disable=too-many-arguments,too-many-function-args,consider-using-with
class I2C(Lockable):
if detector.board.pico_u2if:
from adafruit_blinka.microcontroller.pico_u2if.i2c import I2C as _I2C
+ self._i2c = _I2C(scl, sda, frequency=frequency)
+ return
+ if detector.chip.id == ap_chip.RP2040:
+ from adafruit_blinka.microcontroller.rp2040.i2c import I2C as _I2C
+
self._i2c = _I2C(scl, sda, frequency=frequency)
return
if detector.board.any_embedded_linux:
from adafruit_blinka.microcontroller.generic_linux.i2c import I2C as _I2C
else:
- from machine import I2C as _I2C
+ from adafruit_blinka.microcontroller.generic_micropython.i2c import (
+ I2C as _I2C,
+ )
from microcontroller.pin import i2cPorts
for portId, portScl, portSda in i2cPorts:
try:
+ # pylint: disable=unexpected-keyword-arg
if scl == portScl and sda == portSda:
self._i2c = _I2C(portId, mode=_I2C.MASTER, baudrate=frequency)
break
+ # pylint: enable=unexpected-keyword-arg
except RuntimeError:
pass
else:
self._spi = _SPI(clock) # this is really all that's needed
self._pins = (clock, clock, clock) # will determine MOSI/MISO from clock
return
+ if detector.chip.id == ap_chip.RP2040:
+ from adafruit_blinka.microcontroller.rp2040.spi import SPI as _SPI
+
+ self._spi = _SPI(clock, MOSI, MISO) # Pins configured on instantiation
+ self._pins = (clock, clock, clock) # These don't matter, they're discarded
+ return
if detector.board.any_embedded_linux:
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
else:
- from machine import SPI as _SPI
+ from adafruit_blinka.microcontroller.generic_micropython.spi import (
+ SPI as _SPI,
+ )
from microcontroller.pin import spiPorts
for portId, portSck, portMosi, portMiso in spiPorts:
def configure(self, baudrate=100000, polarity=0, phase=0, bits=8):
"""Update the configuration"""
if detector.board.any_raspberry_pi or detector.board.any_raspberry_pi_40_pin:
- from adafruit_blinka.microcontroller.bcm283x.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif detector.board.BEAGLEBONE_AI:
- from adafruit_blinka.microcontroller.dra74x.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif detector.board.any_beaglebone:
- from adafruit_blinka.microcontroller.am335x.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif detector.board.any_orange_pi:
- if detector.chip.id == ap_chip.SUN8I:
- from adafruit_blinka.microcontroller.allwinner.h3.pin import Pin
- elif detector.chip.id == ap_chip.H5:
- from adafruit_blinka.microcontroller.allwinner.h5.pin import Pin
- elif detector.chip.id == ap_chip.H616:
- from adafruit_blinka.microcontroller.allwinner.h616.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif detector.board.any_nanopi and detector.chip.id == ap_chip.SUN8I:
- from adafruit_blinka.microcontroller.allwinner.h3.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.GIANT_BOARD:
- from adafruit_blinka.microcontroller.sama5.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.CORAL_EDGE_TPU_DEV:
- from adafruit_blinka.microcontroller.nxp_imx8m.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.CORAL_EDGE_TPU_DEV_MINI:
- from adafruit_blinka.microcontroller.mt8167.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.ODROID_C2:
- from adafruit_blinka.microcontroller.amlogic.s905.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.ODROID_C4:
- from adafruit_blinka.microcontroller.amlogic.s905x3.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.ODROID_XU4:
- from adafruit_blinka.microcontroller.samsung.exynos5422.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.DRAGONBOARD_410C:
- from adafruit_blinka.microcontroller.snapdragon.apq8016.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.JETSON_NANO:
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.tegra.t210.pin import Pin
elif board_id == ap_board.JETSON_TX1:
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.tegra.t210.pin import Pin
elif board_id == ap_board.JETSON_TX2:
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.tegra.t186.pin import Pin
elif board_id == ap_board.JETSON_XAVIER:
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.tegra.t194.pin import Pin
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.ROCK_PI_4:
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.rockchip.rk3399.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
elif detector.board.ftdi_ft232h:
from adafruit_blinka.microcontroller.ft232h.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.ft232h.pin import Pin
elif detector.board.binho_nova:
from adafruit_blinka.microcontroller.nova.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.nova.pin import Pin
elif detector.board.greatfet_one:
from adafruit_blinka.microcontroller.nxp_lpc4330.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.nxp_lpc4330.pin import Pin
elif board_id in (
ap_board.PINE64,
ap_board.PINEBOOK,
ap_board.PINEPHONE,
ap_board.SOPINE,
):
- from adafruit_blinka.microcontroller.allwinner.a64.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.CLOCKWORK_CPI3:
- from adafruit_blinka.microcontroller.allwinner.a33.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif board_id == ap_board.ONION_OMEGA2:
- from adafruit_blinka.microcontroller.mips24kec.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif detector.board.any_lubancat and detector.chip.id == ap_chip.IMX6ULL:
- from adafruit_blinka.microcontroller.nxp_imx6ull.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
elif detector.board.pico_u2if:
from adafruit_blinka.microcontroller.pico_u2if.spi import SPI as _SPI
- from adafruit_blinka.microcontroller.pico_u2if.pin import Pin
+ elif detector.chip.id == ap_chip.RP2040:
+ from adafruit_blinka.microcontroller.rp2040.spi import SPI as _SPI
else:
- from machine import SPI as _SPI
- from machine import Pin
+ from adafruit_blinka.microcontroller.generic_micropython.spi import (
+ SPI as _SPI,
+ )
if self._locked:
# TODO check if #init ignores MOSI=None rather than unsetting, to save _pinIds attribute
phase=phase,
bits=bits,
firstbit=_SPI.MSB,
- sck=Pin(self._pins[0].id),
- mosi=Pin(self._pins[1].id),
- miso=Pin(self._pins[2].id),
)
else:
raise RuntimeError("First call try_lock()")
from adafruit_blinka.microcontroller.nova.uart import UART as _UART
elif detector.board.greatfet_one:
from adafruit_blinka.microcontroller.nxp_lpc4330.uart import UART as _UART
+ elif detector.chip.id == ap_chip.RP2040:
+ from adafruit_blinka.microcontroller.rp2040.uart import UART as _UART
else:
from machine import UART as _UART
- if detector.board.binho_nova:
- from adafruit_blinka.microcontroller.nova.pin import uartPorts
- else:
- from microcontroller.pin import uartPorts
+ from microcontroller.pin import uartPorts
self.baudrate = baudrate
else:
raise ValueError("Invalid parity")
- # check tx and rx have hardware support
- for portId, portTx, portRx in uartPorts: #
- if portTx == tx and portRx == rx:
- self._uart = _UART(
- portId,
- baudrate,
- bits=bits,
- parity=parity,
- stop=stop,
- timeout=timeout,
- read_buf_len=receiver_buffer_size,
- )
- break
+ if detector.chip.id == ap_chip.RP2040:
+ self._uart = _UART(
+ tx,
+ rx,
+ baudrate=baudrate,
+ bits=bits,
+ parity=parity,
+ stop=stop,
+ )
else:
- raise ValueError(
- "No Hardware UART on (tx,rx)={}\nValid UART ports: {}".format(
- (tx, rx), uartPorts
+ # check tx and rx have hardware support
+ for portId, portTx, portRx in uartPorts: #
+ if portTx == tx and portRx == rx:
+ self._uart = _UART(
+ portId,
+ baudrate,
+ bits=bits,
+ parity=parity,
+ stop=stop,
+ timeout=timeout,
+ read_buf_len=receiver_buffer_size,
+ )
+ break
+ else:
+ raise ValueError(
+ "No Hardware UART on (tx,rx)={}\nValid UART ports: {}".format(
+ (tx, rx), uartPorts
+ )
)
- )
def deinit(self):
"""Deinitialization"""
from adafruit_blinka.microcontroller.nxp_lpc4330.pin import Pin
elif detector.chip.STM32F405:
from machine import Pin
+elif detector.chip.RP2040:
+ from machine import Pin
elif detector.board.microchip_mcp2221:
from adafruit_blinka.microcontroller.mcp2221.pin import Pin
elif detector.chip.PENTIUM_N3710:
def __init__(self, pin_id):
"""Identifier for pin, referencing platform-specific pin id"""
- self._id = pin_id
+ self.id = pin_id
def __repr__(self):
# pylint: disable=import-outside-toplevel, cyclic-import
from adafruit_blinka.microcontroller.esp8266 import *
elif chip_id == ap_chip.STM32F405:
from adafruit_blinka.microcontroller.stm32.stm32f405 import *
+elif chip_id == ap_chip.RP2040:
+ from adafruit_blinka.microcontroller.rp2040 import *
elif chip_id == ap_chip.BCM2XXX:
from adafruit_blinka.microcontroller.bcm283x import *
elif chip_id == ap_chip.DRA74X:
from adafruit_blinka.microcontroller.esp8266.pin import *
elif chip_id == ap_chip.STM32F405:
from adafruit_blinka.microcontroller.stm32.stm32f405.pin import *
+elif chip_id == ap_chip.RP2040:
+ from adafruit_blinka.microcontroller.rp2040.pin import *
elif chip_id == ap_chip.BCM2XXX:
from adafruit_blinka.microcontroller.bcm283x.pin import *
elif chip_id == ap_chip.DRA74X: