stm32f4xx_exti: teach exti abotu new gpio handle format
am: dc6027baa1
* commit 'dc6027baa1521dbc4070164231abbfcfd6b247ce':
stm32f4xx_exti: teach exti abotu new gpio handle format
diff --git a/firmware/inc/platform/stm32f4xx/exti.h b/firmware/inc/platform/stm32f4xx/exti.h
index cbf2309..d403cc7 100644
--- a/firmware/inc/platform/stm32f4xx/exti.h
+++ b/firmware/inc/platform/stm32f4xx/exti.h
@@ -69,23 +69,32 @@
static inline void extiEnableIntGpio(const struct Gpio *__restrict gpioHandle, enum ExtiTrigger trigger)
{
- uint32_t gpioNum = (uint32_t)gpioHandle;
- extiEnableIntLine(gpioNum & GPIO_PIN_MASK, trigger);
+ if (gpioHandle) {
+ uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
+ extiEnableIntLine(gpioNum & GPIO_PIN_MASK, trigger);
+ }
}
static inline void extiDisableIntGpio(const struct Gpio *__restrict gpioHandle)
{
- uint32_t gpioNum = (uint32_t)gpioHandle;
- extiDisableIntLine(gpioNum & GPIO_PIN_MASK);
+ if (gpioHandle) {
+ uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
+ extiDisableIntLine(gpioNum & GPIO_PIN_MASK);
+ }
}
static inline bool extiIsPendingGpio(const struct Gpio *__restrict gpioHandle)
{
- uint32_t gpioNum = (uint32_t)gpioHandle;
- return extiIsPendingLine(gpioNum & GPIO_PIN_MASK);
+ if (gpioHandle) {
+ uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
+ return extiIsPendingLine(gpioNum & GPIO_PIN_MASK);
+ }
+ return false;
}
static inline void extiClearPendingGpio(const struct Gpio *__restrict gpioHandle)
{
- uint32_t gpioNum = (uint32_t)gpioHandle;
- extiClearPendingLine(gpioNum & GPIO_PIN_MASK);
+ if (gpioHandle) {
+ uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
+ extiClearPendingLine(gpioNum & GPIO_PIN_MASK);
+ }
}
#ifdef __cplusplus
diff --git a/firmware/inc/platform/stm32f4xx/gpio.h b/firmware/inc/platform/stm32f4xx/gpio.h
index 4fbef47..a45110f 100644
--- a/firmware/inc/platform/stm32f4xx/gpio.h
+++ b/firmware/inc/platform/stm32f4xx/gpio.h
@@ -23,6 +23,9 @@
#include <stdint.h>
+#define GPIO_HANDLE_OFFSET 1 /* to make sure that 0 stays an invalid number */
+
+
#define GPIO_PORTA 0
#define GPIO_PORTB 1
#define GPIO_PORTC 2
diff --git a/firmware/src/platform/stm32f4xx/gpio.c b/firmware/src/platform/stm32f4xx/gpio.c
index 2ba381e..1c4b590 100644
--- a/firmware/src/platform/stm32f4xx/gpio.c
+++ b/firmware/src/platform/stm32f4xx/gpio.c
@@ -19,8 +19,6 @@
#include <gpio.h>
#include <cpu.h>
-#define GPIO_HANDLE_OFFSET 1 /* to make sure that 0 stays an invalid number */
-
struct StmGpio {
volatile uint32_t MODER;
volatile uint32_t OTYPER;
diff --git a/firmware/src/platform/stm32f4xx/syscfg.c b/firmware/src/platform/stm32f4xx/syscfg.c
index 88c938b..27aa132 100644
--- a/firmware/src/platform/stm32f4xx/syscfg.c
+++ b/firmware/src/platform/stm32f4xx/syscfg.c
@@ -29,16 +29,18 @@
void syscfgSetExtiPort(const struct Gpio *__restrict gpioHandle)
{
- uint32_t gpioNum = (uint32_t)gpioHandle;
- struct StmSyscfg *block = (struct StmSyscfg *)SYSCFG_BASE;
- const uint32_t bankNo = gpioNum >> GPIO_PORT_SHIFT;
- const uint32_t pinNo = gpioNum & GPIO_PIN_MASK;
- const uint32_t regNo = pinNo >> SYSCFG_REG_SHIFT;
- const uint32_t nibbleNo = pinNo & ((1UL << SYSCFG_REG_SHIFT) - 1UL);
- const uint32_t shift_4b = nibbleNo << 2UL;
- const uint32_t mask_4b = 0x0FUL << shift_4b;
+ if (gpioHandle) {
+ uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
+ struct StmSyscfg *block = (struct StmSyscfg *)SYSCFG_BASE;
+ const uint32_t bankNo = gpioNum >> GPIO_PORT_SHIFT;
+ const uint32_t pinNo = gpioNum & GPIO_PIN_MASK;
+ const uint32_t regNo = pinNo >> SYSCFG_REG_SHIFT;
+ const uint32_t nibbleNo = pinNo & ((1UL << SYSCFG_REG_SHIFT) - 1UL);
+ const uint32_t shift_4b = nibbleNo << 2UL;
+ const uint32_t mask_4b = 0x0FUL << shift_4b;
- pwrUnitClock(PERIPH_BUS_APB2, PERIPH_APB2_SYSCFG, true);
+ pwrUnitClock(PERIPH_BUS_APB2, PERIPH_APB2_SYSCFG, true);
- block->EXTICR[regNo] = (block->EXTICR[regNo] & ~mask_4b) | (bankNo << shift_4b);
+ block->EXTICR[regNo] = (block->EXTICR[regNo] & ~mask_4b) | (bankNo << shift_4b);
+ }
}