Skip to content

Commit 602945f

Browse files
Quency-Dthebentern
andcommitted
Add the Heltec v4 expansion box. (#8539)
* Add the Heltec v4 expansion box. * Change heltec-v4-oled to heltec-v4. * Add touchscreen to I2C scanning. * Add reset and busy pins to the ST7789. * Ignore the touch interrupt pin and extend the sleep time to 1 hour. * Remove the default sleep function. --------- Co-authored-by: Ben Meadors <[email protected]>
1 parent b868279 commit 602945f

File tree

8 files changed

+187
-17
lines changed

8 files changed

+187
-17
lines changed

src/configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
250250
// -----------------------------------------------------------------------------
251251
#define FT6336U_ADDR 0x48
252252
#define CST328_ADDR 0x1A
253+
#define CHSC6X_ADDR 0x2E
253254

254255
// -----------------------------------------------------------------------------
255256
// RAK12035VB Soil Monitor (using RAK12023 up to 3 RAK12035 monitors can be connected)

src/detect/ScanI2C.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ class ScanI2C
8282
BHI260AP,
8383
BMM150,
8484
TSL2561,
85-
DRV2605
85+
DRV2605,
86+
BH1750,
87+
DA217,
88+
CHSC6X
8689
} DeviceType;
8790

8891
// typedef uint8_t DeviceAddress;

src/detect/ScanI2CTwoWire.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,26 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
485485
SCAN_SIMPLE_CASE(LTR390UV_ADDR, LTR390UV, "LTR390UV", (uint8_t)addr.address);
486486
SCAN_SIMPLE_CASE(PCT2075_ADDR, PCT2075, "PCT2075", (uint8_t)addr.address);
487487
SCAN_SIMPLE_CASE(CST328_ADDR, CST328, "CST328", (uint8_t)addr.address);
488-
SCAN_SIMPLE_CASE(LTR553ALS_ADDR, LTR553ALS, "LTR553ALS", (uint8_t)addr.address);
488+
SCAN_SIMPLE_CASE(CHSC6X_ADDR, CHSC6X, "CHSC6X", (uint8_t)addr.address);
489+
case LTR553ALS_ADDR:
490+
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x86), 1); // Part ID register
491+
if (registerValue == 0x92) { // LTR553ALS Part ID
492+
type = LTR553ALS;
493+
logFoundDevice("LTR553ALS", (uint8_t)addr.address);
494+
} else {
495+
// Test BH1750 - send power on command
496+
i2cBus->beginTransmission(addr.address);
497+
i2cBus->write(0x01); // Power On command
498+
uint8_t bh1750_error = i2cBus->endTransmission();
499+
if (bh1750_error == 0) {
500+
type = BH1750;
501+
logFoundDevice("BH1750", (uint8_t)addr.address);
502+
} else {
503+
LOG_INFO("Device found at address 0x%x was not able to be enumerated", (uint8_t)addr.address);
504+
}
505+
}
506+
break;
507+
489508
SCAN_SIMPLE_CASE(BHI260AP_ADDR, BHI260AP, "BHI260AP", (uint8_t)addr.address);
490509
SCAN_SIMPLE_CASE(SCD4X_ADDR, SCD4X, "SCD4X", (uint8_t)addr.address);
491510
SCAN_SIMPLE_CASE(BMM150_ADDR, BMM150, "BMM150", (uint8_t)addr.address);

src/graphics/TFTDisplay.cpp

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,57 @@ static LGFX *tft = nullptr;
422422

