Skip to content

Commit e417c43

Browse files
committed
wireless paper board support
1 parent ba34cff commit e417c43

File tree

6 files changed

+312
-2
lines changed

6 files changed

+312
-2
lines changed

src/helpers/HeltecV3Board.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <helpers/RefCountedDigitalPin.h>
55

66
// LoRa radio module pins for Heltec V3
7-
// Also for Heltec Wireless Tracker
7+
// Also for Heltec Wireless Tracker/Paper
88
#define P_LORA_DIO_1 14
99
#define P_LORA_NSS 8
1010
#define P_LORA_RESET RADIOLIB_NC
@@ -14,7 +14,9 @@
1414
#define P_LORA_MOSI 10
1515

1616
// built-ins
17-
#define PIN_VBAT_READ 1
17+
#ifndef PIN_VBAT_READ // set in platformio.ini for boards like Heltec Wireless Paper (20)
18+
#define PIN_VBAT_READ 1
19+
#endif
1820
#ifndef PIN_ADC_CTRL // set in platformio.ini for Heltec Wireless Tracker (2)
1921
#define PIN_ADC_CTRL 37
2022
#endif

src/helpers/ui/E213Display.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#include "E213Display.h"
2+
#include "../../MeshCore.h"
3+
4+
bool E213Display::begin() {
5+
if (_init) return true;
6+
7+
powerOn();
8+
display.begin();
9+
10+
// Set to landscape mode rotated 180 degrees
11+
display.setRotation(3);
12+
13+
_init = true;
14+
_isOn = true;
15+
16+
clear();
17+
display.fastmodeOn(); // Enable fast mode for quicker (partial) updates
18+
19+
return true;
20+
}
21+
22+
void E213Display::powerOn() {
23+
#ifdef PIN_VEXT_EN
24+
pinMode(PIN_VEXT_EN, OUTPUT);
25+
digitalWrite(PIN_VEXT_EN, LOW); // Active low
26+
delay(50); // Allow power to stabilize
27+
#endif
28+
}
29+
30+
void E213Display::powerOff() {
31+
#ifdef PIN_VEXT_EN
32+
digitalWrite(PIN_VEXT_EN, HIGH); // Turn off power
33+
#endif
34+
}
35+
36+
void E213Display::turnOn() {
37+
if (!_init) begin();
38+
powerOn();
39+
_isOn = true;
40+
}
41+
42+
void E213Display::turnOff() {
43+
powerOff();
44+
_isOn = false;
45+
}
46+
47+
void E213Display::clear() {
48+
display.clear();
49+
}
50+
51+
void E213Display::startFrame(Color bkg) {
52+
// Fill screen with white first to ensure clean background
53+
display.fillRect(0, 0, width(), height(), WHITE);
54+
if (bkg == LIGHT) {
55+
// Fill with black if light background requested (inverted for e-ink)
56+
display.fillRect(0, 0, width(), height(), BLACK);
57+
}
58+
}
59+
60+
void E213Display::setTextSize(int sz) {
61+
// The library handles text size internally
62+
display.setTextSize(sz);
63+
}
64+
65+
void E213Display::setColor(Color c) {
66+
// implemented in individual display methods
67+
}
68+
69+
void E213Display::setCursor(int x, int y) {
70+
display.setCursor(x, y);
71+
}
72+
73+
void E213Display::print(const char* str) {
74+
display.print(str);
75+
}
76+
77+
void E213Display::fillRect(int x, int y, int w, int h) {
78+
display.fillRect(x, y, w, h, BLACK);
79+
}
80+
81+
void E213Display::drawRect(int x, int y, int w, int h) {
82+
display.drawRect(x, y, w, h, BLACK);
83+
}
84+
85+
void E213Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
86+
// Width in bytes for bitmap processing
87+
uint16_t widthInBytes = (w + 7) / 8;
88+
89+
// Process the bitmap row by row
90+
for (int by = 0; by < h; by++) {
91+
// Scan across the row bit by bit
92+
for (int bx = 0; bx < w; bx++) {
93+
// Get the current bit using MSB ordering (like GxEPDDisplay)
94+
uint16_t byteOffset = (by * widthInBytes) + (bx / 8);
95+
uint8_t bitMask = 0x80 >> (bx & 7);
96+
bool bitSet = bits[byteOffset] & bitMask;
97+
98+
// If the bit is set, draw the pixel
99+
if (bitSet) {
100+
display.drawPixel(x + bx, y + by, BLACK);
101+
}
102+
}
103+
}
104+
}
105+
106+
uint16_t E213Display::getTextWidth(const char* str) {
107+
int16_t x1, y1;
108+
uint16_t w, h;
109+
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
110+
return w;
111+
}
112+
113+
void E213Display::endFrame() {
114+
display.update();
115+
}
116+

