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
7 changes: 2 additions & 5 deletions bsp/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
#include "driver/i2s_types.h"
#include "esp_err.h"

// Badge BSP
// Audio APIs

/// @brief Initialize BSP audio subsystem
/// @brief BSP audio set sample rate
/// @return ESP-IDF error code
esp_err_t bsp_audio_initialize(uint32_t rate);
esp_err_t bsp_audio_set_rate(uint32_t rate);

/// @brief BSP audio get volume
/// @return ESP-IDF error code
Expand Down
16 changes: 0 additions & 16 deletions bsp/battery.h

This file was deleted.

3 changes: 0 additions & 3 deletions bsp/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <stdint.h>
#include "esp_err.h"

// Badge BSP
// Device related APIs

/// @brief Initialize the hardware managed by the BSP
/// @details Initialize the hardware and related drivers managed by the BSP
/// @return ESP-IDF error code
Expand Down
10 changes: 0 additions & 10 deletions bsp/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include "esp_lcd_types.h"
#include "freertos/FreeRTOS.h"

// Badge BSP
// Display related APIs

/// @brief Display rotation
/// @details Relative to how you would rotate the display clockwise
typedef enum {
Expand All @@ -26,13 +23,6 @@ typedef enum {
BSP_DISPLAY_TE_V_AND_H_BLANKING,
} bsp_display_te_mode_t;

/// @brief Initialize the display
/// @details Initialize the display
/// @return ESP-IDF error code
/// - ESP_OK if BSP initialized correctly
/// - ESP_FAIL if the BSP could not initialize
esp_err_t bsp_display_initialize(void);

/// @brief Get display parameters
/// @details Get display parameters
/// @return ESP-IDF error code
Expand Down
7 changes: 0 additions & 7 deletions bsp/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"

// Badge BSP
// I2C APIs

/// @brief Initialize the primary I2C bus
/// @return ESP-IDF error code
esp_err_t bsp_i2c_primary_bus_initialize(void);

/// @brief Get the primary I2C bus handle
/// @return ESP-IDF error code
esp_err_t bsp_i2c_primary_bus_get_handle(i2c_master_bus_handle_t* handle);
Expand Down
4 changes: 0 additions & 4 deletions bsp/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ typedef struct _bsp_input_event {
};
} bsp_input_event_t;

/// @brief Initialize the BSP input subsystem
/// @return ESP-IDF error code
esp_err_t bsp_input_initialize(void);

/// @brief Get the queue handle for the input event queue
/// @return ESP-IDF error code
esp_err_t bsp_input_get_queue(QueueHandle_t* out_queue);
Expand Down
7 changes: 0 additions & 7 deletions bsp/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
#include <stdint.h>
#include "esp_err.h"

// Badge BSP
// LED APIs

/// @brief Initialize BSP led subsystem
/// @return ESP-IDF error code
esp_err_t bsp_led_initialize(void);

/// @brief Write data to LEDs
/// @return ESP-IDF error code
esp_err_t bsp_led_write(const uint8_t* data, uint32_t length);
12 changes: 12 additions & 0 deletions bsp/macro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "esp_err.h"

#define BSP_RETURN_ON_FAILURE(x, ...) \
do { \
esp_err_t err_rc_ = (x); \
if (unlikely(err_rc_ != ESP_OK && err_rc_ != ESP_ERR_NOT_SUPPORTED)) { \
__VA_ARGS__; \
return err_rc_; \
} \
} while (0)
4 changes: 0 additions & 4 deletions bsp/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ typedef enum {
BSP_POWER_RADIO_STATE_APPLICATION = 2,
} bsp_radio_state_t;

/// @brief Initialize BSP power subsystem
/// @return ESP-IDF error code
esp_err_t bsp_power_initialize(void);

/// @brief Get battery information
/// @return ESP-IDF error code
esp_err_t bsp_power_get_battery_information(bsp_power_battery_information_t* out_information);
Expand Down
3 changes: 0 additions & 3 deletions bsp/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <stdint.h>
#include "esp_err.h"

