moved a bunch of garbage (things that have nothing to do in root) to _trash
This commit is contained in:
parent
d094982b2c
commit
3226ed29ec
2610 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,159 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Custom PWMOut Wrapper for Jetson GPIO PWM Class"""
|
||||
from RPi import GPIO
|
||||
|
||||
GPIO.setmode(GPIO.TEGRA_SOC) # Use BCM pins D4 = GPIO #4
|
||||
GPIO.setwarnings(True) # shh!
|
||||
|
||||
|
||||
class PWMError(IOError):
|
||||
"""Base class for PWM errors."""
|
||||
|
||||
|
||||
class PWMOut:
|
||||
"""Pulse Width Modulation Output Class"""
|
||||
|
||||
def __init__(self, pin, *, frequency=500, duty_cycle=0, variable_frequency=False):
|
||||
self._pwmpin = 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._pin = pin
|
||||
GPIO.setup(pin.id, GPIO.OUT, initial=GPIO.HIGH)
|
||||
self._pwmpin = GPIO.PWM(pin.id, freq)
|
||||
|
||||
if variable_frequency:
|
||||
print("Variable Frequency is not supported, continuing without it...")
|
||||
|
||||
# set frequency
|
||||
self.frequency = freq
|
||||
# set duty
|
||||
self.duty_cycle = duty
|
||||
|
||||
self.enabled = True
|
||||
|
||||
def deinit(self):
|
||||
"""Deinit the PWM."""
|
||||
if self._pwmpin is not None:
|
||||
self._pwmpin.stop()
|
||||
GPIO.cleanup(self._pin.id)
|
||||
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))
|
||||
|
||||
@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.")
|
||||
|
||||
self._pwmpin.ChangeFrequency(round(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.start(round(self._duty_cycle * 100))
|
||||
else:
|
||||
self._pwmpin.stop()
|
||||
|
||||
self._enabled = value
|
||||
|
||||
# String representation
|
||||
def __str__(self):
|
||||
return "pin %s (freq=%f Hz, duty_cycle=%f%%)" % (
|
||||
self._pin,
|
||||
self.frequency,
|
||||
self.duty_cycle,
|
||||
)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,138 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Tegra T186 pin names"""
|
||||
|
||||
import atexit
|
||||
from Jetson import GPIO
|
||||
|
||||
GPIO.setmode(GPIO.TEGRA_SOC)
|
||||
GPIO.setwarnings(False) # shh!
|
||||
|
||||
|
||||
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, bcm_number):
|
||||
self.id = bcm_number
|
||||
|
||||
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)
|
||||
return None
|
||||
if val == self.HIGH:
|
||||
self._value = val
|
||||
GPIO.output(self.id, val)
|
||||
return None
|
||||
raise RuntimeError("Invalid value for pin")
|
||||
return GPIO.input(self.id)
|
||||
|
||||
# pylint: disable=no-method-argument
|
||||
@atexit.register
|
||||
def cleanup():
|
||||
"""Clean up pins"""
|
||||
print("Exiting... \nCleaning up pins")
|
||||
GPIO.cleanup()
|
||||
|
||||
# pylint: enable=no-method-argument
|
||||
|
||||
|
||||
# Cannot be used as GPIO
|
||||
SDA = Pin("GPIO_SEN9")
|
||||
SCL = Pin("GPIO_SEN8")
|
||||
SDA_1 = Pin("GEN1_I2C_SDA")
|
||||
SCL_1 = Pin("GEN1_I2C_SCL")
|
||||
|
||||
# Jetson TX2 specific
|
||||
J06 = Pin("GPIO_AUD1")
|
||||
AA02 = Pin("CAN_GPIO2")
|
||||
N06 = Pin("GPIO_CAM7")
|
||||
N04 = Pin("GPIO_CAM5")
|
||||
N05 = Pin("GPIO_CAM6")
|
||||
N03 = Pin("GPIO_CAM4")
|
||||
AA01 = Pin("CAN_GPIO1")
|
||||
I05 = Pin("GPIO_PQ5")
|
||||
T03 = Pin("UART1_CTS")
|
||||
T02 = Pin("UART1_RTS")
|
||||
P17 = Pin("GPIO_EXP_P17")
|
||||
AA00 = Pin("CAN_GPIO0")
|
||||
Y01 = Pin("GPIO_MDM2")
|
||||
P16 = Pin("GPIO_EXP_P16")
|
||||
I04 = Pin("GPIO_PQ4")
|
||||
J05 = Pin("GPIO_AUD0")
|
||||
|
||||
# Jetson TX2 NX specific
|
||||
W04 = Pin("UART3_RTS")
|
||||
V01 = Pin("GPIO_SEN1")
|
||||
C02 = Pin("DAP2_DOUT")
|
||||
C03 = Pin("DAP2_DIN")
|
||||
V04 = Pin("GPIO_SEN4")
|
||||
H02 = Pin("GPIO_WAN7")
|
||||
H01 = Pin("GPIO_WAN6")
|
||||
V02 = Pin("GPIO_SEN2")
|
||||
H00 = Pin("GPIO_WAN5")
|
||||
H03 = Pin("GPIO_WAN8")
|
||||
Y03 = Pin("GPIO_MDM4")
|
||||
N01 = Pin("GPIO_CAM2")
|
||||
EE02 = Pin("TOUCH_CLK")
|
||||
U00 = Pin("GPIO_DIS0")
|
||||
U05 = Pin("GPIO_DIS5")
|
||||
W05 = Pin("UART3_CTS")
|
||||
V03 = Pin("GPIO_SEN3")
|
||||
|
||||
# Shared pin
|
||||
J03 = Pin("DAP1_FS")
|
||||
J02 = Pin("DAP1_DIN")
|
||||
J01 = Pin("DAP1_DOUT")
|
||||
J00 = Pin("DAP1_SCLK")
|
||||
J04 = Pin("AUD_MCLK")
|
||||
|
||||
i2cPorts = (
|
||||
(1, SCL, SDA),
|
||||
(0, SCL_1, SDA_1),
|
||||
)
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = ((3, N03, N05, N04),)
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,137 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Tegra T194 pin names"""
|
||||
import atexit
|
||||
from Jetson import GPIO
|
||||
|
||||
GPIO.setmode(GPIO.TEGRA_SOC)
|
||||
GPIO.setwarnings(False) # shh!
|
||||
|
||||
|
||||
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, bcm_number):
|
||||
self.id = bcm_number
|
||||
|
||||
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)
|
||||
return None
|
||||
if val == self.HIGH:
|
||||
self._value = val
|
||||
GPIO.output(self.id, val)
|
||||
return None
|
||||
raise RuntimeError("Invalid value for pin")
|
||||
return GPIO.input(self.id)
|
||||
|
||||
# pylint: disable=no-method-argument
|
||||
@atexit.register
|
||||
def cleanup():
|
||||
"""Clean up pins"""
|
||||
print("Exiting... \nCleaning up pins")
|
||||
GPIO.cleanup()
|
||||
|
||||
# pylint: enable=no-method-argument
|
||||
|
||||
|
||||
# Cannot be used as GPIO
|
||||
SDA = Pin("DP_AUX_CH3_N")
|
||||
SCL = Pin("DP_AUX_CH3_P")
|
||||
SDA_1 = Pin("GEN2_I2C_SDA")
|
||||
SCL_1 = Pin("GEN2_I2C_SCL")
|
||||
|
||||
# Jetson Xavier only
|
||||
Q06 = Pin("SOC_GPIO42")
|
||||
AA03 = Pin("CAN0_DIN")
|
||||
AA02 = Pin("CAN0_DOUT")
|
||||
BB01 = Pin("CAN1_EN")
|
||||
AA00 = Pin("CAN1_DOUT")
|
||||
H07 = Pin("DAP2_SCLK")
|
||||
I02 = Pin("DAP2_FS")
|
||||
I01 = Pin("DAP2_DIN")
|
||||
I00 = Pin("DAP2_DOUT")
|
||||
BB00 = Pin("CAN1_STB")
|
||||
H00 = Pin("SOC_GPIO12")
|
||||
Q01 = Pin("SOC_GPIO21")
|
||||
AA01 = Pin("CAN1_DIN")
|
||||
|
||||
# Jetson NX only
|
||||
S04 = Pin("AUD_MCLK")
|
||||
T05 = Pin("DAP5_SCLK")
|
||||
Y00 = Pin("SPI3_SCK")
|
||||
CC04 = Pin("TOUCH_CLK")
|
||||
Y04 = Pin("SPI3_CS1_N")
|
||||
Y03 = Pin("SPI3_CS0_N")
|
||||
Y01 = Pin("SPI3_MISO")
|
||||
Q05 = Pin("SOC_GPIO41")
|
||||
Q06 = Pin("SOC_GPIO42")
|
||||
U00 = Pin("DAP5_FS")
|
||||
Y02 = Pin("SPI3_MOSI")
|
||||
T07 = Pin("DAP5_DIN")
|
||||
T06 = Pin("DAP5_DOUT")
|
||||
|
||||
# Clara AGX Xavier only
|
||||
P04 = Pin("SOC_GPIO04")
|
||||
|
||||
# Shared
|
||||
N01 = Pin("SOC_GPIO54")
|
||||
R00 = Pin("SOC_GPIO44")
|
||||
R04 = Pin("UART1_RTS")
|
||||
R05 = Pin("UART1_CTS")
|
||||
Z03 = Pin("SPI1_SCK")
|
||||
Z04 = Pin("SPI1_MISO")
|
||||
Z05 = Pin("SPI1_MOSI")
|
||||
Z06 = Pin("SPI1_CS0_N")
|
||||
Z07 = Pin("SPI1_CS1_N")
|
||||
|
||||
i2cPorts = (
|
||||
(8, SCL, SDA),
|
||||
(1, SCL_1, SDA_1),
|
||||
)
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = ((0, Z03, Z05, Z04),)
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,143 @@
|
|||
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Tegra T210 pin names"""
|
||||
|
||||
import atexit
|
||||
from Jetson import GPIO
|
||||
|
||||
GPIO.setmode(GPIO.TEGRA_SOC)
|
||||
GPIO.setwarnings(False) # shh!
|
||||
|
||||
|
||||
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, bcm_number):
|
||||
self.id = bcm_number
|
||||
|
||||
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)
|
||||
return None
|
||||
if val == self.HIGH:
|
||||
self._value = val
|
||||
GPIO.output(self.id, val)
|
||||
return None
|
||||
raise RuntimeError("Invalid value for pin")
|
||||
return GPIO.input(self.id)
|
||||
|
||||
# pylint: disable=no-method-argument
|
||||
@atexit.register
|
||||
def cleanup():
|
||||
"""Clean up pins"""
|
||||
print("Exiting... \nCleaning up pins")
|
||||
GPIO.cleanup()
|
||||
|
||||
# pylint: enable=no-method-argument
|
||||
|
||||
|
||||
# Cannot be used as GPIO
|
||||
SDA = Pin("GEN1_I2C_SDA")
|
||||
SCL = Pin("GEN1_I2C_SCL")
|
||||
SDA_1 = Pin("GEN2_I2C_SDA")
|
||||
SCL_1 = Pin("GEN2_I2C_SCL")
|
||||
|
||||
# These pins are native to TX1
|
||||
BB03 = Pin("GPIO_X1_AUD")
|
||||
X02 = Pin("MOTION_INT")
|
||||
H07 = Pin("AP_WAKE_NFC")
|
||||
E04 = Pin("DMIC3_CLK")
|
||||
U03 = Pin("UART1_CTS")
|
||||
U02 = Pin("UART1_RTS")
|
||||
B03 = Pin("DAP1_SCLK")
|
||||
B00 = Pin("DAP1_FS")
|
||||
B01 = Pin("DAP1_DIN")
|
||||
B02 = Pin("DAP1_DOUT")
|
||||
P17 = Pin("GPIO_EXP_P17")
|
||||
E05 = Pin("DMIC3_DAT")
|
||||
X00 = Pin("MODEM_WAKE_AP")
|
||||
P16 = Pin("GPIO_EXP_P16")
|
||||
X03 = Pin("ALS_PROX_INT")
|
||||
|
||||
# These pins are native to NANO
|
||||
S05 = Pin("CAM_AF_EN")
|
||||
Z00 = Pin("GPIO_PZ0")
|
||||
V00 = Pin("LCD_BL_PW")
|
||||
G03 = Pin("UART2_CTS")
|
||||
G02 = Pin("UART2_RTS")
|
||||
J07 = Pin("DAP4_SCLK")
|
||||
J04 = Pin("DAP4_FS")
|
||||
J05 = Pin("DAP4_DIN")
|
||||
J06 = Pin("DAP4_DOUT")
|
||||
Y02 = Pin("LCD_TE")
|
||||
DD00 = Pin("SPI2_CS1")
|
||||
B07 = Pin("SPI2_CS0")
|
||||
B05 = Pin("SPI2_MISO")
|
||||
B04 = Pin("SPI2_MOSI")
|
||||
B06 = Pin("SPI2_SCK")
|
||||
|
||||
# These pins are shared across T210
|
||||
BB00 = Pin("AUD_MCLK")
|
||||
C04 = Pin("SPI1_CS1")
|
||||
C03 = Pin("SPI1_CS0")
|
||||
C01 = Pin("SPI1_MISO")
|
||||
C00 = Pin("SPI1_MOSI")
|
||||
C02 = Pin("SPI1_SCK")
|
||||
E06 = Pin("GPIO_PE6")
|
||||
|
||||
i2cPorts = (
|
||||
(0, SCL, SDA),
|
||||
(1, SCL_1, SDA_1),
|
||||
)
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = ((0, C02, C00, C01), (1, B06, B04, B05))
|
||||
|
||||
# SysFS pwm outputs, pwm channel and pin in first tuple
|
||||
pwmOuts = (
|
||||
((0, 0), V00),
|
||||
((0, 1), E06),
|
||||
)
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,131 @@
|
|||
# SPDX-FileCopyrightText: 2022 Linh Hoang for NVIDIA
|
||||
# SPDX-FileCopyrightText: 2022 Melissa LeBlanc-Williams for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""Tegra T234 pin names"""
|
||||
import atexit
|
||||
from Jetson import GPIO
|
||||
|
||||
GPIO.setmode(GPIO.TEGRA_SOC)
|
||||
GPIO.setwarnings(False) # shh!
|
||||
|
||||
|
||||
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, bcm_number):
|
||||
self.id = bcm_number
|
||||
|
||||
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)
|
||||
return None
|
||||
if val == self.HIGH:
|
||||
self._value = val
|
||||
GPIO.output(self.id, val)
|
||||
return None
|
||||
raise RuntimeError("Invalid value for pin")
|
||||
return GPIO.input(self.id)
|
||||
|
||||
# pylint: disable=no-method-argument
|
||||
@atexit.register
|
||||
def cleanup():
|
||||
"""Clean up pins"""
|
||||
print("Exiting... \nCleaning up pins")
|
||||
GPIO.cleanup()
|
||||
|
||||
# pylint: enable=no-method-argument
|
||||
|
||||
|
||||
# Cannot be used as GPIO
|
||||
SDA = Pin("GP16_I2C8_DAT") # I2C4
|
||||
SCL = Pin("GP81_I2C9_CLK")
|
||||
SDA_1 = Pin("GP14_I2C2_DAT") # I2C2
|
||||
SCL_1 = Pin("GP13_I2C2_CLK")
|
||||
|
||||
# Jetson AGX Orin
|
||||
Q06 = Pin("GP66")
|
||||
R04 = Pin("GP72_UART1_RTS_N")
|
||||
H07 = Pin("GP122")
|
||||
R00 = Pin("GP68")
|
||||
N01 = Pin("GP88_PWM1")
|
||||
BB00 = Pin("GP25")
|
||||
H00 = Pin("GP115")
|
||||
Z05 = Pin("GP49_SPI1_MOSI")
|
||||
Z04 = Pin("GP48_SPI1_MISO")
|
||||
P04 = Pin("GP56")
|
||||
Z03 = Pin("GP47_SPI1_CLK")
|
||||
Z06 = Pin("GP50_SPI1_CS0_N")
|
||||
Z07 = Pin("GP51_SPI1_CS1_N")
|
||||
AA01 = Pin("GP18_CAN0_DIN")
|
||||
AA00 = Pin("GP17_CAN0_DOUT")
|
||||
BB01 = Pin("GP26")
|
||||
AA02 = Pin("GP19_CAN1_DOUT")
|
||||
I02 = Pin("GP125")
|
||||
R05 = Pin("GP73_UART1_CTS_N")
|
||||
AA03 = Pin("GP20_CAN1_DIN")
|
||||
I01 = Pin("GP124")
|
||||
I00 = Pin("GP123")
|
||||
|
||||
|
||||
AC06 = Pin("GP167")
|
||||
Y00 = Pin("SPI1_SCK")
|
||||
N01 = Pin("GP88_PWM1")
|
||||
Y04 = Pin("GP40_SPI3_CS1_N")
|
||||
Y03 = Pin("GP39_SPI3_CS0_N")
|
||||
Y01 = Pin("GP37_SPI3_MISO")
|
||||
Q05 = Pin("GP65")
|
||||
G06 = Pin("GP113_PWM7")
|
||||
Y02 = Pin("GP38_SPI3_MOSI")
|
||||
|
||||
|
||||
i2cPorts = (
|
||||
(7, SCL, SDA),
|
||||
(1, SCL_1, SDA_1),
|
||||
)
|
||||
|
||||
# ordered as spiId, sckId, mosiId, misoId
|
||||
spiPorts = ((0, Z03, Z05, Z04),)
|
Loading…
Add table
Add a link
Reference in a new issue