1 # SPDX-FileCopyrightText: 2025 Brett Walach for Particle
3 # SPDX-License-Identifier: MIT
4 """Quectel QCM6490 pin names"""
5 # from adafruit_blinka.microcontroller.generic_linux.sysfs_pin import Pin
6 # from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
7 from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin as GenericLinuxPin
11 # Release (unexport) all pins on init and set to INPUT mode
12 class Pin(GenericLinuxPin):
13 def __init__(self, pin_id):
14 self._release_sysfs_gpio(pin_id)
15 super().__init__(pin_id)
17 def _release_sysfs_gpio(self, pin_id, base_offset=336):
18 # pin_id might be a tuple like (chip_id, line_number)
19 if isinstance(pin_id, tuple):
20 _, line_number = pin_id
24 gpio_num = base_offset + int(line_number)
25 gpio_path = f"/sys/class/gpio/gpio{gpio_num}"
28 if not os.path.exists(gpio_path):
29 with open("/sys/class/gpio/export", "w") as f:
30 f.write(f"{gpio_num}")
31 with open(f"{gpio_path}/direction", "w") as f:
33 with open("/sys/class/gpio/unexport", "w") as f:
34 f.write(f"{gpio_num}")
36 # fail silently if not allowed
42 # Use with libgpiod_pin
45 GPIO_6 = Pin(GPIO_BASE + 6)
48 GPIO_8 = Pin(GPIO_BASE + 8)
51 GPIO_9 = Pin(GPIO_BASE + 9)
54 GPIO_18 = Pin(GPIO_BASE + 18)
57 GPIO_19 = Pin(GPIO_BASE + 19)
60 GPIO_24 = Pin(GPIO_BASE + 24)
61 GPIO_33 = Pin(GPIO_BASE + 33)
65 GPIO_34 = Pin(GPIO_BASE + 34)
68 GPIO_36 = Pin(GPIO_BASE + 36)
73 GPIO_37 = Pin(GPIO_BASE + 37)
77 GPIO_48 = Pin(GPIO_BASE + 48)
82 GPIO_49 = Pin(GPIO_BASE + 49)
87 GPIO_50 = Pin(GPIO_BASE + 50)
92 GPIO_51 = Pin(GPIO_BASE + 51)
96 GPIO_56 = Pin(GPIO_BASE + 56)
98 GPIO_57 = Pin(GPIO_BASE + 57)
106 GPIO_58 = Pin(GPIO_BASE + 58)
110 GPIO_59 = Pin(GPIO_BASE + 59)
113 GPIO_61 = Pin((0, GPIO_BASE + 61))
114 GPIO_62 = Pin(GPIO_BASE + 62)
116 GPIO_106 = Pin(GPIO_BASE + 106)
117 UART13_TXD = GPIO_106
119 GPIO_144 = Pin(GPIO_BASE + 144)
120 PRI_MI2S_MCLK = GPIO_144
121 GPIO_145 = Pin(GPIO_BASE + 145)
124 GPIO_146 = Pin(GPIO_BASE + 146)
125 MI2S0_DATA0 = GPIO_146
126 GPIO_147 = Pin(GPIO_BASE + 147)
127 MI2S0_DATA1 = GPIO_147
128 GPIO_158 = Pin(GPIO_BASE + 158)
129 GPIO_165 = Pin(GPIO_BASE + 165)
130 GPIO_166 = Pin(GPIO_BASE + 166)
132 # ordered as i2cId, i2cSclId, i2cSdaId
133 i2cPorts = ((1, I2C02_SCL, I2C02_SDA),)
135 # ordered as spiId, sckId, mosiId, misoId
136 spiPorts = ((16, SPI16_CLK, SPI16_MOSI, SPI16_MISO),)
138 # ordered as uartId, txId, rxId
139 uartPorts = ((14, UART14_TXD, UART14_RXD),)
141 # ordered as pwmChipId, pwmChannelId, pwmId
142 pwmOuts = (((0, 0), PWM1),)