diff --git a/firmware/include/pentabug/hal.h b/firmware/include/pentabug/hal.h index 5806387..919591c 100644 --- a/firmware/include/pentabug/hal.h +++ b/firmware/include/pentabug/hal.h @@ -6,6 +6,9 @@ #define LEFT 0 #define RIGHT 1 +#define OFF 0 +#define ON 1 + // INITIALIZATION // initializes the hardware (timers, ...) @@ -18,6 +21,7 @@ void reset_hw(void); // BUTTONS // returns 1 if the button is currently pressed, 0 otherwise +// WARNING: you should really use button_clicked() instead uint8_t button_state(uint8_t btn); // returns 1 if the button was clicked since the last call to this function or button_reset() @@ -26,12 +30,14 @@ void button_reset(uint8_t btn); // LEDS +void led_set(uint8_t led, uint8_t state); void led_on(uint8_t led); void led_off(uint8_t led); void led_inv(uint8_t led); // MOTOR +void motor_set(uint8_t state); void motor_on(void); void motor_off(void); void motor_inv(void); diff --git a/firmware/lib/hal.c b/firmware/lib/hal.c index b1b0e69..932a6a1 100644 --- a/firmware/lib/hal.c +++ b/firmware/lib/hal.c @@ -2,8 +2,6 @@ #include #include -#define __DELAY_BACKWARD_COMPATIBLE__ -#include #include @@ -38,6 +36,7 @@ inline static void major_interrupt(void) { } } +// WARNING: this interrupt is already way too big. extend only in case of emergency! ISR(TIMER0_COMPA_vect) { if(ir_active) { PORTD ^= 1 << 2; @@ -99,6 +98,10 @@ void reset_hw(void) { button_pressed[1] = 0; } +uint8_t button_state(uint8_t btn) { + return !(PINB & (1 << btn)); +} + uint8_t button_clicked(uint8_t btn) { uint8_t clicked = button_pressed[btn]; button_pressed[btn] = 0; @@ -109,6 +112,14 @@ void button_reset(uint8_t btn) { button_pressed[btn] = 0; } +void led_set(uint8_t led, uint8_t state) { + if(state) { + led_on(led); + } else { + led_off(led); + } +} + void led_on(uint8_t led) { if(led == RIGHT) { PORTC &= ~(1 << 2); @@ -133,6 +144,14 @@ void led_inv(uint8_t led) { } } +void motor_set(uint8_t state) { + if(state) { + motor_on(); + } else { + motor_off(); + } +} + void motor_on(void) { PORTB |= 1 << 6; } diff --git a/firmware/lib/music.c b/firmware/lib/music.c index 1e5bb5c..71b3e54 100644 --- a/firmware/lib/music.c +++ b/firmware/lib/music.c @@ -1,8 +1,6 @@ #include #include -#define __DELAY_BACKWARD_COMPATIBLE__ -#include #include #include