Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49d7105

Browse files
committed
[genpinmap] Manage atlernative pins (_ALTx)
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 202d869 commit 49d7105

File tree

1 file changed

+92
-15
lines changed

1 file changed

+92
-15
lines changed

src/genpinmap/genpinmap_arduino.py

+92-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
mcu_file = ""
1313
mcu_list = [] # 'name'
1414
io_list = [] # 'PIN','name'
15+
alt_list = [] # 'PIN','name'
1516
adclist = [] # 'PIN','name','ADCSignal'
1617
daclist = [] # 'PIN','name','DACSignal'
1718
i2cscl_list = [] # 'PIN','name','I2CSCLSignal'
@@ -167,13 +168,13 @@ def isPinAndSignalInList(pin, signal, lst):
167168
return len([item for item in lst if item[0] == pin and item[2] == signal])
168169

169170

170-
def store_pin(pin, name):
171-
if pin in [p[0] for p in io_list]:
171+
def store_pin(pin, name, dest_list):
172+
if pin in [p[0] for p in dest_list]:
172173
return
173174
# store pin I/O
174175
p = [pin, name]
175-
if p not in io_list:
176-
io_list.append(p)
176+
if p not in dest_list:
177+
dest_list.append(p)
177178

178179

179180
# function to store ADC list
@@ -349,8 +350,14 @@ def print_header():
349350
#include "%s.h"
350351
351352
/* =====
352-
* Note: Commented lines are alternative possibilities which are not used per default.
353-
* If you change them, you will have to know what you do
353+
* Notes:
354+
* - The pins mentioned Px_y_ALTz are alternative possibilities which use other
355+
* HW peripheral instances. You can use them the same way as any other "normal"
356+
* pin (i.e. analogWrite(PA7_ALT0, 128);). These pins are not available thanks
357+
* pin number (Dx or x).
358+
*
359+
* - Commented lines are alternative possibilities which are not used per default.
360+
* If you change them, you will have to know what you do
354361
* =====
355362
*/
356363
""" % (
@@ -444,6 +451,7 @@ def print_all_lists():
444451
if print_list_header("SD", "SD", "SD", sd_list):
445452
print_sd()
446453
# Print specific PinNames in header file
454+
print_alt_h()
447455
print_syswkup_h()
448456
print_usb_h()
449457

@@ -500,9 +508,19 @@ def print_adc():
500508
s_pin_data += "_ADC_CONTROL"
501509
s_pin_data += ", GPIO_NOPULL, 0, "
502510

511+
prev_p = ""
512+
alt_index = 0
513+
503514
for p in adclist:
504515
if "IN" in p[2]:
505-
s1 = "%-10s" % (" {" + p[0] + ",")
516+
if p[0] == prev_p:
517+
p[0] += "_ALT%d" % alt_index
518+
alt_index += 1
519+
store_pin(p[0], p[1], alt_list)
520+
else:
521+
prev_p = p[0]
522+
alt_index = 0
523+
s1 = "%-15s" % (" {" + p[0] + ",")
506524
a = p[2].split("_")
507525
inst = a[0].replace("ADC", "")
508526
if len(inst) == 0:
@@ -553,9 +571,18 @@ def print_dac():
553571

554572

555573
def print_i2c(lst):
574+
prev_p = ""
575+
alt_index = 0
556576
for p in lst:
557577
result = get_gpio_af_num(p[1], p[2])
558-
s1 = "%-10s" % (" {" + p[0] + ",")
578+
if p[0] == prev_p:
579+
p[0] += "_ALT%d" % alt_index
580+
store_pin(p[0], p[1], alt_list)
581+
alt_index += 1
582+
else:
583+
prev_p = p[0]
584+
alt_index = 0
585+
s1 = "%-15s" % (" {" + p[0] + ",")
559586
# 2nd element is the I2C XXX signal
560587
b = p[2].split("_")[0]
561588
s1 += (
@@ -576,9 +603,18 @@ def print_i2c(lst):
576603

577604

578605
def print_pwm():
606+
prev_p = ""
607+
alt_index = 0
579608
for p in pwm_list:
580609
result = get_gpio_af_num(p[1], p[2])
581-
s1 = "%-10s" % (" {" + p[0] + ",")
610+
if p[0] == prev_p:
611+
p[0] += "_ALT%d" % alt_index
612+
store_pin(p[0], p[1], alt_list)
613+
alt_index += 1
614+
else:
615+
prev_p = p[0]
616+
alt_index = 0
617+
s1 = "%-15s" % (" {" + p[0] + ",")
582618
# 2nd element is the PWM signal
583619
a = p[2].split("_")
584620
inst = a[0]
@@ -605,9 +641,18 @@ def print_pwm():
605641

606642

607643
def print_uart(lst):
644+
prev_p = ""
645+
alt_index = 0
608646
for p in lst:
609647
result = get_gpio_af_num(p[1], p[2])
610-
s1 = "%-10s" % (" {" + p[0] + ",")
648+
if p[0] == prev_p:
649+
p[0] += "_ALT%d" % alt_index
650+
store_pin(p[0], p[1], alt_list)
651+
alt_index += 1
652+
else:
653+
prev_p = p[0]
654+
alt_index = 0
655+
s1 = "%-15s" % (" {" + p[0] + ",")
611656
# 2nd element is the UART_XX signal
612657
b = p[2].split("_")[0]
613658
s1 += "%-9s" % (b[: len(b) - 1] + b[len(b) - 1 :] + ",")
@@ -628,9 +673,18 @@ def print_uart(lst):
628673

629674

630675
def print_spi(lst):
676+
prev_p = ""
677+
alt_index = 0
631678
for p in lst:
632679
result = get_gpio_af_num(p[1], p[2])
633-
s1 = "%-10s" % (" {" + p[0] + ",")
680+
if p[0] == prev_p:
681+
p[0] += "_ALT%d" % alt_index
682+
store_pin(p[0], p[1], alt_list)
683+
alt_index += 1
684+
else:
685+
prev_p = p[0]
686+
alt_index = 0
687+
s1 = "%-15s" % (" {" + p[0] + ",")
634688
# 2nd element is the SPI_XXXX signal
635689
instance = p[2].split("_")[0].replace("SPI", "")
636690
s1 += "SPI" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
@@ -804,6 +858,23 @@ def print_usb(lst):
804858
)
805859

806860

861+
def print_alt_h():
862+
if len(alt_list) == 0:
863+
out_h_file.write("/* No alternate */\n")
864+
else:
865+
out_h_file.write("/* Alternate pin name */\n")
866+
# print pin name under switch
867+
for p in alt_list:
868+
if "_ALT" in p[0]:
869+
s1 = " %-10s = %-5s | %s,\n" % (
870+
p[0],
871+
p[0].split("_A")[0],
872+
p[0].split("_")[2],
873+
)
874+
out_h_file.write(s1)
875+
out_h_file.write("\n")
876+
877+
807878
def print_syswkup_h():
808879
if len(syswkup_list) == 0:
809880
out_h_file.write("/* NO SYS_WKUP */\n")
@@ -863,6 +934,8 @@ def natural_sortkey2(list_2_elem):
863934

864935

865936
def sort_my_lists():
937+
io_list.sort(key=natural_sortkey)
938+
alt_list.sort(key=natural_sortkey)
866939
adclist.sort(key=natural_sortkey)
867940
daclist.sort(key=natural_sortkey)
868941
i2cscl_list.sort(key=natural_sortkey)
@@ -895,6 +968,7 @@ def sort_my_lists():
895968

896969
def clean_all_lists():
897970
del io_list[:]
971+
del alt_list[:]
898972
del adclist[:]
899973
del daclist[:]
900974
del i2cscl_list[:]
@@ -939,7 +1013,7 @@ def parse_pins():
9391013
pin = m.group(0)[:3] + "_" + m.group(0)[3:]
9401014
name = s.attributes["Name"].value.strip() # full name: "PF0 / OSC_IN"
9411015
if s.attributes["Type"].value in ["I/O", "MonoIO"]:
942-
store_pin(pin, name)
1016+
store_pin(pin, name, io_list)
9431017
else:
9441018
continue
9451019
siglist = s.getElementsByTagName("Signal")
@@ -1110,12 +1184,15 @@ def parse_pins():
11101184
print_header()
11111185
print_all_lists()
11121186

1113-
nb_pin = len(io_list)
1114-
print(" * I/O pins found: %i" % nb_pin)
1187+
print(
1188+
" * Total I/O pins found: {} ({} + {} ALT I/O pins)\n".format(
1189+
(len(io_list) + len(alt_list)), len(io_list), len(alt_list)
1190+
)
1191+
)
11151192
# io_list.sort(key=natural_sortkey)
11161193
# for io in io_list:
11171194
# print(io[0] + ", " + io[1])
1118-
print("done\n")
1195+
11191196
clean_all_lists()
11201197

11211198
out_c_file.close()

0 commit comments

Comments
 (0)