firmware: LED heartbeat on GPIO35 (boot/alive/rx/tx/fault patterns), non-blocking
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
#include "led.h"
|
||||
#include "board.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
static volatile bool s_boot_done;
|
||||
static volatile int64_t s_rx_at; // us timestamps of last events
|
||||
static volatile int64_t s_tx_at;
|
||||
static volatile int64_t s_fault_at;
|
||||
|
||||
static void set(bool on)
|
||||
{
|
||||
gpio_set_level(BOARD_LED, on);
|
||||
}
|
||||
|
||||
// Pattern engine. 10 ms resolution is plenty for eyes and costs nothing.
|
||||
static void led_task(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
for (;;) {
|
||||
int64_t now = esp_timer_get_time();
|
||||
|
||||
if (!s_boot_done) {
|
||||
set(true); // solid: powering up / radio init
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now - s_fault_at < 5000000LL) { // fault: rapid flash, 5 s
|
||||
set(true); vTaskDelay(pdMS_TO_TICKS(100));
|
||||
set(false); vTaskDelay(pdMS_TO_TICKS(100));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now - s_tx_at < 1000000LL) { // repeat: double blink
|
||||
s_tx_at = 0;
|
||||
set(true); vTaskDelay(pdMS_TO_TICKS(60));
|
||||
set(false); vTaskDelay(pdMS_TO_TICKS(80));
|
||||
set(true); vTaskDelay(pdMS_TO_TICKS(60));
|
||||
set(false); vTaskDelay(pdMS_TO_TICKS(200));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now - s_rx_at < 1000000LL) { // valid RX: single blink
|
||||
s_rx_at = 0;
|
||||
set(true); vTaskDelay(pdMS_TO_TICKS(40));
|
||||
set(false); vTaskDelay(pdMS_TO_TICKS(200));
|
||||
continue;
|
||||
}
|
||||
|
||||
// alive: short blip every 2 s
|
||||
set(true); vTaskDelay(pdMS_TO_TICKS(30));
|
||||
set(false); vTaskDelay(pdMS_TO_TICKS(1970));
|
||||
}
|
||||
}
|
||||
|
||||
void led_init(void)
|
||||
{
|
||||
gpio_config_t cfg = {
|
||||
.pin_bit_mask = 1ULL << BOARD_LED,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
};
|
||||
gpio_config(&cfg);
|
||||
set(true);
|
||||
xTaskCreate(led_task, "led", 2048, NULL, 2, NULL);
|
||||
}
|
||||
|
||||
void led_boot_done(void) { s_boot_done = true; }
|
||||
void led_notify_rx(void) { s_rx_at = esp_timer_get_time(); }
|
||||
void led_notify_tx(void) { s_tx_at = esp_timer_get_time(); }
|
||||
void led_notify_fault(void) { s_fault_at = esp_timer_get_time(); }
|
||||
Reference in New Issue
Block a user