423423
#elif defined(ST7789_CS)
424424
#include <LovyanGFX.hpp> // Graphics and font library for ST7735 driver chip
425+
#ifdef HELTEC_V4_TFT
426+
#include "chsc6x.h"
427+
#include "lgfx/v1/Touch.hpp"
428+
namespace lgfx
429+
{
430+
inline namespace v1
431+
{
432+
class TOUCH_CHSC6X : public ITouch
433+
{
434+
public:
435+
TOUCH_CHSC6X(void)
436+
{
437+
_cfg.i2c_addr = TOUCH_SLAVE_ADDRESS;
438+
_cfg.x_min = 0;
439+
_cfg.x_max = 240;
440+
_cfg.y_min = 0;
441+
_cfg.y_max = 320;
442+
};
443+
444+
bool init(void) override
445+
{
446+
if (chsc6xTouch == nullptr) {
447+
chsc6xTouch = new chsc6x(&Wire1, TOUCH_SDA_PIN, TOUCH_SCL_PIN, TOUCH_INT_PIN, TOUCH_RST_PIN);
448+
}
449+
chsc6xTouch->chsc6x_init();
450+
return true;
451+
};
452+
453+
uint_fast8_t getTouchRaw(touch_point_t *tp, uint_fast8_t count) override
454+
{
455+
uint16_t raw_x, raw_y;
456+
if (chsc6xTouch->chsc6x_read_touch_info(&raw_x, &raw_y) == 0) {
457+
tp[0].x = 320 - 1 - raw_y;
458+
tp[0].y = 240 - 1 - raw_x;
459+
tp[0].size = 1;
460+
tp[0].id = 1;
461+
return 1;
462+
}
463+
tp[0].size = 0;
464+
return 0;
465+
};
425466

467+
void wakeup(void) override{};
468+
void sleep(void) override{};
469+
470+
private:
471+
chsc6x *chsc6xTouch = nullptr;
472+
};
473+
} // namespace v1
474+
} // namespace lgfx
475+
#endif
426476
class LGFX : public lgfx::LGFX_Device
427477
{
428478
lgfx::Panel_ST7789 _panel_instance;
@@ -431,6 +481,8 @@ class LGFX : public lgfx::LGFX_Device
431481
#if HAS_TOUCHSCREEN
432482
#if defined(T_WATCH_S3) || defined(ELECROW)
433483
lgfx::Touch_FT5x06 _touch_instance;
484+
#elif defined(HELTEC_V4_TFT)
485+
lgfx::TOUCH_CHSC6X _touch_instance;
434486
#else
435487
lgfx::Touch_GT911 _touch_instance;
436488
#endif
@@ -464,9 +516,9 @@ class LGFX : public lgfx::LGFX_Device
464516
{ // Set the display panel control.
465517
auto cfg = _panel_instance.config(); // Gets a structure for display panel settings.
466518

467-
cfg.pin_cs = ST7789_CS; // Pin number where CS is connected (-1 = disable)
468-
cfg.pin_rst = -1; // Pin number where RST is connected (-1 = disable)
469-
cfg.pin_busy = -1; // Pin number where BUSY is connected (-1 = disable)
519+
cfg.pin_cs = ST7789_CS; // Pin number where CS is connected (-1 = disable)
520+
cfg.pin_rst = ST7789_RESET; // Pin number where RST is connected (-1 = disable)
521+
cfg.pin_busy = ST7789_BUSY; // Pin number where BUSY is connected (-1 = disable)
470522

471523
// The following setting values ​​are general initial values ​​for each panel, so please comment out any
472524
// unknown items and try them.

src/mesh/NodeDB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ void NodeDB::installDefaultConfig(bool preserveKey = false)
653653
strncpy(config.network.ntp_server, "meshtastic.pool.ntp.org", 32);
654654

655655
#if (defined(T_DECK) || defined(T_WATCH_S3) || defined(UNPHONE) || defined(PICOMPUTER_S3) || defined(SENSECAP_INDICATOR) || \
656-
defined(ELECROW_PANEL)) && \
656+
defined(ELECROW_PANEL) || defined(HELTEC_V4_TFT)) && \
657657
HAS_TFT
658658
// switch BT off by default; use TFT programming mode or hotkey to enable
659659
config.bluetooth.enabled = false;

variants/esp32s3/heltec_v4/pins_arduino.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ static const uint8_t LED_BUILTIN = 35;
1313
static const uint8_t TX = 43;
1414
static const uint8_t RX = 44;
1515

16-
static const uint8_t SDA = 3;
17-
static const uint8_t SCL = 4;
16+
static const uint8_t SDA = 4;
17+
static const uint8_t SCL = 3;
1818

