From b52fe53e3bd791419b99f48abaaf54f7e597bdb9 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 5 May 2024 02:45:37 +0200 Subject: [PATCH] ESP32: emulation heartbeat --- ESP32/console_esp32.cpp | 19 +++++++++++++++++-- ESP32/esp32.h | 3 +++ ESP32/main.ino | 13 ++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/ESP32/console_esp32.cpp b/ESP32/console_esp32.cpp index 1d99941..f63c22f 100644 --- a/ESP32/console_esp32.cpp +++ b/ESP32/console_esp32.cpp @@ -61,11 +61,11 @@ void console_esp32::refresh_virtual_terminal() void console_esp32::panel_update_thread() { -#if !defined(BUILD_FOR_RP2040) && defined(NEOPIXELS_PIN) Serial.println(F("panel task started")); cpu *const c = b->getCpu(); +#if !defined(BUILD_FOR_RP2040) && defined(NEOPIXELS_PIN) constexpr const uint8_t n_leds = 60; Adafruit_NeoPixel pixels(n_leds, NEOPIXELS_PIN, NEO_RGBW); pixels.begin(); @@ -142,7 +142,22 @@ void console_esp32::panel_update_thread() pixels.clear(); pixels.show(); +#elif defined(HEARTBEAT_PIN) + uint64_t prev_count = 0; + bool led_state = true; + + while(!stop_panel) { + vTaskDelay(333 / portTICK_PERIOD_MS); + + uint64_t current_count = c->get_instructions_executed_count(); + if (prev_count != current_count) { + prev_count = current_count; + + digitalWrite(HEARTBEAT_PIN, led_state ? HIGH : LOW); + led_state = !led_state; + } + } +#endif Serial.println(F("panel task terminating")); -#endif } diff --git a/ESP32/esp32.h b/ESP32/esp32.h index 39e0813..4aa43e1 100644 --- a/ESP32/esp32.h +++ b/ESP32/esp32.h @@ -15,5 +15,8 @@ // #define NEOPIXELS_PIN 24 +#define HEARTBEAT_PIN LED_BUILTIN +// #define HEARTBEAT_PIN 18 + // #define CONSOLE_SERIAL_RX 16 // #define CONSOLE_SERIAL_TX 17 diff --git a/ESP32/main.ino b/ESP32/main.ino index 172a5e8..c3703e6 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -343,7 +343,14 @@ void setup() { tty_ = new tty(cnsl, b); b->add_tty(tty_); -#if !defined(BUILD_FOR_RP2040) && defined(NEOPIXELS_PIN) +#if !defined(SHA2017) + pinMode(LED_BUILTIN, OUTPUT); +#endif +#if defined(HEARTBEAT_PIN) + pinMode(HEARTBEAT_PIN, OUTPUT); +#endif + +#if !defined(BUILD_FOR_RP2040) && (defined(NEOPIXELS_PIN) || defined(HEARTBEAT_PIN)) Serial.println(F("Starting panel")); xTaskCreate(&console_thread_wrapper_panel, "panel", 3072, cnsl, 1, nullptr); #endif @@ -354,10 +361,6 @@ void setup() { Serial.println(F("")); #endif -#if !defined(SHA2017) - pinMode(LED_BUILTIN, OUTPUT); -#endif - Serial.flush(); Serial.println(F("* Starting console"));