#!/usr/bin/python # This file is part of Espruino, a JavaScript interpreter for Microcontrollers # # Copyright (C) 2013 Gordon Williams # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # ---------------------------------------------------------------------------------------- # Builds HTML documentation from the files in the boards directory # ---------------------------------------------------------------------------------------- import subprocess; import re; import json; import sys; import os; import importlib; scriptdir = os.path.dirname(os.path.realpath(__file__)) basedir = scriptdir+"/../" sys.path.append(basedir+"scripts"); sys.path.append(basedir+"boards"); import pinutils; # ----------------------------------------------------------------------------------------- # Now scan AF file print "Script location "+scriptdir #if len(sys.argv)!=3: # print "ERROR, USAGE: build_board_docs.py BOARD_NAME HTML_FILENAME" # exit(1) if len(sys.argv)!=2: print "ERROR, USAGE: build_board_docs.py BOARD_NAME" exit(1) boardname = sys.argv[1] #htmlFilename = sys.argv[2] htmlFilename = "boards/"+boardname+".html" print "HTML_FILENAME "+htmlFilename print "BOARD "+boardname # import the board def board = importlib.import_module(boardname) # Call the included board_specific file - it sets up 'pins' and 'fill_gaps' pins = board.get_pins() pins = pinutils.append_devices_to_pin_list(pins, board) # ----------------------------------------------------------------------------------------- for pin in pins: if pin["name"][0] == 'P': pin["name"] = pin["name"][1:]; pinmap = {}; if '_pinmap' in board.board: pinmap = board.board['_pinmap']; # ----------------------------------------------------------------------------------------- htmlFile = open(htmlFilename, 'w') def writeHTML(s): htmlFile.write(s+"\n"); def dump_pin(pin, pinstrip): if pin in pinmap: pin = pinmap[pin]; pininfo = pinutils.findpin(pins, pin, False) not_five_volt = False # print(json.dumps(pininfo)) if ("csv" in pininfo) and ("IO" in pininfo["csv"]) and ("Type" in pininfo["csv"]) and (pininfo["csv"]["Type"]=="I/O") and (pininfo["csv"]["IO"]!="FT") : not_five_volt = True writeHTML('
'); pinHTML = ' '+pin+"."; pinHTML2 = ''; if not_five_volt: pinHTML2 += '3.3v'; reverse = pinstrip=="left" or pinstrip=="right2"; if not reverse: writeHTML(pinHTML+"\n"+pinHTML2) pinfuncs = {} for func in sorted(pininfo["functions"]): # writeHTML(' '+func) if func in pinutils.CLASSES: funcdata = str(pininfo["functions"][func]) cls = pinutils.CLASSES[func] name = cls title = func if cls=="I2C" or cls=="SPI" or cls=="USART": name=func.replace("_"," ") if cls=="DEVICE" and funcdata[:4]=="pin_": title = title + " ("+funcdata[4:]+")"; # print title if func in pinutils.NAMES: name = pinutils.NAMES[func] writeHTML('') if name in pinfuncs: pinfuncs[name]["title"] = pinfuncs[name]["title"] + " " + title else: pinfuncs[name] = { 'cls': cls, 'title': "["+pin+"] "+title, 'name': name, 'id': pin+"_"+func }; for func in sorted(pinfuncs.items(),key=lambda x: x[1]['cls']): pf = func[1] writeHTML(' '+pf["name"]+'') writeHTML(' ') if reverse: writeHTML(pinHTML2+"\n"+pinHTML) writeHTML('
') writeHTML(""" "+'') writeHTML(""" """) writeHTML(" ") writeHTML(" ") writeHTML('

'+board.info["name"]+'

') writeHTML(' ') if "link" in board.info: for link in board.info["link"]: writeHTML('

'+link+'

') writeHTML('

Specifications

') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML(' ') writeHTML('
Chip'+board.chip['part']+'
Package'+board.chip['package']+'
RAM'+str(board.chip['ram'])+' kBytes
Flash'+str(board.chip['flash'])+' kBytes
Speed'+str(board.chip['speed'])+' Mhz
USARTs'+str(board.chip['usart'])+'
SPIs'+str(board.chip['spi'])+'
I2Cs'+str(board.chip['i2c'])+'
USB'+("Yes" if "USB" in board.devices else "No")+'
DACs'+(str(board.chip['dac']) if board.chip['dac']>0 else "No")+'
SD Card'+("Yes" if "SD" in board.devices else "No")+'
') writeHTML('

Like this? Please tell your friends, blog, or support us by buying our board!

') writeHTML('

Pinout

') writeHTML('

Hover the mouse over a pin function for more information

') writeHTML('
') writeHTML('
') usedpins = [] for pinstrip in board.board: if pinstrip[0]!='_': writeHTML('
') for pin in board.board[pinstrip]: usedpins.append(pin) dump_pin(pin, pinstrip) writeHTML('
') otherpins=0 for pinstruct in pins: pin = pinstruct["name"] if not pin in usedpins: otherpins = otherpins + 1 writeHTML('
') writeHTML('
') if otherpins>0: writeHTML('
') writeHTML('

Pins not on connectors

') for pinstruct in pins: pin = pinstruct["name"] if not pin in usedpins: dump_pin(pin, "otherpins") writeHTML('
') writeHTML('

') writeHTML(''); writeHTML(" ") writeHTML("")