Skip to content

Commit 2bb5fa7

Browse files
authored
Merge pull request #37 from badgeteam/bornhack24
Add bornhack 2024 support
2 parents 50ae166 + 5d31966 commit 2bb5fa7

File tree

5 files changed

+189
-0
lines changed

5 files changed

+189
-0
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ elseif(CONFIG_BSP_TARGET_KAMI)
1616
set(BSP_TARGET "kami")
1717
elseif(CONFIG_BSP_TARGET_BORNHACK_2025_CIRCLE)
1818
set(BSP_TARGET "bornhack-2025-circle")
19+
elseif(CONFIG_BSP_TARGET_BORNHACK_2024_POV)
20+
set(BSP_TARGET "bornhack-2024-pov")
1921
else()
2022
set(BSP_TARGET "stub")
2123
endif()

Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ menu "Badge.Team BSP"
2727
config BSP_TARGET_ESP32_P4_FUNCTION_EV_BOARD
2828
bool "Espressif ESP32-P4 Function EV Board"
2929

30+
config BSP_TARGET_BORNHACK_2024_POV
31+
bool "Bornhack 2024 POV"
32+
3033
config BSP_TARGET_BORNHACK_2025_CIRCLE
3134
bool "Bornhack 2025 circle"
3235
endchoice
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// SPDX-FileCopyrightText: 2024 Julian Schefferss
2+
// SPDX-License-Identifier: MIT
3+
4+
#include <stdint.h>
5+
#include "bsp/input.h"
6+
#include "driver/gpio.h"
7+
#include "esp_attr.h"
8+
#include "esp_check.h"
9+
#include "esp_err.h"
10+
#include "esp_intr_alloc.h"
11+
#include "freertos/FreeRTOS.h"
12+
#include "freertos/queue.h"
13+
#include "hal/gpio_types.h"
14+
#include "portmacro.h"
15+
#include "targets/bornhack-2024-pov/bh24_hardware.h"
16+
17+
static char const TAG[] = "BSP: INPUT";
18+
19+
static QueueHandle_t event_queue = NULL;
20+
21+
static int const input_pins[] = {
22+
BSP_GPIO_BTN_UP,
23+
BSP_GPIO_BTN_DOWN,
24+
BSP_GPIO_BTN_SELECT,
25+
};
26+
static bsp_input_navigation_key_t const input_nav_keys[] = {
27+
BSP_INPUT_NAVIGATION_KEY_UP,
28+
BSP_INPUT_NAVIGATION_KEY_DOWN,
29+
BSP_INPUT_NAVIGATION_KEY_SELECT,
30+
};
31+
32+
static IRAM_ATTR void gpio_isr(void* arg) {
33+
size_t index = (size_t)arg;
34+
bsp_input_event_t event = {
35+
.type = INPUT_EVENT_TYPE_NAVIGATION,
36+
.args_navigation =
37+
{
38+
.key = input_nav_keys[index],
39+
.modifiers = 0,
40+
.state = !gpio_get_level(input_pins[index]),
41+
},
42+
};
43+
BaseType_t shouldYield = pdFALSE;
44+
xQueueSendFromISR(event_queue, &event, &shouldYield);
45+
if (shouldYield == pdTRUE) {
46+
portYIELD_FROM_ISR();
47+
}
48+
}
49+
50+
esp_err_t bsp_input_initialize(void) {
51+
// Create input queue.
52+
if (event_queue) {
53+
return ESP_OK;
54+
}
55+
56+
event_queue = xQueueCreate(32, sizeof(bsp_input_event_t));
57+
ESP_RETURN_ON_FALSE(event_queue, ESP_ERR_NO_MEM, TAG, "Failed to create input event queue");
58+
59+
ESP_ERROR_CHECK(gpio_install_isr_service(0));
60+
for (int i = 0; i < 3; i++) {
61+
ESP_ERROR_CHECK(gpio_set_direction(input_pins[i], GPIO_MODE_INPUT));
62+
ESP_ERROR_CHECK(gpio_set_intr_type(input_pins[i], GPIO_INTR_ANYEDGE));
63+
ESP_ERROR_CHECK(gpio_isr_handler_add(input_pins[i], gpio_isr, (void*)i));
64+
ESP_ERROR_CHECK(gpio_intr_enable(input_pins[i]));
65+
}
66+
67+
return ESP_OK;
68+
}
69+
70+
esp_err_t bsp_input_get_queue(QueueHandle_t* out_queue) {
71+
if (out_queue == NULL) {
72+
return ESP_ERR_INVALID_ARG;
73+
}
74+
if (event_queue == NULL) {
75+
return ESP_FAIL;
76+
}
77+
*out_queue = event_queue;
78+
return ESP_OK;
79+
}
80+
81+
bool bsp_input_needs_on_screen_keyboard(void) {
82+
return false;
83+
}
84+
85+
esp_err_t bsp_input_get_backlight_brightness(uint8_t* out_percentage) {
86+
return ESP_ERR_NOT_SUPPORTED;
87+
}
88+
89+
esp_err_t bsp_input_set_backlight_brightness(uint8_t percentage) {
90+
return ESP_ERR_NOT_SUPPORTED;
91+
}
92+
93+
esp_err_t bsp_input_read_navigation_key(bsp_input_navigation_key_t key, bool* out_state) {
94+
switch (key) {
95+
default:
96+
return ESP_ERR_NOT_SUPPORTED;
97+
case BSP_INPUT_NAVIGATION_KEY_UP:
98+
*out_state = !gpio_get_level(BSP_GPIO_BTN_UP);
99+
return ESP_OK;
100+
case BSP_INPUT_NAVIGATION_KEY_DOWN:
101+
*out_state = !gpio_get_level(BSP_GPIO_BTN_DOWN);
102+
return ESP_OK;
103+
case BSP_INPUT_NAVIGATION_KEY_SELECT:
104+
*out_state = !gpio_get_level(BSP_GPIO_BTN_SELECT);
105+
return ESP_OK;
106+
}
107+
return ESP_ERR_NOT_SUPPORTED;
108+
}
109+
110+
esp_err_t bsp_input_read_action(bsp_input_action_type_t action, bool* out_state) {
111+
return ESP_ERR_NOT_SUPPORTED;
112+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-FileCopyrightText: 2025 Nicolai Electronics
2+
// SPDX-License-Identifier: MIT
3+
4+
#include <stdint.h>
5+
#include "bh24_hardware.h"
6+
#include "bsp/led.h"
7+
#include "esp_err.h"
8+
#include "esp_log.h"
9+
#include "led_strip.h"
10+
11+
static led_strip_handle_t led_strip = NULL;
12+
13+
esp_err_t bsp_led_initialize(void) {
14+
ESP_LOGI("led", "test");
15+
16+
led_strip_config_t strip_config = {
17+
.strip_gpio_num = BSP_LED_DATA_PIN,
18+
.max_leds = BSP_LED_NUM,
19+
.led_model = LED_MODEL_SK6812,
20+
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB,
21+
.flags =
22+
{
23+
.invert_out = false,
24+
},
25+
};
26+
27+
led_strip_rmt_config_t rmt_config = {
28+
.clk_src = RMT_CLK_SRC_DEFAULT,
29+
.resolution_hz = (10 * 1000 * 1000),
30+
.mem_block_symbols = 0,
31+
.flags =
32+
{
33+
.with_dma = false,
34+
},
35+
};
36+
37+
return led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip);
38+
}
39+
40+
esp_err_t bsp_led_write(uint8_t* data, uint32_t length) {
41+
if (led_strip == NULL) {
42+
return ESP_ERR_INVALID_STATE;
43+
}
44+
if (length % 3 != 0) {
45+
return ESP_ERR_INVALID_ARG;
46+
}
47+
for (uint32_t i = 0; i < length; i += 3) {
48+
led_strip_set_pixel(led_strip, i / 3, data[i], data[i + 1], data[i + 2]);
49+
}
50+
return led_strip_refresh(led_strip);
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
// SPDX-FileCopyrightText: 2025 Julian Scheffers <julian@scheffers.net>
3+
// SPDX-License-Identifier: MIT
4+
5+
#pragma once
6+
7+
// I2C bus
8+
#define BSP_I2C_BUS 0
9+
#define BSP_I2C_SDA_PIN 6
10+
#define BSP_I2C_SCL_PIN 7
11+
#define BSP_I2C_SPEED 400000 // 400 kHz
12+
#define BSP_I2C_TIMEOUT 250 // us
13+
14+
// Buttons.
15+
#define BSP_GPIO_BTN_UP 2
16+
#define BSP_GPIO_BTN_DOWN 8
17+
#define BSP_GPIO_BTN_SELECT 9
18+
19+
// Addressable LEDs
20+
#define BSP_LED_NUM 16
21+
#define BSP_LED_DATA_PIN 10

0 commit comments

Comments
 (0)