Skip to content

Commit

Permalink
Merge pull request #1 from adafruit/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
twa127 authored Dec 19, 2020
2 parents 2945373 + 72d4f20 commit 1a7e281
Show file tree
Hide file tree
Showing 22 changed files with 384 additions and 55 deletions.
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Introduction
:alt: Documentation Status

.. image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://discord.gg/nBQh6qu
:target: https://adafru.it/discord
:alt: Discord

.. image:: https://travis-ci.com/adafruit/Adafruit_Blinka.svg?branch=master
Expand All @@ -26,8 +26,10 @@ on hosts running micropython. Working code exists to emulate the CircuitPython p
* **digitalio** - digital input/output pins, using pin identities from board+microcontroller packages
* **bitbangio** - software-driven interfaces for I2C, SPI
* **busio** - hardware-driven interfaces for I2C, SPI, UART
* **time** * - substitute functions monkey-patched to time module
* **pulseio** - contains classes that provide access to basic pulse IO (PWM)

For details, see the `Blinka API reference
<https://circuitpython.readthedocs.io/projects/blinka/en/latest/index.html>`_.

Dependencies
=============
Expand Down Expand Up @@ -97,7 +99,7 @@ install dependencies (feel free to reuse the virtual environment from above):
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
pip install Sphinx sphinx-rtd-theme Adafruit-PlatformDetect
Now, once you have the virtual environment activated:

Expand Down
11 changes: 11 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@

.. automodule:: digitalio
:members:

.. automodule:: analogio
:members:

.. automodule:: pulseio
:members:

.. automodule:: neopixel_write
:members:


9 changes: 8 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["machine", "Adafruit_GPIO"]
autodoc_mock_imports = [
"machine",
"Adafruit_GPIO",
"RPi",
"RPi.GPIO",
"hid",
"sysv_ipc",
]

intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),
Expand Down
24 changes: 24 additions & 0 deletions src/adafruit_blinka/board/coral_dev_board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Pin definitions for the Coral Dev Board."""

from adafruit_blinka.microcontroller.nxp_imx8m import pin

# Board name = RPI name [= alias] = pin name
I2C2_SDA = D2 = SDA = pin.I2C2_SDA
I2C2_SCL = D3 = SCL = pin.I2C2_SCL

PWM1 = D12 = pin.PWM1
PWM2 = D13 = pin.PWM2
PWM3 = D22 = pin.PWM3

GPIO_P13 = D27 = pin.GPIO6
GPIO_P16 = D23 = pin.GPIO73
GPIO_P18 = D24 = pin.GPIO138
GPIO_P29 = D5 = pin.GPIO7
GPIO_P31 = D6 = pin.GPIO8
GPIO_P36 = D16 = pin.GPIO141
GPIO_P37 = D26 = pin.GPIO77

ECSPI1_MISO = D9 = MISO = pin.ECSPI1_MISO
ECSPI1_MOSI = D10 = MOSI = pin.ECSPI1_MOSI
ECSPI1_SCLK = D11 = SCLK = SCK = pin.ECSPI1_SCLK
ECSPI1_SS0 = D8 = SS0 = pin.ECSPI1_SS0
38 changes: 38 additions & 0 deletions src/adafruit_blinka/board/coral_dev_board_mini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Pin definitions for the Coral Dev Board Mini."""

from adafruit_blinka.microcontroller.mt8167 import pin

# Board name = RPI name [= alias] = pin name
GPIO22 = D4 = pin.GPIO22 # Pin 7
GPIO9 = D17 = pin.GPIO9 # Pin 11
GPIO36 = D18 = pin.GPIO36 # Pin 12
GPIO10 = D27 = pin.GPIO10 # Pin 13
GPIO0 = D23 = pin.GPIO0 # Pin 16
GPIO1 = D24 = pin.GPIO1 # Pin 18
GPIO7 = D25 = pin.GPIO7 # Pin 22
GPIO8 = D7 = pin.GPIO8 # Pin 26
GPIO37 = D19 = pin.GPIO37 # Pin 35
GPIO13 = D16 = pin.GPIO13 # Pin 36
GPIO45 = D26 = pin.GPIO45 # Pin 37
GPIO38 = D20 = pin.GPIO38 # Pin 38
GPIO39 = D21 = pin.GPIO39 # Pin 40

I2C1_SDA = D2 = SDA1 = pin.I2C1_SDA # Pin 3
I2C1_SCL = D3 = SCL1 = pin.I2C1_SCL # Pin 5
I2C2_SDA = D0 = SDA2 = pin.I2C2_SDA # Pin 27
I2C2_SCL = D1 = SCL2 = pin.I2C2_SCL # Pin 28

PWM_A = D12 = pin.PWM_A # Pin 32
PWM_B = D13 = pin.PWM_B # Pin 33
PWM_C = D22 = pin.PWM_C # Pin 15

SPI_MO = D10 = MOSI = pin.SPI_MO # Pin 19
SPI_MI = D9 = MISO = pin.SPI_MI # Pin 21
SPI_CLK = D11 = SCLK = pin.SPI_CLK # Pin 23
SPI_CSB = D8 = CS0 = pin.SPI_CSB # Pin 24

# UART currently not supported
GPIO63 = D14 = pin.GPIO63 # UART0_TX, Pin 8
GPIO62 = D15 = pin.GPIO62 # UART0_RX, Pin 10
GPIO65 = D5 = pin.GPIO65 # UART1_TX, Pin 29
GPIO64 = D6 = pin.GPIO64 # UART1_RX, Pin 31
24 changes: 0 additions & 24 deletions src/adafruit_blinka/board/coral_edge_tpu.py

This file was deleted.

