commit 0752dfb582927a173f0c184ccee5ec1d2d8f5a8f Author: Phil Howard Date: Tue Feb 24 09:59:29 2015 +0000 Initial Commit diff --git a/convert.py b/convert.py new file mode 100644 index 0000000..c798c18 --- /dev/null +++ b/convert.py @@ -0,0 +1,27 @@ +import json, sys + +db = json.load(open('pi-pinout.db')) + +def from_phys(phys, mode="bcm"): + pin = db['pins'][str(phys)] + if 'scheme' in pin: + if mode in pin['scheme']: + return int(pin['scheme'][mode]) + return None + +def to_phys(pin, mode="bcm"): + for pin in db['pins']: + if 'scheme' in db['pins'][pin]: + if mode in db['pins'][pin]['scheme']: + return int(pin) + return None + +pin = int(sys.argv[1]) + +mode = 'bcm' + +if len(sys.argv) > 2: + mode = sys.argv[2] + +print("Pin {} is {}: {}".format(pin,mode.upper(),from_phys(pin,mode))) + diff --git a/generate-html.py b/generate-html.py new file mode 100755 index 0000000..d8f28dd --- /dev/null +++ b/generate-html.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +import json +import unicodedata +import re + +overlays = ['pibrella','break'] + +def slugify(value): + """ + Normalizes string, converts to lowercase, removes non-alpha characters, + and converts spaces to hyphens. + """ + value = unicode(value) + value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') + value = re.sub('[^\w\s-]', '', value).strip().lower() + return re.sub('[-\s]+', '_', value) + +def load_overlay(overlay): + try: + return json.load(open('overlay/{}.json'.format(overlay))) + except IOError: + return None + +db = json.load(open('pi-pinout.json')) + +pins = db['pins'] + +html_odd = '' +html_even = '' + +overlays = map(load_overlay,overlays) + +def render_alternate(handle, name): + handle = slugify(handle.lower()) + return '{}'.format(handle,name) + +def render_pin(pin_num): + pin = pins[str(pin_num)] + pin_type = list([x.strip() for x in pin['type'].lower().split('/')]) + pin_url = pin['name'] + pin_name = pin['name'] + alternates = [] + + for overlay in overlays: + if overlay != None: + if str(pin_num) in overlay['pin']: + alternates.append(render_alternate(overlay['name'],overlay['pin'][str(pin_num)]['name'])) + + if 'scheme' in pin: + if 'bcm' in pin['scheme']: + bcm = pin['scheme']['bcm'] + pin_subname = '' + #if pin_url == '': + pin_url = 'gpio{}'.format(bcm) + if pin['name'] != '': + pin_subname = '({})'.format(pin['name']) + pin_name = 'GPIO {} {}'.format(bcm, pin_subname) + if 'wiringpi' in pin['scheme']: + wiringpi = pin['scheme']['wiringpi'] + alternates.append(render_alternate('wiringpi','Wiring Pi pin {}'.format(wiringpi))) + + #print(pin_type) + + return '
  • {} {}\n{}
  • \n'.format( + pin_num, + ' '.join(map(slugify,pin_type)), + pin_num, + slugify(pin_url), + pin_num, + pin_name, + '\n'.join(alternates) + ) + +for odd in range(1,len(pins),2): + html_odd += render_pin(odd) + html_even += render_pin(odd+1) + +html = ''.format(html_odd, html_even) + +print(html) diff --git a/overlay/explorer-hat-pro.json b/overlay/explorer-hat-pro.json new file mode 100644 index 0000000..c4f3d87 --- /dev/null +++ b/overlay/explorer-hat-pro.json @@ -0,0 +1,27 @@ +{ + "name": "Explorer HAT Pro", + "manufacturer": "Pimoroni", + "url": "https://github.com/pimoroni/explorer-hat", + "description": { + "short": "An all-in-one light, input, motor, touch and output add-on board.", + "long": "pibrella.md" + }, + "pin": { + "7": { + "name": "LED 1", + "exclusive": "true" + }, + "11": { + "name": "LED 2", + "exclusive": "true" + }, + "13": { + "name": "LED 3", + "exclusive": "true" + }, + "25": { + "name": "LED 4", + "exclusive": "true" + }, + } +} \ No newline at end of file diff --git a/overlay/pibrella.json b/overlay/pibrella.json new file mode 100644 index 0000000..0f784cc --- /dev/null +++ b/overlay/pibrella.json @@ -0,0 +1,63 @@ +{ + "name": "Pibrella", + "manufacturer": "Pimoroni", + "url": "https://github.com/pimoroni/pibrella", + "description": { + "short": "An all-in-one light, sound, input and output add-on board.", + "long": "pibrella.md" + }, + "pin": { + "7": { + "name": "Green LED", + "exclusive": "true" + }, + "11": { + "name": "Yellow LED", + "exclusive": "true" + }, + "13": { + "name": "Red LED", + "exclusive": "true" + }, + "15": { + "name": "Output A", + "exclusive": "true" + }, + "19": { + "name": "Input D", + "exclusive": "true" + }, + "21": { + "name": "Input A", + "exclusive": "true" + }, + "23": { + "name": "Button", + "exclusive": "true" + }, + "12": { + "name": "Buzzer", + "exclusive": "true" + }, + "16": { + "name": "Output B", + "exclusive": "true" + }, + "18": { + "name": "Output C", + "exclusive": "true" + }, + "22": { + "name": "Output D", + "exclusive": "true" + }, + "24": { + "name": "Input C", + "exclusive": "true" + }, + "26": { + "name": "Input B", + "exclusive": "true" + } + } +} \ No newline at end of file diff --git a/pi-pinout.json b/pi-pinout.json new file mode 100644 index 0000000..fdccfe8 --- /dev/null +++ b/pi-pinout.json @@ -0,0 +1,272 @@ +{ + "name": "Raspberry Pi GPIO Pinout", + "pins":{ + "1":{ + "name": "3v3 Power", + "type": "+3v3" + }, + "3":{ + "name": "SDA", + "type": "GPIO/I2C", + "scheme": { + "wiringpi": 8, + "bcm": 2, + "bcmAlt": 0 + } + }, + "5":{ + "name": "SCL", + "type": "GPIO/I2C", + "scheme": { + "wiringpi": 9, + "bcm": 3, + "bcmAlt": 1 + } + }, + "7":{ + "name": "GPCLK0", + "type": "GPIO", + "scheme": { + "wiringpi": 7, + "bcm": 4 + } + }, + "9":{ + "name": "Ground", + "type": "GND" + }, + "11":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 0, + "bcm": 17 + } + }, + "13":{ + "name": "PCM_D", + "type": "GPIO", + "scheme": { + "wiringpi": 2, + "bcm": 27, + "bcmAlt": 21 + } + }, + "15":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 3, + "bcm": 22 + } + }, + "17":{ + "name": "3v3 Power", + "type": "+3v3" + }, + "19":{ + "name": "MOSI", + "type": "GPIO/SPI", + "scheme": { + "wiringpi": 12, + "bcm": 10 + } + }, + "21":{ + "name": "MISO", + "type": "GPIO/SPI", + "scheme": { + "wiringpi": 13, + "bcm": 9 + } + }, + "23":{ + "name": "SCKL", + "type": "GPIO/SPI", + "scheme": { + "wiringpi": 14, + "bcm": 11 + } + }, + "25":{ + "name": "Ground", + "type": "GND" + }, + "27":{ + "name": "ID_SD", + "type": "GPIO/I2C" + }, + "29":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 0, + "bcm": 5 + } + }, + "31":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 0, + "bcm": 6 + } + }, + "33":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 0, + "bcm": 13 + } + }, + "35":{ + "name": "MISO", + "type": "GPIO/SPI", + "scheme": { + "wiringpi": 0, + "bcm": 19 + } + }, + "37":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 0, + "bcm": 26 + } + }, + "39":{ + "name": "Ground", + "type": "GND" + }, + "2":{ + "name": "5v Power", + "type": "+5v" + }, + "4":{ + "name": "5v Power", + "type": "+5v" + }, + "6":{ + "name": "Ground", + "type": "GND" + }, + "8":{ + "name": "TXD", + "type": "GPIO/UART", + "scheme": { + "wiringpi": 15, + "bcm": 14 + } + }, + "10":{ + "name": "RXD", + "type": "GPIO/UART", + "scheme": { + "wiringpi": 16, + "bcm": 15 + } + }, + "12":{ + "name": "PCM_C", + "type": "GPIO", + "scheme": { + "wiringpi": 1, + "bcm": 18 + } + }, + "14":{ + "name": "Ground", + "type": "GND" + }, + "16":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 4, + "bcm": 23 + } + }, + "18":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 5, + "bcm": 24 + } + }, + "20":{ + "name": "Ground", + "type": "GND" + }, + "22":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 6, + "bcm": 25 + } + }, + "24":{ + "name": "CE0", + "type": "GPIO/SPI", + "scheme": { + "wiringpi": 10, + "bcm": 8 + } + }, + "26":{ + "name": "CE1", + "type": "GPIO/SPI", + "scheme": { + "wiringpi": 11, + "bcm": 7 + } + }, + "28":{ + "name": "ID_SC", + "type": "GPIO" + }, + "30":{ + "name": "Ground", + "type": "GND" + }, + "32":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 0, + "bcm": 12 + } + }, + "34":{ + "name": "Ground", + "type": "GND" + }, + "36":{ + "name": "", + "type": "GPIO", + "scheme": { + "wiringpi": 0, + "bcm": 16 + } + }, + "38":{ + "name": "MOSI", + "type": "GPIO/SPI", + "scheme": { + "wiringpi": 0, + "bcm": 20 + } + }, + "40":{ + "name": "SCLK", + "type": "GPIO/SPI", + "scheme": { + "wiringpi": 0, + "bcm": 21 + } + } + } +} \ No newline at end of file