// Badge BSP
// Real Time Clock APIs

/// @brief Get time
/// @return ESP-IDF error code
esp_err_t bsp_rtc_get_time(uint32_t* value);
Expand Down
3 changes: 0 additions & 3 deletions bsp/tanmatsu.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include "freertos/semphr.h"
#include "tanmatsu_coprocessor.h"

// Badge BSP
// TANMATSU specific APIs

/// @brief Get coprocessor handle
/// @return ESP-IDF error code
esp_err_t bsp_tanmatsu_coprocessor_get_handle(tanmatsu_coprocessor_handle_t* handle);
Expand Down
26 changes: 0 additions & 26 deletions bsp/wrapped/bsp_err.h

This file was deleted.

6 changes: 0 additions & 6 deletions bsp/wrapper.h

This file was deleted.

55 changes: 55 additions & 0 deletions common/badge_bsp_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "bsp/audio.h"
#include "bsp/device.h"
#include "bsp/display.h"
#include "bsp/i2c.h"
#include "bsp/input.h"
#include "bsp/macro.h"
#include "bsp/power.h"
#include "bsp/rtc.h"
#include "driver/gpio.h"
#include "esp_err.h"
#include "esp_log.h"

static char const TAG[] = "BSP: device";

// Internal BSP functions to initialize the subsystems
esp_err_t bsp_device_initialize_custom(void);
esp_err_t bsp_audio_initialize(void);
esp_err_t bsp_display_initialize(void);
esp_err_t bsp_i2c_primary_bus_initialize(void);
esp_err_t bsp_input_initialize(void);
esp_err_t bsp_led_initialize(void);
esp_err_t bsp_power_initialize(void);
esp_err_t bsp_rtc_initialize(void);

esp_err_t bsp_device_initialize(void) {
// Install the ISR service for GPIO interrupts
gpio_install_isr_service(0);

// Initialize the primary I2C bus
BSP_RETURN_ON_FAILURE(bsp_i2c_primary_bus_initialize(), ESP_LOGE(TAG, "Failed to initialize primary I2C bus"));

// Initialize the display
BSP_RETURN_ON_FAILURE(bsp_display_initialize(), ESP_LOGE(TAG, "Failed to initialize display"));

// Initialize the input framework
BSP_RETURN_ON_FAILURE(bsp_input_initialize(), ESP_LOGE(TAG, "Failed to initialize input framework"));

// Initialize device specific hardware
BSP_RETURN_ON_FAILURE(bsp_device_initialize_custom(),
ESP_LOGE(TAG, "Failed to initialize device specific hardware"));

// Initialize power
BSP_RETURN_ON_FAILURE(bsp_power_initialize(), ESP_LOGE(TAG, "Failed to initialize power subsystem"));

// Initialize the RTC
BSP_RETURN_ON_FAILURE(bsp_rtc_initialize(), ESP_LOGE(TAG, "Failed to initialize RTC subsystem"));

// Initialize audio
BSP_RETURN_ON_FAILURE(bsp_audio_initialize(), ESP_LOGE(TAG, "Failed to initialize audio subsystem"));

// Initialize LEDs
BSP_RETURN_ON_FAILURE(bsp_led_initialize(), ESP_LOGE(TAG, "Failed to initialize LED subsystem"));

return ESP_OK;
}
28 changes: 0 additions & 28 deletions common/wrapper.c

This file was deleted.

6 changes: 5 additions & 1 deletion stub/badge_bsp_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#include "bsp/audio.h"
#include "esp_err.h"

