roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
touch_ft6x36.cpp
Go to the documentation of this file.
1
#include "
roo_display/driver/touch_ft6x36.h
"
2
3
#include "
roo_display/hal/i2c.h
"
4
5
namespace
roo_display
{
6
7
namespace
{
8
9
static
constexpr
uint8_t kTouchI2cAddr = 0x38;
10
static
constexpr
int
kRegNumTouches = 2;
11
12
static
constexpr
int
kRegBaseXh = 3;
13
static
constexpr
int
kRegBaseXl = 4;
14
static
constexpr
int
kRegBaseYh = 5;
15
static
constexpr
int
kRegBaseYl = 6;
16
static
constexpr
int
kRegBaseWeight = 7;
17
static
constexpr
int
kRegBaseSize = 8;
18
19
static
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).
26
TouchFt6x36::TouchFt6x36
(
I2cMasterBusHandle
i2c
)
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
32
TouchFt6x36::TouchFt6x36
() :
TouchFt6x36
(
I2cMasterBusHandle
()) {}
33
34
void
TouchFt6x36::initTouch
() { i2c_slave_.init(); }
35
36
int
TouchFt6x36::readTouch
(
TouchPoint
*
point
) {
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;
42
TouchPoint
*
p
=
point
;
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
}
53
++
confirmed_touched
;
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
roo_display::BasicTouchDevice
Definition
basic_touch.h:14
roo_display::TouchFt6x36
Definition
touch_ft6x36.h:8
roo_display::TouchFt6x36::readTouch
int readTouch(TouchPoint *point) override
Definition
touch_ft6x36.cpp:36
roo_display::TouchFt6x36::TouchFt6x36
TouchFt6x36()
Definition
touch_ft6x36.cpp:32
roo_display::TouchFt6x36::initTouch
void initTouch() override
Initialize the touch controller.
Definition
touch_ft6x36.cpp:34
i2c.h
roo_display
Defines 140 opaque HTML named colors.
Definition
roo_display.cpp:7
roo_display::BlendOp
Definition
blending.h:200
roo_display::TouchPoint
A single touch point returned by a touch controller.
Definition
device.h:390
touch_ft6x36.h
temp_repos
roo_display
src
roo_display
driver
touch_ft6x36.cpp
Generated by
1.9.8