2 ******************************************************************************
\r
3 * @file tsl_acq_stm32l1xx_hw.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 Hardware mode (with Timers).
\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_hw.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
44 /* 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
51 #define TSL_GPIO_AFR(channel) ((TSL_CHANNEL_IO(channel) < 8) ? 0 : 1)
\r
52 #define TSL_GPIO_AFR_Shift(channel) ((TSL_CHANNEL_IO(channel) < 8) ? (4 * TSL_CHANNEL_IO(channel)) : (4 * (TSL_CHANNEL_IO(channel) - 8)))
\r
54 #define TSL_CPRI_HYSCR_MASK(channel) (1 << TSL_CHANNEL_IO(channel))
\r
55 #define TSL_CPRI_ASMR_MASK(channel) (1 << TSL_CHANNEL_IO(channel))
\r
56 #define TSL_CPRI_CMR_MASK(channel) (1 << TSL_CHANNEL_IO(channel))
\r
57 #define TSL_CPRI_CICR_MASK(channel) (1 << TSL_CHANNEL_IO(channel))
\r
59 #define TSL_RCC_AHBENR_Config(channel) (RCC->AHBENR |= TSL_GPIO_Clock_LookUpTable[TSL_CHANNEL_PORT(channel)])
\r
61 #define TSL_CPRI_ASCR_Config(channel) (*TSL_CPRI_ASCR_LookUpTable[TSL_RI_Conf_LookUpTable[channel].RI_ASCR] |= (1 << (TSL_RI_Conf_LookUpTable[channel].RI_ASCR_bit)))
\r
62 #define TSL_CPRI_HYSCR_Config(channel) (*TSL_CPRI_HYSCR_LookUpTable[TSL_CHANNEL_PORT(channel)] |= TSL_CPRI_HYSCR_MASK(channel))
\r
63 #define TSL_CPRI_ASMR_Config(channel) (*TSL_CPRI_ASMR_LookUpTable[TSL_CHANNEL_PORT(channel)] |= TSL_CPRI_ASMR_MASK(channel))
\r
64 #define TSL_CPRI_ASMR_Config_Clear(channel) (*TSL_CPRI_ASMR_LookUpTable[TSL_CHANNEL_PORT(channel)] &= (uint32_t)(~TSL_CPRI_ASMR_MASK(channel)))
\r
65 #define TSL_CPRI_CMR_Config(channel) (*TSL_CPRI_CMR_LookUpTable[TSL_CHANNEL_PORT(channel)] |= TSL_CPRI_CMR_MASK(channel))
\r
66 #define TSL_CPRI_CMR_Config_Clear(channel) (*TSL_CPRI_CMR_LookUpTable[TSL_CHANNEL_PORT(channel)] &= (uint32_t)(~TSL_CPRI_CMR_MASK(channel)))
\r
67 #define TSL_CPRI_CICR_Config(channel) (*TSL_CPRI_CICR_LookUpTable[TSL_CHANNEL_PORT(channel)] |= TSL_CPRI_CICR_MASK(channel))
\r
68 #define TSL_CPRI_CICR_Config_Clear(channel) (*TSL_CPRI_CICR_LookUpTable[TSL_CHANNEL_PORT(channel)] &= (uint32_t)(~TSL_CPRI_CICR_MASK(channel)))
\r
70 #define TSL_GPIO_MODER_IN_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->MODER &= (uint32_t)(~(3 << (2 * TSL_CHANNEL_IO(channel)))))
\r
71 #define TSL_GPIO_MODER_AF_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))))) | (2 << (2 * TSL_CHANNEL_IO(channel))))
\r
72 #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
73 #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
74 #define TSL_GPIO_OTYPER_PP_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->OTYPER &= (uint32_t)(~(1 << TSL_CHANNEL_IO(channel))))
\r
75 #define TSL_GPIO_OSPEEDR_VL_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->OSPEEDR &= (uint32_t)~(3 << (2 * TSL_CHANNEL_IO(channel))))
\r
76 #define TSL_GPIO_AFR_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->AFR[TSL_GPIO_AFR(channel)] |= (0x0E << (TSL_GPIO_AFR_Shift(channel))))
\r
77 #define TSL_GPIO_BS_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->BSRRL = (uint16_t)(1 << (TSL_CHANNEL_IO(channel))))
\r
78 #define TSL_GPIO_BR_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->BSRRH = (uint16_t)(1 << (TSL_CHANNEL_IO(channel))))
\r
80 #define TSL_GPIO_AFR_NOAF_Config(channel) (TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->AFR[TSL_GPIO_AFR(channel)] &= (uint32_t)(~(0x0F << (TSL_GPIO_AFR_Shift(channel)))))
\r
82 #define TSL_GPIO_IDR_XOR_CPRI_CMR(channel) ((TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->IDR)^(*TSL_CPRI_CMR_LookUpTable[TSL_CHANNEL_PORT(channel)]))
\r
83 #define TSL_GPIO_IDR_AND_CPRI_CMR(channel) ((TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(channel)]->IDR)&(*TSL_CPRI_CMR_LookUpTable[TSL_CHANNEL_PORT(channel)]))
\r
85 /* Private variables ---------------------------------------------------------*/
\r
86 CONST TSL_Bank_T *bank;
\r
87 TSL_tIndex_T NumberOfChannelOn = 0;
\r
88 TSL_tNb_T NumberOfChannels = 0;
\r
89 uint32_t tab_MeasurementCounter[11];
\r
90 TSL_Status_enum_T TSL_Acq_Status = TSL_STATUS_BUSY;
\r
91 static uint16_t GroupToCheck = 0;
\r
92 static TSL_tIndex_T NumberOfChannelChecked = 0;
\r
94 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
95 GPIO_TypeDef *TSL_GPIO_LookUpTable[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH};
\r
97 uint32_t *TSL_CPRI_ASCR_LookUpTable[] = {(uint32_t *)&CPRI->ASCR1, (uint32_t *)&CPRI->ASCR2};
\r
99 uint16_t *TSL_CPRI_HYSCR_LookUpTable[] =
\r
101 (uint16_t *)&CPRI->HYSCR1, (uint16_t *)&CPRI->HYSCR1 + 1,
\r
102 (uint16_t *)&CPRI->HYSCR2, (uint16_t *)&CPRI->HYSCR2 + 1,
\r
103 (uint16_t *)&CPRI->HYSCR3, (uint16_t *)&CPRI->HYSCR3 + 1,
\r
104 (uint16_t *)&CPRI->HYSCR4, (uint16_t *)&CPRI->HYSCR4 + 1
\r
107 uint32_t *TSL_CPRI_ASMR_LookUpTable[] = {(uint32_t *)&CPRI->ASMR1, (uint32_t *)&CPRI->ASMR2, (uint32_t *)&CPRI->ASMR3, 0, 0, (uint32_t *)&CPRI->ASMR4, (uint32_t *)&CPRI->ASMR5};
\r
108 uint32_t *TSL_CPRI_CMR_LookUpTable[] = {(uint32_t *)&CPRI->CMR1, (uint32_t *)&CPRI->CMR2, (uint32_t *)&CPRI->CMR3, 0, 0, (uint32_t *)&CPRI->CMR4, (uint32_t *)&CPRI->CMR5};
\r
109 uint32_t *TSL_CPRI_CICR_LookUpTable[] = {(uint32_t *)&CPRI->CICR1, (uint32_t *)&CPRI->CICR2, (uint32_t *)&CPRI->CICR3, 0, 0, (uint32_t *)&CPRI->CICR4, (uint32_t *)&CPRI->CICR5};
\r
111 CONST TSL_RIConf_t TSL_RI_Conf_LookUpTable[101] =
\r
222 /* Private functions prototype -----------------------------------------------*/
\r
223 void TSL_Init_GPIOs(void);
\r
224 void TSL_Init_TIMs(void);
\r
225 void TSL_Init_RI(void);
\r
226 uint8_t TSL_Check_GPIO_IDR(uint8_t sample);
\r
227 void SoftDelay(uint16_t val);
\r
231 * @brief Initializes the TouchSensing GPIOs.
\r
235 void TSL_Init_GPIOs(void)
\r
237 CONST TSL_Bank_T *LocalBank = &(TSL_Globals.Bank_Array[0]);
\r
238 TSL_tNb_T NumberOfBanks = TSLPRM_TOTAL_BANKS;
\r
239 TSL_tNb_T LocalNumberOfChannels = 0;
\r
240 TSL_tIndex_T idx_bk;
\r
241 TSL_tIndex_T idx_ch;
\r
242 CONST TSL_ChannelSrc_T *p_chSrc = LocalBank->p_chSrc; // Pointer to the current channel
\r
244 for (idx_bk = 0; idx_bk < NumberOfBanks; idx_bk++)
\r
246 LocalBank = &(TSL_Globals.Bank_Array[idx_bk]);
\r
247 p_chSrc = LocalBank->p_chSrc;
\r
249 #if (TSLPRM_USE_SHIELD > 0)
\r
250 // Enables GPIOs clock
\r
251 TSL_RCC_AHBENR_Config(LocalBank->shield_sample);
\r
253 // Bank shield configuration
\r
254 TSL_GPIO_OTYPER_PP_Config(LocalBank->shield_channel);
\r
255 TSL_GPIO_OSPEEDR_VL_Config(LocalBank->shield_channel);
\r
256 TSL_GPIO_PUPDR_NO_PUPD_Config(LocalBank->shield_channel);
\r
257 TSL_GPIO_AFR_Config(LocalBank->shield_channel);
\r
259 TSL_GPIO_OSPEEDR_VL_Config(LocalBank->shield_sample);
\r
260 TSL_GPIO_BR_Config(LocalBank->shield_sample);
\r
261 TSL_GPIO_OTYPER_PP_Config(LocalBank->shield_sample);
\r
262 TSL_GPIO_PUPDR_NO_PUPD_Config(LocalBank->shield_sample);
\r
264 TSL_GPIO_MODER_OUT_Config(LocalBank->shield_sample);
\r
265 TSL_GPIO_MODER_OUT_Config(LocalBank->shield_channel);
\r
268 LocalNumberOfChannels = LocalBank->NbChannels;
\r
271 idx_ch < LocalNumberOfChannels;
\r
274 TSL_RCC_AHBENR_Config(p_chSrc->t_sample);
\r
275 TSL_RCC_AHBENR_Config(p_chSrc->t_channel);
\r
277 TSL_GPIO_OTYPER_PP_Config(p_chSrc->t_channel);
\r
278 TSL_GPIO_OSPEEDR_VL_Config(p_chSrc->t_channel);
\r
279 TSL_GPIO_PUPDR_NO_PUPD_Config(p_chSrc->t_channel);
\r
280 TSL_GPIO_AFR_Config(p_chSrc->t_channel);
\r
282 TSL_GPIO_OSPEEDR_VL_Config(p_chSrc->t_sample);
\r
283 TSL_GPIO_BR_Config(p_chSrc->t_sample);
\r
284 TSL_GPIO_OTYPER_PP_Config(p_chSrc->t_sample);
\r
285 TSL_GPIO_PUPDR_NO_PUPD_Config(p_chSrc->t_sample);
\r
287 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_sample);
\r
288 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_channel);
\r
296 * @brief Initializes the TouchSensing timers.
\r
300 void TSL_Init_TIMs(void)
\r
302 // Enable Timers clocks
\r
303 RCC->APB2ENR |= ((1 << 4) | (1 << 2)); // TIM11, TIM9
\r
305 //==============================
\r
306 // TIMER 9 configuration: Master
\r
307 //==============================
\r
308 // Set the option register to redirect cpri_tim9_itr_O to TIM9_itr
\r
310 // Set the Autoreload value (signal frequency)
\r
311 //TIM9->ARR = 64; // freq = (64*2)*31.25ns = 1us
\r
312 TIM9->ARR = TSLPRM_TIM_RELOAD; // freq = (64*2)*31.25ns = 1us
\r
313 // Set the Prescaler value
\r
314 //TIM9->PSC = 0; // fCK_CNT = 32MHz/(0+1) = 32MHz --> T=31.25ns
\r
315 TIM9->PSC = TSLPRM_TIM_PRESCALER; // fCK_CNT = 32MHz/(1+1) = 32MHz --> T=31.25ns
\r
316 // Set UP counter, Center-Aligned mode 1
\r
318 // OC1REF used as TRGO
\r
319 TIM9->CR2 |= 0x40; // MMS=100
\r
320 // Select Master mode
\r
322 // Set Update generation
\r
325 // Channel 1 PWM configuration
\r
326 // Set the Output Compare Mode, PWM2
\r
327 TIM9->CCMR1 |= 0x0070;
\r
328 // Set the Pulse value
\r
329 //TIM9->CCR1 = 34; // duty cycle
\r
330 TIM9->CCR1 = (TSLPRM_TIM_RELOAD >> 1) + 1; // duty cycle
\r
331 // Compare output enable, active high
\r
332 TIM9->CCER |= 0x01;
\r
334 // Channel 2 PWM configuration
\r
335 // Set the Output Compare Mode, PWM2
\r
336 TIM9->CCMR1 |= 0x6000;
\r
337 // Set the Pulse value
\r
339 TIM9->CCR2 = (TSLPRM_TIM_RELOAD >> 1) - 1;
\r
340 // Compare output enable, active high
\r
341 TIM9->CCER |= 0x10;
\r
343 //==============================
\r
344 // TIMER 11 configuration: slave
\r
345 //==============================
\r
346 // Set the option register to redirect TIM11_ic_o to TIM11_ti
\r
348 // Set the option register to redirect TIM9_tgo_cktim to TIM11_etri
\r
350 // Set the Prescaler value
\r
352 // Set UP counter, edge-aligned mode
\r
354 // Select Slave mode, Internal Trigger 2 (ITR2 = TIM9), External clock mode 1
\r
355 TIM11->SMCR = 0x4000; // ECE bit
\r
356 // Channel 1 configured in Input capture mode
\r
357 TIM11->CCMR1 = 0x01; // No prescaler, no filter
\r
358 // Channel 1 capture enable (CCE1 = 1)
\r
359 TIM11->CCER = 0x01;
\r
360 // Interrupt Enable, active high
\r
361 TIM11->DIER |= 0x02;
\r
362 // Start slave timer
\r
363 TIM11->CR1 |= 0x01;
\r
368 * @brief Init TS routing interface.
\r
372 void TSL_Init_RI(void)
\r
374 CONST TSL_Bank_T *LocalBank;
\r
375 TSL_tNb_T NumberOfBanks = TSLPRM_TOTAL_BANKS;
\r
376 TSL_tNb_T LocalNumberOfChannels = 0;
\r
377 TSL_tIndex_T idx_bk;
\r
378 TSL_tIndex_T idx_ch;
\r
379 CONST TSL_ChannelSrc_T *p_chSrc; // Pointer to the current channel
\r
381 RCC->APB1ENR |= (uint32_t)((uint32_t)1 << 31); // COMP enable
\r
383 for (idx_bk = 0; idx_bk < NumberOfBanks; idx_bk++)
\r
385 LocalBank = &(TSL_Globals.Bank_Array[idx_bk]);
\r
387 #if (TSLPRM_USE_SHIELD > 0)
\r
388 TSL_CPRI_HYSCR_Config(LocalBank->shield_sample);
\r
389 TSL_CPRI_CICR_Config(LocalBank->shield_sample);
\r
390 TSL_CPRI_CICR_Config_Clear(LocalBank->shield_channel);
\r
392 TSL_CPRI_ASCR_Config(LocalBank->shield_sample);
\r
395 LocalNumberOfChannels = LocalBank->NbChannels;
\r
397 p_chSrc = LocalBank->p_chSrc;
\r
398 for (idx_ch = 0; idx_ch < LocalNumberOfChannels; idx_ch++)
\r
400 TSL_CPRI_HYSCR_Config(p_chSrc->t_sample);
\r
401 TSL_CPRI_CICR_Config(p_chSrc->t_sample);
\r
402 TSL_CPRI_CICR_Config_Clear(p_chSrc->t_channel);
\r
403 TSL_CPRI_ASCR_Config(p_chSrc->t_sample);
\r
408 // Reset TSUSP bit, TIM9 ITR enabled to suspend OC TIM9 generation
\r
409 COMP->CSR &= (uint32_t)(~0x80000000);
\r
415 * @brief Initializes the acquisition module.
\r
419 TSL_Status_enum_T TSL_acq_Init(void)
\r
421 NVIC_InitTypeDef NVIC_InitStructure;
\r
423 NVIC_InitStructure.NVIC_IRQChannel = TIM11_IRQn;
\r
424 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
\r
425 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
\r
426 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
427 NVIC_Init(&NVIC_InitStructure);
\r
433 return TSL_STATUS_OK;
\r
438 * @brief Configures a Bank.
\r
439 * @param[in] idx_bk Index of the Bank to configure
\r
442 TSL_Status_enum_T TSL_acq_BankConfig(TSL_tIndex_T idx_bk)
\r
444 TSL_tIndex_T idx_dest;
\r
445 TSL_tIndex_T idx_ch;
\r
446 CONST TSL_ChannelDest_T *p_chDest; // Pointer to the current channel
\r
447 CONST TSL_ChannelSrc_T *p_chSrc; // Pointer to the current channel
\r
449 // Check parameters (if USE_FULL_ASSERT is defined)
\r
450 assert_param(IS_BANK_INDEX_OK(idx_bk));
\r
452 bank = &(TSL_Globals.Bank_Array[idx_bk]);
\r
454 NumberOfChannels = bank->NbChannels;
\r
456 GroupToCheck = 0;//init group to check
\r
457 NumberOfChannelOn = 0;//init number of channel on
\r
466 p_chDest = bank->p_chDest;
\r
467 p_chSrc = bank->p_chSrc;
\r
468 for (idx_ch = 0; idx_ch < NumberOfChannels; idx_ch++)
\r
470 // Get index in the result array associated to the current channel
\r
471 idx_dest = p_chDest->IdxDest;
\r
472 if (bank->p_chData[idx_dest].Flags.ObjStatus != TSL_OBJ_STATUS_OFF)
\r
474 TSL_CPRI_CMR_Config(p_chSrc->t_sample);
\r
475 TSL_CPRI_ASMR_Config(p_chSrc->t_channel);
\r
476 GroupToCheck |= (1 << (p_chSrc->IdxSrc));
\r
477 NumberOfChannelOn++;
\r
483 return TSL_STATUS_OK;
\r
489 * @brief Start acquisition on a previously configured bank
\r
493 void TSL_acq_BankStartAcq(void)
\r
495 #if (TSLPRM_IODEF > 0)
\r
496 CONST TSL_Bank_T *LocalBank = &(TSL_Globals.Bank_Array[0]);
\r
497 TSL_tNb_T NumberOfBanks = TSLPRM_TOTAL_BANKS;
\r
498 TSL_tNb_T LocalNumberOfChannels = 0;
\r
499 TSL_tIndex_T BankIndex;
\r
501 CONST TSL_ChannelSrc_T *p_chSrc;
\r
502 CONST TSL_ChannelDest_T *p_chDest;
\r
503 TSL_tIndex_T idx_dest;
\r
504 TSL_tIndex_T idx_ch;
\r
506 if (NumberOfChannelOn)
\r
508 #if (TSLPRM_IODEF > 0)
\r
509 //============================
\r
510 // All GPIOs in Input floating
\r
511 //============================
\r
512 for (BankIndex = 0; BankIndex < NumberOfBanks; BankIndex++)
\r
514 LocalBank = &(TSL_Globals.Bank_Array[BankIndex]);
\r
515 p_chSrc = LocalBank->p_chSrc;
\r
517 #if (TSLPRM_USE_SHIELD > 0)
\r
518 TSL_GPIO_MODER_IN_Config(LocalBank->shield_sample);
\r
519 TSL_GPIO_MODER_IN_Config(LocalBank->shield_channel);
\r
522 LocalNumberOfChannels = LocalBank->NbChannels;
\r
525 idx_ch < LocalNumberOfChannels;
\r
528 TSL_GPIO_MODER_IN_Config(p_chSrc->t_sample);
\r
529 TSL_GPIO_MODER_IN_Config(p_chSrc->t_channel);
\r
540 // Discharge sample capacitors
\r
541 p_chDest = bank->p_chDest;
\r
542 p_chSrc = bank->p_chSrc;
\r
543 for (idx_ch = 0; idx_ch < NumberOfChannels; idx_ch++)
\r
545 // Get index in the result array associated to the current channel
\r
546 idx_dest = p_chDest->IdxDest;
\r
547 if (bank->p_chData[idx_dest].Flags.ObjStatus != TSL_OBJ_STATUS_OFF)
\r
549 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_sample);
\r
555 #if (TSLPRM_USE_SHIELD > 0)
\r
556 // Discharge shield sample capacitor
\r
557 TSL_GPIO_MODER_OUT_Config(bank->shield_sample);
\r
560 // Wait for capa discharge
\r
563 #if (TSLPRM_USE_SHIELD > 0)
\r
564 // Init sample shield in floating input
\r
565 TSL_GPIO_MODER_IN_Config(bank->shield_sample);
\r
566 TSL_GPIO_MODER_AF_Config(bank->shield_channel);
\r
568 TSL_CPRI_ASMR_Config(bank->shield_channel);
\r
571 // Init samples in floating input and channels in alternate
\r
572 p_chDest = bank->p_chDest;
\r
573 p_chSrc = bank->p_chSrc;
\r
574 for (idx_ch = 0; idx_ch < NumberOfChannels; idx_ch++)
\r
576 // Get index in the result array associated to the current channel
\r
577 idx_dest = p_chDest->IdxDest;
\r
579 if (bank->p_chData[idx_dest].Flags.ObjStatus != TSL_OBJ_STATUS_OFF)
\r
581 TSL_GPIO_MODER_IN_Config(p_chSrc->t_sample);
\r
582 TSL_GPIO_MODER_AF_Config(p_chSrc->t_channel);
\r
589 /* Start acquisition */
\r
590 TSL_Acq_Status = TSL_STATUS_BUSY;
\r
591 TIM9 ->CR1 |= 0x01; // Master
\r
595 TSL_Acq_Status = TSL_STATUS_OK;
\r
601 * @brief Wait end of acquisition
\r
605 TSL_Status_enum_T TSL_acq_BankWaitEOC(void)
\r
607 return TSL_Acq_Status;
\r
612 * @brief Return the current measure
\r
613 * @param[in] index Index of the measure source
\r
616 TSL_tMeas_T TSL_acq_GetMeas(TSL_tIndex_T index)
\r
618 return(tab_MeasurementCounter[index]);
\r
623 * @brief Check noise (not used)
\r
627 TSL_AcqStatus_enum_T TSL_acq_CheckNoise(void)
\r
629 return TSL_ACQ_STATUS_OK;
\r
634 * @brief Check GPIO IDR for the sample
\r
635 * @param[in] sample
\r
638 uint8_t TSL_Check_GPIO_IDR(uint8_t sample)
\r
640 GPIO_TypeDef *GPIO;
\r
641 uint32_t GPIO_IDR_Mask = 0;
\r
643 GPIO = TSL_GPIO_LookUpTable[TSL_CHANNEL_PORT(sample)];
\r
645 GPIO_IDR_Mask = (1 << (sample & 0x0F));
\r
647 if (((GPIO->IDR) & GPIO_IDR_Mask) == GPIO_IDR_Mask)
\r
659 * @brief Process the TS Interrupt routine
\r
663 void TSL_acq_ProcessIT(void)
\r
665 CONST TSL_Bank_T *LocalBank = &(TSL_Globals.Bank_Array[0]);
\r
666 TSL_tNb_T NumberOfBanks = TSLPRM_TOTAL_BANKS;
\r
667 TSL_tNb_T LocalNumberOfChannels = 0;
\r
668 TSL_tIndex_T BankIndex;
\r
670 CONST TSL_ChannelSrc_T *p_chSrc;
\r
671 CONST TSL_ChannelDest_T *p_chDest;
\r
672 TSL_tIndex_T idx_dest;
\r
673 TSL_tIndex_T idx_ch;
\r
679 p_chDest = bank->p_chDest;
\r
680 p_chSrc = bank->p_chSrc;
\r
683 // Get index in the result array associated to the current channel
\r
684 idx_dest = p_chDest->IdxDest;
\r
686 if (bank->p_chData[idx_dest].Flags.ObjStatus != TSL_OBJ_STATUS_OFF)
\r
688 if ((TSL_Check_GPIO_IDR(p_chSrc->t_sample)) &&
\r
689 ((GroupToCheck & (1 << (p_chSrc->IdxSrc))) == (1 << (p_chSrc->IdxSrc))))
\r
691 tab_MeasurementCounter[p_chSrc->IdxSrc] = TIM11->CCR1;
\r
692 NumberOfChannelChecked++;
\r
693 GroupToCheck &= (uint32_t)(~(1 << (p_chSrc->IdxSrc)));
\r
695 // Reset CMR register to restart the timer
\r
696 TSL_CPRI_CMR_Config_Clear(p_chSrc->t_sample);
\r
703 while (idx_ch < NumberOfChannels);
\r
705 if (NumberOfChannelChecked >= NumberOfChannelOn)
\r
707 NumberOfChannelOn = 0;
\r
708 NumberOfChannelChecked = 0;
\r
710 // Disable master counter
\r
711 TIM9->CR1 &= (uint16_t)(~0x01);
\r
713 //====================
\r
714 // All GPIOs in PP Low
\r
715 //====================
\r
716 for (BankIndex = 0; BankIndex < NumberOfBanks; BankIndex++)
\r
718 LocalBank = &(TSL_Globals.Bank_Array[BankIndex]);
\r
719 p_chSrc = LocalBank->p_chSrc;
\r
721 #if (TSLPRM_USE_SHIELD > 0)
\r
722 TSL_GPIO_BR_Config(LocalBank->shield_sample);
\r
723 TSL_GPIO_BR_Config(LocalBank->shield_channel);
\r
724 TSL_GPIO_MODER_OUT_Config(LocalBank->shield_sample);
\r
725 TSL_GPIO_MODER_OUT_Config(LocalBank->shield_channel);
\r
728 LocalNumberOfChannels = LocalBank->NbChannels;
\r
731 idx_ch < LocalNumberOfChannels;
\r
734 TSL_GPIO_BR_Config(p_chSrc->t_sample);
\r
735 TSL_GPIO_BR_Config(p_chSrc->t_channel);
\r
736 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_sample);
\r
737 TSL_GPIO_MODER_OUT_Config(p_chSrc->t_channel);
\r
742 TSL_Acq_Status = TSL_STATUS_OK;
\r
750 * @brief Check if a filter must be used on the current channel (not used)
\r
751 * @param[in] pCh Pointer on the channel data information
\r
752 * @retval Result TRUE if a filter can be applied
\r
754 TSL_Bool_enum_T TSL_acq_UseFilter(TSL_ChannelData_T *pCh)
\r
761 * @brief Compute the Delta value
\r
762 * @param[in] ref Reference value
\r
763 * @param[in] meas Last Measurement value
\r
764 * @retval Delta value
\r
766 TSL_tDelta_T TSL_acq_ComputeDelta(TSL_tRef_T ref, TSL_tMeas_T meas)
\r
768 return((TSL_tDelta_T)(ref - meas));
\r
773 * @brief Compute the Measurement value
\r
774 * @param[in] ref Reference value
\r
775 * @param[in] delta Delta value
\r
776 * @retval Measurement value
\r
778 TSL_tMeas_T TSL_acq_ComputeMeas(TSL_tRef_T ref, TSL_tDelta_T delta)
\r
780 return((TSL_tMeas_T)(ref - delta));
\r
785 * @brief Test if the Reference is incorrect (not used)
\r
786 * @param[in] pCh Pointer on the channel data information
\r
787 * @retval Result TRUE if the Reference is out of range
\r
789 TSL_Bool_enum_T TSL_acq_TestReferenceOutOfRange(TSL_ChannelData_T *pCh)
\r
796 * @brief Test if the measure has crossed the reference target (not used)
\r
797 * @param[in] pCh Pointer on the channel data information
\r
798 * @param[in] new_meas Measure of the last acquisition on this channel
\r
799 * @retval Result TRUE if the Reference is valid
\r
801 TSL_Bool_enum_T TSL_acq_TestFirstReferenceIsValid(TSL_ChannelData_T *pCh, TSL_tMeas_T new_meas)
\r
807 #if defined(__IAR_SYSTEMS_ICC__) // IAR/EWARM
\r
808 #pragma optimize=medium
\r
809 #elif defined(__CC_ARM) // Keil/MDK-ARM
\r
812 #elif defined(__TASKING__) // Altium/Tasking
\r
813 #pragma optimize O0
\r
814 #elif defined(__GNUC__) // Atollic/True Studio + Raisonance/RKit
\r
815 #pragma GCC push_options
\r
816 #pragma GCC optimize ("O0")
\r
819 * @brief Software delay (private routine)
\r
820 * @param val Wait delay
\r
821 * With fHCLK = 32MHz: 1 = ~1µs, 50 = ~14µs, 100 = ~25µs, 200 = ~50µs
\r
824 void SoftDelay(uint16_t val)
\r
827 for (i = val; i > 0; i--)
\r
830 #if defined(__TASKING__)
\r
831 #pragma endoptimize
\r
834 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r