moved a bunch of garbage (things that have nothing to do in root) to _trash
This commit is contained in:
parent
d094982b2c
commit
3226ed29ec
2610 changed files with 0 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,65 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""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()
|
||||
|
||||
def writeto(self, address, buffer, *, stop=True):
|
||||
"Write data to the address from the buffer"
|
||||
return self._i2c.writeto(address, buffer, stop)
|
||||
|
||||
def readfrom_into(self, address, buffer, *, stop=True):
|
||||
"""Read data from an address and into the buffer"""
|
||||
return self._i2c.readfrom_into(address, buffer, stop)
|
||||
|
||||
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
|
||||
"""
|
||||
if out_end:
|
||||
self.writeto(address, buffer_out[out_start:out_end], stop=stop)
|
||||
else:
|
||||
self.writeto(address, buffer_out[out_start:], stop=stop)
|
||||
|
||||
if not in_end:
|
||||
in_end = len(buffer_in)
|
||||
read_buffer = memoryview(buffer_in)[in_start:in_end]
|
||||
self.readfrom_into(address, read_buffer, stop=stop)
|
|
@ -0,0 +1,238 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""RP2040 pins"""
|
||||
|
||||
from ..generic_micropython 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, GP3, GP16),
|
||||
(0, GP2, GP3, GP20),
|
||||
(0, GP2, GP7, GP0),
|
||||
(0, GP2, GP7, GP4),
|
||||
(0, GP2, GP7, GP16),
|
||||
(0, GP2, GP7, GP20),
|
||||
(0, GP2, GP19, GP0),
|
||||
(0, GP2, GP19, GP4),
|
||||
(0, GP2, GP19, GP16),
|
||||
(0, GP2, GP19, GP20),
|
||||
(0, GP6, GP3, GP0),
|
||||
(0, GP6, GP3, GP4),
|
||||
(0, GP6, GP3, GP16),
|
||||
(0, GP6, GP3, GP20),
|
||||
(0, GP6, GP7, GP0),
|
||||
(0, GP6, GP7, GP4),
|
||||
(0, GP6, GP7, GP16),
|
||||
(0, GP6, GP7, GP20),
|
||||
(0, GP6, GP19, GP0),
|
||||
(0, GP6, GP19, GP4),
|
||||
(0, GP6, GP19, GP16),
|
||||
(0, GP6, GP19, GP20),
|
||||
(0, GP18, GP3, GP0),
|
||||
(0, GP18, GP3, GP4),
|
||||
(0, GP18, GP3, GP16),
|
||||
(0, GP18, GP3, GP20),
|
||||
(0, GP18, GP7, GP0),
|
||||
(0, GP18, GP7, GP4),
|
||||
(0, GP18, GP7, GP16),
|
||||
(0, GP18, GP7, GP20),
|
||||
(0, GP18, GP19, GP0),
|
||||
(0, GP18, GP19, GP4),
|
||||
(0, GP18, GP19, GP16),
|
||||
(0, GP18, GP19, GP20),
|
||||
(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, GP0, GP17),
|
||||
(0, GP0, GP29),
|
||||
(0, GP12, GP1),
|
||||
(0, GP12, GP13),
|
||||
(0, GP12, GP17),
|
||||
(0, GP12, GP29),
|
||||
(0, GP16, GP1),
|
||||
(0, GP16, GP13),
|
||||
(0, GP16, GP17),
|
||||
(0, GP16, GP29),
|
||||
(0, GP28, GP1),
|
||||
(0, GP28, GP13),
|
||||
(0, GP28, GP17),
|
||||
(0, GP28, GP29),
|
||||
(1, GP4, GP5),
|
||||
(1, GP4, GP9),
|
||||
(1, GP4, GP21),
|
||||
(1, GP4, GP25),
|
||||
(1, GP8, GP5),
|
||||
(1, GP8, GP9),
|
||||
(1, GP8, GP21),
|
||||
(1, GP8, GP25),
|
||||
(1, GP20, GP5),
|
||||
(1, GP20, GP9),
|
||||
(1, GP20, GP21),
|
||||
(1, GP20, GP25),
|
||||
(1, GP24, GP5),
|
||||
(1, GP24, GP9),
|
||||
(1, GP24, GP21),
|
||||
(1, GP24, GP25),
|
||||
)
|
||||
|
||||
# ordered as scl, sda
|
||||
i2cPorts = (
|
||||
(0, GP1, GP0),
|
||||
(0, GP1, GP4),
|
||||
(0, GP1, GP8),
|
||||
(0, GP1, GP12),
|
||||
(0, GP1, GP16),
|
||||
(0, GP1, GP20),
|
||||
(0, GP1, GP24),
|
||||
(0, GP1, GP28),
|
||||
(1, GP3, GP2),
|
||||
(1, GP3, GP6),
|
||||
(1, GP3, GP10),
|
||||
(1, GP3, GP14),
|
||||
(1, GP3, GP18),
|
||||
(1, GP3, GP22),
|
||||
(1, GP3, GP26),
|
||||
(0, GP5, GP0),
|
||||
(0, GP5, GP4),
|
||||
(0, GP5, GP8),
|
||||
(0, GP5, GP12),
|
||||
(0, GP5, GP16),
|
||||
(0, GP5, GP20),
|
||||
(0, GP5, GP24),
|
||||
(0, GP5, GP28),
|
||||
(1, GP7, GP2),
|
||||
(1, GP7, GP6),
|
||||
(1, GP7, GP10),
|
||||
(1, GP7, GP14),
|
||||
(1, GP7, GP18),
|
||||
(1, GP7, GP22),
|
||||
(1, GP7, GP26),
|
||||
(0, GP9, GP0),
|
||||
(0, GP9, GP4),
|
||||
(0, GP9, GP8),
|
||||
(0, GP9, GP12),
|
||||
(0, GP9, GP16),
|
||||
(0, GP9, GP20),
|
||||
(0, GP9, GP24),
|
||||
(0, GP9, GP28),
|
||||
(1, GP11, GP2),
|
||||
(1, GP11, GP6),
|
||||
(1, GP11, GP10),
|
||||
(1, GP11, GP14),
|
||||
(1, GP11, GP18),
|
||||
(1, GP11, GP22),
|
||||
(1, GP11, GP26),
|
||||
(0, GP13, GP0),
|
||||
(0, GP13, GP4),
|
||||
(0, GP13, GP8),
|
||||
(0, GP13, GP12),
|
||||
(0, GP13, GP16),
|
||||
(0, GP13, GP20),
|
||||
(0, GP13, GP24),
|
||||
(0, GP13, GP28),
|
||||
(1, GP15, GP2),
|
||||
(1, GP15, GP6),
|
||||
(1, GP15, GP10),
|
||||
(1, GP15, GP14),
|
||||
(1, GP15, GP18),
|
||||
(1, GP15, GP22),
|
||||
(1, GP15, GP26),
|
||||
(0, GP17, GP0),
|
||||
(0, GP17, GP4),
|
||||
(0, GP17, GP8),
|
||||
(0, GP17, GP12),
|
||||
(0, GP17, GP16),
|
||||
(0, GP17, GP20),
|
||||
(0, GP17, GP24),
|
||||
(0, GP17, GP28),
|
||||
(1, GP19, GP2),
|
||||
(1, GP19, GP6),
|
||||
(1, GP19, GP10),
|
||||
(1, GP19, GP14),
|
||||
(1, GP19, GP18),
|
||||
(1, GP19, GP22),
|
||||
(1, GP19, GP26),
|
||||
(0, GP21, GP0),
|
||||
(0, GP21, GP4),
|
||||
(0, GP21, GP8),
|
||||
(0, GP21, GP12),
|
||||
(0, GP21, GP16),
|
||||
(0, GP21, GP20),
|
||||
(0, GP21, GP24),
|
||||
(0, GP21, GP28),
|
||||
(1, GP23, GP2),
|
||||
(1, GP23, GP6),
|
||||
(1, GP23, GP10),
|
||||
(1, GP23, GP14),
|
||||
(1, GP23, GP18),
|
||||
(1, GP23, GP22),
|
||||
(1, GP23, GP26),
|
||||
(0, GP25, GP0),
|
||||
(0, GP25, GP4),
|
||||
(0, GP25, GP8),
|
||||
(0, GP25, GP12),
|
||||
(0, GP25, GP16),
|
||||
(0, GP25, GP20),
|
||||
(0, GP25, GP24),
|
||||
(0, GP25, GP28),
|
||||
(1, GP27, GP2),
|
||||
(1, GP27, GP6),
|
||||
(1, GP27, GP10),
|
||||
(1, GP27, GP14),
|
||||
(1, GP27, GP18),
|
||||
(1, GP27, GP22),
|
||||
(1, GP27, GP26),
|
||||
(0, GP29, GP0),
|
||||
(0, GP29, GP4),
|
||||
(0, GP29, GP8),
|
||||
(0, GP29, GP12),
|
||||
(0, GP29, GP16),
|
||||
(0, GP29, GP20),
|
||||
(0, GP29, GP24),
|
||||
(0, GP29, GP28),
|
||||
)
|
|
@ -0,0 +1,94 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""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"""
|
||||
|
||||
MSB = _SPI.MSB
|
||||
|
||||
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
|
|
@ -0,0 +1,52 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""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)
|
Loading…
Add table
Add a link
Reference in a new issue