Add documentation and convenience hal stuff

This commit is contained in:
Thammi 2013-08-29 23:07:17 +02:00
parent 86a97f4873
commit 26c2c6aa9c
3 changed files with 27 additions and 4 deletions

View File

@ -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);

View File

@ -2,8 +2,6 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#define __DELAY_BACKWARD_COMPATIBLE__
#include <util/delay.h>
#include <pentabug/lifecycle.h>
@ -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;
}

View File

@ -1,8 +1,6 @@
#include <pentabug/music.h>
#include <avr/io.h>
#define __DELAY_BACKWARD_COMPATIBLE__
#include <util/delay.h>
#include <pentabug/timer.h>
#include <pentabug/lifecycle.h>