Last active
July 16, 2025 21:24
-
-
Save todbot/e91853b9d5e021405bb9a85081a39163 to your computer and use it in GitHub Desktop.
Find the defined board.* pins for a CircuitPython board, given a repo directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Find all the defined pins for a CircuitPython board | |
# 5 Jul 2025 - @todbot / Tod Kurt | |
# e.g. "cirpy-showpins.py qtpy_m0 ~/projects/adafruit/circuitpython" | |
# Note: you need a checkout of the CircuitPython github repo for this tool to work | |
# e.g. "mkdir -f ~/projects/adafruit && cd ~/projects/adafruit && git checkout https://github.com/adafruit/circuitpython/" | |
import os, sys, re | |
if len(sys.argv) <= 1: | |
print("usage: cirpy-showpins.py board_id [repo_dir]") | |
exit(1) | |
home_dir = os.path.expanduser('~') | |
board_id = sys.argv[1] | |
cirpy_repo = sys.argv[2] if len(sys.argv)==3 else home_dir + "/projects/adafruit/circuitpython" | |
print("board_id:", board_id) | |
def find_port_dir(board_id, repo_dir): | |
"""Find port directory for given board_id or None""" | |
ports_dir = repo_dir+"/ports" | |
for root, dirs, files in os.walk(ports_dir): | |
for d in dirs: | |
if d.endswith(board_id) and d.find('build')==-1: | |
return root + "/" + d | |
return None | |
def find_pins(board_id, repo_dir): | |
port_dir = find_port_dir(board_id, repo_dir) | |
if not port_dir: | |
print("no board found with id", board_id) | |
exit(1) | |
pins = [] | |
with open(port_dir+"/pins.c", "r") as pin_file: | |
for line in pin_file: | |
if m:= re.search(r'MP_QSTR_(.+?)\)', line): | |
pins.append(m[1]) | |
return pins | |
pins = find_pins(board_id, cirpy_repo) | |
print("pins:", " ".join(sorted(pins))) |
Great project!
Thanks! I only now realized that this replicates some of the function of board_stub_builder.py
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great project!