summaryrefslogtreecommitdiffstatshomepage
path: root/teensy/make-pins.py
diff options
context:
space:
mode:
authorDave Hylands <dhylands@gmail.com>2014-07-22 07:57:36 -0700
committerDave Hylands <dhylands@gmail.com>2014-08-07 23:15:41 -0700
commit6f418fc1b068c1a41113bb2b019a5803765e1deb (patch)
tree79477835459eb424012f58d77a150bdf9a80eed5 /teensy/make-pins.py
parent3ef911345c94a6d612ab50c1e912e81cb2cc3f71 (diff)
downloadmicropython-6f418fc1b068c1a41113bb2b019a5803765e1deb.tar.gz
micropython-6f418fc1b068c1a41113bb2b019a5803765e1deb.zip
Add support for selecting pin alternate functions from python.
Converts generted pins to use qstrs instead of string pointers. This patch also adds the following functions: pyb.Pin.names() pyb.Pin.af_list() pyb.Pin.gpio() dir(pyb.Pin.board) and dir(pyb.Pin.cpu) also produce useful results. pyb.Pin now takes kw args. pyb.Pin.__str__ now prints more useful information about the pin configuration. I found the following functions in my boot.py to be useful: ```python def pins(): for pin_name in dir(pyb.Pin.board): pin = pyb.Pin(pin_name) print('{:10s} {:s}'.format(pin_name, str(pin))) def af(): for pin_name in dir(pyb.Pin.board): pin = pyb.Pin(pin_name) print('{:10s} {:s}'.format(pin_name, str(pin.af_list()))) ```
Diffstat (limited to 'teensy/make-pins.py')
-rwxr-xr-xteensy/make-pins.py67
1 files changed, 64 insertions, 3 deletions
diff --git a/teensy/make-pins.py b/teensy/make-pins.py
index 1fd05ec207..6df1e4162b 100755
--- a/teensy/make-pins.py
+++ b/teensy/make-pins.py
@@ -71,6 +71,9 @@ class AlternateFunction(object):
return self.func
return '{:s}{:d}'.format(self.func, self.fn_num)
+ def mux_name(self):
+ return 'AF{:d}_{:s}'.format(self.idx, self.ptr())
+
def print(self):
"""Prints the C representation of this AF."""
if self.supported:
@@ -83,6 +86,9 @@ class AlternateFunction(object):
print('({:2d}, {:8s}, {:2d}, {:10s}, {:8s}), // {:s}'.format(self.idx,
self.func, fn_num, self.pin_type, self.ptr(), self.af_str))
+ def qstr_list(self):
+ return [self.mux_name()]
+
class Pin(object):
"""Holds the information associated with a pin."""
@@ -169,6 +175,14 @@ class Pin(object):
hdr_file.write('extern const pin_af_obj_t pin_{:s}_af[];\n'.
format(self.cpu_pin_name()))
+ def qstr_list(self):
+ result = []
+ for alt_fn in self.alt_fn:
+ if alt_fn.is_supported():
+ result += alt_fn.qstr_list()
+ return result
+
+
class NamedPin(object):
def __init__(self, name, pin):
@@ -222,13 +236,13 @@ class Pins(object):
self.board_pins.append(NamedPin(row[0], pin))
def print_named(self, label, named_pins):
- print('const pin_named_pin_t pin_{:s}_pins[] = {{'.format(label))
+ print('STATIC const mp_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{'.format(label))
for named_pin in named_pins:
pin = named_pin.pin()
if pin.is_board_pin():
- print(' {{ "{:s}", &pin_{:s} }},'.format(named_pin.name(), pin.cpu_pin_name()))
- print(' { NULL, NULL }')
+ print(' {{ MP_OBJ_NEW_QSTR(MP_QSTR_{:s}), (mp_obj_t)&pin_{:s} }},'.format(named_pin.name(), pin.cpu_pin_name()))
print('};')
+ print('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);'.format(label, label));
def print(self):
for named_pin in self.cpu_pins:
@@ -266,6 +280,39 @@ class Pins(object):
hdr_file.write('extern const pin_obj_t * const pin_adc2[];\n')
hdr_file.write('extern const pin_obj_t * const pin_adc3[];\n')
+ def print_qstr(self, qstr_filename):
+ with open(qstr_filename, 'wt') as qstr_file:
+ qstr_set = set([])
+ for named_pin in self.cpu_pins:
+ pin = named_pin.pin()
+ if pin.is_board_pin():
+ qstr_set |= set(pin.qstr_list())
+ qstr_set |= set([named_pin.name()])
+ for named_pin in self.board_pins:
+ qstr_set |= set([named_pin.name()])
+ for qstr in sorted(qstr_set):
+ print('Q({})'.format(qstr), file=qstr_file)
+
+
+ def print_af_hdr(self, af_const_filename):
+ with open(af_const_filename, 'wt') as af_const_file:
+ af_hdr_set = set([])
+ mux_name_width = 0
+ for named_pin in self.cpu_pins:
+ pin = named_pin.pin()
+ if pin.is_board_pin():
+ for af in pin.alt_fn:
+ if af.is_supported():
+ mux_name = af.mux_name()
+ af_hdr_set |= set([mux_name])
+ if len(mux_name) > mux_name_width:
+ mux_name_width = len(mux_name)
+ for mux_name in sorted(af_hdr_set):
+ key = 'MP_OBJ_NEW_QSTR(MP_QSTR_{}),'.format(mux_name)
+ val = 'MP_OBJ_NEW_SMALL_INT(GPIO_{})'.format(mux_name)
+ print(' { %-*s %s },' % (mux_name_width + 26, key, val),
+ file=af_const_file)
+
def main():
parser = argparse.ArgumentParser(
@@ -280,6 +327,12 @@ def main():
default="stm32f4xx-af.csv"
)
parser.add_argument(
+ "--af-const",
+ dest="af_const_filename",
+ help="Specifies header file for alternate function constants.",
+ default="build/pins-af-const.h"
+ )
+ parser.add_argument(
"-b", "--board",
dest="board_filename",
help="Specifies the board file",
@@ -291,6 +344,12 @@ def main():
default="stm32f4xx-prefix.c"
)
parser.add_argument(
+ "-q", "--qstr",
+ dest="qstr_filename",
+ help="Specifies name of generated qstr header file",
+ default="build/pins-qstr.h"
+ )
+ parser.add_argument(
"-r", "--hdr",
dest="hdr_filename",
help="Specifies name of generated pin header file",
@@ -320,6 +379,8 @@ def main():
pins.print_adc(2)
pins.print_adc(3)
pins.print_header(args.hdr_filename)
+ pins.print_qstr(args.qstr_filename)
+ pins.print_af_hdr(args.af_const_filename)
if __name__ == "__main__":