esp_err_t __attribute__((weak)) bsp_audio_initialize(uint32_t rate) {
esp_err_t __attribute__((weak)) bsp_audio_initialize(void) {
return ESP_ERR_NOT_SUPPORTED;
}

esp_err_t __attribute__((weak)) bsp_audio_set_rate(uint32_t rate) {
return ESP_ERR_NOT_SUPPORTED;
}

Expand Down
17 changes: 0 additions & 17 deletions stub/badge_bsp_battery.c

This file was deleted.

5 changes: 3 additions & 2 deletions stub/badge_bsp_device.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Board support package API: Generic stub implementation
// SPDX-FileCopyrightText: 2024 Nicolai Electronics
// SPDX-FileCopyrightText: 2025 Nicolai Electronics
// SPDX-License-Identifier: MIT

#include <stdbool.h>
Expand All @@ -8,12 +8,13 @@
#include "bootloader_common.h"
#include "bsp/device.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_system.h"

static char const device_name[] = "Generic board";
static char const device_manufacturer[] = "Unknown";

esp_err_t __attribute__((weak)) bsp_device_initialize(void) {
esp_err_t __attribute__((weak)) bsp_device_initialize_custom(void) {
return ESP_OK;
}

Expand Down
4 changes: 4 additions & 0 deletions stub/badge_bsp_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "bsp/rtc.h"
#include "esp_err.h"

esp_err_t __attribute__((weak)) bsp_rtc_initialize(void) {
return ESP_ERR_NOT_SUPPORTED;
}

esp_err_t __attribute__((weak)) bsp_rtc_get_time(uint32_t* value) {
return ESP_ERR_NOT_SUPPORTED;
}
Expand Down
33 changes: 33 additions & 0 deletions targets/bornhack-2024-pov/badge_bsp_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2025 Nicolai Electronics
// SPDX-License-Identifier: MIT

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "bsp/device.h"
#include "bsp/display.h"
#include "bsp/i2c.h"
#include "bsp/input.h"
#include "driver/gpio.h"
#include "esp_check.h"
#include "esp_err.h"
#include "esp_log.h"

static char const device_name[] = "Bornhack 2024 badge";
static char const device_manufacturer[] = "Thomas Flummer";

esp_err_t bsp_device_get_name(char* output, uint8_t buffer_length) {
if (output == NULL) {
return ESP_ERR_INVALID_ARG;
}
strlcpy(output, device_name, buffer_length);
return ESP_OK;
}

esp_err_t bsp_device_get_manufacturer(char* output, uint8_t buffer_length) {
if (output == NULL) {
return ESP_ERR_INVALID_ARG;
}
strlcpy(output, device_manufacturer, buffer_length);
return ESP_OK;
}
4 changes: 2 additions & 2 deletions targets/bornhack-2024-pov/badge_bsp_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ i2c_master_bus_config_t i2c_master_config_internal = {
};

esp_err_t bsp_i2c_primary_bus_initialize(void) {
ESP_RETURN_ON_ERROR(i2c_new_master_bus(&i2c_master_config_internal, &i2c_bus_handle_internal), TAG,
"Failed to initialize I2C bus");
i2c_concurrency_semaphore = xSemaphoreCreateBinary();
if (i2c_concurrency_semaphore == NULL) {
return ESP_ERR_NO_MEM;
}
ESP_RETURN_ON_ERROR(i2c_new_master_bus(&i2c_master_config_internal, &i2c_bus_handle_internal), TAG,
"Failed to initialize I2C bus");
xSemaphoreGive(i2c_concurrency_semaphore);
return ESP_OK;
}
Expand Down
6 changes: 0 additions & 6 deletions targets/bornhack-2024-pov/badge_bsp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ static IRAM_ATTR void gpio_isr(void* arg) {
}

esp_err_t bsp_input_initialize(void) {
// Create input queue.
if (event_queue) {
return ESP_OK;
}

event_queue = xQueueCreate(32, sizeof(bsp_input_event_t));
ESP_RETURN_ON_FALSE(event_queue, ESP_ERR_NO_MEM, TAG, "Failed to create input event queue");

ESP_ERROR_CHECK(gpio_install_isr_service(0));
for (int i = 0; i < 3; i++) {
ESP_ERROR_CHECK(gpio_set_direction(input_pins[i], GPIO_MODE_INPUT));
ESP_ERROR_CHECK(gpio_set_intr_type(input_pins[i], GPIO_INTR_ANYEDGE));
Expand Down
Loading