mirror of
https://github.com/easytarget/MQ-Pro-IO.git
synced 2025-10-14 09:45:52 +01:00
pin map tool
This commit is contained in:
parent
e82fcf1d11
commit
d1669f1e43
@ -1,21 +1,64 @@
|
|||||||
from subprocess import run,PIPE
|
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)
|
# get the model for our board, generate an index and prep it
|
||||||
pinlist = rawlist.stdout.splitlines()[1:]
|
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:
|
for line in pinlist:
|
||||||
out = shlex.split(line)
|
pmux = line.split()
|
||||||
number = int(out[1][:-1])
|
if int(pmux[1]) in muxindex:
|
||||||
pin = 'P{}{}'.format('ABCDEFGH'[int(number / 32)], number % 32)
|
state = 'free'
|
||||||
print('pin: {:3d}, {:>4}'.format(number, pin), end='')
|
if pmux[3] == 'device':
|
||||||
print(', {:>6}'.format(out[4]), end='')
|
state = pmux[6] + ' (' + pmux[4] + ')'
|
||||||
if out[2] != 'unnamed':
|
elif pmux[3] == 'GPIO':
|
||||||
print(', name: ' + out[2], end='')
|
state = 'gpio (' + pmux[4] + ')'
|
||||||
if out[3] != 'unused':
|
board.gpio[muxindex.index(int(pmux[1]))][3] = state
|
||||||
print(', used by: ' + out[3], end='')
|
|
||||||
|
# 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()
|
||||||
|
print('Notes:')
|
||||||
|
for l in board.notes:
|
||||||
|
print('- ' + l)
|
||||||
|
40
tools/maps/MangoPi-MQ-Pro.py
Normal file
40
tools/maps/MangoPi-MQ-Pro.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
'''
|
||||||
|
Map file for a MangoPi MQ Pro
|
||||||
|
|
||||||
|
The 'gpio' list has 40 entries corresponding
|
||||||
|
to pins 1-40 on the 2-row GPIO header.
|
||||||
|
|
||||||
|
Each gpio[] entry is a list with two items:
|
||||||
|
[0] the pinmux pin number, or 'None' if a power pin
|
||||||
|
[1] the pin number on the connector
|
||||||
|
[2] a text description, or 'None' to omit the pin
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
name = 'MangoPI MQ Pro GPIO header'
|
||||||
|
cols = 2
|
||||||
|
gpio = [
|
||||||
|
[None, 1, '3v3'], [None, 2, '5v'],
|
||||||
|
[ 205, 3, 'PG13'], [None, 4, '5v'],
|
||||||
|
[ 204, 5, 'PG12'], [None, 6, 'gnd'],
|
||||||
|
[ 39, 7, 'PB7'], [ 40, 8, 'PB8'],
|
||||||
|
[None, 9, 'gnd'], [ 41, 10, 'PB9'],
|
||||||
|
[ 117, 11, 'PD21'], [ 37, 12, 'PB5'],
|
||||||
|
[ 118, 13, 'PD22'], [None, 14, 'gnd'],
|
||||||
|
[ 32, 15, 'PB0'], [ 33, 16, 'PB1'],
|
||||||
|
[None, 17, '3v3'], [ 110, 18, 'PD14'],
|
||||||
|
[ 108, 19, 'PD12'], [None, 20, 'gnd'],
|
||||||
|
[ 109, 21, 'PD13'], [ 65, 22, 'PC1'],
|
||||||
|
[ 107, 23, 'PD11'], [ 106, 24, 'PD10'],
|
||||||
|
[None, 25, 'gnd'], [ 111, 26, 'PD15'],
|
||||||
|
[ 145, 27, 'PE17'], [ 144, 28, 'PE16'],
|
||||||
|
[ 42, 29, 'PB10'], [None, 30, 'gnd'],
|
||||||
|
[ 43, 31, 'PB11'], [ 64, 32, 'PC0'],
|
||||||
|
[ 44, 33, 'PB12'], [None, 34, 'gnd'],
|
||||||
|
[ 38, 35, 'PB6'], [ 34, 36, 'PB2'],
|
||||||
|
[ 113, 37, 'PD17'], [ 35, 38, 'PB3'],
|
||||||
|
[None, 39, 'gnd'], [ 36, 40, 'PB4'],
|
||||||
|
]
|
||||||
|
notes = ['I2C pins 2,5,27 and 28 (PG13, PG12, PE17 and PE16) have 10K pullup resistors to 3v3',
|
||||||
|
'The onboard blue status LED is on PD18 [pwm2]']
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user