diff --git a/firmware/include/pentabug/hal.h b/firmware/include/pentabug/hal.h index 2c9342d..0f7b46f 100644 --- a/firmware/include/pentabug/hal.h +++ b/firmware/include/pentabug/hal.h @@ -51,6 +51,17 @@ void buzzer_inv(void); // turns buzzer off, buzzer_inv() won't create a sound wave after this call void buzzer_off(void); +// IR + +// all this functions control whether a 38kHz modulated IR signal is sent +void ir_on(void); +void ir_off(void); +void ir_inv(void); +void ir_set(uint8_t state); + +// returns 1 if a 38kHz modulated IR signal is received +uint8_t ir_recv(void); + // WAITING // waits the given amount of ms diff --git a/firmware/lib/hal.c b/firmware/lib/hal.c index 0315023..aadfc6e 100644 --- a/firmware/lib/hal.c +++ b/firmware/lib/hal.c @@ -99,7 +99,8 @@ void reset_hw(void) { PORTC = (1 << 2) | (1 << 3); DDRC = (1 << 0) | (1 << 2) | (1 << 3); - // 2: IR + // 2: IRSEND + // 3: IRRECV // 4: LED PORTD = (1 << 4); DDRD = (1 << 2) | (1 << 4); @@ -108,6 +109,10 @@ void reset_hw(void) { button_pressed[0] = 0; button_pressed[1] = 0; + + // turn ir off + + ir_off(); } uint8_t button_state(uint8_t btn) { @@ -220,3 +225,32 @@ void wait_ms(uint16_t ms) { } } +void ir_on(void) { + ir_active = 1; +} + +void ir_off(void) { + ir_active = 0; + PORTD &= ~(1 << 2); +} + +void ir_inv(void) { + if(ir_active) { + ir_off(); + } else { + ir_on(); + } +} + +void ir_set(uint8_t state) { + if(state) { + ir_on(); + } else { + ir_off(); + } +} + +uint8_t ir_recv(void) { + return !(PIND & (1 << 3)); +} +