2 ******************************************************************************
\r
3 * @file tsl_acq_stm32f0xx.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 STM32F0xx 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_stm32f0xx.h"
\r
31 #include "tsl_globals.h"
\r
32 #include "stm32f0xx_it.h"
\r
34 /* Private typedefs ----------------------------------------------------------*/
\r
35 /* Private defines -----------------------------------------------------------*/
\r
36 #define TSL_DELAY_DISCHARGE (1000)
\r
38 #define NU (0) // Not Used IO
\r
39 #define CHANNEL (1) // Channel IO
\r
40 #define SHIELD (2) // Shield IO (= Channel IO but not acquired)
\r
41 #define SAMPCAP (3) // Sampling Capacitor IO
\r
43 /* Private macros ------------------------------------------------------------*/
\r
44 #define IS_BANK_INDEX_OK(INDEX) (((INDEX) == 0) || (((INDEX) > 0) && ((INDEX) < TSLPRM_TOTAL_BANKS)))
\r
45 #define IS_SOURCE_INDEX_OK(INDEX) (((INDEX) == 0) || (((INDEX) > 0) && ((INDEX) < TSLPRM_TOTAL_CHANNELS)))
\r
47 /* Private variables ---------------------------------------------------------*/
\r
49 /* Private functions prototype -----------------------------------------------*/
\r
50 void SoftDelay(uint32_t val);
\r
53 * @brief Initializes the TouchSensing GPIOs.
\r
57 void TSL_acq_InitGPIOs(void)
\r
60 GPIO_InitTypeDef GPIO_InitStructure;
\r
61 uint32_t tmp_value_0;
\r
62 uint32_t tmp_value_1;
\r
64 //====================
\r
65 // GPIOs configuration
\r
66 //====================
\r
68 // Enable GPIOs clocks
\r
69 RCC->AHBENR |= (RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN | RCC_AHBENR_GPIOCEN);
\r
71 // Alternate function Output Open-Drain for Sampling Capacitor IOs
\r
72 //----------------------------------------------------------------
\r
74 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
\r
75 GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
\r
76 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
\r
77 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
\r
80 GPIO_InitStructure.GPIO_Pin = 0;
\r
81 #if TSLPRM_TSC_GROUP1_IO1 == SAMPCAP
\r
82 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
84 #if TSLPRM_TSC_GROUP1_IO2 == SAMPCAP
\r
85 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
87 #if TSLPRM_TSC_GROUP1_IO3 == SAMPCAP
\r
88 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
90 #if TSLPRM_TSC_GROUP1_IO4 == SAMPCAP
\r
91 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
93 #if TSLPRM_TSC_GROUP2_IO1 == SAMPCAP
\r
94 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
96 #if TSLPRM_TSC_GROUP2_IO2 == SAMPCAP
\r
97 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_5;
\r
99 #if TSLPRM_TSC_GROUP2_IO3 == SAMPCAP
\r
100 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
102 #if TSLPRM_TSC_GROUP2_IO4 == SAMPCAP
\r
103 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
105 #if TSLPRM_TSC_GROUP4_IO1 == SAMPCAP
\r
106 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_9;
\r
108 #if TSLPRM_TSC_GROUP4_IO2 == SAMPCAP
\r
109 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_10;
\r
111 #if TSLPRM_TSC_GROUP4_IO3 == SAMPCAP
\r
112 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_11;
\r
114 #if TSLPRM_TSC_GROUP4_IO4 == SAMPCAP
\r
115 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
\r
117 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
119 GPIO_Init(GPIOA, &GPIO_InitStructure);
\r
123 GPIO_InitStructure.GPIO_Pin = 0;
\r
124 #if TSLPRM_TSC_GROUP3_IO2 == SAMPCAP
\r
125 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
127 #if TSLPRM_TSC_GROUP3_IO3 == SAMPCAP
\r
128 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
130 #if TSLPRM_TSC_GROUP3_IO4 == SAMPCAP
\r
131 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
133 #if TSLPRM_TSC_GROUP5_IO1 == SAMPCAP
\r
134 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
136 #if TSLPRM_TSC_GROUP5_IO2 == SAMPCAP
\r
137 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
139 #if TSLPRM_TSC_GROUP5_IO3 == SAMPCAP
\r
140 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
142 #if TSLPRM_TSC_GROUP5_IO4 == SAMPCAP
\r
143 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
145 #if TSLPRM_TSC_GROUP6_IO1 == SAMPCAP
\r
146 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_11;
\r
148 #if TSLPRM_TSC_GROUP6_IO2 == SAMPCAP
\r
149 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
\r
151 #if TSLPRM_TSC_GROUP6_IO3 == SAMPCAP
\r
152 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_13;
\r
154 #if TSLPRM_TSC_GROUP6_IO4 == SAMPCAP
\r
155 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
157 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
159 GPIO_Init(GPIOB, &GPIO_InitStructure);
\r
163 #if TSLPRM_TSC_GROUP3_IO1 == SAMPCAP
\r
164 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
\r
165 GPIO_Init(GPIOC, &GPIO_InitStructure);
\r
168 // Alternate function Output Push-Pull for Channel and Shield IOs
\r
169 //---------------------------------------------------------------
\r
171 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
\r
174 GPIO_InitStructure.GPIO_Pin = 0;
\r
175 #if (TSLPRM_TSC_GROUP1_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP1_IO1 == SHIELD)
\r
176 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
178 #if (TSLPRM_TSC_GROUP1_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP1_IO2 == SHIELD)
\r
179 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
181 #if (TSLPRM_TSC_GROUP1_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP1_IO3 == SHIELD)
\r
182 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
184 #if (TSLPRM_TSC_GROUP1_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP1_IO4 == SHIELD)
\r
185 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
187 #if (TSLPRM_TSC_GROUP2_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP2_IO1 == SHIELD)
\r
188 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
190 #if (TSLPRM_TSC_GROUP2_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP2_IO2 == SHIELD)
\r
191 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_5;
\r
193 #if (TSLPRM_TSC_GROUP2_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP2_IO3 == SHIELD)
\r
194 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
196 #if (TSLPRM_TSC_GROUP2_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP2_IO4 == SHIELD)
\r
197 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
199 #if (TSLPRM_TSC_GROUP4_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP4_IO1 == SHIELD)
\r
200 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_9;
\r
202 #if (TSLPRM_TSC_GROUP4_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP4_IO2 == SHIELD)
\r
203 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_10;
\r
205 #if (TSLPRM_TSC_GROUP4_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP4_IO3 == SHIELD)
\r
206 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_11;
\r
208 #if (TSLPRM_TSC_GROUP4_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP4_IO4 == SHIELD)
\r
209 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
\r
211 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
213 GPIO_Init(GPIOA, &GPIO_InitStructure);
\r
217 GPIO_InitStructure.GPIO_Pin = 0;
\r
218 #if (TSLPRM_TSC_GROUP3_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO2 == SHIELD)
\r
219 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_0;
\r
221 #if (TSLPRM_TSC_GROUP3_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO3 == SHIELD)
\r
222 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1;
\r
224 #if (TSLPRM_TSC_GROUP3_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO4 == SHIELD)
\r
225 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2;
\r
227 #if (TSLPRM_TSC_GROUP5_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO1 == SHIELD)
\r
228 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_3;
\r
230 #if (TSLPRM_TSC_GROUP5_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO2 == SHIELD)
\r
231 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4;
\r
233 #if (TSLPRM_TSC_GROUP5_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO3 == SHIELD)
\r
234 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_6;
\r
236 #if (TSLPRM_TSC_GROUP5_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP5_IO4 == SHIELD)
\r
237 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_7;
\r
239 #if (TSLPRM_TSC_GROUP6_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO1 == SHIELD)
\r
240 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_11;
\r
242 #if (TSLPRM_TSC_GROUP6_IO2 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO2 == SHIELD)
\r
243 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_12;
\r
245 #if (TSLPRM_TSC_GROUP6_IO3 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO3 == SHIELD)
\r
246 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_13;
\r
248 #if (TSLPRM_TSC_GROUP6_IO4 == CHANNEL) || (TSLPRM_TSC_GROUP6_IO4 == SHIELD)
\r
249 GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_14;
\r
251 if (GPIO_InitStructure.GPIO_Pin != 0)
\r
253 GPIO_Init(GPIOB, &GPIO_InitStructure);
\r
257 #if (TSLPRM_TSC_GROUP3_IO1 == CHANNEL) || (TSLPRM_TSC_GROUP3_IO1 == SHIELD)
\r
258 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
\r
259 GPIO_Init(GPIOC, &GPIO_InitStructure);
\r
262 // Set Alternate-Function AF3 for GPIOA and GPIOB
\r
263 //-----------------------------------------------
\r
268 #if TSLPRM_TSC_GROUP1_IO1 != NU
\r
269 tmp_value_0 |= (uint32_t)((uint32_t)3 << (0 * 4));
\r
271 #if TSLPRM_TSC_GROUP1_IO2 != NU
\r
272 tmp_value_0 |= (uint32_t)((uint32_t)3 << (1 * 4));
\r
274 #if TSLPRM_TSC_GROUP1_IO3 != NU
\r
275 tmp_value_0 |= (uint32_t)((uint32_t)3 << (2 * 4));
\r
277 #if TSLPRM_TSC_GROUP1_IO4 != NU
\r
278 tmp_value_0 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
280 #if TSLPRM_TSC_GROUP2_IO1 != NU
\r
281 tmp_value_0 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
283 #if TSLPRM_TSC_GROUP2_IO2 != NU
\r
284 tmp_value_0 |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
286 #if TSLPRM_TSC_GROUP2_IO3 != NU
\r
287 tmp_value_0 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
289 #if TSLPRM_TSC_GROUP2_IO4 != NU
\r
290 tmp_value_0 |= (uint32_t)((uint32_t)3 << (7 * 4));
\r
292 #if TSLPRM_TSC_GROUP4_IO1 != NU
\r
293 tmp_value_1 |= (uint32_t)((uint32_t)3 << (1 * 4));
\r
295 #if TSLPRM_TSC_GROUP4_IO2 != NU
\r
296 tmp_value_1 |= (uint32_t)((uint32_t)3 << (2 * 4));
\r
298 #if TSLPRM_TSC_GROUP4_IO3 != NU
\r
299 tmp_value_1 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
301 #if TSLPRM_TSC_GROUP4_IO4 != NU
\r
302 tmp_value_1 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
304 if (tmp_value_0 != 0) {GPIOA->AFR[0] |= tmp_value_0;}
\r
305 if (tmp_value_1 != 0) {GPIOA->AFR[1] |= tmp_value_1;}
\r
310 #if TSLPRM_TSC_GROUP3_IO2 != NU
\r
311 tmp_value_0 |= (uint32_t)((uint32_t)3 << (0 * 4));
\r
313 #if TSLPRM_TSC_GROUP3_IO3 != NU
\r
314 tmp_value_0 |= (uint32_t)((uint32_t)3 << (1 * 4));
\r
316 #if TSLPRM_TSC_GROUP3_IO4 != NU
\r
317 tmp_value_0 |= (uint32_t)((uint32_t)3 << (2 * 4));
\r
319 #if TSLPRM_TSC_GROUP5_IO1 != NU
\r
320 tmp_value_0 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
322 #if TSLPRM_TSC_GROUP5_IO2 != NU
\r
323 tmp_value_0 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
325 #if TSLPRM_TSC_GROUP5_IO3 != NU
\r
326 tmp_value_0 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
328 #if TSLPRM_TSC_GROUP5_IO4 != NU
\r
329 tmp_value_0 |= (uint32_t)((uint32_t)3 << (7 * 4));
\r
331 #if TSLPRM_TSC_GROUP6_IO1 != NU
\r
332 tmp_value_1 |= (uint32_t)((uint32_t)3 << (3 * 4));
\r
334 #if TSLPRM_TSC_GROUP6_IO2 != NU
\r
335 tmp_value_1 |= (uint32_t)((uint32_t)3 << (4 * 4));
\r
337 #if TSLPRM_TSC_GROUP6_IO3 != NU
\r
338 tmp_value_1 |= (uint32_t)((uint32_t)3 << (5 * 4));
\r
340 #if TSLPRM_TSC_GROUP6_IO4 != NU
\r
341 tmp_value_1 |= (uint32_t)((uint32_t)3 << (6 * 4));
\r
343 if (tmp_value_0 != 0) {GPIOB->AFR[0] |= tmp_value_0;}
\r
344 if (tmp_value_1 != 0) {GPIOB->AFR[1] |= tmp_value_1;}
\r
346 //==================
\r
347 // TSC configuration
\r
348 //==================
\r
350 // Enable TSC clock
\r
351 RCC->AHBENR |= RCC_AHBENR_TSEN;
\r
353 // Disable Schmitt trigger hysteresis on all used TS IOs (Channel, Shield and Sampling IOs)
\r
354 //-----------------------------------------------------------------------------------------
\r
356 tmp_value_0 = 0xFFFFFFFF;
\r
357 #if TSLPRM_TSC_GROUP1_IO1 != NU
\r
358 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 0);
\r
360 #if TSLPRM_TSC_GROUP1_IO2 != NU
\r
361 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 1);
\r
363 #if TSLPRM_TSC_GROUP1_IO3 != NU
\r
364 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 2);
\r
366 #if TSLPRM_TSC_GROUP1_IO4 != NU
\r
367 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 3);
\r
369 #if TSLPRM_TSC_GROUP2_IO1 != NU
\r
370 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 4);
\r
372 #if TSLPRM_TSC_GROUP2_IO2 != NU
\r
373 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 5);
\r
375 #if TSLPRM_TSC_GROUP2_IO3 != NU
\r
376 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 6);
\r
378 #if TSLPRM_TSC_GROUP2_IO4 != NU
\r
379 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 7);
\r
381 #if TSLPRM_TSC_GROUP3_IO1 != NU
\r
382 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 8);
\r
384 #if TSLPRM_TSC_GROUP3_IO2 != NU
\r
385 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 9);
\r
387 #if TSLPRM_TSC_GROUP3_IO3 != NU
\r
388 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 10);
\r
390 #if TSLPRM_TSC_GROUP3_IO4 != NU
\r
391 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 11);
\r
393 #if TSLPRM_TSC_GROUP4_IO1 != NU
\r
394 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 12);
\r
396 #if TSLPRM_TSC_GROUP4_IO2 != NU
\r
397 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 13);
\r
399 #if TSLPRM_TSC_GROUP4_IO3 != NU
\r
400 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 14);
\r
402 #if TSLPRM_TSC_GROUP4_IO4 != NU
\r
403 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 15);
\r
405 #if TSLPRM_TSC_GROUP5_IO1 != NU
\r
406 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 16);
\r
408 #if TSLPRM_TSC_GROUP5_IO2 != NU
\r
409 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 17);
\r
411 #if TSLPRM_TSC_GROUP5_IO3 != NU
\r
412 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 18);
\r
414 #if TSLPRM_TSC_GROUP5_IO4 != NU
\r
415 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 19);
\r
417 #if TSLPRM_TSC_GROUP6_IO1 != NU
\r
418 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 20);
\r
420 #if TSLPRM_TSC_GROUP6_IO2 != NU
\r
421 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 21);
\r
423 #if TSLPRM_TSC_GROUP6_IO3 != NU
\r
424 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 22);
\r
426 #if TSLPRM_TSC_GROUP6_IO4 != NU
\r
427 tmp_value_0 &= (uint32_t)~((uint32_t)1 << 23);
\r
429 if (tmp_value_0 != 0xFFFFFFFF) {TSC->IOHCR &= tmp_value_0;}
\r
431 // Set Sampling Capacitor IOs
\r
432 //---------------------------
\r
435 #if TSLPRM_TSC_GROUP1_IO1 == SAMPCAP
\r
436 tmp_value_0 |= (uint32_t)((uint32_t)1 << 0);
\r
438 #if TSLPRM_TSC_GROUP1_IO2 == SAMPCAP
\r
439 tmp_value_0 |= (uint32_t)((uint32_t)1 << 1);
\r
441 #if TSLPRM_TSC_GROUP1_IO3 == SAMPCAP
\r
442 tmp_value_0 |= (uint32_t)((uint32_t)1 << 2);
\r
444 #if TSLPRM_TSC_GROUP1_IO4 == SAMPCAP
\r
445 tmp_value_0 |= (uint32_t)((uint32_t)1 << 3);
\r
447 #if TSLPRM_TSC_GROUP2_IO1 == SAMPCAP
\r
448 tmp_value_0 |= (uint32_t)((uint32_t)1 << 4);
\r
450 #if TSLPRM_TSC_GROUP2_IO2 == SAMPCAP
\r
451 tmp_value_0 |= (uint32_t)((uint32_t)1 << 5);
\r
453 #if TSLPRM_TSC_GROUP2_IO3 == SAMPCAP
\r
454 tmp_value_0 |= (uint32_t)((uint32_t)1 << 6);
\r
456 #if TSLPRM_TSC_GROUP2_IO4 == SAMPCAP
\r
457 tmp_value_0 |= (uint32_t)((uint32_t)1 << 7);
\r
459 #if TSLPRM_TSC_GROUP3_IO1 == SAMPCAP
\r
460 tmp_value_0 |= (uint32_t)((uint32_t)1 << 8);
\r
462 #if TSLPRM_TSC_GROUP3_IO2 == SAMPCAP
\r
463 tmp_value_0 |= (uint32_t)((uint32_t)1 << 9);
\r
465 #if TSLPRM_TSC_GROUP3_IO3 == SAMPCAP
\r
466 tmp_value_0 |= (uint32_t)((uint32_t)1 << 10);
\r
468 #if TSLPRM_TSC_GROUP3_IO4 == SAMPCAP
\r
469 tmp_value_0 |= (uint32_t)((uint32_t)1 << 11);
\r
471 #if TSLPRM_TSC_GROUP4_IO1 == SAMPCAP
\r
472 tmp_value_0 |= (uint32_t)((uint32_t)1 << 12);
\r
474 #if TSLPRM_TSC_GROUP4_IO2 == SAMPCAP
\r
475 tmp_value_0 |= (uint32_t)((uint32_t)1 << 13);
\r
477 #if TSLPRM_TSC_GROUP4_IO3 == SAMPCAP
\r
478 tmp_value_0 |= (uint32_t)((uint32_t)1 << 14);
\r
480 #if TSLPRM_TSC_GROUP4_IO4 == SAMPCAP
\r
481 tmp_value_0 |= (uint32_t)((uint32_t)1 << 15);
\r
483 #if TSLPRM_TSC_GROUP5_IO1 == SAMPCAP
\r
484 tmp_value_0 |= (uint32_t)((uint32_t)1 << 16);
\r
486 #if TSLPRM_TSC_GROUP5_IO2 == SAMPCAP
\r
487 tmp_value_0 |= (uint32_t)((uint32_t)1 << 17);
\r
489 #if TSLPRM_TSC_GROUP5_IO3 == SAMPCAP
\r
490 tmp_value_0 |= (uint32_t)((uint32_t)1 << 18);
\r
492 #if TSLPRM_TSC_GROUP5_IO4 == SAMPCAP
\r
493 tmp_value_0 |= (uint32_t)((uint32_t)1 << 19);
\r
495 #if TSLPRM_TSC_GROUP6_IO1 == SAMPCAP
\r
496 tmp_value_0 |= (uint32_t)((uint32_t)1 << 20);
\r
498 #if TSLPRM_TSC_GROUP6_IO2 == SAMPCAP
\r
499 tmp_value_0 |= (uint32_t)((uint32_t)1 << 21);
\r
501 #if TSLPRM_TSC_GROUP6_IO3 == SAMPCAP
\r
502 tmp_value_0 |= (uint32_t)((uint32_t)1 << 22);
\r
504 #if TSLPRM_TSC_GROUP6_IO4 == SAMPCAP
\r
505 tmp_value_0 |= (uint32_t)((uint32_t)1 << 23);
\r
507 if (tmp_value_0 != 0) {TSC->IOSCR |= tmp_value_0;}
\r
513 * @brief Initializes the acquisition module.
\r
517 TSL_Status_enum_T TSL_acq_Init(void)
\r
520 #if TSLPRM_TSC_GPIO_CONFIG > 0
\r
521 TSL_acq_InitGPIOs();
\r
524 // Enable TSC clock
\r
525 RCC->AHBENR |= RCC_AHBENR_TSEN;
\r
531 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_CTPH << 28) & 0xF0000000;
\r
534 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_CTPL << 24) & 0x0F000000;
\r
536 // Set SpreadSpectrum
\r
537 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_USE_SS << 16) & 0x00010000;
\r
538 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_SSD << 17) & 0x00FE0000;
\r
539 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_SSPSC << 15) & 0x00008000;
\r
542 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_PGPSC << 12) & 0x00007000;
\r
545 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_MCV << 5) & 0x000000E0;
\r
547 // Set IO default in Output PP Low to discharge all capacitors
\r
548 TSC->CR &= (uint32_t)(~(1 << 4));
\r
550 // Set Synchronization Mode
\r
551 #if TSLPRM_TSC_AM > 0
\r
553 // Set Synchronization Pin in Alternate-Function mode
\r
554 RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // Set GPIOB clock
\r
556 #if TSLPRM_TSC_SYNC_PIN == 0 // PB08
\r
557 GPIOB->MODER &= 0xFFFCFFFF;
\r
558 GPIOB->MODER |= 0x00020000;
\r
559 GPIOB->AFR[1] |= 0x00000003;
\r
561 GPIOB->MODER &= 0xFFCFFFFF;
\r
562 GPIOB->MODER |= 0x00200000;
\r
563 GPIOB->AFR[1] |= 0x00000300;
\r
566 // Set Synchronization Polarity
\r
567 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_SYNC_POL << 3) & 0x00000008;
\r
571 // Set acquisition mode
\r
572 TSC->CR |= (uint32_t)((uint32_t)TSLPRM_TSC_AM << 2) & 0x00000004;
\r
574 #if TSLPRM_USE_ACQ_INTERRUPT > 0
\r
576 // Set both EOA and MCE interrupts
\r
580 NVIC_SetPriority(TS_IRQn, 0);
\r
581 NVIC_EnableIRQ(TS_IRQn);
\r
585 return TSL_STATUS_OK;
\r
591 * @brief Configures a Bank.
\r
592 * @param[in] idx_bk Index of the Bank to configure
\r
595 TSL_Status_enum_T TSL_acq_BankConfig(TSL_tIndex_T idx_bk)
\r
597 TSL_tIndex_T idx_ch;
\r
598 uint32_t objs; /* bit field of TSL_ObjStatus_enum_T type */
\r
601 CONST TSL_Bank_T *bank = &(TSL_Globals.Bank_Array[idx_bk]);
\r
602 CONST TSL_ChannelSrc_T *pchSrc = bank->p_chSrc;
\r
603 CONST TSL_ChannelDest_T *pchDest = bank->p_chDest;
\r
605 // Check parameters (if USE_FULL_ASSERT is defined)
\r
606 assert_param(IS_BANK_INDEX_OK(idx_bk));
\r
608 // Mark the current bank processed
\r
609 TSL_Globals.This_Bank = idx_bk;
\r
611 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
612 // Enable the Gx_IOy used as channels (channels + shield)
\r
613 TSC->IOCCR = bank->msk_IOCCR_channels;
\r
614 // Enable acquisition on selected Groups
\r
615 TSC->IOGCSR = bank->msk_IOGCSR_groups;
\r
616 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
618 // For all channels of the bank check if they are OFF or BURST_ONLY
\r
619 // and set acquisition status flag
\r
620 for (idx_ch = 0; idx_ch < bank->NbChannels; idx_ch++)
\r
623 // Check Object status flag
\r
624 objs = bank->p_chData[pchDest->IdxDest].Flags.ObjStatus;
\r
626 if (objs != TSL_OBJ_STATUS_ON)
\r
628 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
629 // Get the Channel Group mask
\r
630 gx = pchSrc->msk_IOGCSR_group;
\r
631 // Stop acquisition of the Group
\r
632 TSC->IOGCSR &= (uint32_t)~gx;
\r
633 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
635 if (objs == TSL_OBJ_STATUS_OFF)
\r
637 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
638 // Get the Channel IO mask
\r
639 ioy = pchSrc->msk_IOCCR_channel;
\r
640 // Stop Burst of the Channel
\r
641 TSC->IOCCR &= (uint32_t)~ioy;
\r
642 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
651 return TSL_STATUS_OK;
\r
656 * @brief Start acquisition on a previously configured bank
\r
660 void TSL_acq_BankStartAcq(void)
\r
662 // Clear both EOAIC and MCEIC flags
\r
665 // Wait capacitors discharge
\r
666 SoftDelay(TSL_DELAY_DISCHARGE);
\r
668 #if TSLPRM_TSC_IODEF > 0 // Default = Input Floating
\r
669 // Set IO default in Input Floating
\r
670 TSC->CR |= (1 << 4);
\r
673 // Start acquisition
\r
679 * @brief Wait end of acquisition
\r
683 TSL_Status_enum_T TSL_acq_BankWaitEOC(void)
\r
685 TSL_Status_enum_T retval = TSL_STATUS_BUSY;
\r
688 if (TSC->ISR & 0x01)
\r
691 #if TSLPRM_TSC_IODEF > 0 // Default = Input Floating
\r
692 // Set IO default in Output PP Low to discharge all capacitors
\r
693 TSC->CR &= (uint32_t)(~(1 << 4));
\r
697 if (TSC->ISR & 0x02)
\r
699 retval = TSL_STATUS_ERROR;
\r
703 retval = TSL_STATUS_OK;
\r
712 * @brief Return the current measure
\r
713 * @param[in] index Index of the measure source
\r
716 TSL_tMeas_T TSL_acq_GetMeas(TSL_tIndex_T index)
\r
718 return(TSC->IOGXCR[index]);
\r
723 * @brief Compute the Delta value
\r
724 * @param[in] ref Reference value
\r
725 * @param[in] meas Last Measurement value
\r
726 * @retval Delta value
\r
728 TSL_tDelta_T TSL_acq_ComputeDelta(TSL_tRef_T ref, TSL_tMeas_T meas)
\r
730 return((TSL_tDelta_T)(ref - meas));
\r
735 * @brief Compute the Measurement value
\r
736 * @param[in] ref Reference value
\r
737 * @param[in] delta Delta value
\r
738 * @retval Measurement value
\r
740 TSL_tMeas_T TSL_acq_ComputeMeas(TSL_tRef_T ref, TSL_tDelta_T delta)
\r
742 return((TSL_tMeas_T)(ref - delta));
\r
747 * @brief Check noise (not used)
\r
751 TSL_AcqStatus_enum_T TSL_acq_CheckNoise(void)
\r
753 return TSL_ACQ_STATUS_OK;
\r
758 * @brief Check if a filter must be used on the current channel (not used)
\r
759 * @param[in] pCh Pointer on the channel data information
\r
760 * @retval Result TRUE if a filter can be applied
\r
762 TSL_Bool_enum_T TSL_acq_UseFilter(TSL_ChannelData_T *pCh)
\r
769 * @brief Test if the Reference is incorrect (not used)
\r
770 * @param[in] pCh Pointer on the channel data information
\r
771 * @retval Result TRUE if the Reference is out of range
\r
773 TSL_Bool_enum_T TSL_acq_TestReferenceOutOfRange(TSL_ChannelData_T *pCh)
\r
780 * @brief Test if the measure has crossed the reference target (not used)
\r
781 * @param[in] pCh Pointer on the channel data information
\r
782 * @param[in] new_meas Measure of the last acquisition on this channel
\r
783 * @retval Result TRUE if the Reference is valid
\r
785 TSL_Bool_enum_T TSL_acq_TestFirstReferenceIsValid(TSL_ChannelData_T *pCh, TSL_tMeas_T new_meas)
\r
791 #if defined(__IAR_SYSTEMS_ICC__) // IAR/EWARM
\r
792 #pragma optimize=low
\r
793 #elif defined(__CC_ARM) // Keil/MDK-ARM
\r
796 #elif defined(__TASKING__) // Altium/Tasking
\r
797 #pragma optimize O0
\r
798 #elif defined(__GNUC__) // Atollic/True Studio + Raisonance/RKit
\r
799 #pragma GCC push_options
\r
800 #pragma GCC optimize ("O0")
\r
803 * @brief Software delay (private routine)
\r
804 * @param val Wait delay
\r
807 void SoftDelay(uint32_t val)
\r
810 for (i = val; i > 0; i--)
\r
813 #if defined(__TASKING__)
\r
814 #pragma endoptimize
\r
817 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r