mirror of
https://github.com/easytarget/MQ-Pro-IO.git
synced 2026-01-30 23:03:28 +00:00
pin map tool
This commit is contained in:
@@ -1,21 +1,64 @@
|
||||
from subprocess import run,PIPE
|
||||
import shlex
|
||||
from importlib import import_module
|
||||
from sys import path,argv
|
||||
path.append('maps')
|
||||
|
||||
'''
|
||||
Runs 'gpioinfo' and parses it's output to a more human form, with pin designator included
|
||||
Gathers the pinmux table and parses it's output to a more human form, with pin designator included
|
||||
'''
|
||||
|
||||
rawlist = run(['sudo', 'gpioinfo'],stdout=PIPE,universal_newlines=True)
|
||||
pinlist = rawlist.stdout.splitlines()[1:]
|
||||
# get the model for our board, generate an index and prep it
|
||||
dtname = run(['cat','/proc/device-tree/model'],stdout=PIPE,universal_newlines=True).stdout[:-1]
|
||||
if len(argv) == 2:
|
||||
model = argv[1]
|
||||
else:
|
||||
model = dtname
|
||||
board = import_module(model.replace(' ','-'))
|
||||
muxindex = [pin[0] for pin in board.gpio]
|
||||
for pin in board.gpio:
|
||||
pin.append('')
|
||||
|
||||
# start
|
||||
print('{} (dtb name: {})\n'.format(board.name, dtname))
|
||||
|
||||
# Get the full pinmux list
|
||||
rawlist = run(['sudo', 'cat','/sys/kernel/debug/pinctrl/2000000.pinctrl/pinmux-pins'],stdout=PIPE,universal_newlines=True).stdout
|
||||
pinlist = rawlist.splitlines()[2:]
|
||||
|
||||
# interpret list
|
||||
for line in pinlist:
|
||||
out = shlex.split(line)
|
||||
number = int(out[1][:-1])
|
||||
pin = 'P{}{}'.format('ABCDEFGH'[int(number / 32)], number % 32)
|
||||
print('pin: {:3d}, {:>4}'.format(number, pin), end='')
|
||||
print(', {:>6}'.format(out[4]), end='')
|
||||
if out[2] != 'unnamed':
|
||||
print(', name: ' + out[2], end='')
|
||||
if out[3] != 'unused':
|
||||
print(', used by: ' + out[3], end='')
|
||||
pmux = line.split()
|
||||
if int(pmux[1]) in muxindex:
|
||||
state = 'free'
|
||||
if pmux[3] == 'device':
|
||||
state = pmux[6] + ' (' + pmux[4] + ')'
|
||||
elif pmux[3] == 'GPIO':
|
||||
state = 'gpio (' + pmux[4] + ')'
|
||||
board.gpio[muxindex.index(int(pmux[1]))][3] = state
|
||||
|
||||
# work out column widths
|
||||
width = []
|
||||
for c in range(0, board.cols):
|
||||
wide = 0
|
||||
for p in range(c, len(board.gpio), board.cols):
|
||||
w = len(board.gpio[p][3])
|
||||
wide = w if w > wide else wide
|
||||
width.append(wide)
|
||||
|
||||
# Output result.
|
||||
for l in range(0, len(board.gpio), board.cols):
|
||||
for p in range(l, l + board.cols):
|
||||
if board.gpio[p][2] is None:
|
||||
board.gpio[p][3] = ''
|
||||
board.gpio[p][2] = ''
|
||||
pad = (width[p - l] - len(board.gpio[p][3])) * ' '
|
||||
if p % 2 == 0:
|
||||
print(' {}{} {:>5} {:>3} --o'.format(pad, board.gpio[p][3], board.gpio[p][2], str(board.gpio[p][1])), end='')
|
||||
else:
|
||||
print(' o-- {:3} {:5} {}{} '.format(str(board.gpio[p][1]), board.gpio[p][2], board.gpio[p][3], pad), end='')
|
||||
print()
|
||||
|
||||
print()
|
||||
print('Notes:')
|
||||
for l in board.notes:
|
||||
print('- ' + l)
|
||||
|
||||
Reference in New Issue
Block a user