roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
touch_ft6x36.cpp
Go to the documentation of this file.
2
4
5namespace roo_display {
6
7namespace {
8
9static constexpr uint8_t kTouchI2cAddr = 0x38;
10static constexpr int kRegNumTouches = 2;
11
12static constexpr int kRegBaseXh = 3;
13static constexpr int kRegBaseXl = 4;
14static constexpr int kRegBaseYh = 5;
15static constexpr int kRegBaseYl = 6;
16static constexpr int kRegBaseWeight = 7;
17static constexpr int kRegBaseSize = 8;
18
19static constexpr int kTouchBufferSize = 6;
20
21} // namespace
22
23// The panel reports the same, cached, coordinates if scanned more frequently
24// than every 25ms. So let's not bother asking, just serve cached values.
25// (This also allows velocity detection to work).
27 : BasicTouchDevice<2>(Config{.min_sampling_interval_ms = 25,
28 .touch_intertia_ms = 0,
29 .smoothing_factor = 0.0}),
30 i2c_slave_(i2c, kTouchI2cAddr) {}
31
33
34void TouchFt6x36::initTouch() { i2c_slave_.init(); }
35
37 static constexpr uint8_t size = 16;
38 uint8_t data[size];
39 roo::byte request[] = {roo::byte{0}};
40 if (!i2c_slave_.transmit(request, 1)) return 0;
41 if (i2c_slave_.receive((roo::byte*)data, size) < size) return 0;
43 int touched = data[kRegNumTouches] & 0x0F;
44 if (touched == 0 || touched > 2) return 0;
45 int confirmed_touched = 0;
46 for (uint8_t i = 0; i < 2; i++) {
47 const int base = i * kTouchBufferSize;
48 int kind = data[base + kRegBaseXh] >> 6;
49 if ((kind & 1) != 0) {
50 // Lift-up or no-event.
51 continue;
52 }
54 p->id = data[base + kRegBaseYh] >> 4;
55 p->x = ((data[base + kRegBaseXh] << 8) | data[base + kRegBaseXl]) & 0x0FFF;
56 p->y = ((data[base + kRegBaseYh] << 8) | data[base + kRegBaseYl]) & 0x0FFF;
57 p->z = data[base + kRegBaseWeight] << 4; // 0-4080.
58 if (p->z == 0) p->z = 1024;
59 ++p;
60 }
61 return std::min(touched, confirmed_touched);
62}
63
64} // namespace roo_display
int readTouch(TouchPoint *point) override
void initTouch() override
Initialize the touch controller.
Defines 140 opaque HTML named colors.
A single touch point returned by a touch controller.
Definition device.h:390