/** * @brief Execute STMTouch Driver main State machine * @param None * @retval status Return TSL_STATUS_OK if the acquisition is done */ TSL_Status_enum_T TSL_user_Action(void) { TSL_Status_enum_T status; /* Configure bank */ if (!config_done) { TSL_acq_BankConfig(idx_bank); /* Configure Bank */ TSL_acq_BankStartAcq(); /* Start Bank acquisition */ config_done = 1; #if TSLPRM_USE_ACQ_INTERRUPT > 0 Gv_EOA = 0; /* Will be set by the TS interrupt routine */ #endif } /* Check end of acquisition */ #if TSLPRM_USE_ACQ_INTERRUPT > 0 if (Gv_EOA) /* Set by the TS interrupt routine */ #else if (TSL_acq_BankWaitEOC() == TSL_STATUS_OK) #endif { TSL_acq_BankGetResult(idx_bank, 0, 0); /* Get Bank Result */ idx_bank++; /* Next bank */ config_done = 0; } /* Process objects, DxS and ECS Check if all banks have been acquired */ if (idx_bank > TSLPRM_TOTAL_BANKS-1) { /* Reset flags for next banks acquisition */ idx_bank = 0; config_done = 0; /* Process Objects */ TSL_obj_GroupProcess(&MyObjGroup); /* DxS processing (if TSLPRM_USE_DXS option is set) */ /*TSL_dxs_FirstObj(&MyObjGroup);*/ /* ECS every 100ms */ if (TSL_tim_CheckDelay_ms(100, &Gv_ECS_last_tick) == TSL_STATUS_OK) { TSL_ecs_Process(&MyObjGroup); } status = TSL_STATUS_OK; /* All banks have been acquired and sensors processed */ } else { status = TSL_STATUS_BUSY; } return status; }
/** * @brief Initialize the STMTouch Driver * @param None * @retval None */ void tsl_user_Init(void) { TSL_obj_GroupInit(&MyObjGroup); /* Init Objects */ TSL_Init(MyBanks); /* Init acquisition module */ tsl_user_SetThresholds(); /* Init thresholds for each object individually (optional) */ /* Configure first bank and start acquisition in Interrupt mode */ idx_bank = 0; TSL_acq_BankConfig(idx_bank); TSL_acq_BankStartAcq_IT(); }
/** * @brief Acquisition completed callback in non blocking mode * @param htsc: pointer to a TSC_HandleTypeDef structure that contains * the configuration information for the specified TSC. * @retval None */ void HAL_TSC_ConvCpltCallback(TSC_HandleTypeDef* htsc) { static __IO TSL_tTick_ms_T ECSLastTick; /* Hold the last time value for ECS */ /* Discharge all capacitors */ #if TSLPRM_IODEF > 0 __HAL_TSC_SET_IODEF_OUTPPLOW(&TscHandle); #endif TSL_acq_BankGetResult(idx_bank++, 0, 0); /* Read current bank result */ /* Check if we have acquired all the banks */ if (idx_bank > TSLPRM_TOTAL_BANKS - 1) { /* Process the objects state machine, DxS and ECS */ TSL_obj_GroupProcess(&MyObjGroup); TSL_dxs_FirstObj(&MyObjGroup); if (TSL_tim_CheckDelay_ms(100, &ECSLastTick) == TSL_STATUS_OK) { if(TSL_ecs_Process(&MyObjGroup) == TSL_STATUS_OK) { BSP_LED_Toggle(LED6); } else { BSP_LED_Off(LED6); } } /* Start again with the first bank */ idx_bank = 0; } /* Configure bank */ TSL_acq_BankConfig(idx_bank); /* Start bank acquisition in Interrupt mode */ TSL_acq_BankStartAcq_IT(); }
/** * @brief Execute STMTouch Driver main State machine * @param None * @retval status Return TSL_STATUS_OK if the acquisition is done */ tsl_user_status_t tsl_user_Exec(void) { static uint32_t idx_bank = 0; static uint32_t config_done = 0; tsl_user_status_t status = TSL_USER_STATUS_BUSY; /* Configure and start bank acquisition */ if (!config_done) { TSL_acq_BankConfig(idx_bank); TSL_acq_BankStartAcq(); config_done = 1; } /* Check end of acquisition (polling mode) and read result */ if (TSL_acq_BankWaitEOC() == TSL_STATUS_OK) { STMSTUDIO_LOCK; TSL_acq_BankGetResult(idx_bank, 0, 0); STMSTUDIO_UNLOCK; idx_bank++; /* Next bank */ config_done = 0; } /* Process objects, DxS and ECS Check if all banks have been acquired */ if (idx_bank > TSLPRM_TOTAL_BANKS-1) { /* Reset flags for next banks acquisition */ idx_bank = 0; config_done = 0; /* Process Objects */ TSL_obj_GroupProcess(&MyObjGroup); /* DxS processing (if TSLPRM_USE_DXS option is set) */ TSL_dxs_FirstObj(&MyObjGroup); /* ECS every 100ms */ if (TSL_tim_CheckDelay_ms(100, &ECSLastTick) == TSL_STATUS_OK) { if (TSL_ecs_Process(&MyObjGroup) == TSL_STATUS_OK) { status = TSL_USER_STATUS_OK_ECS_ON; } else { status = TSL_USER_STATUS_OK_ECS_OFF; } } else { status = TSL_USER_STATUS_OK_NO_ECS; } } else { status = TSL_USER_STATUS_BUSY; } return status; }
/** * @brief Calibrate a Bank * @param[in] idx_bk Index of the Bank to access * @retval Status */ TSL_Status_enum_T TSL_acq_BankCalibrate(TSL_tIndex_T idx_bk) { TSL_Status_enum_T retval; TSL_Status_enum_T acq_status; TSL_tIndex_T idx_ch; TSL_tIndexDest_T idx_dest; TSL_tMeas_T new_meas; static TSL_tIndex_T calibration_ongoing = 0; static TSL_tNb_T calibration_done = 0; static TSL_tNb_T div; CONST TSL_Bank_T *bank; CONST TSL_ChannelDest_T *pchDest; // Pointer to the current channel CONST TSL_ChannelSrc_T *pchSrc; // Pointer to the current channel if (idx_bk >= TSLPRM_TOTAL_BANKS) { return TSL_STATUS_ERROR; } bank = &(TSL_Globals.Bank_Array[idx_bk]); if (calibration_ongoing == 0) { switch (TSL_Params.NbCalibSamples) { case 4: div = 2; break; case 16: div = 4; break; default: TSL_Params.NbCalibSamples = 8; div = 3; break; } // Clear data for all channels of the bank TSL_acq_BankClearData(idx_bk); // Configure bank if (TSL_acq_BankConfig(idx_bk) == TSL_STATUS_OK) { // Start acquisition TSL_acq_BankStartAcq(); calibration_ongoing = 1; // Calibration started calibration_done = TSL_Params.NbCalibSamples; retval = TSL_STATUS_BUSY; } else { // Stop calibration // Clear data for all channels of the bank TSL_acq_BankClearData(idx_bk); calibration_ongoing = 0; retval = TSL_STATUS_ERROR; } } else // Calibration is on-going { // Check End of Acquisition acq_status = TSL_acq_BankWaitEOC(); if (acq_status == TSL_STATUS_OK) { // Get the first channel of the bank pchDest = bank->p_chDest; pchSrc = bank->p_chSrc; // Get new measurement for all channels of the bank for (idx_ch = 0; idx_ch < bank->NbChannels; idx_ch++) { // Get index of the current channel idx_dest = pchDest->IdxDest; // Get the new measure (the access is different between acquisitions) new_meas = TSL_acq_GetMeas(pchSrc->IdxSrc); // Check min/max and set status flag if ((new_meas < TSL_Params.AcqMin) || (new_meas > TSL_Params.AcqMax)) { // Stop calibration // Clear data for all channels of the bank TSL_acq_BankClearData(idx_bk); calibration_ongoing = 0; return TSL_STATUS_ERROR; } else { // Add the measure bank->p_chData[idx_dest].Ref += new_meas; } // Next channel pchDest++; pchSrc++; } // Check that we have all the needed measurements calibration_done--; if (calibration_done == 0) { // Get the first channel of the bank pchDest = bank->p_chDest; // Calculate the Reference for all channels of the bank for (idx_ch = 0; idx_ch < bank->NbChannels; idx_ch++) { // Get index of the current channel idx_dest = pchDest->IdxDest; // Divide the Reference by the number of samples bank->p_chData[idx_dest].Ref >>= div; // Next channel pchDest++; } // End calibration_ongoing = 0; retval = TSL_STATUS_OK; } else // Restart a new measurement on the bank {
/** * @brief Execute STMTouch Driver main State machine * @param None * @retval status Return TSL_STATUS_OK if the acquisition is done */ TSL_Status_enum_T TSL_user_Action(void) { static uint8_t idx_bank=0; static uint8_t ConfigDone=0; TSL_Status_enum_T status; if(!ConfigDone) { // Configure Bank TSL_acq_BankConfig(idx_bank); // Start Bank acquisition TSL_acq_BankStartAcq(); // Set flag ConfigDone=1; } // Check Bank End of Acquisition if (TSL_acq_BankWaitEOC() == TSL_STATUS_OK) { // Get Bank Result TSL_acq_BankGetResult(idx_bank, 0, 0); ConfigDone=0; idx_bank++; } if(idx_bank == TSLPRM_TOTAL_BANKS) { idx_bank=0; // Process Objects TSL_obj_GroupProcess(&MyObjGroup); // DxS processing // Warning: TSLPRM_USE_DXS must be set !!! TSL_dxs_FirstObj(&MyObjGroup); // ECS every 100ms if (TSL_tim_CheckDelay_ms(100, &ECS_last_tick) == TSL_STATUS_OK) { LED_BLUE_TOGGLE; if (TSL_ecs_Process(&MyObjGroup) == TSL_STATUS_OK) { LED_GREEN_ON; process_sensor = 0; } else { LED_GREEN_OFF; process_sensor = 1; } } status = TSL_STATUS_OK; // All banks have been acquired and sensors processed } else { status = TSL_STATUS_BUSY; } return status; }