diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-10-15 18:02:21 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-10-23 21:16:35 -0400 |
commit | c2881f7d150f46590d489665e53f38ee8b032877 (patch) | |
tree | 551eda58ccfa8c8d77d85086729bd835e78c0f64 /src/stm32/gpio.c | |
parent | f160a3a824811967bf64376e5afa7261f6a9bd91 (diff) | |
download | kutter-c2881f7d150f46590d489665e53f38ee8b032877.tar.gz kutter-c2881f7d150f46590d489665e53f38ee8b032877.tar.xz kutter-c2881f7d150f46590d489665e53f38ee8b032877.zip |
stm32: Be explicit in layout of gpio banks in digital_regs variable
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stm32/gpio.c')
-rw-r--r-- | src/stm32/gpio.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/stm32/gpio.c b/src/stm32/gpio.c index cadb3396..de56e168 100644 --- a/src/stm32/gpio.c +++ b/src/stm32/gpio.c @@ -26,12 +26,12 @@ DECL_ENUMERATION_RANGE("pin", "PI0", GPIO('I', 0), 16); #endif GPIO_TypeDef * const digital_regs[] = { - GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, + ['A' - 'A'] = GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, #ifdef GPIOH - GPIOF, GPIOG, GPIOH, + ['F' - 'A'] = GPIOF, GPIOG, GPIOH, #endif #ifdef GPIOI - GPIOI, + ['I' - 'A'] = GPIOI, #endif }; @@ -52,6 +52,8 @@ gpio_out_setup(uint32_t pin, uint32_t val) if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs)) goto fail; GPIO_TypeDef *regs = digital_regs[GPIO2PORT(pin)]; + if (! regs) + goto fail; gpio_clock_enable(regs); struct gpio_out g = { .regs=regs, .bit=GPIO2BIT(pin) }; gpio_out_reset(g, val); @@ -106,6 +108,8 @@ gpio_in_setup(uint32_t pin, int32_t pull_up) if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs)) goto fail; GPIO_TypeDef *regs = digital_regs[GPIO2PORT(pin)]; + if (! regs) + goto fail; struct gpio_in g = { .regs=regs, .bit=GPIO2BIT(pin) }; gpio_in_reset(g, pull_up); return g; |