1 /*! 2 * @file tsc_config.h 3 * 4 * @brief Acquisition parameters for APM32F0xx products. 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 __TSC_CONFIG_H 28 #define __TSC_CONFIG_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /** @addtogroup TSC_Driver_Library TSC Driver Library 35 @{ 36 */ 37 38 /** @addtogroup TSC_Config_Driver TSC Config Driver 39 @{ 40 */ 41 42 /** @defgroup TSC_Config_Macros Macros 43 @{ 44 */ 45 46 /** @defgroup Common_Parameters_Number_Of_Elements 47 @{ 48 */ 49 50 /* The number of channels (1..24) */ 51 #define TOUCH_TOTAL_CHANNELS (11) 52 53 /* The number of blocks (1..8) */ 54 #define TOUCH_TOTAL_BLOCKS (3) 55 56 /* The number of "Extended" TouchKeys (0..24) */ 57 #define TOUCH_TOTAL_TOUCHKEYS (5) 58 59 /* The number of "Basic" TouchKeys (0..24) */ 60 #define TOUCH_TOTAL_TOUCHKEYS_B (0) 61 62 /* The number of "Extended" Linear and Rotary sensors (0..24) */ 63 #define TOUCH_TOTAL_LINROTS (2) 64 65 /* The number of "Basic" Linear and Rotary sensors (0..24) */ 66 #define TOUCH_TOTAL_LINROTS_B (0) 67 68 /** The number of sensors/objects (1..24) 69 * - Count all TouchKeys, Linear and Rotary sensors 70 */ 71 #define TOUCH_TOTAL_OBJECTS (7) 72 73 /**@} Common_Parameters_Number_Of_Elements */ 74 75 /** @defgroup Common_Parameters_Optional_Features 76 @{ 77 */ 78 79 /** Record the last measure (0=No, 1=Yes) 80 * - If No the measure is recalculated using the Reference and Delta 81 */ 82 #define TOUCH_USE_MEAS (1) 83 84 /* Zone management usage (0=No, 1=Yes) */ 85 #define TOUCH_USE_ZONE (0) 86 87 /* Proximity detection usage (0=No, 1=Yes) */ 88 #define TOUCH_USE_PROX (1) 89 90 /** Use the Timer tick callback (0=No, 1=Yes) 91 * - When equal to 1, the function TSC_CallBack_TimerTick 92 */ 93 #define TOUCH_USE_TIMER_CALLBACK (0) 94 95 /** Acquisition interrupt mode (0=No, 1=Yes) 96 * - If No the TSC interrupt is not used. 97 * - If Yes the TSC interrupt is used. 98 */ 99 #define TOUCH_USE_ACQ_INTERRUPT (0) 100 101 /**@} Common_Parameters_Optional_Features */ 102 103 /** @defgroup Common_Parameters_Acquisition_limits 104 @{ 105 */ 106 107 /** Minimum acquisition measurement (0..65535) 108 * - This is the minimum acceptable value for the acquisition measure. 109 * - The acquisition will be in error if the measure is below this value. 110 */ 111 #define TOUCH_ACQ_MIN (10) 112 113 /** Maximum acquisition measurement (255, 511, 1023, 2047, 8191, 16383) 114 * - This is the maximum acceptable value for the acquisition measure. 115 * - The acquisition will be in error if the measure is above this value. 116 */ 117 #define TOUCH_ACQ_MAX (8191) 118 119 /**@} Common_Parameters_Acquisition_limits */ 120 121 /** @defgroup Common_Parameters_Calibration 122 @{ 123 */ 124 /** Number of calibration samples (4, 8, 16) 125 * - Low value = faster calibration but less precision. 126 * - High value = slower calibration but more precision. 127 */ 128 #define TOUCH_CALIB_SAMPLES (16) 129 130 /** Delay in measurement samples before starting the calibration (0..40) 131 * - This is useful if a noise filter is used. 132 * - Write 0 to disable the delay. 133 */ 134 #define TOUCH_CALIB_DELAY (0) 135 136 /**@} Common_Parameters_Calibration */ 137 138 /** @defgroup Common_Parameters_Thresholds_for_TouchKey 139 @{ 140 */ 141 142 /** TouchKeys Proximity state input threshold (0..255) 143 * - Enter Proximity state if delta is above 144 */ 145 #define TOUCH_KEY_PROX_IN_TH (10) 146 147 /** TouchKeys Proximity state output threshold (0..255) 148 * - Exit Proximity state if delta is below 149 */ 150 #define TOUCH_KEY_PROX_OUT_TH (5) 151 152 /** TouchKeys Detect state input threshold (0..255) 153 * - Enter Detect state if delta is above 154 */ 155 #define TOUCH_KEY_DETECT_IN_TH (200) 156 157 /** TouchKeys Detect state output threshold (0..255) 158 * - Exit Detect state if delta is below 159 */ 160 #define TOUCH_KEY_DETECT_OUT_TH (150) 161 162 /** TouchKeys re-Calibration threshold (0..255) 163 * - @warning The value is inverted in the sensor state machine 164 * - Enter Calibration state if delta is below 165 */ 166 #define TOUCH_KEY_CALIB_TH (150) 167 168 /** TouchKey, Linear and Rotary sensors thresholds coefficient (0..4) 169 * This multiplier coefficient is applied on Detect and Re-Calibration thresholds only. 170 * - 0: disabled 171 * - 1: thresholds x 2 172 * - 2: thresholds x 4 173 * - 3: thresholds x 8 174 * - 4: thresholds x 16 175 */ 176 #define TOUCH_COEFF_TH (0) 177 178 /**@} Common_Parameters_Thresholds_for_TouchKey */ 179 180 /** @defgroup Common_Parameters_Thresholds_For_Linear_Rotary 181 @{ 182 */ 183 184 /** Linear/Rotary Proximity state input threshold (0..255) 185 * - Enter Proximity state if delta is above 186 */ 187 #define TOUCH_LINROT_PROX_IN_TH (10) 188 189 /** Linear/Rotary Proximity state output threshold (0..255) 190 * - Exit Proximity state if delta is below 191 */ 192 #define TOUCH_LINROT_PROX_OUT_TH (5) 193 194 /** Linear/Rotary Detect state input threshold (0..255) 195 * - Enter Detect state if delta is above 196 */ 197 #define TOUCH_LINROT_DETECT_IN_TH (20) 198 199 /** Linear/Rotary Detect state output threshold (0..255) 200 * - Exit Detect state if delta is below 201 */ 202 #define TOUCH_LINROT_DETECT_OUT_TH (15) 203 204 /** Linear/Rotary Re-Calibration threshold (0..255) 205 * - @warning The value is inverted in the sensor state machine 206 * - Enter Calibration state if delta is below 207 */ 208 #define TOUCH_LINROT_CALIB_TH (30) 209 210 /** Linear/Rotary Delta normalization (0=No, 1=Yes) 211 * - When this parameter is set, a coefficient is applied on all Delta of all sensors 212 * in order to normalize them and to improve the position calculation. 213 * - These coefficients must be defined in a constant table 214 * - The MSB is the coefficient integer part, the LSB is the coefficient real part. 215 * Examples: 216 * - To apply a factor 1.10: 217 * 0x01 to the MSB 218 * 0x1A to the LSB (0.10 x 256 = 25.6 -> rounded to 26 = 0x1A) 219 * - To apply a factor 0.90: 220 * 0x00 to the MSB 221 * 0xE6 to the LSB (0.90 x 256 = 230.4 -> rounded to 230 = 0xE6) 222 */ 223 #define TOUCH_LINROT_USE_NORMDELTA (0) 224 225 /**@} Common_Parameters_Thresholds_For_Linear_Rotary */ 226 227 /** @defgroup Common_Parameters_Used_Linear_Rotary 228 @{ 229 */ 230 231 /** Select which Linear and Rotary sensors you use in your application. 232 * - 0 = Not Used 233 * - 1 = Used 234 * 235 * LIN = Linear sensor 236 * ROT = Rotary sensor 237 * M1 = Mono electrodes design with 0/255 position at extremities of the sensor 238 * M2 = Mono electrodes design 239 * H = Half-ended electrodes design 240 * D = Dual electrodes design 241 */ 242 #define TOUCH_USE_3CH_LIN_M1 (1) 243 #define TOUCH_USE_3CH_LIN_M2 (1) 244 #define TOUCH_USE_3CH_LIN_H (1) 245 #define TOUCH_USE_3CH_ROT_M (1) 246 247 #define TOUCH_USE_4CH_LIN_M1 (1) 248 #define TOUCH_USE_4CH_LIN_M2 (1) 249 #define TOUCH_USE_4CH_LIN_H (1) 250 #define TOUCH_USE_4CH_ROT_M (1) 251 252 #define TOUCH_USE_5CH_LIN_M1 (1) 253 #define TOUCH_USE_5CH_LIN_M2 (1) 254 #define TOUCH_USE_5CH_LIN_H (1) 255 #define TOUCH_USE_5CH_ROT_M (1) 256 #define TOUCH_USE_5CH_ROT_D (1) 257 258 #define TOUCH_USE_6CH_LIN_M1 (1) 259 #define TOUCH_USE_6CH_LIN_M2 (1) 260 #define TOUCH_USE_6CH_LIN_H (1) 261 #define TOUCH_USE_6CH_ROT_M (1) 262 263 /**@} Common_Parameters_Used_Linear_Rotary */ 264 265 /** @defgroup Common_Parameters_Position_Linear_Rotary 266 @{ 267 */ 268 269 /** Position resolution in number of bits (1..8) 270 * - A Low value will result in a low resolution and will be less subject to noise. 271 * - A High value will result in a high resolution and will be more subject to noise. 272 */ 273 #define TOUCH_LINROT_RESOLUTION (7) 274 275 /** Direction change threshold in position unit (0..255) 276 * - Defines the default threshold used during the change direction process. 277 * - A Low value will result in a faster direction change. 278 * - A High value will result in a slower direction change. 279 */ 280 #define TOUCH_LINROT_DIR_CHG_POS (10) 281 282 /** Direction change debounce (0..63) 283 * - Defines the default integrator counter used during the change direction process. 284 * - This counter is decremented when the same change in the position is detected and the direction will 285 * change after this counter reaches zero. 286 * - A Low value will result in a faster direction change. 287 * - A High value will result in a slower direction change. 288 */ 289 #define TOUCH_LINROT_DIR_CHG_DEB (1) 290 291 /**@} Common_Parameters_Position_Linear_Rotary */ 292 293 /** @defgroup Common_Parameters_Debounce_Counters 294 @{ 295 */ 296 297 /** Proximity state debounce in samples unit (0..63) 298 * - A Low value will result in a higher sensitivity during the Proximity detection but with less noise filtering. 299 * - A High value will result in improving the system noise immunity but will increase the system response time. 300 */ 301 #define TOUCH_DEBOUNCE_PROX (3) 302 303 /** Detect state debounce in samples unit (0..63) 304 * - A Low value will result in a higher sensitivity during the detection but with less noise filtering. 305 * - A High value will result in improving the system noise immunity but will increase the system response time. 306 */ 307 #define TOUCH_DEBOUNCE_DETECT (3) 308 309 /** Release state debounce in samples unit (0..63) 310 * - A Low value will result in a higher sensitivity during the end-detection but with less noise filtering. 311 * - A High value will result in a lower sensitivity during the end-detection but with more noise filtering. 312 */ 313 #define TOUCH_DEBOUNCE_RELEASE (3) 314 315 /** Re-calibration state debounce in samples unit (0..63) 316 * - A Low value will result in a higher sensitivity during the recalibration but with less noise filtering. 317 * - A High value will result in a lower sensitivity during the recalibration but with more noise filtering. 318 */ 319 #define TOUCH_DEBOUNCE_CALIB (3) 320 321 /** Error state debounce in samples unit (0..63) 322 * - A Low value will result in a higher sensitivity to enter in error state. 323 * - A High value will result in a lower sensitivity to enter in error state. 324 */ 325 #define TOUCH_DEBOUNCE_ERROR (3) 326 327 /**@} Common_Parameters_Debounce_Counters */ 328 329 /** @defgroup Common_Parameters_Environment_Change_System (ECS) 330 @{ 331 */ 332 333 /** Environment Change System Different K factor (0..255) 334 * - The higher value is K, the faster is the response time. 335 */ 336 #define TOUCH_ECS_K_DIFFER (10) 337 338 /** Environment Change System Same K factor (0..255) 339 * - The higher value is K, the faster is the response time. 340 */ 341 #define TOUCH_ECS_K_SAME (20) 342 343 /** Environment Change System delay in msec (0..5000) 344 * - The ECS will be started after this delay and when all sensors are in Release state. 345 */ 346 #define TOUCH_ECS_DELAY (500) 347 348 /**@} Common_Parameters_Environment_Change_System */ 349 350 /** @defgroup Common_Parameters_Detection_Time_Out (DTO) 351 @{ 352 */ 353 354 /** Detection Time Out delay in seconds (0..63) 355 * - Value 0: DTO processing not compiled in the code (to gain size if not used). 356 * - Value 1: Default time out infinite. 357 * - Value between 2 and 63: Default time out between value n-1 and n. 358 * - Examples: 359 * - With a DTO equal to 2, the time out is between 1s and 2s. 360 * - With a DTO equal to 63, the time out is between 62s and 63s. 361 * 362 *@note The DTO can be changed in run-time by the application only if the 363 * default value is between 1 and 63. 364 */ 365 #define TOUCH_DTO (0) 366 367 /**@} Common_Parameters_Detection_Time_Out */ 368 369 /** @defgroup Common_Parameters_Detection_Exclusion_System (DXS) 370 @{ 371 */ 372 373 /** Detection Exclusion System (0=No, 1=Yes) */ 374 #define TOUCH_USE_DXS (0) 375 376 /**@} Common_Parameters_Detection_Exclusion_System */ 377 378 /** @defgroup Common_Parameters_Miscellaneous_Parameters 379 @{ 380 */ 381 382 /** Timing tick frequency in Hz (125, 250, 500, 1000, 2000) 383 * - Result to a timing interrupt respectively every 8ms, 4ms, 2ms, 1ms, 0.5ms 384 */ 385 #define TOUCH_TICK_FREQ (1000) 386 387 /** Delay for discharging Cx and Cs capacitors (0..65535) 388 * - The value corresponds to the Softdelay function parameter. 389 * - 500 gives around 53 delay whatever HCLK 390 * - 1000 gives around 106 delay whatever HCLK 391 * - 2000 gives around 210 delay whatever HCLK 392 */ 393 #define TOUCH_DELAY_DISCHARGE_ALL (1000) 394 395 /**@} Common_Parameters_Miscellaneous_Parameters */ 396 397 /** @defgroup APM32F0xx_Parameters_GPIOs_Configuration 398 @{ 399 */ 400 401 /** TSC GPIOs Configuration selection (0..1) 402 * - 0: Manual. The TSC GPIOs configuration must be done by the application code. 403 * - 1: Automatic. The TOUCH_TSC_GROUPx_IOy parameters below must be filled up. 404 * The TSC GPIOs configuration is automatically done by the Touch driver. 405 */ 406 #define TOUCH_TSC_GPIO_CONFIG (1) 407 408 /* DO NOT CHANGE THESE VALUES */ 409 /* These defines must be applied to the TOUCH_TSC_GROUPx_IOy parameters below */ 410 #define NU (0) /*!< Not Used IO */ 411 #define CHANNEL (1) /*!< Channel IO */ 412 #define SHIELD (2) /*!< Shield IO (= Channel IO but not acquired) */ 413 #define SAMPCAP (3) /*!< Sampling Capacitor IO */ 414 415 /* If TOUCH_TSC_GPIO_CONFIG=0 these parameters are ignored */ 416 /* If TOUCH_TSC_GPIO_CONFIG=1 assign each TOUCH_TSC_GROUPx_IOy parameters below */ 417 418 #define TOUCH_TSC_GROUP1_IO1 SAMPCAP /*!< PA0 */ 419 #define TOUCH_TSC_GROUP1_IO2 CHANNEL /*!< PA1 */ 420 #define TOUCH_TSC_GROUP1_IO3 CHANNEL /*!< PA2 */ 421 #define TOUCH_TSC_GROUP1_IO4 NU /*!< PA3 */ 422 423 #define TOUCH_TSC_GROUP2_IO1 SAMPCAP /*!< PA4 */ 424 #define TOUCH_TSC_GROUP2_IO2 CHANNEL /*!< PA5 */ 425 #define TOUCH_TSC_GROUP2_IO3 CHANNEL /*!< PA6 */ 426 #define TOUCH_TSC_GROUP2_IO4 CHANNEL /*!< PA7 */ 427 428 #define TOUCH_TSC_GROUP3_IO1 SAMPCAP /*!< PC5 */ 429 #define TOUCH_TSC_GROUP3_IO2 NU /*!< PB0 */ 430 #define TOUCH_TSC_GROUP3_IO3 CHANNEL /*!< PB1 */ 431 #define TOUCH_TSC_GROUP3_IO4 CHANNEL /*!< PB2 */ 432 433 #define TOUCH_TSC_GROUP4_IO1 SAMPCAP /*!< PA9 */ 434 #define TOUCH_TSC_GROUP4_IO2 NU /*!< PA10 */ 435 #define TOUCH_TSC_GROUP4_IO3 CHANNEL /*!< PA11 */ 436 #define TOUCH_TSC_GROUP4_IO4 CHANNEL /*!< PA12 */ 437 438 #define TOUCH_TSC_GROUP5_IO1 NU /*!< PB3 */ 439 #define TOUCH_TSC_GROUP5_IO2 NU /*!< PB4 */ 440 #define TOUCH_TSC_GROUP5_IO3 NU /*!< PB6 */ 441 #define TOUCH_TSC_GROUP5_IO4 NU /*!< PB7 */ 442 443 #define TOUCH_TSC_GROUP6_IO1 SAMPCAP /*!< PB11 */ 444 #define TOUCH_TSC_GROUP6_IO2 NU /*!< PB12 */ 445 #define TOUCH_TSC_GROUP6_IO3 CHANNEL /*!< PB13 */ 446 #define TOUCH_TSC_GROUP6_IO4 CHANNEL /*!< PB14 */ 447 448 /* Warning: this group is available on some devices only */ 449 #define TOUCH_TSC_GROUP7_IO1 NU /*!< PE2 */ 450 #define TOUCH_TSC_GROUP7_IO2 NU /*!< PE3 */ 451 #define TOUCH_TSC_GROUP7_IO3 NU /*!< PE4 */ 452 #define TOUCH_TSC_GROUP7_IO4 NU /*!< PE5 */ 453 454 /* Warning: this group is available on some devices only */ 455 #define TOUCH_TSC_GROUP8_IO1 NU /*!< PD12 */ 456 #define TOUCH_TSC_GROUP8_IO2 NU /*!< PD13 */ 457 #define TOUCH_TSC_GROUP8_IO3 NU /*!< PD14 */ 458 #define TOUCH_TSC_GROUP8_IO4 NU /*!< PD15 */ 459 460 /**@} APM32F0xx_Parameters_GPIOs_Configuration */ 461 462 /** @defgroup APM32F0xx_Parameters_Charge_Transfer_Pulses 463 @{ 464 */ 465 466 /** Charge Transfer Pulse High (0..15) 467 * - 0: 1 x tPGCLK 468 * - 1: 2 x tPGCLK 469 * - ... 470 * - 15: 16 x tPGCLK 471 */ 472 #define TOUCH_TSC_CTPHSEL (1) 473 474 /** Charge Transfer Pulse Low (0..15) 475 * - 0: 1 x tPGCLK 476 * - 1: 2 x tPGCLK 477 * - ... 478 * - 15: 16 x tPGCLK 479 */ 480 #define TOUCH_TSC_CTPLSEL (1) 481 482 /** Pulse Generator Clock Divide Factor Select (0..7) 483 * - 0: fPGCLK = fHCLK 484 * - 1: fPGCLK = fHCLK/2 485 * - ... 486 * - 7: fPGCLK = fHCLK/128 487 */ 488 #define TOUCH_TSC_PGCDFSEL (3) 489 490 /**@} APM32F0xx_Parameters_Charge_Transfer_Pulses */ 491 492 /** @defgroup APM32F0xx_Parameters_GPIOs 493 @{ 494 */ 495 496 /** TSC IOs default mode when no on-going acquisition (0..1) 497 * - 0: Output push-pull low 498 * - 1: Input floating 499 * @note To ensure a correct operation in noisy environment, this parameter should 500 * be configured to output push-pull low. 501 */ 502 #define TOUCH_TSC_IODEF (0) 503 504 /** Acquisition Mode (0..1) 505 * - 0: Normal acquisition mode 506 * - 1: Synchronized acquisition mode 507 */ 508 #define TOUCH_TSC_AMCFG (0) 509 510 /** Synchronization Pin (0..1) 511 * - 0: PB8 512 * - 1: PB10 513 */ 514 #define TOUCH_TSC_SYNC_PIN (0) 515 516 /** Synchronization Polarity (0..1) 517 * - 0: Falling edge only 518 * - 1: Rising edge and high level 519 */ 520 #define TOUCH_TSC_SYNC_POL (0) 521 522 /**@} APM32F0xx_Parameters_GPIOs */ 523 524 /** @addtogroup APM32F0xx_Parameters_Spread_Spectrum 525 @{ 526 */ 527 528 /* Use Spread Spectrum (0=No, 1=Yes) */ 529 #define TOUCH_TSC_USE_SSEN (0) 530 531 /** Spread Spectrum Error Value Select (0..127) 532 * - 0: 1 x tSSCLK 533 * - 1: 2 x tSSCLK 534 * - ... 535 * - 127: 128 x tSSCLK 536 */ 537 #define TOUCH_TSC_SSERRVSEL (0) 538 539 /** Spread Spectrum Clock Divide Factor Select (0..1) 540 * - 0: fSSCLK = fHCLK 541 * - 1: fSSCLK = fHCLK/2 542 */ 543 #define TOUCH_TSC_SSCDFSEL (0) 544 545 /**@} APM32F0xx_Parameters_Spread_Spectrum */ 546 547 /* Includes */ 548 /* Must be placed last */ 549 #include "tsc_check.h" 550 551 #ifdef __cplusplus 552 } 553 #endif 554 555 #endif /* __TSC_CONFIG_H */ 556 557 /**@} end of group TSC_Config_Macros */ 558 559 /** @defgroup TSC_Config_Enumerations Enumerations 560 @{ 561 */ 562 563 /**@} end of group TSC_Config_Enumerations */ 564 565 /** @defgroup TSC_Config_Structures Structures 566 @{ 567 */ 568 569 /**@} end of group TSC_Config_Structures */ 570 571 /** @defgroup TSC_Config_Variables Variables 572 @{ 573 */ 574 575 /**@} end of group TSC_Config_Variables */ 576 577 /** @defgroup TSC_Config_Functions Functions 578 @{ 579 */ 580 581 /**@} end of group TSC_Config_Functions */ 582 /**@} end of group TSC_Config_Driver */ 583 /**@} end of group TSC_Driver_Library */ 584