-
Notifications
You must be signed in to change notification settings - Fork 0
Add bornhack 2024 support #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} |
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); | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please suffix pin defines with PIN, GPIO is redundant in that case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the pattern established by the Tanmatsu target with |
||
#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 |
Uh oh!
There was an error while loading. Please reload this page.