From d4dbeb6933537aa5acb0880734fd4f3eaf23cb6a Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 27 May 2021 13:25:06 +0200 Subject: [PATCH] Handle case where pin value could be 0 In the case where GPIO mapping could look like this: PA5: SPI1_SCK: 0 The pin would not get any generated impl because the if expression would evaluate to false. Fix this for all cases in gen.py by comparing against None ~ --- embassy-stm32/gen.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 97beadab..4343d775 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py @@ -108,15 +108,15 @@ for chip in chips.values(): f.write(f'impl_usart!({name});') for pin, funcs in af.items(): if pin in pins: - if func := funcs.get(f'{name}_RX'): + if (func := funcs.get(f'{name}_RX')) != None: f.write(f'impl_usart_pin!({name}, RxPin, {pin}, {func});') - if func := funcs.get(f'{name}_TX'): + if (func := funcs.get(f'{name}_TX')) != None: f.write(f'impl_usart_pin!({name}, TxPin, {pin}, {func});') - if func := funcs.get(f'{name}_CTS'): + if (func := funcs.get(f'{name}_CTS')) != None: f.write(f'impl_usart_pin!({name}, CtsPin, {pin}, {func});') - if func := funcs.get(f'{name}_RTS'): + if (func := funcs.get(f'{name}_RTS')) != None: f.write(f'impl_usart_pin!({name}, RtsPin, {pin}, {func});') - if func := funcs.get(f'{name}_CK'): + if (func := funcs.get(f'{name}_CK')) != None: f.write(f'impl_usart_pin!({name}, CkPin, {pin}, {func});') if block_mod == 'rng': @@ -130,11 +130,11 @@ for chip in chips.values(): f.write(f'impl_spi!({name}, {clock});') for pin, funcs in af.items(): if pin in pins: - if func := funcs.get(f'{name}_SCK'): + if (func := funcs.get(f'{name}_SCK')) != None: f.write(f'impl_spi_pin!({name}, SckPin, {pin}, {func});') - if func := funcs.get(f'{name}_MOSI'): + if (func := funcs.get(f'{name}_MOSI')) != None: f.write(f'impl_spi_pin!({name}, MosiPin, {pin}, {func});') - if func := funcs.get(f'{name}_MISO'): + if (func := funcs.get(f'{name}_MISO')) != None: f.write(f'impl_spi_pin!({name}, MisoPin, {pin}, {func});') if block_mod == 'i2c': @@ -174,25 +174,25 @@ for chip in chips.values(): f.write(f'impl_sdmmc!({name});') for pin, funcs in af.items(): if pin in pins: - if func := funcs.get(f'{name}_CK'): + if (func := funcs.get(f'{name}_CK')) != None: f.write(f'impl_sdmmc_pin!({name}, CkPin, {pin}, {func});') - if func := funcs.get(f'{name}_CMD'): + if (func := funcs.get(f'{name}_CMD')) != None: f.write(f'impl_sdmmc_pin!({name}, CmdPin, {pin}, {func});') - if func := funcs.get(f'{name}_D0'): + if (func := funcs.get(f'{name}_D0')) != None: f.write(f'impl_sdmmc_pin!({name}, D0Pin, {pin}, {func});') - if func := funcs.get(f'{name}_D1'): + if (func := funcs.get(f'{name}_D1')) != None: f.write(f'impl_sdmmc_pin!({name}, D1Pin, {pin}, {func});') - if func := funcs.get(f'{name}_D2'): + if (func := funcs.get(f'{name}_D2')) != None: f.write(f'impl_sdmmc_pin!({name}, D2Pin, {pin}, {func});') - if func := funcs.get(f'{name}_D3'): + if (func := funcs.get(f'{name}_D3')) != None: f.write(f'impl_sdmmc_pin!({name}, D3Pin, {pin}, {func});') - if func := funcs.get(f'{name}_D4'): + if (func := funcs.get(f'{name}_D4')) != None: f.write(f'impl_sdmmc_pin!({name}, D4Pin, {pin}, {func});') - if func := funcs.get(f'{name}_D5'): + if (func := funcs.get(f'{name}_D5')) != None: f.write(f'impl_sdmmc_pin!({name}, D5Pin, {pin}, {func});') - if func := funcs.get(f'{name}_D6'): + if (func := funcs.get(f'{name}_D6')) != None: f.write(f'impl_sdmmc_pin!({name}, D6Pin, {pin}, {func});') - if func := funcs.get(f'{name}_D7'): + if (func := funcs.get(f'{name}_D7')) != None: f.write(f'impl_sdmmc_pin!({name}, D7Pin, {pin}, {func});') if block_name == 'TimGp16':