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