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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ elseif(CONFIG_BSP_TARGET_KAMI)
set(BSP_TARGET "kami")
elseif(CONFIG_BSP_TARGET_BORNHACK_2025_CIRCLE)
set(BSP_TARGET "bornhack-2025-circle")
elseif(CONFIG_BSP_TARGET_BORNHACK_2024_POV)
set(BSP_TARGET "bornhack-2024-pov")
else()
set(BSP_TARGET "stub")
endif()
Expand Down
3 changes: 3 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ menu "Badge.Team BSP"
config BSP_TARGET_ESP32_P4_FUNCTION_EV_BOARD
bool "Espressif ESP32-P4 Function EV Board"

config BSP_TARGET_BORNHACK_2024_POV
bool "Bornhack 2024 POV"

config BSP_TARGET_BORNHACK_2025_CIRCLE
bool "Bornhack 2025 circle"
endchoice
Expand Down
112 changes: 112 additions & 0 deletions targets/bornhack-2024-pov/badge_bsp_input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// SPDX-FileCopyrightText: 2024 Julian Schefferss
// SPDX-License-Identifier: MIT

#include <stdint.h>
#include "bsp/input.h"
#include "driver/gpio.h"
#include "esp_attr.h"
#include "esp_check.h"
#include "esp_err.h"
#include "esp_intr_alloc.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "hal/gpio_types.h"
#include "portmacro.h"
#include "targets/bornhack-2024-pov/bh24_hardware.h"

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

static QueueHandle_t event_queue = NULL;

static int const input_pins[] = {
BSP_GPIO_BTN_UP,
BSP_GPIO_BTN_DOWN,
BSP_GPIO_BTN_SELECT,
};
static bsp_input_navigation_key_t const input_nav_keys[] = {
BSP_INPUT_NAVIGATION_KEY_UP,
BSP_INPUT_NAVIGATION_KEY_DOWN,
BSP_INPUT_NAVIGATION_KEY_SELECT,
};

static IRAM_ATTR void gpio_isr(void* arg) {
size_t index = (size_t)arg;
bsp_input_event_t event = {
.type = INPUT_EVENT_TYPE_NAVIGATION,
.args_navigation =
{
.key = input_nav_keys[index],
.modifiers = 0,
.state = !gpio_get_level(input_pins[index]),
},
};
BaseType_t shouldYield = pdFALSE;
xQueueSendFromISR(event_queue, &event, &shouldYield);
if (shouldYield == pdTRUE) {
portYIELD_FROM_ISR();
}
}

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));
ESP_ERROR_CHECK(gpio_isr_handler_add(input_pins[i], gpio_isr, (void*)i));
ESP_ERROR_CHECK(gpio_intr_enable(input_pins[i]));
}

return ESP_OK;
}

esp_err_t bsp_input_get_queue(QueueHandle_t* out_queue) {
if (out_queue == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (event_queue == NULL) {
return ESP_FAIL;
}
*out_queue = event_queue;
return ESP_OK;
}

bool bsp_input_needs_on_screen_keyboard(void) {
return false;
}

esp_err_t bsp_input_get_backlight_brightness(uint8_t* out_percentage) {
return ESP_ERR_NOT_SUPPORTED;
}

esp_err_t bsp_input_set_backlight_brightness(uint8_t percentage) {
return ESP_ERR_NOT_SUPPORTED;
}

esp_err_t bsp_input_read_navigation_key(bsp_input_navigation_key_t key, bool* out_state) {
switch (key) {
default:
return ESP_ERR_NOT_SUPPORTED;
case BSP_INPUT_NAVIGATION_KEY_UP:
*out_state = !gpio_get_level(BSP_GPIO_BTN_UP);
return ESP_OK;
case BSP_INPUT_NAVIGATION_KEY_DOWN:
*out_state = !gpio_get_level(BSP_GPIO_BTN_DOWN);
return ESP_OK;
case BSP_INPUT_NAVIGATION_KEY_SELECT:
*out_state = !gpio_get_level(BSP_GPIO_BTN_SELECT);
return ESP_OK;
}
return ESP_ERR_NOT_SUPPORTED;
}

esp_err_t bsp_input_read_action(bsp_input_action_type_t action, bool* out_state) {
return ESP_ERR_NOT_SUPPORTED;
}
51 changes: 51 additions & 0 deletions targets/bornhack-2024-pov/badge_bsp_led.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: 2025 Nicolai Electronics
// SPDX-License-Identifier: MIT

#include <stdint.h>
#include "bh24_hardware.h"
#include "bsp/led.h"
#include "esp_err.h"
#include "esp_log.h"
#include "led_strip.h"

static led_strip_handle_t led_strip = NULL;

esp_err_t bsp_led_initialize(void) {
ESP_LOGI("led", "test");

led_strip_config_t strip_config = {
.strip_gpio_num = BSP_LED_DATA_PIN,
.max_leds = BSP_LED_NUM,
.led_model = LED_MODEL_SK6812,
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB,
.flags =
{
.invert_out = false,
},
};

led_strip_rmt_config_t rmt_config = {
.clk_src = RMT_CLK_SRC_DEFAULT,
.resolution_hz = (10 * 1000 * 1000),
.mem_block_symbols = 0,
.flags =
{
.with_dma = false,
},
};

return led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip);
}

esp_err_t bsp_led_write(uint8_t* data, uint32_t length) {
if (led_strip == NULL) {
return ESP_ERR_INVALID_STATE;
}
if (length % 3 != 0) {
return ESP_ERR_INVALID_ARG;
}
for (uint32_t i = 0; i < length; i += 3) {
led_strip_set_pixel(led_strip, i / 3, data[i], data[i + 1], data[i + 2]);
}
return led_strip_refresh(led_strip);
}
21 changes: 21 additions & 0 deletions targets/bornhack-2024-pov/bh24_hardware.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

// SPDX-FileCopyrightText: 2025 Julian Scheffers <julian@scheffers.net>
// SPDX-License-Identifier: MIT

#pragma once

// I2C bus
#define BSP_I2C_BUS 0
#define BSP_I2C_SDA_PIN 6
#define BSP_I2C_SCL_PIN 7
#define BSP_I2C_SPEED 400000 // 400 kHz
#define BSP_I2C_TIMEOUT 250 // us

// Buttons.
#define BSP_GPIO_BTN_UP 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please suffix pin defines with PIN, GPIO is redundant in that case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the pattern established by the Tanmatsu target with BSP_GPIO_BTN_VOLUME_DOWN

#define BSP_GPIO_BTN_DOWN 8
#define BSP_GPIO_BTN_SELECT 9

// Addressable LEDs
#define BSP_LED_NUM 16
#define BSP_LED_DATA_PIN 10