Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions drivers/include/actuators/led.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
#ifndef __ACTUATORS_LED_H
#define __ACTUATORS_LED_H
#ifndef ACTUATORS_LED_H
#define ACTUATORS_LED_H

class LED {
public:
LED(int pin);

void LED_init(void);

void LED_on(void);

void LED_off(void);
/**
*
* @param pin GPIO attached to pin
*/
explicit LED(int pin);
/**
* @brief Board specific implementation of GPIO initialization
*/
void LED_init() const;
/**
* @brief Board specific implementation of GPIO high output
*/
void LED_on() const;
/**
* @brief Board specific implementation of GPIO low output
*/
void LED_off() const;

private:
/** GPIO number to whom the LED is connected */
int _pin;
};

Expand Down
113 changes: 76 additions & 37 deletions drivers/include/bsp.h
Original file line number Diff line number Diff line change
@@ -1,55 +1,94 @@
#ifndef __BSP_H__
#define __BSP_H__
#ifndef BSP_H_
#define BSP_H_
#include "led.h"
#include "hsm.h"

namespace BSP
{
void BSP_init();

void BSP_init_actuators();

void BSP_init_sensors();

void BSP_LED_on();

void BSP_LED_off();

void BSP_alternate_LED_on();

void BSP_alternate_LED_off();

void BSP_blue_led_on();

void BSP_blue_led_off();

void BSP_green_led_on();

void BSP_green_led_off();

void BSP_red_led_on();

void BSP_red_led_off();

void BSP_button_read();

/**
* @brief Init all board functions
*/
void init();
/**
* @brief Configures actuator GPIOs
*/
void init_actuators();
/**
* @brief Configure sensor GPIOs
*/
void init_sensors();
/**
* @brief Turn onboard LED ON
* @note Init actuators must have been called
*/
void onboard_led_on();
/**
* @brief Turn onboard LED off
*/
void onboard_led_off();
/**
* @brief Turn blue LED ON
* @note Init actuators must have been called
*/
void blue_led_on();
/**
* @brief Turn blue LED OFF
* @note Init actuators must have been called
*/
void blue_led_off();
/**
* @brief Turn green LED ON
* @note Init actuators must have been called
*/
void green_led_on();
/**
* @brief Turn green LED OFF
* @note Init actuators must have been called
*/
void green_led_off();
/**
* @brief Turn red LED ON
* @note Init actuators must have been called
*/
void red_led_on();
/**
* @brief Turn red LED OFF
* @note Init actuators must have been called
*/
void red_led_off();
/**
* @brief Check status of trigger and defuse buttons
* @note Init sensors must have been called
*/
void trigger_buttons_read();
/**
* @brief blocking wait in line
* @param ms no. of milliseconds to wait
*/
void BSP_delay(unsigned int ms);

void delay(unsigned int ms);
/**
* @brief Get on dev board led default instance
* @return pointer to onboard LED
*/
LED* get_default_onboard_led();

LED* get_alternate_onboard_led();

/**
* @brief Get blue LED default instance
* @return pointer to blue LED
*/
LED* get_blue_led();

/**
* @brief Get green LED default instance
* @return pointer to green LED
*/
LED* get_green_led();

/**
* @brief Get red LED default instance
* @return pointer to red LED
*/
LED* get_red_led();
};

