Skip to content

Commit

Permalink
S3BoxV3::GT911 red circle button support (see #569)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobozo committed Jun 11, 2024
1 parent 50a1800 commit 6376299
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
35 changes: 29 additions & 6 deletions src/lgfx/v1/touch/Touch_GT911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace lgfx
inline namespace v1
{
//----------------------------------------------------------------------------
static constexpr uint8_t gt911cmd_getdata[] = { 0x81, 0x4E, 0x00 };
static constexpr uint8_t gt911cmd_getdata[] = { 0x81, 0x4E, 0x00 }; // read XY
static constexpr uint8_t gt911cmd_getkey[] = { 0x80, 0x93, 0x00 }; // read button

static uint8_t calcChecksum(const uint8_t *buf, uint8_t len)
{
Expand Down Expand Up @@ -131,6 +132,21 @@ namespace lgfx
_writeBytes(writedata, 3);
}



void Touch_GT911::_update_keys(void)
{
if ( (_readdata[0] & 0x10) == 0x10)
{
_writeReadBytes(gt911cmd_getkey, 2, &_readdata[0], max_touch_points);
// Serial.printf("%04x: %02x %02x %02x %02x %02x\n" , 0x8093, _readdata[0], _readdata[1], _readdata[2], _readdata[3], _readdata[4]);
_writeBytes(gt911cmd_getkey, 3); // clear
_readdata[0] = 1;
_readdata[2] = _cfg.y_max+20; // assign value outside coords
}
}


bool Touch_GT911::_update_data(void)
{
bool res = false;
Expand All @@ -148,11 +164,18 @@ namespace lgfx
_readdata[0] = buf;
res = true;
}
} else {
if( buf !=0 ) ESP_LOGI("[Touch_GT911]", "buf: 0x%02x", buf);
}
lgfx::i2c::endTransaction(_cfg.i2c_port).has_value();

if(_buttons>0) {
_update_keys();
}

if (res)
{
_writeBytes(gt911cmd_getdata, 3);
_writeBytes(gt911cmd_getdata, 3); // clear
}
}
return res;
Expand All @@ -161,7 +184,7 @@ namespace lgfx
uint_fast8_t Touch_GT911::getTouchRaw(touch_point_t* __restrict tp, uint_fast8_t count)
{
if (!_inited || count == 0) return 0;
if (count > 5) { count = 5; }
if (count > max_touch_points) { count = max_touch_points; }

uint32_t msec = lgfx::millis();
uint32_t diff_msec = msec - _last_update;
Expand Down Expand Up @@ -201,13 +224,13 @@ namespace lgfx

void Touch_GT911::setTouchNums(int_fast8_t nums)
{
nums = std::max<int_fast8_t>(1, std::min<int_fast8_t>(5, nums));
_buttons = std::max<int_fast8_t>(1, std::min<int_fast8_t>(max_touch_points, _buttons));

uint8_t buf[] = { 0x80, 0x4c, 0x00 };
_writeReadBytes(buf, 2, &buf[2], 1);
if (buf[2] != nums)
if (buf[2] != _buttons)
{
buf[2] = nums;
buf[2] = _buttons;
_writeBytes(buf, 3);

_freshConfig();
Expand Down
3 changes: 3 additions & 0 deletions src/lgfx/v1/touch/Touch_GT911.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace lgfx
bool _writeBytes(const uint8_t* data, size_t len);
bool _writeReadBytes(const uint8_t* write_data, size_t write_len, uint8_t* read_data, size_t read_len);
bool _update_data(void);
void _update_keys(void);

uint8_t _buttons = 0; // touch nums
};

//----------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32_all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,21 +1315,22 @@ namespace lgfx
cfg.pin_int = GPIO_NUM_3;
cfg.pin_sda = GPIO_NUM_8;
cfg.pin_scl = GPIO_NUM_18;
cfg.i2c_addr = 0x14;
cfg.i2c_addr = t->default_addr_1; // 0x14;
cfg.i2c_port = I2C_NUM_0;
cfg.x_min = 0;
cfg.x_max = 319;
cfg.y_min = 0;
// Max-y = 239 + 40 pixels for "red" touch point below LCD active area
cfg.y_max = 279;
cfg.y_max = 239;
cfg.offset_rotation = 2;
cfg.bus_shared = false;
t->config(cfg);
if (!t->init())
{
cfg.i2c_addr = 0x5D; // addr change (0x14 or 0x5D)
cfg.i2c_addr = t->default_addr_2; // 0x5D; // addr change (0x14 or 0x5D)
t->config(cfg);
//ESP_LOGI(LIBRARY_NAME, "[TouchInit] i2c addr 0x%02x, init: %s", t->default_addr_2, t->init()?"success":"fail");
}
t->setTouchNums(5); // /!\ driver is not multitouch+button ready
p->touch(t);
}
}
Expand Down

0 comments on commit 6376299

Please sign in to comment.