Skip to content

Commit 0b7848d

Browse files
logging: send to console on uCs / LED control
1 parent e907968 commit 0b7848d

10 files changed

Lines changed: 75 additions & 31 deletions

File tree

ESP32/console_esp32.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
console_esp32::console_esp32(kek_event_t *const stop_event, comm *const io_port, const int t_width, const int t_height) :
2727
console_comm(stop_event, io_port, t_width, t_height)
2828
{
29+
#if defined(WAVESHARE_S3_ETH)
30+
rgb_led.begin();
31+
rgb_led.setBrightness(50);
32+
#endif
2933
}
3034

3135
console_esp32::~console_esp32()
@@ -188,22 +192,24 @@ void console_esp32::panel_update_thread()
188192

189193
pixels.clear();
190194
pixels.show();
191-
#elif defined(HEARTBEAT_PIN) && !defined(WAVESHARE_S3_ETH)
192-
uint64_t prev_count = 0;
193-
bool led_state = true;
194-
195-
while(!stop_panel) {
196-
vTaskDelay(333 / portTICK_PERIOD_MS);
195+
#endif
197196

198-
uint64_t current_count = c->get_trap_counter();
199-
if (prev_count != current_count) {
200-
prev_count = current_count;
197+
DOLOG(info, false, "panel task terminating");
198+
}
201199

202-
digitalWrite(HEARTBEAT_PIN, led_state ? HIGH : LOW);
203-
led_state = !led_state;
204-
}
205-
}
200+
void console_esp32::set_LED_state(const bool state)
201+
{
202+
#if defined(WAVESHARE_S3_ETH)
203+
uint8_t brightness = state ? 255 : 0;
204+
rgb_led.setPixelColor(0, brightness, brightness, brightness);
205+
rgb_led.show();
206+
#else
207+
digitalWrite(HEARTBEAT_PIN, state);
206208
#endif
209+
prev_led_state = state;
210+
}
207211

208-
DOLOG(info, false, "panel task terminating");
212+
void console_esp32::toggle_LED_state()
213+
{
214+
set_LED_state(!prev_led_state);
209215
}

ESP32/console_esp32.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// (C) 2018-2026 by Folkert van Heusden
22
// Released under MIT license
33

4+
#if defined(WAVESHARE_S3_ETH)
5+
#include <Adafruit_NeoPixel.h>
6+
#endif
47
#include <vector>
58

69
#include "comm.h"
@@ -9,6 +12,12 @@
912

1013
class console_esp32 : public console_comm
1114
{
15+
private:
16+
#if defined(WAVESHARE_S3_ETH)
17+
Adafruit_NeoPixel rgb_led { Adafruit_NeoPixel(1, 21, NEO_GRB + NEO_KHZ800) };
18+
#endif
19+
bool prev_led_state { false };
20+
1221
protected:
1322
int wait_for_char_ll(const short timeout) override;
1423
void put_char_ll (const char c) override;
@@ -17,13 +26,13 @@ class console_esp32 : public console_comm
1726
console_esp32(kek_event_t *const stop_event, comm *const io_port, const int t_width, const int t_height);
1827
virtual ~console_esp32();
1928

20-
void set_panel_mode(const panel_mode_t pm);
21-
2229
void put_string_lf(const std::string & what) override;
2330

2431
void resize_terminal() override;
25-
2632
void refresh_virtual_terminal() override;
2733

34+
void set_panel_mode(const panel_mode_t pm);
2835
void panel_update_thread() override;
36+
void set_LED_state (const bool state) override;
37+
void toggle_LED_state( ) override;
2938
};

