diff options
Diffstat (limited to 'src/drv/ir/ir.c')
-rw-r--r-- | src/drv/ir/ir.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/drv/ir/ir.c b/src/drv/ir/ir.c index c84417d..9b7cd20 100644 --- a/src/drv/ir/ir.c +++ b/src/drv/ir/ir.c @@ -6,8 +6,8 @@ #include "arch/stm32l4xxx/peripherals/syscfg.h" #include "arch/stm32l4xxx/peripherals/tim.h" #include "kern/gpio/gpio_manager.h" -#include "kern/mem.h" #include "kern/log.h" +#include "kern/mem.h" #include "kern/panic.h" #include "shared/linked_list.h" @@ -27,7 +27,7 @@ void on_exti9_5() if (read_into.n == 0) { /* Starting fresh, start the timer. */ regset(TIM2.c_r1, tim_cen, 1); - read_into.ts[read_into.n ++] = 0; + read_into.ts[read_into.n++] = 0; } else { uint32_t ts = TIM2.cnt; if (read_into.n < 64) { @@ -36,21 +36,18 @@ void on_exti9_5() } } -typedef enum { - PARITY_LOW = 0, - PARITY_HIGH = 1 -} ir_parity_t; +typedef enum { PARITY_LOW = 0, PARITY_HIGH = 1 } ir_parity_t; static ir_parity_t ir_discover_parity(const ir_code_t* code) { uint32_t max_even = 0; - uint32_t min_even = (uint32_t) -1; + uint32_t min_even = (uint32_t)-1; uint32_t max_odd = 0; - uint32_t min_odd = (uint32_t) -1; + uint32_t min_odd = (uint32_t)-1; - for (int i = 3; i < code->n; ++ i) { - uint32_t n = code->ts[i] - code->ts[i-1]; + for (int i = 3; i < code->n; ++i) { + uint32_t n = code->ts[i] - code->ts[i - 1]; if (i % 2 == 0) { if (n < min_even) { min_even = n; @@ -73,20 +70,19 @@ static ir_parity_t ir_discover_parity(const ir_code_t* code) } } -int ir_generic_decode( - const ir_code_t* code, uint32_t* out_) +int ir_generic_decode(const ir_code_t* code, uint32_t* out_) { if (code->n < 5) { return 0; } - uint32_t min = (uint32_t) -1; + uint32_t min = (uint32_t)-1; uint32_t max = 0; uint32_t start = 4 + ir_discover_parity(code); for (int i = start; i < code->n; i += 2) { - uint32_t n = code->ts[i] - code->ts[i-1]; + uint32_t n = code->ts[i] - code->ts[i - 1]; if (n > max) { max = n; @@ -101,7 +97,7 @@ int ir_generic_decode( uint32_t mask = 0x80000000; for (int i = start; i < code->n; i += 2) { - if ((code->ts[i] - code->ts[i-1]) >= mid) { + if ((code->ts[i] - code->ts[i - 1]) >= mid) { out |= mask; } mask >>= 1; @@ -143,8 +139,8 @@ void ir_begin_listen() enable_interrupt(IRQ_EXTI9_5); /* Configure the timer. */ - TIM2.psc = 80; /* Counts every microsecond. */ - TIM2.ar_r = 50000; /* Stop after 50ms. */ + TIM2.psc = 80; /* Counts every microsecond. */ + TIM2.ar_r = 50000; /* Stop after 50ms. */ regset(TIM2.die_r, tim_uie, 1); /* Enable interrupts. */ regset(TIM2.c_r1, tim_opm, 1); /* Set one-pulse-mode. */ |