/* Custom event signals. Extends from HSM signals */
enum EventSignals {
BUTTON_PRESSED_SIG = USER_SIGNAL,
BUTTON_RELEASED_SIG,
Expand Down
10 changes: 5 additions & 5 deletions drivers/ports/ESP32/ESP32_bsp.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef ESP32_BSP_H
#define ESP32_BSP_H
#include "bsp.h"
#include "freertos/FreeRTOS.h"


namespace ESP_BSP
{
void ESP32_BSP_Button_init(void);

void BSP_button_read(TimerHandle_t xTimer);
/**
* @brief Trampoline for BSP::trigger_buttons_read
* @param xTimer Handle to the timer that triggered the callback
*/
void button_read(TimerHandle_t xTimer);
}
#endif //ESP32_BSP_H
6 changes: 3 additions & 3 deletions drivers/ports/ESP32/actuators/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ LED::LED(const int pin) {
_pin = pin;
}

void LED::LED_init() {
void LED::LED_init() const {
gpio_set_direction(static_cast<gpio_num_t>(_pin), GPIO_MODE_OUTPUT);
printf("LED init\n");
}


void LED::LED_on() {
void LED::LED_on() const {
gpio_set_level(static_cast<gpio_num_t>(_pin), 1);
}

void LED::LED_off() {
void LED::LED_off() const {
gpio_set_level(static_cast<gpio_num_t>(_pin), 0);
}
55 changes: 21 additions & 34 deletions drivers/ports/ESP32/bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
#include "timebomb.h"

namespace BSP{
void BSP_init() {
BSP_init_actuators();
BSP_init_sensors();
void init() {
init_actuators();
init_sensors();
}

void BSP_init_actuators() {
void init_actuators() {
get_default_onboard_led()->LED_init();
get_blue_led()->LED_init();
get_red_led()->LED_init();
get_green_led()->LED_init();
}

void BSP_init_sensors() {
void init_sensors() {
gpio_set_direction(GPIO_NUM_25, GPIO_MODE_INPUT);
gpio_set_pull_mode(GPIO_NUM_25, GPIO_PULLDOWN_ONLY);

Expand All @@ -29,23 +29,15 @@ namespace BSP{
}


void BSP_LED_on() {
void onboard_led_on() {
get_default_onboard_led()->LED_on();
}

void BSP_LED_off() {
void onboard_led_off() {
get_default_onboard_led()->LED_off();
}

void BSP_alternate_LED_on() {
get_alternate_onboard_led()->LED_on();
}

void BSP_alternate_LED_off() {
get_alternate_onboard_led()->LED_off();
}

void BSP_delay(unsigned int ms) {
void delay(unsigned int ms) {
vTaskDelay(ms/portTICK_PERIOD_MS);
}

Expand All @@ -55,37 +47,32 @@ namespace BSP{
return &led;
}

LED* get_alternate_onboard_led() {
static LED led(12);
return &led;
}

void BSP_blue_led_on() {
void blue_led_on() {
get_blue_led()->LED_on();
}

void BSP_blue_led_off() {
void blue_led_off() {
get_blue_led()->LED_off();
}

void BSP_green_led_on() {
void green_led_on() {
get_green_led()->LED_on();
}

void BSP_green_led_off() {
void green_led_off() {
get_green_led()->LED_off();
}


void BSP_red_led_on() {
void red_led_on() {
get_red_led()->LED_on();
}

void BSP_red_led_off() {
void red_led_off() {
get_red_led()->LED_off();
}

void BSP_button_read() {
void trigger_buttons_read() {
int button_status[2] = {};

/* state of button. static to persist between func calls */
Expand Down Expand Up @@ -113,20 +100,20 @@ namespace BSP{

if (tmp) { /*change of button state has occurred */
if (button_status[0]) { /* button pressed */
static const Event button_pressed_event = {BUTTON_PRESSED_SIG};
static constexpr Event button_pressed_event = {BUTTON_PRESSED_SIG};
TimeBomb::get_default_instance()->_post(&button_pressed_event);
} else { /* button released */
static const Event button_released_event = {BUTTON_RELEASED_SIG};
static constexpr Event button_released_event = {BUTTON_RELEASED_SIG};
TimeBomb::get_default_instance()->_post(&button_released_event);
}
}

if (tmp2) { /*change of button 2 state has occurred */
if (button_status[1]) { /* button 2 pressed */
static const Event button2_pressed_event = {BUTTON2_PRESSED_SIG};
static constexpr Event button2_pressed_event = {BUTTON2_PRESSED_SIG};
TimeBomb::get_default_instance()->_post(&button2_pressed_event);
} else { /* button 2 released */
static const Event button2_released_event = {BUTTON2_RELEASED_SIG};
static constexpr Event button2_released_event = {BUTTON2_RELEASED_SIG};
TimeBomb::get_default_instance()->_post(&button2_released_event);
}
}
Expand All @@ -153,7 +140,7 @@ namespace BSP{

namespace ESP_BSP
{
void BSP_button_read(TimerHandle_t xTimer) {
BSP::BSP_button_read();
void button_read(TimerHandle_t xTimer) {
BSP::trigger_buttons_read();
}
}
6 changes: 3 additions & 3 deletions drivers/ports/mbed-common/actuators/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ LED::LED(const int pin) {
_pin = pin;
}

void LED::LED_init() {
void LED::LED_init() const {
printf("LED init\n");
}


void LED::LED_on() {
void LED::LED_on() const{
DigitalOut onboard_led(static_cast<PinName>(_pin));
onboard_led.write(1);
printf("LED on\n");
}

void LED::LED_off() {
void LED::LED_off() const{
DigitalInOut onboard_led(static_cast<PinName>(_pin));
onboard_led.output();
onboard_led.write(0);
Expand Down
Loading
Loading