1 /*!
2  * @file        tsc_touchkey.h
3  *
4  * @brief       This file contains external declarations of the tsc_touchkey.c file.
5  *
6  * @version     V1.0.1
7  *
8  * @date        2022-09-20
9  *
10  * @attention
11  *
12  *  Copyright (C) 2020-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be useful and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 /* Define to prevent recursive inclusion */
27 #ifndef __TOUCH_TOUCHKEY_H
28 #define __TOUCH_TOUCHKEY_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* Includes */
35 #include "tsc_acq.h"
36 #include "tsc_time.h"
37 
38 /** @addtogroup TSC_Driver_Library TSC Driver Library
39   @{
40 */
41 
42 /** @addtogroup TSC_TouchKey_Driver TSC TouchKey Driver
43   @{
44 */
45 
46 /** @defgroup TSC_TouchKey_Macros Macros
47   @{
48 */
49 
50 /**@} end of group TSC_TouchKey_Macros */
51 
52 /** @defgroup TSC_TouchKey_Enumerations Enumerations
53   @{
54 */
55 
56 /**@} end of group TSC_TouchKey_Enumerations */
57 
58 /** @defgroup TSC_TouchKey_Structures Structures
59   @{
60 */
61 
62 /**
63  * @brief   Contains all data related to TouchKey sensor.
64  *          Variables of this structure type must be placed in RAM only.
65  */
66 typedef struct
67 {
68     TSC_STATEID_T      StateId;           /*!< Current state identifier */
69     TSC_tCounter_T     CounterDebounce;   /*!< Counter for debounce and calibration management */
70     unsigned int       CounterDTO : 6;    /*!< Counter for DTO management (TSC_tCounter_T) */
71     unsigned int       Change     : 1;    /*!< The State is different from the previous one (TSC_STATE_T) */
72     unsigned int       DxsLock    : 1;    /*!< The State is locked by the DxS (TSC_BOOL_T) */
73 } TSC_TouchKeyData_T;
74 
75 /**
76  * @brief   Contains all data related to TouchKey sensor.
77  *          Variables of this structure type can be placed in RAM or ROM.
78  */
79 typedef struct
80 {
81 #if TOUCH_USE_PROX > 0
82     TSC_tThreshold_T  ProxInTh;           /*!< Proximity in threshold */
83     TSC_tThreshold_T  ProxOutTh;          /*!< Proximity out threshold */
84 #endif
85     TSC_tThreshold_T  DetectInTh;         /*!< Detection in threshold */
86     TSC_tThreshold_T  DetectOutTh;        /*!< Detection out threshold */
87     TSC_tThreshold_T  CalibTh;            /*!< Calibration threshold */
88     TSC_tCounter_T    CounterDebCalib;    /*!< Debounce counter to enter in Calibration state */
89 #if TOUCH_USE_PROX > 0
90     TSC_tCounter_T    CounterDebProx;     /*!< Debounce counter to enter in Proximity state */
91 #endif
92     TSC_tCounter_T    CounterDebDetect;   /*!< Debounce counter to enter in Detect state */
93     TSC_tCounter_T    CounterDebRelease;  /*!< Debounce counter to enter in Release state */
94     TSC_tCounter_T    CounterDebError;    /*!< Debounce counter to enter in Error state */
95 } TSC_TouchKeyParam_T;
96 
97 /**
98  * @brief   Contains definition of a TouchKey sensor.
99  *          Variables of this structure type can be placed in RAM or ROM.
100  */
101 typedef struct
102 {
103     TSC_TouchKeyData_T*          p_Data;    /*!< Data (state id, counter, flag, ...) */
104     TSC_TouchKeyParam_T*         p_Param;   /*!< Parameters (thresholds, debounce, ...) */
105     TSC_Channel_Data_T*          p_ChD;     /*!< Channel Data (Meas, Refer, Delta, ...) */
106     CONST TSC_State_T*           p_SM;      /*!< State Machine */
107     CONST TSC_TouchKeyMethods_T* p_Methods; /*!< Methods */
108 } TSC_TouchKey_T;
109 
110 /**
111  * @brief   Contains definition of a Basic TouchKey sensor.
112  *          Variables of this structure type can be placed in RAM or ROM.
113  *          Basic sensor does not contain its own state machine and methods. It used
114  *          default ones instead to gain memory space.
115  */
116 typedef struct
117 {
118     TSC_TouchKeyData_T*          p_Data;    /*!< Data (state id, counters, flag, ...) */
119     TSC_TouchKeyParam_T*         p_Param;   /*!< Parameters (thresholds, debounce, ...) */
120     TSC_Channel_Data_T*          p_ChD;     /*!< Channel Data (Meas, Refer, Delta, ...) */
121 } TSC_TouchKeyB_T;
122 
123 /**@} end of group TSC_TouchKey_Structures */
124 
125 /** @defgroup TSC_TouchKey_Functions Functions
126   @{
127 */
128 
129 /* "Object methods" functions */
130 void TSC_TouchKey_Config(void);
131 void TSC_TouchKey_Process(void);
132 
133 /* Utility functions */
134 void TSC_TouchKey_ConfigCalibrationState(TSC_tCounter_T delay);
135 void TSC_TouchKey_ConfigOffState(void);
136 void TSC_TouchKey_ConfigBurstOnlyState(void);
137 TSC_STATEID_T TSC_TouchKey_ReadStateId(void);
138 TSC_STATEMASK_T TSC_TouchKey_ReadStateMask(void);
139 TSC_tNum_T TSC_TouchKey_ReadChangeFlag(void);
140 
141 /* State machine functions */
142 void TSC_TouchKey_ProcessCalibrationState(void);
143 void TSC_TouchKey_ProcessDebCalibrationState(void);
144 void TSC_TouchKey_ProcessReleaseState(void);
145 void TSC_TouchKey_ProcessDebReleaseProxState(void);
146 void TSC_TouchKey_ProcessDebReleaseDetectState(void);
147 void TSC_TouchKey_ProcessDebReleaseTouchState(void);
148 void TSC_TouchKey_ProcessProxState(void);
149 void TSC_TouchKey_ProcessDebProxState(void);
150 void TSC_TouchKey_ProcessDebProxDetectState(void);
151 void TSC_TouchKey_ProcessDebProxTouchState(void);
152 void TSC_TouchKey_ProcessDetectState(void);
153 void TSC_TouchKey_ProcessDebDetectState(void);
154 void TSC_TouchKey_ProcessTouchState(void);
155 void TSC_TouchKey_ProcessDebErrorState(void);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif /* __TSC_TOUCHKEY_H */
162 
163 /**@} end of group TSC_TouchKey_Functions */
164 /**@} end of group TSC_TouchKey_Driver */
165 /**@} end of group TSC_Driver_Library */
166