diff --git a/src/system/gpio.c b/src/system/gpio.c --- a/src/system/gpio.c +++ b/src/system/gpio.c @@ -3,50 +3,12 @@ // #include "stm32f3xx_hal.h" - #include "gpio.h" -#define CHANGE_PERIOD_MS 100 -#define CHANGE_ELAPSED (HAL_GetTick() - change_time_reset) > CHANGE_PERIOD_MS -#define CHANGE_RESET change_time_reset = HAL_GetTick() - -// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow... -static uint32_t change_time_reset = 0; - -// Increment/decrement unsigned variable with up/down buttons -void user_input(uint16_t* to_modify) -{ - if(CHANGE_ELAPSED) { - if(!HAL_GPIO_ReadPin(SW_UP) ) { - CHANGE_RESET; - (*to_modify)++; - } - else if(!HAL_GPIO_ReadPin(SW_DOWN) && (*to_modify) > 0) { - CHANGE_RESET; - (*to_modify)--; - } - } -} - - -// Increment/decrement signed variable with up/down buttons -void user_input_signed(int32_t* to_modify) -{ - //fixme: need to cast to 16/32 bits correctly - if(CHANGE_ELAPSED) { - if(!HAL_GPIO_ReadPin(SW_UP) ) { - CHANGE_RESET; - if (*to_modify < 32768) - (*to_modify)++; - } - else if(!HAL_GPIO_ReadPin(SW_DOWN)) { - CHANGE_RESET; - if (*to_modify >= -32768) - (*to_modify)--; - } - } -} +// Private variables +// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow... +static uint32_t change_time_reset = 0; // Initialize GPIOs @@ -90,3 +52,38 @@ void gpio_init(void) HAL_GPIO_WritePin(LED, 0); } + + +// Increment/decrement unsigned variable with up/down buttons +void user_input(uint16_t* to_modify) +{ + if(CHANGE_ELAPSED) { + if(!HAL_GPIO_ReadPin(SW_UP) ) { + CHANGE_RESET; + (*to_modify)++; + } + else if(!HAL_GPIO_ReadPin(SW_DOWN) && (*to_modify) > 0) { + CHANGE_RESET; + (*to_modify)--; + } + } +} + + +// Increment/decrement signed variable with up/down buttons +void user_input_signed(int32_t* to_modify) +{ + //fixme: need to cast to 16/32 bits correctly + if(CHANGE_ELAPSED) { + if(!HAL_GPIO_ReadPin(SW_UP) ) { + CHANGE_RESET; + if (*to_modify < 32768) + (*to_modify)++; + } + else if(!HAL_GPIO_ReadPin(SW_DOWN)) { + CHANGE_RESET; + if (*to_modify >= -32768) + (*to_modify)--; + } + } +}