Exemplo n.º 1
0
/**
  * @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);
    }
  }
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: shjere/common
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  tsl_user_status_t tsl_status;
  
  /* STM32L0xx HAL library initialization:
       - Configure the Flash prefetch, Flash preread and Buffer caches
       - 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 get correspondent USB clock source */
  SystemClock_Config();
  
  /* Configure Key button for remote wakeup */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
   
  /* Init Device Library */
  USBD_Init(&USBD_Device, &HID_Desc, 0);
  
  /* Register the HID class */
  USBD_RegisterClass(&USBD_Device, &USBD_HID);
  
  /* Start Device Process */
  USBD_Start(&USBD_Device);
  
  /* Configure the TSL */
  TSL_Config();

  /* In an infinite loop, send periodically host mouse pointer position (emulated) */  
  while (1)
  {
    /* Execute STMTouch Driver state machine */
    tsl_status = tsl_user_Exec();
    if (tsl_status != TSL_USER_STATUS_BUSY)
    {
      Process_Sensors(tsl_status);
    }
  }
}
Exemplo n.º 3
0
/**
  * @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);
    }
  }
}
Exemplo n.º 4
0
/**
  * @brief  Manages Menu Process.
  * @param  None
  * @retval None
  */
void Menu_Process(void)
{
  tsl_user_status_t tsl_status;
  
  /* background menu: entry menu */
  switch(menu_state)
  {
  case BACKGROUND_MENU:
    BSP_EPD_SetFont(&Font16);
    BSP_EPD_DrawImage(0, 0, 72, 172, Background_pic);
    BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"STM32L053", RIGHT_MODE);
    BSP_EPD_SetFont(&Font12);
    BSP_EPD_DisplayStringAt(87, 8, (uint8_t*)"DISCOVERY", LEFT_MODE);
    BSP_EPD_DisplayStringAt(71, 3, (uint8_t*)"DEMONSTRATION", LEFT_MODE);
    BSP_EPD_DisplayStringAt(94, 0, (uint8_t*)"V1.0.0", LEFT_MODE);
    BSP_EPD_RefreshDisplay();
    HAL_Delay(2000);
    menu_state = MAIN_MENU;
    break;

  /* main menu */
  case MAIN_MENU:
    BSP_EPD_Clear(EPD_COLOR_WHITE);
    BSP_EPD_DrawImage(5, 0, 48, 48, Mouse_pic);
    BSP_EPD_DrawImage(130, 0, 48, 26, Batery_pic);
    BSP_EPD_DrawImage(60, 0, 16, 60, Slider_pic);
    BSP_EPD_SetFont(&Font12);
    BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"STM32L053 Demonstration", CENTER_MODE);
    BSP_EPD_DisplayStringAt(56, 7, (uint8_t*)"USE LTS to", LEFT_MODE);
    BSP_EPD_DisplayStringAt(53, 4, (uint8_t*)"Select Demo", LEFT_MODE);
    BSP_EPD_DrawRect(2, 12, 166, 5);
    BSP_EPD_RefreshDisplay();
    menu_state = MODULE_MENU;
    break;
    
  case MODULE_MENU:
    MyLinRots[0].p_Data->Position = 0;
    /* Execute STMTouch Driver state machine */
    tsl_status = tsl_user_Exec();
    if(tsl_status != TSL_USER_STATUS_BUSY)
    {
      if(LINEAR_DETECT)
      {
        /* USB Module Menu*****************************************************/
        if((LINEAR_POSITION >= 1 ) && (LINEAR_POSITION <= 127))
        {
          menu_state = USB_MENU;
        }  
        /* PWR Module Menu*****************************************************/
        else if ((LINEAR_POSITION >= 128 ) && (LINEAR_POSITION < 255))
        {
          menu_state = PWR_MENU;
        }
      }
    }
    break;

  case USB_MENU:
    BSP_EPD_Clear(EPD_COLOR_WHITE);
    BSP_EPD_DrawImage(13, 4, 28, 146, FullSlider_pic);
    BSP_EPD_SetFont(&Font12);
    BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"STM32L053 USB Demo", CENTER_MODE);
    BSP_EPD_DisplayStringAt(15, 1, (uint8_t*)"LEFT RIGHT UP DOWN", LEFT_MODE);
    BSP_EPD_DrawRect(2, 12, 166, 5);
    BSP_EPD_DrawRect(145, 0, 26, 4);
    BSP_EPD_SetFont(&Font8);
    BSP_EPD_DisplayStringAt(146, 1, (uint8_t*)"B1 Ex", LEFT_MODE);
    BSP_EPD_RefreshDisplay();
    MyLinRots[0].p_Data->Position = 0;

    /* USB Clock config */
    USBClock_Enable();
    /* USB Initialization */
    BSP_USB_Init();
    
    ButtonPressed = 0;
    while(ButtonPressed == 0)
    {
      /* Execute STMTouch Driver state machine */
      tsl_status = tsl_user_Exec();
      if(tsl_status != TSL_USER_STATUS_BUSY)
      {
        USB_process(tsl_status);
      }
    }
    /* USB Clock disable */
    USBClock_Disable();
    /* USB DeInitialize */
    USBD_DeInit(&USBD_Device);

    ButtonPressed = 0;
    menu_state = MAIN_MENU;
    break;

  case PWR_MENU:
    BSP_LED_Off(LED4);
    BSP_LED_Off(LED3);
    /* Power Main IDD Menu ****************************************************/
    BSP_EPD_Clear(EPD_COLOR_WHITE);
    BSP_EPD_DrawImage(30, 0, 16, 60, Slider_pic);
    BSP_EPD_DrawImage(3, 4, 32, 32, Run_pic);
    BSP_EPD_DrawImage(50, 4, 32, 29, Sleep_pic);
    BSP_EPD_DrawImage(90, 4, 32, 29, LPSleep_pic);
    BSP_EPD_DrawImage(130, 4, 32, 32, Stop_pic);
    BSP_EPD_SetFont(&Font12);
    BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"STM32L053 IDD Demo", CENTER_MODE);
    BSP_EPD_DrawRect(2, 12, 166, 5);
    BSP_EPD_DrawRect(113, 0, 57, 3);
    BSP_EPD_SetFont(&Font8);
    BSP_EPD_DisplayStringAt(116, 1, (uint8_t*)"B1 to Exit", LEFT_MODE);
    BSP_EPD_RefreshDisplay();
   
    MyLinRots[0].p_Data->Position = 0;
    MyLinRots[0].p_Data->StateId = TSL_STATEID_RELEASE;
    ButtonPressed = 0;
    tsl_status = tsl_user_Exec();
    while((ButtonPressed == 0) && ((MyLinRots[0].p_Data->StateId != TSL_STATEID_DETECT) || (LINEAR_POSITION == 0)) && (!LINEAR_POSITION))
    {
      tsl_status = tsl_user_Exec();
    }
    
    if(MyLinRots[0].p_Data->StateId  == TSL_STATEID_DETECT)
    {
      /* Run mode menu ********************************************************/
      if((LINEAR_POSITION >= 1 ) && (LINEAR_POSITION <= 64))
      {
        Idd_Run_process();
        BSP_EPD_Clear(EPD_COLOR_WHITE);
        BSP_EPD_SetFont(&Font12);
        BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"MCU in Run Mode", CENTER_MODE);
        BSP_EPD_DrawRect(2, 12, 166, 5);
        BSP_EPD_DisplayStringAt(8, 7, (uint8_t*)"Current consumption", LEFT_MODE);
        BSP_EPD_DisplayStringAt(8, 3, str, LEFT_MODE);
        BSP_EPD_DrawRect(113, 0, 57, 4);
        BSP_EPD_SetFont(&Font8);
        BSP_EPD_DisplayStringAt(116, 1, (uint8_t*)"B1 to Exit", LEFT_MODE);
        BSP_EPD_RefreshDisplay();
      }
      
      /* Sleep mode menu ******************************************************/
      else if ((LINEAR_POSITION >= 65 ) && (LINEAR_POSITION <= 127))
      {
        /* Display before entering Sleep mode */
        BSP_EPD_Clear(EPD_COLOR_WHITE);
        BSP_EPD_SetFont(&Font12);
        BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"MCU in Sleep Mode", CENTER_MODE);
        BSP_EPD_DrawRect(2, 12, 166, 5);
        BSP_EPD_RefreshDisplay();
        
        /* Execute Sleep */
        Idd_Sleep_process();
        
        /* Display after wakeup from Sleep mode */
        BSP_EPD_Clear(EPD_COLOR_WHITE);
        BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"Wake up from Sleep", CENTER_MODE);
        BSP_EPD_DrawRect(2, 12, 166, 5);
        BSP_EPD_DisplayStringAt(8, 7, (uint8_t*)"Current consumption", LEFT_MODE);
        BSP_EPD_DisplayStringAt(8, 3, str, LEFT_MODE);
        BSP_EPD_DrawRect(113, 0, 57, 4);
        BSP_EPD_SetFont(&Font8);
        BSP_EPD_DisplayStringAt(116, 1, (uint8_t*)"B1 to Exit", LEFT_MODE);
        BSP_EPD_RefreshDisplay();
      }
      
      /* LP Sleep menu ********************************************************/
      else if ((LINEAR_POSITION >= 128 ) && (LINEAR_POSITION <= 191))
      {
        /* Display before entering LP Sleep mode */
        BSP_EPD_Clear(EPD_COLOR_WHITE);
        BSP_EPD_SetFont(&Font12);
        BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"MCU in LPSleep Mode", CENTER_MODE);
        BSP_EPD_DrawRect(2, 12, 166, 5);
        BSP_EPD_RefreshDisplay();
         
        /* Execute LP SLEEP */
        Idd_LPSleep_process();
        
        /* Display after wakeup from LP Sleep mode */
        BSP_EPD_Clear(EPD_COLOR_WHITE);
        BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"Wake up from LPSleep", CENTER_MODE);
        BSP_EPD_DrawRect(2, 12, 166, 5);
        BSP_EPD_DisplayStringAt(8, 7, (uint8_t*)"Current consumption", LEFT_MODE);
        BSP_EPD_DisplayStringAt(8, 3, str, LEFT_MODE);
        BSP_EPD_DrawRect(113, 0, 57, 4);
        BSP_EPD_SetFont(&Font8);
        BSP_EPD_DisplayStringAt(116, 1, (uint8_t*)"B1 to Exit", LEFT_MODE);
        BSP_EPD_RefreshDisplay();
      }
      /* Stop menu ************************************************************/
      else
      {
        /* Display before entering Stop mode */
        BSP_EPD_Clear(EPD_COLOR_WHITE);
        BSP_EPD_SetFont(&Font12);
        BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"MCU in Stop Mode", CENTER_MODE);
        BSP_EPD_DrawRect(2, 12, 166, 5);
        BSP_EPD_RefreshDisplay();
        
        /* Execute STOP Process */
        Idd_Stop_process();
        
        /* Display after wakeup from Stop mode */
        BSP_EPD_Clear(EPD_COLOR_WHITE);
        BSP_EPD_DisplayStringAt(0, 13, (uint8_t*)"Wake up from STOP", CENTER_MODE);
        BSP_EPD_DrawRect(2, 12, 166, 5);
        BSP_EPD_DisplayStringAt(8, 7, (uint8_t*)"Current consumption", LEFT_MODE);
        BSP_EPD_DisplayStringAt(8, 3, str, LEFT_MODE);
        BSP_EPD_DrawRect(113, 0, 57, 4);
        BSP_EPD_SetFont(&Font8);
        BSP_EPD_DisplayStringAt(116, 1, (uint8_t*)"B1 to Exit", LEFT_MODE);
        BSP_EPD_RefreshDisplay();
      }
      
      ButtonPressed = 0;
      while(ButtonPressed == 0)
      {
      }
      menu_state = PWR_MENU;
    }
    else /* BUTTON_KEY != 0 */
    {
      menu_state = MAIN_MENU;
    }

    break;
    
  default:
    break;
  }
}