src/helpers/ui/E213Display.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
3+
#include <SPI.h>
4+
#include <Wire.h>
5+
#include <heltec-eink-modules.h>
6+
#include "DisplayDriver.h"
7+
8+
// Display driver for E213 e-ink display
9+
class E213Display : public DisplayDriver {
10+
EInkDisplay_VisionMasterE213 display;
11+
bool _init = false;
12+
bool _isOn = false;
13+
14+
public:
15+
E213Display() : DisplayDriver(250, 122) {
16+
}
17+
18+
bool begin();
19+
bool isOn() override { return _isOn; }
20+
void turnOn() override;
21+
void turnOff() override;
22+
void clear() override;
23+
void startFrame(Color bkg = DARK) override;
24+
void setTextSize(int sz) override;
25+
void setColor(Color c) override;
26+
void setCursor(int x, int y) override;
27+
void print(const char* str) override;
28+
void fillRect(int x, int y, int w, int h) override;
29+
void drawRect(int x, int y, int w, int h) override;
30+
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
31+
uint16_t getTextWidth(const char* str) override;
32+
void endFrame() override;
33+
34+
private:
35+
void powerOn();
36+
void powerOff();
37+
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[Heltec_Wireless_Paper_base]
2+
extends = esp32_base
3+
board = esp32-s3-devkitc-1
4+
build_flags =
5+
${esp32_base.build_flags}
6+
-I variants/heltec_wireless_paper
7+
-D HELTEC_WIRELESS_PAPER
8+
-D RADIO_CLASS=CustomSX1262
9+
-D WRAPPER_CLASS=CustomSX1262Wrapper
10+
-D LORA_TX_POWER=22
11+
-D P_LORA_TX_LED=18
12+
; -D PIN_BOARD_SDA=17
13+
; -D PIN_BOARD_SCL=18
14+
-D PIN_USER_BTN=0
15+
-D PIN_VEXT_EN=45
16+
-D PIN_VBAT_READ=20
17+
-D PIN_ADC_CTRL=19
18+
-D SX126X_DIO2_AS_RF_SWITCH=true
19+
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
20+
-D SX126X_CURRENT_LIMIT=140
21+
-D SX126X_RX_BOOSTED_GAIN=1
22+
-D DISP_CS=4
23+
-D DISP_BUSY=7
24+
-D DISP_DC=5
25+
-D DISP_RST=6
26+
-D DISP_SCLK=3
27+
-D DISP_MOSI=2
28+
-D ARDUINO_heltec_wifi_lora_32_V3
29+
-D WIRELESS_PAPER
30+
build_src_filter = ${esp32_base.build_src_filter}
31+
+<../variants/heltec_wireless_paper>
32+
lib_deps =
33+
${esp32_base.lib_deps}
34+
todd-herbert/heltec-eink-modules @ 4.5.0
35+
36+
[env:Heltec_Wireless_Paper_companion_radio_ble]
37+
extends = Heltec_Wireless_Paper_base
38+
build_flags =
39+
${Heltec_Wireless_Paper_base.build_flags}
40+
-D MAX_CONTACTS=100
41+
-D MAX_GROUP_CHANNELS=8
42+
-D DISPLAY_CLASS=E213Display
43+
-D BLE_PIN_CODE=0 ; dynamic, random PIN
44+
-D BLE_DEBUG_LOGGING=1
45+
-D OFFLINE_QUEUE_SIZE=256
46+
build_src_filter = ${Heltec_Wireless_Paper_base.build_src_filter}
47+
+<helpers/ui/E213Display.cpp>
48+
+<helpers/esp32/*.cpp>
49+
+<../examples/companion_radio>
50+
lib_deps =
51+
${Heltec_Wireless_Paper_base.lib_deps}
52+
densaugeo/base64 @ ~1.4.0
53+
54+
[env:Heltec_Wireless_Paper_repeater]
55+
extends = Heltec_Wireless_Paper_base
56+
build_flags =
57+
${Heltec_Wireless_Paper_base.build_flags}
58+
-D DISPLAY_CLASS=E213Display
59+
-D ADVERT_NAME='"Heltec WP Repeater"'
60+
-D ADVERT_LAT=0.0
61+
-D ADVERT_LON=0.0
62+
build_src_filter = ${Heltec_Wireless_Paper_base.build_src_filter}
63+
+<helpers/ui/E213Display.cpp>
64+
+<../examples/simple_repeater>
65+
lib_deps =
66+
${Heltec_Wireless_Paper_base.lib_deps}
67+
${esp32_ota.lib_deps}
68+
69+
[env:Heltec_Wireless_Paper_room_server]
70+
extends = Heltec_Wireless_Paper_base
71+
build_flags =
72+
${Heltec_Wireless_Paper_base.build_flags}
73+
-D DISPLAY_CLASS=E213Display
74+
-D ADVERT_NAME='"Heltec WP Room"'
75+
-D ADVERT_LAT=0.0
76+
-D ADVERT_LON=0.0
77+
-D ADMIN_PASSWORD='"password"'
78+
-D ROOM_PASSWORD='"hello"'
79+
build_src_filter = ${Heltec_Wireless_Paper_base.build_src_filter}
80+
+<helpers/ui/E213Display.cpp>
81+
+<../examples/simple_room_server>
82+
lib_deps =
83+
${Heltec_Wireless_Paper_base.lib_deps}
84+
${esp32_ota.lib_deps}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <Arduino.h>
2+
#include "target.h"
3+
4+
HeltecV3Board board;
5+
6+
static SPIClass spi;
7+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
8+
9+
WRAPPER_CLASS radio_driver(radio, board);
10+
11+
ESP32RTCClock fallback_clock;
12+
AutoDiscoverRTCClock rtc_clock(fallback_clock);
13+
14+
SensorManager sensors;
15+
16+
#ifdef DISPLAY_CLASS
17+
DISPLAY_CLASS display;
18+
#endif
19+
20+
bool radio_init() {
21+
fallback_clock.begin();
22+
rtc_clock.begin(Wire);
23+
return radio.std_init(&spi);
24+
}
25+
26+
uint32_t radio_get_rng_seed() {
27+
return radio.random(0x7FFFFFFF);
28+
}
29+
30+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
31+
radio.setFrequency(freq);
32+
radio.setSpreadingFactor(sf);
33+
radio.setBandwidth(bw);
34+
radio.setCodingRate(cr);
35+
}
36+
37+
void radio_set_tx_power(uint8_t dbm) {
38+
radio.setOutputPower(dbm);
39+
}
40+
41+
mesh::LocalIdentity radio_new_identity() {
42+
RadioNoiseListener rng(radio);
43+
return mesh::LocalIdentity(&rng); // create new random identity
44+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#define RADIOLIB_STATIC_ONLY 1
4+
#include <RadioLib.h>
5+
#include <helpers/RadioLibWrappers.h>
6+
#include <helpers/HeltecV3Board.h>
7+
#include <helpers/CustomSX1262Wrapper.h>
8+
#include <helpers/AutoDiscoverRTCClock.h>
9+
#include <helpers/SensorManager.h>
10+
#ifdef DISPLAY_CLASS
11+
#include <helpers/ui/E213Display.h>
12+
#endif
13+
14+
extern HeltecV3Board board;
15+
extern WRAPPER_CLASS radio_driver;
16+
extern AutoDiscoverRTCClock rtc_clock;
17+
extern SensorManager sensors;
18+
19+
#ifdef DISPLAY_CLASS
20+
extern DISPLAY_CLASS display;
21+
#endif
22+
23+
bool radio_init();
24+
uint32_t radio_get_rng_seed();
25+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
26+
void radio_set_tx_power(uint8_t dbm);
27+
mesh::LocalIdentity radio_new_identity();

0 commit comments

Comments
 (0)