Skip to content

Commit 21e2f93

Browse files
authored
Merge branch 'adafruit:main' into Support_for_Orange_Pi_Zero2W
2 parents 62e6197 + 706e5f8 commit 21e2f93

File tree

24 files changed

+1161
-105
lines changed

24 files changed

+1161
-105
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
- name: Translate Repo Name For Build Tools filename_prefix
1717
id: repo-name
1818
run: echo "repo-name=Adafruit-Blinka" >> $GITHUB_OUTPUT
19-
- name: Set up Python 3.7
19+
- name: Set up Python 3.8
2020
uses: actions/setup-python@v4
2121
with:
22-
python-version: 3.7
22+
python-version: 3.8
2323
- name: Versions
2424
run: |
2525
python3 --version

LICENSES/BSD-3-Clause.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2023, Raspberry Pi Ltd.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of the copyright holder nor the
12+
names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
19+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2025 Justin Myers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
[pytest]
5+
pythonpath = src

setup.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,27 @@
2424
if os.path.exists("/proc/device-tree/compatible"):
2525
with open("/proc/device-tree/compatible", "rb") as f:
2626
compat = f.read()
27+
# Jetson Nano, TX2, Xavier, etc
2728
if b"nvidia,tegra" in compat:
2829
board_reqs = ["Jetson.GPIO"]
30+
# Pi 5
31+
elif b"brcm,bcm2712" in compat:
32+
board_reqs = [
33+
"rpi_ws281x>=4.0.0",
34+
"lgpio",
35+
"Adafruit-Blinka-Raspberry-Pi5-Neopixel",
36+
]
2937
# Pi 4 and Earlier
30-
if (
38+
elif (
3139
b"brcm,bcm2835" in compat
3240
or b"brcm,bcm2836" in compat
3341
or b"brcm,bcm2837" in compat
3442
or b"brcm,bcm2838" in compat
3543
or b"brcm,bcm2711" in compat
3644
):
3745
board_reqs = ["RPi.GPIO", "rpi_ws281x>=4.0.0"]
38-
# Pi 5
39-
if b"brcm,bcm2712" in compat:
40-
board_reqs = ["rpi_ws281x>=4.0.0", "rpi-lgpio"]
41-
if (
42-
b"ti,am335x" in compat
43-
): # BeagleBone Black, Green, PocketBeagle, BeagleBone AI, etc.
46+
# BeagleBone Black, Green, PocketBeagle, BeagleBone AI, etc.
47+
elif b"ti,am335x" in compat:
4448
board_reqs = ["Adafruit_BBIO"]
4549

4650
setup(
@@ -95,6 +99,7 @@
9599
"pyftdi>=0.40.0",
96100
"adafruit-circuitpython-typing",
97101
"sysv_ipc>=1.1.0;sys_platform=='linux' and platform_machine!='mips'",
102+
"toml>=0.10.2;python_version<'3.11'",
98103
]
99104
+ board_reqs,
100105
license="MIT",

src/adafruit_blinka/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
* Author(s): cefn
99
"""
1010

11+
import os
12+
13+
try:
14+
import tomllib
15+
except ImportError:
16+
import toml as tomllib
17+
1118

1219
class Enum:
1320
"""
@@ -74,6 +81,39 @@ def unlock(self):
7481
self._locked = False
7582

7683

84+
def load_settings_toml():
85+
"""Load values from settings.toml into os.environ, so that os.getenv returns them."""
86+
if not os.path.isfile("settings.toml"):
87+
raise FileNotFoundError("settings.toml not cound in current directory.")
88+
89+
print("settings.toml found. Updating environment variables:")
90+
with open("settings.toml", "rb") as toml_file:
91+
try:
92+
settings = tomllib.load(toml_file)
93+
except tomllib.TOMLDecodeError as e:
94+
raise tomllib.TOMLDecodeError("Error with settings.toml file.") from e
95+
96+
invalid_types = set()
97+
for key, value in settings.items():
98+
if not isinstance(value, (bool, int, float, str)):
99+
invalid_types.add(type(value).__name__)
100+
if invalid_types:
101+
invalid_types_string = ", ".join(invalid_types)
102+
raise ValueError(
103+
f"The types: '{invalid_types_string}' are not supported in settings.toml."
104+
)
105+
106+
for key, value in settings.items():
107+
key = str(key)
108+
if key in os.environ:
109+
print(f" - {key} already exists in environment")
110+
continue
111+
os.environ[key] = str(value)
112+
print(f" - {key} added")
113+
114+
return settings
115+
116+
77117
def patch_system():
78118
"""Patch modules that may be different due to the platform."""
79119
# pylint: disable=import-outside-toplevel
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""Pin definitions for the Orange Pi 3 LTS."""
5+
6+
from adafruit_blinka.microcontroller.allwinner.h6 import pin
7+
8+
PD26 = pin.PD26
9+
SDA = pin.PD26
10+
PD25 = pin.PD25
11+
SCL = pin.PD25
12+
PD22 = pin.PD22
13+
PL2 = pin.PL2
14+
PL3 = pin.PL3
15+
PD24 = pin.PD24
16+
UART3_RX = pin.PD24
17+
PD18 = pin.PD18
18+
PD23 = pin.PD23
19+
UART3_TX = pin.PD23
20+
PL10 = pin.PL10
21+
PD15 = pin.PD15
22+
PD16 = pin.PD16
23+
PH5 = pin.PH5
24+
PH6 = pin.PH6
25+
PD21 = pin.PD21
26+
PH4 = pin.PH4
27+
SPI1_CLK = pin.PH4
28+
PH3 = pin.PH3
29+
SPI1_CS = pin.PH3
30+
PL8 = pin.PL8
31+
32+
SCLK = pin.PH4
33+
MOSI = pin.PH5
34+
MISO = pin.PH6
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""Pin definitions for Raspberry Pi 5 models using the BCM2712."""
5+
6+
from adafruit_blinka.microcontroller.bcm2712 import pin
7+
8+
D0 = pin.D0
9+
D1 = pin.D1
10+
11+
D2 = pin.D2
12+
SDA = pin.SDA
13+
D3 = pin.D3
14+
SCL = pin.SCL
15+
16+
D4 = pin.D4
17+
D5 = pin.D5
18+
D6 = pin.D6
19+
20+
D7 = pin.D7
21+
CE1 = pin.D7
22+
D8 = pin.D8
23+
CE0 = pin.D8
24+
D9 = pin.D9
25+
MISO = pin.D9
26+
D10 = pin.D10
27+
MOSI = pin.D10
28+
D11 = pin.D11
29+
SCLK = pin.D11
30+
SCK = pin.D11
31+
32+
D12 = pin.D12
33+
D13 = pin.D13
34+
35+
D14 = pin.D14
36+
TXD = pin.D14
37+
D15 = pin.D15
38+
RXD = pin.D15
39+
# create alias for most of the examples
40+
TX = pin.D14
41+
RX = pin.D15
42+
43+
D16 = pin.D16
44+
D17 = pin.D17
45+
D18 = pin.D18
46+
D19 = pin.D19
47+
MISO_1 = pin.D19
48+
D20 = pin.D20
49+
MOSI_1 = pin.D20
50+
D21 = pin.D21
51+
SCLK_1 = pin.D21
52+
SCK_1 = pin.D21
53+
D22 = pin.D22
54+
D23 = pin.D23
55+
D24 = pin.D24
56+
D25 = pin.D25
57+
D26 = pin.D26
58+
D27 = pin.D27

src/adafruit_blinka/microcontroller/bcm2711/pin.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
#
33
# SPDX-License-Identifier: MIT
44
"""Broadcom BCM2711 pin names"""
5-
from RPi import GPIO
6-
from adafruit_blinka.microcontroller.bcm283x.pin import Pin
75

8-
GPIO.setmode(GPIO.BCM) # Use BCM pins D4 = GPIO #4
9-
GPIO.setwarnings(False) # shh!
6+
# Use RPi.GPIO pins for Raspberry Pi 4
7+
from adafruit_blinka.microcontroller.generic_linux.rpi_gpio_pin import Pin
108

119
D0 = Pin(0)
1210
D1 = Pin(1)
File renamed without changes.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""Broadcom BCM2712 pin names"""
5+
6+
# Use lgpio pins for Raspberry Pi 5
7+
from adafruit_blinka.microcontroller.generic_linux.lgpio_pin import Pin
8+
9+
D0 = Pin(0)
10+
D1 = Pin(1)
11+
12+
D2 = Pin(2)
13+
SDA = Pin(2)
14+
D3 = Pin(3)
15+
SCL = Pin(3)
16+
17+
D4 = Pin(4)
18+
D5 = Pin(5)
19+
D6 = Pin(6)
20+
21+
D7 = Pin(7)
22+
CE1 = Pin(7)
23+
D8 = Pin(8)
24+
CE0 = Pin(8)
25+
D9 = Pin(9)
26+
MISO = Pin(9)
27+
D10 = Pin(10)
28+
MOSI = Pin(10)
29+
D11 = Pin(11)
30+
SCLK = Pin(11) # Raspberry Pi naming
31+
SCK = Pin(11) # CircuitPython naming
32+
33+
D12 = Pin(12)
34+
D13 = Pin(13)
35+
36+
D14 = Pin(14)
37+
TXD = Pin(14)
38+
D15 = Pin(15)
39+
RXD = Pin(15)
40+
41+
D16 = Pin(16)
42+
D17 = Pin(17)
43+
D18 = Pin(18)
44+
D19 = Pin(19)
45+
MISO_1 = Pin(19)
46+
D20 = Pin(20)
47+
MOSI_1 = Pin(20)
48+
D21 = Pin(21)
49+
SCLK_1 = Pin(21)
50+
SCK_1 = Pin(21)
51+
D22 = Pin(22)
52+
D23 = Pin(23)
53+
D24 = Pin(24)
54+
D25 = Pin(25)
55+
D26 = Pin(26)
56+
D27 = Pin(27)
57+
D28 = Pin(28)
58+
D29 = Pin(29)
59+
D30 = Pin(30)
60+
D31 = Pin(31)
61+
D32 = Pin(32)
62+
D33 = Pin(33)
63+
D34 = Pin(34)
64+
D35 = Pin(35)
65+
D36 = Pin(36)
66+
D37 = Pin(37)
67+
D38 = Pin(38)
68+
D39 = Pin(39)
69+
D40 = Pin(40)
70+
MISO_2 = Pin(40)
71+
D41 = Pin(41)
72+
MOSI_2 = Pin(41)
73+
D42 = Pin(42)
74+
SCLK_2 = Pin(42)
75+
SCK_2 = Pin(43)
76+
D43 = Pin(43)
77+
D44 = Pin(44)
78+
D45 = Pin(45)
79+
80+
# ordered as spiId, sckId, mosiId, misoId
81+
spiPorts = (
82+
(0, SCLK, MOSI, MISO),
83+
(1, SCLK_1, MOSI_1, MISO_1),
84+
(2, SCLK_2, MOSI_2, MISO_2),
85+
(3, D3, D2, D1),
86+
(4, D7, D6, D5),
87+
(5, D15, D14, D13),
88+
)
89+
90+
# ordered as uartId, txId, rxId
91+
uartPorts = ((1, TXD, RXD),)
92+
93+
# These are the known hardware I2C ports / pins.
94+
# For software I2C ports created with the i2c-gpio overlay, see:
95+
# https://github.com/adafruit/Adafruit_Python_Extended_Bus
96+
i2cPorts = (
97+
(1, SCL, SDA),
98+
(0, D1, D0), # both pi 1 and pi 2 i2c ports!
99+
(10, D45, D44), # internal i2c bus for the CM4
100+
)

0 commit comments

Comments
 (0)