8000 stm32/boards/make-pins.py: Allow a CPU pin to be hidden. · theidealist/micropython@a6907c7 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit a6907c7

Browse files
committed
stm32/boards/make-pins.py: Allow a CPU pin to be hidden.
This change allows a CPU pin to be hidden from the user by prefixing it with a "-" in the pins.csv file for a board. It will still be available in C code, just not exposed to Python. Signed-off-by: Damien George <damien@micropython.org>
1 parent e3eebc3 commit a6907c7

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

ports/stm32/boards/make-pins.py

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
#!/usr/bin/env python
2-
"""Creates the pin file for the STM32F4xx."""
2+
3+
"""
4+
Generates pin source files based on an MCU alternate-function definition (eg
5+
stm32f405_af.csv) and a board-specific pin definition file, pins.csv.
6+
7+
The pins.csv file must contain lines of the form:
8+
9+
board,cpu
10+
11+
Where "board" is the user-facing name of the pin as specified by the particular
12+
board layout and markings, and "cpu" is the corresponding name of the CPU/MCU
13+
pin.
14+
15+
The "board" entry may be absent if the CPU pin has no additional name, and both
16+
entries may start with "-" to hide them from the corresponding Python dict of
17+
pins, and hence hide them from the user (but they are still accessible in C).
18+
19+
For example, take the following pins.csv file:
20+
21+
X1,PA0
22+
-X2,PA1
23+
X3,-PA2
24+
-X4,-PA3
25+
,PA4
26+
,-PA5
27+
28+
The first row here configures:
29+
- The CPU pin PA0 is labelled X1.
30+
- The Python user can access both by the names Pin("X1") and Pin("A0").
31+
- The Python user can access both by the members Pin.board.X1 and Pin.cpu.A0.
32+
- In C code they are available as pyb_pin_X1 and pin_A0.
33+
34+
Prefixing the names with "-" hides them from the user. The following table
35+
summarises the various possibilities:
36+
37+
pins.csv entry | board name | cpu name | C board name | C cpu name
38+
---------------+------------+----------+--------------+-----------
39+
X1,PA0 "X1" "A0" pyb_pin_X1 pin_A0
40+
-X2,PA1 - "A1" pyb_pin_X2 pin_A1
41+
X3,-PA2 "X3" - pyb_pin_X3 pin_A2
42+
-X4,-PA3 - - pyb_pin_X4 pin_A3
43+
,PA4 - "A4" - pin_A4
44+
,-PA5 - - - pin_A5
45+
46+
"""
347

448
from __future__ import print_function
549

@@ -273,6 +317,9 @@ def __init__(self, name, pin):
273317
self._name = name
274318
self._pin = pin
275319

320+
def set_hidden(self, value):
321+
self._is_hidden = value
322+
276323
def is_hidden(self):
277324
return self._is_hidden
278325

@@ -293,7 +340,7 @@ def find_pin(self, port_num, pin_num):
293340
for named_pin in self.cpu_pins:
294341
pin = named_pin.pin()
295342
if pin.port == port_num and pin.pin == pin_num:
296-
return pin
343+
return named_pin
297344

298345
def parse_af_file(self, filename, pinname_col, af_col):
299346
with open(filename, "r") as csvfile:
@@ -315,12 +362,19 @@ def parse_board_file(self, filename):
315362
with open(filename, "r") as csvfile:
316363
rows = csv.reader(csvfile)
317364
for row in rows:
365+
cpu_pin_name = row[1]
366+
cpu_pin_hidden = False
367+
if cpu_pin_name.startswith("-"):
368+
cpu_pin_name = cpu_pin_name[1:]
369+
cpu_pin_hidden = True
318370
try:
319-
(port_num, pin_num) = parse_port_pin(row[1])
371+
(port_num, pin_num) = parse_port_pin(cpu_pin_name)
320372
except:
321373
continue
322-
pin = self.find_pin(port_num, pin_num)
323-
if pin:
374+
named_pin = self.find_pin(port_num, pin_num)
375+
if named_pin:
376+
named_pin.set_hidden(cpu_pin_hidden)
377+
pin = named_pin.pin()
324378
pin.set_is_board_pin()
325379
if row[0]: # Only add board pins that have a name
326380
self.board_pins.append(NamedPin(row[0], pin))

0 commit comments

Comments
 (0)
0