41 changes: 41 additions & 0 deletions src/adafruit_blinka/board/pineH64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Pin definitions for the PineH64."""

from adafruit_blinka.microcontroller.allwinner.h6 import pin

D2 = pin.PD26
D3 = pin.PD25
D4 = pin.PL8
D5 = pin.PH2
D6 = pin.PG14
D7 = pin.PC16
D8 = pin.PH3
D9 = pin.PH6
D10 = pin.PH5
D11 = pin.PH4
D12 = pin.PD22
D13 = pin.PD21
D14 = pin.PD19
D15 = pin.PD20
D16 = pin.PD24
D17 = pin.PL9
D18 = pin.PG11
D19 = pin.PG10
D21 = pin.PG12
D22 = pin.PG13
D23 = pin.PD16
D24 = pin.PD17
D25 = pin.PD18
D26 = pin.PD23
D27 = pin.PD14

SDA = D2
SCL = D3

SCLK = D11
MOSI = D10
MISO = D9
CS = D8
SCK = SCLK

UART_TX = D14
UART_RX = D15
51 changes: 51 additions & 0 deletions src/adafruit_blinka/board/soPine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Pin definitions for the SoPine."""

from adafruit_blinka.microcontroller.allwinner.a64 import pin

D2 = pin.PH3
D3 = pin.PH2
D4 = pin.PL10
D5 = pin.PH5
D6 = pin.PH6
D7 = pin.PH7
D8 = pin.PC3
D9 = pin.PC1
D10 = pin.PC0
D11 = pin.PC2
D12 = pin.PC4
D13 = pin.PC5
D14 = pin.PB0
D15 = pin.PB1
D16 = pin.PC6
D17 = pin.PC7
D18 = pin.PC8
D19 = pin.PC9
D20 = pin.PC10
D21 = pin.PC11
D22 = pin.PC12
D23 = pin.PC13
D24 = pin.PC14
D25 = pin.PC15
D26 = pin.PC16
D27 = pin.PH9

SDA = D2
SCL = D3

SCL2 = pin.PL8
SDA2 = pin.PL9

SCLK = D11
MOSI = D10
MISO = D9
CS = D8
SCK = SCLK

UART_TX = D14
UART_RX = D15

UART3_TX = pin.PD0
UART3_RX = pin.PD1

UART4_TX = pin.PD2
UART4_RX = pin.PD3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Definition for the AllWinner H6 chip"""
47 changes: 47 additions & 0 deletions src/adafruit_blinka/microcontroller/allwinner/h6/pin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Allwinner H6 Pin Names"""
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin

PC16 = Pin((1, 79))

PD14 = Pin((1, 110))
PD15 = Pin((1, 111))
PD16 = Pin((1, 112))
PD17 = Pin((1, 113))
PD18 = Pin((1, 114))
PD19 = Pin((1, 115))
UART2_TX = PD19
PD20 = Pin((1, 116))
UART2_RX = PD20
PD21 = Pin((1, 117))
PD22 = Pin((1, 118))
PD23 = Pin((1, 119))
PD24 = Pin((1, 120))
PD25 = Pin((1, 121))
TWI0_SCL = PD25
PD26 = Pin((1, 122))
TWI0_SDA = PD26

PG10 = Pin((1, 202))
PG11 = Pin((1, 203))
PG12 = Pin((1, 204))
PG13 = Pin((1, 205))
PG14 = Pin((1, 206))

PH2 = Pin((1, 226))
PH3 = Pin((1, 227))
SPI1_CS = PH3
PH4 = Pin((1, 228))
SPI1_SCLK = PH4
PH5 = Pin((1, 229))
SPI1_MOSI = PH5
PH6 = Pin((1, 230))
SPI1_MISO = PH6
PH8 = Pin((1, 230))
PH9 = Pin((1, 231))

PL8 = Pin((1, 360))
PL9 = Pin((1, 361))

i2cPorts = ((0, TWI0_SCL, TWI0_SDA),)
spiPorts = ((0, SPI1_SCLK, SPI1_MOSI, SPI1_MISO),)
uartPorts = ((2, UART2_TX, UART2_RX),)
29 changes: 16 additions & 13 deletions src/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,29 @@ def __init__(self, pin, maxlen=2, idle_state=False):
# 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

Expand Down
26 changes: 26 additions & 0 deletions src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

import os
from time import sleep
from errno import EACCES

try:
from microcontroller.pin import pwmOuts
Expand All @@ -25,6 +27,11 @@ class PWMError(IOError):
class PWMOut:
"""Pulse Width Modulation Output Class"""

# Number of retries to check for successful PWM export on open
PWM_STAT_RETRIES = 10
# Delay between check for scucessful PWM export on open (100ms)
PWM_STAT_DELAY = 0.1

# Sysfs paths
_sysfs_path = "/sys/class/pwm/"
_channel_path = "pwmchip{}"
Expand Down Expand Up @@ -109,6 +116,25 @@ def _open(self, pin, duty=0, freq=500, variable_frequency=False):
except IOError as e:
raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror) from IOError

# Loop until 'period' is writable, because application of udev rules
# after the above pin export is asynchronous.
# Without this loop, the following properties may not be writable yet.
for i in range(PWMOut.PWM_STAT_RETRIES):
try:
with open(
os.path.join(
channel_path, self._pin_path.format(self._pwmpin), "period"
),
"w",
):
break
except IOError as e:
if e.errno != EACCES or (
e.errno == EACCES and i == PWMOut.PWM_STAT_RETRIES - 1
):
raise PWMError(e.errno, "Opening PWM period: " + e.strerror) from e
sleep(PWMOut.PWM_STAT_DELAY)

# self._set_enabled(False) # This line causes a write error when trying to enable

# Look up the period, for fast duty cycle updates
Expand Down
Empty file.
Loading

0 comments on commit 1a7e281

Please sign in to comment.