[genpinmap] Use foreach for list iteration

Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
This commit is contained in:
Frederic.Pillon 2018-04-30 15:51:01 +02:00
parent 33205722ff
commit a944cb5f58

View file

@ -296,226 +296,185 @@ const PinMap PinMap_%s[] = {
return len(l) return len(l)
def print_adc(): def print_adc():
i = 0 # Check GPIO version (alternate or not)
if len(adclist)>0: s_pin_data = 'STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, '
# Check GPIO version (alternate or not) for p in adclist:
s_pin_data = 'STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' if "IN" in p[2]:
while i < len(adclist): s1 = "%-12s" % (" {" + p[0] + ',')
p=adclist[i] a = p[2].split('_')
if "IN" in p[2]: inst = a[0].replace("ADC", "")
s1 = "%-12s" % (" {" + p[0] + ',') if len(inst) == 0:
a = p[2].split('_') inst = '1' #single ADC for this product
inst = a[0].replace("ADC", "") s1 += "%-7s" % ('ADC' + inst + ',')
if len(inst) == 0: chan = re.sub('IN[N|P]?', '', a[1])
inst = '1' #single ADC for this product s1 += s_pin_data + chan
s1 += "%-7s" % ('ADC' + inst + ',') s1 += ', 0)}, // ' + p[2] + '\n'
chan = re.sub('IN[N|P]?', '', a[1]) out_file.write(s1)
s1 += s_pin_data + chan out_file.write( """ {NC, NP, 0}
s1 += ', 0)}, // ' + p[2] + '\n'
out_file.write(s1)
i += 1
out_file.write( """ {NC, NP, 0}
}; };
#endif #endif
""") """)
def print_dac(): def print_dac():
i = 0 for p in daclist:
if len(daclist)>0: b=p[2]
while i < len(daclist): s1 = "%-12s" % (" {" + p[0] + ',')
p=daclist[i] #2nd element is the DAC signal
b=p[2] if b[3] == '_': # 1 DAC in this chip
s1 = "%-12s" % (" {" + p[0] + ',') s1 += 'DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b[7] + ', 0)}, // ' + b + '\n'
#2nd element is the DAC signal else:
if b[3] == '_': # 1 DAC in this chip s1 += 'DAC' + b[3] + ', STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b[8] + ', 0)}, // ' + b + '\n'
s1 += 'DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b[7] + ', 0)}, // ' + b + '\n' out_file.write(s1)
else: out_file.write( """ {NC, NP, 0}
s1 += 'DAC' + b[3] + ', STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b[8] + ', 0)}, // ' + b + '\n'
out_file.write(s1)
i += 1
out_file.write( """ {NC, NP, 0}
}; };
#endif #endif
""") """)
def print_i2c(xml, l): def print_i2c(xml, l):
i = 0 for p in l:
if len(l)>0: result = get_gpio_af_num(xml, p[1], p[2])
while i < len(l): if result != 'NOTFOUND':
p=l[i] s1 = "%-12s" % (" {" + p[0] + ',')
result = get_gpio_af_num(xml, p[1], p[2]) #2nd element is the I2C XXX signal
if result != 'NOTFOUND': b = p[2].split('_')[0]
s1 = "%-12s" % (" {" + p[0] + ',') s1 += b[:len(b)-1] + b[len(b)-1] + ', STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, '
#2nd element is the I2C XXX signal r = result.split(' ')
b = p[2].split('_')[0] for af in r:
s1 += b[:len(b)-1] + b[len(b)-1] + ', STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, ' s2 = s1 + af + ')},\n'
r = result.split(' ') out_file.write(s2)
for af in r: out_file.write( """ {NC, NP, 0}
s2 = s1 + af + ')},\n'
out_file.write(s2)
i += 1
out_file.write( """ {NC, NP, 0}
}; };
#endif #endif
""") """)
def print_pwm(xml): def print_pwm(xml):
i=0 for p in pwm_list:
if len(pwm_list)>0: result = get_gpio_af_num(xml, p[1], p[2])
while i < len(pwm_list): if result != 'NOTFOUND':
p=pwm_list[i] s1 = "%-12s" % (" {" + p[0] + ',')
result = get_gpio_af_num(xml, p[1], p[2]) #2nd element is the PWM signal
if result != 'NOTFOUND': a = p[2].split('_')
s1 = "%-12s" % (" {" + p[0] + ',') inst = a[0]
#2nd element is the PWM signal if len(inst) == 3:
a = p[2].split('_') inst += '1'
inst = a[0] s1 += "%-8s" % (inst + ',')
if len(inst) == 3: chan = a[1].replace("CH", "")
inst += '1' if chan.endswith('N'):
s1 += "%-8s" % (inst + ',') neg = ', 1'
chan = a[1].replace("CH", "") chan = chan.strip('N')
if chan.endswith('N'): else:
neg = ', 1' neg = ', 0'
chan = chan.strip('N') s1 += 'STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, '
else: r = result.split(' ')
neg = ', 0' for af in r:
s1 += 'STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, ' s2 = s1 + af + ', ' + chan + neg + ')}, // ' + p[2] + '\n'
r = result.split(' ') out_file.write(s2)
for af in r: out_file.write( """ {NC, NP, 0}
s2 = s1 + af + ', ' + chan + neg + ')}, // ' + p[2] + '\n'
out_file.write(s2)
i += 1
out_file.write( """ {NC, NP, 0}
}; };
#endif #endif
""") """)
def print_uart(xml, l): def print_uart(xml, l):
i=0 for p in l:
if len(l)>0: result = get_gpio_af_num(xml, p[1], p[2])
while i < len(l): if result != 'NOTFOUND':
p=l[i] s1 = "%-12s" % (" {" + p[0] + ',')
result = get_gpio_af_num(xml, p[1], p[2]) #2nd element is the UART_XX signal
if result != 'NOTFOUND': b=p[2].split('_')[0]
s1 = "%-12s" % (" {" + p[0] + ',') s1 += "%-9s" % (b[:len(b)-1] + b[len(b)-1:] + ',')
#2nd element is the UART_XX signal if 'STM32F10' in mcu_file and l == uartrx_list:
b=p[2].split('_')[0] s1 += 'STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, '
s1 += "%-9s" % (b[:len(b)-1] + b[len(b)-1:] + ',') else:
if 'STM32F10' in mcu_file and l == uartrx_list: s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
s1 += 'STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, ' r = result.split(' ')
else: for af in r:
s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' s2 = s1 + af + ')},\n'
r = result.split(' ') out_file.write(s2)
for af in r:
s2 = s1 + af + ')},\n'
out_file.write(s2)
i += 1
out_file.write( """ {NC, NP, 0} out_file.write( """ {NC, NP, 0}
}; };
#endif #endif
""") """)
def print_spi(xml, l): def print_spi(xml, l):
i=0 for p in l:
if len(l)>0: result = get_gpio_af_num(xml, p[1], p[2])
while i < len(l): if result != 'NOTFOUND':
p=l[i] s1 = "%-12s" % (" {" + p[0] + ',')
result = get_gpio_af_num(xml, p[1], p[2]) #2nd element is the SPI_XXXX signal
if result != 'NOTFOUND': instance=p[2].split('_')[0].replace("SPI", "")
s1 = "%-12s" % (" {" + p[0] + ',') s1 += 'SPI' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
#2nd element is the SPI_XXXX signal r = result.split(' ')
instance=p[2].split('_')[0].replace("SPI", "") for af in r:
s1 += 'SPI' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' s2 = s1 + af + ')},\n'
r = result.split(' ') out_file.write(s2)
for af in r: out_file.write( """ {NC, NP, 0}
s2 = s1 + af + ')},\n'
out_file.write(s2)
i += 1
out_file.write( """ {NC, NP, 0}
}; };
#endif #endif
""") """)
def print_can(xml, l): def print_can(xml, l):
i=0 for p in l:
if len(l)>0: b=p[2]
while i < len(l): result = get_gpio_af_num(xml, p[1], p[2])
p=l[i] if result != 'NOTFOUND':
b=p[2] s1 = "%-12s" % (" {" + p[0] + ',')
result = get_gpio_af_num(xml, p[1], p[2]) #2nd element is the CAN_XX signal
if result != 'NOTFOUND': instance = p[2].split('_')[0].replace("CAN", "")
s1 = "%-12s" % (" {" + p[0] + ',') if len(instance) == 0:
#2nd element is the CAN_XX signal instance = '1'
instance = p[2].split('_')[0].replace("CAN", "") if 'STM32F10' in mcu_file and l == canrd_list:
if len(instance) == 0: s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, '
instance = '1' else:
if 'STM32F10' in mcu_file and l == canrd_list: s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, '
s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, ' r = result.split(' ')
else: for af in r:
s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, ' s2 = s1 + af + ')},\n'
r = result.split(' ') out_file.write(s2)
for af in r: out_file.write( """ {NC, NP, 0}
s2 = s1 + af + ')},\n'
out_file.write(s2)
i += 1
out_file.write( """ {NC, NP, 0}
}; };
#endif #endif
""") """)
def print_eth(xml, l): def print_eth(xml, l):
i=0 prev_s = ''
if len(l)>0: for p in l:
prev_s = '' result = get_gpio_af_num(xml, p[1], p[2])
while i < len(l): if result != 'NOTFOUND':
p=l[i] s1 = "%-12s" % (" {" + p[0] + ',')
result = get_gpio_af_num(xml, p[1], p[2]) #2nd element is the ETH_XXXX signal
if result != 'NOTFOUND': s1 += 'ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},'
s1 = "%-12s" % (" {" + p[0] + ',') #check duplicated lines, only signal differs
#2nd element is the ETH_XXXX signal if (prev_s == s1):
s1 += 'ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},' s1 = '|' + p[2]
#check duplicated lines, only signal differs else:
if (prev_s == s1): if len(prev_s)>0:
s1 = '|' + p[2] out_file.write('\n')
else: prev_s = s1
if len(prev_s)>0: s1 += ' // ' + p[2]
out_file.write('\n') out_file.write(s1)
prev_s = s1 out_file.write( """\n {NC, NP, 0}
s1 += ' // ' + p[2]
out_file.write(s1)
i += 1
out_file.write( """\n {NC, NP, 0}
}; };
#endif #endif
""") """)
def print_qspi(xml, l): def print_qspi(xml, l):
i=0 prev_s = ''
if len(l)>0: for p in l:
prev_s = '' result = get_gpio_af_num(xml, p[1], p[2])
while i < len(l): if result != 'NOTFOUND':
p=l[i] s1 = "%-12s" % (" {" + p[0] + ',')
result = get_gpio_af_num(xml, p[1], p[2]) #2nd element is the QUADSPI_XXXX signal
if result != 'NOTFOUND': s1 += 'QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},'
s1 = "%-12s" % (" {" + p[0] + ',') #check duplicated lines, only signal differs
#2nd element is the QUADSPI_XXXX signal if (prev_s == s1):
s1 += 'QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},' s1 = '|' + p[2]
#check duplicated lines, only signal differs else:
if (prev_s == s1): if len(prev_s)>0:
s1 = '|' + p[2] out_file.write('\n')
else: prev_s = s1
if len(prev_s)>0: s1 += ' // ' + p[2]
out_file.write('\n') out_file.write(s1)
prev_s = s1 out_file.write( """\n {NC, NP, 0}
s1 += ' // ' + p[2]
out_file.write(s1)
i += 1
out_file.write( """\n {NC, NP, 0}
}; };
#endif #endif
""") """)