diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-09-04 11:38:27 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-09-04 11:38:27 +0200 |
commit | 545d7c7317df0358d8f9ca913fd139f5b6c08346 (patch) | |
tree | 553cd04e3075bd74abb5677ea8ed02a3de40d610 | |
parent | 65649efba6873c797ee66ef6c50900ab68f81da9 (diff) | |
download | glutte-o-matic-545d7c7317df0358d8f9ca913fd139f5b6c08346.tar.gz glutte-o-matic-545d7c7317df0358d8f9ca913fd139f5b6c08346.tar.bz2 glutte-o-matic-545d7c7317df0358d8f9ca913fd139f5b6c08346.zip |
Debounce SQ, D and U signals
-rw-r--r-- | src/glutt-o-logique/pio.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/glutt-o-logique/pio.c b/src/glutt-o-logique/pio.c index 7220b80..b3b372a 100644 --- a/src/glutt-o-logique/pio.c +++ b/src/glutt-o-logique/pio.c @@ -72,6 +72,15 @@ void read_fsm_input_task(void *pvParameters); struct fsm_input_signals_t pio_signals; + +/* Some signals need additional debouncing or delays, the following + * variables are shift registers. + */ +static uint8_t debounce_sq[3] = {0}; +static uint8_t debounce_discrim_d[3] = {0}; +static uint8_t debounce_discrim_u[3] = {0}; + + void pio_init() { GPIO_InitTypeDef GPIO_InitStructure; @@ -136,15 +145,37 @@ void read_fsm_input_task(void __attribute__ ((unused))*pvParameters) pio_signals.tone_1750 = GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_1750_n) ? 0 : 1; - pio_signals.sq = + debounce_sq[0] = debounce_sq[1]; + debounce_sq[1] = debounce_sq[2]; + debounce_sq[2] = GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_SQ_n) ? 0 : 1; - pio_signals.discrim_u = + /* Only change the signal if its input has stabilised */ + if (debounce_sq[0] == debounce_sq[1] && + debounce_sq[1] == debounce_sq[2]) { + pio_signals.sq = debounce_sq[0]; + } + + /* The discrim U and D signals should be very sensitive: + * if one toggles to 1, set to 1; reset to 0 only if all + * are at 0 + */ + debounce_discrim_u[0] = debounce_discrim_u[1]; + debounce_discrim_u[1] = debounce_discrim_u[2]; + debounce_discrim_u[2] = GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_U) ? 1 : 0; - pio_signals.discrim_d = + pio_signals.discrim_u = + debounce_discrim_u[0] | debounce_discrim_u[1] | debounce_discrim_u[2]; + + debounce_discrim_d[0] = debounce_discrim_d[1]; + debounce_discrim_d[1] = debounce_discrim_d[2]; + debounce_discrim_d[2] = GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_D) ? 1 : 0; + pio_signals.discrim_d = + debounce_discrim_d[0] | debounce_discrim_d[1] | debounce_discrim_d[2]; + pio_signals.wind_generator_ok = GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_REPLIE) ? 0 : 1; |