Created
March 17, 2017 20:02
-
-
Save dominicgs/40825221ec7ca40b98b83594905df7ac to your computer and use it in GitHub Desktop.
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 | |
import csv | |
class Pin(object): | |
def __init__(self, name, number): | |
self.name = name | |
if self.name.startswith('P'): | |
x = self.name.split('_') | |
self.port = x[0].strip('P') | |
self.pin = x[1] | |
else: | |
self.port = '' | |
self.pin = '' | |
self.number = number | |
self.functions = [] | |
def add_function(self, function): | |
self.functions.append(function) | |
def __repr__(self): | |
return '%s %s\n%s %s %s' % (self.port, self.pin, self.name, self.number, self.functions) | |
if __name__ == "__main__": | |
with open('lpc43xx_pins.csv', 'r') as f: | |
reader = csv.reader(f) | |
pins = [] | |
current_pin = None | |
for line in reader: | |
if len(line)>=5 and line[0]: | |
if line[4] not in ('', '-'): | |
try: | |
pin_number = int(line[4]) | |
except: | |
# Not a numbered pin - so not on the part we care about | |
current_pin = None | |
next | |
current_pin = Pin(line[0], pin_number) | |
pins.append(current_pin) | |
else: | |
current_pin = None | |
if len(line) >= 9 and line[8] and current_pin: | |
func_name = line[8].split('—')[0].strip() | |
if func_name == 'R': | |
func_name = '*' | |
pins[-1].add_function(func_name) | |
y = [] | |
for p in pins: | |
y.append((p.number, p.name, p)) | |
y.sort() | |
for num, name, p in y: | |
print(p) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment