source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
- pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
+ pip install --force-reinstall pylint black Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: Check formatting
--- /dev/null
+import time
+import hid
+import busio
+
+from adafruit_blinka.microcontroller.mcp2221.mcp2221 import mcp2221 as _mcp2221
+from adafruit_blinka.microcontroller.mcp2221.mcp2221 import MCP2221 as _MCP2221
+from adafruit_blinka.microcontroller.mcp2221.i2c import I2C as _MCP2221I2C
+
+MLXADDR = 0x33
+ADDRID1 = 0x2407
+
+
+class MCP2221(_MCP2221): # pylint: disable=too-few-public-methods
+ def __init__(self, address):
+ self._hid = hid.device()
+ self._hid.open_path(address)
+ print("Connected to " + str(address))
+ self._gp_config = [0x07] * 4 # "don't care" initial value
+ for pin in range(4):
+ self.gp_set_mode(pin, self.GP_GPIO) # set to GPIO mode
+ self.gpio_set_direction(pin, 1) # set to INPUT
+
+
+class MCP2221I2C(_MCP2221I2C): # pylint: disable=too-few-public-methods
+ def __init__(self, mcp2221, *, frequency=100000):
+ self._mcp2221 = mcp2221
+ self._mcp2221.i2c_configure(frequency)
+
+
+class I2C(busio.I2C): # pylint: disable=too-few-public-methods
+ def __init__(self, mcp2221_i2c):
+ self._i2c = mcp2221_i2c
+
+
+addresses = [mcp["path"] for mcp in hid.enumerate(0x04D8, 0x00DD)]
+
+i2c_devices = []
+i2c_devices.append(I2C(MCP2221I2C(_mcp2221)))
+
+for addr in addresses:
+ try:
+ i2c_device = I2C(MCP2221I2C(MCP2221(addr)))
+ i2c_devices.append(i2c_device)
+ except OSError:
+ print("Device path: " + str(addr) + " is used")
+
+
+while True:
+ for i2c in i2c_devices:
+ addrbuf = bytearray(2)
+ addrbuf[0] = ADDRID1 >> 8
+ addrbuf[1] = ADDRID1 & 0xFF
+ inbuf = bytearray(6)
+ i2c.writeto_then_readfrom(MLXADDR, addrbuf, inbuf)
+ print("Device " + str(i2c_devices.index(i2c)) + ": ")
+ print(inbuf)
+ time.sleep(0.5)
-Adafruit-PlatformDetect>=2.11.1
-Adafruit-PureIO>=1.1.5
+Adafruit-PlatformDetect>=2.18.1
+Adafruit-PureIO>=1.1.7
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'
or b"brcm,bcm2837" in compat
or b"brcm,bcm2838" in compat
):
- board_reqs = ["RPi.GPIO", "rpi_ws281x>=4.0.0"]
+ board_reqs = ["RPi.GPIO", "rpi_ws281x>=4.0.0", "sysv_ipc"]
setup(
name="Adafruit-Blinka",
"adafruit_blinka.microcontroller.bcm283x.pulseio": ["libgpiod_pulsein"]
},
install_requires=[
- "Adafruit-PlatformDetect>=2.11.1",
- "Adafruit-PureIO>=1.1.5",
- "sysv_ipc; platform_system != 'Windows' and platform_machine != 'mips'",
+ "Adafruit-PlatformDetect>=2.18.1",
+ "Adafruit-PureIO>=1.1.7",
"pyftdi>=0.40.0",
]
+ board_reqs,
class Enum:
"""
- Object supporting CircuitPython-style of static symbols
- as seen with Direction.OUTPUT, Pull.UP
+ Object supporting CircuitPython-style of static symbols
+ as seen with Direction.OUTPUT, Pull.UP
"""
def __repr__(self):
@classmethod
def iteritems(cls):
"""
- Inspects attributes of the class for instances of the class
- and returns as key,value pairs mirroring dict#iteritems
+ Inspects attributes of the class for instances of the class
+ and returns as key,value pairs mirroring dict#iteritems
"""
for key in dir(cls):
val = getattr(cls, key)
--- /dev/null
+"""Pin definitions for the Banana Pi M2 Zero."""
+
+# The Banana Pi M2 Zero uses the AllWinner H2 SoC, but pins
+# are the same as the AllWinner H3 SoC, so we import those
+from adafruit_blinka.microcontroller.allwinner.h3 import pin
+
+PA12 = pin.PA12
+SDA = pin.PA12
+PA11 = pin.PA11
+SCL = pin.PA11
+PA6 = pin.PA6
+PWM1 = pin.PA6
+PA1 = pin.PA1
+UART2_RX = pin.PA1
+PA0 = pin.PA0
+UART2_TX = pin.PA0
+PA3 = pin.PA3
+UART2_CTS = pin.PA3
+PA10 = pin.PA10
+
+PA13 = pin.PA13
+SPI1_CS = pin.PA13
+PA14 = pin.PA14
+SPI1_CLK = pin.PA14
+PA2 = pin.PA2
+UART2_RTS = pin.PA2
+PA18 = pin.PA18
+TWI1_SCK = pin.PA18
+PG6 = pin.PG6
+UART1_TX = pin.PG6
+PG7 = pin.PG7
+UART1_RX = pin.PG7
+
+SCLK = pin.PA14
+MOSI = pin.PA15
+MISO = pin.PA16
--- /dev/null
+"""Pin definitions for Clara AGX Xavier."""
+
+from adafruit_blinka.microcontroller.tegra.t194 import pin
+
+SDA = pin.SDA
+SCL = pin.SCL
+SDA_1 = pin.SDA_1
+SCL_1 = pin.SCL_1
+
+D4 = pin.Q06
+D5 = pin.AA03
+D6 = pin.AA02
+D7 = pin.Z07
+D8 = pin.Z06
+D9 = pin.Z04
+D10 = pin.Z05
+D11 = pin.Z03
+D12 = pin.BB01
+D13 = pin.AA00
+D16 = pin.R05
+D17 = pin.R04
+D18 = pin.H07
+D19 = pin.I02
+D20 = pin.I01
+D21 = pin.I00
+D22 = pin.N01
+D23 = pin.BB00
+D24 = pin.H00
+D25 = pin.Q01
+D26 = pin.AA01
+D27 = pin.P04
+
+CE1 = D7
+CE0 = D8
+MISO = D9
+MOSI = D10
+SCLK = D11
+SCK = D11
"""PyBoard pin names"""
-from adafruit_blinka.microcontroller.stm32 import pin
+from adafruit_blinka.microcontroller.stm32.stm32f405 import pin
X1 = pin.A0
X2 = pin.A1
--- /dev/null
+"""Boards definition from STM32"""
--- /dev/null
+"""Pin definitions for the STM32MP157C Development Kit 2."""
+
+from adafruit_blinka.microcontroller.stm32.stm32mp157 import pin
+
+D2 = pin.PA12
+D3 = pin.PA11
+D4 = pin.PA8
+D5 = pin.PG2
+D6 = pin.PH11
+D7 = pin.PF3
+D8 = pin.PF6
+D9 = pin.PF8
+D10 = pin.PF9
+D11 = pin.PF7
+D12 = pin.PD13
+D13 = pin.PC7
+D14 = pin.PB10
+D15 = pin.PB12
+D16 = pin.PB13
+D17 = pin.PG8
+D18 = pin.PI5
+D19 = pin.PI7
+D20 = pin.PI6
+D21 = pin.PF11
+D22 = pin.PG15
+D23 = pin.PF1
+D24 = pin.PF0
+D25 = pin.PF4
+D26 = pin.PF5
+D27 = pin.PD7
+
+SDA = D2
+SCL = D3
+
+SDA1 = pin.PF15
+SCL1 = pin.PD12
+
+SCLK = D11
+MOSI = D10
+MISO = D9
+
+CE0 = D8
+CE1 = D7
+
+CS = CE0
+SCK = SCLK
+
+UART_TX = D14
+UART_RX = D15
--- /dev/null
+"""Pin definitions for Udoo x86 Ultra
+(should work for Ultra and Ultra II)
+
+There are 2 naming systems. A Digital Pin system which includes
+the arduino chip (Leonardo or 101). The Braswell #s start at 16 and
+is documented in the diagram and text for linux version later than 4.15 in:
+https://www.udoo.org/docs-x86II/Introduction/Introduction.html
+The other is based on the hardware manual:
+https://udoo.org/download/files/UDOO_X86/Doc/UDOO_X86II_MANUAL.pdf
+
+This will use the D system based on the diagram in the user guide
+
+i2c use i2c(board.I2C0_SCL, board_I2C0_SDA) or i2c(board.I2C1_SCL, board_I2C1_SDA)
+for the i2c(board.SCL, board.SCL) in the examples
+
+UART use pyserial not busio
+"""
+
+from adafruit_blinka.microcontroller.pentium.n3710 import pin
+
+# Connector CN15
+D16 = pin.UART1_RTS
+D17 = pin.UART1_CTS
+D18 = pin.UART1_TXD
+D19 = pin.UART1_RXD
+D20 = pin.UART2_RTS
+D21 = pin.UART2_CTS
+D22 = pin.UART2_TXD
+D23 = pin.UART2_RXD
+
+# Connector CN13 LPC interface
+D24 = pin.GPIO_275
+D25 = pin.GPIO_280
+D26 = pin.GPIO_273
+D27 = pin.GPIO_278
+D28 = pin.GPIO_276
+D29 = pin.GPIO_279
+D30 = pin.GPIO_307
+
+# Connector CN14
+D34 = pin.I2C0_SCL
+D35 = pin.I2C0_SDA
+
+D36 = pin.GPIO_492
+D37 = pin.GPIO_490
+
+D38 = pin.I2C1_SCL
+D39 = pin.I2C1_SDA
+
+# Connector CN12 SDIO SD/MMC interfaces
+D40 = pin.GPIO_358
+D41 = pin.GPIO_243
+D42 = pin.GPIO_249
+D43 = pin.GPIO_246
+D44 = pin.GPIO_253
+D45 = pin.GPIO_250
+D46 = pin.GPIO_247
+
+# aliases
+UART1_RX = D19
+UART1_TX = D18
+
+UART2_RX = D23
+UART2_TX = D22
+
+I2C0_SCL = D34 # labeled on diagram as I2C1, hardware manual port 0
+I2C0_SDA = D35 # i2cdetect-l lists it as i2c-0
+
+I2C1_SCL = D38 # Labeled on diagram as I2C2, hardware manual port 5
+I2C1_SCL = D39 # i2cdetect lists it as i2c-1
try:
from microcontroller.pin import pwmOuts
except ImportError:
- raise RuntimeError("No PWM outputs defined for this board")
+ raise RuntimeError("No PWM outputs defined for this board") from ImportError
# pylint: disable=unnecessary-pass
class PWMError(IOError):
) as f_export:
f_export.write("%d\n" % self._pwmpin)
except IOError as e:
- raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror)
+ raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror) from IOError
# Look up the period, for fast duty cycle updates
self._period = self._get_period()
) as f_unexport:
f_unexport.write("%d\n" % self._pwmpin)
except IOError as e:
- raise PWMError(e.errno, "Unexporting PWM pin: " + e.strerror)
+ raise PWMError(
+ e.errno, "Unexporting PWM pin: " + e.strerror
+ ) from IOError
except Exception as e:
# due to a race condition for which I have not yet been
# able to find the root cause, deinit() often fails
try:
period_ns = int(period_ns)
except ValueError:
- raise PWMError(None, 'Unknown period value: "%s"' % period_ns)
+ raise PWMError(
+ None, 'Unknown period value: "%s"' % period_ns
+ ) from ValueError
# Convert period from nanoseconds to seconds
period = period_ns / 1e9
try:
duty_cycle_ns = int(duty_cycle_ns)
except ValueError:
- raise PWMError(None, 'Unknown duty cycle value: "%s"' % duty_cycle_ns)
+ raise PWMError(
+ None, 'Unknown duty cycle value: "%s"' % duty_cycle_ns
+ ) from ValueError
# Convert duty cycle from nanoseconds to seconds
duty_cycle = duty_cycle_ns / 1e9
"""
import re
-from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
import gpiod
+from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
chip0 = gpiod.Chip("0")
chip1 = gpiod.Chip("1")
print("Message Queue Key: ", self._mq.key)
queues.append(self._mq)
except sysv_ipc.ExistentialError:
- raise RuntimeError("Message queue creation failed")
+ raise RuntimeError(
+ "Message queue creation failed"
+ ) from sysv_ipc.ExistentialError
dir_path = os.path.dirname(os.path.realpath(__file__))
cmd = [
# wait for it to start up
if DEBUG:
print("Waiting for startup success message from subprocess")
- message = self._wait_receive_msg()
+ message = self._wait_receive_msg(timeout=0.25)
if message[0] != b"!":
raise RuntimeError("Could not establish message queue with subprocess")
self._paused = False
# pylint: disable=redefined-builtin
- def _wait_receive_msg(self, timeout=0.25, type=2):
+ def _wait_receive_msg(self, timeout=0, type=2):
"""Internal helper that will wait for new messages of a given type,
and throw an exception on timeout"""
- stamp = time.monotonic()
- while (time.monotonic() - stamp) < timeout:
- try:
- message = self._mq.receive(block=False, type=type)
- return message
- except sysv_ipc.BusyError:
- time.sleep(0.001) # wait a bit then retry!
- # uh-oh timed out
- raise RuntimeError(
- "Timed out waiting for PulseIn message. Make sure libgpiod is installed."
- )
+ if timeout > 0:
+ stamp = time.monotonic()
+ while (time.monotonic() - stamp) < timeout:
+ try:
+ message = self._mq.receive(block=False, type=type)
+ return message
+ except sysv_ipc.BusyError:
+ time.sleep(0.001) # wait a bit then retry!
+ # uh-oh timed out
+ raise RuntimeError(
+ "Timed out waiting for PulseIn message. Make sure libgpiod is installed."
+ )
+ message = self._mq.receive(block=True, type=type)
+ return message
# pylint: enable=redefined-builtin
chunk_end = chunk_start + self._spi.PAYLOAD_MAX_LENGTH
self._port.write(buf[chunk_start:chunk_end])
if rest:
- self._port.write(buf[-1 * rest :])
+ rest_start = start + chunks * self._spi.PAYLOAD_MAX_LENGTH
+ self._port.write(buf[rest_start:end])
# pylint: disable=unused-argument
def readinto(self, buf, start=0, end=None, write_value=0):
except FileNotFoundError:
raise RuntimeError(
"I2C Bus #%d not found, check if enabled in config!" % bus_num
- )
+ ) from RuntimeError
# pylint: enable=unused-argument
raise ImportError(
"libgpiod Python bindings not found, please install and try again! See "
"https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh"
- )
+ ) from ImportError
class Pin:
raise ImportError(
"Periphery Python bindings not found, please install and try again! "
"Try running 'pip3 install python-periphery'"
- )
+ ) from ImportError
class Pin:
try:
from microcontroller.pin import analogIns
except ImportError:
- raise RuntimeError("No Analog Inputs defined for this board")
+ raise RuntimeError("No Analog Inputs defined for this board") from ImportError
class AnalogIn(ContextManaged):
try:
from microcontroller.pin import analogOuts
except ImportError:
- raise RuntimeError("No Analog Outputs defined for this board")
+ raise RuntimeError("No Analog Outputs defined for this board") from ImportError
class AnalogOut(ContextManaged):
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)
+ raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror) from IOError
# Loop until GPIO is exported
exported = False
):
raise GPIOError(
e.errno, "Setting GPIO direction: " + e.strerror
- )
+ ) from IOError
time.sleep(self.GPIO_OPEN_DELAY)
else:
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)
+ raise GPIOError(
+ e.errno, "Setting GPIO direction: " + e.strerror
+ ) from IOError
# 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)
+ raise GPIOError(e.errno, "Opening GPIO: " + e.strerror) from OSError
self._path = gpio_path
try:
os.close(self._fd)
except OSError as e:
- raise GPIOError(e.errno, "Closing GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Closing GPIO: " + e.strerror) from OSError
self._fd = None
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)
+ raise GPIOError(e.errno, "Unexporting GPIO: " + e.strerror) from OSError
def _read(self):
# Read value
try:
buf = os.read(self._fd, 2)
except OSError as e:
- raise GPIOError(e.errno, "Reading GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Reading GPIO: " + e.strerror) from OSError
# Rewind
try:
os.lseek(self._fd, 0, os.SEEK_SET)
except OSError as e:
- raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror) from OSError
if buf[0] == b"0"[0]:
return False
else:
os.write(self._fd, b"0\n")
except OSError as e:
- raise GPIOError(e.errno, "Writing GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Writing GPIO: " + e.strerror) from OSError
# Rewind
try:
os.lseek(self._fd, 0, os.SEEK_SET)
except OSError as e:
- raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror) from OSError
@property
def chip_name(self):
label = f_label.read()
except (GPIOError, IOError) as e:
if isinstance(e, IOError):
- raise GPIOError(e.errno, "Reading gpiochip label: " + e.strerror)
+ raise GPIOError(
+ e.errno, "Reading gpiochip label: " + e.strerror
+ ) from IOError
- raise GPIOError(None, "Reading gpiochip label: " + e.strerror)
+ raise GPIOError(
+ None, "Reading gpiochip label: " + e.strerror
+ ) from GPIOError
return label.strip()
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)
+ raise GPIOError(
+ e.errno, "Getting GPIO direction: " + e.strerror
+ ) from IOError
return direction.strip()
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)
+ raise GPIOError(
+ e.errno, "Setting GPIO direction: " + e.strerror
+ ) from IOError
direction = property(_get_direction, _set_direction)
try:
from microcontroller.pin import pwmOuts
except ImportError:
- raise RuntimeError("No PWM outputs defined for this board")
+ raise RuntimeError("No PWM outputs defined for this board") from ImportError
# pylint: disable=unnecessary-pass
with open(os.path.join(channel_path, self._export_path), "w") as f_export:
f_export.write("%d\n" % self._pwmpin)
except IOError as e:
- raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror)
+ raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror) from IOError
# self._set_enabled(False) # This line causes a write error when trying to enable
) as f_unexport:
f_unexport.write("%d\n" % self._pwmpin)
except IOError as e:
- raise PWMError(e.errno, "Unexporting PWM pin: " + e.strerror)
+ raise PWMError(
+ e.errno, "Unexporting PWM pin: " + e.strerror
+ ) from IOError
self._channel = None
self._pwmpin = None
try:
period_ns = int(period_ns)
except ValueError:
- raise PWMError(None, 'Unknown period value: "%s"' % period_ns)
+ raise PWMError(
+ None, 'Unknown period value: "%s"' % period_ns
+ ) from ValueError
# Convert period from nanoseconds to seconds
period = period_ns / 1e9
try:
duty_cycle_ns = int(duty_cycle_ns)
except ValueError:
- raise PWMError(None, 'Unknown duty cycle value: "%s"' % duty_cycle_ns)
+ raise PWMError(
+ None, 'Unknown duty cycle value: "%s"' % duty_cycle_ns
+ ) from ValueError
# Convert duty cycle from nanoseconds to seconds
duty_cycle = duty_cycle_ns / 1e9
# Here if you need it
MCP2221_HID_DELAY = float(os.environ.get("BLINKA_MCP2221_HID_DELAY", 0))
-# Use to set delay between reset and device reopen
+# Use to set delay between reset and device reopen. if negative, don't reset at all
MCP2221_RESET_DELAY = float(os.environ.get("BLINKA_MCP2221_RESET_DELAY", 0.5))
# from the C driver
# http://ww1.microchip.com/downloads/en/DeviceDoc/mcp2221_0_1.tar.gz
# others (???) determined during driver developement
-# pylint: disable=bad-whitespace
RESP_ERR_NOERR = 0x00
RESP_ADDR_NACK = 0x25
RESP_READ_ERR = 0x7F
MCP2221_RETRY_MAX = 50
MCP2221_MAX_I2C_DATA_LEN = 60
MASK_ADDR_NACK = 0x40
-# pylint: enable=bad-whitespace
class MCP2221:
def __init__(self):
self._hid = hid.device()
self._hid.open(MCP2221.VID, MCP2221.PID)
- self._reset()
+ if MCP2221_RESET_DELAY >= 0:
+ self._reset()
self._gp_config = [0x07] * 4 # "don't care" initial value
for pin in range(4):
self.gp_set_mode(pin, self.GP_GPIO) # set to GPIO mode
continue
if resp[2] in (RESP_READ_COMPL, RESP_READ_PARTIAL):
break
+ else:
+ raise RuntimeError("I2C read error: max retries reached.")
# move data into buffer
chunk = min(end - start, 60)
try:
from microcontroller.pin import pwmOuts
except ImportError:
- raise RuntimeError("No PWM outputs defined for this board")
+ raise RuntimeError("No PWM outputs defined for this board") from ImportError
from microcontroller.pin import Pin
from greatfet.interfaces.adc import ADC
gf = GreatFET()
-except:
+except ModuleNotFoundError:
raise RuntimeError(
"Unable to create GreatFET object. Make sure library is "
"installed and the device is connected."
- )
+ ) from ModuleNotFoundError
class Pin:
try:
from microcontroller.pin import pwmOuts
except ImportError:
- raise RuntimeError("No PWM outputs defined for this board")
+ raise RuntimeError("No PWM outputs defined for this board") from ImportError
# pylint: disable=unnecessary-pass
class PWMError(IOError):
--- /dev/null
+"""Pentium N3710 (Braswell core SOC) pin names
+ i2c and GPIO can be accessed through Blinka.
+ For i2c use IC20_SCL, IC20-SDA and IC21-SCL, IC21-SDA in the i2c(<sdl, sda>) calls.
+ For UART use pyserial"""
+from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
+
+# gpiochip3
+GPIO_243 = Pin((3, 15))
+GPIO_246 = Pin((3, 18))
+GPIO_247 = Pin((3, 19))
+GPIO_249 = Pin((3, 21))
+GPIO_250 = Pin((3, 22))
+GPIO_253 = Pin((3, 25))
+GPIO_273 = Pin((3, 45))
+GPIO_275 = Pin((3, 47))
+GPIO_276 = Pin((3, 48))
+GPIO_278 = Pin((3, 50))
+GPIO_279 = Pin((3, 51))
+GPIO_280 = Pin((3, 52))
+GPIO_307 = Pin((3, 79))
+
+SDIO_D3 = SDMMC2_D3 = GPIO_243
+SDIO_DI = SDMMC2_D1 = GPIO_246
+SDIO_CLK = SDMMC2_CLK = GPIO_247
+SDIO_D2 = SDMMC2_D2 = GPIO_249
+SDIO_CMD = SDMMC2_CMD = GPIO_250
+SDIO_D0 = SDMMC2_D0 = GPIO_253
+
+MF_LPC_AD2 = GPIO_273
+MF_LPC_AD0 = GPIO_275
+LPC_FRAMEB = GPIO_276
+MF_LPC_AD3 = GPIO_278
+MF_LPC_CLKOUT0 = GPIO_279
+MF_LPC_AD1 = GPIO_280
+ILB_SERIRQ = GPIO_307
+
+# ggpiochip1
+GPIO_358 = Pin((1, 17))
+GPIO_SUS3 = SDIO_WAKE = GPIO_358
+
+
+# gpiochip0
+GPIO_490 = Pin((0, 76))
+GPIO_492 = Pin((0, 78))
+
+SATA_GP1 = TS_INT = GPIO_490
+SATA_GP2 = TS_RST = GPIO_492
+
+
+# not general gpio on chip 0
+# use pyserial not blinka. These are only included for completeness
+
+UART1_RXD = Pin((0, 16))
+UART1_TXD = Pin((0, 20))
+UART1_RTS = Pin((0, 15))
+UART1_CTS = Pin((0, 18))
+
+UART2_RXD = Pin((0, 17))
+UART2_TXD = Pin((0, 21))
+UART2_RTS = Pin((0, 19))
+UART2_CTS = Pin((0, 22))
+
+GPIO_429 = UART1_RTS
+GPIO_430 = UART1_RXD
+GPIO_431 = UART2_RXD
+GPIO_432 = UART1_CTS
+GPIO_434 = UART1_TXD
+GPIO_435 = UART2_TXD
+GPIO_436 = UART2_CTS
+
+# i2c use these addresses when accessing i2c from Blinka. You can also access
+# the i2c useing smbus
+I2C0_SDA = Pin((0, 61)) # IC21 on diagram, port 0 in hardware manual
+I2C0_SCL = Pin((0, 65))
+
+I2C1_SDA = TS_I2C_SDA = Pin((0, 45)) # I2C2 on diagram, port 5 in hardware manual
+I2C1_SCL = TS_I2C_SCL = Pin((0, 48))
+
+
+GPIO_469 = I2C1_SDA # I2C2 on diagram
+GPIO_472 = I2C1_SCL
+GPIO_475 = I2C0_SDA # I2C1 on diagram
+GPIO_479 = I2C0_SCL
+
+# ordered as i2cId, sclId, sdaId
+i2cPorts = ((0, I2C0_SCL, I2C0_SDA), (1, I2C1_SCL, I2C1_SDA))
-"""STM32 pins"""
+"""STM32F405 pins"""
from microcontroller import Pin
--- /dev/null
+"""STM32MP157 pins"""
+from adafruit_blinka.microcontroller.generic_linux.periphery_pin import Pin
+
+PA0 = Pin((0, 0))
+PA1 = Pin((0, 1))
+PA2 = Pin((0, 2))
+PA3 = Pin((0, 3))
+PA4 = Pin((0, 4))
+PA5 = Pin((0, 5))
+PA6 = Pin((0, 6))
+PA7 = Pin((0, 7))
+PA8 = Pin((0, 8))
+PA9 = Pin((0, 9))
+PA11 = Pin((0, 11))
+PA12 = Pin((0, 12))
+PA13 = Pin((0, 13))
+PA14 = Pin((0, 14))
+PA15 = Pin((0, 15))
+PB0 = Pin((1, 0))
+PB1 = Pin((1, 1))
+PB2 = Pin((1, 2))
+PB3 = Pin((1, 3))
+PB4 = Pin((1, 4))
+PB5 = Pin((1, 5))
+PB6 = Pin((1, 6))
+PB7 = Pin((1, 7))
+PB8 = Pin((1, 8))
+PB9 = Pin((1, 9))
+PB10 = Pin((1, 10))
+PB11 = Pin((1, 11))
+PB12 = Pin((1, 12))
+PB13 = Pin((1, 13))
+PB14 = Pin((1, 14))
+PB15 = Pin((1, 15))
+PC0 = Pin((2, 0))
+PC1 = Pin((2, 1))
+PC2 = Pin((2, 2))
+PC3 = Pin((2, 3))
+PC4 = Pin((2, 4))
+PC5 = Pin((2, 5))
+PC6 = Pin((2, 6))
+PC7 = Pin((2, 7))
+PC8 = Pin((2, 8))
+PC9 = Pin((2, 9))
+PC10 = Pin((2, 10))
+PC11 = Pin((2, 11))
+PC12 = Pin((2, 12))
+PC13 = Pin((2, 13))
+PD0 = Pin((3, 0))
+PD1 = Pin((3, 1))
+PD2 = Pin((3, 2))
+PD3 = Pin((3, 3))
+PD4 = Pin((3, 4))
+PD5 = Pin((3, 5))
+PD6 = Pin((3, 6))
+PD7 = Pin((3, 7))
+PD8 = Pin((3, 8))
+PD9 = Pin((3, 9))
+PD10 = Pin((3, 10))
+PD11 = Pin((3, 11))
+PD12 = Pin((3, 12))
+PD13 = Pin((3, 13))
+PD14 = Pin((3, 14))
+PD15 = Pin((3, 15))
+PE0 = Pin((4, 0))
+PE1 = Pin((4, 1))
+PE2 = Pin((4, 2))
+PE3 = Pin((4, 3))
+PE4 = Pin((4, 4))
+PE5 = Pin((4, 5))
+PE6 = Pin((4, 6))
+PE7 = Pin((4, 7))
+PE8 = Pin((4, 8))
+PE9 = Pin((4, 9))
+PE10 = Pin((4, 10))
+PE11 = Pin((4, 11))
+PE12 = Pin((4, 12))
+PE13 = Pin((4, 13))
+PE14 = Pin((4, 14))
+PE15 = Pin((4, 15))
+PF0 = Pin((5, 0))
+PF1 = Pin((5, 1))
+PF2 = Pin((5, 2))
+PF3 = Pin((5, 3))
+PF4 = Pin((5, 4))
+PF5 = Pin((5, 5))
+PF6 = Pin((5, 6))
+PF7 = Pin((5, 7))
+PF8 = Pin((5, 8))
+PF9 = Pin((5, 9))
+PF10 = Pin((5, 10))
+PF11 = Pin((5, 11))
+PF12 = Pin((5, 12))
+PF13 = Pin((5, 13))
+PF14 = Pin((5, 14))
+PF15 = Pin((5, 15))
+PG1 = Pin((6, 1))
+PG2 = Pin((6, 2))
+PG3 = Pin((6, 3))
+PG4 = Pin((6, 4))
+PG5 = Pin((6, 5))
+PG6 = Pin((6, 6))
+PG7 = Pin((6, 7))
+PG8 = Pin((6, 8))
+PG9 = Pin((6, 9))
+PG10 = Pin((6, 10))
+PG11 = Pin((6, 11))
+PG12 = Pin((6, 12))
+PG13 = Pin((6, 13))
+PG14 = Pin((6, 14))
+PG15 = Pin((6, 15))
+PH2 = Pin((7, 2))
+PH3 = Pin((7, 3))
+PH4 = Pin((7, 4))
+PH5 = Pin((7, 5))
+PH6 = Pin((7, 6))
+PH7 = Pin((7, 7))
+PH8 = Pin((7, 8))
+PH9 = Pin((7, 9))
+PH10 = Pin((7, 10))
+PH11 = Pin((7, 11))
+PH12 = Pin((7, 12))
+PH13 = Pin((7, 13))
+PH14 = Pin((7, 14))
+PH15 = Pin((7, 15))
+PI0 = Pin((8, 0))
+PI1 = Pin((8, 1))
+PI2 = Pin((8, 2))
+PI3 = Pin((8, 3))
+PI4 = Pin((8, 4))
+PI5 = Pin((8, 5))
+PI6 = Pin((8, 6))
+PI7 = Pin((8, 7))
+PI8 = Pin((8, 8))
+PI9 = Pin((8, 9))
+PI10 = Pin((8, 10))
+PI11 = Pin((8, 11))
+PZ0 = Pin((9, 0))
+PZ1 = Pin((9, 1))
+PZ2 = Pin((9, 2))
+PZ3 = Pin((9, 3))
+PZ4 = Pin((9, 4))
+PZ5 = Pin((9, 5))
+PZ6 = Pin((9, 6))
+PZ7 = Pin((9, 7))
+
+# ordered as uartId, txId, rxId
+UART_PORTS = ((3, PB10, PB12),)
+
+# ordered as i2cId, sclId, sdaId
+I2C_PORTS = (
+ (1, PD12, PF15),
+ (5, PA11, PA12),
+)
T07 = Pin("DAP5_DIN")
T06 = Pin("DAP5_DOUT")
+# Clara AGX Xavier only
+P04 = Pin("SOC_GPIO04")
+
# Shared
N01 = Pin("SOC_GPIO54")
R00 = Pin("SOC_GPIO44")
elif detector.board.any_raspberry_pi_cm:
from adafruit_blinka.board.raspberrypi.raspi_cm import *
-elif detector.board.RASPBERRY_PI_A or detector.board.RASPBERRY_PI_B_REV1:
+elif detector.board.RASPBERRY_PI_B_REV1:
from adafruit_blinka.board.raspberrypi.raspi_1b_rev1 import *
-elif detector.board.RASPBERRY_PI_B_REV2:
+elif detector.board.RASPBERRY_PI_A or detector.board.RASPBERRY_PI_B_REV2:
from adafruit_blinka.board.raspberrypi.raspi_1b_rev2 import *
elif board_id == ap_board.BEAGLEBONE_BLACK:
elif board_id == ap_board.ORANGE_PI_2:
from adafruit_blinka.board.orangepi.orangepipc import *
+elif board_id == ap_board.BANANA_PI_M2_ZERO:
+ from adafruit_blinka.board.bananapi.bpim2zero import *
+
elif board_id == ap_board.GIANT_BOARD:
from adafruit_blinka.board.giantboard import *
elif board_id == ap_board.JETSON_NX:
from adafruit_blinka.board.nvidia.jetson_nx import *
+elif board_id == ap_board.CLARA_AGX_XAVIER:
+ from adafruit_blinka.board.nvidia.clara_agx_xavier import *
+
elif board_id == ap_board.CORAL_EDGE_TPU_DEV:
from adafruit_blinka.board.coral_edge_tpu import *
elif board_id == ap_board.ROCK_PI_S:
from adafruit_blinka.board.radxa.rockpis import *
+elif board_id == ap_board.UDOO_X86:
+ from adafruit_blinka.board.udoo_x86ultra import *
+
+elif board_id == ap_board.STM32MP157C_DK2:
+ from adafruit_blinka.board.stm32.stm32mp157c_dk2 import *
+
elif "sphinx" in sys.modules:
pass
in_end=None,
stop=False
):
- """"Write to a device at specified address from a buffer then read
+ """ "Write to a device at specified address from a buffer then read
from a device at specified address into a buffer
"""
return self._i2c.writeto_then_readfrom(
except AttributeError:
raise NotImplementedError(
"Frequency attribute not implemented for this platform"
- )
+ ) from AttributeError
def write(self, buf, start=0, end=None):
"""Write to the SPI device"""
def write(self, buf):
"""Write to the UART from a buffer"""
return self._uart.write(buf)
+
+
+class OneWire:
+ """
+ Stub class for OneWire, which is currently not implemented
+ """
+
+ def __init__(self, pin):
+ raise NotImplementedError("OneWire has not been implemented")
+
+ def deinit(self):
+ """
+ Deinitialize the OneWire bus and release any hardware resources for reuse.
+ """
+ raise NotImplementedError("OneWire has not been implemented")
+
+ def reset(self):
+ """
+ Reset the OneWire bus and read presence
+ """
+ raise NotImplementedError("OneWire has not been implemented")
+
+ def read_bit(self):
+ """
+ Read in a bit
+ """
+ raise NotImplementedError("OneWire has not been implemented")
+
+ def write_bit(self, value):
+ """
+ Write out a bit based on value.
+ """
+ raise NotImplementedError("OneWire has not been implemented")
from adafruit_blinka.microcontroller.nova.pin import Pin
elif detector.board.greatfet_one:
from adafruit_blinka.microcontroller.nxp_lpc4330.pin import Pin
-elif detector.chip.STM32:
+elif detector.chip.STM32F405:
from machine import Pin
elif detector.board.microchip_mcp2221:
from adafruit_blinka.microcontroller.mcp2221.pin import Pin
+elif detector.chip.PENTIUM_N3710:
+ from adafruit_blinka.microcontroller.pentium.n3710.pin import Pin
+elif detector.chip.STM32MP157:
+ from adafruit_blinka.microcontroller.stm32.stm32mp157.pin import Pin
+
from adafruit_blinka import Enum, ContextManaged
if chip_id == ap_chip.ESP8266:
from adafruit_blinka.microcontroller.esp8266 import *
-elif chip_id == ap_chip.STM32:
- from adafruit_blinka.microcontroller.stm32 import *
+elif chip_id == ap_chip.STM32F405:
+ from adafruit_blinka.microcontroller.stm32.stm32f405 import *
elif chip_id == ap_chip.BCM2XXX:
from adafruit_blinka.microcontroller.bcm283x import *
elif chip_id == ap_chip.AM33XX:
from adafruit_blinka.microcontroller.atheros.ar9331.pin import *
elif chip_id == ap_chip.MIPS24KEC:
from adafruit_blinka.microcontroller.mips24kec.pin import *
+elif chip_id == ap_chip.PENTIUM_N3710:
+ from adafruit_blinka.microcontroller.pentium.n3710.pin import *
+elif chip_id == ap_chip.STM32MP157:
+ from adafruit_blinka.microcontroller.stm32.stm32mp157.pin import *
else:
raise NotImplementedError("Microcontroller not supported:", chip_id)
if chip_id == ap_chip.ESP8266:
from adafruit_blinka.microcontroller.esp8266.pin import *
-elif chip_id == ap_chip.STM32:
- from adafruit_blinka.microcontroller.stm32.pin import *
+elif chip_id == ap_chip.STM32F405:
+ from adafruit_blinka.microcontroller.stm32.stm32f405.pin import *
elif chip_id == ap_chip.BCM2XXX:
from adafruit_blinka.microcontroller.bcm283x.pin import *
elif chip_id == ap_chip.AM33XX:
from adafruit_blinka.microcontroller.atheros.ar9331.pin import *
elif chip_id == ap_chip.MIPS24KEC:
from adafruit_blinka.microcontroller.mips24kec.pin import *
+elif chip_id == ap_chip.PENTIUM_N3710:
+ from adafruit_blinka.microcontroller.pentium.n3710.pin import *
+elif chip_id == ap_chip.STM32MP157:
+ from adafruit_blinka.microcontroller.stm32.stm32mp157.pin import *
else:
raise NotImplementedError("Microcontroller not supported: ", chip_id)
class TestEnum(unittest.TestCase):
"""
- Verifies the repl() and str() behaviour of an example Enum
- Enums represent configuration values such as digitalio.Direction, digitalio.Pull etc.
+ Verifies the repl() and str() behaviour of an example Enum
+ Enums represent configuration values such as digitalio.Direction, digitalio.Pull etc.
"""
def setUp(self):
def test_iteritems(self):
"""A subtype of Enum can list all attributes of its own type"""
items = list(self.Cls.iteritems())
- self.assertEqual(items, [("one", self.Cls.one), ("two", self.Cls.two),])
+ self.assertEqual(
+ items,
+ [
+ ("one", self.Cls.one),
+ ("two", self.Cls.two),
+ ],
+ )
def test_repr(self):
"""A repr() call on an Enum gives its fully-qualified name"""