/** * @brief Configures the TSC peripheral. * @param None * @retval None */ static void TSL_Config(void) { /* Configure the TSC peripheral */ TscHandle.Instance = TSC; TscHandle.Init.AcquisitionMode = TSC_ACQ_MODE_NORMAL; TscHandle.Init.CTPulseHighLength = TSC_CTPH_2CYCLES; TscHandle.Init.CTPulseLowLength = TSC_CTPL_2CYCLES; TscHandle.Init.IODefaultMode = TSC_IODEF_OUT_PP_LOW; TscHandle.Init.MaxCountInterrupt = DISABLE; TscHandle.Init.MaxCountValue = TSC_MCV_8191; TscHandle.Init.PulseGeneratorPrescaler = TSC_PG_PRESC_DIV2; TscHandle.Init.SpreadSpectrum = DISABLE; TscHandle.Init.SpreadSpectrumDeviation = 127; TscHandle.Init.SpreadSpectrumPrescaler = TSC_SS_PRESC_DIV1; TscHandle.Init.SynchroPinPolarity = TSC_SYNC_POL_FALL; /* All channel, shield and sampling IOs must be declared below */ TscHandle.Init.ChannelIOs = TSC_GROUP1_IO3 | TSC_GROUP2_IO3 | TSC_GROUP3_IO2; TscHandle.Init.SamplingIOs = TSC_GROUP1_IO4 | TSC_GROUP2_IO4 | TSC_GROUP3_IO3; TscHandle.Init.ShieldIOs = 0; HAL_TSC_Init(&TscHandle); /* Initialize the STMTouch driver */ tsl_user_Init(); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { tsl_user_status_t tsl_status; /* STM32F0xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /* Configure LEDs */ BSP_LED_Init(LED4); BSP_LED_Init(LED5); BSP_LED_Init(LED3); /* Configure the TSC peripheral */ TscHandle.Instance = TSCx; TscHandle.Init.AcquisitionMode = TSC_ACQ_MODE_NORMAL; TscHandle.Init.CTPulseHighLength = TSC_CTPH_2CYCLES; TscHandle.Init.CTPulseLowLength = TSC_CTPL_2CYCLES; TscHandle.Init.IODefaultMode = TSC_IODEF_OUT_PP_LOW; TscHandle.Init.MaxCountInterrupt = DISABLE; TscHandle.Init.MaxCountValue = TSC_MCV_8191; TscHandle.Init.PulseGeneratorPrescaler = TSC_PG_PRESC_DIV64; TscHandle.Init.SpreadSpectrum = DISABLE; TscHandle.Init.SpreadSpectrumDeviation = 127; TscHandle.Init.SpreadSpectrumPrescaler = TSC_SS_PRESC_DIV1; TscHandle.Init.SynchroPinPolarity = TSC_SYNC_POLARITY_FALLING; /* All channel, shield and sampling IOs must be declared below */ TscHandle.Init.ChannelIOs = (TSC_GROUP1_IO3 | TSC_GROUP2_IO3 | TSC_GROUP3_IO2); TscHandle.Init.SamplingIOs = (TSC_GROUP1_IO4 | TSC_GROUP2_IO4 | TSC_GROUP3_IO3); TscHandle.Init.ShieldIOs = 0; if (HAL_TSC_Init(&TscHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Initialize the STMTouch driver */ tsl_user_Init(); /* Infinite loop */ while (1) { /* Execute STMTouch Driver state machine */ tsl_status = tsl_user_Exec(); if (tsl_status != TSL_USER_STATUS_BUSY) { Process_Sensors(tsl_status); } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization */ HAL_Init(); tsl_user_status_t tsl_status; /* Initialize the STMTouch driver */ tsl_user_Init(); __GPIOB_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7; GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; GPIO_InitStructure.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); /* Thread 1 definition */ osThreadDef(LED1, LED_Thread1, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); /* Thread 2 definition */ osThreadDef(LED2, LED_Thread2, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); /* Start thread 1 */ LEDThread1Handle = osThreadCreate(osThread(LED1), NULL); /* Start thread 2 */ LEDThread2Handle = osThreadCreate(osThread(LED2), NULL); /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ for (;;) ; }
/** * @brief Main program. * @param None * @retval None */ int main(void) { tsl_user_status_t tsl_status; /* STM32F0xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure LEDs */ BSP_LED_Init(LED2); BSP_LED_Init(LED1); BSP_LED_Init(LED4); BSP_LED_Init(LED3); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /* Configure the TSC peripheral */ TscHandle.Instance = TSCx; TscHandle.Init.AcquisitionMode = TSC_ACQ_MODE_NORMAL; TscHandle.Init.CTPulseHighLength = TSC_CTPH_2CYCLES; TscHandle.Init.CTPulseLowLength = TSC_CTPL_2CYCLES; TscHandle.Init.IODefaultMode = TSC_IODEF_OUT_PP_LOW; TscHandle.Init.MaxCountInterrupt = DISABLE; TscHandle.Init.MaxCountValue = TSC_MCV_8191; TscHandle.Init.PulseGeneratorPrescaler = TSC_PG_PRESC_DIV64; TscHandle.Init.SpreadSpectrum = DISABLE; TscHandle.Init.SpreadSpectrumDeviation = 127; TscHandle.Init.SpreadSpectrumPrescaler = TSC_SS_PRESC_DIV1; TscHandle.Init.SynchroPinPolarity = TSC_SYNC_POLARITY_FALLING; /* All channel, shield and sampling IOs must be declared below */ TscHandle.Init.ChannelIOs = (TSC_GROUP8_IO2 | TSC_GROUP8_IO1); TscHandle.Init.SamplingIOs = (TSC_GROUP8_IO3 | TSC_GROUP8_IO3 | TSC_GROUP6_IO1); TscHandle.Init.ShieldIOs = TSC_GROUP6_IO2; if (HAL_TSC_Init(&TscHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Just to indicate the fw is alive... */ BSP_LED_On(LED2); BSP_LED_On(LED1); BSP_LED_On(LED4); BSP_LED_On(LED3); /* Configure LCD */ #if USE_LCD > 0 BSP_LCD_Init(); BSP_LCD_SetFont(&LCD_DEFAULT_FONT); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); BSP_LCD_DisplayStringAt(0, 10, (uint8_t *)"STM32F091xx", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 35, (uint8_t *)"TouchSensing", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 55, (uint8_t *)"Example", CENTER_MODE); #endif BSP_LED_Off(LED2); BSP_LED_Off(LED1); BSP_LED_Off(LED4); BSP_LED_Off(LED3); /* Initialize the STMTouch driver */ tsl_user_Init(); /* Infinite loop */ while (1) { /* Execute STMTouch Driver state machine */ tsl_status = tsl_user_Exec(); if (tsl_status != TSL_USER_STATUS_BUSY) { Process_Sensors(tsl_status); } } }