Skip to content

Commit c4643f7

Browse files
authored
Merge pull request #4 from esp-cpp/feature/box-3-support
Simplify code and add support for ESP32-S3-BOX-3
2 parents bd0d3fa + a1c054f commit c4643f7

File tree

8 files changed

+112
-83
lines changed

8 files changed

+112
-83
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Wireless Debug Display
22

33
This repository contains an example application designed for either
4-
ESP32-WROVER-KIT, ESP32-S3-BOX, or LILYGO T-DECK (selectable via menuconfig) which listens on a
5-
UDP socket for data. It then parses that data and if it matches a certain
6-
format, it will plot the data in a graph, otherwise it will print the data to a
7-
text log for display.
4+
ESP32-WROVER-KIT, ESP32-S3-BOX, ESP32-S3-BOX-3, or LILYGO T-DECK (selectable via
5+
menuconfig) which listens on a UDP socket for data. It then parses that data and
6+
if it matches a certain format, it will plot the data in a graph, otherwise it
7+
will print the data to a text log for display.
88

99
https://github.com/esp-cpp/wireless-debug-display/assets/213467/f835922f-e17f-4f76-95ee-5d6585e84656
1010

@@ -152,3 +152,7 @@ https://github.com/esp-cpp/wireless-debug-display/assets/213467/395400f6-e677-46
152152

153153
https://github.com/esp-cpp/wireless-debug-display/assets/213467/f835922f-e17f-4f76-95ee-5d6585e84656
154154

