- Dual-Core Architecture: Dedicated 1000Hz USB gaming pipeline on Core 1 and BLE/Wi-Fi/Web telemetry on Core 0. - Multi-Input BLE Host: Parsers for Xbox Wireless, Google Stadia, 8BitDo (Ultimate/Pro2/SN30), and Generic HOGP gamepads. - Multi-Console USB Emulation: Nintendo Switch, PC DirectInput, PS3, PS4, Xbox 360 (libxsm3 cryptographic challenge-response), Original Xbox, and Couch Mouse/Keyboard. - Onboard Web Portal & Captive Portal: Real-time SVG gamepad visualizer, stick deadzone calibration, button combo remapping, and Wi-Fi manager. - Low-Latency Radio Management: Interactive SoftAP toggle to drop to 0-latency gaming mode. - Dual OTA Firmware Flashing: Browser-based wireless firmware updater and automated Python OTA script. - Strict Build Quality: Clean build under -Wall -Wextra with zero warnings or errors. - Versioning & Licensing: Semantic Versioning v1.0.0 and GNU GPLv3 with Commercial Restrictions.
174 lines
5.1 KiB
C
174 lines
5.1 KiB
C
#include "status_led.h"
|
|
#include "board_esp32_s3_zero.h"
|
|
#include "led_strip.h"
|
|
#include "esp_log.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
static const char *TAG = "STATUS_LED";
|
|
static led_strip_handle_t s_led_strip = NULL;
|
|
static volatile led_status_mode_t s_current_mode = LED_STATE_SCANNING;
|
|
static volatile uint8_t s_brightness = 100; /* Percentage 0-100 */
|
|
|
|
static void set_scaled_pixel(uint8_t r, uint8_t g, uint8_t b)
|
|
{
|
|
if (!s_led_strip) return;
|
|
uint32_t br = s_brightness;
|
|
uint8_t sr = (uint8_t)((r * br) / 100);
|
|
uint8_t sg = (uint8_t)((g * br) / 100);
|
|
uint8_t sb = (uint8_t)((b * br) / 100);
|
|
led_strip_set_pixel(s_led_strip, 0, sr, sg, sb);
|
|
}
|
|
|
|
static void status_led_task(void *pvParameters)
|
|
{
|
|
uint32_t step = 0;
|
|
while (1) {
|
|
if (!s_led_strip) {
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
continue;
|
|
}
|
|
|
|
switch (s_current_mode) {
|
|
case LED_STATE_SCANNING:
|
|
/* Yellow flash: 200ms on, 200ms off */
|
|
if ((step % 2) == 0) {
|
|
set_scaled_pixel(30, 25, 0); // Dim yellow
|
|
} else {
|
|
led_strip_clear(s_led_strip);
|
|
}
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(200));
|
|
break;
|
|
|
|
case LED_STATE_CONFIG_PORTAL:
|
|
/* Config Mode: Pulsating Magenta / Violet (250ms cadence) */
|
|
if ((step % 2) == 0) {
|
|
set_scaled_pixel(35, 0, 35);
|
|
} else {
|
|
set_scaled_pixel(6, 0, 6);
|
|
}
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(250));
|
|
break;
|
|
|
|
case LED_STATE_SWITCH_MODE:
|
|
/* Nintendo Switch: Solid Cyan / Joy-Con Teal */
|
|
set_scaled_pixel(0, 25, 25);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
break;
|
|
|
|
case LED_STATE_PC_MODE:
|
|
/* PC DirectInput: Solid Blue */
|
|
set_scaled_pixel(0, 0, 30);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
break;
|
|
|
|
case LED_STATE_PS3_MODE:
|
|
/* PS3: Solid Red */
|
|
set_scaled_pixel(30, 0, 0);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
break;
|
|
|
|
case LED_STATE_XBOX360_MODE:
|
|
/* Xbox 360: Solid Emerald Green */
|
|
set_scaled_pixel(0, 35, 0);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
break;
|
|
|
|
case LED_STATE_XBOXOG_MODE:
|
|
/* Original Xbox: Solid Amber / Warm Orange */
|
|
set_scaled_pixel(35, 12, 0);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
break;
|
|
|
|
case LED_STATE_PS4_MODE:
|
|
/* PlayStation 4: Solid DualShock 4 Royal Blue */
|
|
set_scaled_pixel(0, 10, 45);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
break;
|
|
|
|
case LED_STATE_MOUSE_KB_MODE:
|
|
/* Couch Mouse & Keyboard: Solid Turquoise / Teal */
|
|
set_scaled_pixel(0, 35, 30);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
break;
|
|
|
|
case LED_STATE_MODE_SWITCHING:
|
|
/* White fast flash */
|
|
set_scaled_pixel(40, 40, 40);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
led_strip_clear(s_led_strip);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
break;
|
|
|
|
case LED_STATE_OFF:
|
|
default:
|
|
led_strip_clear(s_led_strip);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
break;
|
|
}
|
|
step++;
|
|
}
|
|
}
|
|
|
|
esp_err_t status_led_init(void)
|
|
{
|
|
led_strip_config_t strip_config = {
|
|
.strip_gpio_num = BOARD_RGB_LED_GPIO,
|
|
.max_leds = 1,
|
|
};
|
|
led_strip_rmt_config_t rmt_config = {
|
|
.resolution_hz = 10 * 1000 * 1000, /* 10MHz */
|
|
.flags.with_dma = false,
|
|
};
|
|
|
|
esp_err_t err = led_strip_new_rmt_device(&strip_config, &rmt_config, &s_led_strip);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "Failed to initialize WS2812 on GPIO%d: %s", BOARD_RGB_LED_GPIO, esp_err_to_name(err));
|
|
return err;
|
|
}
|
|
|
|
led_strip_clear(s_led_strip);
|
|
led_strip_refresh(s_led_strip);
|
|
|
|
/* Pin WS2812 RMT animation engine to Core 1 */
|
|
xTaskCreatePinnedToCore(status_led_task, "status_led_task", 2048, NULL, 3, NULL, 1);
|
|
ESP_LOGI(TAG, "WS2812 RGB LED initialized on GPIO%d", BOARD_RGB_LED_GPIO);
|
|
return ESP_OK;
|
|
}
|
|
|
|
void status_led_set_mode(led_status_mode_t mode)
|
|
{
|
|
s_current_mode = mode;
|
|
}
|
|
|
|
void status_led_set_brightness(uint8_t percent)
|
|
{
|
|
if (percent > 100) percent = 100;
|
|
s_brightness = percent;
|
|
}
|
|
|
|
uint8_t status_led_get_brightness(void)
|
|
{
|
|
return s_brightness;
|
|
}
|
|
|
|
void status_led_flash_color(uint8_t r, uint8_t g, uint8_t b, uint32_t duration_ms)
|
|
{
|
|
if (!s_led_strip) return;
|
|
set_scaled_pixel(r, g, b);
|
|
led_strip_refresh(s_led_strip);
|
|
vTaskDelay(pdMS_TO_TICKS(duration_ms));
|
|
}
|