11#include " input.h"
22
3- #include " i2c .hpp"
3+ #include " hal_i2c .hpp"
44
55#include " task.hpp"
66
77#include " mcp23x17.hpp"
88
99#include " touchpad_input.hpp"
10- #define USE_FT5X06 0
11- #if USE_FT5X06
12- #include " ft5x06.hpp"
13- #else
1410#include " tt21100.hpp"
15- #endif
1611
1712using namespace std ::chrono_literals;
1813
1914static std::shared_ptr<espp::Mcp23x17> mcp23x17;
20-
21- #if USE_FT5X06
22- static std::shared_ptr<Ft5x06> ft5x06;
23- #else
24- static std::shared_ptr<Tt21100> tt21100;
25- #endif
15+ static std::shared_ptr<espp::Tt21100> tt21100;
2616static std::shared_ptr<espp::TouchpadInput> touchpad;
2717
2818/* *
2919 * Touch Controller configuration
3020 */
31- #if USE_FT5X06
32- void ft5x06_write (uint8_t reg_addr, uint8_t value) {
33- uint8_t write_buf[] = {reg_addr, value};
34- i2c_write_internal_bus (Ft5x06::ADDRESS, write_buf, 2 );
35- }
36-
37- void ft5x06_read (uint8_t reg_addr, uint8_t *read_data, size_t read_len) {
38- i2c_read_internal_bus (Ft5x06::ADDRESS, reg_addr, read_data, read_len);
39- }
40- #else
41- void tt21100_write (uint8_t reg_addr, uint8_t value) {
42- uint8_t write_buf[] = {reg_addr, value};
43- i2c_write_internal_bus (Tt21100::ADDRESS, write_buf, 2 );
44- }
45-
46- void tt21100_read (uint8_t *read_data, size_t read_len) {
47- i2c_read_internal_bus (Tt21100::ADDRESS, read_data, read_len);
48- }
49- #endif
50-
5121void touchpad_read (uint8_t * num_touch_points, uint16_t * x, uint16_t * y, uint8_t * btn_state) {
52- // NOTE: ft5x06 does not have button support, so data->btn_val cannot be set
53- #if USE_FT5X06
54- ft5x06->get_touch_point (num_touch_points, x, y);
55- // TODO: how to handle quit condition if FT5x06?
56- #else
5722 // get the latest data from the device
58- while (!tt21100->read ())
59- ;
23+ std::error_code ec;
24+ tt21100->update (ec);
25+ if (ec) {
26+ fmt::print (" error updating tt21100: {}\n " , ec.message ());
27+ return ;
28+ }
6029 // now hand it off
6130 tt21100->get_touch_point (num_touch_points, x, y);
6231 *btn_state = tt21100->get_home_button_state ();
63- #endif
6432}
6533
6634static std::atomic<bool > initialized = false ;
6735void init_input () {
6836 if (initialized) return ;
6937 fmt::print (" Initializing input drivers...\n " );
7038
71- #if USE_FT5X06
72- fmt::print (" Initializing ft5x06\n " );
73- ft5x06 = std::make_shared<Ft5x06>(Ft5x06::Config{
74- .write = ft5x06_write,
75- .read = ft5x06_read,
76- .log_level = espp::Logger::Verbosity::WARN
77- });
78- #else
7939 fmt::print (" Initializing Tt21100\n " );
80- tt21100 = std::make_shared<Tt21100>(Tt21100::Config{
81- .read = tt21100_read ,
40+ tt21100 = std::make_shared<espp:: Tt21100>(espp:: Tt21100::Config{
41+ .read = std::bind (&espp::I2c::read, internal_i2c. get (), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3) ,
8242 .log_level = espp::Logger::Verbosity::WARN
8343 });
84- #endif
8544
8645 fmt::print (" Initializing touchpad\n " );
8746 touchpad = std::make_shared<espp::TouchpadInput>(espp::TouchpadInput::Config{
@@ -98,8 +57,8 @@ void init_input() {
9857 .port_a_interrupt_mask = 0x00 ,
9958 .port_b_direction_mask = 0xFF , // D-pad B0-B3, ABXY B4-B7
10059 .port_b_interrupt_mask = 0x00 ,
101- .write = i2c_write_external_bus ,
102- .read = i2c_read_external_bus ,
60+ .write = std::bind (&espp::I2c::write, external_i2c. get (), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3) ,
61+ .read = std::bind (&espp::I2c::read_at_register, external_i2c. get (), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4) ,
10362 .log_level = espp::Logger::Verbosity::WARN
10463 });
10564
0 commit comments