pentabug/firmware/include/pentabug/hal.h

153 lines
2.7 KiB
C

/** @file */
#ifndef HAL_H
#define HAL_H
#include <stdint.h>
/** direction constant for LEDs etc */
#define LEFT 0
/** direction constant for LEDs etc */
#define RIGHT 1
#define OFF 0
#define ON 1
#define TICKS_PER_MS 38
// INITIALIZATION
// initializes the hardware (timers, ...)
void init_hw(void);
// resets hardware to a state which is convenient for starting applications
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 if the button was clicked since the last call to this
* function or button_reset().
* @param btn Button (0 or 1)
* @return 1 if the button was pressed, 0 else
*/
uint8_t button_clicked(uint8_t btn);
void button_reset(uint8_t btn);
// LEDS
/**
* Sets LED to state.
* @param led Side (LEFT or RIGHT)
* @param state State off (0) or on (else)
*/
void led_set(uint8_t led, uint8_t state);
/**
* Switches on the LED on the side specified.
* @param led Side (LEFT or RIGHT)
*/
void led_on(uint8_t led);
/**
* Switches off the LED on the side specified.
* @param led Side (LEFT or RIGHT)
*/
void led_off(uint8_t led);
/**
* Returns the LED state.
* @param led Side (LEFT or RIGHT)
* @return State (0 for off, 1 for on)
*/
uint8_t led_state(uint8_t led);
/**
* Toggles the LED state.
* @param led Side (LEFT or RIGHT)
*/
void led_inv(uint8_t led);
// MOTOR
/**
* Sets motor to state.
* @param state State off (0) or on (else)
*/
void motor_set(uint8_t state);
/**
* Turns motor on.
*/
void motor_on(void);
/**
* Turns motor off.
*/
void motor_off(void);
/**
* Toggles motor state.
*/
void motor_inv(void);
// BUZZER
// turns buzzer into one of the sound wave creating states
void buzzer_up(void);
void buzzer_down(void);
// inverts both buzzer pins, creates a sound wave if buzzer was previously up or down (see above)
void buzzer_inv(void);
// turns buzzer off, buzzer_inv() won't create a sound wave after this call
void buzzer_off(void);
// IR
// all these functions control whether a 38kHz modulated IR signal is sent
/**
* Turns sending of IR signal on.
*/
void ir_on(void);
/**
* Turns sending of IR signal off.
*/
void ir_off(void);
/**
* Toggles state of IR signal (sending on or off).
*/
void ir_inv(void);
/**
* Set IR signal sending to state.
* @param state State off (0) or on (else)
*/
void ir_set(uint8_t state);
/**
* Returns if a signal was received.
* @return 1 if yes, 0 else
*/
uint8_t ir_recv(void);
// WAITING
/**
* Waits the given amount of ms.
* @ms Time in milliseconds (must be below 1500)
*/
void wait_ms(uint16_t ms);
// wait the given amount of ticks, see TICKS_PER_MS
void wait_ticks(int16_t ticks);
#endif /* HAL_H */