Settings: disable onboard LED
All checks were successful
ESP32 Build & Release / build (push) Successful in 1m16s
All checks were successful
ESP32 Build & Release / build (push) Successful in 1m16s
This commit is contained in:
57
main/board_led.c
Normal file
57
main/board_led.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "board_led.h"
|
||||
#include "hw_pins.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "nvs.h"
|
||||
|
||||
static const char *TAG = "board_led";
|
||||
static bool s_led_enabled = false;
|
||||
|
||||
esp_err_t board_led_init(void)
|
||||
{
|
||||
/* Configure GPIO */
|
||||
gpio_config_t io_conf = {
|
||||
.pin_bit_mask = (1ULL << HW_STATUS_LED_GPIO),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
gpio_config(&io_conf);
|
||||
|
||||
/* Load persisted preference from NVS (default: false / OFF) */
|
||||
nvs_handle_t h;
|
||||
if (nvs_open("mtg_cfg", NVS_READONLY, &h) == ESP_OK) {
|
||||
uint8_t val = 0;
|
||||
if (nvs_get_u8(h, "led_en", &val) == ESP_OK) {
|
||||
s_led_enabled = (val != 0);
|
||||
}
|
||||
nvs_close(h);
|
||||
}
|
||||
|
||||
gpio_set_level(HW_STATUS_LED_GPIO, s_led_enabled ? 1 : 0);
|
||||
ESP_LOGI(TAG, "Onboard status LED initialized on GPIO %d (state: %s)",
|
||||
HW_STATUS_LED_GPIO, s_led_enabled ? "ON" : "OFF");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool board_led_get_enabled(void)
|
||||
{
|
||||
return s_led_enabled;
|
||||
}
|
||||
|
||||
void board_led_set_enabled(bool enabled)
|
||||
{
|
||||
s_led_enabled = enabled;
|
||||
gpio_set_level(HW_STATUS_LED_GPIO, s_led_enabled ? 1 : 0);
|
||||
|
||||
/* Persist to NVS */
|
||||
nvs_handle_t h;
|
||||
if (nvs_open("mtg_cfg", NVS_READWRITE, &h) == ESP_OK) {
|
||||
nvs_set_u8(h, "led_en", enabled ? 1 : 0);
|
||||
nvs_commit(h);
|
||||
nvs_close(h);
|
||||
}
|
||||
ESP_LOGI(TAG, "Onboard status LED set to %s", enabled ? "ON" : "OFF");
|
||||
}
|
||||
Reference in New Issue
Block a user