1 /*! 2 * @file tsc_linrot.h 3 * 4 * @brief This file contains external declarations of the tsc_linrot.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_LINROT_H 28 #define __TOUCH_LINROT_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_Linrot_Driver TSC Linrot Driver 43 @{ 44 */ 45 46 /** @defgroup TSC_Linrot_Macros Macros 47 @{ 48 */ 49 50 #define TSC_SCTCOMP_3CH_LIN_M1 ((TSC_tNum_T)(128)) 51 #define TSC_POSCORR_3CH_LIN_M1 ((TSC_tNum_T)( 64)) 52 #define TSC_SCTCOMP_3CH_LIN_M2 ((TSC_tNum_T)(256)) 53 #define TSC_POSCORR_3CH_LIN_M2 ((TSC_tNum_T)(256)) 54 55 #define TSC_SCTCOMP_3CH_LIN_H ((TSC_tNum_T)(128)) 56 #define TSC_POSCORR_3CH_LIN_H ((TSC_tNum_T)(128)) 57 58 #define TSC_SCTCOMP_3CH_ROT_M ((TSC_tNum_T)( 85)) 59 60 #define TSC_SCTCOMP_4CH_LIN_M1 ((TSC_tNum_T)( 85)) 61 #define TSC_POSCORR_4CH_LIN_M1 ((TSC_tNum_T)( 43)) 62 #define TSC_SCTCOMP_4CH_LIN_M2 ((TSC_tNum_T)(128)) 63 #define TSC_POSCORR_4CH_LIN_M2 ((TSC_tNum_T)(128)) 64 65 #define TSC_SCTCOMP_4CH_LIN_H ((TSC_tNum_T)( 85)) 66 #define TSC_POSCORR_4CH_LIN_H ((TSC_tNum_T)( 85)) 67 68 #define TSC_SCTCOMP_4CH_ROT_M ((TSC_tNum_T)( 64)) 69 70 #define TSC_SCTCOMP_5CH_LIN_M1 ((TSC_tNum_T)( 64)) 71 #define TSC_POSCORR_5CH_LIN_M1 ((TSC_tNum_T)( 32)) 72 #define TSC_SCTCOMP_5CH_LIN_M2 ((TSC_tNum_T)( 85)) 73 #define TSC_POSCORR_5CH_LIN_M2 ((TSC_tNum_T)( 85)) 74 75 #define TSC_SCTCOMP_5CH_LIN_H ((TSC_tNum_T)( 64)) 76 #define TSC_POSCORR_5CH_LIN_H ((TSC_tNum_T)( 64)) 77 78 #define TSC_SCTCOMP_5CH_ROT_M ((TSC_tNum_T)( 51)) 79 80 #define TSC_SCTCOMP_5CH_ROT_D ((TSC_tNum_T)( 26)) 81 82 #define TSC_SCTCOMP_6CH_LIN_M1 ((TSC_tNum_T)( 51)) 83 #define TSC_POSCORR_6CH_LIN_M1 ((TSC_tNum_T)( 25)) 84 #define TSC_SCTCOMP_6CH_LIN_M2 ((TSC_tNum_T)( 64)) 85 #define TSC_POSCORR_6CH_LIN_M2 ((TSC_tNum_T)( 64)) 86 87 #define TSC_SCTCOMP_6CH_LIN_H ((TSC_tNum_T)( 51)) 88 #define TSC_POSCORR_6CH_LIN_H ((TSC_tNum_T)( 51)) 89 90 #define TSC_SCTCOMP_6CH_ROT_M ((TSC_tNum_T)( 43)) 91 92 /**@} end of group TSC_Linrot_Macros */ 93 94 /** @defgroup TSC_Linrot_Enumerations Enumerations 95 @{ 96 */ 97 98 /**@} end of group TSC_Linrot_Enumerations */ 99 100 /** @defgroup TSC_Linrot_Structures Structures 101 @{ 102 */ 103 104 /** 105 * @brief Contains all data related to Linear and Rotary sensor. 106 * Variables of this structure type must be placed in RAM only. 107 */ 108 typedef struct 109 { 110 TSC_STATEID_T StateId; /*!< Current state identifier */ 111 TSC_tsignPosition_T RawPosition; /*!< Raw position */ 112 TSC_tsignPosition_T Position; /*!< Scaled position */ 113 TSC_tCounter_T CounterDebounce; /*!< Counter for debounce and calibration management */ 114 unsigned int CounterDTO : 6; /*!< Counter for DTO management (TSC_tCounter_T) */ 115 unsigned int Change : 1; /*!< The State is different from the previous one (TSC_STATE_T) */ 116 unsigned int PosChange : 1; /*!< The RawPosition/Position is different from the previous one (TSC_STATE_T) */ 117 unsigned int CounterDirection : 6; /*!< Counter for direction debounce management (TSC_tCounter_T) */ 118 unsigned int DxsLock : 1; /*!< The State is locked by the DxS (TSC_BOOL_T) */ 119 unsigned int Direction : 1; /*!< Movement direction (TSC_BOOL_T) */ 120 } TSC_LinRotData_T; 121 122 /** 123 * @brief Contains all parameters related to Linear and Rotary sensor. 124 * Variables of this structure type can be placed in RAM or ROM. 125 */ 126 typedef struct 127 { 128 /* Thresholds */ 129 #if TOUCH_USE_PROX > 0 130 TSC_tThreshold_T ProxInTh; /*!< Proximity state in threshold */ 131 TSC_tThreshold_T ProxOutTh; /*!< Proximity state out threshold */ 132 #endif 133 TSC_tThreshold_T DetectInTh; /*!< Detection state in threshold */ 134 TSC_tThreshold_T DetectOutTh; /*!< Detection state out threshold */ 135 TSC_tThreshold_T CalibTh; /*!< Calibration state threshold */ 136 137 /* Debounce counters */ 138 TSC_tCounter_T CounterDebCalib; /*!< Debounce counter to enter in Calibration state */ 139 #if TOUCH_USE_PROX > 0 140 TSC_tCounter_T CounterDebProx; /*!< Debounce counter to enter in Proximity state */ 141 #endif 142 TSC_tCounter_T CounterDebDetect; /*!< Debounce counter to enter in Detect state */ 143 TSC_tCounter_T CounterDebRelease; /*!< Debounce counter to enter in Release state */ 144 TSC_tCounter_T CounterDebError; /*!< Debounce counter to enter in Error state */ 145 TSC_tCounter_T CounterDebDirection; /*!< Debounce counter for the direction change */ 146 147 /* Other parameters */ 148 TSC_tCounter_T Resolution; /*!< Position resolution */ 149 TSC_tsignPosition_T DirChangePos; /*!< Direction change position threshold */ 150 } TSC_LinRotParam_T; 151 152 /** 153 * @brief Contains all parameters related to Linear and Rotary sensor. 154 * Variables of this structure type can be placed in RAM or ROM. 155 */ 156 typedef struct 157 { 158 TSC_LinRotData_T* p_Data; /*!< Data (state id, counter, flag, ...) */ 159 TSC_LinRotParam_T* p_Param; /*!< Parameters (thresholds, debounce, ...) */ 160 TSC_Channel_Data_T* p_ChD; /*!< First Channel Data (Meas, Refer, Delta, ...) */ 161 TSC_tNum_T NumChannel; /*!< Number of channels */ 162 CONST uint16_t* p_DeltaCoeff; /*!< Coefficient to apply on Delta */ 163 CONST TSC_tPosition_T* p_PosOff; /*!< Position offset table */ 164 TSC_tNum_T SctComp; /*!< Sector Computation */ 165 TSC_tNum_T PosCorr; /*!< Position Correction */ 166 CONST TSC_State_T* p_SM; /*!< State Machine */ 167 CONST TSC_LinRotMethods_T* p_Methods; /*!< Methods */ 168 } TSC_LinRot_T; 169 170 /** 171 * @brief Contains all parameters related to Linear and Rotary sensor. 172 * Variables of this structure type can be placed in RAM or ROM. 173 * Basic sensor does not contain its own state machine and methods. 174 * It used default ones instead to gain memory space. 175 */ 176 typedef struct 177 { 178 TSC_LinRotData_T* p_Data; /*!< Data (state id, counter, flag, ...) */ 179 TSC_LinRotParam_T* p_Param; /*!< Parameters (thresholds, debounce, ...) */ 180 TSC_Channel_Data_T* p_ChD; /*!< First Channel Data (Meas, Refer, Delta, ...) */ 181 TSC_tNum_T NumChannel; /*!< Number of channels */ 182 CONST uint16_t* p_DeltaCoeff; /*!< Coefficient to apply on Delta */ 183 CONST TSC_tPosition_T* p_PosOff; /*!< Position offset table */ 184 TSC_tNum_T SctComp; /*!< Sector Computation */ 185 TSC_tNum_T PosCorr; /*!< Position Correction */ 186 } TSC_LinRotB_T; 187 188 /**@} end of group TSC_Linrot_Structures */ 189 190 /** @defgroup TSC_Linrot_Variables Variables 191 @{ 192 */ 193 194 /* Position offset constant tables and corrections */ 195 extern CONST TSC_tPosition_T TSC_POSOFF_3CH_LIN_M1[3][3]; 196 extern CONST TSC_tPosition_T TSC_POSOFF_3CH_LIN_M2[3][3]; 197 extern CONST TSC_tPosition_T TSC_POSOFF_3CH_LIN_H[3][3]; 198 extern CONST TSC_tPosition_T TSC_POSOFF_3CH_ROT_M[3][3]; 199 200 extern CONST TSC_tPosition_T TSC_POSOFF_4CH_LIN_M1[4][4]; 201 extern CONST TSC_tPosition_T TSC_POSOFF_4CH_LIN_M2[4][4]; 202 extern CONST TSC_tPosition_T TSC_POSOFF_4CH_LIN_H[4][4]; 203 extern CONST TSC_tPosition_T TSC_POSOFF_4CH_ROT_M[4][4]; 204 205 extern CONST TSC_tPosition_T TSC_POSOFF_5CH_LIN_M1[5][5]; 206 extern CONST TSC_tPosition_T TSC_POSOFF_5CH_LIN_M2[5][5]; 207 extern CONST TSC_tPosition_T TSC_POSOFF_5CH_LIN_H[5][5]; 208 extern CONST TSC_tPosition_T TSC_POSOFF_5CH_ROT_M[5][5]; 209 extern CONST TSC_tPosition_T TSC_POSOFF_5CH_ROT_D[5][5]; 210 211 extern CONST TSC_tPosition_T TSC_POSOFF_6CH_LIN_M1[6][6]; 212 extern CONST TSC_tPosition_T TSC_POSOFF_6CH_LIN_M2[6][6]; 213 extern CONST TSC_tPosition_T TSC_POSOFF_6CH_LIN_H[6][6]; 214 extern CONST TSC_tPosition_T TSC_POSOFF_6CH_ROT_M[6][6]; 215 216 /**@} end of group TSC_Linrot_Variables */ 217 218 /** @defgroup TSC_Linrot_Functions Functions 219 @{ 220 */ 221 222 /* "Object methods" functions */ 223 void TSC_Linrot_Config(void); 224 void TSC_Linrot_Process(void); 225 TSC_STATUS_T TSC_Linrot_CalcPos(void); 226 227 /* Utility functions */ 228 void TSC_Linrot_ConfigCalibrationState(TSC_tCounter_T delay); 229 void TSC_Linrot_ConfigOffState(void); 230 void TSC_Linrot_ConfigBurstOnlyState(void); 231 TSC_STATEID_T TSC_Linrot_ReadStateId(void); 232 TSC_STATEMASK_T TSC_Linrot_ReadStateMask(void); 233 TSC_tNum_T TSC_Linrot_ReadChangeFlag(void); 234 235 /* State machine functions */ 236 void TSC_Linrot_ProcessCalibrationState(void); 237 void TSC_Linrot_ProcessDebCalibrationState(void); 238 void TSC_Linrot_ProcessReleaseState(void); 239 void TSC_Linrot_ProcessDebReleaseProxState(void); 240 void TSC_Linrot_ProcessDebReleaseDetectState(void); 241 void TSC_Linrot_ProcessDebReleaseTouchState(void); 242 void TSC_Linrot_ProcessProxState(void); 243 void TSC_Linrot_ProcessDebProxState(void); 244 void TSC_Linrot_ProcessDebProxDetectState(void); 245 void TSC_Linrot_ProcessDebProxTouchState(void); 246 void TSC_Linrot_ProcessDetectState(void); 247 void TSC_Linrot_ProcessDebDetectState(void); 248 void TSC_Linrot_ProcessTouchState(void); 249 void TSC_Linrot_ProcessDebTouchState(void); 250 void TSC_Linrot_ProcessDebErrorState(void); 251 252 /* Private functions */ 253 void TSC_Linrot_ReadTimeForDTO(void); 254 void TSC_Linrot_Process_AllChannel_Status(TSC_OBJ_STATUS_T status); 255 TSC_STATUS_T TSC_Linrot_Process_OneChannel_DataReady(void); 256 TSC_STATUS_T TSC_Linrot_Process_AllChannel_AcqStatus(TSC_ACQ_STATUS_T status); 257 TSC_STATUS_T TSC_Linrot_Process_OneChannel_AcqStatusError(void); 258 TSC_STATUS_T TSC_Linrot_Process_OneChannel_DeltaBelowEquMinus(TSC_tThreshold_T threshold, TSC_tIndex_T Cmd); 259 TSC_STATUS_T TSC_Linrot_Process_OneChannel_DeltaAboveEqu(TSC_tThreshold_T threshold, TSC_tIndex_T Cmd); 260 TSC_STATUS_T TSC_Linrot_Process_OneChannel_DeltaAbove(TSC_tThreshold_T threshold, TSC_tIndex_T Cmd); 261 TSC_STATUS_T TSC_Linrot_Process_AllChannel_DeltaBelowEqu(TSC_tThreshold_T threshold, TSC_tIndex_T Cmd); 262 void TSC_Linrot_Process_AllChannel_ClearRef(void); 263 TSC_tDelta_T TSC_Linrot_NormDelta(TSC_Channel_Data_T* channel, TSC_tIndex_T index); 264 265 #ifdef __cplusplus 266 } 267 #endif 268 269 #endif /* __TSC_LINROT_H */ 270 271 /**@} end of group TSC_Linrot_Functions */ 272 /**@} end of group TSC_Linrot_Driver */ 273 /**@} end of group TSC_Driver_Library */ 274