1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef HDF_TOUCH_H
10 #define HDF_TOUCH_H
11 
12 #include <securec.h>
13 #include "osal_time.h"
14 #include "hdf_input_device_manager.h"
15 #include "input_config.h"
16 #include "input_i2c_ops.h"
17 
18 #define CHIP_CHECK_RETURN(ret) do { \
19     if ((ret) != HDF_SUCCESS) { \
20         return ret; \
21     } \
22 } while (0)
23 
24 #define MAX_FINGERS_NUM 10
25 #define SELF_TEST_RESULT_LEN 20
26 
27 #define PWR_TYPE_INDEX      0
28 #define PWR_STATUS_INDEX    1
29 #define PWR_DIR_INDEX       2
30 #define PWR_DELAY_INDEX     3
31 #define PWR_CELL_LEN        4
32 
33 typedef enum {
34     TOUCH_DOWN,    // 0
35     TOUCH_UP,      // 1
36     TOUCH_CONTACT, // 2
37 } EventType;
38 
39 typedef enum {
40     TYPE_UNKNOWN,    // 0
41     TYPE_VCC,        // 1
42     TYPE_VCI,        // 2
43     TYPE_RESET,      // 3
44     TYPE_INT,        // 4
45 } TimingType;
46 
47 typedef struct {
48     int32_t x;    /* x coordinate */
49     int32_t y;    /* y coordinate */
50     int32_t pressure;
51     int32_t trackId;   /* touch ID */
52     int32_t status;    /* record every point's status */
53     bool valid;
54 } FingerData;
55 
56 typedef struct {
57     FingerData fingers[MAX_FINGERS_NUM];
58     int32_t realPointNum;
59     int32_t definedEvent;    /* touch event: 0-down; 1-up; 2-contact */
60     OsalTimespec time;
61 } FrameData;
62 
63 struct TouchChipDevice;
64 typedef struct TouchPlatformDriver {
65     struct HdfDeviceObject *hdfTouchDev;
66     InputDevice *inputDev;
67     struct TouchChipDevice *device;
68     FrameData frameData;
69     uint32_t devType;
70     const char *devName;
71     TouchBoardCfg *boardCfg;
72     InputI2cClient i2cClient;
73     struct OsalMutex mutex;
74     uint32_t pwrStatus;
75     uint32_t gestureMode;
76     bool initedFlag;
77     bool irqStopFlag;
78 } TouchDriver;
79 
80 struct TouchChipOps;
81 typedef struct TouchChipDevice {
82     TouchDriver *driver;
83     const char *chipName;
84     const char *vendorName;
85     struct TouchChipOps *ops;
86     TouchChipCfg *chipCfg;
87     TouchBoardCfg *boardCfg;
88 } ChipDevice;
89 
90 struct TouchChipOps {
91     int32_t (*Init)(ChipDevice *device);
92     int32_t (*Detect)(ChipDevice *device);
93     int32_t (*Resume)(ChipDevice *device);
94     int32_t (*Suspend)(ChipDevice *device);
95     int32_t (*DataHandle)(ChipDevice *device);
96     int32_t (*UpdateFirmware)(ChipDevice *device);
97     void (*SetAbility)(ChipDevice *device);
98 };
99 
100 typedef struct {
101     uint32_t testType;
102     char testResult[SELF_TEST_RESULT_LEN];
103 } CapacitanceTestInfo;
104 
105 typedef struct {
106     const char *cmdCode;
107     const char *cmdValue;
108 } InputExtraCmd;
109 
110 int32_t RegisterTouchChipDevice(ChipDevice *chipDev);
111 
112 typedef int32_t (*PowerEventHandler)(ChipDevice *chipDev, uint32_t *timing, uint32_t length);
113 
114 #endif
115