2 ******************************************************************************
\r
3 * @file tsl_acq_stm32f3xx.c
\r
4 * @author MCD Application Team
\r
6 * @date 22-January-2013
\r
7 * @brief This file contains all functions to manage the TSC acquisition
\r
8 * on STM32F3xx products.
\r
9 ******************************************************************************
\r
12 * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
\r
14 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
\r
15 * You may not use this file except in compliance with the License.
\r
16 * You may obtain a copy of the License at:
\r
18 * http://www.st.com/software_license_agreement_liberty_v2
\r
20 * Unless required by applicable law or agreed to in writing, software
\r
21 * distributed under the License is distributed on an "AS IS" BASIS,
\r
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
23 * See the License for the specific language governing permissions and
\r
24 * limitations under the License.
\r
26 ******************************************************************************
\r
29 /* Includes ------------------------------------------------------------------*/
\r
30 #include "tsl_acq_stm32f3xx.h"
\r
31 #include "tsl_globals.h"
\r
32 #if defined(STM32F30X)
\r
33 #include "stm32f30x_it.h"
\r
35 #if defined(STM32F37X)
\r
36 #include "stm32f37x_it.h"
\r
39 /* Private typedefs ----------------------------------------------------------*/
\r
40 /* Private defines -----------------------------------------------------------*/
\r
41 #define TSL_DELAY_DISCHARGE (1000)
\r
43 #define NU (0) // Not Used IO
\r
44 #define CHANNEL (1) // Channel IO
\r
45 #define SHIELD (2) // Shield IO (= Channel IO but not acquired)
\r
46 #define SAMPCAP (3) // Sampling Capacitor IO
\r
48 /* Private macros ------------------------------------------------------------*/
\r
49 #define IS_BANK_INDEX_OK(INDEX) (((INDEX) == 0) || (((INDEX) > 0) && ((INDEX) < TSLPRM_TOTAL_BANKS)))
\r
50 #define IS_SOURCE_INDEX_OK(INDEX) (((INDEX) == 0) || (((INDEX) > 0) && ((INDEX) < TSLPRM_TOTAL_CHANNELS)))
\r
52 /* Private variables ---------------------------------------------------------*/
\r
54 /* Private functions prototype -----------------------------------------------*/
\r
55 void SoftDelay(uint32_t val);
\r
58 * @brief Initializes the TouchSensing GPIOs.
\r
62 void TSL_acq_InitGPIOs(void)
\r
65 GPIO_InitTypeDef GPIO_InitStructure;
\r
66 uint32_t tmp_value_0;
\r
67 uint32_t tmp_value_1;
\r
69 //====================
\r
70 // GPIOs configuration
\r
71 //====================
\r
73 // Enable GPIOs clocks
\r
74 RCC->AHBENR |= (RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN | RCC_AHBENR_GPIOCEN);
\r
76 // Alternate function Output Open-Drain for Sampling Capacitor IOs
\r
77 //----------------------------------------------------------------
\r
79 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
\r
80 GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
\r
81 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
\r
82 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
\r
85 GPIO_InitStructure.GPIO_Pin = 0;
\r
86 #if TSLPRM_TSC_GROUP1_IO1 == SAMPCAP
\r
87 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
89 #if TSLPRM_TSC_GROUP1_IO2 == SAMPCAP
\r
90 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
92 #if TSLPRM_TSC_GROUP1_IO3 == SAMPCAP
\r
93 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
95 #if TSLPRM_TSC_GROUP1_IO4 == SAMPCAP
\r
96 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
98 #if TSLPRM_TSC_GROUP2_IO1 == SAMPCAP
\r
99 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
101 #if TSLPRM_TSC_GROUP2_IO2 == SAMPCAP
\r
102 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_5;
\r
104 #if TSLPRM_TSC_GROUP2_IO3 == SAMPCAP
\r
105 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
107 #if TSLPRM_TSC_GROUP2_IO4 == SAMPCAP
\r
108 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
110 #if TSLPRM_TSC_GROUP4_IO1 == SAMPCAP
\r
111 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_9;
\r
113 #if TSLPRM_TSC_GROUP4_IO2 == SAMPCAP
\r
114 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_10;
\r
116 #if TSLPRM_TSC_GROUP4_IO3 == SAMPCAP
\r
117 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_13;
\r
119 #if TSLPRM_TSC_GROUP4_IO4 == SAMPCAP
\r
120 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
122 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
124 GPIO_Init(GPIOA, &GPIO_InitStructure);
\r
128 GPIO_InitStructure.GPIO_Pin = 0;
\r
130 #if defined(STM32F30X)
\r
131 #if TSLPRM_TSC_GROUP3_IO2 == SAMPCAP
\r
132 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
134 #if TSLPRM_TSC_GROUP3_IO3 == SAMPCAP
\r
135 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
137 #if TSLPRM_TSC_GROUP3_IO4 == SAMPCAP
\r
138 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
140 #if TSLPRM_TSC_GROUP5_IO1 == SAMPCAP
\r
141 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
143 #if TSLPRM_TSC_GROUP5_IO2 == SAMPCAP
\r
144 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
146 #if TSLPRM_TSC_GROUP5_IO3 == SAMPCAP
\r
147 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
149 #if TSLPRM_TSC_GROUP5_IO4 == SAMPCAP
\r
150 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
152 #if TSLPRM_TSC_GROUP6_IO1 == SAMPCAP
\r
153 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_11;
\r
155 #if TSLPRM_TSC_GROUP6_IO2 == SAMPCAP
\r
156 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
\r
158 #if TSLPRM_TSC_GROUP6_IO3 == SAMPCAP
\r
159 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_13;
\r
161 #if TSLPRM_TSC_GROUP6_IO4 == SAMPCAP
\r
162 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
164 #endif // STM32F30X
\r
166 #if defined(STM32F37X)
\r
167 #if TSLPRM_TSC_GROUP3_IO3 == SAMPCAP
\r
168 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
170 #if TSLPRM_TSC_GROUP3_IO4 == SAMPCAP
\r
171 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
173 #if TSLPRM_TSC_GROUP5_IO1 == SAMPCAP
\r
174 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
176 #if TSLPRM_TSC_GROUP5_IO2 == SAMPCAP
\r
177 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
179 #if TSLPRM_TSC_GROUP5_IO3 == SAMPCAP
\r
180 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
182 #if TSLPRM_TSC_GROUP5_IO4 == SAMPCAP
\r
183 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
185 #if TSLPRM_TSC_GROUP6_IO1 == SAMPCAP
\r
186 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
188 #if TSLPRM_TSC_GROUP6_IO2 == SAMPCAP
\r
189 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_15;
\r
191 #endif // STM32F37X
\r
193 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
195 GPIO_Init(GPIOB, &GPIO_InitStructure);
\r
199 #if defined(STM32F30X)
\r
200 #if TSLPRM_TSC_GROUP3_IO1 == SAMPCAP
\r
201 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
\r
202 GPIO_Init(GPIOC, &GPIO_InitStructure);
\r
204 #endif // STM32F30X
\r
206 #if defined(STM32F37X)
\r
207 GPIO_InitStructure.GPIO_Pin = 0;
\r
208 #if TSLPRM_TSC_GROUP3_IO1 == SAMPCAP
\r
209 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
211 #if TSLPRM_TSC_GROUP3_IO2 == SAMPCAP
\r
212 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_5;
\r
214 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
216 GPIO_Init(GPIOC, &GPIO_InitStructure);
\r
218 #endif // STM32F37X
\r
221 GPIO_InitStructure.GPIO_Pin = 0;
\r
223 #if defined(STM32F37X)
\r
224 #if TSLPRM_TSC_GROUP6_IO3 == SAMPCAP
\r
225 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
\r
227 #if TSLPRM_TSC_GROUP6_IO4 == SAMPCAP
\r
228 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
\r
230 #endif // STM32F37X
\r
232 #if TSLPRM_TSC_GROUP8_IO1 == SAMPCAP
\r
233 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
\r
235 #if TSLPRM_TSC_GROUP8_IO2 == SAMPCAP
\r
236 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
\r
238 #if TSLPRM_TSC_GROUP8_IO3 == SAMPCAP
\r
239 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
\r
241 #if TSLPRM_TSC_GROUP8_IO4 == SAMPCAP
\r
242 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
\r
244 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
246 GPIO_Init(GPIOD, &GPIO_InitStructure);
\r
250 GPIO_InitStructure.GPIO_Pin = 0;
\r
251 #if TSLPRM_TSC_GROUP7_IO1 == SAMPCAP
\r
252 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
\r
254 #if TSLPRM_TSC_GROUP7_IO2 == SAMPCAP
\r
255 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
\r
257 #if TSLPRM_TSC_GROUP7_IO3 == SAMPCAP
\r
258 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
\r
260 #if TSLPRM_TSC_GROUP7_IO4 == SAMPCAP
\r
261 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
\r
263 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
265 GPIO_Init(GPIOE, &GPIO_InitStructure);
\r
268 // Alternate function Output Push-Pull for Channel and Shield IOs
\r
269 //---------------------------------------------------------------
\r
271 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
\r
274 GPIO_InitStructure.GPIO_Pin = 0;
\r
275 #if (TSLPRM_TSC_GROUP1_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP1_IO1 == SHIELD)
\r
276 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
278 #if (TSLPRM_TSC_GROUP1_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP1_IO2 == SHIELD)
\r
279 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
281 #if (TSLPRM_TSC_GROUP1_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP1_IO3 == SHIELD)
\r
282 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
284 #if (TSLPRM_TSC_GROUP1_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP1_IO4 == SHIELD)
\r
285 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
287 #if (TSLPRM_TSC_GROUP2_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP2_IO1 == SHIELD)
\r
288 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
290 #if (TSLPRM_TSC_GROUP2_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP2_IO2 == SHIELD)
\r
291 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_5;
\r
293 #if (TSLPRM_TSC_GROUP2_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP2_IO3 == SHIELD)
\r
294 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
296 #if (TSLPRM_TSC_GROUP2_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP2_IO4 == SHIELD)
\r
297 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
299 #if (TSLPRM_TSC_GROUP4_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP4_IO1 == SHIELD)
\r
300 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_9;
\r
302 #if (TSLPRM_TSC_GROUP4_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP4_IO2 == SHIELD)
\r
303 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_10;
\r
305 #if (TSLPRM_TSC_GROUP4_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP4_IO3 == SHIELD)
\r
306 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_13;
\r
308 #if (TSLPRM_TSC_GROUP4_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP4_IO4 == SHIELD)
\r
309 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
311 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
313 GPIO_Init(GPIOA, &GPIO_InitStructure);
\r
317 GPIO_InitStructure.GPIO_Pin = 0;
\r
319 #if defined(STM32F30X)
\r
320 #if (TSLPRM_TSC_GROUP3_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO2 == SHIELD)
\r
321 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
323 #if (TSLPRM_TSC_GROUP3_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO3 == SHIELD)
\r
324 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
326 #if (TSLPRM_TSC_GROUP3_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO4 == SHIELD)
\r
327 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
329 #if (TSLPRM_TSC_GROUP5_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO1 == SHIELD)
\r
330 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
332 #if (TSLPRM_TSC_GROUP5_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO2 == SHIELD)
\r
333 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
335 #if (TSLPRM_TSC_GROUP5_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO3 == SHIELD)
\r
336 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
338 #if (TSLPRM_TSC_GROUP5_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO4 == SHIELD)
\r
339 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
341 #if (TSLPRM_TSC_GROUP6_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO1 == SHIELD)
\r
342 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_11;
\r
344 #if (TSLPRM_TSC_GROUP6_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO2 == SHIELD)
\r
345 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
\r
347 #if (TSLPRM_TSC_GROUP6_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO3 == SHIELD)
\r
348 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_13;
\r
350 #if (TSLPRM_TSC_GROUP6_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO4 == SHIELD)
\r
351 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
353 #endif // STM32F30X
\r
355 #if defined(STM32F37X)
\r
356 #if (TSLPRM_TSC_GROUP3_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO3 == SHIELD)
\r
357 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
359 #if (TSLPRM_TSC_GROUP3_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO4 == SHIELD)
\r
360 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
362 #if (TSLPRM_TSC_GROUP5_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO1 == SHIELD)
\r
363 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
365 #if (TSLPRM_TSC_GROUP5_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO2 == SHIELD)
\r
366 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
368 #if (TSLPRM_TSC_GROUP5_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO3 == SHIELD)
\r
369 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
371 #if (TSLPRM_TSC_GROUP5_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO4 == SHIELD)
\r
372 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
374 #if (TSLPRM_TSC_GROUP6_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO1 == SHIELD)
\r
375 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
377 #if (TSLPRM_TSC_GROUP6_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO2 == SHIELD)
\r
378 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_15;
\r
380 #endif // STM32F37X
\r
382 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
384 GPIO_Init(GPIOB, &GPIO_InitStructure);
\r
389 #if defined(STM32F30X)
\r
390 #if (TSLPRM_TSC_GROUP3_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO1 == SHIELD)
\r
391 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
\r
392 GPIO_Init(GPIOC, &GPIO_InitStructure);
\r
394 #endif // STM32F30X
\r
396 #if defined(STM32F37X)
\r
397 GPIO_InitStructure.GPIO_Pin = 0;
\r
398 #if (TSLPRM_TSC_GROUP3_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO1 == SHIELD)
\r
399 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
401 #if (TSLPRM_TSC_GROUP3_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO2 == SHIELD)
\r
402 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_5;
\r
404 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
406 GPIO_Init(GPIOC, &GPIO_InitStructure);
\r
408 #endif // STM32F37X
\r
411 GPIO_InitStructure.GPIO_Pin = 0;
\r
413 #if defined(STM32F37X)
\r
414 #if (TSLPRM_TSC_GROUP6_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO3 == SHIELD)
\r
415 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_8;
\r
417 #if (TSLPRM_TSC_GROUP6_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO4 == SHIELD)
\r
418 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_9;
\r
420 #endif // STM32F37X
\r
422 #if (TSLPRM_TSC_GROUP8_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP8_IO1 == SHIELD)
\r
423 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
\r
425 #if (TSLPRM_TSC_GROUP8_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP8_IO2 == SHIELD)
\r
426 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_13;
\r
428 #if (TSLPRM_TSC_GROUP8_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP8_IO3 == SHIELD)
\r
429 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
431 #if (TSLPRM_TSC_GROUP8_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP8_IO4 == SHIELD)
\r
432 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_15;
\r
434 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
436 GPIO_Init(GPIOD, &GPIO_InitStructure);
\r
440 GPIO_InitStructure.GPIO_Pin = 0;
\r
441 #if (TSLPRM_TSC_GROUP7_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP7_IO1 == SHIELD)
\r
442 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
444 #if (TSLPRM_TSC_GROUP7_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP7_IO2 == SHIELD)
\r
445 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
447 #if (TSLPRM_TSC_GROUP7_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP7_IO3 == SHIELD)
\r
448 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
450 #if (TSLPRM_TSC_GROUP7_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP7_IO4 == SHIELD)
\r
451 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_5;
\r
453 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
455 GPIO_Init(GPIOE, &GPIO_InitStructure);
\r
458 // Set Alternate-Function AF3 on used TSC IOs
\r
459 //-------------------------------------------
\r
464 #if TSLPRM_TSC_GROUP1_IO1 != NU
\r
465 tmp_value_0 |= (uint32_t)((uint32_t)3 << (0 * 4));
\r
467 #if TSLPRM_TSC_GROUP1_IO2 != NU
\r
468 tmp_value_0 |= (uint32_t)((uint32_t)3 << (1 * 4));
\r
470 #if TSLPRM_TSC_GROUP1_IO3 != NU
\r
471 tmp_value_0 |= (uint32_t)((uint32_t)3 << (2 * 4));
\r
473 #if TSLPRM_TSC_GROUP1_IO4 != NU
\r
474 tmp_value_0 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
476 #if TSLPRM_TSC_GROUP2_IO1 != NU
\r
477 tmp_value_0 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
479 #if TSLPRM_TSC_GROUP2_IO2 != NU
\r
480 tmp_value_0 |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
482 #if TSLPRM_TSC_GROUP2_IO3 != NU
\r
483 tmp_value_0 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
485 #if TSLPRM_TSC_GROUP2_IO4 != NU
\r
486 tmp_value_0 |= (uint32_t)((uint32_t)3 << (7 * 4));
\r
488 #if TSLPRM_TSC_GROUP4_IO1 != NU
\r
489 tmp_value_1 |= (uint32_t)((uint32_t)3 << (1 * 4));
\r
491 #if TSLPRM_TSC_GROUP4_IO2 != NU
\r
492 tmp_value_1 |= (uint32_t)((uint32_t)3 << (2 * 4));
\r
494 #if TSLPRM_TSC_GROUP4_IO3 != NU
\r
495 tmp_value_1 |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
497 #if TSLPRM_TSC_GROUP4_IO4 != NU
\r
498 tmp_value_1 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
500 if (tmp_value_0 != 0) {GPIOA->AFR[0] |= tmp_value_0;}
\r
501 if (tmp_value_1 != 0) {GPIOA->AFR[1] |= tmp_value_1;}
\r
507 #if defined(STM32F30X)
\r
508 #if TSLPRM_TSC_GROUP3_IO2 != NU
\r
509 tmp_value_0 |= (uint32_t)((uint32_t)3 << (0 * 4));
\r
511 #if TSLPRM_TSC_GROUP3_IO3 != NU
\r
512 tmp_value_0 |= (uint32_t)((uint32_t)3 << (1 * 4));
\r
514 #if TSLPRM_TSC_GROUP3_IO4 != NU
\r
515 tmp_value_0 |= (uint32_t)((uint32_t)3 << (2 * 4));
\r
517 #if TSLPRM_TSC_GROUP5_IO1 != NU
\r
518 tmp_value_0 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
520 #if TSLPRM_TSC_GROUP5_IO2 != NU
\r
521 tmp_value_0 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
523 #if TSLPRM_TSC_GROUP5_IO3 != NU
\r
524 tmp_value_0 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
526 #if TSLPRM_TSC_GROUP5_IO4 != NU
\r
527 tmp_value_0 |= (uint32_t)((uint32_t)3 << (7 * 4));
\r
529 #if TSLPRM_TSC_GROUP6_IO1 != NU
\r
530 tmp_value_1 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
532 #if TSLPRM_TSC_GROUP6_IO2 != NU
\r
533 tmp_value_1 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
535 #if TSLPRM_TSC_GROUP6_IO3 != NU
\r
536 tmp_value_1 |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
538 #if TSLPRM_TSC_GROUP6_IO4 != NU
\r
539 tmp_value_1 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
541 #endif // STM32F30X
\r
543 #if defined(STM32F37X)
\r
544 #if TSLPRM_TSC_GROUP3_IO3 != NU
\r
545 tmp_value_0 |= (uint32_t)((uint32_t)3 << (0 * 4));
\r
547 #if TSLPRM_TSC_GROUP3_IO4 != NU
\r
548 tmp_value_0 |= (uint32_t)((uint32_t)3 << (1 * 4));
\r
550 #if TSLPRM_TSC_GROUP5_IO1 != NU
\r
551 tmp_value_0 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
553 #if TSLPRM_TSC_GROUP5_IO2 != NU
\r
554 tmp_value_0 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
556 #if TSLPRM_TSC_GROUP5_IO3 != NU
\r
557 tmp_value_0 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
559 #if TSLPRM_TSC_GROUP5_IO4 != NU
\r
560 tmp_value_0 |= (uint32_t)((uint32_t)3 << (7 * 4));
\r
562 #if TSLPRM_TSC_GROUP6_IO1 != NU
\r
563 tmp_value_1 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
565 #if TSLPRM_TSC_GROUP6_IO2 != NU
\r
566 tmp_value_1 |= (uint32_t)((uint32_t)3 << (7 * 4));
\r
568 #endif // STM32F37X
\r
570 if (tmp_value_0 != 0) {GPIOB->AFR[0] |= tmp_value_0;}
\r
571 if (tmp_value_1 != 0) {GPIOB->AFR[1] |= tmp_value_1;}
\r
574 #if defined(STM32F30X)
\r
575 #if TSLPRM_TSC_GROUP3_IO1 != NU
\r
576 GPIOC->AFR[0] |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
578 #endif // STM32F30X
\r
580 #if defined(STM32F37X)
\r
581 #if TSLPRM_TSC_GROUP3_IO1 != NU
\r
582 GPIOC->AFR[0] |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
584 #if TSLPRM_TSC_GROUP3_IO2 != NU
\r
585 GPIOC->AFR[0] |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
587 #endif // STM32F37X
\r
592 #if defined(STM32F37X)
\r
593 #if TSLPRM_TSC_GROUP6_IO3 != NU
\r
594 tmp_value_1 |= (uint32_t)((uint32_t)3 << (0 * 4));
\r
596 #if TSLPRM_TSC_GROUP6_IO4 != NU
\r
597 tmp_value_1 |= (uint32_t)((uint32_t)3 << (1 * 4));
\r
599 #endif // STM32F37X
\r
601 #if TSLPRM_TSC_GROUP8_IO1 != NU
\r
602 tmp_value_1 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
604 #if TSLPRM_TSC_GROUP8_IO2 != NU
\r
605 tmp_value_1 |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
607 #if TSLPRM_TSC_GROUP8_IO3 != NU
\r
608 tmp_value_1 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
610 #if TSLPRM_TSC_GROUP8_IO4 != NU
\r
611 tmp_value_1 |= (uint32_t)((uint32_t)3 << (7 * 4));
\r
613 if (tmp_value_1 != 0) {GPIOD->AFR[1] |= tmp_value_1;}
\r
617 #if TSLPRM_TSC_GROUP7_IO1 != NU
\r
618 tmp_value_0 |= (uint32_t)((uint32_t)3 << (2 * 4));
\r
620 #if TSLPRM_TSC_GROUP7_IO2 != NU
\r
621 tmp_value_0 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
623 #if TSLPRM_TSC_GROUP7_IO3 != NU
\r
624 tmp_value_0 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
626 #if TSLPRM_TSC_GROUP7_IO4 != NU
\r
627 tmp_value_0 |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
629 if (tmp_value_0 != 0) {GPIOE->AFR[0] |= tmp_value_0;}
\r
631 //==================
\r
632 // TSC configuration
\r
633 //==================
\r
635 // Enable TSC clock
\r
636 RCC->AHBENR |= RCC_AHBENR_TSEN;
\r
638 // Disable Schmitt trigger hysteresis on all used TS IOs (Channel, Shield and Sampling IOs)
\r
639 //-----------------------------------------------------------------------------------------
\r
641 tmp_value_0 = 0xFFFFFFFF;
\r
642 #if TSLPRM_TSC_GROUP1_IO1 != NU
\r
643 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 0);
\r
645 #if TSLPRM_TSC_GROUP1_IO2 != NU
\r
646 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 1);
\r
648 #if TSLPRM_TSC_GROUP1_IO3 != NU
\r
649 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 2);
\r
651 #if TSLPRM_TSC_GROUP1_IO4 != NU
\r
652 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 3);
\r
654 #if TSLPRM_TSC_GROUP2_IO1 != NU
\r
655 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 4);
\r
657 #if TSLPRM_TSC_GROUP2_IO2 != NU
\r
658 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 5);
\r
660 #if TSLPRM_TSC_GROUP2_IO3 != NU
\r
661 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 6);
\r
663 #if TSLPRM_TSC_GROUP2_IO4 != NU
\r
664 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 7);
\r
666 #if TSLPRM_TSC_GROUP3_IO1 != NU
\r
667 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 8);
\r
669 #if TSLPRM_TSC_GROUP3_IO2 != NU
\r
670 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 9);
\r
672 #if TSLPRM_TSC_GROUP3_IO3 != NU
\r
673 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 10);
\r
675 #if TSLPRM_TSC_GROUP3_IO4 != NU
\r
676 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 11);
\r
678 #if TSLPRM_TSC_GROUP4_IO1 != NU
\r
679 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 12);
\r
681 #if TSLPRM_TSC_GROUP4_IO2 != NU
\r
682 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 13);
\r
684 #if TSLPRM_TSC_GROUP4_IO3 != NU
\r
685 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 14);
\r
687 #if TSLPRM_TSC_GROUP4_IO4 != NU
\r
688 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 15);
\r
690 #if TSLPRM_TSC_GROUP5_IO1 != NU
\r
691 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 16);
\r
693 #if TSLPRM_TSC_GROUP5_IO2 != NU
\r
694 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 17);
\r
696 #if TSLPRM_TSC_GROUP5_IO3 != NU
\r
697 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 18);
\r
699 #if TSLPRM_TSC_GROUP5_IO4 != NU
\r
700 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 19);
\r
702 #if TSLPRM_TSC_GROUP6_IO1 != NU
\r
703 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 20);
\r
705 #if TSLPRM_TSC_GROUP6_IO2 != NU
\r
706 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 21);
\r
708 #if TSLPRM_TSC_GROUP6_IO3 != NU
\r
709 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 22);
\r
711 #if TSLPRM_TSC_GROUP6_IO4 != NU
\r
712 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 23);
\r
714 #if TSLPRM_TSC_GROUP7_IO1 != NU
\r
715 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 24);
\r
717 #if TSLPRM_TSC_GROUP7_IO2 != NU
\r
718 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 25);
\r
720 #if TSLPRM_TSC_GROUP7_IO3 != NU
\r
721 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 26);
\r
723 #if TSLPRM_TSC_GROUP7_IO4 != NU
\r
724 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 27);
\r
726 #if TSLPRM_TSC_GROUP8_IO1 != NU
\r
727 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 28);
\r
729 #if TSLPRM_TSC_GROUP8_IO2 != NU
\r
730 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 29);
\r
732 #if TSLPRM_TSC_GROUP8_IO3 != NU
\r
733 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 30);
\r
735 #if TSLPRM_TSC_GROUP8_IO4 != NU
\r
736 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 31);
\r
738 if (tmp_value_0 != 0xFFFFFFFF) {TSC->IOHCR &= tmp_value_0;}
\r
740 // Set Sampling Capacitor IOs
\r
741 //---------------------------
\r
744 #if TSLPRM_TSC_GROUP1_IO1 == SAMPCAP
\r
745 tmp_value_0 |= (uint32_t)((uint32_t)1 << 0);
\r
747 #if TSLPRM_TSC_GROUP1_IO2 == SAMPCAP
\r
748 tmp_value_0 |= (uint32_t)((uint32_t)1 << 1);
\r
750 #if TSLPRM_TSC_GROUP1_IO3 == SAMPCAP
\r
751 tmp_value_0 |= (uint32_t)((uint32_t)1 << 2);
\r
753 #if TSLPRM_TSC_GROUP1_IO4 == SAMPCAP
\r
754 tmp_value_0 |= (uint32_t)((uint32_t)1 << 3);
\r
756 #if TSLPRM_TSC_GROUP2_IO1 == SAMPCAP
\r
757 tmp_value_0 |= (uint32_t)((uint32_t)1 << 4);
\r
759 #if TSLPRM_TSC_GROUP2_IO2 == SAMPCAP
\r
760 tmp_value_0 |= (uint32_t)((uint32_t)1 << 5);
\r
762 #if TSLPRM_TSC_GROUP2_IO3 == SAMPCAP
\r
763 tmp_value_0 |= (uint32_t)((uint32_t)1 << 6);
\r
765 #if TSLPRM_TSC_GROUP2_IO4 == SAMPCAP
\r
766 tmp_value_0 |= (uint32_t)((uint32_t)1 << 7);
\r
768 #if TSLPRM_TSC_GROUP3_IO1 == SAMPCAP
\r
769 tmp_value_0 |= (uint32_t)((uint32_t)1 << 8);
\r
771 #if TSLPRM_TSC_GROUP3_IO2 == SAMPCAP
\r
772 tmp_value_0 |= (uint32_t)((uint32_t)1 << 9);
\r
774 #if TSLPRM_TSC_GROUP3_IO3 == SAMPCAP
\r
775 tmp_value_0 |= (uint32_t)((uint32_t)1 << 10);
\r
777 #if TSLPRM_TSC_GROUP3_IO4 == SAMPCAP
\r
778 tmp_value_0 |= (uint32_t)((uint32_t)1 << 11);
\r
780 #if TSLPRM_TSC_GROUP4_IO1 == SAMPCAP
\r
781 tmp_value_0 |= (uint32_t)((uint32_t)1 << 12);
\r
783 #if TSLPRM_TSC_GROUP4_IO2 == SAMPCAP
\r
784 tmp_value_0 |= (uint32_t)((uint32_t)1 << 13);
\r
786 #if TSLPRM_TSC_GROUP4_IO3 == SAMPCAP
\r
787 tmp_value_0 |= (uint32_t)((uint32_t)1 << 14);
\r
789 #if TSLPRM_TSC_GROUP4_IO4 == SAMPCAP
\r
790 tmp_value_0 |= (uint32_t)((uint32_t)1 << 15);
\r
792 #if TSLPRM_TSC_GROUP5_IO1 == SAMPCAP
\r
793 tmp_value_0 |= (uint32_t)((uint32_t)1 << 16);
\r
795 #if TSLPRM_TSC_GROUP5_IO2 == SAMPCAP
\r
796 tmp_value_0 |= (uint32_t)((uint32_t)1 << 17);
\r
798 #if TSLPRM_TSC_GROUP5_IO3 == SAMPCAP
\r
799 tmp_value_0 |= (uint32_t)((uint32_t)1 << 18);
\r
801 #if TSLPRM_TSC_GROUP5_IO4 == SAMPCAP
\r
802 tmp_value_0 |= (uint32_t)((uint32_t)1 << 19);
\r
804 #if TSLPRM_TSC_GROUP6_IO1 == SAMPCAP
\r
805 tmp_value_0 |= (uint32_t)((uint32_t)1 << 20);
\r
807 #if TSLPRM_TSC_GROUP6_IO2 == SAMPCAP
\r
808 tmp_value_0 |= (uint32_t)((uint32_t)1 << 21);
\r
810 #if TSLPRM_TSC_GROUP6_IO3 == SAMPCAP
\r
811 tmp_value_0 |= (uint32_t)((uint32_t)1 << 22);
\r
813 #if TSLPRM_TSC_GROUP6_IO4 == SAMPCAP
\r
814 tmp_value_0 |= (uint32_t)((uint32_t)1 << 23);
\r
816 #if TSLPRM_TSC_GROUP7_IO1 == SAMPCAP
\r
817 tmp_value_0 |= (uint32_t)((uint32_t)1 << 24);
\r
819 #if TSLPRM_TSC_GROUP7_IO2 == SAMPCAP
\r
820 tmp_value_0 |= (uint32_t)((uint32_t)1 << 25);
\r
822 #if TSLPRM_TSC_GROUP7_IO3 == SAMPCAP
\r
823 tmp_value_0 |= (uint32_t)((uint32_t)1 << 26);
\r
825 #if TSLPRM_TSC_GROUP7_IO4 == SAMPCAP
\r
826 tmp_value_0 |= (uint32_t)((uint32_t)1 << 27);
\r
828 #if TSLPRM_TSC_GROUP8_IO1 == SAMPCAP
\r
829 tmp_value_0 |= (uint32_t)((uint32_t)1 << 28);
\r
831 #if TSLPRM_TSC_GROUP8_IO2 == SAMPCAP
\r
832 tmp_value_0 |= (uint32_t)((uint32_t)1 << 29);
\r
834 #if TSLPRM_TSC_GROUP8_IO3 == SAMPCAP
\r
835 tmp_value_0 |= (uint32_t)((uint32_t)1 << 30);
\r
837 #if TSLPRM_TSC_GROUP8_IO4 == SAMPCAP
\r
838 tmp_value_0 |= (uint32_t)((uint32_t)1 << 31);
\r
840 if (tmp_value_0 != 0) {TSC->IOSCR |= tmp_value_0;}
\r
846 * @brief Initializes the acquisition module.
\r
850 TSL_Status_enum_T TSL_acq_Init(void)
\r
853 #if TSLPRM_TSC_GPIO_CONFIG > 0
\r
854 TSL_acq_InitGPIOs();
\r
857 // Enable TSC clock
\r
858 RCC->AHBENR |= RCC_AHBENR_TSEN;
\r
864 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_CTPH << 28) & 0xF0000000;
\r
867 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_CTPL << 24) & 0x0F000000;
\r
869 // Set SpreadSpectrum
\r
870 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_USE_SS << 16) & 0x00010000;
\r
871 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_SSD << 17) & 0x00FE0000;
\r
872 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_SSPSC << 15) & 0x00008000;
\r
875 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_PGPSC << 12) & 0x00007000;
\r
878 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_MCV << 5) & 0x000000E0;
\r
880 // Set IO default in Output PP Low to discharge all capacitors
\r
881 TSC->CR &= (uint32_t)(~(1 << 4));
\r
883 // Set Synchronization Mode
\r
884 #if TSLPRM_TSC_AM > 0
\r
886 // Set Synchronization Pin in Alternate-Function mode
\r
887 RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // Set GPIOB clock
\r
889 #if TSLPRM_TSC_SYNC_PIN == 0 // PB08
\r
890 GPIOB->MODER &= 0xFFFCFFFF;
\r
891 GPIOB->MODER |= 0x00020000;
\r
892 GPIOB->AFR[1] |= 0x00000003;
\r
894 GPIOB->MODER &= 0xFFCFFFFF;
\r
895 GPIOB->MODER |= 0x00200000;
\r
896 GPIOB->AFR[1] |= 0x00000300;
\r
899 // Set Synchronization Polarity
\r
900 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_SYNC_POL << 3) & 0x00000008;
\r
904 // Set acquisition mode
\r
905 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_AM << 2) & 0x00000004;
\r
907 #if TSLPRM_USE_ACQ_INTERRUPT > 0
\r
909 // Set both EOA and MCE interrupts
\r
913 NVIC_SetPriority(EXTI2_TS_IRQn, 0);
\r
914 NVIC_EnableIRQ(EXTI2_TS_IRQn);
\r
918 return TSL_STATUS_OK;
\r
924 * @brief Configures a Bank.
\r
925 * @param[in] idx_bk Index of the Bank to configure
\r
928 TSL_Status_enum_T TSL_acq_BankConfig(TSL_tIndex_T idx_bk)
\r
930 TSL_tIndex_T idx_ch;
\r
931 uint32_t objs; /* bit field of TSL_ObjStatus_enum_T type */
\r
934 CONST TSL_Bank_T *bank = &(TSL_Globals.Bank_Array[idx_bk]);
\r
935 CONST TSL_ChannelSrc_T *pchSrc = bank->p_chSrc;
\r
936 CONST TSL_ChannelDest_T *pchDest = bank->p_chDest;
\r
938 // Check parameters (if USE_FULL_ASSERT is defined)
\r
939 assert_param(IS_BANK_INDEX_OK(idx_bk));
\r
941 // Mark the current bank processed
\r
942 TSL_Globals.This_Bank = idx_bk;
\r
944 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
945 // Enable the Gx_IOy used as channels (channels + shield)
\r
946 TSC->IOCCR = bank->msk_IOCCR_channels;
\r
947 // Enable acquisition on selected Groups
\r
948 TSC->IOGCSR = bank->msk_IOGCSR_groups;
\r
949 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
951 // For all channels of the bank check if they are OFF or BURST_ONLY
\r
952 // and set acquisition status flag
\r
953 for (idx_ch = 0; idx_ch < bank->NbChannels; idx_ch++)
\r
956 // Check Object status flag
\r
957 objs = bank->p_chData[pchDest->IdxDest].Flags.ObjStatus;
\r
959 if (objs != TSL_OBJ_STATUS_ON)
\r
961 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
962 // Get the Channel Group mask
\r
963 gx = pchSrc->msk_IOGCSR_group;
\r
964 // Stop acquisition of the Group
\r
965 TSC->IOGCSR &= (uint32_t)~gx;
\r
966 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
968 if (objs == TSL_OBJ_STATUS_OFF)
\r
970 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
971 // Get the Channel IO mask
\r
972 ioy = pchSrc->msk_IOCCR_channel;
\r
973 // Stop Burst of the Channel
\r
974 TSC->IOCCR &= (uint32_t)~ioy;
\r
975 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
984 return TSL_STATUS_OK;
\r
989 * @brief Start acquisition on a previously configured bank
\r
993 void TSL_acq_BankStartAcq(void)
\r
995 // Clear both EOAIC and MCEIC flags
\r
998 // Wait capacitors discharge
\r
999 SoftDelay(TSL_DELAY_DISCHARGE);
\r
1001 #if TSLPRM_TSC_IODEF > 0 // Default = Input Floating
\r
1002 // Set IO default in Input Floating
\r
1003 TSC->CR |= (1 << 4);
\r
1006 // Start acquisition
\r
1012 * @brief Wait end of acquisition
\r
1016 TSL_Status_enum_T TSL_acq_BankWaitEOC(void)
\r
1018 TSL_Status_enum_T retval = TSL_STATUS_BUSY;
\r
1020 // Check EOAF flag
\r
1021 if (TSC->ISR & 0x01)
\r
1024 #if TSLPRM_TSC_IODEF > 0 // Default = Input Floating
\r
1025 // Set IO default in Output PP Low to discharge all capacitors
\r
1026 TSC->CR &= (uint32_t)(~(1 << 4));
\r
1029 // Check MCEF flag
\r
1030 if (TSC->ISR & 0x02)
\r
1032 retval = TSL_STATUS_ERROR;
\r
1036 retval = TSL_STATUS_OK;
\r
1045 * @brief Return the current measure
\r
1046 * @param[in] index Index of the measure source
\r
1049 TSL_tMeas_T TSL_acq_GetMeas(TSL_tIndex_T index)
\r
1051 return(TSC->IOGXCR[index]);
\r
1056 * @brief Compute the Delta value
\r
1057 * @param[in] ref Reference value
\r
1058 * @param[in] meas Last Measurement value
\r
1059 * @retval Delta value
\r
1061 TSL_tDelta_T TSL_acq_ComputeDelta(TSL_tRef_T ref, TSL_tMeas_T meas)
\r
1063 return((TSL_tDelta_T)(ref - meas));
\r
1068 * @brief Compute the Measurement value
\r
1069 * @param[in] ref Reference value
\r
1070 * @param[in] delta Delta value
\r
1071 * @retval Measurement value
\r
1073 TSL_tMeas_T TSL_acq_ComputeMeas(TSL_tRef_T ref, TSL_tDelta_T delta)
\r
1075 return((TSL_tMeas_T)(ref - delta));
\r
1080 * @brief Check noise (not used)
\r
1084 TSL_AcqStatus_enum_T TSL_acq_CheckNoise(void)
\r
1086 return TSL_ACQ_STATUS_OK;
\r
1091 * @brief Check if a filter must be used on the current channel (not used)
\r
1092 * @param[in] pCh Pointer on the channel data information
\r
1093 * @retval Result TRUE if a filter can be applied
\r
1095 TSL_Bool_enum_T TSL_acq_UseFilter(TSL_ChannelData_T *pCh)
\r
1102 * @brief Test if the Reference is incorrect (not used)
\r
1103 * @param[in] pCh Pointer on the channel data information
\r
1104 * @retval Result TRUE if the Reference is out of range
\r
1106 TSL_Bool_enum_T TSL_acq_TestReferenceOutOfRange(TSL_ChannelData_T *pCh)
\r
1113 * @brief Test if the measure has crossed the reference target (not used)
\r
1114 * @param[in] pCh Pointer on the channel data information
\r
1115 * @param[in] new_meas Measure of the last acquisition on this channel
\r
1116 * @retval Result TRUE if the Reference is valid
\r
1118 TSL_Bool_enum_T TSL_acq_TestFirstReferenceIsValid(TSL_ChannelData_T *pCh, TSL_tMeas_T new_meas)
\r
1124 #if defined(__IAR_SYSTEMS_ICC__) // IAR/EWARM
\r
1125 #pragma optimize=low
\r
1126 #elif defined(__CC_ARM) // Keil/MDK-ARM
\r
1129 #elif defined(__TASKING__) // Altium/Tasking
\r
1130 #pragma optimize O0
\r
1131 #elif defined(__GNUC__) // Atollic/True Studio + Raisonance/RKit
\r
1132 #pragma GCC push_options
\r
1133 #pragma GCC optimize ("O0")
\r
1136 * @brief Software delay (private routine)
\r
1137 * @param val Wait delay
\r
1140 void SoftDelay(uint32_t val)
\r
1143 for (i = val; i > 0; i--)
\r
1146 #if defined(__TASKING__)
\r
1147 #pragma endoptimize
\r
1150 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r