Initial Commit

This commit is contained in:
2026-07-06 11:14:35 +09:00
parent e6de6e8cc3
commit e55b283b39
31 changed files with 1023 additions and 2123 deletions
+17 -38
View File
@@ -11,33 +11,25 @@
#include "led_control.h"
#include "debug_print.h"
/*==============================================================================
* Devicetree LED specs
*============================================================================*/
/* Devicetree LED specs */
#define LED_BLE_NODE DT_NODELABEL(led_ble)
#define FUNCTION_LED_NODE DT_NODELABEL(function_led)
static const struct gpio_dt_spec led_ble = GPIO_DT_SPEC_GET(LED_BLE_NODE, gpios);
static const struct gpio_dt_spec function_led = GPIO_DT_SPEC_GET(FUNCTION_LED_NODE, gpios);
/*==============================================================================
* Color constants
*============================================================================*/
/* Color constants */
#define COLOR_NONE 0
#define COLOR_GREEN 1
#define COLOR_ORANGE 2
/*==============================================================================
* Error pattern constants (State 7)
*============================================================================*/
/* Error pattern constants (State 7) */
#define ERROR_BLINK_ON_MS 166
#define ERROR_BLINK_OFF_MS 166
#define ERROR_BLINK_COUNT 3
#define ERROR_PAUSE_MS 1000
/*==============================================================================
* Pattern table
*============================================================================*/
/* Pattern table */
typedef struct {
uint32_t on_ms;
uint32_t off_ms;
@@ -56,9 +48,7 @@ static const led_pattern_t m_patterns[LED_STATE_COUNT] = {
[LED_STATE_ERROR] = { 0, 0, COLOR_ORANGE, true },
};
/*==============================================================================
* Module variables
*============================================================================*/
/* Module variables */
static struct k_timer m_led_timer;
static led_state_t m_current_state = LED_STATE_OFF;
@@ -68,9 +58,7 @@ static bool m_phase_on;
static uint8_t m_error_blink_cnt;
static uint8_t m_error_phase;
/*==============================================================================
* GPIO helpers
*============================================================================*/
/* GPIO helpers */
static inline void led_ble_on(void) { gpio_pin_set_dt(&led_ble, 1); }
static inline void led_ble_off(void) { gpio_pin_set_dt(&led_ble, 0); }
static inline void function_led_on(void) { gpio_pin_set_dt(&function_led, 1); }
@@ -89,18 +77,14 @@ static void led_color_on(uint8_t color)
else if (color == COLOR_ORANGE) function_led_on();
}
/*==============================================================================
* Timer helper
*============================================================================*/
/* Timer helper */
static void timer_start_ms(uint32_t ms)
{
if (ms == 0) return;
k_timer_start(&m_led_timer, K_MSEC(ms), K_NO_WAIT);
}
/*==============================================================================
* Error pattern state machine
*============================================================================*/
/* Error pattern state machine */
static void error_pattern_start(void)
{
m_error_blink_cnt = 0;
@@ -113,12 +97,12 @@ static void error_pattern_tick(void)
{
switch (m_error_phase)
{
case 0: /* ON period done -> OFF */
case 0: // ON period done -> OFF
led_all_off();
m_error_phase = 1;
timer_start_ms(ERROR_BLINK_OFF_MS);
break;
case 1: /* OFF period done */
case 1: // OFF period done
m_error_blink_cnt++;
if (m_error_blink_cnt < ERROR_BLINK_COUNT) {
m_error_phase = 0;
@@ -129,7 +113,7 @@ static void error_pattern_tick(void)
timer_start_ms(ERROR_PAUSE_MS);
}
break;
case 2: /* Pause done -> restart */
case 2: // Pause done -> restart
m_error_blink_cnt = 0;
m_error_phase = 0;
led_color_on(COLOR_ORANGE);
@@ -140,9 +124,7 @@ static void error_pattern_tick(void)
}
}
/*==============================================================================
* Timer callback
*============================================================================*/
/* Timer callback */
static void led_timer_handler(struct k_timer *timer)
{
ARG_UNUSED(timer);
@@ -157,7 +139,7 @@ static void led_timer_handler(struct k_timer *timer)
if (m_phase_on)
{
/* ON -> OFF transition */
// ON -> OFF transition
led_all_off();
m_phase_on = false;
@@ -171,12 +153,12 @@ static void led_timer_handler(struct k_timer *timer)
led_all_off();
m_current_state = LED_STATE_OFF;
}
/* POWER_ON: stays lit, no timer */
// POWER_ON: stays lit, no timer
}
}
else
{
/* OFF -> ON transition */
// OFF -> ON transition
if (p->repeat)
{
led_color_on(p->color);
@@ -186,10 +168,7 @@ static void led_timer_handler(struct k_timer *timer)
}
}
/*==============================================================================
* Public functions
*============================================================================*/
/* Public functions */
void led_init(void)
{
gpio_pin_configure_dt(&led_ble, GPIO_OUTPUT_INACTIVE);
@@ -242,5 +221,5 @@ void led_ble_solid(void)
k_timer_stop(&m_led_timer);
led_all_off();
led_ble_on();
m_current_state = LED_STATE_OFF; /* no pattern running */
m_current_state = LED_STATE_OFF; // no pattern running
}