2 ******************************************************************************
\r
3 * @file tsl_acq_stm32l1xx_sw.c
\r
4 * @author MCD Application Team
\r
6 * @date 22-January-2013
\r
7 * @brief This file contains all functions to manage the acquisition
\r
8 * on STM32l1xx products using the software mode.
\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_stm32l1xx_sw.h"
\r
31 #include "tsl_globals.h"
\r
33 /* Private typedefs ----------------------------------------------------------*/
\r
35 // Register configuration
\r
38 unsigned int RI_ASCR : 3;
\r
39 unsigned int RI_ASCR_bit : 5;
\r
42 /* Private defines -----------------------------------------------------------*/
\r
43 #define SIZEOFBANKCONF (17) //2 mask RIRs + 5 ports x 3 mask registers(MODER input, output, ODR) => 17 registers
\r
45 /* Private macros ------------------------------------------------------------*/
\r
46 #define IS_BANK_INDEX_OK(INDEX) (((INDEX) == 0) || (((INDEX) > 0) && ((INDEX) < TSLPRM_TOTAL_BANKS)))
\r
48 #define TSL_CHANNEL_PORT(channel) (channel >> 4)
\r
49 #define TSL_CHANNEL_IO(channel) (channel & 0x0F)
\r
52 #define TSL_RI_HYSCR_MASK(channel) (1 << TSL_CHANNEL_IO(channel))
\r
54 #define TSL_RCC_AHBENR_Config(channel) (RCC->AHBENR |= TSL_GPIO_Clock_LookUpTable[TSL_CHANNEL_PORT(channel)])
\r
56 #define TSL_RI_HYSCR_Config(channel) (*TSL_RI_HYSCR_LookUpTable[TSL_CHANNEL_PORT(channel)] |= TSL_RI_HYSCR_MASK(channel))
\r
58 #define TSL_GPIO_MODER_IN_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->MODER &= (uint32_t)(~(3 << (2 * TSL_CHANNEL_IO(channel)))))
\r
59 #define TSL_GPIO_MODER_OUT_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->MODER = (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->MODER & (uint32_t)(~(3 << (2 * TSL_CHANNEL_IO(channel))))) | (1 << (2 * TSL_CHANNEL_IO(channel))))
\r
60 #define TSL_GPIO_PUPDR_NO_PUPD_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->PUPDR &= (uint32_t)(~(3 << (2 * TSL_CHANNEL_IO(channel)))))
\r
61 #define TSL_GPIO_OTYPER_PP_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->OTYPER &= (uint32_t)(~(1 << TSL_CHANNEL_IO(channel))))
\r
62 #define TSL_GPIO_OSPEEDR_VL_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->OSPEEDR &= (uint32_t)~(3 << (2 * TSL_CHANNEL_IO(channel))))
\r
63 #define TSL_GPIO_BS_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->BSRRL = (uint16_t)(1 << (TSL_CHANNEL_IO(channel))))
\r
64 #define TSL_GPIO_BR_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->BSRRH = (uint16_t)(1 << (TSL_CHANNEL_IO(channel))))
\r
67 /* Private variables ---------------------------------------------------------*/
\r
68 uint32_t TSL_BankSampleConf[SIZEOFBANKCONF];
\r
69 uint32_t TSL_BankChannelConf[SIZEOFBANKCONF];
\r
70 uint32_t tab_MeasurementCounter[11];
\r
71 extern TSL_Params_T TSL_Params;
\r
73 CONST TSL_Bank_T *bank;
\r
74 TSL_tIndex_T NumberOfChannelOn = 0;
\r
75 TSL_tNb_T NumberOfChannels = 0;
\r
76 TSL_Status_enum_T TSL_Acq_Status = TSL_STATUS_BUSY;
\r
77 uint16_t GroupToCheck = 0;
\r
79 uint32_t TSL_GPIO_Clock_LookUpTable[] = {RCC_AHBPeriph_GPIOA, RCC_AHBPeriph_GPIOB, RCC_AHBPeriph_GPIOC, RCC_AHBPeriph_GPIOD, RCC_AHBPeriph_GPIOE, RCC_AHBPeriph_GPIOF, RCC_AHBPeriph_GPIOG, RCC_AHBPeriph_GPIOH};
\r
80 GPIO_TypeDef *TSL_GPIO_LookUpTable[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH};
\r
82 uint16_t *TSL_RI_HYSCR_LookUpTable[] =
\r
84 (uint16_t *)&RI->HYSCR1, (uint16_t *)&RI->HYSCR1 + 1,
\r
85 (uint16_t *)&RI->HYSCR2, (uint16_t *)&RI->HYSCR2 + 1,
\r
86 (uint16_t *)&RI->HYSCR3, (uint16_t *)&RI->HYSCR3 + 1,
\r
87 (uint16_t *)&RI->HYSCR4, (uint16_t *)&RI->HYSCR4 + 1
\r
90 CONST TSL_RIConf_t TSL_RI_Conf_LookUpTable[101] =
\r
201 #if (TSLPRM_USE_GPIOA)
\r
202 uint32_t GPIOA_IDR_Mask = 0;
\r
204 #if (TSLPRM_USE_GPIOB)
\r
205 uint32_t GPIOB_IDR_Mask = 0;
\r
207 #if (TSLPRM_USE_GPIOC)
\r
208 uint32_t GPIOC_IDR_Mask = 0;
\r
210 #if (TSLPRM_USE_GPIOF)
\r
211 uint32_t GPIOF_IDR_Mask = 0;
\r
213 #if (TSLPRM_USE_GPIOG)
\r
214 uint32_t GPIOG_IDR_Mask = 0;
\r
217 /* Private functions prototype -----------------------------------------------*/
\r
218 void SoftDelay(uint16_t val);
\r
219 void TSL_BankConf(uint32_t * BankConf, TSL_Conf_t Conf);
\r
220 void TSL_acq_GroupDone(uint16_t EndedGroup);
\r
223 * @brief Configures the acquisition module.
\r
224 * @param[in] BankConf Pointer to the bank to configure
\r
225 * @param[in] Conf Configuration
\r
228 void TSL_BankConf(uint32_t *BankConf, TSL_Conf_t Conf)
\r
230 BankConf[TSL_RI_Conf_LookUpTable[Conf].RI_ASCR] |= (1 << (TSL_RI_Conf_LookUpTable[Conf].RI_ASCR_bit));
\r
232 switch (TSL_CHANNEL_PORT(Conf))
\r
234 case TSL_BANK_GPIOA: BankConf[2] |= (3 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER input
\r
235 BankConf[3] |= (1 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER output
\r
236 BankConf[4] |= (1 << (TSL_CHANNEL_IO(Conf))); //ODR
\r
238 case TSL_BANK_GPIOB: BankConf[5] |= (3 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER input
\r
239 BankConf[6] |= (1 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER output
\r
240 BankConf[7] |= (1 << (TSL_CHANNEL_IO(Conf))); //ODR
\r
242 case TSL_BANK_GPIOC: BankConf[8] |= (3 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER input
\r
243 BankConf[9] |= (1 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER output
\r
244 BankConf[10] |= (1 << (TSL_CHANNEL_IO(Conf))); //ODR
\r
246 case TSL_BANK_GPIOF: BankConf[11] |= (3 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER input
\r
247 BankConf[12] |= (1 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER output
\r
248 BankConf[13] |= (1 << (TSL_CHANNEL_IO(Conf))); //ODR
\r
250 case TSL_BANK_GPIOG: BankConf[14] |= (3 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER input
\r
251 BankConf[15] |= (1 << (2 * (TSL_CHANNEL_IO(Conf)))); //MODER output
\r
252 BankConf[16] |= (1 << (TSL_CHANNEL_IO(Conf))); //ODR
\r
260 * @brief Initializes the acquisition module.
\r
264 TSL_Status_enum_T TSL_acq_Init(void)
\r
266 CONST TSL_Bank_T *LocalBank = &(TSL_Globals.Bank_Array[0]);
\r
267 TSL_tNb_T NumberOfBanks = TSLPRM_TOTAL_BANKS;
\r
268 TSL_tNb_T LocalNumberOfChannels = 0;
\r
269 TSL_tIndex_T idx_bk;
\r
270 TSL_tIndex_T idx_ch;
\r
271 CONST TSL_ChannelSrc_T *p_chSrc = LocalBank->p_chSrc; // Pointer to the current channel
\r
273 /* Enables the comparator interface clock */
\r
274 RCC->APB1ENR |= RCC_APB1Periph_COMP;
\r
276 //====================
\r
277 // GPIOs configuration
\r
278 //====================
\r
279 for (idx_bk = 0; idx_bk < NumberOfBanks; idx_bk++)
\r
281 LocalBank = &(TSL_Globals.Bank_Array[idx_bk]);
\r
282 p_chSrc = LocalBank->p_chSrc;
\r
284 #if (TSLPRM_USE_SHIELD > 0)
\r
285 // Enables GPIOs clock
\r
286 TSL_RCC_AHBENR_Config(LocalBank->shield_sample);
\r
288 // Bank shield configuration
\r
289 /* Disables Hysteresis Register */
\r
290 TSL_RI_HYSCR_Config(LocalBank->shield_sample);
\r
292 /* Output PP config */
\r
293 TSL_GPIO_OTYPER_PP_Config(p_chSrc->t_sample);
\r
294 TSL_GPIO_OTYPER_PP_Config(p_chSrc->t_channel);
\r
295 /* 400kHz config */
\r
296 TSL_GPIO_OSPEEDR_VL_Config(p_chSrc->t_sample);
\r
297 TSL_GPIO_OSPEEDR_VL_Config(p_chSrc->t_channel);
\r
298 /* No pull up/pull down config */
\r
299 TSL_GPIO_PUPDR_NO_PUPD_Config(LocalBank->shield_sample);
\r
300 TSL_GPIO_PUPDR_NO_PUPD_Config(LocalBank->shield_channel);
\r
302 TSL_GPIO_BR_Config(LocalBank->shield_sample);
\r
303 TSL_GPIO_BR_Config(LocalBank->shield_channel);
\r
305 TSL_GPIO_MODER_OUT_Config(LocalBank->shield_sample);
\r
306 TSL_GPIO_MODER_OUT_Config(LocalBank->shield_channel);
\r
309 LocalNumberOfChannels = LocalBank->NbChannels;
\r
312 idx_ch < LocalNumberOfChannels;
\r
315 /* Enables GPIOs clock */
\r
316 TSL_RCC_AHBENR_Config(p_chSrc->t_sample);
\r
317 TSL_RCC_AHBENR_Config(p_chSrc->t_channel);
\r
319 // Bank/channel configuration
\r
320 /* Disables Hysteresis Register */
\r
321 TSL_RI_HYSCR_Config(p_chSrc->t_sample);
\r
322 /* Output PP config */
\r
323 TSL_GPIO_OTYPER_PP_Config(p_chSrc->t_sample);
\r
324 TSL_GPIO_OTYPER_PP_Config(p_chSrc->t_channel);
\r
325 /* 400kHz config */
\r
326 TSL_GPIO_OSPEEDR_VL_Config(p_chSrc->t_sample);
\r
327 TSL_GPIO_OSPEEDR_VL_Config(p_chSrc->t_channel);
\r
328 /* No pull up/pull down config */
\r
329 TSL_GPIO_PUPDR_NO_PUPD_Config(p_chSrc->t_sample);
\r
330 TSL_GPIO_PUPDR_NO_PUPD_Config(p_chSrc->t_channel);
\r
332 TSL_GPIO_BR_Config(p_chSrc->t_sample);
\r
333 TSL_GPIO_BR_Config(p_chSrc->t_channel);
\r
335 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_sample);
\r
336 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_channel);
\r
342 /* Enable RI Switch */
\r
343 RI->ASCR1 &= (uint32_t)(~0x80000000); // ADC analog switches open !!!
\r
345 return TSL_STATUS_OK;
\r
350 * @brief Configures a Bank.
\r
351 * @param[in] idx_bk Index of the Bank to configure
\r
354 TSL_Status_enum_T TSL_acq_BankConfig(TSL_tIndex_T idx_bk)
\r
356 TSL_tIndex_T index;
\r
357 TSL_tIndex_T idx_dest;
\r
358 TSL_tIndex_T idx_ch;
\r
359 CONST TSL_ChannelDest_T *p_chDest; // Pointer to the current channel
\r
360 CONST TSL_ChannelSrc_T *p_chSrc; // Pointer to the current channel
\r
362 // Check parameters (if USE_FULL_ASSERT is defined)
\r
363 assert_param(IS_BANK_INDEX_OK(idx_bk));
\r
365 bank = &(TSL_Globals.Bank_Array[idx_bk]);
\r
367 for (index = 0;index < SIZEOFBANKCONF;index++)
\r
369 TSL_BankSampleConf[index] = 0x00000000;
\r
370 TSL_BankChannelConf[index] = 0x00000000;
\r
373 NumberOfChannels = bank->NbChannels;
\r
374 NumberOfChannelOn = 0;
\r
375 GroupToCheck = 0;//init group to check
\r
377 p_chDest = bank->p_chDest;
\r
378 p_chSrc = bank->p_chSrc;
\r
379 for (idx_ch = 0; idx_ch < NumberOfChannels; idx_ch++)
\r
381 // Get index in the result array associated to the current channel
\r
382 idx_dest = p_chDest->IdxDest;
\r
384 if (bank->p_chData[idx_dest].Flags.ObjStatus != TSL_OBJ_STATUS_OFF)
\r
386 TSL_BankConf(TSL_BankSampleConf, p_chSrc->t_sample);
\r
387 TSL_BankConf(TSL_BankChannelConf, p_chSrc->t_channel);
\r
388 GroupToCheck |= (1 << (p_chSrc->IdxSrc));
\r
389 NumberOfChannelOn++;
\r
396 #if (TSLPRM_USE_GPIOA)
\r
397 GPIOA_IDR_Mask = TSL_BankSampleConf[4];
\r
400 #if (TSLPRM_USE_GPIOB)
\r
401 GPIOB_IDR_Mask = TSL_BankSampleConf[7];
\r
404 #if (TSLPRM_USE_GPIOC)
\r
405 GPIOC_IDR_Mask = TSL_BankSampleConf[10];
\r
408 #if (TSLPRM_USE_GPIOF)
\r
409 GPIOF_IDR_Mask = TSL_BankSampleConf[13];
\r
412 #if (TSLPRM_USE_GPIOG)
\r
413 GPIOG_IDR_Mask = TSL_BankSampleConf[16];
\r
417 #if (TSLPRM_USE_SHIELD > 0)
\r
418 if (NumberOfChannelOn != 0)
\r
420 TSL_BankConf(TSL_BankSampleConf, bank->shield_sample);
\r
421 TSL_BankConf(TSL_BankChannelConf, bank->shield_channel);
\r
425 return TSL_STATUS_OK;
\r
431 * @brief Check which group is not over
\r
432 * @param[in] EndedGroup
\r
435 void TSL_acq_GroupDone(uint16_t EndedGroup)
\r
439 for (i = 0;i < 11;i++)
\r
441 if ((EndedGroup & (1 << i)) != (1 << i))
\r
443 tab_MeasurementCounter[i] = TSL_Params.AcqMax + 1;
\r
451 * @brief Start acquisition on a previously configured bank
\r
455 void TSL_acq_BankStartAcq(void)
\r
457 CONST TSL_Bank_T *LocalBank = &(TSL_Globals.Bank_Array[0]);
\r
458 TSL_tNb_T NumberOfBanks = TSLPRM_TOTAL_BANKS;
\r
459 TSL_tNb_T LocalNumberOfChannels = 0;
\r
460 TSL_tIndex_T BankIndex;
\r
462 uint16_t MeasurementCounter = 0;
\r
463 CONST TSL_ChannelSrc_T *p_chSrc;
\r
464 TSL_tIndex_T idx_ch;
\r
465 uint16_t GroupToCheckMask = 0;
\r
466 uint32_t GPIO_IDR_Mask = 0;
\r
467 uint8_t Check_Input = 0;
\r
469 #if (TSLPRM_USE_GPIOA)
\r
470 uint16_t TSL_GPIOA_IDR = 0;
\r
472 #if (TSLPRM_USE_GPIOB)
\r
473 uint16_t TSL_GPIOB_IDR = 0;
\r
475 #if (TSLPRM_USE_GPIOC)
\r
476 uint16_t TSL_GPIOC_IDR = 0;
\r
478 #if (TSLPRM_USE_GPIOF)
\r
479 uint16_t TSL_GPIOF_IDR = 0;
\r
481 #if (TSLPRM_USE_GPIOG)
\r
482 uint16_t TSL_GPIOG_IDR = 0;
\r
484 uint16_t GPIO_IDR = 0;
\r
486 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
489 #if (TSLPRM_IODEF > 0)
\r
490 //============================
\r
491 // All GPIOs in Input floating
\r
492 //============================
\r
493 for (BankIndex = 0; BankIndex < NumberOfBanks; BankIndex++)
\r
495 LocalBank = &(TSL_Globals.Bank_Array[BankIndex]);
\r
496 p_chSrc = LocalBank->p_chSrc;
\r
498 #if (TSLPRM_USE_SHIELD > 0)
\r
499 TSL_GPIO_MODER_IN_Config(LocalBank->shield_sample);
\r
500 TSL_GPIO_MODER_IN_Config(LocalBank->shield_channel);
\r
503 LocalNumberOfChannels = LocalBank->NbChannels;
\r
506 idx_ch < LocalNumberOfChannels;
\r
509 TSL_GPIO_MODER_IN_Config(p_chSrc->t_sample);
\r
510 TSL_GPIO_MODER_IN_Config(p_chSrc->t_channel);
\r
516 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
520 /* Open the analog switches */
\r
521 RI->ASCR1 &= (uint32_t)(~(TSL_BankSampleConf[0] | TSL_BankChannelConf[0]));
\r
522 RI->ASCR2 &= (uint32_t)(~(TSL_BankSampleConf[1] | TSL_BankChannelConf[1]));
\r
524 /* All IO to pushpull LOW for discharging all capacitors (Ctouch and Csense) */
\r
525 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
528 /* Discharging sampling capacitor and CTouch */
\r
529 #if (TSLPRM_USE_GPIOA)
\r
530 GPIOA->ODR &= (uint32_t)(~(TSL_BankSampleConf[4] | TSL_BankChannelConf[4]));
\r
531 GPIOA->MODER = (GPIOA->MODER & (uint32_t)(~(TSL_BankSampleConf[2] | TSL_BankChannelConf[2]))) | (TSL_BankSampleConf[3] | TSL_BankChannelConf[3]);
\r
533 #if (TSLPRM_USE_GPIOB)
\r
534 GPIOB->ODR &= (uint32_t)(~(TSL_BankSampleConf[7] | TSL_BankChannelConf[7]));
\r
535 GPIOB->MODER = (GPIOB->MODER & (uint32_t)(~(TSL_BankSampleConf[5] | TSL_BankChannelConf[5]))) | (TSL_BankSampleConf[6] | TSL_BankChannelConf[6]);
\r
537 #if (TSLPRM_USE_GPIOC)
\r
538 GPIOC->ODR &= (uint32_t)(~(TSL_BankSampleConf[10] | TSL_BankChannelConf[10]));
\r
539 GPIOC->MODER = (GPIOC->MODER & (uint32_t)(~(TSL_BankSampleConf[8] | TSL_BankChannelConf[8]))) | (TSL_BankSampleConf[9] | TSL_BankChannelConf[9]);
\r
541 #if (TSLPRM_USE_GPIOF)
\r
542 GPIOF->ODR &= (uint32_t)(~(TSL_BankSampleConf[13] | TSL_BankChannelConf[13]));
\r
543 GPIOF->MODER = (GPIOF->MODER & (uint32_t)(~(TSL_BankSampleConf[11] | TSL_BankChannelConf[11]))) | (TSL_BankSampleConf[12] | TSL_BankChannelConf[12]);
\r
545 #if (TSLPRM_USE_GPIOG)
\r
546 GPIOG->ODR &= (uint32_t)(~(TSL_BankSampleConf[16] | TSL_BankChannelConf[16]));
\r
547 GPIOG->MODER = (GPIOG->MODER & (uint32_t)(~(TSL_BankSampleConf[14] | TSL_BankChannelConf[14]))) | (TSL_BankSampleConf[15] | TSL_BankChannelConf[15]);
\r
552 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
556 /* Wait a while for a good discharging of all capacitors */
\r
557 SoftDelay(50); // ~14µs with fHCLK = 32MHz
\r
558 //this time depends of the size of the sampling capacitor
\r
560 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
563 /* All IO in input floating */
\r
564 #if (TSLPRM_USE_GPIOA)
\r
565 GPIOA->MODER &= (uint32_t)(~(TSL_BankSampleConf[2] | TSL_BankChannelConf[2]));
\r
567 #if (TSLPRM_USE_GPIOB)
\r
568 GPIOB->MODER &= (uint32_t)(~(TSL_BankSampleConf[5] | TSL_BankChannelConf[5]));
\r
570 #if (TSLPRM_USE_GPIOC)
\r
571 GPIOC->MODER &= (uint32_t)(~(TSL_BankSampleConf[8] | TSL_BankChannelConf[8]));
\r
573 #if (TSLPRM_USE_GPIOF)
\r
574 GPIOF->MODER &= (uint32_t)(~(TSL_BankSampleConf[11] | TSL_BankChannelConf[11]));
\r
576 #if (TSLPRM_USE_GPIOG)
\r
577 GPIOG->MODER &= (uint32_t)(~(TSL_BankSampleConf[14] | TSL_BankChannelConf[14]));
\r
580 /* set the IO to Vdd (io in push-pull HIGH when in output mode) */
\r
581 #if (TSLPRM_USE_GPIOA)
\r
582 GPIOA->ODR |= (TSL_BankSampleConf[4] | TSL_BankChannelConf[4]); /* HIGH level */
\r
584 #if (TSLPRM_USE_GPIOB)
\r
585 GPIOB->ODR |= (TSL_BankSampleConf[7] | TSL_BankChannelConf[7]); /* HIGH level */
\r
587 #if (TSLPRM_USE_GPIOC)
\r
588 GPIOC->ODR |= (TSL_BankSampleConf[10] | TSL_BankChannelConf[10]); /* HIGH level */
\r
590 #if (TSLPRM_USE_GPIOF)
\r
591 GPIOF->ODR |= (TSL_BankSampleConf[13] | TSL_BankChannelConf[13]); /* HIGH level */
\r
593 #if (TSLPRM_USE_GPIOG)
\r
594 GPIOG->ODR |= (TSL_BankSampleConf[16] | TSL_BankChannelConf[16]); /* HIGH level */
\r
597 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
601 /* Close the sampling capacitor analog switch */
\r
602 RI->ASCR1 |= (TSL_BankSampleConf[0]);
\r
603 RI->ASCR2 |= (TSL_BankSampleConf[1]);
\r
606 /* Loop while all the 1st channel of each group have not reach the VIH level */
\r
610 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
613 /* Charging Ctouch by connecting the IO to Vdd (io in push-pull HIGH) */
\r
614 #if (TSLPRM_USE_GPIOA)
\r
615 GPIOA->MODER |= (TSL_BankChannelConf[3]); /* Output push pull config */
\r
617 #if (TSLPRM_USE_GPIOB)
\r
618 GPIOB->MODER |= (TSL_BankChannelConf[6]); /* Output push pull config */
\r
620 #if (TSLPRM_USE_GPIOC)
\r
621 GPIOC->MODER |= (TSL_BankChannelConf[9]); /* Output push pull config */
\r
623 #if (TSLPRM_USE_GPIOF)
\r
624 GPIOF->MODER |= (TSL_BankChannelConf[12]); /* Output push pull config */
\r
626 #if (TSLPRM_USE_GPIOG)
\r
627 GPIOG->MODER |= (TSL_BankChannelConf[15]); /* Output push pull config */
\r
629 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
633 /* Wait a while for a good charging (programmable delay) */
\r
636 /* test GPIOx->IDR bit + group configuration for each channel */
\r
638 #if (TSLPRM_USE_GPIOA)
\r
639 TSL_GPIOA_IDR = GPIOA->IDR;
\r
640 if ((TSL_GPIOA_IDR & GPIOA_IDR_Mask) != 0)
\r
643 GPIOA_IDR_Mask &= (uint32_t)(~TSL_GPIOA_IDR);
\r
647 #if (TSLPRM_USE_GPIOB)
\r
648 TSL_GPIOB_IDR = GPIOB->IDR;
\r
649 if ((TSL_GPIOB_IDR & GPIOB_IDR_Mask) != 0)
\r
651 Check_Input = (1 << 1);
\r
652 GPIOB_IDR_Mask &= (uint32_t)(~TSL_GPIOB_IDR);
\r
656 #if (TSLPRM_USE_GPIOC)
\r
657 TSL_GPIOC_IDR = GPIOC->IDR;
\r
658 if ((TSL_GPIOC_IDR & GPIOC_IDR_Mask) != 0)
\r
660 Check_Input = (1 << 2);
\r
661 GPIOC_IDR_Mask &= (uint32_t)(~TSL_GPIOC_IDR);
\r
665 #if (TSLPRM_USE_GPIOF)
\r
666 TSL_GPIOF_IDR = GPIOF->IDR;
\r
667 if ((TSL_GPIOF_IDR & GPIOF_IDR_Mask) != 0)
\r
669 Check_Input = (1 << 5);
\r
670 GPIOF_IDR_Mask &= (uint32_t)(~TSL_GPIOF_IDR);
\r
674 #if (TSLPRM_USE_GPIOG)
\r
675 TSL_GPIOG_IDR = GPIOG->IDR;
\r
676 if ((TSL_GPIOG_IDR & GPIOG_IDR_Mask) != 0)
\r
678 Check_Input = (1 << 6);
\r
679 GPIOG_IDR_Mask &= (uint32_t)(~TSL_GPIOG_IDR);
\r
686 p_chSrc = bank->p_chSrc;
\r
687 for (idx_ch = 0; idx_ch < NumberOfChannels; idx_ch++)
\r
689 GroupToCheckMask = (1 << (p_chSrc->IdxSrc));
\r
690 if ((GroupToCheck & GroupToCheckMask) == (GroupToCheckMask))
\r
692 GPIO_IDR_Mask = (1 << TSL_CHANNEL_IO(p_chSrc->t_sample));
\r
694 switch (TSL_CHANNEL_PORT(p_chSrc->t_sample))
\r
696 #if (TSLPRM_USE_GPIOA)
\r
697 case 0: GPIO_IDR = TSL_GPIOA_IDR; break;
\r
699 #if (TSLPRM_USE_GPIOB)
\r
700 case 1: GPIO_IDR = TSL_GPIOB_IDR; break;
\r
702 #if (TSLPRM_USE_GPIOC)
\r
703 case 2: GPIO_IDR = TSL_GPIOC_IDR; break;
\r
705 #if (TSLPRM_USE_GPIOF)
\r
706 case 5: GPIO_IDR = TSL_GPIOF_IDR; break;
\r
708 #if (TSLPRM_USE_GPIOG)
\r
709 case 6: GPIO_IDR = TSL_GPIOG_IDR; break;
\r
714 if ((GPIO_IDR & GPIO_IDR_Mask) == GPIO_IDR_Mask)
\r
716 tab_MeasurementCounter[p_chSrc->IdxSrc] = MeasurementCounter;
\r
717 GroupToCheck &= (uint32_t)(~(1 << (p_chSrc->IdxSrc)));
\r
718 Check_Input &= (uint32_t)(~(1 << TSL_CHANNEL_PORT(p_chSrc->t_sample)));
\r
725 MeasurementCounter++;
\r
727 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
730 /* Configure All channels in input floating */
\r
731 #if (TSLPRM_USE_GPIOA)
\r
732 GPIOA->MODER &= (uint32_t)(~(TSL_BankChannelConf[2]));
\r
734 #if (TSLPRM_USE_GPIOB)
\r
735 GPIOB->MODER &= (uint32_t)(~(TSL_BankChannelConf[5]));
\r
737 #if (TSLPRM_USE_GPIOC)
\r
738 GPIOC->MODER &= (uint32_t)(~(TSL_BankChannelConf[8]));
\r
740 #if (TSLPRM_USE_GPIOF)
\r
741 GPIOF->MODER &= (uint32_t)(~(TSL_BankChannelConf[11]));
\r
743 #if (TSLPRM_USE_GPIOG)
\r
744 GPIOG->MODER &= (uint32_t)(~(TSL_BankChannelConf[14]));
\r
747 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
751 /* Charging the Csense cap with connecting it to Ctouch by closing the analog switch */
\r
752 RI->ASCR1 |= (TSL_BankChannelConf[0]);
\r
753 RI->ASCR2 |= (TSL_BankChannelConf[1]);
\r
755 /* Wait a while for a good charge transfering (programmable delay) */
\r
758 RI->ASCR1 &= (uint32_t)(~(TSL_BankChannelConf[0]));
\r
759 RI->ASCR2 &= (uint32_t)(~(TSL_BankChannelConf[1]));
\r
761 /*it's better to implement this like that because it's much more faster than to put this test in the "while test" below */
\r
762 if (MeasurementCounter > TSL_Params.AcqMax)
\r
764 TSL_acq_GroupDone(GroupToCheck);
\r
770 while (GroupToCheck != 0);
\r
773 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
776 //====================
\r
777 // All GPIOs in PP Low
\r
778 //====================
\r
779 for (BankIndex = 0; BankIndex < NumberOfBanks; BankIndex++)
\r
781 LocalBank = &(TSL_Globals.Bank_Array[BankIndex]);
\r
782 p_chSrc = LocalBank->p_chSrc;
\r
784 #if (TSLPRM_USE_SHIELD > 0)
\r
785 TSL_GPIO_BR_Config(LocalBank->shield_sample);
\r
786 TSL_GPIO_BR_Config(LocalBank->shield_channel);
\r
787 TSL_GPIO_MODER_OUT_Config(LocalBank->shield_sample);
\r
788 TSL_GPIO_MODER_OUT_Config(LocalBank->shield_channel);
\r
791 LocalNumberOfChannels = LocalBank->NbChannels;
\r
794 idx_ch < LocalNumberOfChannels;
\r
797 TSL_GPIO_BR_Config(p_chSrc->t_sample);
\r
798 TSL_GPIO_BR_Config(p_chSrc->t_channel);
\r
799 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_sample);
\r
800 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_channel);
\r
805 #if (TSLPRM_PROTECT_IO_ACCESS > 0)
\r
814 * @brief Wait end of acquisition
\r
818 TSL_Status_enum_T TSL_acq_BankWaitEOC(void)
\r
820 TSL_Status_enum_T retval = TSL_STATUS_BUSY;
\r
821 retval = TSL_STATUS_OK;
\r
827 * @brief Return the current measure
\r
828 * @param[in] index Index of the measure source
\r
831 TSL_tMeas_T TSL_acq_GetMeas(TSL_tIndex_T index)
\r
833 return(tab_MeasurementCounter[index]);
\r
838 * @brief Check noise (not used)
\r
842 TSL_AcqStatus_enum_T TSL_acq_CheckNoise(void)
\r
844 return TSL_ACQ_STATUS_OK;
\r
849 * @brief Process the TS Interrupt routine
\r
853 void TSL_acq_ProcessIT(void)
\r
858 * @brief Check if a filter must be used on the current channel (not used)
\r
859 * @param[in] pCh Pointer on the channel data information
\r
860 * @retval Result TRUE if a filter can be applied
\r
862 TSL_Bool_enum_T TSL_acq_UseFilter(TSL_ChannelData_T *pCh)
\r
869 * @brief Compute the Delta value
\r
870 * @param[in] ref Reference value
\r
871 * @param[in] meas Last Measurement value
\r
872 * @retval Delta value
\r
874 TSL_tDelta_T TSL_acq_ComputeDelta(TSL_tRef_T ref, TSL_tMeas_T meas)
\r
876 return((TSL_tDelta_T)(ref - meas));
\r
881 * @brief Compute the Measurement value
\r
882 * @param[in] ref Reference value
\r
883 * @param[in] delta Delta value
\r
884 * @retval Measurement value
\r
886 TSL_tMeas_T TSL_acq_ComputeMeas(TSL_tRef_T ref, TSL_tDelta_T delta)
\r
888 return((TSL_tMeas_T)(ref - delta));
\r
893 * @brief Test if the Reference is incorrect (not used)
\r
894 * @param[in] pCh Pointer on the channel data information
\r
895 * @retval Result TRUE if the Reference is out of range
\r
897 TSL_Bool_enum_T TSL_acq_TestReferenceOutOfRange(TSL_ChannelData_T *pCh)
\r
904 * @brief Test if the measure has crossed the reference target (not used)
\r
905 * @param[in] pCh Pointer on the channel data information
\r
906 * @param[in] new_meas Measure of the last acquisition on this channel
\r
907 * @retval Result TRUE if the Reference is valid
\r
909 TSL_Bool_enum_T TSL_acq_TestFirstReferenceIsValid(TSL_ChannelData_T *pCh, TSL_tMeas_T new_meas)
\r
915 #if defined(__IAR_SYSTEMS_ICC__) // IAR/EWARM
\r
916 #pragma optimize=medium
\r
917 #elif defined(__CC_ARM) // Keil/MDK-ARM
\r
920 #elif defined(__TASKING__) // Altium/Tasking
\r
921 #pragma optimize O0
\r
922 #elif defined(__GNUC__) // Atollic/True Studio + Raisonance/RKit
\r
923 #pragma GCC push_options
\r
924 #pragma GCC optimize ("O0")
\r
927 * @brief Software delay (private routine)
\r
928 * @param val Wait delay
\r
929 * With fHCLK = 32MHz: 1 = ~1µs, 50 = ~14µs, 100 = ~25µs, 200 = ~50µs
\r
932 void SoftDelay(uint16_t val)
\r
935 for (i = val; i > 0; i--)
\r
938 #if defined(__TASKING__)
\r
939 #pragma endoptimize
\r
942 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r