2012-09-02 23:17:59 +02:00
|
|
|
#ifndef BUGHAL_H
|
|
|
|
#define BUGHAL_H
|
|
|
|
|
2012-10-01 22:11:28 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2012-09-02 23:17:59 +02:00
|
|
|
/* Hardware abstraction layer for Pentabug hardware */
|
|
|
|
|
|
|
|
enum { BUZZR_OUT, //initialize buzzer for OUTPUT mode (emmiting soundwaves)
|
|
|
|
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 (0<<PORTB1)
|
|
|
|
#define MOTOR_OFF (1<<PORTB1)
|
2012-09-02 23:17:59 +02:00
|
|
|
|
2012-10-01 23:36:37 +02:00
|
|
|
#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,
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2012-09-02 23:17:59 +02:00
|
|
|
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
|
|
|
|
2012-10-01 23:36:37 +02:00
|
|
|
// init ports and stuff for button functions
|
2012-09-02 23:17:59 +02:00
|
|
|
void init_switch(void);
|
2012-10-01 23:36:37 +02:00
|
|
|
|
|
|
|
// 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?
|
|
|
|
|
2012-09-02 23:17:59 +02:00
|
|
|
void init_motor(void);
|
2012-09-06 23:09:20 +02:00
|
|
|
void set_motor(int);
|
|
|
|
|
|
|
|
|
2012-10-01 23:36:37 +02:00
|
|
|
// 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);
|
2012-09-02 23:17:59 +02:00
|
|
|
|
2012-10-01 22:11:28 +02:00
|
|
|
|
2012-09-02 23:17:59 +02:00
|
|
|
#endif
|