Skip to content

Commit eaba441

Browse files
committed
feat(box3): simplified code and working on adding box3 support (display and touch do not seem to work, and the touch drivers are not recognized on the bus at all :/
1 parent bd0d3fa commit eaba441

File tree

7 files changed

+93
-77
lines changed

7 files changed

+93
-77
lines changed

components/espp

Submodule espp updated 85 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ static constexpr size_t height = 240;
2323
static constexpr size_t pixel_buffer_size = width * 50;
2424
static constexpr bool backlight_value = true;
2525
static constexpr bool invert_colors = true;
26-
static constexpr auto flush_cb = espp::St7789::flush;
2726
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE;
27+
static constexpr bool mirror_x = true;
28+
static constexpr bool mirror_y = true;
29+
30+
using DisplayDriver = espp::St7789;

main/box_3.hpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 bool touch_swap_xy = false;
15+
// static constexpr int clock_speed = 60 * 1000 * 1000;
16+
static constexpr int clock_speed = 20 * 1000 * 1000;
17+
static constexpr auto spi_num = SPI2_HOST;
18+
static constexpr gpio_num_t mosi = GPIO_NUM_6;
19+
static constexpr gpio_num_t sclk = GPIO_NUM_7;
20+
static constexpr gpio_num_t spics = GPIO_NUM_5;
21+
static constexpr gpio_num_t reset = GPIO_NUM_48;
22+
static constexpr gpio_num_t dc_pin = (gpio_num_t)DC_PIN_NUM;
23+
static constexpr gpio_num_t backlight = GPIO_NUM_47;
24+
static constexpr size_t width = 320;
25+
static constexpr size_t height = 240;
26+
static constexpr size_t pixel_buffer_size = 16384;
27+
// static constexpr size_t pixel_buffer_size = width * 50;
28+
static constexpr bool backlight_value = true;
29+
static constexpr bool invert_colors = true;
30+
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE;
31+
static constexpr bool mirror_x = true;
32+
static constexpr bool mirror_y = true;
33+
34+
using DisplayDriver = espp::Ili9341;

main/main.cpp

Lines changed: 43 additions & 73 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,25 @@ 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+
.invert_colors = invert_colors,
227+
.mirror_x = mirror_x,
228+
.mirror_y = mirror_y,
253229
});
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});
230+
// initialize the display / lvgl
231+
auto display = std::make_shared<espp::Display>(
232+
espp::Display::AllocatingConfig{.width = width,
233+
.height = height,
234+
.pixel_buffer_size = pixel_buffer_size,
235+
.flush_callback = DisplayDriver::flush,
236+
.rotation = rotation,
237+
.software_rotation_enabled = true});
263238

264239
// create the gui
265240
Gui gui({
@@ -282,8 +257,8 @@ extern "C" void app_main(void) {
282257
.log_level = espp::Logger::Verbosity::WARN,
283258
});
284259
#endif
285-
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_TDECK
286-
// initialize the i2c bus to read the touchpad driver (tt21100)
260+
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_BOX_3 || CONFIG_HARDWARE_TDECK
261+
// initialize the i2c bus to read the touchpad driver
287262
espp::I2c i2c({
288263
.port = I2C_NUM_0,
289264
.sda_io_num = i2c_sda,
@@ -293,46 +268,41 @@ extern "C" void app_main(void) {
293268
.clk_speed = 400 * 1000,
294269
});
295270

296-
#if CONFIG_HARDWARE_BOX
271+
// probe for the touch devices:
272+
// tt21100, gt911
273+
bool has_tt21100 = false;
274+
bool has_gt911 = false;
275+
has_tt21100 = i2c.probe_device(0x24);
276+
has_gt911 = i2c.probe_device(0x5d) | i2c.probe_device(0x14);
277+
logger.info("Touchpad probe results: tt21100: {}, gt911: {}", has_tt21100, has_gt911);
278+
279+
#if CONFIG_HARDWARE_BOX || CONFIG_HARDWARE_BOX_3
297280
logger.info("Initializing Tt21100");
298-
auto tt21100 = espp::Tt21100({
281+
espp::Tt21100 touch({
299282
.read = std::bind(&espp::I2c::read, &i2c, std::placeholders::_1, std::placeholders::_2,
300283
std::placeholders::_3),
301284
});
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-
};
314285
#endif
315286
#if CONFIG_HARDWARE_TDECK
316287
logger.info("Initializing GT911");
317288
// implement GT911
318-
espp::Gt911 gt911({.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1,
289+
espp::Gt911 touch({.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1,
319290
std::placeholders::_2, std::placeholders::_3),
320291
.write_read = std::bind(&espp::I2c::write_read, &i2c, std::placeholders::_1,
321292
std::placeholders::_2, std::placeholders::_3,
322293
std::placeholders::_4, std::placeholders::_5)});
323294

324-
auto touchpad_read = [&](uint8_t* num_touch_points, uint16_t* x, uint16_t* y, uint8_t* btn_state) {
295+
#endif
296+
297+
auto touchpad_read = [&touch](uint8_t* num_touch_points, uint16_t* x, uint16_t* y, uint8_t* btn_state) {
298+
std::error_code ec;
325299
*num_touch_points = 0;
326300
// 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);
301+
if (touch.update(ec) && !ec) {
302+
touch.get_touch_point(num_touch_points, x, y);
330303
}
331-
// now hand it off
332-
*btn_state = false; // no touchscreen button on t-deck
304+
*btn_state = touch.get_home_button_state();
333305
};
334-
#endif
335-
336306
logger.info("Initializing touchpad");
337307
auto touchpad = espp::TouchpadInput(espp::TouchpadInput::Config{
338308
.touchpad_read = touchpad_read,

main/tdeck.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ static constexpr size_t height = 240;
2323
static constexpr size_t pixel_buffer_size = width * 50;
2424
static constexpr bool backlight_value = true;
2525
static constexpr bool invert_colors = false;
26-
static constexpr auto flush_cb = espp::St7789::flush;
2726
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE_INVERTED;
27+
static constexpr bool mirror_x = true;
28+
static constexpr bool mirror_y = true;
29+
30+
using DisplayDriver = espp::St7789;

main/wrover_kit.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ 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;
1920
static constexpr bool invert_colors = false;
20-
static auto flush_cb = espp::Ili9341::flush;
2121
static auto rotation = espp::Display::Rotation::LANDSCAPE;
22+
static constexpr bool mirror_x = false;
23+
static constexpr bool mirror_y = false;
24+
25+
using DisplayDriver = espp::Ili9341;

0 commit comments

Comments
 (0)