ESP32/main.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ void setup() {
517517
#endif
518518
cnsl->set_bus(b);
519519
cnsl->begin();
520+
c->set_console(cnsl);
521+
522+
set_terminal(cnsl);
523+
DOLOG(info, true, "Logging enabled");
520524

521525
running = cnsl->get_running_flag();
522526

console.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void console::put_char(const char c)
218218
else if (c == 13)
219219
tx = 0;
220220
else if (c == 10) {
221-
if (debug_buffer.empty() == false) {
221+
if (debug_buffer.empty() == false && is_terminal_set() == false) {
222222
DOLOG(debug, false, "TTY: %s", debug_buffer.c_str());
223223
debug_buffer.clear();
224224
}
@@ -304,3 +304,11 @@ void console::set_blinkenlights_panel(blinkenlights *const p_blinkenlights)
304304
{
305305
this->p_blinkenlights = p_blinkenlights;
306306
}
307+
308+
void console::set_LED_state(const bool state)
309+
{
310+
}
311+
312+
void console::toggle_LED_state()
313+
{
314+
}

console.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,7 @@ class console
106106
virtual void panel_update_thread() = 0;
107107
int get_refreshrate( ) const { return refreshrate; }
108108
void set_refreshrate(const int rate) { refreshrate = rate; }
109+
110+
virtual void set_LED_state (const bool state);
111+
virtual void toggle_LED_state();
109112
};

cpu.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,18 @@ void cpu::execute_any_pending_interrupt()
342342
auto vector = queued_interrupts[i].begin();
343343
uint16_t v = *vector;
344344
queued_interrupts[i].erase(vector);
345-
#if defined(ESP32)
346-
if (v == 0100) { // 50 Hz interrupt
347-
if (++kw11l_counter >= 25) {
348-
kw11l_counter = 0;
349-
digitalWrite(HEARTBEAT_PIN, !digitalRead(HEARTBEAT_PIN));
345+
346+
if (cnsl) {
347+
if (v == 0100) { // 50 Hz interrupt
348+
if (++kw11l_counter >= 25) {
349+
kw11l_counter = 0;
350+
cnsl->toggle_LED_state();
351+
}
352+
}
353+
else {
354+
cnsl->toggle_LED_state();
350355
}
351356
}
352-
else {
353-
digitalWrite(HEARTBEAT_PIN, !digitalRead(HEARTBEAT_PIN));
354-
}
355-
#endif
356357

357358
TRACE("Invoking interrupt vector %o (IPL %d, current: %d)", v, i, current_level);
358359
trap(v, i, true);

cpu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class cpu
7979
mmu *const mmu_ { nullptr };
8080

8181
kek_event_t *const event { nullptr };
82+
console *cnsl { nullptr };
8283

8384
bool check_pending_interrupts() const; // needs the 'qi_lock'-lock
8485
void execute_any_pending_interrupt();
@@ -120,6 +121,8 @@ class cpu
120121
explicit cpu(bus *const b, kek_event_t *const event);
121122
~cpu();
122123

124+
void set_console(console *const cnsl) { this->cnsl = cnsl; }
125+
123126
JsonDocument serialize();
124127
static cpu *deserialize(const JsonVariantConst j, bus *const b, kek_event_t *const event);
125128

debugger.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,13 +1383,17 @@ bool debugger_do(debugger_state *const state, console *const cnsl, bus *const b,
13831383
if (false) {
13841384
}
13851385
#if !defined(WAVESHARE_S3_ETH)
1386-
if (!network_configured)
1386+
else if (!network_configured)
13871387
cnsl->put_string_lf("Please configure network first (cfgnet)");
13881388
#endif
1389-
else if (dev->begin())
1389+
else if (dev->begin()) {
13901390
b->add_DEQNA(new deqna(b, mac, dev));
1391-
else
1391+
cnsl->put_string_lf("DEQNA emulation initialized");
1392+
}
1393+
else {
13921394
delete dev;
1395+
cnsl->put_string_lf("DEQNA emulation initialization failed");
1396+
}
13931397
}
13941398

13951399
return true;
@@ -1681,7 +1685,7 @@ void debugger(console *const cnsl, bus *const b, kek_event_t *const stop_event,
16811685
if (state.marker)
16821686
cnsl->put_string_lf("---");
16831687

1684-
std::string cmd = cnsl->read_line(format("%d", int(*stop_event)));
1688+
std::string cmd = cnsl->read_line(std::to_string(int(*stop_event)));
16851689

16861690
if (debugger_do(&state, cnsl, b, stop_event, cmd) == false)
16871691
break;

log.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ void set_terminal(console *const cnsl)
7777
log_cnsl = cnsl;
7878
}
7979

80+
bool is_terminal_set()
81+
{
82+
return log_cnsl;
83+
}
84+
8085
void settrace(const bool on)
8186
{
8287
log_trace_enabled = on;

log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ bool gettrace();
2626
void set_clock_reference(const char *const ntp_server);
2727
#endif
2828
void set_terminal(console *const cnsl);
29+
bool is_terminal_set();
2930

3031
#ifdef TURBO
3132
#define DOLOG(ll, always, fmt, ...) do { } while(0)

0 commit comments

Comments
 (0)