5#include "roo_threads.h"
6#include "roo_threads/thread.h"
13static constexpr int kAddr1 = 0x5D;
14static constexpr int kAddr2 = 0x14;
16static constexpr int kTouchRead = 0x814e;
17static constexpr int kPointBuffer = 0x814f;
19TouchPoint ReadPoint(
const roo::byte* data) {
21 tp.id = (uint16_t)data[0];
22 tp.x = ((int16_t)data[2] << 8) | (int16_t)data[1];
23 tp.y = ((int16_t)data[4] << 8) | (int16_t)data[3];
38 .touch_intertia_ms = 30,
39 .smoothing_factor = 0.0}),
43 i2c_slave_(
i2c, addr_),
59 if (reset_thread_.joinable()) {
64 reset_thread_ = roo::thread([
this]() {
69 roo::this_thread::sleep_for(roo_time::Millis((reset_low_hold_ms_)));
76 roo::this_thread::sleep_for(roo_time::Millis(1));
80 roo::this_thread::sleep_for(roo_time::Millis(5));
86 roo::this_thread::sleep_for(roo_time::Millis(100));
92 if (!ready_)
return 0;
93 if (reset_thread_.joinable()) {
101 bool ready = (
status & roo::byte{0x80}) != roo::byte{0};
103 if (!
ready)
return 0;
116 roo::byte
addr[] = {(roo::byte)(
reg >> 8), (roo::byte)(
reg & 0xFF)};
117 if (!i2c_slave_.transmit(addr, 2))
return false;
118 return (i2c_slave_.receive(&result, 1) == 1);
121void TouchGt911::writeByte(uint16_t reg, roo::byte val) {
122 roo::byte buf[] = {(roo::byte)(reg >> 8), (roo::byte)(reg & 0xFF), val};
123 i2c_slave_.transmit(buf, 3);
126void TouchGt911::readBlock(roo::byte* buf, uint16_t reg, uint8_t size) {
127 roo::byte addr[] = {(roo::byte)(reg >> 8), (roo::byte)(reg & 0xFF)};
128 i2c_slave_.transmit(addr, 2);
129 i2c_slave_.receive(buf, size);
TouchGt911(GpioSetter pinIntr, GpioSetter pinRst, long reset_low_hold_ms=1)
void initTouch() override
Initialize the touch controller.
int readTouch(TouchPoint *point) override
Defines 140 opaque HTML named colors.
A single touch point returned by a touch controller.