src.nth.io/

summaryrefslogtreecommitdiff
path: root/main/button.c
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-06-14 16:41:03 -0500
committerLuke Hoersten <[email protected]>2026-06-14 16:41:03 -0500
commitc6ce4b3f46a1f1adf700306dadc9034a6a2ac0d3 (patch)
tree3bd6f0a3c2eea8b0095bd05549cae650fe166b40 /main/button.c
parent6c1a26bdae63d152caa45023e8255561a22fc0e2 (diff)
M3 done: drop boot test, fold BOOT button into touch long-press
The Waveshare ESP32-P4-ETH board exposes BOOT on GPIO 35, but at runtime that pin is owned by the EMAC TXD1 signal. No usable GPIO is wired to a separate user button, so the BOOT-button task could never fire. Move both BOOT-button behaviours onto the touch panel: - ≥1.5s hold → 15s identity overlay (was BOOT short-press) - ≥5s hold → factory reset (was BOOT long-hold) Short tap (<500ms) still toggles wake/sleep. Long-press fires while the finger is still down so the user gets immediate feedback at each threshold. Also strip the R/G/B 6 s boot test sequence — the panel now renders correctly, so it's no longer useful diagnostically. Boot subsystem flags drop the trailing B column: [EMHDJT].
Diffstat (limited to 'main/button.c')
-rw-r--r--main/button.c96
1 files changed, 0 insertions, 96 deletions
diff --git a/main/button.c b/main/button.c
deleted file mode 100644
index 26e7cff..0000000
--- a/main/button.c
+++ /dev/null
@@ -1,96 +0,0 @@
-#include "button.h"
-
-#include "driver/gpio.h"
-#include "esp_log.h"
-#include "esp_system.h"
-#include "esp_timer.h"
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-
-#include "display.h"
-#include "local_screens.h"
-#include "nvs_config.h"
-
-static const char *TAG = "button";
-
-// TODO confirm against the Waveshare ESP32-P4-ETH schematic. ESP32-P4's
-// strapping pin is GPIO35 but that's owned by RMII TXD1 at runtime. Most
-// Waveshare ESP32-P4 boards expose an additional user/BOOT button on a
-// free GPIO; GPIO0 is the conventional default if a separate button isn't
-// available. The button task fail-soft: if the pin reads stuck-high (no
-// button), it just never fires.
-#define PIN_BOOT_BUTTON 0
-
-#define POLL_PERIOD_MS 30
-#define LONG_HOLD_MS 5000
-#define OVERLAY_MS 15000
-
-static void start_overlay(void)
-{
- if (!display_is_up()) return;
- local_screens_overlay(OVERLAY_MS);
- ESP_LOGI(TAG, "BOOT short-press → identity overlay for %dms", OVERLAY_MS);
-}
-
-static void factory_reset(void)
-{
- ESP_LOGW(TAG, "BOOT held %dms → factory reset", LONG_HOLD_MS);
- nvs_config_reset();
- vTaskDelay(pdMS_TO_TICKS(200)); // let log flush
- esp_restart();
-}
-
-static void button_task(void *arg)
-{
- bool was_pressed = false;
- uint64_t press_started = 0;
- bool long_fired = false;
-
- for (;;) {
- vTaskDelay(pdMS_TO_TICKS(POLL_PERIOD_MS));
-
- bool pressed = (gpio_get_level(PIN_BOOT_BUTTON) == 0); // active-low
-
- if (pressed && !was_pressed) {
- press_started = (uint64_t)esp_timer_get_time();
- long_fired = false;
- was_pressed = true;
- } else if (pressed && was_pressed) {
- uint64_t held_ms = ((uint64_t)esp_timer_get_time() - press_started) / 1000ULL;
- if (!long_fired && held_ms >= LONG_HOLD_MS) {
- long_fired = true;
- factory_reset(); // does not return
- }
- } else if (!pressed && was_pressed) {
- uint64_t held_ms = ((uint64_t)esp_timer_get_time() - press_started) / 1000ULL;
- was_pressed = false;
- if (!long_fired && held_ms < LONG_HOLD_MS) {
- start_overlay();
- }
- }
- }
-}
-
-esp_err_t button_init(void)
-{
- gpio_config_t cfg = {
- .pin_bit_mask = 1ULL << PIN_BOOT_BUTTON,
- .mode = GPIO_MODE_INPUT,
- .pull_up_en = GPIO_PULLUP_ENABLE,
- .pull_down_en = GPIO_PULLDOWN_DISABLE,
- .intr_type = GPIO_INTR_DISABLE,
- };
- esp_err_t err = gpio_config(&cfg);
- if (err != ESP_OK) {
- ESP_LOGW(TAG, "gpio_config GPIO%d failed: %s — button disabled",
- PIN_BOOT_BUTTON, esp_err_to_name(err));
- return err;
- }
-
- BaseType_t ok = xTaskCreate(button_task, "boot_btn", 3072, NULL, 3, NULL);
- if (ok != pdPASS) return ESP_FAIL;
-
- ESP_LOGI(TAG, "BOOT button on GPIO%d (short=IP overlay 15s, hold 5s=factory reset)",
- PIN_BOOT_BUTTON);
- return ESP_OK;
-}