1 /** 2 ****************************************************************************** 3 * @file stm32f3xx_hal_tsc.h 4 * @author MCD Application Team 5 * @brief Header file of TSC HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2016 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32F3xx_HAL_TSC_H 21 #define STM32F3xx_HAL_TSC_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32f3xx_hal_def.h" 29 30 31 /** @addtogroup STM32F3xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup TSC 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup TSC_Exported_Types TSC Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief TSC state structure definition 46 */ 47 typedef enum 48 { 49 HAL_TSC_STATE_RESET = 0x00UL, /*!< TSC registers have their reset value */ 50 HAL_TSC_STATE_READY = 0x01UL, /*!< TSC registers are initialized or acquisition is completed with success */ 51 HAL_TSC_STATE_BUSY = 0x02UL, /*!< TSC initialization or acquisition is on-going */ 52 HAL_TSC_STATE_ERROR = 0x03UL /*!< Acquisition is completed with max count error */ 53 } HAL_TSC_StateTypeDef; 54 55 /** 56 * @brief TSC group status structure definition 57 */ 58 typedef enum 59 { 60 TSC_GROUP_ONGOING = 0x00UL, /*!< Acquisition on group is on-going or not started */ 61 TSC_GROUP_COMPLETED = 0x01UL /*!< Acquisition on group is completed with success (no max count error) */ 62 } TSC_GroupStatusTypeDef; 63 64 /** 65 * @brief TSC init structure definition 66 */ 67 typedef struct 68 { 69 uint32_t CTPulseHighLength; /*!< Charge-transfer high pulse length 70 This parameter can be a value of @ref TSC_CTPulseHL_Config */ 71 uint32_t CTPulseLowLength; /*!< Charge-transfer low pulse length 72 This parameter can be a value of @ref TSC_CTPulseLL_Config */ 73 FunctionalState SpreadSpectrum; /*!< Spread spectrum activation 74 This parameter can be set to ENABLE or DISABLE. */ 75 uint32_t SpreadSpectrumDeviation; /*!< Spread spectrum deviation 76 This parameter must be a number between Min_Data = 0 and Max_Data = 127 */ 77 uint32_t SpreadSpectrumPrescaler; /*!< Spread spectrum prescaler 78 This parameter can be a value of @ref TSC_SpreadSpec_Prescaler */ 79 uint32_t PulseGeneratorPrescaler; /*!< Pulse generator prescaler 80 This parameter can be a value of @ref TSC_PulseGenerator_Prescaler */ 81 uint32_t MaxCountValue; /*!< Max count value 82 This parameter can be a value of @ref TSC_MaxCount_Value */ 83 uint32_t IODefaultMode; /*!< IO default mode 84 This parameter can be a value of @ref TSC_IO_Default_Mode */ 85 uint32_t SynchroPinPolarity; /*!< Synchro pin polarity 86 This parameter can be a value of @ref TSC_Synchro_Pin_Polarity */ 87 uint32_t AcquisitionMode; /*!< Acquisition mode 88 This parameter can be a value of @ref TSC_Acquisition_Mode */ 89 FunctionalState MaxCountInterrupt;/*!< Max count interrupt activation 90 This parameter can be set to ENABLE or DISABLE. */ 91 uint32_t ChannelIOs; /*!< Channel IOs mask */ 92 uint32_t ShieldIOs; /*!< Shield IOs mask */ 93 uint32_t SamplingIOs; /*!< Sampling IOs mask */ 94 } TSC_InitTypeDef; 95 96 /** 97 * @brief TSC IOs configuration structure definition 98 */ 99 typedef struct 100 { 101 uint32_t ChannelIOs; /*!< Channel IOs mask */ 102 uint32_t ShieldIOs; /*!< Shield IOs mask */ 103 uint32_t SamplingIOs; /*!< Sampling IOs mask */ 104 } TSC_IOConfigTypeDef; 105 106 /** 107 * @brief TSC handle Structure definition 108 */ 109 #if (USE_HAL_TSC_REGISTER_CALLBACKS == 1) 110 typedef struct __TSC_HandleTypeDef 111 #else 112 typedef struct 113 #endif /* USE_HAL_TSC_REGISTER_CALLBACKS */ 114 { 115 TSC_TypeDef *Instance; /*!< Register base address */ 116 TSC_InitTypeDef Init; /*!< Initialization parameters */ 117 __IO HAL_TSC_StateTypeDef State; /*!< Peripheral state */ 118 HAL_LockTypeDef Lock; /*!< Lock feature */ 119 __IO uint32_t ErrorCode; /*!< TSC Error code */ 120 121 #if (USE_HAL_TSC_REGISTER_CALLBACKS == 1) 122 void (* ConvCpltCallback)(struct __TSC_HandleTypeDef *htsc); /*!< TSC Conversion complete callback */ 123 void (* ErrorCallback)(struct __TSC_HandleTypeDef *htsc); /*!< TSC Error callback */ 124 125 void (* MspInitCallback)(struct __TSC_HandleTypeDef *htsc); /*!< TSC Msp Init callback */ 126 void (* MspDeInitCallback)(struct __TSC_HandleTypeDef *htsc); /*!< TSC Msp DeInit callback */ 127 128 #endif /* USE_HAL_TSC_REGISTER_CALLBACKS */ 129 } TSC_HandleTypeDef; 130 131 enum 132 { 133 TSC_GROUP1_IDX = 0x00UL, 134 TSC_GROUP2_IDX, 135 TSC_GROUP3_IDX, 136 TSC_GROUP4_IDX, 137 TSC_GROUP5_IDX, 138 TSC_GROUP6_IDX, 139 TSC_GROUP7_IDX, 140 TSC_GROUP8_IDX, 141 TSC_NB_OF_GROUPS 142 }; 143 144 #if (USE_HAL_TSC_REGISTER_CALLBACKS == 1) 145 /** 146 * @brief HAL TSC Callback ID enumeration definition 147 */ 148 typedef enum 149 { 150 HAL_TSC_CONV_COMPLETE_CB_ID = 0x00UL, /*!< TSC Conversion completed callback ID */ 151 HAL_TSC_ERROR_CB_ID = 0x01UL, /*!< TSC Error callback ID */ 152 153 HAL_TSC_MSPINIT_CB_ID = 0x02UL, /*!< TSC Msp Init callback ID */ 154 HAL_TSC_MSPDEINIT_CB_ID = 0x03UL /*!< TSC Msp DeInit callback ID */ 155 156 } HAL_TSC_CallbackIDTypeDef; 157 158 /** 159 * @brief HAL TSC Callback pointer definition 160 */ 161 typedef void (*pTSC_CallbackTypeDef)(TSC_HandleTypeDef *htsc); /*!< pointer to an TSC callback function */ 162 163 #endif /* USE_HAL_TSC_REGISTER_CALLBACKS */ 164 165 /** 166 * @} 167 */ 168 169 /* Exported constants --------------------------------------------------------*/ 170 /** @defgroup TSC_Exported_Constants TSC Exported Constants 171 * @{ 172 */ 173 174 /** @defgroup TSC_Error_Code_definition TSC Error Code definition 175 * @brief TSC Error Code definition 176 * @{ 177 */ 178 #define HAL_TSC_ERROR_NONE 0x00000000UL /*!< No error */ 179 #if (USE_HAL_TSC_REGISTER_CALLBACKS == 1) 180 #define HAL_TSC_ERROR_INVALID_CALLBACK 0x00000001UL /*!< Invalid Callback error */ 181 #endif /* USE_HAL_TSC_REGISTER_CALLBACKS */ 182 /** 183 * @} 184 */ 185 186 /** @defgroup TSC_CTPulseHL_Config CTPulse High Length 187 * @{ 188 */ 189 #define TSC_CTPH_1CYCLE 0x00000000UL 190 /*!< Charge transfer pulse high during 1 cycle (PGCLK) */ 191 #define TSC_CTPH_2CYCLES TSC_CR_CTPH_0 192 /*!< Charge transfer pulse high during 2 cycles (PGCLK) */ 193 #define TSC_CTPH_3CYCLES TSC_CR_CTPH_1 194 /*!< Charge transfer pulse high during 3 cycles (PGCLK) */ 195 #define TSC_CTPH_4CYCLES (TSC_CR_CTPH_1 | TSC_CR_CTPH_0) 196 /*!< Charge transfer pulse high during 4 cycles (PGCLK) */ 197 #define TSC_CTPH_5CYCLES TSC_CR_CTPH_2 198 /*!< Charge transfer pulse high during 5 cycles (PGCLK) */ 199 #define TSC_CTPH_6CYCLES (TSC_CR_CTPH_2 | TSC_CR_CTPH_0) 200 /*!< Charge transfer pulse high during 6 cycles (PGCLK) */ 201 #define TSC_CTPH_7CYCLES (TSC_CR_CTPH_2 | TSC_CR_CTPH_1) 202 /*!< Charge transfer pulse high during 7 cycles (PGCLK) */ 203 #define TSC_CTPH_8CYCLES (TSC_CR_CTPH_2 | TSC_CR_CTPH_1 | TSC_CR_CTPH_0) 204 /*!< Charge transfer pulse high during 8 cycles (PGCLK) */ 205 #define TSC_CTPH_9CYCLES TSC_CR_CTPH_3 206 /*!< Charge transfer pulse high during 9 cycles (PGCLK) */ 207 #define TSC_CTPH_10CYCLES (TSC_CR_CTPH_3 | TSC_CR_CTPH_0) 208 /*!< Charge transfer pulse high during 10 cycles (PGCLK) */ 209 #define TSC_CTPH_11CYCLES (TSC_CR_CTPH_3 | TSC_CR_CTPH_1) 210 /*!< Charge transfer pulse high during 11 cycles (PGCLK) */ 211 #define TSC_CTPH_12CYCLES (TSC_CR_CTPH_3 | TSC_CR_CTPH_1 | TSC_CR_CTPH_0) 212 /*!< Charge transfer pulse high during 12 cycles (PGCLK) */ 213 #define TSC_CTPH_13CYCLES (TSC_CR_CTPH_3 | TSC_CR_CTPH_2) 214 /*!< Charge transfer pulse high during 13 cycles (PGCLK) */ 215 #define TSC_CTPH_14CYCLES (TSC_CR_CTPH_3 | TSC_CR_CTPH_2 | TSC_CR_CTPH_0) 216 /*!< Charge transfer pulse high during 14 cycles (PGCLK) */ 217 #define TSC_CTPH_15CYCLES (TSC_CR_CTPH_3 | TSC_CR_CTPH_2 | TSC_CR_CTPH_1) 218 /*!< Charge transfer pulse high during 15 cycles (PGCLK) */ 219 #define TSC_CTPH_16CYCLES (TSC_CR_CTPH_3 | TSC_CR_CTPH_2 | TSC_CR_CTPH_1 | TSC_CR_CTPH_0) 220 /*!< Charge transfer pulse high during 16 cycles (PGCLK) */ 221 /** 222 * @} 223 */ 224 225 /** @defgroup TSC_CTPulseLL_Config CTPulse Low Length 226 * @{ 227 */ 228 #define TSC_CTPL_1CYCLE 0x00000000UL 229 /*!< Charge transfer pulse low during 1 cycle (PGCLK) */ 230 #define TSC_CTPL_2CYCLES TSC_CR_CTPL_0 231 /*!< Charge transfer pulse low during 2 cycles (PGCLK) */ 232 #define TSC_CTPL_3CYCLES TSC_CR_CTPL_1 233 /*!< Charge transfer pulse low during 3 cycles (PGCLK) */ 234 #define TSC_CTPL_4CYCLES (TSC_CR_CTPL_1 | TSC_CR_CTPL_0) 235 /*!< Charge transfer pulse low during 4 cycles (PGCLK) */ 236 #define TSC_CTPL_5CYCLES TSC_CR_CTPL_2 237 /*!< Charge transfer pulse low during 5 cycles (PGCLK) */ 238 #define TSC_CTPL_6CYCLES (TSC_CR_CTPL_2 | TSC_CR_CTPL_0) 239 /*!< Charge transfer pulse low during 6 cycles (PGCLK) */ 240 #define TSC_CTPL_7CYCLES (TSC_CR_CTPL_2 | TSC_CR_CTPL_1) 241 /*!< Charge transfer pulse low during 7 cycles (PGCLK) */ 242 #define TSC_CTPL_8CYCLES (TSC_CR_CTPL_2 | TSC_CR_CTPL_1 | TSC_CR_CTPL_0) 243 /*!< Charge transfer pulse low during 8 cycles (PGCLK) */ 244 #define TSC_CTPL_9CYCLES TSC_CR_CTPL_3 245 /*!< Charge transfer pulse low during 9 cycles (PGCLK) */ 246 #define TSC_CTPL_10CYCLES (TSC_CR_CTPL_3 | TSC_CR_CTPL_0) 247 /*!< Charge transfer pulse low during 10 cycles (PGCLK) */ 248 #define TSC_CTPL_11CYCLES (TSC_CR_CTPL_3 | TSC_CR_CTPL_1) 249 /*!< Charge transfer pulse low during 11 cycles (PGCLK) */ 250 #define TSC_CTPL_12CYCLES (TSC_CR_CTPL_3 | TSC_CR_CTPL_1 | TSC_CR_CTPL_0) 251 /*!< Charge transfer pulse low during 12 cycles (PGCLK) */ 252 #define TSC_CTPL_13CYCLES (TSC_CR_CTPL_3 | TSC_CR_CTPL_2) 253 /*!< Charge transfer pulse low during 13 cycles (PGCLK) */ 254 #define TSC_CTPL_14CYCLES (TSC_CR_CTPL_3 | TSC_CR_CTPL_2 | TSC_CR_CTPL_0) 255 /*!< Charge transfer pulse low during 14 cycles (PGCLK) */ 256 #define TSC_CTPL_15CYCLES (TSC_CR_CTPL_3 | TSC_CR_CTPL_2 | TSC_CR_CTPL_1) 257 /*!< Charge transfer pulse low during 15 cycles (PGCLK) */ 258 #define TSC_CTPL_16CYCLES (TSC_CR_CTPL_3 | TSC_CR_CTPL_2 | TSC_CR_CTPL_1 | TSC_CR_CTPL_0) 259 /*!< Charge transfer pulse low during 16 cycles (PGCLK) */ 260 /** 261 * @} 262 */ 263 264 /** @defgroup TSC_SpreadSpec_Prescaler Spread Spectrum Prescaler 265 * @{ 266 */ 267 #define TSC_SS_PRESC_DIV1 0x00000000UL /*!< Spread Spectrum Prescaler Div1 */ 268 #define TSC_SS_PRESC_DIV2 TSC_CR_SSPSC /*!< Spread Spectrum Prescaler Div2 */ 269 /** 270 * @} 271 */ 272 273 /** @defgroup TSC_PulseGenerator_Prescaler Pulse Generator Prescaler 274 * @{ 275 */ 276 #define TSC_PG_PRESC_DIV1 0x00000000UL /*!< Pulse Generator HCLK Div1 */ 277 #define TSC_PG_PRESC_DIV2 TSC_CR_PGPSC_0 /*!< Pulse Generator HCLK Div2 */ 278 #define TSC_PG_PRESC_DIV4 TSC_CR_PGPSC_1 /*!< Pulse Generator HCLK Div4 */ 279 #define TSC_PG_PRESC_DIV8 (TSC_CR_PGPSC_1 | TSC_CR_PGPSC_0) /*!< Pulse Generator HCLK Div8 */ 280 #define TSC_PG_PRESC_DIV16 TSC_CR_PGPSC_2 /*!< Pulse Generator HCLK Div16 */ 281 #define TSC_PG_PRESC_DIV32 (TSC_CR_PGPSC_2 | TSC_CR_PGPSC_0) /*!< Pulse Generator HCLK Div32 */ 282 #define TSC_PG_PRESC_DIV64 (TSC_CR_PGPSC_2 | TSC_CR_PGPSC_1) /*!< Pulse Generator HCLK Div64 */ 283 #define TSC_PG_PRESC_DIV128 (TSC_CR_PGPSC_2 | TSC_CR_PGPSC_1 | TSC_CR_PGPSC_0) /*!< Pulse Generator HCLK Div128 */ 284 /** 285 * @} 286 */ 287 288 /** @defgroup TSC_MaxCount_Value Max Count Value 289 * @{ 290 */ 291 #define TSC_MCV_255 0x00000000UL /*!< 255 maximum number of charge transfer pulses */ 292 #define TSC_MCV_511 TSC_CR_MCV_0 /*!< 511 maximum number of charge transfer pulses */ 293 #define TSC_MCV_1023 TSC_CR_MCV_1 /*!< 1023 maximum number of charge transfer pulses */ 294 #define TSC_MCV_2047 (TSC_CR_MCV_1 | TSC_CR_MCV_0) /*!< 2047 maximum number of charge transfer pulses */ 295 #define TSC_MCV_4095 TSC_CR_MCV_2 /*!< 4095 maximum number of charge transfer pulses */ 296 #define TSC_MCV_8191 (TSC_CR_MCV_2 | TSC_CR_MCV_0) /*!< 8191 maximum number of charge transfer pulses */ 297 #define TSC_MCV_16383 (TSC_CR_MCV_2 | TSC_CR_MCV_1) /*!< 16383 maximum number of charge transfer pulses */ 298 /** 299 * @} 300 */ 301 302 /** @defgroup TSC_IO_Default_Mode IO Default Mode 303 * @{ 304 */ 305 #define TSC_IODEF_OUT_PP_LOW 0x00000000UL /*!< I/Os are forced to output push-pull low */ 306 #define TSC_IODEF_IN_FLOAT TSC_CR_IODEF /*!< I/Os are in input floating */ 307 /** 308 * @} 309 */ 310 311 /** @defgroup TSC_Synchro_Pin_Polarity Synchro Pin Polarity 312 * @{ 313 */ 314 #define TSC_SYNC_POLARITY_FALLING 0x00000000UL /*!< Falling edge only */ 315 #define TSC_SYNC_POLARITY_RISING TSC_CR_SYNCPOL /*!< Rising edge and high level */ 316 /** 317 * @} 318 */ 319 320 /** @defgroup TSC_Acquisition_Mode Acquisition Mode 321 * @{ 322 */ 323 #define TSC_ACQ_MODE_NORMAL 0x00000000UL 324 /*!< Normal acquisition mode (acquisition starts as soon as START bit is set) */ 325 #define TSC_ACQ_MODE_SYNCHRO TSC_CR_AM 326 /*!< Synchronized acquisition mode (acquisition starts if START bit is set and 327 when the selected signal is detected on the SYNC input pin) */ 328 /** 329 * @} 330 */ 331 332 /** @defgroup TSC_interrupts_definition Interrupts definition 333 * @{ 334 */ 335 #define TSC_IT_EOA TSC_IER_EOAIE /*!< End of acquisition interrupt enable */ 336 #define TSC_IT_MCE TSC_IER_MCEIE /*!< Max count error interrupt enable */ 337 /** 338 * @} 339 */ 340 341 /** @defgroup TSC_flags_definition Flags definition 342 * @{ 343 */ 344 #define TSC_FLAG_EOA TSC_ISR_EOAF /*!< End of acquisition flag */ 345 #define TSC_FLAG_MCE TSC_ISR_MCEF /*!< Max count error flag */ 346 /** 347 * @} 348 */ 349 350 /** @defgroup TSC_Group_definition Group definition 351 * @{ 352 */ 353 #define TSC_GROUP1 (0x1UL << TSC_GROUP1_IDX) 354 #define TSC_GROUP2 (0x1UL << TSC_GROUP2_IDX) 355 #define TSC_GROUP3 (0x1UL << TSC_GROUP3_IDX) 356 #define TSC_GROUP4 (0x1UL << TSC_GROUP4_IDX) 357 #define TSC_GROUP5 (0x1UL << TSC_GROUP5_IDX) 358 #define TSC_GROUP6 (0x1UL << TSC_GROUP6_IDX) 359 #define TSC_GROUP7 (0x1UL << TSC_GROUP7_IDX) 360 #define TSC_GROUP8 (0x1UL << TSC_GROUP8_IDX) 361 362 #define TSC_GROUP1_IO1 TSC_IOCCR_G1_IO1 /*!< TSC Group1 IO1 */ 363 #define TSC_GROUP1_IO2 TSC_IOCCR_G1_IO2 /*!< TSC Group1 IO2 */ 364 #define TSC_GROUP1_IO3 TSC_IOCCR_G1_IO3 /*!< TSC Group1 IO3 */ 365 #define TSC_GROUP1_IO4 TSC_IOCCR_G1_IO4 /*!< TSC Group1 IO4 */ 366 367 #define TSC_GROUP2_IO1 TSC_IOCCR_G2_IO1 /*!< TSC Group2 IO1 */ 368 #define TSC_GROUP2_IO2 TSC_IOCCR_G2_IO2 /*!< TSC Group2 IO2 */ 369 #define TSC_GROUP2_IO3 TSC_IOCCR_G2_IO3 /*!< TSC Group2 IO3 */ 370 #define TSC_GROUP2_IO4 TSC_IOCCR_G2_IO4 /*!< TSC Group2 IO4 */ 371 372 #define TSC_GROUP3_IO1 TSC_IOCCR_G3_IO1 /*!< TSC Group3 IO1 */ 373 #define TSC_GROUP3_IO2 TSC_IOCCR_G3_IO2 /*!< TSC Group3 IO2 */ 374 #define TSC_GROUP3_IO3 TSC_IOCCR_G3_IO3 /*!< TSC Group3 IO3 */ 375 #define TSC_GROUP3_IO4 TSC_IOCCR_G3_IO4 /*!< TSC Group3 IO4 */ 376 377 #define TSC_GROUP4_IO1 TSC_IOCCR_G4_IO1 /*!< TSC Group4 IO1 */ 378 #define TSC_GROUP4_IO2 TSC_IOCCR_G4_IO2 /*!< TSC Group4 IO2 */ 379 #define TSC_GROUP4_IO3 TSC_IOCCR_G4_IO3 /*!< TSC Group4 IO3 */ 380 #define TSC_GROUP4_IO4 TSC_IOCCR_G4_IO4 /*!< TSC Group4 IO4 */ 381 382 #define TSC_GROUP5_IO1 TSC_IOCCR_G5_IO1 /*!< TSC Group5 IO1 */ 383 #define TSC_GROUP5_IO2 TSC_IOCCR_G5_IO2 /*!< TSC Group5 IO2 */ 384 #define TSC_GROUP5_IO3 TSC_IOCCR_G5_IO3 /*!< TSC Group5 IO3 */ 385 #define TSC_GROUP5_IO4 TSC_IOCCR_G5_IO4 /*!< TSC Group5 IO4 */ 386 387 #define TSC_GROUP6_IO1 TSC_IOCCR_G6_IO1 /*!< TSC Group6 IO1 */ 388 #define TSC_GROUP6_IO2 TSC_IOCCR_G6_IO2 /*!< TSC Group6 IO2 */ 389 #define TSC_GROUP6_IO3 TSC_IOCCR_G6_IO3 /*!< TSC Group6 IO3 */ 390 #define TSC_GROUP6_IO4 TSC_IOCCR_G6_IO4 /*!< TSC Group6 IO4 */ 391 392 #define TSC_GROUP7_IO1 TSC_IOCCR_G7_IO1 /*!< TSC Group7 IO1 */ 393 #define TSC_GROUP7_IO2 TSC_IOCCR_G7_IO2 /*!< TSC Group7 IO2 */ 394 #define TSC_GROUP7_IO3 TSC_IOCCR_G7_IO3 /*!< TSC Group7 IO3 */ 395 #define TSC_GROUP7_IO4 TSC_IOCCR_G7_IO4 /*!< TSC Group7 IO4 */ 396 397 #define TSC_GROUP8_IO1 TSC_IOCCR_G8_IO1 /*!< TSC Group8 IO1 */ 398 #define TSC_GROUP8_IO2 TSC_IOCCR_G8_IO2 /*!< TSC Group8 IO2 */ 399 #define TSC_GROUP8_IO3 TSC_IOCCR_G8_IO3 /*!< TSC Group8 IO3 */ 400 #define TSC_GROUP8_IO4 TSC_IOCCR_G8_IO4 /*!< TSC Group8 IO4 */ 401 /** 402 * @} 403 */ 404 405 /** 406 * @} 407 */ 408 409 /* Exported macros -----------------------------------------------------------*/ 410 411 /** @defgroup TSC_Exported_Macros TSC Exported Macros 412 * @{ 413 */ 414 415 /** @brief Reset TSC handle state. 416 * @param __HANDLE__ TSC handle 417 * @retval None 418 */ 419 #if (USE_HAL_TSC_REGISTER_CALLBACKS == 1) 420 #define __HAL_TSC_RESET_HANDLE_STATE(__HANDLE__) do{ \ 421 (__HANDLE__)->State = HAL_TSC_STATE_RESET; \ 422 (__HANDLE__)->MspInitCallback = NULL; \ 423 (__HANDLE__)->MspDeInitCallback = NULL; \ 424 } while(0) 425 #else 426 #define __HAL_TSC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_TSC_STATE_RESET) 427 #endif /* (USE_HAL_TSC_REGISTER_CALLBACKS == 1) */ 428 429 /** 430 * @brief Enable the TSC peripheral. 431 * @param __HANDLE__ TSC handle 432 * @retval None 433 */ 434 #define __HAL_TSC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= TSC_CR_TSCE) 435 436 /** 437 * @brief Disable the TSC peripheral. 438 * @param __HANDLE__ TSC handle 439 * @retval None 440 */ 441 #define __HAL_TSC_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= (~TSC_CR_TSCE)) 442 443 /** 444 * @brief Start acquisition. 445 * @param __HANDLE__ TSC handle 446 * @retval None 447 */ 448 #define __HAL_TSC_START_ACQ(__HANDLE__) ((__HANDLE__)->Instance->CR |= TSC_CR_START) 449 450 /** 451 * @brief Stop acquisition. 452 * @param __HANDLE__ TSC handle 453 * @retval None 454 */ 455 #define __HAL_TSC_STOP_ACQ(__HANDLE__) ((__HANDLE__)->Instance->CR &= (~TSC_CR_START)) 456 457 /** 458 * @brief Set IO default mode to output push-pull low. 459 * @param __HANDLE__ TSC handle 460 * @retval None 461 */ 462 #define __HAL_TSC_SET_IODEF_OUTPPLOW(__HANDLE__) ((__HANDLE__)->Instance->CR &= (~TSC_CR_IODEF)) 463 464 /** 465 * @brief Set IO default mode to input floating. 466 * @param __HANDLE__ TSC handle 467 * @retval None 468 */ 469 #define __HAL_TSC_SET_IODEF_INFLOAT(__HANDLE__) ((__HANDLE__)->Instance->CR |= TSC_CR_IODEF) 470 471 /** 472 * @brief Set synchronization polarity to falling edge. 473 * @param __HANDLE__ TSC handle 474 * @retval None 475 */ 476 #define __HAL_TSC_SET_SYNC_POL_FALL(__HANDLE__) ((__HANDLE__)->Instance->CR &= (~TSC_CR_SYNCPOL)) 477 478 /** 479 * @brief Set synchronization polarity to rising edge and high level. 480 * @param __HANDLE__ TSC handle 481 * @retval None 482 */ 483 #define __HAL_TSC_SET_SYNC_POL_RISE_HIGH(__HANDLE__) ((__HANDLE__)->Instance->CR |= TSC_CR_SYNCPOL) 484 485 /** 486 * @brief Enable TSC interrupt. 487 * @param __HANDLE__ TSC handle 488 * @param __INTERRUPT__ TSC interrupt 489 * @retval None 490 */ 491 #define __HAL_TSC_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__)) 492 493 /** 494 * @brief Disable TSC interrupt. 495 * @param __HANDLE__ TSC handle 496 * @param __INTERRUPT__ TSC interrupt 497 * @retval None 498 */ 499 #define __HAL_TSC_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= (~(__INTERRUPT__))) 500 501 /** @brief Check whether the specified TSC interrupt source is enabled or not. 502 * @param __HANDLE__ TSC Handle 503 * @param __INTERRUPT__ TSC interrupt 504 * @retval SET or RESET 505 */ 506 #define __HAL_TSC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER\ 507 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET :\ 508 RESET) 509 510 /** 511 * @brief Check whether the specified TSC flag is set or not. 512 * @param __HANDLE__ TSC handle 513 * @param __FLAG__ TSC flag 514 * @retval SET or RESET 515 */ 516 #define __HAL_TSC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->ISR\ 517 & (__FLAG__)) == (__FLAG__)) ? SET : RESET) 518 519 /** 520 * @brief Clear the TSC's pending flag. 521 * @param __HANDLE__ TSC handle 522 * @param __FLAG__ TSC flag 523 * @retval None 524 */ 525 #define __HAL_TSC_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__)) 526 527 /** 528 * @brief Enable schmitt trigger hysteresis on a group of IOs. 529 * @param __HANDLE__ TSC handle 530 * @param __GX_IOY_MASK__ IOs mask 531 * @retval None 532 */ 533 #define __HAL_TSC_ENABLE_HYSTERESIS(__HANDLE__, __GX_IOY_MASK__) ((__HANDLE__)->Instance->IOHCR |= (__GX_IOY_MASK__)) 534 535 /** 536 * @brief Disable schmitt trigger hysteresis on a group of IOs. 537 * @param __HANDLE__ TSC handle 538 * @param __GX_IOY_MASK__ IOs mask 539 * @retval None 540 */ 541 #define __HAL_TSC_DISABLE_HYSTERESIS(__HANDLE__, __GX_IOY_MASK__) ((__HANDLE__)->Instance->IOHCR\ 542 &= (~(__GX_IOY_MASK__))) 543 544 /** 545 * @brief Open analog switch on a group of IOs. 546 * @param __HANDLE__ TSC handle 547 * @param __GX_IOY_MASK__ IOs mask 548 * @retval None 549 */ 550 #define __HAL_TSC_OPEN_ANALOG_SWITCH(__HANDLE__, __GX_IOY_MASK__) ((__HANDLE__)->Instance->IOASCR\ 551 &= (~(__GX_IOY_MASK__))) 552 553 /** 554 * @brief Close analog switch on a group of IOs. 555 * @param __HANDLE__ TSC handle 556 * @param __GX_IOY_MASK__ IOs mask 557 * @retval None 558 */ 559 #define __HAL_TSC_CLOSE_ANALOG_SWITCH(__HANDLE__, __GX_IOY_MASK__) ((__HANDLE__)->Instance->IOASCR |= (__GX_IOY_MASK__)) 560 561 /** 562 * @brief Enable a group of IOs in channel mode. 563 * @param __HANDLE__ TSC handle 564 * @param __GX_IOY_MASK__ IOs mask 565 * @retval None 566 */ 567 #define __HAL_TSC_ENABLE_CHANNEL(__HANDLE__, __GX_IOY_MASK__) ((__HANDLE__)->Instance->IOCCR |= (__GX_IOY_MASK__)) 568 569 /** 570 * @brief Disable a group of channel IOs. 571 * @param __HANDLE__ TSC handle 572 * @param __GX_IOY_MASK__ IOs mask 573 * @retval None 574 */ 575 #define __HAL_TSC_DISABLE_CHANNEL(__HANDLE__, __GX_IOY_MASK__) ((__HANDLE__)->Instance->IOCCR\ 576 &= (~(__GX_IOY_MASK__))) 577 578 /** 579 * @brief Enable a group of IOs in sampling mode. 580 * @param __HANDLE__ TSC handle 581 * @param __GX_IOY_MASK__ IOs mask 582 * @retval None 583 */ 584 #define __HAL_TSC_ENABLE_SAMPLING(__HANDLE__, __GX_IOY_MASK__) ((__HANDLE__)->Instance->IOSCR |= (__GX_IOY_MASK__)) 585 586 /** 587 * @brief Disable a group of sampling IOs. 588 * @param __HANDLE__ TSC handle 589 * @param __GX_IOY_MASK__ IOs mask 590 * @retval None 591 */ 592 #define __HAL_TSC_DISABLE_SAMPLING(__HANDLE__, __GX_IOY_MASK__) ((__HANDLE__)->Instance->IOSCR &= (~(__GX_IOY_MASK__))) 593 594 /** 595 * @brief Enable acquisition groups. 596 * @param __HANDLE__ TSC handle 597 * @param __GX_MASK__ Groups mask 598 * @retval None 599 */ 600 #define __HAL_TSC_ENABLE_GROUP(__HANDLE__, __GX_MASK__) ((__HANDLE__)->Instance->IOGCSR |= (__GX_MASK__)) 601 602 /** 603 * @brief Disable acquisition groups. 604 * @param __HANDLE__ TSC handle 605 * @param __GX_MASK__ Groups mask 606 * @retval None 607 */ 608 #define __HAL_TSC_DISABLE_GROUP(__HANDLE__, __GX_MASK__) ((__HANDLE__)->Instance->IOGCSR &= (~(__GX_MASK__))) 609 610 /** @brief Gets acquisition group status. 611 * @param __HANDLE__ TSC Handle 612 * @param __GX_INDEX__ Group index 613 * @retval SET or RESET 614 */ 615 #define __HAL_TSC_GET_GROUP_STATUS(__HANDLE__, __GX_INDEX__) \ 616 ((((__HANDLE__)->Instance->IOGCSR & (uint32_t)(1UL << (((__GX_INDEX__) & 0xFUL) + 16UL))) == \ 617 (uint32_t)(1UL << (((__GX_INDEX__) & 0xFUL) + 16UL))) ? TSC_GROUP_COMPLETED : TSC_GROUP_ONGOING) 618 619 /** 620 * @} 621 */ 622 623 /* Private macros ------------------------------------------------------------*/ 624 625 /** @defgroup TSC_Private_Macros TSC Private Macros 626 * @{ 627 */ 628 629 #define IS_TSC_CTPH(__VALUE__) (((__VALUE__) == TSC_CTPH_1CYCLE) || \ 630 ((__VALUE__) == TSC_CTPH_2CYCLES) || \ 631 ((__VALUE__) == TSC_CTPH_3CYCLES) || \ 632 ((__VALUE__) == TSC_CTPH_4CYCLES) || \ 633 ((__VALUE__) == TSC_CTPH_5CYCLES) || \ 634 ((__VALUE__) == TSC_CTPH_6CYCLES) || \ 635 ((__VALUE__) == TSC_CTPH_7CYCLES) || \ 636 ((__VALUE__) == TSC_CTPH_8CYCLES) || \ 637 ((__VALUE__) == TSC_CTPH_9CYCLES) || \ 638 ((__VALUE__) == TSC_CTPH_10CYCLES) || \ 639 ((__VALUE__) == TSC_CTPH_11CYCLES) || \ 640 ((__VALUE__) == TSC_CTPH_12CYCLES) || \ 641 ((__VALUE__) == TSC_CTPH_13CYCLES) || \ 642 ((__VALUE__) == TSC_CTPH_14CYCLES) || \ 643 ((__VALUE__) == TSC_CTPH_15CYCLES) || \ 644 ((__VALUE__) == TSC_CTPH_16CYCLES)) 645 646 #define IS_TSC_CTPL(__VALUE__) (((__VALUE__) == TSC_CTPL_1CYCLE) || \ 647 ((__VALUE__) == TSC_CTPL_2CYCLES) || \ 648 ((__VALUE__) == TSC_CTPL_3CYCLES) || \ 649 ((__VALUE__) == TSC_CTPL_4CYCLES) || \ 650 ((__VALUE__) == TSC_CTPL_5CYCLES) || \ 651 ((__VALUE__) == TSC_CTPL_6CYCLES) || \ 652 ((__VALUE__) == TSC_CTPL_7CYCLES) || \ 653 ((__VALUE__) == TSC_CTPL_8CYCLES) || \ 654 ((__VALUE__) == TSC_CTPL_9CYCLES) || \ 655 ((__VALUE__) == TSC_CTPL_10CYCLES) || \ 656 ((__VALUE__) == TSC_CTPL_11CYCLES) || \ 657 ((__VALUE__) == TSC_CTPL_12CYCLES) || \ 658 ((__VALUE__) == TSC_CTPL_13CYCLES) || \ 659 ((__VALUE__) == TSC_CTPL_14CYCLES) || \ 660 ((__VALUE__) == TSC_CTPL_15CYCLES) || \ 661 ((__VALUE__) == TSC_CTPL_16CYCLES)) 662 663 #define IS_TSC_SS(__VALUE__) (((FunctionalState)(__VALUE__) == DISABLE)\ 664 || ((FunctionalState)(__VALUE__) == ENABLE)) 665 666 #define IS_TSC_SSD(__VALUE__) (((__VALUE__) == 0UL) || (((__VALUE__) > 0UL) && ((__VALUE__) < 128UL))) 667 668 #define IS_TSC_SS_PRESC(__VALUE__) (((__VALUE__) == TSC_SS_PRESC_DIV1) || ((__VALUE__) == TSC_SS_PRESC_DIV2)) 669 670 #define IS_TSC_PG_PRESC(__VALUE__) (((__VALUE__) == TSC_PG_PRESC_DIV1) || \ 671 ((__VALUE__) == TSC_PG_PRESC_DIV2) || \ 672 ((__VALUE__) == TSC_PG_PRESC_DIV4) || \ 673 ((__VALUE__) == TSC_PG_PRESC_DIV8) || \ 674 ((__VALUE__) == TSC_PG_PRESC_DIV16) || \ 675 ((__VALUE__) == TSC_PG_PRESC_DIV32) || \ 676 ((__VALUE__) == TSC_PG_PRESC_DIV64) || \ 677 ((__VALUE__) == TSC_PG_PRESC_DIV128)) 678 679 #define IS_TSC_PG_PRESC_VS_CTPL(__PGPSC__, __CTPL__) ((((__PGPSC__) == TSC_PG_PRESC_DIV1) && \ 680 ((__CTPL__) > TSC_CTPL_2CYCLES)) || \ 681 (((__PGPSC__) == TSC_PG_PRESC_DIV2) && \ 682 ((__CTPL__) > TSC_CTPL_1CYCLE)) || \ 683 (((__PGPSC__) > TSC_PG_PRESC_DIV2) && \ 684 (((__CTPL__) == TSC_CTPL_1CYCLE) || \ 685 ((__CTPL__) > TSC_CTPL_1CYCLE)))) 686 687 #define IS_TSC_MCV(__VALUE__) (((__VALUE__) == TSC_MCV_255) || \ 688 ((__VALUE__) == TSC_MCV_511) || \ 689 ((__VALUE__) == TSC_MCV_1023) || \ 690 ((__VALUE__) == TSC_MCV_2047) || \ 691 ((__VALUE__) == TSC_MCV_4095) || \ 692 ((__VALUE__) == TSC_MCV_8191) || \ 693 ((__VALUE__) == TSC_MCV_16383)) 694 695 #define IS_TSC_IODEF(__VALUE__) (((__VALUE__) == TSC_IODEF_OUT_PP_LOW) || ((__VALUE__) == TSC_IODEF_IN_FLOAT)) 696 697 #define IS_TSC_SYNC_POL(__VALUE__) (((__VALUE__) == TSC_SYNC_POLARITY_FALLING)\ 698 || ((__VALUE__) == TSC_SYNC_POLARITY_RISING)) 699 700 #define IS_TSC_ACQ_MODE(__VALUE__) (((__VALUE__) == TSC_ACQ_MODE_NORMAL) || ((__VALUE__) == TSC_ACQ_MODE_SYNCHRO)) 701 702 #define IS_TSC_MCE_IT(__VALUE__) (((FunctionalState)(__VALUE__) == DISABLE)\ 703 || ((FunctionalState)(__VALUE__) == ENABLE)) 704 705 #define IS_TSC_GROUP_INDEX(__VALUE__) (((__VALUE__) == 0UL)\ 706 || (((__VALUE__) > 0UL) && ((__VALUE__) < (uint32_t)TSC_NB_OF_GROUPS))) 707 708 #define IS_TSC_GROUP(__VALUE__) (((__VALUE__) == 0UL) ||\ 709 (((__VALUE__) & TSC_GROUP1_IO1) == TSC_GROUP1_IO1) ||\ 710 (((__VALUE__) & TSC_GROUP1_IO2) == TSC_GROUP1_IO2) ||\ 711 (((__VALUE__) & TSC_GROUP1_IO3) == TSC_GROUP1_IO3) ||\ 712 (((__VALUE__) & TSC_GROUP1_IO4) == TSC_GROUP1_IO4) ||\ 713 (((__VALUE__) & TSC_GROUP2_IO1) == TSC_GROUP2_IO1) ||\ 714 (((__VALUE__) & TSC_GROUP2_IO2) == TSC_GROUP2_IO2) ||\ 715 (((__VALUE__) & TSC_GROUP2_IO3) == TSC_GROUP2_IO3) ||\ 716 (((__VALUE__) & TSC_GROUP2_IO4) == TSC_GROUP2_IO4) ||\ 717 (((__VALUE__) & TSC_GROUP3_IO1) == TSC_GROUP3_IO1) ||\ 718 (((__VALUE__) & TSC_GROUP3_IO2) == TSC_GROUP3_IO2) ||\ 719 (((__VALUE__) & TSC_GROUP3_IO3) == TSC_GROUP3_IO3) ||\ 720 (((__VALUE__) & TSC_GROUP3_IO4) == TSC_GROUP3_IO4) ||\ 721 (((__VALUE__) & TSC_GROUP4_IO1) == TSC_GROUP4_IO1) ||\ 722 (((__VALUE__) & TSC_GROUP4_IO2) == TSC_GROUP4_IO2) ||\ 723 (((__VALUE__) & TSC_GROUP4_IO3) == TSC_GROUP4_IO3) ||\ 724 (((__VALUE__) & TSC_GROUP4_IO4) == TSC_GROUP4_IO4) ||\ 725 (((__VALUE__) & TSC_GROUP5_IO1) == TSC_GROUP5_IO1) ||\ 726 (((__VALUE__) & TSC_GROUP5_IO2) == TSC_GROUP5_IO2) ||\ 727 (((__VALUE__) & TSC_GROUP5_IO3) == TSC_GROUP5_IO3) ||\ 728 (((__VALUE__) & TSC_GROUP5_IO4) == TSC_GROUP5_IO4) ||\ 729 (((__VALUE__) & TSC_GROUP6_IO1) == TSC_GROUP6_IO1) ||\ 730 (((__VALUE__) & TSC_GROUP6_IO2) == TSC_GROUP6_IO2) ||\ 731 (((__VALUE__) & TSC_GROUP6_IO3) == TSC_GROUP6_IO3) ||\ 732 (((__VALUE__) & TSC_GROUP6_IO4) == TSC_GROUP6_IO4) ||\ 733 (((__VALUE__) & TSC_GROUP7_IO1) == TSC_GROUP7_IO1) ||\ 734 (((__VALUE__) & TSC_GROUP7_IO2) == TSC_GROUP7_IO2) ||\ 735 (((__VALUE__) & TSC_GROUP7_IO3) == TSC_GROUP7_IO3) ||\ 736 (((__VALUE__) & TSC_GROUP7_IO4) == TSC_GROUP7_IO4) ||\ 737 (((__VALUE__) & TSC_GROUP8_IO1) == TSC_GROUP8_IO1) ||\ 738 (((__VALUE__) & TSC_GROUP8_IO2) == TSC_GROUP8_IO2) ||\ 739 (((__VALUE__) & TSC_GROUP8_IO3) == TSC_GROUP8_IO3) ||\ 740 (((__VALUE__) & TSC_GROUP8_IO4) == TSC_GROUP8_IO4)) 741 /** 742 * @} 743 */ 744 745 /* Exported functions --------------------------------------------------------*/ 746 /** @addtogroup TSC_Exported_Functions 747 * @{ 748 */ 749 750 /** @addtogroup TSC_Exported_Functions_Group1 Initialization and de-initialization functions 751 * @{ 752 */ 753 /* Initialization and de-initialization functions *****************************/ 754 HAL_StatusTypeDef HAL_TSC_Init(TSC_HandleTypeDef *htsc); 755 HAL_StatusTypeDef HAL_TSC_DeInit(TSC_HandleTypeDef *htsc); 756 void HAL_TSC_MspInit(TSC_HandleTypeDef *htsc); 757 void HAL_TSC_MspDeInit(TSC_HandleTypeDef *htsc); 758 759 /* Callbacks Register/UnRegister functions ***********************************/ 760 #if (USE_HAL_TSC_REGISTER_CALLBACKS == 1) 761 HAL_StatusTypeDef HAL_TSC_RegisterCallback(TSC_HandleTypeDef *htsc, HAL_TSC_CallbackIDTypeDef CallbackID, 762 pTSC_CallbackTypeDef pCallback); 763 HAL_StatusTypeDef HAL_TSC_UnRegisterCallback(TSC_HandleTypeDef *htsc, HAL_TSC_CallbackIDTypeDef CallbackID); 764 #endif /* USE_HAL_TSC_REGISTER_CALLBACKS */ 765 /** 766 * @} 767 */ 768 769 /** @addtogroup TSC_Exported_Functions_Group2 Input and Output operation functions 770 * @{ 771 */ 772 /* IO operation functions *****************************************************/ 773 HAL_StatusTypeDef HAL_TSC_Start(TSC_HandleTypeDef *htsc); 774 HAL_StatusTypeDef HAL_TSC_Start_IT(TSC_HandleTypeDef *htsc); 775 HAL_StatusTypeDef HAL_TSC_Stop(TSC_HandleTypeDef *htsc); 776 HAL_StatusTypeDef HAL_TSC_Stop_IT(TSC_HandleTypeDef *htsc); 777 HAL_StatusTypeDef HAL_TSC_PollForAcquisition(TSC_HandleTypeDef *htsc); 778 TSC_GroupStatusTypeDef HAL_TSC_GroupGetStatus(const TSC_HandleTypeDef *htsc, uint32_t gx_index); 779 uint32_t HAL_TSC_GroupGetValue(const TSC_HandleTypeDef *htsc, uint32_t gx_index); 780 /** 781 * @} 782 */ 783 784 /** @addtogroup TSC_Exported_Functions_Group3 Peripheral Control functions 785 * @{ 786 */ 787 /* Peripheral Control functions ***********************************************/ 788 HAL_StatusTypeDef HAL_TSC_IOConfig(TSC_HandleTypeDef *htsc, const TSC_IOConfigTypeDef *config); 789 HAL_StatusTypeDef HAL_TSC_IODischarge(TSC_HandleTypeDef *htsc, FunctionalState choice); 790 /** 791 * @} 792 */ 793 794 /** @addtogroup TSC_Exported_Functions_Group4 Peripheral State and Errors functions 795 * @{ 796 */ 797 /* Peripheral State and Error functions ***************************************/ 798 HAL_TSC_StateTypeDef HAL_TSC_GetState(TSC_HandleTypeDef *htsc); 799 /** 800 * @} 801 */ 802 803 /** @addtogroup TSC_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks 804 * @{ 805 */ 806 /******* TSC IRQHandler and Callbacks used in Interrupt mode */ 807 void HAL_TSC_IRQHandler(TSC_HandleTypeDef *htsc); 808 void HAL_TSC_ConvCpltCallback(TSC_HandleTypeDef *htsc); 809 void HAL_TSC_ErrorCallback(TSC_HandleTypeDef *htsc); 810 /** 811 * @} 812 */ 813 814 /** 815 * @} 816 */ 817 818 /** 819 * @} 820 */ 821 822 /** 823 * @} 824 */ 825 826 #ifdef __cplusplus 827 } 828 #endif 829 830 #endif /* STM32F3xx_HAL_TSC_H */ 831