From 468fe59d9747078830dd489668b8c8ee8520b4a5 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 22 Dec 2018 14:38:07 +0900 Subject: First AC/mux test working --- fw/main.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'fw/main.c') diff --git a/fw/main.c b/fw/main.c index b599cff..e00f3a6 100644 --- a/fw/main.c +++ b/fw/main.c @@ -38,8 +38,8 @@ int main(void) { RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; GPIOA->MODER |= - (3<ODR &= ~(!a<<3 | !b<<7 | c<<6 | d<<4); GPIOA->ODR |= a<<3 | b<<7 | !c<<6 | !d<<4; } + set_outputs(0); + + uint8_t out_state = 0x01; +#define DEBOUNCE 100 + int debounce_ctr = 0; + int val_last = 0; + int ctr = 0; +#define RESET 1000 + int reset_ctr = 0; while (42) { #define FOO 500000 + if (reset_ctr) + reset_ctr--; + else + set_outputs(0); + + if (debounce_ctr) { + debounce_ctr--; + } else { + int val = !!(GPIOA->IDR & 1); + debounce_ctr = DEBOUNCE; + + if (val != val_last) { + if (val) + set_outputs(out_state & 0xf); + else + set_outputs(out_state >> 4); + reset_ctr = RESET; + val_last = val; + ctr++; + + if (ctr == 100) { + ctr = 0; + out_state = out_state<<1 | out_state>>7; + } + } + } + /* for (int i=0; iODR ^= 4; } } -- cgit