155+
### ESP32-S3-BOX-3
156+
157+
![image](https://github.com/esp-cpp/wireless-debug-display/assets/213467/26501803-44bc-47a6-b229-d0b3ca1eb3be)
158+
![image](https://github.com/esp-cpp/wireless-debug-display/assets/213467/a1f34a60-dae2-4264-a85b-a8b28f9bbacf)

components/espp

Submodule espp updated 86 files

main/Kconfig.projbuild

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ menu "Wireless Debug Display Configuration"
99
bool "ESP32 WROVER KIT V4"
1010
config HARDWARE_BOX
1111
bool "ESP BOX"
12+
config HARDWARE_BOX_3
13+
bool "ESP BOX 3"
1214
config HARDWARE_TDECK
1315
bool "LILYGO T DECK"
1416
endchoice

main/box.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ static constexpr size_t width = 320;
2222
static constexpr size_t height = 240;
2323
static constexpr size_t pixel_buffer_size = width * 50;
2424
static constexpr bool backlight_value = true;
25+
static constexpr bool reset_value = false;
2526
static constexpr bool invert_colors = true;
26-
static constexpr auto flush_cb = espp::St7789::flush;
2727
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE;
28+
static constexpr bool mirror_x = true;
29+
static constexpr bool mirror_y = true;
30+
static constexpr bool touch_invert_x = true;
31+
static constexpr bool touch_invert_y = false;
32+
33+
using DisplayDriver = espp::St7789;

main/box_3.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include "i2c.hpp"
4+
#include "ili9341.hpp"
5+
#include "st7789.hpp"
6+
#include "touchpad_input.hpp"
7+
#include "gt911.hpp"
8+
#include "tt21100.hpp"
9+
static constexpr int DC_PIN_NUM = 4;
10+
11+
static constexpr std::string_view dev_kit = "ESP32-S3-BOX-3";
12+
static constexpr gpio_num_t i2c_sda = GPIO_NUM_8;
13+
static constexpr gpio_num_t i2c_scl = GPIO_NUM_18;
14+
static constexpr int clock_speed = 60 * 1000 * 1000;
15+
static constexpr auto spi_num = SPI2_HOST;
16+
static constexpr gpio_num_t mosi = GPIO_NUM_6;
17+
static constexpr gpio_num_t sclk = GPIO_NUM_7;
18+
static constexpr gpio_num_t spics = GPIO_NUM_5;
19+
static constexpr gpio_num_t reset = GPIO_NUM_48;
20+
static constexpr gpio_num_t dc_pin = (gpio_num_t)DC_PIN_NUM;
21+
static constexpr gpio_num_t backlight = GPIO_NUM_47;
22+
static constexpr size_t width = 320;
23+
static constexpr size_t height = 240;
24+
static constexpr size_t pixel_buffer_size = width * 50;
25+
static constexpr bool backlight_value = true;
26+
static constexpr bool reset_value = true;
27+
static constexpr bool invert_colors = true;
28+
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE;
29+
static constexpr bool mirror_x = true;
30+
static constexpr bool mirror_y = true;
31+
static constexpr bool touch_swap_xy = false;
32+
static constexpr bool touch_invert_x = false;
33+
static constexpr bool touch_invert_y = false;
34+
35+
using DisplayDriver = espp::St7789;

main/main.cpp

Lines changed: 46 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "wrover_kit.hpp"
1717
#elif CONFIG_HARDWARE_BOX
1818
#include "box.hpp"
19+
#elif CONFIG_HARDWARE_BOX_3
20+
#include "box_3.hpp"
1921
#elif CONFIG_HARDWARE_TDECK
2022
#include "tdeck.hpp"
2123
#else
@@ -115,32 +117,17 @@ void IRAM_ATTR lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *dat
115117
trans[i].flags = SPI_TRANS_USE_TXDATA;
116118
}
117119
size_t length = (xe - xs + 1) * (ye - ys + 1) * 2;
118-
#if CONFIG_HARDWARE_WROVER_KIT
119-
trans[0].tx_data[0] = (uint8_t)espp::Ili9341::Command::caset;
120-
#endif
121-
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_TDECK
122-
trans[0].tx_data[0] = (uint8_t)espp::St7789::Command::caset;
123-
#endif
120+
trans[0].tx_data[0] = (uint8_t)DisplayDriver::Command::caset;
124121
trans[1].tx_data[0] = (xs) >> 8;
125122
trans[1].tx_data[1] = (xs)&0xff;
126123
trans[1].tx_data[2] = (xe) >> 8;
127124
trans[1].tx_data[3] = (xe)&0xff;
128-
#if CONFIG_HARDWARE_WROVER_KIT
129-
trans[2].tx_data[0] = (uint8_t)espp::Ili9341::Command::raset;
130-
#endif
131-
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_TDECK
132-
trans[2].tx_data[0] = (uint8_t)espp::St7789::Command::raset;
133-
#endif
125+
trans[2].tx_data[0] = (uint8_t)DisplayDriver::Command::raset;
134126
trans[3].tx_data[0] = (ys) >> 8;
135127
trans[3].tx_data[1] = (ys)&0xff;
136128
trans[3].tx_data[2] = (ye) >> 8;
137129
trans[3].tx_data[3] = (ye)&0xff;
138-
#if CONFIG_HARDWARE_WROVER_KIT
139-
trans[4].tx_data[0] = (uint8_t)espp::Ili9341::Command::ramwr;
140-
#endif
141-
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_TDECK
142-
trans[4].tx_data[0] = (uint8_t)espp::St7789::Command::ramwr;
143-
#endif
130+
trans[4].tx_data[0] = (uint8_t)DisplayDriver::Command::ramwr;
144131
trans[5].tx_buffer = data;
145132
trans[5].length = length * 8;
146133
// undo SPI_TRANS_USE_TXDATA flag
@@ -229,37 +216,26 @@ extern "C" void app_main(void) {
229216
// Attach the LCD to the SPI bus
230217
ret = spi_bus_add_device(spi_num, &devcfg, &spi);
231218
ESP_ERROR_CHECK(ret);
232-
#if CONFIG_HARDWARE_WROVER_KIT
233-
// initialize the controller
234-
espp::Ili9341::initialize(espp::display_drivers::Config{.lcd_write = lcd_write,
235-
.lcd_send_lines = lcd_send_lines,
236-
.reset_pin = reset,
237-
.data_command_pin = dc_pin,
238-
.backlight_pin = backlight,
239-
.invert_colors = invert_colors});
240-
#endif
241-
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_TDECK
242-
// initialize the controller
243-
espp::St7789::initialize(espp::display_drivers::Config{
244-
.lcd_write = lcd_write,
245-
.lcd_send_lines = lcd_send_lines,
246-
.reset_pin = reset,
247-
.data_command_pin = dc_pin,
248-
.backlight_pin = backlight,
249-
.backlight_on_value = backlight_value,
250-
.invert_colors = invert_colors,
251-
.mirror_x = true,
252-
.mirror_y = true,
219+
// initialize the controller
220+
DisplayDriver::initialize(espp::display_drivers::Config{.lcd_write = lcd_write,
221+
.lcd_send_lines = lcd_send_lines,
222+
.reset_pin = reset,
223+
.data_command_pin = dc_pin,
224+
.backlight_pin = backlight,
225+
.backlight_on_value = backlight_value,
226+
.reset_value = reset_value,
227+
.invert_colors = invert_colors,
228+
.mirror_x = mirror_x,
229+
.mirror_y = mirror_y,
253230
});
254-
#endif
255-
// initialize the display / lvgl
256-
auto display = std::make_shared<espp::Display>(
257-
espp::Display::AllocatingConfig{.width = width,
258-
.height = height,
259-
.pixel_buffer_size = pixel_buffer_size,
260-
.flush_callback = flush_cb,
261-
.rotation = rotation,
262-
.software_rotation_enabled = true});
231+
// initialize the display / lvgl
232+
auto display = std::make_shared<espp::Display>(
233+
espp::Display::AllocatingConfig{.width = width,
234+
.height = height,
235+
.pixel_buffer_size = pixel_buffer_size,
236+
.flush_callback = DisplayDriver::flush,
237+
.rotation = rotation,
238+
.software_rotation_enabled = true});
263239

264240
// create the gui
265241
Gui gui({
@@ -282,8 +258,8 @@ extern "C" void app_main(void) {
282258
.log_level = espp::Logger::Verbosity::WARN,
283259
});
284260
#endif
285-
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_TDECK
286-
// initialize the i2c bus to read the touchpad driver (tt21100)
261+
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_BOX_3 || CONFIG_HARDWARE_TDECK
262+
// initialize the i2c bus to read the touchpad driver
287263
espp::I2c i2c({
288264
.port = I2C_NUM_0,
289265
.sda_io_num = i2c_sda,
@@ -293,52 +269,47 @@ extern "C" void app_main(void) {
293269
.clk_speed = 400 * 1000,
294270
});
295271

272+
// probe for the touch devices:
273+
// tt21100, gt911
274+
bool has_tt21100 = false;
275+
bool has_gt911 = false;
276+
has_tt21100 = i2c.probe_device(0x24);
277+
has_gt911 = i2c.probe_device(0x5d) | i2c.probe_device(0x14);
278+
logger.info("Touchpad probe results: tt21100: {}, gt911: {}", has_tt21100, has_gt911);
279+
296280
#if CONFIG_HARDWARE_BOX
297281
logger.info("Initializing Tt21100");
298-
auto tt21100 = espp::Tt21100({
282+
espp::Tt21100 touch({
299283
.read = std::bind(&espp::I2c::read, &i2c, std::placeholders::_1, std::placeholders::_2,
300284
std::placeholders::_3),
301285
});
302-
auto touchpad_read = [&](uint8_t* num_touch_points, uint16_t* x, uint16_t* y, uint8_t* btn_state) {
303-
std::error_code ec;
304-
// get the latest data from the device
305-
tt21100.update(ec);
306-
if (ec) {
307-
logger.error("Could not update tt21100: {}", ec.message());
308-
return;
309-
}
310-
// now hand it off
311-
tt21100.get_touch_point(num_touch_points, x, y);
312-
*btn_state = tt21100.get_home_button_state();
313-
};
314286
#endif
315-
#if CONFIG_HARDWARE_TDECK
287+
#if CONFIG_HARDWARE_TDECK || CONFIG_HARDWARE_BOX_3
316288
logger.info("Initializing GT911");
317289
// implement GT911
318-
espp::Gt911 gt911({.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1,
290+
espp::Gt911 touch({.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1,
319291
std::placeholders::_2, std::placeholders::_3),
320292
.write_read = std::bind(&espp::I2c::write_read, &i2c, std::placeholders::_1,
321293
std::placeholders::_2, std::placeholders::_3,
322294
std::placeholders::_4, std::placeholders::_5)});
323295

324-
auto touchpad_read = [&](uint8_t* num_touch_points, uint16_t* x, uint16_t* y, uint8_t* btn_state) {
296+
#endif
297+
298+
auto touchpad_read = [&touch](uint8_t* num_touch_points, uint16_t* x, uint16_t* y, uint8_t* btn_state) {
299+
std::error_code ec;
325300
*num_touch_points = 0;
326301
// get the latest data from the device
327-
std::error_code ec;
328-
if (gt911.update(ec) && !ec) {
329-
gt911.get_touch_point(num_touch_points, x, y);
302+
if (touch.update(ec) && !ec) {
303+
touch.get_touch_point(num_touch_points, x, y);
330304
}
331-
// now hand it off
332-
*btn_state = false; // no touchscreen button on t-deck
305+
*btn_state = touch.get_home_button_state();
333306
};
334-
#endif
335-
336307
logger.info("Initializing touchpad");
337308
auto touchpad = espp::TouchpadInput(espp::TouchpadInput::Config{
338309
.touchpad_read = touchpad_read,
339310
.swap_xy = touch_swap_xy,
340-
.invert_x = true,
341-
.invert_y = false,
311+
.invert_x = touch_invert_x,
312+
.invert_y = touch_invert_y,
342313
.log_level = espp::Logger::Verbosity::WARN
343314
});
344315
#endif

main/tdeck.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ static constexpr size_t width = 320;
2222
static constexpr size_t height = 240;
2323
static constexpr size_t pixel_buffer_size = width * 50;
2424
static constexpr bool backlight_value = true;
25+
static constexpr bool reset_value = false;
2526
static constexpr bool invert_colors = false;
26-
static constexpr auto flush_cb = espp::St7789::flush;
2727
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE_INVERTED;
28+
static constexpr bool mirror_x = true;
29+
static constexpr bool mirror_y = true;
30+
static constexpr bool touch_invert_x = true;
31+
static constexpr bool touch_invert_y = false;
32+
33+
using DisplayDriver = espp::St7789;

main/wrover_kit.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ static constexpr gpio_num_t backlight = GPIO_NUM_5;
1616
static constexpr size_t width = 320;
1717
static constexpr size_t height = 240;
1818
static constexpr size_t pixel_buffer_size = 16384;
19+
static constexpr bool backlight_value = false;
20+
static constexpr bool reset_value = false;
1921
static constexpr bool invert_colors = false;
20-
static auto flush_cb = espp::Ili9341::flush;
2122
static auto rotation = espp::Display::Rotation::LANDSCAPE;
23+
static constexpr bool mirror_x = false;
24+
static constexpr bool mirror_y = false;
25+
26+
using DisplayDriver = espp::Ili9341;

0 commit comments

Comments
 (0)