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,
0 commit comments