• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "hpm_touch.h"
9 ft5406_context_t ft5406 = {0};
10 
touch_get_data(touch_point_t * points,uint8_t * num_of_points)11 hpm_stat_t touch_get_data(touch_point_t *points, uint8_t *num_of_points)
12 {
13     hpm_stat_t stat = status_success;
14     uint8_t i = 0;
15     ft5406_touch_data_t touch_data = {0};
16 
17     stat = ft5406_read_touch_data(&ft5406, &touch_data);
18     if (stat != status_success) {
19         return stat;
20     }
21 
22     if ((touch_data.status < FT5406_MAX_TOUCH_POINTS) && (touch_data.status)) {
23         for (i = 0; touch_data.points[i].x_h > 0 && touch_data.points[i].x_h < 0xFF; i++) {
24             points[i].x = (touch_data.points[i].x_h & 0xF) << 8 | touch_data.points[i].x_l;
25             points[i].y = (touch_data.points[i].y_h & 0xF) << 8 | touch_data.points[i].y_l;
26         }
27     }
28 
29     *num_of_points = i;
30     return stat;
31 }
32 
touch_init(I2C_Type * i2c_ptr)33 hpm_stat_t touch_init(I2C_Type *i2c_ptr)
34 {
35     hpm_stat_t stat;
36 
37     ft5406.ptr = i2c_ptr;
38     stat = ft5406_init(&ft5406);
39     if (stat != status_success) {
40         return stat;
41     }
42 
43 #ifdef USE_CAP_INT
44     stat = ft5406_write_register(&ft5406, FT5406_ID_G_MODE, 0);
45     if (stat != status_success) {
46         return stat;
47     }
48     cap_int_setup();
49 #endif
50     return stat;
51 }
52