Skip to content

Commit 0c70c71

Browse files
author
vistalba
committed
C6L: Integrate UIColor framework, add variant README, improve comments
1 parent 116c881 commit 0c70c71

5 files changed

Lines changed: 110 additions & 17 deletions

File tree

src/helpers/ui/DisplayDriver.h

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
#include <stdint.h>
44
#include <string.h>
55

6+
// MarqueeScroller: Handles text scrolling for small displays (e.g., 64x48 OLED)
7+
// Used by companion radio UI to display long messages that don't fit on screen
68
struct MarqueeScroller {
7-
int offset = 0;
8-
unsigned long next_time = 0;
9-
bool paused = true;
9+
int offset = 0; // Current scroll offset in pixels
10+
unsigned long next_time = 0; // Next scroll update time (millis)
11+
bool paused = true; // Scroll paused state
1012

13+
// Reset scroller to initial state
1114
void reset() {
1215
offset = 0;
1316
next_time = 0;
1417
paused = true;
1518
}
1619

17-
// Call once per loop iteration to advance the scroll.
18-
// textW/displayW in pixels, now = millis().
20+
// Update scroll position - call once per loop iteration
21+
// Parameters:
22+
// textW - width of text in pixels
23+
// displayW - width of display in pixels
24+
// now - current time from millis()
25+
// speed_ms - milliseconds between scroll steps (default: 150ms)
26+
// pause_ms - milliseconds to pause before scrolling starts (default: 2000ms)
1927
void update(int textW, int displayW, unsigned long now,
2028
unsigned long speed_ms = 150, unsigned long pause_ms = 2000) {
2129
int maxScroll = textW - displayW;
@@ -35,13 +43,32 @@ struct MarqueeScroller {
3543
}
3644
};
3745

46+
// UIColor framework: Provides consistent color definitions across different display types
47+
// Each display driver defines its own UIColor values based on its color capabilities
48+
// For monochrome displays: 0 = BLACK, 1 = WHITE
49+
// For color displays: 16-bit RGB values
50+
using ColorVal = uint16_t;
51+
52+
class UIColor {
53+
public:
54+
// UI element color definitions
55+
// Each display driver implements these with appropriate values for its display
56+
static ColorVal window_bkg; // Background color for windows/panels
57+
static ColorVal title_bkg; // Background color for title bars
58+
static ColorVal title_txt; // Text color for titles
59+
static ColorVal primary_txt; // Primary text color (main content)
60+
static ColorVal secondary_txt; // Secondary text color (metadata, timestamps)
61+
static ColorVal warning_txt; // Warning/alert text color
62+
static ColorVal popup_bkg; // Background color for popups/dialogs
63+
static ColorVal popup_txt; // Text color for popups/dialogs
64+
static ColorVal corp_blue; // Corporate/brand color (blue)
65+
};
66+
3867
class DisplayDriver {
3968
int _w, _h;
4069
protected:
4170
DisplayDriver(int w, int h) { _w = w; _h = h; }
4271
public:
43-
enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light
44-
4572
int width() const { return _w; }
4673
int height() const { return _h; }
4774

@@ -50,9 +77,9 @@ class DisplayDriver {
5077
virtual void turnOn() = 0;
5178
virtual void turnOff() = 0;
5279
virtual void clear() = 0;
53-
virtual void startFrame(Color bkg = DARK) = 0;
80+
virtual void startFrame(ColorVal bkg = UIColor::window_bkg) = 0;
5481
virtual void setTextSize(int sz) = 0;
55-
virtual void setColor(Color c) = 0;
82+
virtual void setColor(ColorVal c) = 0;
5683
virtual void setCursor(int x, int y) = 0;
5784
virtual void print(const char* str) = 0;
5885
virtual void printWordWrap(const char* str, int max_width) { print(str); } // fallback to basic print() if no override
@@ -83,7 +110,7 @@ class DisplayDriver {
83110
if (c >= 32 && c <= 126) {
84111
dest[j++] = c; // ASCII printable
85112
} else if (c >= 0x80) {
86-
dest[j++] = '\xDB'; // CP437 full block ¦
113+
dest[j++] = '\xDB'; // CP437 full block
87114
while (src[i+1] && (src[i+1] & 0xC0) == 0x80)
88115
i++; // skip UTF-8 continuation bytes
89116
}

src/helpers/ui/SSD1306SPIDisplay.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#include "SSD1306SPIDisplay.h"
22

3+
// UIColor definitions for 64x48 OLED (black/white display)
4+
ColorVal UIColor::window_bkg = 0; // BLACK
5+
ColorVal UIColor::title_bkg = 0; // BLACK
6+
ColorVal UIColor::title_txt = 1; // WHITE
7+
ColorVal UIColor::primary_txt = 1; // WHITE
8+
ColorVal UIColor::secondary_txt = 1; // WHITE
9+
ColorVal UIColor::warning_txt = 1; // WHITE
10+
ColorVal UIColor::popup_bkg = 0; // BLACK
11+
ColorVal UIColor::popup_txt = 1; // WHITE
12+
ColorVal UIColor::corp_blue = 1; // WHITE (B/W display)
13+
314
// Check if SPI is ready (set by radio_init in target.cpp)
415
#if defined(P_LORA_SCLK)
516
extern bool spi_initialized;
@@ -67,10 +78,10 @@ void SSD1306SPIDisplay::clear() {
6778
display.display();
6879
}
6980

70-
void SSD1306SPIDisplay::startFrame(Color bkg) {
81+
void SSD1306SPIDisplay::startFrame(ColorVal bkg) {
7182
if (!lazyInit()) return;
7283
display.clearDisplay(); // TODO: apply 'bkg'
73-
_color = SSD1306_WHITE;
84+
_color = 1; // WHITE
7485
display.setTextColor(_color);
7586
display.setFont(NULL); // Default 6x8 font
7687
display.setTextSize(1);
@@ -82,8 +93,8 @@ void SSD1306SPIDisplay::setTextSize(int sz) {
8293
display.setTextSize(sz);
8394
}
8495

85-
void SSD1306SPIDisplay::setColor(Color c) {
86-
_color = (c != 0) ? SSD1306_WHITE : SSD1306_BLACK;
96+
void SSD1306SPIDisplay::setColor(ColorVal c) {
97+
_color = (c != 0) ? 1 : 0; // WHITE or BLACK
8798
display.setTextColor(_color);
8899
}
89100

src/helpers/ui/SSD1306SPIDisplay.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class SSD1306SPIDisplay : public DisplayDriver {
2525
void turnOn() override;
2626
void turnOff() override;
2727
void clear() override;
28-
void startFrame(Color bkg = DARK) override;
28+
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
2929
void setTextSize(int sz) override;
30-
void setColor(Color c) override;
30+
void setColor(ColorVal c) override;
3131
void setCursor(int x, int y) override;
3232
void print(const char* str) override;
3333
void fillRect(int x, int y, int w, int h) override;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# M5Stack Unit C6L - MeshCore Variant
2+
3+
## Overview
4+
5+
Compact ESP32-C6 LoRa module with integrated SX1262 radio, 64x48 OLED display, and PI4IO I/O expander.
6+
7+
## Hardware
8+
9+
- **MCU:** ESP32-C6 (WiFi 6 + Bluetooth 5 LE)
10+
- **LoRa:** SX1262 (SPI)
11+
- **Display:** 64x48 SSD1306 OLED (SPI)
12+
- **I/O Expander:** PI4IO (I2C)
13+
- **LED:** NeoPixel (GPIO 2)
14+
- **Buzzer:** GPIO 11
15+
16+
## Pin Configuration
17+
18+
| Function | GPIO |
19+
|----------|------|
20+
| LoRa SCLK | 20 |
21+
| LoRa MISO | 22 |
22+
| LoRa MOSI | 21 |
23+
| LoRa NSS | 23 |
24+
| LoRa DIO1 | 7 |
25+
| Display CS | 6 |
26+
| Display DC | 18 |
27+
| Display RST | 15 |
28+
| I2C SDA | 10 |
29+
| I2C SCL | 8 |
30+
| NeoPixel | 2 |
31+
| Buzzer | 11 |
32+
| GPS RX | 4 |
33+
| GPS TX | 5 |
34+
35+
## Firmware Environments
36+
37+
| Environment | Interface | Use Case |
38+
|-------------|-----------|----------|
39+
| `m5stack_unit_c6l_companion_radio_usb` | USB Serial | Connect via USB |
40+
| `m5stack_unit_c6l_companion_radio_ble` | BLE | Connect via Bluetooth |
41+
| `m5stack_unit_c6l_repeater` | LoRa | Network extender |
42+
| `m5stack_unit_c6l_room_server` | LoRa | BBS server |
43+
| `m5stack_unit_c6l_kiss_modem` | USB Serial | KISS TNC |
44+
45+
## Build
46+
47+
```bash
48+
pio run -e m5stack_unit_c6l_companion_radio_usb
49+
```
50+
51+
## Resources
52+
53+
- [M5Stack Unit C6L Product Page](https://docs.m5stack.com/en/unit/Unit_C6L)
54+
- [MeshCore Documentation](https://docs.meshcore.io)

variants/m5stack_unit_c6l/companion/UITask.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#include <Arduino.h>
44
#include <helpers/ui/DisplayDriver.h>
55
#include <helpers/SensorManager.h>
6+
#include <helpers/MultiSerialInterface.h>
67
#include "../../examples/companion_radio/NodePrefs.h"
78
#include "../../examples/companion_radio/AbstractUITask.h"
89

910
class UITask : public AbstractUITask {
1011
public:
11-
UITask(mesh::MainBoard* board, BaseSerialInterface* serial)
12+
UITask(mesh::MainBoard* board, MultiSerialInterface* serial)
1213
: AbstractUITask(board, serial), _display(NULL) {}
1314

1415
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);

0 commit comments

Comments
 (0)