pentabug/firmware/lib/bughal.h

70 lines
2.0 KiB
C
Raw Normal View History

#ifndef BUGHAL_H
#define BUGHAL_H
2012-10-01 22:11:28 +02:00
#include <stdbool.h>
/* Hardware abstraction layer for Pentabug hardware */
2012-10-07 00:52:53 +02:00
enum {
BUZZR_OUT, //initialize buzzer for OUTPUT mode (emmiting soundwaves)
2012-10-07 02:04:16 +02:00
BUZZR_IN
//initialize buzzer for INPUT mode (registering soundwaves)
};
2012-09-06 23:09:20 +02:00
#define LED_L (1 << PORTC0)
#define LED_R (1 << PORTC2)
#define MOTOR_ON 1
#define MOTOR_OFF 0
#define BTN_RIGHT 1
#define BTN_LEFT 0
#define BTN_BUTTONS 2 //numer of Buttons
#define BTN_T_DEBOUNCE 5 // 50ms debounce time = minimum short press time
#define BTN_T_LONGFACT 10 // after 10 * T_DEBOUNCE = 500ms button registers as long pressed
//BUTTON state machine states
#define BTNST_NTRL 0 // neutral - initial state nothing interesting, please go along
#define BTNST_DBNC 1 // debounce - pin went up, but we wait for things to stabilize and stop oscillating
#define BTNST_SDN 4 // affirmative, button is pressed,
2012-10-07 00:52:53 +02:00
// and it's pressed no longer than
// BTN_T_LONGFACT * BTN_T_DEBOUNCE * 10ms
#define BTNST_SUP 8 // and button went up after beeing pressed for a _short_ time
2012-10-07 00:52:53 +02:00
#define BTNST_LDN 16 // button is still down for more than
//BTN_T_LONGFACT * BTN_T_DEBOUNCE * 10ms
#define BTNST_LUP 32 // button came up after being pressed for a long time
#define BTNST_SUPDBNC 64 // debounce after short up
#define BTNST_LUPDBNC 128 // debounce after long up
void init_leds(void);
2012-09-06 23:09:20 +02:00
void led_on(int);
void led_off(int);
2012-10-01 04:32:00 +02:00
void init_buzzr(void);
2012-10-05 21:12:26 +02:00
void init_mic(void);
2012-10-01 04:32:00 +02:00
void buzzr_up(void);
void buzzr_down(void);
void buzzr_off(void);
void buzzr_inv(void);
2012-09-06 23:09:20 +02:00
// init ports and stuff for button functions
void init_switch(void);
// direct low level access to switches
2012-10-01 22:11:28 +02:00
bool switch_l(void); //switch pressed?
bool switch_r(void); //switch pressed?
void init_motor(void);
2012-09-06 23:09:20 +02:00
void set_motor(int);
// higher level functions for accessing switches
void button_poll(void); //needs to be polled in regular intervalls (lets say every 10ms)
// reset button to neutral state
void button_clear(uint8_t button);
//test if buttonstate of btn eqals btnstate, returns true if yes
bool btn_state(uint8_t btnstate, uint8_t btn);
#endif