66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
# SPDX-FileCopyrightText: 2021-2023 Kattni Rembor for Adafruit Industries
|
|
# SPDX-License-Identifier: MIT
|
|
"""CircuitPython I2C possible pin-pair identifying script"""
|
|
import board
|
|
import busio
|
|
from microcontroller import Pin
|
|
|
|
|
|
def is_hardware_i2c(scl, sda):
|
|
try:
|
|
p = busio.I2C(scl, sda)
|
|
p.deinit()
|
|
return True
|
|
except ValueError:
|
|
return False
|
|
except RuntimeError:
|
|
return True
|
|
|
|
|
|
def get_unique_pins():
|
|
exclude = [
|
|
getattr(board, p)
|
|
for p in [
|
|
# This is not an exhaustive list of unexposed pins. Your results
|
|
# may include other pins that you cannot easily connect to.
|
|
"NEOPIXEL",
|
|
"DOTSTAR_CLOCK",
|
|
"DOTSTAR_DATA",
|
|
"APA102_SCK",
|
|
"APA102_MOSI",
|
|
"LED",
|
|
"SWITCH",
|
|
"BUTTON",
|
|
"ACCELEROMETER_INTERRUPT",
|
|
"VOLTAGE_MONITOR",
|
|
"MICROPHONE_CLOCK",
|
|
"MICROPHONE_DATA",
|
|
"RFM_RST",
|
|
"RFM_CS",
|
|
"RFM_IO0",
|
|
"RFM_IO1",
|
|
"RFM_IO2",
|
|
"RFM_IO3",
|
|
"RFM_IO4",
|
|
"RFM_IO5",
|
|
]
|
|
if p in dir(board)
|
|
]
|
|
pins = [
|
|
pin
|
|
for pin in [getattr(board, p) for p in dir(board)]
|
|
if isinstance(pin, Pin) and pin not in exclude
|
|
]
|
|
unique = []
|
|
for p in pins:
|
|
if p not in unique:
|
|
unique.append(p)
|
|
return unique
|
|
|
|
|
|
for scl_pin in get_unique_pins():
|
|
for sda_pin in get_unique_pins():
|
|
if scl_pin is sda_pin:
|
|
continue
|
|
if is_hardware_i2c(scl_pin, sda_pin):
|
|
print("SCL pin:", scl_pin, "\t SDA pin:", sda_pin)
|