1919
static const uint8_t SS = 8;
2020
static const uint8_t MOSI = 10;
Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[env:heltec-v4]
1+
[heltec_v4_base]
22
extends = esp32s3_base
33
board = heltec_v4
44
board_check = true
@@ -7,3 +7,106 @@ build_flags =
77
${esp32s3_base.build_flags}
88
-D HELTEC_V4
99
-I variants/esp32s3/heltec_v4
10+
lib_deps =
11+
${esp32s3_base.lib_deps}
12+
13+
14+
[env:heltec-v4]
15+
extends = heltec_v4_base
16+
build_flags =
17+
${heltec_v4_base.build_flags}
18+
-D HELTEC_V4_OLED
19+
-D USE_SSD1306 ; Heltec_v4 has an SSD1315 display (compatible with SSD1306 driver)
20+
-D LED_PIN=35
21+
-D RESET_OLED=21
22+
-D I2C_SDA=17
23+
-D I2C_SCL=18
24+
-D I2C_SDA1=4
25+
-D I2C_SCL1=3
26+
lib_deps =
27+
${heltec_v4_base.lib_deps}
28+
29+
[env:heltec-v4-tft]
30+
extends = heltec_v4_base
31+
build_flags =
32+
${heltec_v4_base.build_flags} ;-Os
33+
-D HELTEC_V4_TFT
34+
-D I2C_SDA=4
35+
-D I2C_SCL=3
36+
-D I2C_SDA1=47
37+
-D I2C_SCL1=48
38+
-D PIN_BUTTON2=35
39+
-D PIN_BUZZER=6
40+
-D USE_PIN_BUZZER=PIN_BUZZER
41+
-D CONFIG_ARDUHAL_LOG_COLORS
42+
-D RADIOLIB_DEBUG_SPI=0
43+
-D RADIOLIB_DEBUG_PROTOCOL=0
44+
-D RADIOLIB_DEBUG_BASIC=0
45+
-D RADIOLIB_VERBOSE_ASSERT=0
46+
-D RADIOLIB_SPI_PARANOID=0
47+
-D CONFIG_DISABLE_HAL_LOCKS=1
48+
-D INPUTDRIVER_BUTTON_TYPE=0
49+
-D HAS_SCREEN=1
50+
-D HAS_TFT=1
51+
-D RAM_SIZE=1560
52+
-D LV_LVGL_H_INCLUDE_SIMPLE
53+
-D LV_CONF_INCLUDE_SIMPLE
54+
-D LV_COMP_CONF_INCLUDE_SIMPLE
55+
-D LV_USE_SYSMON=0
56+
-D LV_USE_PROFILER=0
57+
-D LV_USE_PERF_MONITOR=0
58+
-D LV_USE_MEM_MONITOR=0
59+
-D LV_USE_LOG=0
60+
-D LV_BUILD_TEST=0
61+
-D USE_LOG_DEBUG
62+
-D LOG_DEBUG_INC=\"DebugConfiguration.h\"
63+
-D USE_PACKET_API
64+
-D LGFX_DRIVER=LGFX_HELTEC_V4_TFT
65+
-D GFX_DRIVER_INC=\"graphics/LGFX/LGFX_HELTEC_V4_TFT.h\"
66+
-D VIEW_320x240
67+
-D MAP_FULL_REDRAW
68+
-D DISPLAY_SIZE=320x240 ; landscape mode
69+
-D LGFX_PIN_SCK=17
70+
-D LGFX_PIN_MOSI=33
71+
-D LGFX_PIN_DC=16
72+
-D LGFX_PIN_CS=15
73+
-D LGFX_PIN_BL=21
74+
-D LGFX_PIN_RST=18
75+
-D CUSTOM_TOUCH_DRIVER
76+
-D TOUCH_SDA_PIN=I2C_SDA1
77+
-D TOUCH_SCL_PIN=I2C_SCL1
78+
-D TOUCH_INT_PIN=-1 ;45
79+
-D TOUCH_RST_PIN=44
80+
;base UI
81+
-D TFT_CS=LGFX_PIN_CS
82+
-D ST7789_CS=TFT_CS
83+
-D ST7789_RS=LGFX_PIN_DC
84+
-D ST7789_SDA=LGFX_PIN_MOSI
85+
-D ST7789_SCK=LGFX_PIN_SCK
86+
-D ST7789_RESET=LGFX_PIN_RST
87+
-D ST7789_MISO=-1
88+
-D ST7789_BUSY=-1
89+
-D ST7789_BL=LGFX_PIN_BL
90+
-D ST7789_SPI_HOST=SPI3_HOST
91+
-D TFT_BL=ST7789_BL
92+
-D SPI_FREQUENCY=40000000
93+
-D SPI_READ_FREQUENCY=4000000
94+
-D TFT_HEIGHT=320
95+
-D TFT_WIDTH=240
96+
-D TFT_OFFSET_X=0
97+
-D TFT_OFFSET_Y=0
98+
-D TFT_OFFSET_ROTATION=0
99+
-D SCREEN_ROTATE
100+
-D SCREEN_TRANSITION_FRAMERATE=5
101+
-D BRIGHTNESS_DEFAULT=130 ; Medium Low Brightness
102+
-D HAS_TOUCHSCREEN=1
103+
-D TOUCH_I2C_PORT=0
104+
-D TOUCH_SLAVE_ADDRESS=0x2E
105+
-D SCREEN_TOUCH_INT=TOUCH_INT_PIN
106+
-D SCREEN_TOUCH_RST=TOUCH_RST_PIN
107+
108+
lib_deps = ${heltec_v4_base.lib_deps}
109+
; ${device-ui_base.lib_deps}
110+
111+
https://github.com/Quency-D/chsc6x/archive/5cbead829d6b432a8d621ed1aafd4eb474fd4f27.zip
112+
https://github.com/Quency-D/device-ui/archive/7c9870b8016641190b059bdd90fe16c1012a39eb.zip

variants/esp32s3/heltec_v4/variant.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
#define LED_PIN 35
2-
3-
#define USE_SSD1306 // Heltec_v4 has an SSD1315 display (compatible with SSD1306 driver)
4-
5-
#define RESET_OLED 21
6-
#define I2C_SDA 17 // I2C pins for this board
7-
#define I2C_SCL 18
8-
91
#define VEXT_ENABLE 36 // active low, powers the oled display and the lora antenna boost
102
#define BUTTON_PIN 0
113

0 commit comments

Comments
 (0)