MikrofonSensor und TemperaturSenor die zwei Python programme funktionieren. mit den jeweiligen 2 json Datein. Beim TemperaturSensor wird im Terminal keine Wertre ausgegeben aber in der json Datei kann man die Temp und Hum sehen.
This commit is contained in:
parent
4c654ec969
commit
1751076592
2614 changed files with 349009 additions and 0 deletions
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,38 @@
|
|||
# SPDX-FileCopyrightText: 2023 Steve Jeong for Hardkernel
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""
|
||||
Functions to find aliases for all hardware,
|
||||
including those defined in the device tree.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def get_dts_alias(device: str) -> Optional[str]:
|
||||
"""Get the Device Tree Alias"""
|
||||
uevent_path = "/sys/bus/platform/devices/" + device + "/uevent"
|
||||
if os.path.exists(uevent_path):
|
||||
with open(uevent_path, "r", encoding="utf-8") as fd:
|
||||
pattern = r"^OF_ALIAS_0=(.*)$"
|
||||
uevent = fd.read().split("\n")
|
||||
for line in uevent:
|
||||
match = re.search(pattern, line)
|
||||
if match:
|
||||
return match.group(1).upper()
|
||||
return None
|
||||
|
||||
|
||||
def get_pwm_chipid(device: str):
|
||||
"""Get the PWM Chip ID"""
|
||||
for chipid in range(32):
|
||||
pwm_sys_path = "/sys/class/pwm/pwmchip{}".format(chipid)
|
||||
if not os.path.exists(pwm_sys_path):
|
||||
continue
|
||||
if device in os.path.realpath(pwm_sys_path):
|
||||
alias = "PWM" + str(chipid)
|
||||
return alias
|
||||
return None
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2022 Aleksandr Saiapin for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner D1 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,112 @@
|
|||
# SPDX-FileCopyrightText: 2022 Aleksandr Saiapin for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Allwinner D1 pin names"""
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
PB0 = Pin(32)
|
||||
TWI2_SCL = PB0
|
||||
PB1 = Pin(33)
|
||||
TWI2_SDA = PB1
|
||||
PB2 = Pin(34)
|
||||
PB3 = Pin(35)
|
||||
PB4 = Pin(36)
|
||||
PB5 = Pin(37)
|
||||
PB6 = Pin(38)
|
||||
PB7 = Pin(39)
|
||||
PB8 = Pin(40)
|
||||
UART0_TX = PB8
|
||||
PB9 = Pin(41)
|
||||
UART0_RX = PB9
|
||||
PB10 = Pin(42)
|
||||
PB11 = Pin(43)
|
||||
PB12 = Pin(44)
|
||||
PC0 = Pin(64)
|
||||
UART2_TX = PC0
|
||||
PC1 = Pin(65)
|
||||
UART2_RX = PC1
|
||||
PC2 = Pin(66)
|
||||
SPI0_SCLK = PC2
|
||||
PC3 = Pin(67)
|
||||
SPI0_CS = PC3
|
||||
PC4 = Pin(68)
|
||||
SPI0_MOSI = PC4
|
||||
PC5 = Pin(69)
|
||||
SPI0_MISO = PC5
|
||||
PC6 = Pin(70)
|
||||
SPI0_WP = PC6
|
||||
PC7 = Pin(71)
|
||||
SPI0_HOLD = PC7
|
||||
PD0 = Pin(96)
|
||||
PD1 = Pin(97)
|
||||
PD2 = Pin(98)
|
||||
PD3 = Pin(99)
|
||||
PD4 = Pin(100)
|
||||
PD5 = Pin(101)
|
||||
PD6 = Pin(102)
|
||||
PD7 = Pin(103)
|
||||
PD8 = Pin(104)
|
||||
PD9 = Pin(105)
|
||||
PD10 = Pin(106)
|
||||
PD11 = Pin(107)
|
||||
PD12 = Pin(108)
|
||||
PD13 = Pin(109)
|
||||
PD14 = Pin(110)
|
||||
PD15 = Pin(111)
|
||||
PD16 = Pin(112)
|
||||
PD17 = Pin(113)
|
||||
PD18 = Pin(114)
|
||||
PD19 = Pin(115)
|
||||
PD20 = Pin(116)
|
||||
PD21 = Pin(117)
|
||||
PD22 = Pin(118)
|
||||
PE0 = Pin(128)
|
||||
PE1 = Pin(129)
|
||||
PE2 = Pin(130)
|
||||
PE3 = Pin(131)
|
||||
PE4 = Pin(132)
|
||||
PE5 = Pin(133)
|
||||
PE6 = Pin(134)
|
||||
PE7 = Pin(135)
|
||||
PE8 = Pin(136)
|
||||
PE9 = Pin(137)
|
||||
PE10 = Pin(138)
|
||||
PE11 = Pin(139)
|
||||
PE12 = Pin(140)
|
||||
PE13 = Pin(141)
|
||||
PE14 = Pin(142)
|
||||
TWI1_SCL = PE14
|
||||
PE15 = Pin(143)
|
||||
TWI1_SDA = PE15
|
||||
PE16 = Pin(144)
|
||||
TWI3_SCL = PE16
|
||||
PE17 = Pin(145)
|
||||
TWI3_SDA = PE17
|
||||
PG6 = Pin(198)
|
||||
UART1_TX = PG6
|
||||
PG7 = Pin(199)
|
||||
UART1_RX = PG7
|
||||
PG8 = Pin(200)
|
||||
UART1_RTS = PG8
|
||||
PG9 = Pin(201)
|
||||
UART1_CTS = PG9
|
||||
PG10 = Pin(202)
|
||||
PG11 = Pin(203)
|
||||
PG12 = Pin(204)
|
||||
PG13 = Pin(205)
|
||||
PG14 = Pin(206)
|
||||
PG15 = Pin(207)
|
||||
PG16 = Pin(208)
|
||||
PG17 = Pin(209)
|
||||
PG18 = Pin(210)
|
||||
|
||||
i2cPorts = (
|
||||
(2, TWI2_SCL, TWI2_SDA),
|
||||
(3, TWI3_SCL, TWI3_SDA),
|
||||
)
|
||||
uartPorts = (
|
||||
(0, UART0_TX, UART0_RX),
|
||||
(1, UART1_TX, UART1_RX),
|
||||
(2, UART2_TX, UART2_RX),
|
||||
)
|
||||
spiPorts = ((0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),)
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition of all Allwinner chips"""
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner A20 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,170 @@
|
|||
# SPDX-FileCopyrightText: 2023 Xenokrates
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Allwinner A20 pin names"""
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
# Pin descriptions at https://linux-sunxi.org/A20/PIO
|
||||
|
||||
PA0 = Pin(0)
|
||||
PA1 = Pin(1)
|
||||
PA2 = Pin(2)
|
||||
UART2_TX = PA2
|
||||
PA3 = Pin(3)
|
||||
UART2_RX = PA3
|
||||
PA6 = Pin(6)
|
||||
PA7 = Pin(7)
|
||||
PA8 = Pin(8)
|
||||
PA9 = Pin(9)
|
||||
PA10 = Pin(10)
|
||||
UART1_TX = PA10
|
||||
PA11 = Pin(11)
|
||||
UART1_RX = PA11
|
||||
PA12 = Pin(12)
|
||||
PA13 = Pin(13)
|
||||
PA14 = Pin(14)
|
||||
PA15 = Pin(15)
|
||||
PA16 = Pin(16)
|
||||
PA17 = Pin(17)
|
||||
|
||||
PB0 = Pin(32)
|
||||
TWI0_SCK = PB0
|
||||
PB1 = Pin(33)
|
||||
TWI0_SDA = PB1
|
||||
PB2 = Pin(34)
|
||||
PWM0 = PB2
|
||||
PB3 = Pin(35)
|
||||
IR0_TX = PB3
|
||||
PB4 = Pin(36)
|
||||
IR0_RX = PB4
|
||||
PB5 = Pin(37)
|
||||
PB6 = Pin(38)
|
||||
PB7 = Pin(39)
|
||||
PB8 = Pin(40)
|
||||
PB12 = Pin(44)
|
||||
PB13 = Pin(45)
|
||||
PB18 = Pin(50)
|
||||
TWI1_SCK = PB18
|
||||
PB19 = Pin(51)
|
||||
TWI1_SDA = PB19
|
||||
PB20 = Pin(52)
|
||||
TWI2_SCK = PB20
|
||||
PB21 = Pin(53)
|
||||
TWI2_SDA = PB21
|
||||
PB22 = Pin(54)
|
||||
UART0_TX = PB22
|
||||
PB23 = Pin(55)
|
||||
UART0_RX = PB23
|
||||
|
||||
PC19 = Pin(83)
|
||||
SPI2_CS0 = PC19
|
||||
PC20 = Pin(84)
|
||||
SPI2_SCLK = PC20
|
||||
PC21 = Pin(85)
|
||||
SPI2_MOSI = PC21
|
||||
PC22 = Pin(86)
|
||||
SPI2_MISO = PC22
|
||||
|
||||
PG2 = Pin(194)
|
||||
|
||||
PH2 = Pin(226)
|
||||
PH4 = Pin(228)
|
||||
UART4_TX = PH4
|
||||
PH5 = Pin(229)
|
||||
UART4_RX = PH5
|
||||
PH6 = Pin(230)
|
||||
UART5_TX = PH6
|
||||
PH7 = Pin(231)
|
||||
UART5_RX = PH7
|
||||
PH8 = Pin(232)
|
||||
PH9 = Pin(233)
|
||||
PH10 = Pin(234)
|
||||
PH11 = Pin(235)
|
||||
PH12 = Pin(236)
|
||||
PH13 = Pin(237)
|
||||
PH14 = Pin(238)
|
||||
PH15 = Pin(239)
|
||||
PH16 = Pin(240)
|
||||
PH17 = Pin(241)
|
||||
PH18 = Pin(242)
|
||||
PH19 = Pin(243)
|
||||
PH20 = Pin(244)
|
||||
CAN_TX = PH20
|
||||
PH21 = Pin(245)
|
||||
CAN_RX = PH21
|
||||
PH24 = Pin(248)
|
||||
|
||||
PI0 = Pin(256)
|
||||
TWI3_SCK = PI0
|
||||
PI1 = Pin(257)
|
||||
TWI3_SDA = PI1
|
||||
PI3 = Pin(259)
|
||||
PWM1 = PI3
|
||||
PI10 = Pin(266)
|
||||
SPI0_CS0 = PI10
|
||||
PI11 = Pin(267)
|
||||
SPI0_SCLK = PI11
|
||||
PI12 = Pin(268)
|
||||
SPI0_MOSI = PI12
|
||||
UART6_TX = PI12
|
||||
PI13 = Pin(269)
|
||||
SPI0_MISO = PI13
|
||||
UART6_RX = PI13
|
||||
PI14 = Pin(270)
|
||||
SPI0_CS1 = PI14
|
||||
PI16 = Pin(272)
|
||||
UART2_RTS = PI16
|
||||
PI17 = Pin(273)
|
||||
UART2_CTS = PI17
|
||||
PI18 = Pin(274)
|
||||
UART2_TX = PI18
|
||||
PI19 = Pin(275)
|
||||
UART2_RX = PI19
|
||||
PI20 = Pin(276)
|
||||
UART7_TX = PI20
|
||||
PI21 = Pin(277)
|
||||
UART7_RX = PI21
|
||||
|
||||
# A10/A20 has a touch panel controller which can be configured to operate
|
||||
# as four seperate adc chanels, providing 12-bit resolution.
|
||||
XP_TP = 1
|
||||
XN_TP = 2
|
||||
YP_TP = 3
|
||||
YN_TP = 4
|
||||
|
||||
# SysFS pwm outputs, pwm channel and pin in first tuple
|
||||
pwmOuts = (
|
||||
((0, 0), PWM0),
|
||||
((0, 1), PWM1),
|
||||
)
|
||||
|
||||
# ordered as i2cId, sclId, sdaId
|
||||
i2cPorts = (
|
||||
(0, TWI0_SCK, TWI0_SDA),
|
||||
(1, TWI1_SCK, TWI1_SDA),
|
||||
(2, TWI2_SCK, TWI2_SDA),
|
||||
)
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = (
|
||||
(0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),
|
||||
(2, SPI2_SCLK, SPI2_MOSI, SPI2_MISO),
|
||||
)
|
||||
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = (
|
||||
(0, UART0_TX, UART0_RX),
|
||||
(2, UART2_TX, UART2_RX),
|
||||
(4, UART4_TX, UART4_RX),
|
||||
(5, UART5_TX, UART5_RX),
|
||||
(6, UART6_TX, UART6_RX),
|
||||
(7, UART7_TX, UART7_RX),
|
||||
)
|
||||
|
||||
# sysFs analog inputs, Ordered as analogInId, device, and channel
|
||||
analogIns = (
|
||||
(XP_TP, 1, 0),
|
||||
(XN_TP, 1, 1),
|
||||
(YP_TP, 1, 2),
|
||||
(YN_TP, 1, 3),
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner A33 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,50 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Allwinner A33 pin names"""
|
||||
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
PB0 = Pin(32) # PB0/UART2_TX/UART0_TX/PB_EINT0
|
||||
UART2_TX = PB0
|
||||
PB1 = Pin(33) # PB1/UART2_RX/UART0_RX/PB_EINT1
|
||||
UART2_RX = PB1
|
||||
|
||||
PC0 = Pin(64) # PC0/ND_WE/SPI0_MOSI
|
||||
PC1 = Pin(65) # PC1/ND_ALE/SPI0_MISO
|
||||
PC2 = Pin(66) # PC2/ND_CLE/SPI0_CLK
|
||||
|
||||
PH4 = Pin(228) # PH4/TWI1_SCK
|
||||
TWI1_SCL = PH4
|
||||
PH5 = Pin(229) # PH5/TWI1_SDA
|
||||
TWI1_SDA = PH5
|
||||
|
||||
|
||||
PH6 = Pin(230) # PH6/SPI0_CS/UART3_TX
|
||||
UART3_TX = PH6
|
||||
SPI0_CS = PH6
|
||||
|
||||
PH7 = Pin(231) # PH7/SPI0_CLK/UART3_RX
|
||||
UART3_RX = PH7
|
||||
SPI0_SCLK = PH7
|
||||
|
||||
PH8 = Pin(232) # PH8/SPI0_MOSI/UART3_RTS
|
||||
UART3_RTS = PH8
|
||||
SPI0_MOSI = PH8
|
||||
|
||||
PH9 = Pin(233) # PH9/SPI0_MISO/UART3_CTS
|
||||
UART3_CTS = PH9
|
||||
SPI0_MISO = PH9
|
||||
|
||||
|
||||
# ordered as i2cId, sclId, sdaId
|
||||
i2cPorts = ((0, TWI1_SCL, TWI1_SDA),)
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = ((0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),)
|
||||
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = (
|
||||
(2, UART2_TX, UART2_RX),
|
||||
(3, UART3_TX, UART3_RX),
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner A64 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,91 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Allwinner A64 pin names"""
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
PB0 = Pin((1, 32))
|
||||
UART2_TX = PB0
|
||||
PB1 = Pin((1, 33))
|
||||
UART2_RX = PB1
|
||||
PB2 = Pin((1, 34))
|
||||
PB3 = Pin((1, 35))
|
||||
PB4 = Pin((1, 36))
|
||||
PB5 = Pin((1, 37))
|
||||
PB6 = Pin((1, 38))
|
||||
PB7 = Pin((1, 39))
|
||||
|
||||
PC0 = Pin((1, 64))
|
||||
SPI0_MOSI = PC0
|
||||
PC1 = Pin((1, 65))
|
||||
SPI0_MISO = PC1
|
||||
PC2 = Pin((1, 66))
|
||||
SPI0_SCLK = PC2
|
||||
PC3 = Pin((1, 67))
|
||||
SPI0_CS = PC3
|
||||
PC4 = Pin((1, 68))
|
||||
PC5 = Pin((1, 69))
|
||||
PC6 = Pin((1, 70))
|
||||
PC7 = Pin((1, 71))
|
||||
PC8 = Pin((1, 72))
|
||||
PC9 = Pin((1, 73))
|
||||
PC10 = Pin((1, 74))
|
||||
PC11 = Pin((1, 75))
|
||||
PC12 = Pin((1, 76))
|
||||
PC13 = Pin((1, 77))
|
||||
PC14 = Pin((1, 78))
|
||||
PC15 = Pin((1, 79))
|
||||
PC16 = Pin((1, 80))
|
||||
|
||||
PD0 = Pin((1, 96))
|
||||
UART3_TX = PD0
|
||||
SPI1_CS = PD0
|
||||
PD1 = Pin((1, 97))
|
||||
SPI1_SCLK = PD1
|
||||
UART3_RX = PD1
|
||||
PD2 = Pin((1, 98))
|
||||
UART4_TX = PD2
|
||||
SPI1_MOSI = PD2
|
||||
PD3 = Pin((1, 99))
|
||||
UART4_RX = PD3
|
||||
SPI1_MISO = PD3
|
||||
PD4 = Pin((1, 100))
|
||||
PD5 = Pin((1, 101))
|
||||
PD6 = Pin((1, 102))
|
||||
|
||||
PE14 = Pin((1, 142))
|
||||
TWI2_SCL = PE14
|
||||
PE15 = Pin((1, 143))
|
||||
TWI2_SDA = PE15
|
||||
|
||||
PH2 = Pin((1, 226))
|
||||
TWI1_SCL = PH2
|
||||
PH3 = Pin((1, 227))
|
||||
TWI1_SDA = PH3
|
||||
PH4 = Pin((1, 228))
|
||||
PH5 = Pin((1, 229))
|
||||
PH6 = Pin((1, 230))
|
||||
PH7 = Pin((1, 231))
|
||||
PH8 = Pin((1, 232))
|
||||
PH9 = Pin((1, 233))
|
||||
|
||||
PL2 = Pin((0, 2))
|
||||
PL3 = Pin((0, 3))
|
||||
PL8 = Pin((0, 8))
|
||||
PL9 = Pin((0, 9))
|
||||
PL10 = Pin((0, 10))
|
||||
|
||||
# ordered as i2cId, sclId, sdaId
|
||||
i2cPorts = ((1, TWI1_SCL, TWI1_SDA), (2, TWI2_SCL, TWI2_SDA))
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = (
|
||||
(0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),
|
||||
(1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO),
|
||||
)
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = (
|
||||
(2, UART2_TX, UART2_RX),
|
||||
(3, UART3_TX, UART3_RX),
|
||||
(4, UART4_TX, UART4_RX),
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner H3 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,71 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Allwinner H3 pin names"""
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
PA0 = Pin(0)
|
||||
UART2_TX = PA0
|
||||
PA1 = Pin(1)
|
||||
UART2_RX = PA1
|
||||
PA2 = Pin(2)
|
||||
PA3 = Pin(3)
|
||||
PA6 = Pin(6)
|
||||
PA7 = Pin(7)
|
||||
PA8 = Pin(8)
|
||||
PA9 = Pin(9)
|
||||
PA10 = Pin(10)
|
||||
PA11 = Pin(11)
|
||||
TWI0_SCL = PA11
|
||||
PA12 = Pin(12)
|
||||
TWI0_SDA = PA12
|
||||
PA13 = Pin(13)
|
||||
UART3_TX = PA13
|
||||
PA14 = Pin(14)
|
||||
UART3_RX = PA14
|
||||
SPI1_SCLK = PA14
|
||||
PA15 = Pin(15)
|
||||
SPI1_MOSI = PA15
|
||||
PA16 = Pin(16)
|
||||
SPI1_MISO = PA16
|
||||
PA17 = Pin(17)
|
||||
PA18 = Pin(18)
|
||||
PA19 = Pin(19)
|
||||
PA20 = Pin(20)
|
||||
PA21 = Pin(21)
|
||||
|
||||
PC0 = Pin(64)
|
||||
SPI0_MOSI = PC0
|
||||
PC1 = Pin(65)
|
||||
SPI0_MISO = PC1
|
||||
PC2 = Pin(66)
|
||||
SPI0_SCLK = PC2
|
||||
PC3 = Pin(67)
|
||||
SPI0_CS = PC3
|
||||
PC4 = Pin(68)
|
||||
PC7 = Pin(71)
|
||||
|
||||
PD14 = Pin(110)
|
||||
|
||||
PG6 = Pin(198)
|
||||
UART1_TX = PG6
|
||||
PG7 = Pin(199)
|
||||
UART1_RX = PG7
|
||||
PG8 = Pin(200)
|
||||
PG9 = Pin(201)
|
||||
PG10 = Pin(202)
|
||||
PG11 = Pin(203)
|
||||
PG12 = Pin(204)
|
||||
PG13 = Pin(205)
|
||||
|
||||
PL2 = Pin((1, 2))
|
||||
PL4 = Pin((1, 4))
|
||||
|
||||
i2cPorts = ((0, TWI0_SCL, TWI0_SDA),)
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = (
|
||||
(0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),
|
||||
(1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO),
|
||||
)
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = ((3, UART3_TX, UART3_RX),)
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner H5 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,74 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Allwinner H5 pin names"""
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
PA0 = Pin((1, 0))
|
||||
UART2_TX = PA0
|
||||
PA1 = Pin((1, 1))
|
||||
UART2_RX = PA1
|
||||
PA2 = Pin((1, 2))
|
||||
PA3 = Pin((1, 3))
|
||||
PA6 = Pin((1, 6))
|
||||
PA7 = Pin((1, 7))
|
||||
PA8 = Pin((1, 8))
|
||||
PA9 = Pin((1, 9))
|
||||
PA10 = Pin((1, 10))
|
||||
PA11 = Pin((1, 11))
|
||||
TWI0_SCL = PA11
|
||||
PA12 = Pin((1, 12))
|
||||
TWI0_SDA = PA12
|
||||
PA13 = Pin((1, 13))
|
||||
UART3_TX = PA13
|
||||
PA14 = Pin((1, 14))
|
||||
UART3_RX = PA14
|
||||
SPI1_SCLK = PA14
|
||||
PA15 = Pin((1, 15))
|
||||
SPI1_MOSI = PA15
|
||||
PA16 = Pin((1, 16))
|
||||
SPI1_MISO = PA16
|
||||
PA17 = Pin((1, 17))
|
||||
PA18 = Pin((1, 18))
|
||||
PA19 = Pin((1, 19))
|
||||
PA20 = Pin((1, 20))
|
||||
PA21 = Pin((1, 21))
|
||||
|
||||
PC0 = Pin((1, 64))
|
||||
SPI0_MOSI = PC0
|
||||
PC1 = Pin((1, 65))
|
||||
SPI0_MISO = PC1
|
||||
PC2 = Pin((1, 66))
|
||||
SPI0_SCLK = PC2
|
||||
PC3 = Pin((1, 67))
|
||||
SPI0_CS = PC3
|
||||
PC4 = Pin((1, 68))
|
||||
PC5 = Pin((1, 69))
|
||||
PC6 = Pin((1, 70))
|
||||
PC7 = Pin((1, 71))
|
||||
|
||||
PD11 = Pin((1, 107))
|
||||
PD14 = Pin((1, 110))
|
||||
|
||||
PG6 = Pin((1, 198))
|
||||
UART1_TX = PG6
|
||||
PG7 = Pin((1, 199))
|
||||
UART1_RX = PG7
|
||||
PG8 = Pin((1, 200))
|
||||
PG9 = Pin((1, 201))
|
||||
PG10 = Pin((1, 202))
|
||||
PG11 = Pin((1, 203))
|
||||
PG12 = Pin((1, 204))
|
||||
PG13 = Pin((1, 205))
|
||||
|
||||
PL0 = Pin((0, 0))
|
||||
PL1 = Pin((0, 1))
|
||||
|
||||
i2cPorts = ((0, TWI0_SCL, TWI0_SDA),)
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = (
|
||||
(0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),
|
||||
(1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO),
|
||||
)
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = ((3, UART3_TX, UART3_RX),)
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner H6 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,53 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""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))
|
||||
|
||||
PL2 = Pin((0, 2))
|
||||
PL3 = Pin((0, 3))
|
||||
PL8 = Pin((0, 8))
|
||||
PL9 = Pin((0, 9))
|
||||
PL10 = Pin((0, 10))
|
||||
|
||||
i2cPorts = ((0, TWI0_SCL, TWI0_SDA),)
|
||||
spiPorts = ((1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO),)
|
||||
uartPorts = ((2, UART2_TX, UART2_RX),)
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner H616 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,127 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""Allwinner H616 Pin Names"""
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
__chip_num = 1
|
||||
with open("/sys/class/gpio/gpiochip0/label", "r") as f:
|
||||
label = f.read().strip()
|
||||
if label == "300b000.pinctrl":
|
||||
__chip_num = 0
|
||||
PC0 = Pin((__chip_num, 64))
|
||||
SPI0_SCLK = PC0
|
||||
PC1 = Pin((__chip_num, 65))
|
||||
PC2 = Pin((__chip_num, 66))
|
||||
SPI0_MOSI = PC2
|
||||
PC3 = Pin((__chip_num, 67))
|
||||
SPI0_CS0 = PC3
|
||||
PC4 = Pin((__chip_num, 68))
|
||||
SPI0_MISO = PC4
|
||||
PC5 = Pin((__chip_num, 69))
|
||||
PC6 = Pin((__chip_num, 70))
|
||||
PC7 = Pin((__chip_num, 71))
|
||||
PC8 = Pin((__chip_num, 72))
|
||||
PC9 = Pin((__chip_num, 73))
|
||||
PC10 = Pin((__chip_num, 74))
|
||||
PC11 = Pin((__chip_num, 75))
|
||||
PC12 = Pin((__chip_num, 76))
|
||||
PC13 = Pin((__chip_num, 77))
|
||||
PC14 = Pin((__chip_num, 78))
|
||||
PC15 = Pin((__chip_num, 79))
|
||||
|
||||
PF0 = Pin((__chip_num, 160))
|
||||
PF1 = Pin((__chip_num, 161))
|
||||
PF2 = Pin((__chip_num, 162))
|
||||
PF3 = Pin((__chip_num, 163))
|
||||
PF4 = Pin((__chip_num, 164))
|
||||
PF5 = Pin((__chip_num, 165))
|
||||
PF6 = Pin((__chip_num, 166))
|
||||
|
||||
PG0 = Pin((__chip_num, 192))
|
||||
PG1 = Pin((__chip_num, 193))
|
||||
PG2 = Pin((__chip_num, 194))
|
||||
PG3 = Pin((__chip_num, 195))
|
||||
PG4 = Pin((__chip_num, 196))
|
||||
PG5 = Pin((__chip_num, 197))
|
||||
PG6 = Pin((__chip_num, 198))
|
||||
PG7 = Pin((__chip_num, 199))
|
||||
PG8 = Pin((__chip_num, 200))
|
||||
PG9 = Pin((__chip_num, 201))
|
||||
PG10 = Pin((__chip_num, 202))
|
||||
PG11 = Pin((__chip_num, 203))
|
||||
PG12 = Pin((__chip_num, 204))
|
||||
PG13 = Pin((__chip_num, 205))
|
||||
PG14 = Pin((__chip_num, 206))
|
||||
PG15 = Pin((__chip_num, 207))
|
||||
PG16 = Pin((__chip_num, 208))
|
||||
PG17 = Pin((__chip_num, 209))
|
||||
PG18 = Pin((__chip_num, 210))
|
||||
PG19 = Pin((__chip_num, 211))
|
||||
|
||||
PH0 = Pin((__chip_num, 224))
|
||||
PH1 = Pin((__chip_num, 225))
|
||||
PH2 = Pin((__chip_num, 226))
|
||||
UART5_TX = PH2
|
||||
PH3 = Pin((__chip_num, 227))
|
||||
UART5_RX = PH3
|
||||
PH4 = Pin((__chip_num, 228))
|
||||
TWI3_SCL = PH4
|
||||
PH5 = Pin((__chip_num, 229))
|
||||
UART2_TX = PH5
|
||||
TWI3_SDA = PH5
|
||||
SPI1_CS0 = PH5
|
||||
PH6 = Pin((__chip_num, 230))
|
||||
UART2_RX = PH6
|
||||
SPI1_SCLK = PH6
|
||||
PH7 = Pin((__chip_num, 231))
|
||||
SPI1_MOSI = PH7
|
||||
PH8 = Pin((__chip_num, 232))
|
||||
SPI1_MISO = PH8
|
||||
PH9 = Pin((__chip_num, 233))
|
||||
SPI1_CS1 = PH9
|
||||
PH10 = Pin((__chip_num, 234))
|
||||
|
||||
PI0 = Pin((__chip_num, 256))
|
||||
PI1 = Pin((__chip_num, 257))
|
||||
PI2 = Pin((__chip_num, 258))
|
||||
PI3 = Pin((__chip_num, 259))
|
||||
PI4 = Pin((__chip_num, 260))
|
||||
PI5 = Pin((__chip_num, 261))
|
||||
TWI0_SCL = PI5
|
||||
PI6 = Pin((__chip_num, 262))
|
||||
TWI0_SDA = PI6
|
||||
PI7 = Pin((__chip_num, 263))
|
||||
TWI1_SCL = PI7
|
||||
PI8 = Pin((__chip_num, 264))
|
||||
TWI1_SDA = PI8
|
||||
PI9 = Pin((__chip_num, 265))
|
||||
TWI2_SCL = PI9
|
||||
PI10 = Pin((__chip_num, 266))
|
||||
TWI2_SDA = PI10
|
||||
PI11 = Pin((__chip_num, 267))
|
||||
PI12 = Pin((__chip_num, 268))
|
||||
PI13 = Pin((__chip_num, 269))
|
||||
PI14 = Pin((__chip_num, 270))
|
||||
PI15 = Pin((__chip_num, 271))
|
||||
PI16 = Pin((__chip_num, 272))
|
||||
|
||||
i2cPorts = (
|
||||
(0, TWI0_SCL, TWI0_SDA),
|
||||
(1, TWI1_SCL, TWI1_SDA),
|
||||
(2, TWI2_SCL, TWI2_SDA),
|
||||
(3, TWI3_SCL, TWI3_SDA),
|
||||
)
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
|
||||
spiPorts = (
|
||||
(0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),
|
||||
(1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO),
|
||||
)
|
||||
# ordered as uartId, txId, rxId
|
||||
|
||||
uartPorts = (
|
||||
(2, UART2_TX, UART2_RX),
|
||||
(5, UART5_TX, UART5_RX),
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner H618 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,163 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Allwinner H618 Pin Names"""
|
||||
import re
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
|
||||
def find_gpiochip_number(target_label):
|
||||
"""Get correct gpiochip number, legacy kernel and mainline kernel are different"""
|
||||
try:
|
||||
with open("/sys/kernel/debug/gpio", "r") as f:
|
||||
lines = f.readlines()
|
||||
except FileNotFoundError:
|
||||
print("The file /sys/kernel/debug/gpio does not exist.")
|
||||
return None
|
||||
|
||||
gpiochip_number = None
|
||||
for line in lines:
|
||||
if target_label in line:
|
||||
match = re.search(r"gpiochip(\d+)", line)
|
||||
if match:
|
||||
gpiochip_number = match.group(1)
|
||||
break
|
||||
|
||||
return gpiochip_number
|
||||
|
||||
|
||||
if find_gpiochip_number("300b000.pinctrl"):
|
||||
__chip_num = 1
|
||||
else:
|
||||
__chip_num = 0
|
||||
|
||||
PC0 = Pin((__chip_num, 64))
|
||||
SPI0_SCLK = PC0
|
||||
PC1 = Pin((__chip_num, 65))
|
||||
PC2 = Pin((__chip_num, 66))
|
||||
SPI0_MOSI = PC2
|
||||
PC3 = Pin((__chip_num, 67))
|
||||
SPI0_CS0 = PC3
|
||||
PC4 = Pin((__chip_num, 68))
|
||||
SPI0_MISO = PC4
|
||||
PC5 = Pin((__chip_num, 69))
|
||||
PC6 = Pin((__chip_num, 70))
|
||||
PC7 = Pin((__chip_num, 71))
|
||||
PC8 = Pin((__chip_num, 72))
|
||||
PC9 = Pin((__chip_num, 73))
|
||||
PC10 = Pin((__chip_num, 74))
|
||||
PC11 = Pin((__chip_num, 75))
|
||||
PC12 = Pin((__chip_num, 76))
|
||||
PC13 = Pin((__chip_num, 77))
|
||||
PC14 = Pin((__chip_num, 78))
|
||||
PC15 = Pin((__chip_num, 79))
|
||||
|
||||
PF0 = Pin((__chip_num, 160))
|
||||
PF1 = Pin((__chip_num, 161))
|
||||
PF2 = Pin((__chip_num, 162))
|
||||
PF3 = Pin((__chip_num, 163))
|
||||
PF4 = Pin((__chip_num, 164))
|
||||
PF5 = Pin((__chip_num, 165))
|
||||
PF6 = Pin((__chip_num, 166))
|
||||
|
||||
PG0 = Pin((__chip_num, 192))
|
||||
PG1 = Pin((__chip_num, 193))
|
||||
PG2 = Pin((__chip_num, 194))
|
||||
PG3 = Pin((__chip_num, 195))
|
||||
PG4 = Pin((__chip_num, 196))
|
||||
PG5 = Pin((__chip_num, 197))
|
||||
PG6 = Pin((__chip_num, 198))
|
||||
UART1_TX = PG6
|
||||
PG7 = Pin((__chip_num, 199))
|
||||
UART1_RX = PG7
|
||||
PG8 = Pin((__chip_num, 200))
|
||||
PG9 = Pin((__chip_num, 201))
|
||||
PG10 = Pin((__chip_num, 202))
|
||||
PG11 = Pin((__chip_num, 203))
|
||||
PG12 = Pin((__chip_num, 204))
|
||||
PG13 = Pin((__chip_num, 205))
|
||||
PG14 = Pin((__chip_num, 206))
|
||||
PG15 = Pin((__chip_num, 207))
|
||||
TWI4_SCL = PG15
|
||||
PG16 = Pin((__chip_num, 208))
|
||||
TWI4_SDA = PG16
|
||||
PG17 = Pin((__chip_num, 209))
|
||||
TWI3_SCL = PG17
|
||||
PG18 = Pin((__chip_num, 210))
|
||||
TWI3_SDA = PG18
|
||||
PG19 = Pin((__chip_num, 211))
|
||||
PWM1 = PG19
|
||||
|
||||
PH0 = Pin((__chip_num, 224))
|
||||
PH1 = Pin((__chip_num, 225))
|
||||
PH2 = Pin((__chip_num, 226))
|
||||
UART5_TX = PH2
|
||||
PH3 = Pin((__chip_num, 227))
|
||||
UART5_RX = PH3
|
||||
PH4 = Pin((__chip_num, 228))
|
||||
PH5 = Pin((__chip_num, 229))
|
||||
UART2_TX = PH5
|
||||
SPI1_CS0 = PH5
|
||||
PH6 = Pin((__chip_num, 230))
|
||||
UART2_RX = PH6
|
||||
SPI1_SCLK = PH6
|
||||
PH7 = Pin((__chip_num, 231))
|
||||
SPI1_MOSI = PH7
|
||||
PH8 = Pin((__chip_num, 232))
|
||||
SPI1_MISO = PH8
|
||||
PH9 = Pin((__chip_num, 233))
|
||||
SPI1_CS1 = PH9
|
||||
PH10 = Pin((__chip_num, 234))
|
||||
|
||||
PI0 = Pin((__chip_num, 256))
|
||||
PI1 = Pin((__chip_num, 257))
|
||||
PI2 = Pin((__chip_num, 258))
|
||||
PI3 = Pin((__chip_num, 259))
|
||||
PI4 = Pin((__chip_num, 260))
|
||||
PI5 = Pin((__chip_num, 261))
|
||||
TWI0_SCL = PI5
|
||||
PI6 = Pin((__chip_num, 262))
|
||||
TWI0_SDA = PI6
|
||||
PI7 = Pin((__chip_num, 263))
|
||||
TWI1_SCL = PI7
|
||||
PI8 = Pin((__chip_num, 264))
|
||||
TWI1_SDA = PI8
|
||||
PI9 = Pin((__chip_num, 265))
|
||||
UART3_TX = PI9
|
||||
PI10 = Pin((__chip_num, 266))
|
||||
UART3_RX = PI10
|
||||
PI11 = Pin((__chip_num, 267))
|
||||
PI12 = Pin((__chip_num, 268))
|
||||
PWM2 = PI12
|
||||
PI13 = Pin((__chip_num, 269))
|
||||
UART4_TX = PI13
|
||||
PI14 = Pin((__chip_num, 270))
|
||||
UART4_RX = PI14
|
||||
PI15 = Pin((__chip_num, 271))
|
||||
PI16 = Pin((__chip_num, 272))
|
||||
|
||||
i2cPorts = (
|
||||
(0, TWI0_SCL, TWI0_SDA),
|
||||
(1, TWI1_SCL, TWI1_SDA),
|
||||
(3, TWI3_SCL, TWI3_SDA),
|
||||
(4, TWI4_SCL, TWI4_SDA),
|
||||
)
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = (
|
||||
(0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),
|
||||
(1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO),
|
||||
)
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = (
|
||||
(1, UART1_TX, UART1_RX),
|
||||
(2, UART2_TX, UART2_RX),
|
||||
(3, UART3_TX, UART3_RX),
|
||||
(4, UART4_TX, UART4_RX),
|
||||
(5, UART5_TX, UART5_RX),
|
||||
)
|
||||
|
||||
# SysFS pwm outputs, pwm channel and pin in first tuple
|
||||
pwmOuts = [
|
||||
((0, 1), PWM1),
|
||||
((0, 2), PWM2),
|
||||
]
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Definition for the AllWinner T527 chip"""
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,306 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Allwinner T527 Pin Names"""
|
||||
import gpiod
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
chip0 = gpiod.Chip("/dev/gpiochip0")
|
||||
chip1 = gpiod.Chip("/dev/gpiochip1")
|
||||
num = chip0.get_info().num_lines
|
||||
|
||||
if num < 100:
|
||||
__chip_num = 1
|
||||
__chip_r_num = 0
|
||||
else:
|
||||
__chip_num = 0
|
||||
__chip_r_num = 1
|
||||
|
||||
chip0.close()
|
||||
chip1.close()
|
||||
|
||||
PB0 = Pin((__chip_num, 32))
|
||||
PB1 = Pin((__chip_num, 33))
|
||||
PB2 = Pin((__chip_num, 34))
|
||||
PB3 = Pin((__chip_num, 35))
|
||||
PB4 = Pin((__chip_num, 36))
|
||||
PB5 = Pin((__chip_num, 37))
|
||||
PB6 = Pin((__chip_num, 38))
|
||||
PB7 = Pin((__chip_num, 39))
|
||||
PB8 = Pin((__chip_num, 40))
|
||||
PB9 = Pin((__chip_num, 41))
|
||||
PB10 = Pin((__chip_num, 42))
|
||||
PB11 = Pin((__chip_num, 43))
|
||||
PB12 = Pin((__chip_num, 44))
|
||||
PB13 = Pin((__chip_num, 45))
|
||||
PB14 = Pin((__chip_num, 46))
|
||||
|
||||
PC0 = Pin((__chip_num, 64))
|
||||
PC1 = Pin((__chip_num, 65))
|
||||
PC2 = Pin((__chip_num, 66))
|
||||
PC3 = Pin((__chip_num, 67))
|
||||
PC4 = Pin((__chip_num, 68))
|
||||
PC5 = Pin((__chip_num, 69))
|
||||
PC6 = Pin((__chip_num, 70))
|
||||
PC7 = Pin((__chip_num, 71))
|
||||
PC8 = Pin((__chip_num, 72))
|
||||
PC9 = Pin((__chip_num, 73))
|
||||
PC10 = Pin((__chip_num, 74))
|
||||
PC11 = Pin((__chip_num, 75))
|
||||
PC12 = Pin((__chip_num, 76))
|
||||
PC13 = Pin((__chip_num, 77))
|
||||
PC14 = Pin((__chip_num, 78))
|
||||
PC15 = Pin((__chip_num, 79))
|
||||
PC16 = Pin((__chip_num, 80))
|
||||
|
||||
PD0 = Pin((__chip_num, 96))
|
||||
PD1 = Pin((__chip_num, 97))
|
||||
PD2 = Pin((__chip_num, 98))
|
||||
PD3 = Pin((__chip_num, 99))
|
||||
PD4 = Pin((__chip_num, 100))
|
||||
PD5 = Pin((__chip_num, 101))
|
||||
PD6 = Pin((__chip_num, 102))
|
||||
PD7 = Pin((__chip_num, 103))
|
||||
PD8 = Pin((__chip_num, 104))
|
||||
PD9 = Pin((__chip_num, 105))
|
||||
PD10 = Pin((__chip_num, 106))
|
||||
PD11 = Pin((__chip_num, 107))
|
||||
PD12 = Pin((__chip_num, 108))
|
||||
PD13 = Pin((__chip_num, 109))
|
||||
PD14 = Pin((__chip_num, 110))
|
||||
PD15 = Pin((__chip_num, 111))
|
||||
PD16 = Pin((__chip_num, 112))
|
||||
PD17 = Pin((__chip_num, 113))
|
||||
PD18 = Pin((__chip_num, 114))
|
||||
PD19 = Pin((__chip_num, 115))
|
||||
PD20 = Pin((__chip_num, 116))
|
||||
PD21 = Pin((__chip_num, 117))
|
||||
PD22 = Pin((__chip_num, 118))
|
||||
PD23 = Pin((__chip_num, 119))
|
||||
|
||||
PE0 = Pin((__chip_num, 128))
|
||||
PE1 = Pin((__chip_num, 129))
|
||||
PE2 = Pin((__chip_num, 130))
|
||||
PE3 = Pin((__chip_num, 131))
|
||||
PE4 = Pin((__chip_num, 132))
|
||||
PE5 = Pin((__chip_num, 133))
|
||||
PE6 = Pin((__chip_num, 134))
|
||||
PE7 = Pin((__chip_num, 135))
|
||||
PE8 = Pin((__chip_num, 136))
|
||||
PE9 = Pin((__chip_num, 137))
|
||||
PE10 = Pin((__chip_num, 138))
|
||||
PE11 = Pin((__chip_num, 139))
|
||||
PE12 = Pin((__chip_num, 140))
|
||||
PE13 = Pin((__chip_num, 141))
|
||||
PE14 = Pin((__chip_num, 142))
|
||||
PE15 = Pin((__chip_num, 143))
|
||||
|
||||
PF0 = Pin((__chip_num, 160))
|
||||
PF1 = Pin((__chip_num, 161))
|
||||
PF2 = Pin((__chip_num, 162))
|
||||
PF3 = Pin((__chip_num, 163))
|
||||
PF4 = Pin((__chip_num, 164))
|
||||
PF5 = Pin((__chip_num, 165))
|
||||
PF6 = Pin((__chip_num, 166))
|
||||
|
||||
PG0 = Pin((__chip_num, 192))
|
||||
PG1 = Pin((__chip_num, 193))
|
||||
PG2 = Pin((__chip_num, 194))
|
||||
PG3 = Pin((__chip_num, 195))
|
||||
PG4 = Pin((__chip_num, 196))
|
||||
PG5 = Pin((__chip_num, 197))
|
||||
PG6 = Pin((__chip_num, 198))
|
||||
PG7 = Pin((__chip_num, 199))
|
||||
PG8 = Pin((__chip_num, 200))
|
||||
PG9 = Pin((__chip_num, 201))
|
||||
PG10 = Pin((__chip_num, 202))
|
||||
PG11 = Pin((__chip_num, 203))
|
||||
PG12 = Pin((__chip_num, 204))
|
||||
PG13 = Pin((__chip_num, 205))
|
||||
PG14 = Pin((__chip_num, 206))
|
||||
|
||||
PH0 = Pin((__chip_num, 224))
|
||||
PH1 = Pin((__chip_num, 225))
|
||||
PH2 = Pin((__chip_num, 226))
|
||||
PH3 = Pin((__chip_num, 227))
|
||||
PH4 = Pin((__chip_num, 228))
|
||||
PH5 = Pin((__chip_num, 229))
|
||||
PH6 = Pin((__chip_num, 230))
|
||||
PH7 = Pin((__chip_num, 231))
|
||||
PH8 = Pin((__chip_num, 232))
|
||||
PH9 = Pin((__chip_num, 233))
|
||||
PH10 = Pin((__chip_num, 234))
|
||||
PH11 = Pin((__chip_num, 235))
|
||||
PH12 = Pin((__chip_num, 236))
|
||||
PH13 = Pin((__chip_num, 237))
|
||||
PH14 = Pin((__chip_num, 238))
|
||||
PH15 = Pin((__chip_num, 239))
|
||||
PH16 = Pin((__chip_num, 240))
|
||||
PH17 = Pin((__chip_num, 241))
|
||||
PH18 = Pin((__chip_num, 242))
|
||||
PH19 = Pin((__chip_num, 243))
|
||||
|
||||
PI0 = Pin((__chip_num, 256))
|
||||
PI1 = Pin((__chip_num, 257))
|
||||
PI2 = Pin((__chip_num, 258))
|
||||
PI3 = Pin((__chip_num, 259))
|
||||
PI4 = Pin((__chip_num, 260))
|
||||
PI5 = Pin((__chip_num, 261))
|
||||
PI6 = Pin((__chip_num, 262))
|
||||
PI7 = Pin((__chip_num, 263))
|
||||
PI8 = Pin((__chip_num, 264))
|
||||
PI9 = Pin((__chip_num, 265))
|
||||
PI10 = Pin((__chip_num, 266))
|
||||
PI11 = Pin((__chip_num, 267))
|
||||
PI12 = Pin((__chip_num, 268))
|
||||
PI13 = Pin((__chip_num, 269))
|
||||
PI14 = Pin((__chip_num, 270))
|
||||
PI15 = Pin((__chip_num, 271))
|
||||
PI16 = Pin((__chip_num, 272))
|
||||
|
||||
PJ0 = Pin((__chip_num, 288))
|
||||
PJ1 = Pin((__chip_num, 289))
|
||||
PJ2 = Pin((__chip_num, 290))
|
||||
PJ3 = Pin((__chip_num, 291))
|
||||
PJ4 = Pin((__chip_num, 292))
|
||||
PJ5 = Pin((__chip_num, 293))
|
||||
PJ6 = Pin((__chip_num, 294))
|
||||
PJ7 = Pin((__chip_num, 295))
|
||||
PJ8 = Pin((__chip_num, 296))
|
||||
PJ9 = Pin((__chip_num, 297))
|
||||
PJ10 = Pin((__chip_num, 298))
|
||||
PJ11 = Pin((__chip_num, 299))
|
||||
PJ12 = Pin((__chip_num, 300))
|
||||
PJ13 = Pin((__chip_num, 301))
|
||||
PJ14 = Pin((__chip_num, 302))
|
||||
PJ15 = Pin((__chip_num, 303))
|
||||
PJ16 = Pin((__chip_num, 304))
|
||||
PJ17 = Pin((__chip_num, 305))
|
||||
PJ18 = Pin((__chip_num, 306))
|
||||
PJ19 = Pin((__chip_num, 307))
|
||||
PJ20 = Pin((__chip_num, 308))
|
||||
PJ21 = Pin((__chip_num, 309))
|
||||
PJ22 = Pin((__chip_num, 310))
|
||||
PJ23 = Pin((__chip_num, 311))
|
||||
PJ24 = Pin((__chip_num, 312))
|
||||
PJ25 = Pin((__chip_num, 313))
|
||||
PJ26 = Pin((__chip_num, 314))
|
||||
PJ27 = Pin((__chip_num, 315))
|
||||
|
||||
PK0 = Pin((__chip_num, 320))
|
||||
PK1 = Pin((__chip_num, 321))
|
||||
PK2 = Pin((__chip_num, 322))
|
||||
PK3 = Pin((__chip_num, 323))
|
||||
PK4 = Pin((__chip_num, 324))
|
||||
PK5 = Pin((__chip_num, 325))
|
||||
PK6 = Pin((__chip_num, 326))
|
||||
PK7 = Pin((__chip_num, 327))
|
||||
PK8 = Pin((__chip_num, 328))
|
||||
PK9 = Pin((__chip_num, 329))
|
||||
PK10 = Pin((__chip_num, 330))
|
||||
PK11 = Pin((__chip_num, 331))
|
||||
PK12 = Pin((__chip_num, 332))
|
||||
PK13 = Pin((__chip_num, 333))
|
||||
PK14 = Pin((__chip_num, 334))
|
||||
PK15 = Pin((__chip_num, 335))
|
||||
PK16 = Pin((__chip_num, 336))
|
||||
PK17 = Pin((__chip_num, 337))
|
||||
PK18 = Pin((__chip_num, 338))
|
||||
PK19 = Pin((__chip_num, 339))
|
||||
PK20 = Pin((__chip_num, 340))
|
||||
PK21 = Pin((__chip_num, 341))
|
||||
PK22 = Pin((__chip_num, 342))
|
||||
PK23 = Pin((__chip_num, 343))
|
||||
|
||||
PL0 = Pin((__chip_r_num, 0))
|
||||
PL1 = Pin((__chip_r_num, 1))
|
||||
PL2 = Pin((__chip_r_num, 2))
|
||||
PL3 = Pin((__chip_r_num, 3))
|
||||
PL4 = Pin((__chip_r_num, 4))
|
||||
PL5 = Pin((__chip_r_num, 5))
|
||||
PL6 = Pin((__chip_r_num, 6))
|
||||
PL7 = Pin((__chip_r_num, 7))
|
||||
PL8 = Pin((__chip_r_num, 8))
|
||||
PL9 = Pin((__chip_r_num, 9))
|
||||
PL10 = Pin((__chip_r_num, 10))
|
||||
PL11 = Pin((__chip_r_num, 11))
|
||||
PL12 = Pin((__chip_r_num, 12))
|
||||
PL13 = Pin((__chip_r_num, 13))
|
||||
|
||||
PM0 = Pin((__chip_r_num, 32))
|
||||
PM1 = Pin((__chip_r_num, 33))
|
||||
PM2 = Pin((__chip_r_num, 34))
|
||||
PM3 = Pin((__chip_r_num, 35))
|
||||
PM4 = Pin((__chip_r_num, 36))
|
||||
PM5 = Pin((__chip_r_num, 37))
|
||||
|
||||
# I2C
|
||||
I2C1_SCL = PB4
|
||||
I2C1_SDA = PB5
|
||||
I2C4_SCL = PI0
|
||||
I2C4_SDA = PI1
|
||||
I2C5_SCL = PI8
|
||||
I2C5_SDA = PI9
|
||||
|
||||
i2cPorts = (
|
||||
(1, I2C1_SCL, I2C1_SDA),
|
||||
(4, I2C4_SCL, I2C4_SDA),
|
||||
(5, I2C5_SCL, I2C5_SDA),
|
||||
)
|
||||
|
||||
# SPI
|
||||
SPI1_MOSI = PI4
|
||||
SPI1_MISO = PI5
|
||||
SPI1_SCLK = PI3
|
||||
SPI1_CS0 = PI2
|
||||
SPI2_MOSI = PB2
|
||||
SPI2_MISO = PB3
|
||||
SPI2_SCLK = PB1
|
||||
SPI2_CS0 = PB0
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = (
|
||||
(1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO),
|
||||
(2, SPI2_SCLK, SPI2_MOSI, SPI2_MISO),
|
||||
)
|
||||
|
||||
# UART
|
||||
UART2_TX = PB0
|
||||
UART2_RX = PB1
|
||||
UART3_TX = PI11
|
||||
UART3_RX = PI12
|
||||
UART4_TX = PI0
|
||||
UART4_RX = PI1
|
||||
UART5_TX = PI2
|
||||
UART5_RX = PI3
|
||||
UART6_TX = PI6
|
||||
UART6_RX = PI7
|
||||
UART7_TX = PB13
|
||||
UART7_RX = PB14
|
||||
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = (
|
||||
(2, UART2_TX, UART2_RX),
|
||||
(3, UART3_TX, UART3_RX),
|
||||
(4, UART4_TX, UART4_RX),
|
||||
(5, UART5_TX, UART5_RX),
|
||||
(6, UART6_TX, UART6_RX),
|
||||
(7, UART7_TX, UART7_RX),
|
||||
)
|
||||
|
||||
# SysFS pwm outputs, pwm channel and pin in first tuple
|
||||
pwmOuts = [
|
||||
((0, 1), PI0),
|
||||
((0, 2), PI1),
|
||||
((0, 3), PI2),
|
||||
((0, 4), PI3),
|
||||
((0, 5), PI4),
|
||||
((0, 6), PI5),
|
||||
((0, 7), PI6),
|
||||
((0, 8), PI7),
|
||||
((0, 9), PI8),
|
||||
((0, 10), PI9),
|
||||
((0, 11), PI10),
|
||||
((0, 12), PI11),
|
||||
((0, 13), PI12),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,366 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""AM335x pin names"""
|
||||
try:
|
||||
from Adafruit_BBIO import GPIO
|
||||
except ImportError as error:
|
||||
raise RuntimeError(
|
||||
"The library 'Adafruit_BBIO' was not found. To install, try typing: "
|
||||
"pip install Adafruit_BBIO"
|
||||
) from error
|
||||
|
||||
|
||||
class Pin:
|
||||
"""Pins dont exist in CPython so...lets make our own!"""
|
||||
|
||||
IN = 0
|
||||
OUT = 1
|
||||
LOW = 0
|
||||
HIGH = 1
|
||||
PULL_NONE = 0
|
||||
PULL_UP = 1
|
||||
PULL_DOWN = 2
|
||||
|
||||
id = None
|
||||
_value = LOW
|
||||
_mode = IN
|
||||
|
||||
def __init__(self, pin_name):
|
||||
self.id = pin_name
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.id)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.id == other
|
||||
|
||||
def init(self, mode=IN, pull=None):
|
||||
"""Initialize the Pin"""
|
||||
if mode is not None:
|
||||
if mode == self.IN:
|
||||
self._mode = self.IN
|
||||
GPIO.setup(self.id, GPIO.IN)
|
||||
elif mode == self.OUT:
|
||||
self._mode = self.OUT
|
||||
GPIO.setup(self.id, GPIO.OUT)
|
||||
else:
|
||||
raise RuntimeError("Invalid mode for pin: %s" % self.id)
|
||||
if pull is not None:
|
||||
if self._mode != self.IN:
|
||||
raise RuntimeError("Cannot set pull resistor on output")
|
||||
if pull == self.PULL_UP:
|
||||
GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
elif pull == self.PULL_DOWN:
|
||||
GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
else:
|
||||
raise RuntimeError("Invalid pull for pin: %s" % self.id)
|
||||
|
||||
def value(self, val=None):
|
||||
"""Set or return the Pin Value"""
|
||||
if val is not None:
|
||||
if val == self.LOW:
|
||||
self._value = val
|
||||
GPIO.output(self.id, val)
|
||||
elif val == self.HIGH:
|
||||
self._value = val
|
||||
GPIO.output(self.id, val)
|
||||
else:
|
||||
raise RuntimeError("Invalid value for pin")
|
||||
return None
|
||||
return GPIO.input(self.id)
|
||||
|
||||
|
||||
# names in comments copied from
|
||||
# https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/source/common.c#L73
|
||||
|
||||
# PocketBeagle
|
||||
# P1_1 = SYS VIN # VIN_AC
|
||||
P1_2 = Pin("P1_2") # GPIO2_23 - GPIO_87
|
||||
P1_3 = Pin("P1_3") # USB1_VBUS_OUT - (silkscreen: USB1 V_EN)
|
||||
P1_4 = Pin("P1_4") # GPIO2_25 - GPIO_89
|
||||
# P1_5 = USB VBUS # USB1_VBUS_IN
|
||||
P1_6 = Pin("P1_6") # SPI0_CS0 - GPIO_5
|
||||
# P1_7 = USB VIN # VIN-USB
|
||||
P1_8 = Pin("P1_8") # SPI0_SCLK - GPIO_2
|
||||
# P1_9 = USB1 DN # USB1-DN
|
||||
P1_10 = Pin("P1_10") # SPI0_D0 - GPIO_3
|
||||
# P1_11 = USB1 DP # USB1-DP
|
||||
P1_12 = Pin("P1_12") # SPI0_D1 - GPIO_4
|
||||
# P1_13 = USB1 ID # USB1-ID
|
||||
# P1_14 = SYS 3.3V # VOUT-3.3V
|
||||
# P1_15 = SYS GND # GND
|
||||
# P1_16 = SYS GND # GND
|
||||
# P1_17 = AIN 1.8V REF- # VREFN
|
||||
# P1_18 = AIN 1.8V REF+ # VREFP
|
||||
P1_19 = Pin("P1_19") # AIN0
|
||||
P1_20 = Pin("P1_20") # GPIO0_20 - GPIO_20
|
||||
P1_21 = Pin("P1_21") # AIN1
|
||||
# P1_22 = SYS GND # GND
|
||||
P1_23 = Pin("P1_23") # AIN2
|
||||
# P1_22 = SYS VOUT # VOUT-5V
|
||||
P1_25 = Pin("P1_25") # AIN3
|
||||
P1_26 = Pin("P1_26") # I2C2_SDA - GPIO_12
|
||||
P1_27 = Pin("P1_27") # AIN4
|
||||
P1_28 = Pin("P1_28") # I2C2_SCL - GPIO_13
|
||||
P1_29 = Pin("P1_29") # GPIO3_21 - GPIO_117
|
||||
P1_30 = Pin("P1_30") # UART0_TXD - GPIO_43
|
||||
P1_31 = Pin("P1_31") # GPIO3_18 - GPIO_114
|
||||
P1_32 = Pin("P1_32") # UART0_RXD - GPIO_42
|
||||
P1_33 = Pin("P1_33") # GPIO3_15 - GPIO_111
|
||||
P1_34 = Pin("P1_34") # GPIO0_26 - GPIO_26
|
||||
P1_35 = Pin("P1_35") # GPIO2_24 - GPIO_88
|
||||
P1_36 = Pin("P1_36") # EHRPWM0A - GPIO_110
|
||||
|
||||
|
||||
P2_1 = Pin("P2_1") # EHRPWM1A - GPIO_50
|
||||
P2_2 = Pin("P2_2") # GPIO1_27 - GPIO_59
|
||||
P2_3 = Pin("P2_3") # GPIO0_23 - GPIO_23
|
||||
P2_4 = Pin("P2_4") # GPIO1_26 - GPIO_58
|
||||
P2_5 = Pin("P2_5") # UART4_RXD - GPIO_30
|
||||
P2_6 = Pin("P2_6") # GPIO1_25 - GPIO_57
|
||||
P2_7 = Pin("P2_7") # UART4_TXD - GPIO_31
|
||||
P2_8 = Pin("P2_8") # GPIO1_28 - GPIO_60
|
||||
P2_9 = Pin("P2_9") # I2C1_SCL - GPIO_15
|
||||
P2_10 = Pin("P2_10") # GPIO1_20 - GPIO_52
|
||||
P2_11 = Pin("P2_11") # I2C1_SDA - GPIO_14
|
||||
# P2_12 = SYS PWR BTN # POWER_BUTTON
|
||||
# P2_13 = SYS VOUT # VOUT-5V
|
||||
# P2_14 = BAT VIN # BAT-VIN
|
||||
# P2_15 = SYS GND # GND
|
||||
# P2_16 = BAT TEMP # BAT-TEMP
|
||||
P2_17 = Pin("P2_17") # GPIO2_1 - GPIO_65
|
||||
P2_18 = Pin("P2_18") # GPIO1_15 - GPIO_47
|
||||
P2_19 = Pin("P2_19") # GPIO0_27 - GPIO_27
|
||||
P2_20 = Pin("P2_20") # GPIO2_0 - GPIO_64
|
||||
# P2_21 = SYS GND # GND
|
||||
P2_22 = Pin("P2_22") # GPIO1_14 - GPIO_46
|
||||
# P2_23 = SYS 3.3V # VOUT-3.3V
|
||||
P2_24 = Pin("P2_24") # GPIO1_12 - GPIO_44
|
||||
P2_25 = Pin("P2_25") # SPI1_D1 - GPIO_41
|
||||
# P2_26 = SYS NRST # RESET#
|
||||
P2_27 = Pin("P2_27") # SPI1_D0 - GPIO_40
|
||||
P2_28 = Pin("P2_28") # GPIO3_20 - GPIO_116
|
||||
P2_29 = Pin("P2_29") # SPI1_SCLK - GPIO_7
|
||||
P2_30 = Pin("P2_30") # GPIO3_17 - GPIO_113
|
||||
P2_31 = Pin("P2_31") # SPI1_CS1 - GPIO_19
|
||||
P2_32 = Pin("P2_32") # GPIO3_16 - GPIO_112
|
||||
P2_33 = Pin("P2_33") # GPIO1_13 - GPIO_45
|
||||
P2_34 = Pin("P2_34") # GPIO3_19 - GPIO_115
|
||||
P2_35 = Pin("P2_35") # GPIO2_22 - GPIO_86
|
||||
P2_36 = Pin("P2_36") # AIN7
|
||||
|
||||
|
||||
# BeagleBone Black
|
||||
# P8_1 = DGND # DGND - GPIO_0
|
||||
# P8_2 = DGND # DGND - GPIO_0
|
||||
P8_3 = Pin("P8_3") # GPIO1_6 - GPIO_38
|
||||
P8_4 = Pin("P8_4") # GPIO1_7 - GPIO_39
|
||||
P8_5 = Pin("P8_5") # GPIO1_2 - GPIO_34
|
||||
P8_6 = Pin("P8_6") # GPIO1_3 - GPIO_35
|
||||
P8_7 = Pin("P8_7") # TIMER4 - GPIO_66
|
||||
P8_8 = Pin("P8_8") # TIMER7 - GPIO_67
|
||||
P8_9 = Pin("P8_9") # TIMER5 - GPIO_69
|
||||
P8_10 = Pin("P8_10") # TIMER6 - GPIO_68
|
||||
P8_11 = Pin("P8_11") # GPIO1_13 - GPIO_45
|
||||
P8_12 = Pin("P8_12") # GPIO1_12 - GPIO_44
|
||||
P8_13 = Pin("P8_13") # EHRPWM2B - GPIO_23
|
||||
P8_14 = Pin("P8_14") # GPIO0_26 - GPIO_26
|
||||
P8_15 = Pin("P8_15") # GPIO1_15 - GPIO_47
|
||||
P8_16 = Pin("P8_16") # GPIO1_14 - GPIO_46
|
||||
P8_17 = Pin("P8_17") # GPIO0_27 - GPIO_27
|
||||
P8_18 = Pin("P8_18") # GPIO2_1 - GPIO_65
|
||||
P8_19 = Pin("P8_19") # EHRPWM2A - GPIO_22
|
||||
P8_20 = Pin("P8_20") # GPIO1_31 - GPIO_63
|
||||
P8_21 = Pin("P8_21") # GPIO1_30 - GPIO_62
|
||||
P8_22 = Pin("P8_22") # GPIO1_5 - GPIO_37
|
||||
P8_23 = Pin("P8_23") # GPIO1_4 - GPIO_36
|
||||
P8_24 = Pin("P8_24") # GPIO1_1 - GPIO_33
|
||||
P8_25 = Pin("P8_25") # GPIO1_0 - GPIO_32
|
||||
P8_26 = Pin("P8_26") # GPIO1_29 - GPIO_61
|
||||
P8_27 = Pin("P8_27") # GPIO2_22 - GPIO_86
|
||||
P8_28 = Pin("P8_28") # GPIO2_24 - GPIO_88
|
||||
P8_29 = Pin("P8_29") # GPIO2_23 - GPIO_87
|
||||
P8_30 = Pin("P8_30") # GPIO2_25 - GPIO_89
|
||||
P8_31 = Pin("P8_31") # UART5_CTSN - GPIO_10
|
||||
P8_32 = Pin("P8_32") # UART5_RTSN - GPIO_11
|
||||
P8_33 = Pin("P8_33") # UART4_RTSN - GPIO_9
|
||||
P8_34 = Pin("P8_34") # UART3_RTSN - GPIO_81
|
||||
P8_35 = Pin("P8_35") # UART4_CTSN - GPIO_8
|
||||
P8_36 = Pin("P8_36") # UART3_CTSN - GPIO_80
|
||||
P8_37 = Pin("P8_37") # UART5_TXD - GPIO_78
|
||||
P8_38 = Pin("P8_38") # UART5_RXD - GPIO_79
|
||||
P8_39 = Pin("P8_39") # GPIO2_12 - GPIO_76
|
||||
P8_40 = Pin("P8_40") # GPIO2_13 - GPIO_77
|
||||
P8_41 = Pin("P8_41") # GPIO2_10 - GPIO_74
|
||||
P8_42 = Pin("P8_42") # GPIO2_11 - GPIO_75
|
||||
P8_43 = Pin("P8_43") # GPIO2_8 - GPIO_72
|
||||
P8_44 = Pin("P8_44") # GPIO2_9 - GPIO_73
|
||||
P8_45 = Pin("P8_45") # GPIO2_6 - GPIO_70
|
||||
P8_46 = Pin("P8_46") # GPIO2_7 - GPIO_71
|
||||
|
||||
# P9_1 = DGND # DGND - GPIO_0
|
||||
# P9_2 = DGND # DGND - GPIO_0
|
||||
# P9_3 = VDD_3V3 # VDD_3V3 - GPIO_0
|
||||
# P9_4 = VDD_3V3 # VDD_3V3 - GPIO_0
|
||||
# P9_5 = VDD_5V # VDD_5V - GPIO_0
|
||||
# P9_6 = VDD_5V # VDD_5V - GPIO_0
|
||||
# P9_7 = SYS_5V # SYS_5V - GPIO_0
|
||||
# P9_8 = SYS_5V # SYS_5V - GPIO_0
|
||||
# P9_9 = PWR_BUT # PWR_BUT - GPIO_0
|
||||
# P9_10 = SYS_RESETN # SYS_RESETn - GPIO_0
|
||||
P9_11 = Pin("P9_11") # UART4_RXD - GPIO_30
|
||||
P9_12 = Pin("P9_12") # GPIO1_28 - GPIO_60
|
||||
P9_13 = Pin("P9_13") # UART4_TXD - GPIO_31
|
||||
P9_14 = Pin("P9_14") # EHRPWM1A - GPIO_50
|
||||
P9_15 = Pin("P9_15") # GPIO1_16 - GPIO_48
|
||||
P9_16 = Pin("P9_16") # EHRPWM1B - GPIO_51
|
||||
P9_17 = Pin("P9_17") # I2C1_SCL - GPIO_5
|
||||
P9_18 = Pin("P9_18") # I2C1_SDA - GPIO_4
|
||||
P9_19 = Pin("P9_19") # I2C2_SCL - GPIO_13
|
||||
P9_20 = Pin("P9_20") # I2C2_SDA - GPIO_12
|
||||
P9_21 = Pin("P9_21") # UART2_TXD - GPIO_3
|
||||
P9_22 = Pin("P9_22") # UART2_RXD - GPIO_2
|
||||
P9_23 = Pin("P9_23") # GPIO1_17 - GPIO_49
|
||||
P9_24 = Pin("P9_24") # UART1_TXD - GPIO_15
|
||||
P9_25 = Pin("P9_25") # GPIO3_21 - GPIO_117
|
||||
P9_26 = Pin("P9_26") # UART1_RXD - GPIO_14
|
||||
P9_27 = Pin("P9_27") # GPIO3_19 - GPIO_115
|
||||
P9_28 = Pin("P9_28") # SPI1_CS0 - GPIO_113
|
||||
P9_29 = Pin("P9_29") # SPI1_D0 - GPIO_111
|
||||
P9_30 = Pin("P9_30") # SPI1_D1 - GPIO_112
|
||||
P9_31 = Pin("P9_31") # SPI1_SCLK - GPIO_110
|
||||
# P9_32 = VDD_ADC # VDD_ADC - GPIO_0
|
||||
# P9_33 = AIN4 # AIN4 - GPIO_0
|
||||
# P9_34 = GNDA_ADC # GNDA_ADC - GPIO_0
|
||||
# P9_35 = AIN6 # AIN6 - GPIO_0
|
||||
# P9_36 = AIN5 # AIN5 - GPIO_0
|
||||
# P9_37 = AIN2 # AIN2 - GPIO_0
|
||||
# P9_38 = AIN3 # AIN3 - GPIO_0
|
||||
# P9_39 = AIN0 # AIN0 - GPIO_0
|
||||
# P9_40 = AIN1 # AIN1 - GPIO_0
|
||||
P9_41 = Pin("P9_41") # CLKOUT2 - GPIO_20
|
||||
P9_42 = Pin("P9_42") # GPIO0_7 - GPIO_7
|
||||
# P9_43 = DGND # DGND - GPIO_0
|
||||
# P9_44 = DGND # DGND - GPIO_0
|
||||
# P9_45 = DGND # DGND - GPIO_0
|
||||
# P9_46 = DGND # DGND - GPIO_0
|
||||
|
||||
|
||||
##########################################
|
||||
# common to all beagles
|
||||
USR0 = Pin("USR0") # USR0 - GPIO_53
|
||||
USR1 = Pin("USR1") # USR1 - GPIO_54
|
||||
USR2 = Pin("USR2") # USR2 - GPIO_55
|
||||
USR3 = Pin("USR3") # USR3 - GPIO_56
|
||||
|
||||
|
||||
##########################################
|
||||
# specials
|
||||
|
||||
# analog input
|
||||
AIN0 = Pin("AIN0")
|
||||
AIN1 = Pin("AIN1")
|
||||
AIN2 = Pin("AIN2")
|
||||
AIN3 = Pin("AIN3")
|
||||
AIN4 = Pin("AIN4")
|
||||
AIN5 = Pin("AIN5")
|
||||
AIN6 = Pin("AIN6")
|
||||
AIN7 = Pin("AIN7")
|
||||
|
||||
# PWM
|
||||
EHRPWM0A = Pin("EHRPWM0A")
|
||||
EHRPWM0B = Pin("EHRPWM0B")
|
||||
EHRPWM1A = Pin("EHRPWM1A")
|
||||
EHRPWM1B = Pin("EHRPWM1B")
|
||||
EHRPWM2A = Pin("EHRPWM2A")
|
||||
EHRPWM2B = Pin("EHRPWM2B")
|
||||
ECAPPWM0 = Pin("ECAPPWM0")
|
||||
ECAPPWM2 = Pin("ECAPPWM2")
|
||||
TIMER4 = Pin("TIMER4")
|
||||
TIMER5 = Pin("TIMER5")
|
||||
TIMER6 = Pin("TIMER6")
|
||||
TIMER7 = Pin("TIMER7")
|
||||
|
||||
|
||||
# I2C1
|
||||
I2C1_SDA = Pin("I2C1_SDA")
|
||||
I2C1_SCL = Pin("I2C1_SCL")
|
||||
|
||||
# I2C2
|
||||
I2C2_SDA = Pin("I2C2_SDA")
|
||||
I2C2_SCL = Pin("I2C2_SCL")
|
||||
|
||||
# SPI0
|
||||
SPI0_CS0 = Pin("SPI0_CS0")
|
||||
SPI0_SCLK = Pin("SPI0_SCLK")
|
||||
SPI0_D1 = Pin("SPI0_D1")
|
||||
SPI0_D0 = Pin("SPI0_D0")
|
||||
|
||||
# SPI1
|
||||
SPI1_CS0 = Pin("SPI1_CS0")
|
||||
SPI1_CS1 = Pin("SPI1_CS1")
|
||||
SPI1_SCLK = Pin("SPI1_SCLK")
|
||||
SPI1_D1 = Pin("SPI1_D1")
|
||||
SPI1_D0 = Pin("SPI1_D0")
|
||||
|
||||
# UART0
|
||||
UART0_TXD = Pin("UART0_TXD")
|
||||
UART0_RXD = Pin("UART0_RXD")
|
||||
|
||||
# UART1
|
||||
UART1_TXD = Pin("UART1_TXD")
|
||||
UART1_RXD = Pin("UART1_RXD")
|
||||
UART1_RTSn = Pin("UART1_RTSn")
|
||||
UART1_CTSn = Pin("UART1_CTSn")
|
||||
|
||||
# UART2
|
||||
UART2_TXD = Pin("UART2_TXD")
|
||||
UART2_RXD = Pin("UART2_RXD")
|
||||
|
||||
# UART3
|
||||
UART3_TXD = Pin("UART3_TXD")
|
||||
UART3_RXD = Pin("UART3_RXD")
|
||||
UART3_RTSn = Pin("UART3_RTSn")
|
||||
UART3_CTSn = Pin("UART3_CTSn")
|
||||
|
||||
# UART4
|
||||
UART4_TXD = Pin("UART4_TXD")
|
||||
UART4_RXD = Pin("UART4_RXD")
|
||||
UART4_RTSn = Pin("UART4_RTSn")
|
||||
UART4_CTSn = Pin("UART4_CTSn")
|
||||
|
||||
# UART5
|
||||
UART5_TXD = Pin("UART5_TXD")
|
||||
UART5_RXD = Pin("UART5_RXD")
|
||||
UART5_RTSn = Pin("UART5_RTSn")
|
||||
UART5_CTSn = Pin("UART5_CTSn")
|
||||
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = (
|
||||
(0, SPI0_SCLK, SPI0_D1, SPI0_D0),
|
||||
(1, SPI1_SCLK, SPI1_D1, SPI1_D0),
|
||||
)
|
||||
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = (
|
||||
# (0, UART0_TXD, UART0_RXD),
|
||||
# (1, UART1_TXD, UART1_RXD),
|
||||
# (2, UART2_TXD, UART2_RXD),
|
||||
# (4, UART4_TXD, UART4_RXD),
|
||||
# (5, UART5_TXD, UART5_RXD),
|
||||
)
|
||||
|
||||
# ordered as i2cId, SCL, SDA
|
||||
i2cPorts = (
|
||||
(1, I2C1_SCL, I2C1_SDA),
|
||||
(2, I2C2_SCL, I2C2_SDA),
|
||||
)
|
||||
|
||||
PWM1 = P1_36
|
||||
PWM2 = P1_33
|
||||
PWM3 = P2_1
|
||||
PWM4 = P2_3
|
||||
|
||||
pwmOuts = (((0, 0), PWM1), ((0, 1), PWM2), ((2, 0), PWM3), ((4, 1), PWM4))
|
|
@ -0,0 +1,336 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""
|
||||
Much code from https://github.com/vsergeev/python-periphery/blob/master/periphery/pwm.py
|
||||
Copyright (c) 2015-2016 vsergeev / Ivan (Vanya) A. Sergeev
|
||||
License: MIT
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
try:
|
||||
from microcontroller.pin import pwmOuts
|
||||
except ImportError:
|
||||
raise RuntimeError("No PWM outputs defined for this board") from ImportError
|
||||
|
||||
|
||||
# pylint: disable=unnecessary-pass
|
||||
class PWMError(IOError):
|
||||
"""Base class for PWM errors."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# pylint: enable=unnecessary-pass
|
||||
|
||||
|
||||
class PWMOut:
|
||||
"""Pulse Width Modulation Output Class"""
|
||||
|
||||
# Sysfs paths
|
||||
_sysfs_path = "/sys/class/pwm/"
|
||||
_channel_path = "pwmchip{}"
|
||||
|
||||
# Channel paths
|
||||
_export_path = "export"
|
||||
_unexport_path = "unexport"
|
||||
_pin_path = "pwm-{}:{}"
|
||||
|
||||
# Pin attribute paths
|
||||
_pin_period_path = "period"
|
||||
_pin_duty_cycle_path = "duty_cycle"
|
||||
_pin_polarity_path = "polarity"
|
||||
_pin_enable_path = "enable"
|
||||
|
||||
def __init__(self, pin, *, frequency=500, duty_cycle=0, variable_frequency=False):
|
||||
"""Instantiate a PWM object and open the sysfs PWM corresponding to the
|
||||
specified channel and pin.
|
||||
|
||||
Args:
|
||||
pin (Pin): CircuitPython Pin object to output to
|
||||
duty_cycle (int) : The fraction of each pulse which is high. 16-bit
|
||||
frequency (int) : target frequency in Hertz (32-bit)
|
||||
variable_frequency (bool) : True if the frequency will change over time
|
||||
|
||||
Returns:
|
||||
PWMOut: PWMOut object.
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if `channel` or `pin` types are invalid.
|
||||
ValueError: if PWM channel does not exist.
|
||||
|
||||
"""
|
||||
|
||||
self._pwmpin = None
|
||||
self._channel = None
|
||||
self._period = 0
|
||||
self._open(pin, duty_cycle, frequency, variable_frequency)
|
||||
|
||||
def __del__(self):
|
||||
self.deinit()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, t, value, traceback):
|
||||
self.deinit()
|
||||
|
||||
def _open(self, pin, duty=0, freq=500, variable_frequency=False):
|
||||
self._channel = None
|
||||
for pwmpair in pwmOuts:
|
||||
if pwmpair[1] == pin:
|
||||
self._channel = pwmpair[0][0]
|
||||
self._pwmpin = pwmpair[0][1]
|
||||
|
||||
self._pin = pin
|
||||
if self._channel is None:
|
||||
raise RuntimeError("No PWM channel found for this Pin")
|
||||
|
||||
if variable_frequency:
|
||||
print("Variable Frequency is not supported, continuing without it...")
|
||||
|
||||
channel_path = os.path.join(
|
||||
self._sysfs_path, self._channel_path.format(self._channel)
|
||||
)
|
||||
if not os.path.isdir(channel_path):
|
||||
raise ValueError(
|
||||
"PWM channel does not exist, check that the required modules are loaded."
|
||||
)
|
||||
|
||||
pin_path = os.path.join(
|
||||
channel_path, self._pin_path.format(self._channel, self._pwmpin)
|
||||
)
|
||||
if not os.path.isdir(pin_path):
|
||||
try:
|
||||
with open(
|
||||
os.path.join(channel_path, self._export_path), "w", encoding="utf-8"
|
||||
) as f_export:
|
||||
f_export.write("%d\n" % self._pwmpin)
|
||||
except IOError as e:
|
||||
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()
|
||||
|
||||
# set frequency
|
||||
self.frequency = freq
|
||||
# set duty
|
||||
self.duty_cycle = duty
|
||||
|
||||
self._set_enabled(True)
|
||||
|
||||
def deinit(self):
|
||||
"""Deinit the sysfs PWM."""
|
||||
# pylint: disable=broad-except
|
||||
try:
|
||||
channel_path = os.path.join(
|
||||
self._sysfs_path, self._channel_path.format(self._channel)
|
||||
)
|
||||
|
||||
if self._channel is not None:
|
||||
# self.duty_cycle = 0
|
||||
self._set_enabled(False) # make to disable before unexport
|
||||
try:
|
||||
# unexport_path = os.path.join(channel_path, self._unexport_path)
|
||||
with open(
|
||||
os.path.join(channel_path, self._unexport_path),
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
) as f_unexport:
|
||||
f_unexport.write("%d\n" % self._pwmpin)
|
||||
except IOError as e:
|
||||
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
|
||||
# but it does not effect future usage of the pwm pin
|
||||
print(
|
||||
"warning: failed to deinitialize pwm pin {0}:{1} due to: {2}\n".format(
|
||||
self._channel, self._pwmpin, type(e).__name__
|
||||
)
|
||||
)
|
||||
finally:
|
||||
self._channel = None
|
||||
self._pwmpin = None
|
||||
# pylint: enable=broad-except
|
||||
|
||||
def _is_deinited(self):
|
||||
if self._pwmpin is None:
|
||||
raise ValueError(
|
||||
"Object has been deinitialize and can no longer "
|
||||
"be used. Create a new object."
|
||||
)
|
||||
|
||||
def _write_pin_attr(self, attr, value):
|
||||
# Make sure the pin is active
|
||||
self._is_deinited()
|
||||
|
||||
path = os.path.join(
|
||||
self._sysfs_path,
|
||||
self._channel_path.format(self._channel),
|
||||
self._pin_path.format(self._channel, self._pwmpin),
|
||||
attr,
|
||||
)
|
||||
|
||||
with open(path, "w", encoding="utf-8") as f_attr:
|
||||
f_attr.write(value + "\n")
|
||||
|
||||
def _read_pin_attr(self, attr):
|
||||
# Make sure the pin is active
|
||||
self._is_deinited()
|
||||
|
||||
path = os.path.join(
|
||||
self._sysfs_path,
|
||||
self._channel_path.format(self._channel),
|
||||
self._pin_path.format(self._channel, self._pwmpin),
|
||||
attr,
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f_attr:
|
||||
return f_attr.read().strip()
|
||||
|
||||
# Mutable properties
|
||||
|
||||
def _get_period(self):
|
||||
period_ns = self._read_pin_attr(self._pin_period_path)
|
||||
try:
|
||||
period_ns = int(period_ns)
|
||||
except ValueError:
|
||||
raise PWMError(
|
||||
None, 'Unknown period value: "%s"' % period_ns
|
||||
) from ValueError
|
||||
|
||||
# Convert period from nanoseconds to seconds
|
||||
period = period_ns / 1e9
|
||||
|
||||
# Update our cached period
|
||||
self._period = period
|
||||
|
||||
return period
|
||||
|
||||
def _set_period(self, period):
|
||||
if not isinstance(period, (int, float)):
|
||||
raise TypeError("Invalid period type, should be int or float.")
|
||||
|
||||
# Convert period from seconds to integer nanoseconds
|
||||
period_ns = int(period * 1e9)
|
||||
|
||||
self._write_pin_attr(self._pin_period_path, "{}".format(period_ns))
|
||||
|
||||
# Update our cached period
|
||||
self._period = float(period)
|
||||
|
||||
period = property(_get_period, _set_period)
|
||||
|
||||
"""Get or set the PWM's output period in seconds.
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if value type is not int or float.
|
||||
|
||||
:type: int, float
|
||||
"""
|
||||
|
||||
def _get_duty_cycle(self):
|
||||
duty_cycle_ns = self._read_pin_attr(self._pin_duty_cycle_path)
|
||||
try:
|
||||
duty_cycle_ns = int(duty_cycle_ns)
|
||||
except ValueError:
|
||||
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
|
||||
|
||||
# Convert duty cycle to ratio from 0.0 to 1.0
|
||||
duty_cycle = duty_cycle / self._period
|
||||
|
||||
# convert to 16-bit
|
||||
duty_cycle = int(duty_cycle * 65535)
|
||||
return duty_cycle
|
||||
|
||||
def _set_duty_cycle(self, duty_cycle):
|
||||
if not isinstance(duty_cycle, (int, float)):
|
||||
raise TypeError("Invalid duty cycle type, should be int or float.")
|
||||
|
||||
# convert from 16-bit
|
||||
duty_cycle /= 65535.0
|
||||
if not 0.0 <= duty_cycle <= 1.0:
|
||||
raise ValueError("Invalid duty cycle value, should be between 0.0 and 1.0.")
|
||||
|
||||
# Convert duty cycle from ratio to seconds
|
||||
duty_cycle = duty_cycle * self._period
|
||||
|
||||
# Convert duty cycle from seconds to integer nanoseconds
|
||||
duty_cycle_ns = int(duty_cycle * 1e9)
|
||||
|
||||
self._write_pin_attr(self._pin_duty_cycle_path, "{}".format(duty_cycle_ns))
|
||||
|
||||
duty_cycle = property(_get_duty_cycle, _set_duty_cycle)
|
||||
"""Get or set the PWM's output duty cycle as a ratio from 0.0 to 1.0.
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if value type is not int or float.
|
||||
ValueError: if value is out of bounds of 0.0 to 1.0.
|
||||
|
||||
:type: int, float
|
||||
"""
|
||||
|
||||
def _get_frequency(self):
|
||||
return 1.0 / self._get_period()
|
||||
|
||||
def _set_frequency(self, frequency):
|
||||
if not isinstance(frequency, (int, float)):
|
||||
raise TypeError("Invalid frequency type, should be int or float.")
|
||||
|
||||
self._set_period(1.0 / frequency)
|
||||
|
||||
frequency = property(_get_frequency, _set_frequency)
|
||||
"""Get or set the PWM's output frequency in Hertz.
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if value type is not int or float.
|
||||
|
||||
:type: int, float
|
||||
"""
|
||||
|
||||
def _get_enabled(self):
|
||||
enabled = self._read_pin_attr(self._pin_enable_path)
|
||||
|
||||
if enabled == "1":
|
||||
return True
|
||||
if enabled == "0":
|
||||
return False
|
||||
|
||||
raise PWMError(None, 'Unknown enabled value: "%s"' % enabled)
|
||||
|
||||
def _set_enabled(self, value):
|
||||
"""Get or set the PWM's output enabled state.
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if value type is not bool.
|
||||
|
||||
:type: bool
|
||||
"""
|
||||
if not isinstance(value, bool):
|
||||
raise TypeError("Invalid enabled type, should be string.")
|
||||
|
||||
self._write_pin_attr(self._pin_enable_path, "1" if value else "0")
|
||||
|
||||
# String representation
|
||||
|
||||
def __str__(self):
|
||||
return "PWM%d, pin %s (freq=%f Hz, duty_cycle=%f%%)" % (
|
||||
self._channel,
|
||||
self._pin,
|
||||
self.frequency,
|
||||
self.duty_cycle * 100,
|
||||
)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,57 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""
|
||||
`analogio` - Analog input and output control
|
||||
=================================================
|
||||
See `CircuitPython:analogio` in CircuitPython for more details.
|
||||
* Author(s): Martin Schnur
|
||||
"""
|
||||
|
||||
from adafruit_blinka.microcontroller.am65xx.pin import Pin
|
||||
from adafruit_blinka import ContextManaged
|
||||
|
||||
|
||||
class AnalogIn(ContextManaged):
|
||||
"""Analog Input Class"""
|
||||
|
||||
def __init__(self, pin):
|
||||
self._pin = Pin(pin.id)
|
||||
self._pin.init(mode=Pin.ADC)
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
"""Read the ADC and return the value"""
|
||||
return self._pin.value()
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
# emulate what CircuitPython does
|
||||
raise AttributeError("'AnalogIn' object has no attribute 'value'")
|
||||
|
||||
# pylint: enable=no-self-use
|
||||
|
||||
def deinit(self):
|
||||
del self._pin
|
||||
|
||||
|
||||
class AnalogOut(ContextManaged):
|
||||
"""Analog Output Class"""
|
||||
|
||||
def __init__(self, pin):
|
||||
self._pin = Pin(pin.id)
|
||||
self._pin.init(mode=Pin.DAC)
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
"""Return an error. This is output only."""
|
||||
# emulate what CircuitPython does
|
||||
raise AttributeError("AM65xx doesn't have an DAC! No Analog Output possible!")
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._pin.value(value)
|
||||
|
||||
def deinit(self):
|
||||
del self._pin
|
|
@ -0,0 +1,94 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Generic Linux I2C class using PureIO's smbus class"""
|
||||
from Adafruit_PureIO import smbus
|
||||
|
||||
|
||||
class I2C:
|
||||
"""I2C class"""
|
||||
|
||||
MASTER = 0
|
||||
SLAVE = 1
|
||||
_baudrate = None
|
||||
_mode = None
|
||||
_i2c_bus = None
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def __init__(self, bus_num, mode=MASTER, baudrate=None):
|
||||
if mode != self.MASTER:
|
||||
raise NotImplementedError("Only I2C Master supported!")
|
||||
_mode = self.MASTER
|
||||
|
||||
# if baudrate != None:
|
||||
# print("I2C frequency is not settable in python, ignoring!")
|
||||
|
||||
try:
|
||||
self._i2c_bus = smbus.SMBus(bus_num)
|
||||
except FileNotFoundError:
|
||||
raise RuntimeError(
|
||||
"I2C Bus #%d not found, check if enabled in config!" % bus_num
|
||||
) from RuntimeError
|
||||
|
||||
# pylint: enable=unused-argument
|
||||
|
||||
def scan(self):
|
||||
"""Try to read a byte from each address, if you get an OSError
|
||||
it means the device isnt there"""
|
||||
found = []
|
||||
for addr in range(0, 0x80):
|
||||
try:
|
||||
self._i2c_bus.read_byte(addr)
|
||||
except OSError:
|
||||
continue
|
||||
found.append(addr)
|
||||
return found
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def writeto(self, address, buffer, *, start=0, end=None, stop=True):
|
||||
"""Write data from the buffer to an address"""
|
||||
if end is None:
|
||||
end = len(buffer)
|
||||
self._i2c_bus.write_bytes(address, buffer[start:end])
|
||||
|
||||
def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
|
||||
"""Read data from an address and into the buffer"""
|
||||
if end is None:
|
||||
end = len(buffer)
|
||||
|
||||
readin = self._i2c_bus.read_bytes(address, end - start)
|
||||
for i in range(end - start):
|
||||
buffer[i + start] = readin[i]
|
||||
|
||||
# pylint: enable=unused-argument
|
||||
|
||||
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 is None:
|
||||
out_end = len(buffer_out)
|
||||
if in_end is None:
|
||||
in_end = len(buffer_in)
|
||||
if stop:
|
||||
# To generate a stop in linux, do in two transactions
|
||||
self.writeto(address, buffer_out, start=out_start, end=out_end, stop=True)
|
||||
self.readfrom_into(address, buffer_in, start=in_start, end=in_end)
|
||||
else:
|
||||
# To generate without a stop, do in one block transaction
|
||||
readin = self._i2c_bus.read_i2c_block_data(
|
||||
address, buffer_out[out_start:out_end], in_end - in_start
|
||||
)
|
||||
for i in range(in_end - in_start):
|
||||
buffer_in[i + in_start] = readin[i]
|
|
@ -0,0 +1,202 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-FileCopyrightText: 2022 Martin Schnur for Siemens AG
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""TI AM65XX pin names"""
|
||||
|
||||
import mraa
|
||||
|
||||
# pylint: disable=too-many-branches,too-many-statements
|
||||
# pylint: disable=pointless-string-statement
|
||||
|
||||
|
||||
class Pin:
|
||||
"""Pins don't exist in CPython so...lets make our own!"""
|
||||
|
||||
# pin modes
|
||||
IN = 0
|
||||
OUT = 1
|
||||
ADC = 2
|
||||
DAC = 3
|
||||
PWM = 4
|
||||
# pin values
|
||||
LOW = 0
|
||||
HIGH = 1
|
||||
# pin pulls
|
||||
PULL_NONE = 0
|
||||
PULL_UP = 1
|
||||
PULL_DOWN = 2
|
||||
|
||||
id = None
|
||||
_value = LOW
|
||||
_mode = IN
|
||||
|
||||
def __init__(self, pin_id=None):
|
||||
self.id = pin_id
|
||||
self._mode = None
|
||||
self._pull = None
|
||||
self._pin = None
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.id)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.id == other
|
||||
|
||||
def init(self, mode=IN, pull=None):
|
||||
"""Initialize the Pin"""
|
||||
if self.id is None:
|
||||
raise RuntimeError("Can not init a None type pin.")
|
||||
if mode is not None:
|
||||
if mode == self.IN:
|
||||
self._mode = self.IN
|
||||
mypin = mraa.Gpio(self.id)
|
||||
mypin.dir(mraa.DIR_IN)
|
||||
elif mode == self.OUT:
|
||||
self._mode = self.OUT
|
||||
mypin = mraa.Gpio(self.id)
|
||||
mypin.dir(mraa.DIR_OUT)
|
||||
elif mode in (self.ADC, self.DAC):
|
||||
# ADC (DAC not available) only available on Pin 0-5 (X12 Pin 1-6)
|
||||
if self.id not in (0, 1, 2, 3, 4, 5):
|
||||
raise ValueError("Pin does not have ADC capabilities")
|
||||
self._pin = mraa.Aio(self.id)
|
||||
elif mode == self.PWM:
|
||||
# PWM only available on Pin 4-9 (X10 Pin 1-2, X11 Pin 5-8)
|
||||
if self.id not in (4, 5, 6, 7, 8, 9):
|
||||
raise ValueError("Pin does not have PWM capabilities")
|
||||
return
|
||||
else:
|
||||
raise RuntimeError("Invalid mode for pin: %s" % self.id)
|
||||
self._mode = mode
|
||||
if pull is not None:
|
||||
if self._mode != self.IN:
|
||||
raise RuntimeError("Cannot set pull resistor on output")
|
||||
if pull == self.PULL_UP:
|
||||
mypin = mraa.Gpio(self.id)
|
||||
mypin.dir(mraa.DIR_IN)
|
||||
elif pull == self.PULL_DOWN:
|
||||
mypin = mraa.Gpio(self.id)
|
||||
mypin.dir(mraa.DIR_IN)
|
||||
else:
|
||||
raise RuntimeError("Invalid pull for pin: %s" % self.id)
|
||||
|
||||
def value(self, val=None):
|
||||
"""Set or return the Pin Value"""
|
||||
# Digital In / Out
|
||||
if self._mode in (Pin.IN, Pin.OUT):
|
||||
if val is not None:
|
||||
if val == self.LOW:
|
||||
self._value = val
|
||||
mypin = mraa.Gpio(self.id)
|
||||
mypin.write(0)
|
||||
elif val == self.HIGH:
|
||||
self._value = val
|
||||
mypin = mraa.Gpio(self.id)
|
||||
mypin.write(1)
|
||||
else:
|
||||
raise RuntimeError("Invalid value for pin")
|
||||
return None
|
||||
return mraa.Gpio.read(mraa.Gpio(self.id))
|
||||
# Analog In
|
||||
if self._mode == Pin.ADC:
|
||||
if val is None:
|
||||
# Read ADC here
|
||||
mypin = mraa.Aio(self.id)
|
||||
mypin.read()
|
||||
return mypin.read()
|
||||
# read only
|
||||
raise AttributeError("'AnalogIn' object has no attribute 'value'")
|
||||
# Analog Out
|
||||
if self._mode == Pin.DAC:
|
||||
"""if val is None:
|
||||
# write only
|
||||
raise AttributeError("unreadable attribute")
|
||||
# Set DAC here
|
||||
mypin = mraa.Aio(self.id)
|
||||
mypin.setBit(val)"""
|
||||
raise AttributeError(
|
||||
"AM65xx doesn't have an DAC! No Analog Output possible!"
|
||||
)
|
||||
raise RuntimeError(
|
||||
"No action for mode {} with value {}".format(self._mode, val)
|
||||
)
|
||||
|
||||
|
||||
# Digital Pins (GPIO 0-19)
|
||||
D0 = Pin(0)
|
||||
D1 = Pin(1)
|
||||
D2 = Pin(2)
|
||||
D3 = Pin(3)
|
||||
D4 = Pin(4)
|
||||
D5 = Pin(5)
|
||||
D6 = Pin(6)
|
||||
D7 = Pin(7)
|
||||
D8 = Pin(8)
|
||||
D9 = Pin(9)
|
||||
D10 = Pin(10)
|
||||
D11 = Pin(11)
|
||||
D12 = Pin(12)
|
||||
D13 = Pin(13)
|
||||
D14 = Pin(14)
|
||||
D15 = Pin(15)
|
||||
D16 = Pin(16)
|
||||
D17 = Pin(17)
|
||||
D18 = Pin(18)
|
||||
D19 = Pin(19)
|
||||
|
||||
# Analog Pins (AIO 0-5, only ADC!)
|
||||
A0 = Pin(0)
|
||||
A1 = Pin(1)
|
||||
A2 = Pin(2)
|
||||
A3 = Pin(3)
|
||||
A4 = Pin(4)
|
||||
A5 = Pin(5)
|
||||
|
||||
# I2C allocation
|
||||
I2C_SCL = "SCL"
|
||||
I2C_SDA = "SDA"
|
||||
|
||||
# SPI allocation
|
||||
SPIO_SCLK = D13
|
||||
SPIO_MISO = D12
|
||||
SPIO_MOSI = D11
|
||||
SPIO_SS = D10
|
||||
|
||||
# UART allocation
|
||||
UART_TX = "TX"
|
||||
UART_RX = "RX"
|
||||
|
||||
# pwmOuts (GPIO 4-9)
|
||||
PWM_4 = D4
|
||||
PWM_5 = D5
|
||||
PWM_6 = D6
|
||||
PWM_7 = D7
|
||||
PWM_8 = D8
|
||||
PWM_9 = D9
|
||||
|
||||
# I2C
|
||||
# ordered as sclID, sdaID
|
||||
# i2c-4 (/dev/i2c-4) -> X10 Pin9, Pin10 (SDA, SCL)
|
||||
i2cPorts = ((4, I2C_SCL, I2C_SDA),)
|
||||
|
||||
# SPI
|
||||
# ordered as spiId, sckId, mosiID, misoID
|
||||
spiPorts = ((0, SPIO_SCLK, SPIO_MOSI, SPIO_MISO),)
|
||||
|
||||
# UART
|
||||
# use pySerial = dev/ttyS1
|
||||
# ordered as uartID, txID, rxID
|
||||
uartPorts = ((0, UART_TX, UART_RX),)
|
||||
|
||||
# PWM
|
||||
pwmOuts = (
|
||||
((0, 0), PWM_4),
|
||||
((0, 1), PWM_5),
|
||||
((2, 0), PWM_6),
|
||||
((2, 1), PWM_7),
|
||||
((4, 0), PWM_8),
|
||||
((4, 1), PWM_9),
|
||||
)
|
|
@ -0,0 +1,184 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-FileCopyrightText: 2022 Martin Schnur for Siemens AG
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# pylint: disable=pointless-string-statement
|
||||
# pylint: disable=ungrouped-imports,wrong-import-position,unused-import
|
||||
# pylint: disable=import-outside-toplevel
|
||||
|
||||
"""Custom PWMOut Wrapper for am65xx"""
|
||||
"""
|
||||
Much code from https://github.com/vsergeev/python-periphery/blob/master/periphery/pwm.py
|
||||
Copyright (c) 2015-2016 vsergeev / Ivan (Vanya) A. Sergeev
|
||||
License: MIT
|
||||
"""
|
||||
|
||||
|
||||
import mraa
|
||||
from adafruit_blinka.microcontroller.am65xx.pin import Pin
|
||||
|
||||
# pylint: disable=unnecessary-pass
|
||||
|
||||
|
||||
class PWMError(IOError):
|
||||
"""Base class for PWM errors."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# pylint: enable=unnecessary-pass
|
||||
|
||||
|
||||
class PWMOut:
|
||||
"""Pulse Width Modulation Output Class"""
|
||||
|
||||
def __init__(self, pin, *, frequency=500, duty_cycle=0, variable_frequency=False):
|
||||
self._frequency = None
|
||||
self._duty_cycle = None
|
||||
self._pwmpin = None
|
||||
self._period = 0
|
||||
self._enabled = False
|
||||
self._varfreq = variable_frequency
|
||||
# check pin for PWM support
|
||||
self._pin = Pin(pin.id)
|
||||
self._pin.init(mode=Pin.PWM)
|
||||
# initialize pin
|
||||
self._open(pin, duty_cycle, frequency, variable_frequency)
|
||||
|
||||
def __del__(self):
|
||||
self.deinit()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, t, value, traceback):
|
||||
self.deinit()
|
||||
|
||||
def _open(self, pin, duty=0, freq=500, variable_frequency=False):
|
||||
self._pwmpin = mraa.Pwm(pin.id)
|
||||
self.frequency = freq
|
||||
self.enabled = True
|
||||
self._varfreq = variable_frequency
|
||||
self.duty_cycle = duty
|
||||
|
||||
def deinit(self):
|
||||
"""Deinit the PWM."""
|
||||
if self._pwmpin is not None:
|
||||
self._pwmpin.enable(False)
|
||||
self._pwmpin = None
|
||||
|
||||
def _is_deinited(self):
|
||||
if self._pwmpin is None:
|
||||
raise ValueError(
|
||||
"Object has been deinitialize and can no longer "
|
||||
"be used. Create a new object."
|
||||
)
|
||||
|
||||
@property
|
||||
def period(self):
|
||||
"""Get or set the PWM's output period in seconds.
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if value type is not int or float.
|
||||
|
||||
:type: int, float
|
||||
"""
|
||||
return 1.0 / self.frequency
|
||||
|
||||
@period.setter
|
||||
def period(self, period):
|
||||
if not isinstance(period, (int, float)):
|
||||
raise TypeError("Invalid period type, should be int or float.")
|
||||
|
||||
self.frequency = 1.0 / period
|
||||
|
||||
@property
|
||||
def duty_cycle(self):
|
||||
"""Get or set the PWM's output duty cycle which is the fraction of
|
||||
each pulse which is high. 16-bit
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if value type is not int or float.
|
||||
ValueError: if value is out of bounds of 0.0 to 1.0.
|
||||
|
||||
:type: int, float
|
||||
"""
|
||||
return int(self._duty_cycle * 65535)
|
||||
|
||||
@duty_cycle.setter
|
||||
def duty_cycle(self, duty_cycle):
|
||||
if not isinstance(duty_cycle, (int, float)):
|
||||
raise TypeError("Invalid duty cycle type, should be int or float.")
|
||||
|
||||
if not 0 <= duty_cycle <= 65535:
|
||||
raise ValueError("Invalid duty cycle value, should be between 0 and 65535")
|
||||
|
||||
# convert from 16-bit
|
||||
duty_cycle /= 65535.0
|
||||
|
||||
self._duty_cycle = duty_cycle
|
||||
# self._pwmpin.ChangeDutyCycle(round(self._duty_cycle * 100))
|
||||
self._pwmpin.write(self._duty_cycle) # mraa duty_cycle 0.0f - 1.0f
|
||||
|
||||
@property
|
||||
def frequency(self):
|
||||
"""Get or set the PWM's output frequency in Hertz.
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if value type is not int or float.
|
||||
|
||||
:type: int, float
|
||||
"""
|
||||
|
||||
return self._frequency
|
||||
|
||||
@frequency.setter
|
||||
def frequency(self, frequency):
|
||||
if not isinstance(frequency, (int, float)):
|
||||
raise TypeError("Invalid frequency type, should be int or float.")
|
||||
|
||||
if self._enabled and not self._varfreq:
|
||||
raise TypeError(
|
||||
" Set variable_frequency = True to allow changing frequency "
|
||||
)
|
||||
# mraa has different variants in seconds,milli(_ms),micro(_us)
|
||||
self._pwmpin.period((1 / frequency))
|
||||
self._frequency = frequency
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
"""Get or set the PWM's output enabled state.
|
||||
|
||||
Raises:
|
||||
PWMError: if an I/O or OS error occurs.
|
||||
TypeError: if value type is not bool.
|
||||
|
||||
:type: bool
|
||||
"""
|
||||
return self._enabled
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, value):
|
||||
if not isinstance(value, bool):
|
||||
raise TypeError("Invalid enabled type, should be string.")
|
||||
|
||||
if value:
|
||||
self._pwmpin.enable(True)
|
||||
self._enabled = value
|
||||
else:
|
||||
self._pwmpin.enable(False)
|
||||
self._enabled(False)
|
||||
|
||||
# String representation
|
||||
def __str__(self):
|
||||
return "pin %s (freq=%f Hz, duty_cycle=%f%%)" % (
|
||||
self._pin,
|
||||
self.frequency,
|
||||
self.duty_cycle,
|
||||
)
|
|
@ -0,0 +1,144 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""am65xx SPI class using PureIO's SPI class"""
|
||||
|
||||
from Adafruit_PureIO import spi
|
||||
|
||||
# import Adafruit_PureIO.spi as spi
|
||||
from adafruit_blinka.agnostic import detector
|
||||
|
||||
|
||||
class SPI:
|
||||
"""SPI Class"""
|
||||
|
||||
MSB = 0
|
||||
LSB = 1
|
||||
CPHA = 1
|
||||
CPOL = 2
|
||||
|
||||
baudrate = 100000
|
||||
mode = 0
|
||||
bits = 8
|
||||
|
||||
def __init__(self, portid):
|
||||
if isinstance(portid, tuple):
|
||||
self._spi = spi.SPI(device=portid)
|
||||
else:
|
||||
self._spi = spi.SPI(device=(portid, 0))
|
||||
self.clock_pin = None
|
||||
self.mosi_pin = None
|
||||
self.miso_pin = None
|
||||
self.chip = None
|
||||
|
||||
# pylint: disable=too-many-arguments,unused-argument
|
||||
def init(
|
||||
self,
|
||||
baudrate=100000,
|
||||
polarity=0,
|
||||
phase=0,
|
||||
bits=8,
|
||||
firstbit=MSB,
|
||||
sck=None,
|
||||
mosi=None,
|
||||
miso=None,
|
||||
):
|
||||
"""Initialize SPI"""
|
||||
mode = 0
|
||||
if polarity:
|
||||
mode |= self.CPOL
|
||||
if phase:
|
||||
mode |= self.CPHA
|
||||
self.baudrate = baudrate
|
||||
self.mode = mode
|
||||
self.bits = bits
|
||||
self.chip = detector.chip
|
||||
|
||||
# Pins are not used
|
||||
self.clock_pin = sck
|
||||
self.mosi_pin = mosi
|
||||
self.miso_pin = miso
|
||||
|
||||
# pylint: enable=too-many-arguments,unused-argument
|
||||
|
||||
# pylint: disable=unnecessary-pass
|
||||
def set_no_cs(self):
|
||||
"""Setting so that SPI doesn't automatically set the CS pin"""
|
||||
# No kernel seems to support this, so we're just going to pass
|
||||
pass
|
||||
|
||||
# pylint: enable=unnecessary-pass
|
||||
|
||||
@property
|
||||
def frequency(self):
|
||||
"""Return the current baudrate"""
|
||||
return self.baudrate
|
||||
|
||||
def write(self, buf, start=0, end=None):
|
||||
"""Write data from the buffer to SPI"""
|
||||
if not buf:
|
||||
return
|
||||
if end is None:
|
||||
end = len(buf)
|
||||
try:
|
||||
# self._spi.open(self._port, 0)
|
||||
self.set_no_cs()
|
||||
self._spi.max_speed_hz = self.baudrate
|
||||
self._spi.mode = self.mode
|
||||
self._spi.bits_per_word = self.bits
|
||||
self._spi.writebytes(buf[start:end])
|
||||
# self._spi.close()
|
||||
except FileNotFoundError:
|
||||
print("Could not open SPI device - check if SPI is enabled in kernel!")
|
||||
raise
|
||||
|
||||
def readinto(self, buf, start=0, end=None, write_value=0):
|
||||
"""Read data from SPI and into the buffer"""
|
||||
if not buf:
|
||||
return
|
||||
if end is None:
|
||||
end = len(buf)
|
||||
try:
|
||||
# self._spi.open(self._port, 0)
|
||||
# self.set_no_cs()
|
||||
self._spi.max_speed_hz = self.baudrate
|
||||
self._spi.mode = self.mode
|
||||
self._spi.bits_per_word = self.bits
|
||||
data = self._spi.transfer([write_value] * (end - start))
|
||||
for i in range(end - start): # 'readinto' the given buffer
|
||||
buf[start + i] = data[i]
|
||||
# self._spi.close()
|
||||
except FileNotFoundError:
|
||||
print("Could not open SPI device - check if SPI is enabled in kernel!")
|
||||
raise
|
||||
|
||||
# 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
|
||||
"""
|
||||
if not buffer_out or not buffer_in:
|
||||
return
|
||||
if out_end is None:
|
||||
out_end = len(buffer_out)
|
||||
if in_end is None:
|
||||
in_end = len(buffer_in)
|
||||
if out_end - out_start != in_end - in_start:
|
||||
raise RuntimeError("Buffer slices must be of equal length.")
|
||||
try:
|
||||
# self._spi.open(self._port, 0)
|
||||
# self.set_no_cs()
|
||||
self._spi.max_speed_hz = self.baudrate
|
||||
self._spi.mode = self.mode
|
||||
self._spi.bits_per_word = self.bits
|
||||
data = self._spi.transfer(list(buffer_out[out_start : out_end + 1]))
|
||||
for i in range((in_end - in_start)):
|
||||
buffer_in[i + in_start] = data[i]
|
||||
# self._spi.close()
|
||||
except FileNotFoundError:
|
||||
print("Could not open SPI device - check if SPI is enabled in kernel!")
|
||||
raise
|
||||
|
||||
# pylint: enable=too-many-arguments
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,164 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""
|
||||
G12A, G12B, and SM1 Common Definitions
|
||||
Ref:
|
||||
Linux kernel 4.9.y (hardkernel)
|
||||
linux/include/dt-bindings/gpio/meson-g12a-gpio.h
|
||||
Linux kernel 5.4.y (mainline)
|
||||
linux/include/dt-bindings/gpio/meson-g12a-gpio.h
|
||||
linux/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi
|
||||
"""
|
||||
|
||||
import gpiod
|
||||
from adafruit_blinka.microcontroller.alias import get_dts_alias
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
chip0 = gpiod.Chip("0")
|
||||
chip1 = gpiod.Chip("1")
|
||||
|
||||
if chip0.num_lines() < 20:
|
||||
aobus = 0
|
||||
periphs = 1
|
||||
periphs_offset = chip1.num_lines() - 85
|
||||
else:
|
||||
aobus = 1
|
||||
periphs = 0
|
||||
periphs_offset = chip0.num_lines() - 85
|
||||
|
||||
chip0.close()
|
||||
chip1.close()
|
||||
|
||||
GPIOAO_0 = GPIO496 = Pin((aobus, 0))
|
||||
GPIOAO_1 = GPIO497 = Pin((aobus, 1))
|
||||
GPIOAO_2 = GPIO498 = Pin((aobus, 2))
|
||||
GPIOAO_3 = GPIO499 = Pin((aobus, 3))
|
||||
GPIOAO_4 = GPIO500 = Pin((aobus, 4))
|
||||
GPIOAO_5 = GPIO501 = Pin((aobus, 5))
|
||||
GPIOAO_6 = GPIO502 = Pin((aobus, 6))
|
||||
GPIOAO_7 = GPIO503 = Pin((aobus, 7))
|
||||
GPIOAO_8 = GPIO504 = Pin((aobus, 8))
|
||||
GPIOAO_9 = GPIO505 = Pin((aobus, 9))
|
||||
GPIOAO_10 = GPIO506 = Pin((aobus, 10))
|
||||
GPIOAO_11 = GPIO507 = Pin((aobus, 11))
|
||||
|
||||
GPIOE_0 = GPIO508 = Pin((aobus, 12))
|
||||
GPIOE_1 = GPIO509 = Pin((aobus, 13))
|
||||
GPIOE_2 = GPIO510 = Pin((aobus, 14))
|
||||
|
||||
GPIOZ_0 = GPIO427 = Pin((periphs, 0 + periphs_offset))
|
||||
GPIOZ_1 = GPIO428 = Pin((periphs, 1 + periphs_offset))
|
||||
GPIOZ_2 = GPIO429 = Pin((periphs, 2 + periphs_offset))
|
||||
GPIOZ_3 = GPIO430 = Pin((periphs, 3 + periphs_offset))
|
||||
GPIOZ_4 = GPIO431 = Pin((periphs, 4 + periphs_offset))
|
||||
GPIOZ_5 = GPIO432 = Pin((periphs, 5 + periphs_offset))
|
||||
GPIOZ_6 = GPIO433 = Pin((periphs, 6 + periphs_offset))
|
||||
GPIOZ_7 = GPIO434 = Pin((periphs, 7 + periphs_offset))
|
||||
GPIOZ_8 = GPIO435 = Pin((periphs, 8 + periphs_offset))
|
||||
GPIOZ_9 = GPIO436 = Pin((periphs, 9 + periphs_offset))
|
||||
GPIOZ_10 = GPIO437 = Pin((periphs, 10 + periphs_offset))
|
||||
GPIOZ_11 = GPIO438 = Pin((periphs, 11 + periphs_offset))
|
||||
GPIOZ_12 = GPIO439 = Pin((periphs, 12 + periphs_offset))
|
||||
GPIOZ_13 = GPIO440 = Pin((periphs, 13 + periphs_offset))
|
||||
GPIOZ_14 = GPIO441 = Pin((periphs, 14 + periphs_offset))
|
||||
GPIOZ_15 = GPIO442 = Pin((periphs, 15 + periphs_offset))
|
||||
|
||||
GPIOH_0 = GPIO443 = Pin((periphs, 16 + periphs_offset))
|
||||
GPIOH_1 = GPIO444 = Pin((periphs, 17 + periphs_offset))
|
||||
GPIOH_2 = GPIO445 = Pin((periphs, 18 + periphs_offset))
|
||||
GPIOH_3 = GPIO446 = Pin((periphs, 19 + periphs_offset))
|
||||
GPIOH_4 = GPIO447 = Pin((periphs, 20 + periphs_offset))
|
||||
GPIOH_5 = GPIO448 = Pin((periphs, 21 + periphs_offset))
|
||||
GPIOH_6 = GPIO449 = Pin((periphs, 22 + periphs_offset))
|
||||
GPIOH_7 = GPIO450 = Pin((periphs, 23 + periphs_offset))
|
||||
GPIOH_8 = GPIO451 = Pin((periphs, 24 + periphs_offset))
|
||||
|
||||
BOOT_0 = GPIO452 = Pin((periphs, 25 + periphs_offset))
|
||||
BOOT_1 = GPIO453 = Pin((periphs, 26 + periphs_offset))
|
||||
BOOT_2 = GPIO454 = Pin((periphs, 27 + periphs_offset))
|
||||
BOOT_3 = GPIO455 = Pin((periphs, 28 + periphs_offset))
|
||||
BOOT_4 = GPIO456 = Pin((periphs, 29 + periphs_offset))
|
||||
BOOT_5 = GPIO457 = Pin((periphs, 30 + periphs_offset))
|
||||
BOOT_6 = GPIO458 = Pin((periphs, 31 + periphs_offset))
|
||||
BOOT_7 = GPIO459 = Pin((periphs, 32 + periphs_offset))
|
||||
BOOT_8 = GPIO460 = Pin((periphs, 33 + periphs_offset))
|
||||
BOOT_9 = GPIO461 = Pin((periphs, 34 + periphs_offset))
|
||||
BOOT_10 = GPIO462 = Pin((periphs, 35 + periphs_offset))
|
||||
BOOT_11 = GPIO463 = Pin((periphs, 36 + periphs_offset))
|
||||
BOOT_12 = GPIO464 = Pin((periphs, 37 + periphs_offset))
|
||||
BOOT_13 = GPIO465 = Pin((periphs, 38 + periphs_offset))
|
||||
BOOT_14 = GPIO466 = Pin((periphs, 39 + periphs_offset))
|
||||
BOOT_15 = GPIO467 = Pin((periphs, 40 + periphs_offset))
|
||||
|
||||
GPIOC_0 = GPIO468 = Pin((periphs, 41 + periphs_offset))
|
||||
GPIOC_1 = GPIO469 = Pin((periphs, 42 + periphs_offset))
|
||||
GPIOC_2 = GPIO470 = Pin((periphs, 43 + periphs_offset))
|
||||
GPIOC_3 = GPIO471 = Pin((periphs, 44 + periphs_offset))
|
||||
GPIOC_4 = GPIO472 = Pin((periphs, 45 + periphs_offset))
|
||||
GPIOC_5 = GPIO473 = Pin((periphs, 46 + periphs_offset))
|
||||
GPIOC_6 = GPIO474 = Pin((periphs, 47 + periphs_offset))
|
||||
GPIOC_7 = GPIO475 = Pin((periphs, 48 + periphs_offset))
|
||||
|
||||
GPIOA_0 = GPIO460 = Pin((periphs, 49 + periphs_offset))
|
||||
GPIOA_1 = GPIO461 = Pin((periphs, 50 + periphs_offset))
|
||||
GPIOA_2 = GPIO462 = Pin((periphs, 51 + periphs_offset))
|
||||
GPIOA_3 = GPIO463 = Pin((periphs, 52 + periphs_offset))
|
||||
GPIOA_4 = GPIO464 = Pin((periphs, 53 + periphs_offset))
|
||||
GPIOA_5 = GPIO465 = Pin((periphs, 54 + periphs_offset))
|
||||
GPIOA_6 = GPIO466 = Pin((periphs, 55 + periphs_offset))
|
||||
GPIOA_7 = GPIO467 = Pin((periphs, 56 + periphs_offset))
|
||||
GPIOA_8 = GPIO468 = Pin((periphs, 57 + periphs_offset))
|
||||
GPIOA_9 = GPIO469 = Pin((periphs, 58 + periphs_offset))
|
||||
GPIOA_10 = GPIO470 = Pin((periphs, 59 + periphs_offset))
|
||||
GPIOA_11 = GPIO471 = Pin((periphs, 60 + periphs_offset))
|
||||
GPIOA_12 = GPIO472 = Pin((periphs, 61 + periphs_offset))
|
||||
GPIOA_13 = GPIO473 = Pin((periphs, 62 + periphs_offset))
|
||||
GPIOA_14 = GPIO474 = Pin((periphs, 63 + periphs_offset))
|
||||
GPIOA_15 = GPIO475 = Pin((periphs, 64 + periphs_offset))
|
||||
|
||||
GPIOX_0 = GPIO476 = Pin((periphs, 65 + periphs_offset))
|
||||
GPIOX_1 = GPIO477 = Pin((periphs, 66 + periphs_offset))
|
||||
GPIOX_2 = GPIO478 = Pin((periphs, 67 + periphs_offset))
|
||||
GPIOX_3 = GPIO479 = Pin((periphs, 68 + periphs_offset))
|
||||
GPIOX_4 = GPIO480 = Pin((periphs, 69 + periphs_offset))
|
||||
GPIOX_5 = GPIO481 = Pin((periphs, 70 + periphs_offset))
|
||||
GPIOX_6 = GPIO482 = Pin((periphs, 71 + periphs_offset))
|
||||
GPIOX_7 = GPIO483 = Pin((periphs, 72 + periphs_offset))
|
||||
GPIOX_8 = GPIO484 = Pin((periphs, 73 + periphs_offset))
|
||||
GPIOX_9 = GPIO485 = Pin((periphs, 74 + periphs_offset))
|
||||
GPIOX_10 = GPIO486 = Pin((periphs, 75 + periphs_offset))
|
||||
GPIOX_11 = GPIO487 = Pin((periphs, 76 + periphs_offset))
|
||||
GPIOX_12 = GPIO488 = Pin((periphs, 77 + periphs_offset))
|
||||
GPIOX_13 = GPIO489 = Pin((periphs, 78 + periphs_offset))
|
||||
GPIOX_14 = GPIO490 = Pin((periphs, 79 + periphs_offset))
|
||||
GPIOX_15 = GPIO491 = Pin((periphs, 80 + periphs_offset))
|
||||
GPIOX_16 = GPIO492 = Pin((periphs, 81 + periphs_offset))
|
||||
GPIOX_17 = GPIO493 = Pin((periphs, 82 + periphs_offset))
|
||||
GPIOX_18 = GPIO494 = Pin((periphs, 83 + periphs_offset))
|
||||
GPIOX_19 = GPIO495 = Pin((periphs, 84 + periphs_offset))
|
||||
|
||||
SPI0_SCLK = GPIOA_1
|
||||
SPI0_MCLK0 = GPIOA_0
|
||||
SPI0_SDO = GPIOA_3
|
||||
SPI0_SDI = GPIOA_4
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = ((0, SPI0_SCLK, SPI0_MCLK0, SPI0_SDO, SPI0_SDI),)
|
||||
|
||||
UART1_TX = GPIOH_7
|
||||
UART1_RX = GPIOH_6
|
||||
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = ((1, UART1_TX, UART1_RX),)
|
||||
|
||||
# ordered as i2cId, sclId, sdaId
|
||||
i2cPorts = []
|
||||
|
||||
alias = get_dts_alias("ff805000.i2c")
|
||||
if alias is not None:
|
||||
globals()[alias + "_SCL"] = GPIOX_18
|
||||
globals()[alias + "_SDA"] = GPIOX_17
|
||||
i2cPorts.append((int(alias[3]), GPIOX_18, GPIOX_17))
|
||||
|
||||
i2cPorts = tuple(i2cPorts)
|
|
@ -0,0 +1,183 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Custom PulseIn Class to read PWM signals"""
|
||||
import time
|
||||
import subprocess
|
||||
import os
|
||||
import atexit
|
||||
import random
|
||||
import struct
|
||||
import sysv_ipc
|
||||
|
||||
DEBUG = False
|
||||
queues = []
|
||||
procs = []
|
||||
|
||||
|
||||
# The message queues live outside of python space, and must be formally cleaned!
|
||||
def final():
|
||||
"""In case the program is cancelled or quit, we need to clean up the PulseIn
|
||||
helper process and also the message queue, this is called at exit to do so"""
|
||||
if DEBUG:
|
||||
print("Cleaning up message queues", queues)
|
||||
print("Cleaning up processes", procs)
|
||||
for q in queues:
|
||||
q.remove()
|
||||
for proc in procs:
|
||||
proc.terminate()
|
||||
|
||||
|
||||
atexit.register(final)
|
||||
|
||||
|
||||
# pylint: disable=c-extension-no-member
|
||||
class PulseIn:
|
||||
"""PulseIn Class to read PWM signals"""
|
||||
|
||||
def __init__(self, pin, maxlen=2, idle_state=False):
|
||||
"""Create a PulseIn object associated with the given pin.
|
||||
The object acts as a read-only sequence of pulse lengths with
|
||||
a given max length. When it is active, new pulse lengths are
|
||||
added to the end of the list. When there is no more room
|
||||
(len() == maxlen) the oldest pulse length is removed to make room."""
|
||||
self._pin = pin
|
||||
self._maxlen = maxlen
|
||||
self._idle_state = idle_state
|
||||
self._queue_key = random.randint(1, 9999)
|
||||
try:
|
||||
self._mq = sysv_ipc.MessageQueue(None, flags=sysv_ipc.IPC_CREX)
|
||||
if DEBUG:
|
||||
print("Message Queue Key: ", self._mq.key)
|
||||
queues.append(self._mq)
|
||||
except sysv_ipc.ExistentialError:
|
||||
raise RuntimeError(
|
||||
"Message queue creation failed"
|
||||
) from sysv_ipc.ExistentialError
|
||||
|
||||
# Check if OS is 64-bit
|
||||
if struct.calcsize("P") * 8 == 64: # pylint: disable=no-member
|
||||
libgpiod_filename = "libgpiod_pulsein64"
|
||||
else:
|
||||
libgpiod_filename = "libgpiod_pulsein"
|
||||
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
cmd = [
|
||||
dir_path + "/" + libgpiod_filename,
|
||||
"--pulses",
|
||||
str(maxlen),
|
||||
"--queue",
|
||||
str(self._mq.key),
|
||||
]
|
||||
if idle_state:
|
||||
cmd.append("-i")
|
||||
cmd.append("gpiochip0")
|
||||
cmd.append(str(pin))
|
||||
if DEBUG:
|
||||
print(cmd)
|
||||
|
||||
self._process = subprocess.Popen(cmd) # pylint: disable=consider-using-with
|
||||
procs.append(self._process)
|
||||
|
||||
# wait for it to start up
|
||||
if DEBUG:
|
||||
print("Waiting for startup success message from subprocess")
|
||||
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, type=2):
|
||||
"""Internal helper that will wait for new messages of a given type,
|
||||
and throw an exception on timeout"""
|
||||
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
|
||||
|
||||
def deinit(self):
|
||||
"""Deinitialises the PulseIn and releases any hardware and software
|
||||
resources for reuse."""
|
||||
# Clean up after ourselves
|
||||
self._process.terminate()
|
||||
procs.remove(self._process)
|
||||
self._mq.remove()
|
||||
queues.remove(self._mq)
|
||||
|
||||
def __enter__(self):
|
||||
"""No-op used by Context Managers."""
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, tb):
|
||||
"""Automatically deinitializes the hardware when exiting a context."""
|
||||
self.deinit()
|
||||
|
||||
def resume(self, trigger_duration=0):
|
||||
"""Resumes pulse capture after an optional trigger pulse."""
|
||||
if trigger_duration != 0:
|
||||
self._mq.send("t%d" % trigger_duration, True, type=1)
|
||||
else:
|
||||
self._mq.send("r", True, type=1)
|
||||
self._paused = False
|
||||
|
||||
def pause(self):
|
||||
"""Pause pulse capture"""
|
||||
self._mq.send("p", True, type=1)
|
||||
self._paused = True
|
||||
|
||||
@property
|
||||
def paused(self):
|
||||
"""True when pulse capture is paused as a result of pause() or
|
||||
an error during capture such as a signal that is too fast."""
|
||||
return self._paused
|
||||
|
||||
@property
|
||||
def maxlen(self):
|
||||
"""The maximum length of the PulseIn. When len() is equal to maxlen,
|
||||
it is unclear which pulses are active and which are idle."""
|
||||
return self._maxlen
|
||||
|
||||
def clear(self):
|
||||
"""Clears all captured pulses"""
|
||||
self._mq.send("c", True, type=1)
|
||||
|
||||
def popleft(self):
|
||||
"""Removes and returns the oldest read pulse."""
|
||||
self._mq.send("^", True, type=1)
|
||||
message = self._wait_receive_msg()
|
||||
reply = int(message[0].decode("utf-8"))
|
||||
# print(reply)
|
||||
if reply == -1:
|
||||
raise IndexError("pop from empty list")
|
||||
return reply
|
||||
|
||||
def __len__(self):
|
||||
"""Returns the current pulse length"""
|
||||
self._mq.send("l", True, type=1)
|
||||
message = self._wait_receive_msg()
|
||||
return int(message[0].decode("utf-8"))
|
||||
|
||||
# pylint: disable=redefined-builtin
|
||||
def __getitem__(self, index, type=None):
|
||||
"""Returns the value at the given index or values in slice."""
|
||||
self._mq.send("i%d" % index, True, type=1)
|
||||
message = self._wait_receive_msg()
|
||||
ret = int(message[0].decode("utf-8"))
|
||||
if ret == -1:
|
||||
raise IndexError("list index out of range")
|
||||
return ret
|
||||
|
||||
# pylint: enable=redefined-builtin
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,191 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: 2023 Steve Jeong for Hardkernel
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""
|
||||
G12A, G12B, and SM1 Common Definitions
|
||||
Ref:
|
||||
Linux kernel 4.9.y (hardkernel)
|
||||
linux/include/dt-bindings/gpio/meson-g12a-gpio.h
|
||||
Linux kernel 5.4.y (mainline)
|
||||
linux/include/dt-bindings/gpio/meson-g12a-gpio.h
|
||||
linux/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi
|
||||
"""
|
||||
|
||||
from adafruit_blinka.agnostic import detector
|
||||
from adafruit_blinka.microcontroller.alias import get_dts_alias, get_pwm_chipid
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_chip import Chip
|
||||
|
||||
chip0 = Chip("0")
|
||||
chip1 = Chip("1")
|
||||
|
||||
chip0lines = chip0.num_lines
|
||||
chip1lines = chip1.num_lines
|
||||
|
||||
if chip0lines < 20:
|
||||
aobus = 0
|
||||
periphs = 1
|
||||
periphs_offset = chip1lines - 85
|
||||
else:
|
||||
aobus = 1
|
||||
periphs = 0
|
||||
periphs_offset = chip0lines - 85
|
||||
|
||||
del chip0
|
||||
del chip1
|
||||
|
||||
GPIOAO_0 = GPIO496 = Pin((aobus, 0))
|
||||
GPIOAO_1 = GPIO497 = Pin((aobus, 1))
|
||||
GPIOAO_2 = GPIO498 = Pin((aobus, 2))
|
||||
GPIOAO_3 = GPIO499 = Pin((aobus, 3))
|
||||
GPIOAO_4 = GPIO500 = Pin((aobus, 4))
|
||||
GPIOAO_5 = GPIO501 = Pin((aobus, 5))
|
||||
GPIOAO_6 = GPIO502 = Pin((aobus, 6))
|
||||
GPIOAO_7 = GPIO503 = Pin((aobus, 7))
|
||||
GPIOAO_8 = GPIO504 = Pin((aobus, 8))
|
||||
GPIOAO_9 = GPIO505 = Pin((aobus, 9))
|
||||
GPIOAO_10 = GPIO506 = Pin((aobus, 10))
|
||||
GPIOAO_11 = GPIO507 = Pin((aobus, 11))
|
||||
GPIOE_0 = GPIO508 = Pin((aobus, 12))
|
||||
GPIOE_1 = GPIO509 = Pin((aobus, 13))
|
||||
GPIOE_2 = GPIO510 = Pin((aobus, 14))
|
||||
GPIO_TEST_N = GPIO511 = Pin((aobus, 15))
|
||||
|
||||
GPIOH_0 = GPIO427 = Pin((periphs, 16 + periphs_offset))
|
||||
GPIOH_1 = GPIO428 = Pin((periphs, 17 + periphs_offset))
|
||||
GPIOH_2 = GPIO429 = Pin((periphs, 18 + periphs_offset))
|
||||
GPIOH_3 = GPIO430 = Pin((periphs, 19 + periphs_offset))
|
||||
GPIOH_4 = GPIO431 = Pin((periphs, 20 + periphs_offset))
|
||||
GPIOH_5 = GPIO432 = Pin((periphs, 21 + periphs_offset))
|
||||
GPIOH_6 = GPIO433 = Pin((periphs, 22 + periphs_offset))
|
||||
GPIOH_7 = GPIO434 = Pin((periphs, 23 + periphs_offset))
|
||||
GPIOH_8 = GPIO435 = Pin((periphs, 24 + periphs_offset))
|
||||
|
||||
GPIOA_0 = GPIO460 = Pin((periphs, 49 + periphs_offset))
|
||||
GPIOA_1 = GPIO461 = Pin((periphs, 50 + periphs_offset))
|
||||
GPIOA_2 = GPIO462 = Pin((periphs, 51 + periphs_offset))
|
||||
GPIOA_3 = GPIO463 = Pin((periphs, 52 + periphs_offset))
|
||||
GPIOA_4 = GPIO464 = Pin((periphs, 53 + periphs_offset))
|
||||
GPIOA_5 = GPIO465 = Pin((periphs, 54 + periphs_offset))
|
||||
GPIOA_6 = GPIO466 = Pin((periphs, 55 + periphs_offset))
|
||||
GPIOA_7 = GPIO467 = Pin((periphs, 56 + periphs_offset))
|
||||
GPIOA_8 = GPIO468 = Pin((periphs, 57 + periphs_offset))
|
||||
GPIOA_9 = GPIO469 = Pin((periphs, 58 + periphs_offset))
|
||||
GPIOA_10 = GPIO470 = Pin((periphs, 59 + periphs_offset))
|
||||
GPIOA_11 = GPIO471 = Pin((periphs, 60 + periphs_offset))
|
||||
GPIOA_12 = GPIO472 = Pin((periphs, 61 + periphs_offset))
|
||||
GPIOA_13 = GPIO473 = Pin((periphs, 62 + periphs_offset))
|
||||
GPIOA_14 = GPIO474 = Pin((periphs, 63 + periphs_offset))
|
||||
GPIOA_15 = GPIO475 = Pin((periphs, 64 + periphs_offset))
|
||||
|
||||
GPIOX_0 = GPIO476 = Pin((periphs, 65 + periphs_offset))
|
||||
GPIOX_1 = GPIO477 = Pin((periphs, 66 + periphs_offset))
|
||||
GPIOX_2 = GPIO478 = Pin((periphs, 67 + periphs_offset))
|
||||
GPIOX_3 = GPIO479 = Pin((periphs, 68 + periphs_offset))
|
||||
GPIOX_4 = GPIO480 = Pin((periphs, 69 + periphs_offset))
|
||||
GPIOX_5 = GPIO481 = Pin((periphs, 70 + periphs_offset))
|
||||
GPIOX_6 = GPIO482 = Pin((periphs, 71 + periphs_offset))
|
||||
GPIOX_7 = GPIO483 = Pin((periphs, 72 + periphs_offset))
|
||||
GPIOX_8 = GPIO484 = Pin((periphs, 73 + periphs_offset))
|
||||
GPIOX_9 = GPIO485 = Pin((periphs, 74 + periphs_offset))
|
||||
GPIOX_10 = GPIO486 = Pin((periphs, 75 + periphs_offset))
|
||||
GPIOX_11 = GPIO487 = Pin((periphs, 76 + periphs_offset))
|
||||
GPIOX_12 = GPIO488 = Pin((periphs, 77 + periphs_offset))
|
||||
GPIOX_13 = GPIO489 = Pin((periphs, 78 + periphs_offset))
|
||||
GPIOX_14 = GPIO490 = Pin((periphs, 79 + periphs_offset))
|
||||
GPIOX_15 = GPIO491 = Pin((periphs, 80 + periphs_offset))
|
||||
GPIOX_16 = GPIO492 = Pin((periphs, 81 + periphs_offset))
|
||||
GPIOX_17 = GPIO493 = Pin((periphs, 82 + periphs_offset))
|
||||
GPIOX_18 = GPIO494 = Pin((periphs, 83 + periphs_offset))
|
||||
GPIOX_19 = GPIO495 = Pin((periphs, 84 + periphs_offset))
|
||||
|
||||
SPI0_SCLK = GPIOX_11
|
||||
SPI0_MISO = GPIOX_9
|
||||
SPI0_MOSI = GPIOX_8
|
||||
SPI0_CS0 = GPIOX_10
|
||||
|
||||
UART1_TX = GPIOX_12
|
||||
UART1_RX = GPIOX_13
|
||||
|
||||
# ordered as i2cId, sclId, sdaId
|
||||
i2cPorts = []
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = ((0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),)
|
||||
|
||||
# SysFs pwm outputs, pwm channel and pin in first tuple
|
||||
pwmOuts = []
|
||||
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = [
|
||||
(1, UART1_TX, UART1_RX),
|
||||
]
|
||||
|
||||
# SysFS analog inputs, Ordered as analog analogInId, device, and channel
|
||||
analogIns = []
|
||||
|
||||
board = detector.board.id
|
||||
if board in ("ODROID_C4", "ODROID_N2"):
|
||||
alias = get_dts_alias("ffd1d000.i2c")
|
||||
if alias is not None:
|
||||
globals()[alias + "_SCL"] = GPIOX_18
|
||||
globals()[alias + "_SDA"] = GPIOX_17
|
||||
i2cPorts.append((int(alias[-1]), GPIOX_18, GPIOX_17))
|
||||
alias = get_dts_alias("ffd1c000.i2c")
|
||||
if alias is not None:
|
||||
globals()[alias + "_SCL"] = GPIOA_15
|
||||
globals()[alias + "_SDA"] = GPIOA_14
|
||||
i2cPorts.append((int(alias[-1]), GPIOA_15, GPIOA_14))
|
||||
alias = get_dts_alias("ffd24000.serial")
|
||||
if alias is not None:
|
||||
globals()[alias + "_TX"] = GPIOX_12
|
||||
globals()[alias + "_RX"] = GPIOX_13
|
||||
uartPorts.append((int(alias[-1]), GPIOX_12, GPIOX_13))
|
||||
alias = get_dts_alias("ffd23000.serial")
|
||||
if alias is not None:
|
||||
globals()[alias + "_TX"] = GPIOX_6
|
||||
globals()[alias + "_RX"] = GPIOX_7
|
||||
uartPorts.append((int(alias[-1]), GPIOX_6, GPIOX_7))
|
||||
|
||||
if board in ("ODROID_C4"):
|
||||
alias = get_pwm_chipid("ffd1b000.pwm")
|
||||
if alias is not None:
|
||||
globals()["PWMA"] = GPIOX_6
|
||||
globals()["PWMB"] = GPIOX_19
|
||||
pwmOuts.append(((int(alias[-1]), 0), GPIOX_6))
|
||||
pwmOuts.append(((int(alias[-1]), 1), GPIOX_19))
|
||||
alias = get_pwm_chipid("ffd1a000.pwm")
|
||||
if alias is not None:
|
||||
globals()["PWMC"] = GPIOX_5
|
||||
globals()["PWMD"] = GPIOX_3
|
||||
pwmOuts.append(((int(alias[-1]), 0), GPIOX_5))
|
||||
pwmOuts.append(((int(alias[-1]), 1), GPIOX_3))
|
||||
alias = get_pwm_chipid("ffd19000.pwm")
|
||||
if alias is not None:
|
||||
globals()["PWME"] = GPIOX_16
|
||||
globals()["PWMF"] = GPIOX_7
|
||||
pwmOuts.append(((int(alias[-1]), 0), GPIOX_16))
|
||||
pwmOuts.append(((int(alias[-1]), 1), GPIOX_7))
|
||||
analogIns.append((37, 0, 2))
|
||||
analogIns.append((40, 0, 0))
|
||||
if board in ("ODROID_N2"):
|
||||
alias = get_pwm_chipid("ffd1a000.pwm")
|
||||
if alias is not None:
|
||||
globals()["PWMC"] = GPIOX_5
|
||||
globals()["PWMD"] = GPIOX_6
|
||||
pwmOuts.append(((int(alias[-1]), 0), GPIOX_5))
|
||||
pwmOuts.append(((int(alias[-1]), 1), GPIOX_6))
|
||||
alias = get_pwm_chipid("ffd19000.pwm")
|
||||
if alias is not None:
|
||||
globals()["PWME"] = GPIOX_16
|
||||
globals()["PWMF"] = GPIOX_7
|
||||
pwmOuts.append(((int(alias[-1]), 0), GPIOX_16))
|
||||
pwmOuts.append(((int(alias[-1]), 1), GPIOX_7))
|
||||
analogIns.append((37, 0, 3))
|
||||
analogIns.append((40, 0, 2))
|
||||
|
||||
analogIns = tuple(analogIns)
|
||||
i2cPorts = tuple(i2cPorts)
|
||||
pwmOuts = tuple(pwmOuts)
|
||||
uartPorts = tuple(uartPorts)
|
|
@ -0,0 +1,185 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Custom PulseIn Class to read PWM signals"""
|
||||
import time
|
||||
import subprocess
|
||||
import os
|
||||
import atexit
|
||||
import random
|
||||
import sysv_ipc
|
||||
|
||||
DEBUG = False
|
||||
queues = []
|
||||
procs = []
|
||||
|
||||
|
||||
# The message queues live outside of python space, and must be formally cleaned!
|
||||
def final():
|
||||
"""In case the program is cancelled or quit, we need to clean up the PulseIn
|
||||
helper process and also the message queue, this is called at exit to do so"""
|
||||
if DEBUG:
|
||||
print("Cleaning up message queues", queues)
|
||||
print("Cleaning up processes", procs)
|
||||
for q in queues:
|
||||
q.remove()
|
||||
for proc in procs:
|
||||
proc.terminate()
|
||||
|
||||
|
||||
atexit.register(final)
|
||||
|
||||
|
||||
# pylint: disable=c-extension-no-member
|
||||
class PulseIn:
|
||||
"""PulseIn Class to read PWM signals"""
|
||||
|
||||
def __init__(self, pin, maxlen=2, idle_state=False):
|
||||
"""Create a PulseIn object associated with the given pin.
|
||||
The object acts as a read-only sequence of pulse lengths with
|
||||
a given max length. When it is active, new pulse lengths are
|
||||
added to the end of the list. When there is no more room
|
||||
(len() == maxlen) the oldest pulse length is removed to make room."""
|
||||
|
||||
if isinstance(pin.id, tuple):
|
||||
self._pin = str(pin.id[1])
|
||||
self._chip = "gpiochip{}".format(pin.id[0])
|
||||
else:
|
||||
self._pin = str(pin.id)
|
||||
self._chip = "gpiochip0"
|
||||
|
||||
self._maxlen = maxlen
|
||||
self._idle_state = idle_state
|
||||
self._queue_key = random.randint(1, 9999)
|
||||
try:
|
||||
self._mq = sysv_ipc.MessageQueue(None, flags=sysv_ipc.IPC_CREX)
|
||||
if DEBUG:
|
||||
print("Message Queue Key: ", self._mq.key)
|
||||
queues.append(self._mq)
|
||||
except sysv_ipc.ExistentialError:
|
||||
raise RuntimeError(
|
||||
"Message queue creation failed"
|
||||
) from sysv_ipc.ExistentialError
|
||||
|
||||
# Check if OS is 64-bit
|
||||
libgpiod_filename = "libgpiod_pulsein"
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
cmd = [
|
||||
dir_path + "/" + libgpiod_filename,
|
||||
"--pulses",
|
||||
str(maxlen),
|
||||
"--queue",
|
||||
str(self._mq.key),
|
||||
]
|
||||
if idle_state:
|
||||
cmd.append("-i")
|
||||
cmd.append(self._chip)
|
||||
cmd.append(self._pin)
|
||||
if DEBUG:
|
||||
print(cmd)
|
||||
|
||||
self._process = subprocess.Popen(cmd) # pylint: disable=consider-using-with
|
||||
procs.append(self._process)
|
||||
|
||||
# wait for it to start up
|
||||
if DEBUG:
|
||||
print("Waiting for startup success message from subprocess")
|
||||
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, type=2):
|
||||
"""Internal helper that will wait for new messages of a given type,
|
||||
and throw an exception on timeout"""
|
||||
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
|
||||
|
||||
def deinit(self):
|
||||
"""Deinitialises the PulseIn and releases any hardware and software
|
||||
resources for reuse."""
|
||||
# Clean up after ourselves
|
||||
self._process.terminate()
|
||||
procs.remove(self._process)
|
||||
self._mq.remove()
|
||||
queues.remove(self._mq)
|
||||
|
||||
def __enter__(self):
|
||||
"""No-op used by Context Managers."""
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, tb):
|
||||
"""Automatically deinitializes the hardware when exiting a context."""
|
||||
self.deinit()
|
||||
|
||||
def resume(self, trigger_duration=0):
|
||||
"""Resumes pulse capture after an optional trigger pulse."""
|
||||
if trigger_duration != 0:
|
||||
self._mq.send("t%d" % trigger_duration, True, type=1)
|
||||
else:
|
||||
self._mq.send("r", True, type=1)
|
||||
self._paused = False
|
||||
|
||||
def pause(self):
|
||||
"""Pause pulse capture"""
|
||||
self._mq.send("p", True, type=1)
|
||||
self._paused = True
|
||||
|
||||
@property
|
||||
def paused(self):
|
||||
"""True when pulse capture is paused as a result of pause() or
|
||||
an error during capture such as a signal that is too fast."""
|
||||
return self._paused
|
||||
|
||||
@property
|
||||
def maxlen(self):
|
||||
"""The maximum length of the PulseIn. When len() is equal to maxlen,
|
||||
it is unclear which pulses are active and which are idle."""
|
||||
return self._maxlen
|
||||
|
||||
def clear(self):
|
||||
"""Clears all captured pulses"""
|
||||
self._mq.send("c", True, type=1)
|
||||
|
||||
def popleft(self):
|
||||
"""Removes and returns the oldest read pulse."""
|
||||
self._mq.send("^", True, type=1)
|
||||
message = self._wait_receive_msg()
|
||||
reply = int(message[0].decode("utf-8"))
|
||||
# print(reply)
|
||||
if reply == -1:
|
||||
raise IndexError("pop from empty list")
|
||||
return reply
|
||||
|
||||
def __len__(self):
|
||||
"""Returns the current pulse length"""
|
||||
self._mq.send("l", True, type=1)
|
||||
message = self._wait_receive_msg()
|
||||
return int(message[0].decode("utf-8"))
|
||||
|
||||
# pylint: disable=redefined-builtin
|
||||
def __getitem__(self, index, type=None):
|
||||
"""Returns the value at the given index or values in slice."""
|
||||
self._mq.send("i%d" % index, True, type=1)
|
||||
message = self._wait_receive_msg()
|
||||
ret = int(message[0].decode("utf-8"))
|
||||
if ret == -1:
|
||||
raise IndexError("list index out of range")
|
||||
return ret
|
||||
|
||||
# pylint: enable=redefined-builtin
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
# SPDX-FileCopyrightText: 2023 Jan Volckaert for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,93 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""AmLogic s905 pin names"""
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
GPIO122 = Pin((0, 0))
|
||||
GPIO123 = Pin((0, 1))
|
||||
GPIO124 = Pin((0, 2))
|
||||
GPIO125 = Pin((0, 3))
|
||||
GPIO126 = Pin((0, 4))
|
||||
GPIO127 = Pin((0, 5))
|
||||
GPIO128 = Pin((0, 6))
|
||||
GPIO129 = Pin((0, 7))
|
||||
GPIO130 = Pin((0, 8))
|
||||
GPIO131 = Pin((0, 9))
|
||||
GPIO132 = Pin((0, 10))
|
||||
GPIO133 = Pin((0, 11))
|
||||
GPIO134 = Pin((0, 12))
|
||||
GPIO135 = Pin((0, 13))
|
||||
|
||||
GPIO205 = Pin((1, 69))
|
||||
GPIO206 = Pin((1, 70))
|
||||
GPIO207 = Pin((1, 71))
|
||||
GPIO208 = Pin((1, 72))
|
||||
GPIO209 = Pin((1, 73))
|
||||
GPIO210 = Pin((1, 74))
|
||||
|
||||
GPIO211 = Pin((1, 75))
|
||||
GPIO212 = Pin((1, 76))
|
||||
GPIO213 = Pin((1, 77))
|
||||
GPIO214 = Pin((1, 78))
|
||||
GPIO215 = Pin((1, 79))
|
||||
GPIO216 = Pin((1, 80))
|
||||
GPIO217 = Pin((1, 81))
|
||||
GPIO218 = Pin((1, 82))
|
||||
GPIO219 = Pin((1, 83))
|
||||
GPIO220 = Pin((1, 84))
|
||||
GPIO221 = Pin((1, 85))
|
||||
GPIO222 = Pin((1, 86))
|
||||
GPIO223 = Pin((1, 87))
|
||||
GPIO224 = Pin((1, 88))
|
||||
GPIO225 = Pin((1, 89))
|
||||
GPIO226 = Pin((1, 90))
|
||||
GPIO227 = Pin((1, 91))
|
||||
|
||||
GPIO228 = Pin((1, 92))
|
||||
GPIO229 = Pin((1, 93))
|
||||
GPIO230 = Pin((1, 94))
|
||||
GPIO231 = Pin((1, 95))
|
||||
GPIO232 = Pin((1, 96))
|
||||
GPIO233 = Pin((1, 97))
|
||||
GPIO234 = Pin((1, 98))
|
||||
GPIO235 = Pin((1, 99))
|
||||
GPIO236 = Pin((1, 100))
|
||||
GPIO237 = Pin((1, 101))
|
||||
GPIO238 = Pin((1, 102))
|
||||
GPIO239 = Pin((1, 103))
|
||||
GPIO240 = Pin((1, 104))
|
||||
GPIO241 = Pin((1, 105))
|
||||
GPIO242 = Pin((1, 106))
|
||||
GPIO243 = Pin((1, 107))
|
||||
GPIO247 = Pin((1, 111))
|
||||
GPIO248 = Pin((1, 112))
|
||||
GPIO249 = Pin((1, 113))
|
||||
|
||||
I2C0_SDA = GPIO205
|
||||
I2C0_SCL = GPIO206
|
||||
I2C1_SDA = GPIO207
|
||||
I2C1_SCL = GPIO208
|
||||
I2C2_SDA = GPIO209
|
||||
I2C2_SCL = GPIO210
|
||||
|
||||
UART1_TX = GPIO240
|
||||
UART1_RX = GPIO241
|
||||
UART2_TX = GPIO205
|
||||
UART2_RX = GPIO206
|
||||
|
||||
SPI0_SCLK = GPIO230
|
||||
SPI0_MISO = GPIO232
|
||||
SPI0_MOSI = GPIO235
|
||||
|
||||
i2cPorts = (
|
||||
(0, I2C0_SCL, I2C0_SDA),
|
||||
(1, I2C1_SCL, I2C1_SDA),
|
||||
)
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = ((0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO),)
|
||||
# ordered as uartId, txId, rxId
|
||||
uartPorts = (
|
||||
(1, UART1_TX, UART1_RX),
|
||||
(2, UART2_TX, UART2_RX),
|
||||
)
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,75 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""AmLogic s905x pin names"""
|
||||
# pylint: disable=wildcard-import,unused-wildcard-import
|
||||
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
|
||||
|
||||
# Chip 0
|
||||
GPIO100 = Pin((0, 0))
|
||||
GPIO101 = Pin((0, 1))
|
||||
GPIO104 = Pin((0, 4))
|
||||
GPIO105 = Pin((0, 5))
|
||||
GPIO106 = Pin((0, 6))
|
||||
GPIO109 = Pin((0, 9))
|
||||
GPIO110 = Pin((0, 10))
|
||||
|
||||
# Chip 1
|
||||
GPIO220 = Pin((1, 20))
|
||||
GPIO222 = Pin((1, 22))
|
||||
GPIO223 = Pin((1, 23))
|
||||
GPIO224 = Pin((1, 24))
|
||||
GPIO225 = Pin((1, 25))
|
||||
GPIO275 = Pin((1, 75))
|
||||
GPIO276 = Pin((1, 76))
|
||||
GPIO279 = Pin((1, 79))
|
||||
GPIO280 = Pin((1, 80))
|
||||
GPIO281 = Pin((1, 81))
|
||||
GPIO282 = Pin((1, 82))
|
||||
GPIO283 = Pin((1, 83))
|
||||
GPIO284 = Pin((1, 84))
|
||||
GPIO285 = Pin((1, 85))
|
||||
GPIO286 = Pin((1, 86))
|
||||
GPIO287 = Pin((1, 87))
|
||||
GPIO288 = Pin((1, 88))
|
||||
GPIO289 = Pin((1, 89))
|
||||
GPIO290 = Pin((1, 90))
|
||||
GPIO291 = Pin((1, 91))
|
||||
GPIO292 = Pin((1, 92))
|
||||
GPIO293 = Pin((1, 93))
|
||||
GPIO294 = Pin((1, 94))
|
||||
GPIO295 = Pin((1, 95))
|
||||
GPIO296 = Pin((1, 96))
|
||||
GPIO297 = Pin((1, 97))
|
||||
GPIO298 = Pin((1, 98))
|
||||
|
||||
I2C0_SDA = GPIO105
|
||||
I2C0_SCK = GPIO104
|
||||
I2C1_SDA = GPIO275
|
||||
I2C1_SCK = GPIO276
|
||||
|
||||
UART1_RX = GPIO288
|
||||
UART1_TX = GPIO287
|
||||
UART2_RX = GPIO292
|
||||
UART2_TX = GPIO291
|
||||
|
||||
SPI0_SCLK = GPIO290
|
||||
SPI0_MISO = GPIO288
|
||||
SPI0_MOSI = GPIO287
|
||||
SPI0_CS = GPIO289
|
||||
SPI1_SCLK = GPIO223
|
||||
SPI1_MISO = GPIO288
|
||||
SPI1_MOSI = GPIO287
|
||||
SPI1_CS = GPIO289
|
||||
|
||||
i2cPorts = (
|
||||
(0, I2C0_SCK, I2C0_SDA),
|
||||
(1, I2C1_SCK, I2C1_SDA),
|
||||
)
|
||||
|
||||
spiPorts = ((0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO), (1, SPI1_SCLK, SPI1_MOSI, SPI1_MISO))
|
||||
|
||||
uartPorts = (
|
||||
(1, UART1_TX, UART1_RX),
|
||||
(2, UART2_TX, UART2_RX),
|
||||
)
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""AmLogic s905x3 pin names"""
|
||||
# pylint: disable=wildcard-import,unused-wildcard-import
|
||||
from adafruit_blinka.microcontroller.amlogic.meson_g12_common.pin import *
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue