Пример #1
0
/**
  * @brief  Initializes the STM32756G-EVAL's LCD and LEDs resources.
  * @param  None
  * @retval None
  */
static void BSP_Config(void)
{
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /* Initialize the Touch screen */
#ifdef USE_MB1046
  BSP_TS_Init(480, 272);
#elif defined(USE_MB1063)
  BSP_TS_Init(640, 480);
#endif
}
Пример #2
0
/**
  * @brief  Initializes LEDs, SDRAM, touch screen, CRC and SRAM.
  * @param  None
  * @retval None
  */
void k_BspInit(void)
{

  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable CS GPIO clock and  Configure GPIO PIN for Gyroscope Chip select */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  GPIO_InitStructure.Pin = GPIO_PIN_1;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull  = GPIO_NOPULL;
  GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* Deselect : Chip Select high */
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET);

  /* Configure LED3 and LED4 */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* Initialize the SDRAM */
  BSP_SDRAM_Init();

  /* Initialize the Touch screen */
  BSP_TS_Init(240, 320);

  /* Enable CRC to Unlock GUI */
  __HAL_RCC_CRC_CLK_ENABLE();

  /* Enable Back up SRAM */
  __HAL_RCC_BKPSRAM_CLK_ENABLE();

}
Пример #3
0
/**
  * @brief  Initializes LEDs, touch screen, CRC and SRAM.
  * @param  None
  * @retval None
  */
void k_BspInit(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* Initialize the SRAM */
  BSP_SRAM_Init();

  /* Initialize the Touch screen */
  BSP_TS_Init(320, 240);

  /* Enable CRC to Unlock GUI */
  __HAL_RCC_CRC_CLK_ENABLE();

  /* Enable Back up SRAM */
  __HAL_RCC_BKPSRAM_CLK_ENABLE();


  /* reconfigure FSMC NE3 pin */
  GPIO_InitStructure.Mode      = GPIO_MODE_AF_PP;
  GPIO_InitStructure.Pull      = GPIO_PULLUP;
  GPIO_InitStructure.Speed     = GPIO_SPEED_HIGH;
  GPIO_InitStructure.Alternate = GPIO_AF12_FSMC;
  GPIO_InitStructure.Pin   = GPIO_PIN_10;

  HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
}
Пример #4
0
/**
  * @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();
  
  /* Configure the system clock to 168 MHz */
  SystemClock_Config(); 
    
  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /*##-1- LCD Initialization #################################################*/ 
  /* Initialize the LCD */
  BSP_LCD_Init();
 
  /* Enable the LCD */
  BSP_LCD_DisplayOn();

  /* Clear the LCD Background layer */
  BSP_LCD_Clear(LCD_COLOR_WHITE);

  /*##-2- Touch screen initialization ########################################*/
  Touchscreen_Calibration();
  BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
 
  /*##-3- Link the SD Card disk I/O driver ###################################*/
  if(FATFS_LinkDriver(&SD_Driver, SDPath) != 0) 
  {
    /* FatFs Initialization Error */
    Error_Handler();
  }
  
  /* Create a FAT file system (format) on the logical drive */
  f_mkfs((TCHAR const*)SDPath, 0, 0);
  
  /*##-4- Register the file system object to the FatFs module ################*/
  if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
  {
    /* FatFs Initialization Error */
    Error_Handler();
  }  
  
  /*##-5- Draw the menu ######################################################*/
  Draw_Menu();  

  /* Infinite loop */  
  while (1)
  { 
  /*##-6- Configure the touch screen and Get the position ####################*/    
    GetPosition();
  }
}
Пример #5
0
/**
  * @brief  Initializes the STM324xG-EVAL's LCD and LEDs resources.
  * @param  None
  * @retval None
  */
static void BSP_Config(void)
{
  /* Initialize STM324xG-EVAL's LEDs */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /* Initialize the Touch screen */
  BSP_TS_Init(240, 320);
 
  /* Enable the CRC Module */
  __CRC_CLK_ENABLE();
}
Пример #6
0
/**
  * @brief  Initializes LEDs, touch screen, CRC and SRAM.
  * @param  None 
  * @retval None
  */
void k_BspInit(void)
{
  /* Configure LED1 and LED3 */
   BSP_LED_Init(LED1);
   BSP_LED_Init(LED3);
  
  BSP_SDRAM_Init();
  
  /* Initialize the Touch screen */
  BSP_TS_Init(320, 240);
  
  /* Enable CRC to Unlock GUI */
  __HAL_RCC_CRC_CLK_ENABLE();
}
Пример #7
0
/**
  * @brief  Initializes the STM324xG-EVAL's LCD and LEDs resources.
  * @param  None
  * @retval None
  */
static void BSP_Config(void)
{
    /* Configure LED1, LED2, LED3 and LED4 */
    BSP_LED_Init(LED1);
    BSP_LED_Init(LED2);
    BSP_LED_Init(LED3);
    BSP_LED_Init(LED4);

    /* Initialize the Touch screen */
    BSP_TS_Init(240, 320);

    /* Enable the CRC Module */
    __HAL_RCC_CRC_CLK_ENABLE();
}
Пример #8
0
/**
  * @brief  Initializes the STM32F429I-DISCO's LCD and LEDs resources.
  * @param  None
  * @retval None
  */
static void BSP_Config(void)
{
  /* Initialize STM32F429I-DISCO's LEDs */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /* Initializes the SDRAM device */
  BSP_SDRAM_Init();
  
  /* Initialize the Touch screen */
  BSP_TS_Init(240, 320);
  
  /* Enable the CRC Module */
  __CRC_CLK_ENABLE();
}
Пример #9
0
/**
  * @brief  Performs the TS calibration
  * @param  None
  * @retval None
  */
void Touchscreen_Calibration (void)
{ 
  uint8_t status = 0;
  uint8_t i = 0;

  TouchscreenCalibration_SetHint();
  
  status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
  
  if (status != TS_OK)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE); 
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 95, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 80, (uint8_t *)"Touchscreen cannot be initialized", CENTER_MODE);
  }
  
  while (1)
  {
    if (status == TS_OK)
    {
      aLogX[0] = 15;
      aLogY[0] = 15;
      aLogX[1] = BSP_LCD_GetXSize() - 15;
      aLogY[1] = BSP_LCD_GetYSize() - 15;
      
      for (i = 0; i < 2; i++) 
      {
        GetPhysValues(aLogX[i], aLogY[i], &aPhysX[i], &aPhysY[i]);
      }
      A1 = (TUNE_FACTOR_X * ( aLogX[1] - aLogX[0]))/ ( aPhysX[1] - aPhysX[0]); 
      B1 = (TUNE_FACTOR_X * aLogX[0]) - A1 * aPhysX[0]; 
      
      A2 = (TUNE_FACTOR_Y * ( aLogY[1] - aLogY[0]))/ ( aPhysY[1] - aPhysY[0]); 
      B2 = (TUNE_FACTOR_Y * aLogY[0]) - A2 * aPhysY[0]; 
      if (B2 > 0)
        B2 = 0;
      
      Calibration_Done = 1;
      return;
    }
   
    HAL_Delay(5);
  }
}
Пример #10
0
/**
  * @brief  Initializes LEDs, SDRAM, touch screen, CRC and SRAM.
  * @param  None
  * @retval None
  */
void k_BspInit(void)
{
  /* Initialize the NOR */
//  BSP_QSPI_Init();
//  BSP_QSPI_MemoryMappedMode();

  /* Initialize the SDRAM */
//  BSP_SDRAM_Init();

  /* Initialize the Touch screen */
  BSP_TS_Init(420, 272);

  /* Enable CRC to Unlock GUI */
 __HAL_RCC_CRC_CLK_ENABLE();

 /* Enable Back up SRAM */
__HAL_RCC_BKPSRAM_CLK_ENABLE();

}
Пример #11
0
/**
  * @brief  Initializes LEDs, SDRAM, touch screen, CRC and SRAM.
  * @param  None
  * @retval None
  */
void k_BspInit(void)
{
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* Initialize the SDRAM */
  BSP_SDRAM_Init();

  /* Initialize the Touch screen */
  BSP_TS_Init(640, 480);

  /* Enable CRC to Unlock GUI */
  __HAL_RCC_CRC_CLK_ENABLE();

  /* Enable Back up SRAM */
  __HAL_RCC_BKPSRAM_CLK_ENABLE();

}
Пример #12
0
/**
  * @brief  Initializes LEDs, SDRAM, touch screen, CRC and SRAM.
  * @param  None 
  * @retval None
  */
void k_BspInit(void)
{
  
  BSP_IO_Init();
  
  /* Initialize the NOR */
  BSP_NOR_Init();
  
  /* Initialize the SDRAM */
  BSP_SDRAM_Init();  
  
  /* Initialize the Touch screen */
  BSP_TS_Init(640, 480);
  
  /* Enable CRC to Unlock GUI */
 __HAL_RCC_CRC_CLK_ENABLE();
  
 /* Enable Back up SRAM */
__HAL_RCC_BKPSRAM_CLK_ENABLE();
  
}
Пример #13
0
/**
  * @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();

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  /* Configure LED3 and LED4 */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /*##-1- LCD Initialization #################################################*/
  /* Initialize the LCD */
  BSP_LCD_Init();

  /* Layer2 Init */
  BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER_LAYER1);
  /* Set Foreground Layer */
  BSP_LCD_SelectLayer(1);
  /* Clear the LCD */
  BSP_LCD_Clear(LCD_COLOR_WHITE);
  BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE);
  BSP_LCD_SetLayerVisible(1, DISABLE);

  /* Layer1 Init */
  BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER_LAYER0);

  /* Set Foreground Layer */
  BSP_LCD_SelectLayer(0);

  /* Enable The LCD */
  BSP_LCD_DisplayOn();

  /* Clear the LCD */
  BSP_LCD_Clear(LCD_COLOR_WHITE);

  /*##-2- Touch screen initialization ########################################*/
  Touchscreen_Calibration();
  BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());

  /*##-3- USB Initialization #################################################*/
  /* Init Host Library */
  if (USBH_Init(&hUSB_Host, USBH_UserProcess, 0) != USBH_OK)
  {
    /* USB Initialization Error */
    Error_Handler();
  }

  /* Add Supported Class */
  USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS);

  /* Start Host Process */
  if (USBH_Start(&hUSB_Host) != USBH_OK)
  {
    /* USB Initialization Error */
    Error_Handler();
  }

  /*##-4- Link the USB Mass Storage disk I/O driver ##########################*/
  if(FATFS_LinkDriver(&USBH_Driver, USB_Path) != 0)
  {
    /* FatFs Initialization Error */
    Error_Handler();
  }

  /*##-5- Register the file system object to the FatFs module ################*/
  if(f_mount(&USBDISK_FatFs, (TCHAR const*)USB_Path, 0) != FR_OK)
  {
    /* FatFs Initialization Error */
    Error_Handler();
  }

  /*##-6- Draw the menu ######################################################*/
  Draw_Menu();

  /* Infinite loop */
  while (1)
  {
  /*##-7- Configure the touch screen and Get the position ####################*/
    GetPosition();

    USBH_Process(&hUSB_Host);
  }
}
Пример #14
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint8_t  lcd_status = LCD_OK;

  /* STM32F4xx HAL library initialization:
    - Configure the Flash prefetch, instruction and Data 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.
    - Set NVIC Group Priority to 4
    - Low Level Initialization: global MSP (MCU Support Package) initialization
  */
  HAL_Init();

  /* Configure the system clock to 180 MHz */
  SystemClock_Config();

  BSP_IO_Init();

  /* Initialise QSPI */
  BSP_QSPI_Init();
  BSP_QSPI_MemoryMappedMode();

  /* Initialize the SDRAM */
  BSP_SDRAM_Init();

  /* Initialize the LCD */
  lcd_status = LCD_Init();
  OnError_Handler(lcd_status != LCD_OK);

  /* Initialize LTDC layer 0 iused for Hint */
  LCD_LayertInit(0, LAYER0_ADDRESS);
  BSP_LCD_SelectLayer(0);

  /* Configure the User Button in GPIO Mode */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_EXTI);

   /* Initialize the Touch Screen */
  BSP_TS_Init(800, 480);

  /* Set active display window */
  HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 4, OTM8009A_CMD_CASET, pColLeft);
  HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 4, OTM8009A_CMD_PASET, pPage);

  /* Update pitch : the draw is done on the whole physical X Size */
  HAL_LTDC_SetPitch(&hltdc_eval, BSP_LCD_GetXSize(), 0);


  /* Show first image */
  LL_CopyPicture((uint32_t *)image[ImageIndex], (uint32_t *)LAYER0_ADDRESS);

  valid_buffer = 1;
  active_area = LEFT_AREA;

  HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 2, OTM8009A_CMD_WRTESCN, pSyncLeft);

  /* Infinite loop */
  while (1)
  {
    BSP_TS_GetState(&TS_State);
    if(draw_method == HORIZONTAL_SLIDER)
    {
    LCD_DSI_HorizontalSlider();
    }
    else
    {
     LCD_DSI_VerticalSlider();
    }
  }
}
Пример #15
0
/**
  * @brief  Audio Play demo
  * @param  None
  * @retval None
  */
void AudioPlay_demo (void)
{
  uint32_t *AudioFreq_ptr;
  uint8_t FreqStr[256] = {0};
  TS_StateTypeDef  TS_State;

  AudioFreq_ptr = AudioFreq+6; /*AF_48K*/
  uwPauseEnabledStatus = 1; /* 0 when audio is running, 1 when Pause is on */
  uwVolume = 70;

  Audio_SetHint();

  if (BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, uwVolume, *AudioFreq_ptr) == 0)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 95, (uint8_t *)"  AUDIO CODEC   OK  ", CENTER_MODE);
  }
  else
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 95, (uint8_t *)"  AUDIO CODEC  FAIL ", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 80, (uint8_t *)" Try to reset board ", CENTER_MODE);
  }

  if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) != TS_OK)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 50, (uint8_t *)"Touchscreen cannot be initialized", CENTER_MODE);
  }

  /* 
  Start playing the file from a circular buffer, once the DMA is enabled, it is 
  always in running state. Application has to fill the buffer with the audio data 
  using Transfer complete and/or half transfer complete interrupts callbacks 
  (DISCOVERY_AUDIO_TransferComplete_CallBack() or DISCOVERY_AUDIO_HalfTransfer_CallBack()...
  */
  AUDIO_Start(AUDIO_FILE_ADDRESS, AUDIO_FILE_SIZE);

  /* Display the state on the screen */
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 80, (uint8_t *)"       PLAYING...     ", CENTER_MODE);

  sprintf((char*)FreqStr, "       VOL:    %3lu     ", uwVolume);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)FreqStr, CENTER_MODE);

  sprintf((char*)FreqStr, "      FREQ: %6lu     ", *AudioFreq_ptr);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 50, (uint8_t *)FreqStr, CENTER_MODE);

  BSP_AUDIO_OUT_SetVolume(70);

  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  BSP_LCD_SetTextColor(LCD_COLOR_BLUE);

  /* Infinite loop */
  while (1)
  {
    /* Check in polling mode in touch screen the touch status and coordinates */
    /* if touch occurred                                                      */
    BSP_TS_GetState(&TS_State);
    if(TS_State.touchDetected == 1)
    {
      if (TS_State.touchY[0] < 30)
      {
        /* Increase volume by 5% */
        if (uwVolume < 95)
          uwVolume += 5;
        else
          uwVolume = 100;
        sprintf((char*)FreqStr, "       VOL:    %3lu     ", uwVolume);
        BSP_AUDIO_OUT_SetVolume(uwVolume);
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)FreqStr, CENTER_MODE);
      }
      else if (TS_State.touchY[0] > (BSP_LCD_GetYSize() - 30))
      {
        /* Decrease volume by 5% */
        if (uwVolume > 5)
          uwVolume -= 5;
        else
          uwVolume = 0;
        sprintf((char*)FreqStr, "       VOL:    %3lu     ", uwVolume);
        BSP_AUDIO_OUT_SetVolume(uwVolume);
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)FreqStr, CENTER_MODE);
      }
      else if (TS_State.touchX[0] < 30)
      {
        /*Decrease Frequency */
        if (*AudioFreq_ptr != 8000)
        {
          AudioFreq_ptr--;
          sprintf((char*)FreqStr, "      FREQ: %6lu     ", *AudioFreq_ptr);
          BSP_AUDIO_OUT_Pause();
          BSP_AUDIO_OUT_SetFrequency(*AudioFreq_ptr);
          BSP_AUDIO_OUT_Resume();
          BSP_AUDIO_OUT_SetVolume(uwVolume);
        }
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 50, (uint8_t *)FreqStr, CENTER_MODE);
      }
      else if (TS_State.touchX[0] > (BSP_LCD_GetXSize() - 30))
      {
        /* Increase Frequency */
        if (*AudioFreq_ptr != 96000)
        {
          AudioFreq_ptr++;
          sprintf((char*)FreqStr, "      FREQ: %6lu     ", *AudioFreq_ptr);
          BSP_AUDIO_OUT_Pause();
          BSP_AUDIO_OUT_SetFrequency(*AudioFreq_ptr);
          BSP_AUDIO_OUT_Resume();
          BSP_AUDIO_OUT_SetVolume(uwVolume);
        }
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 50, (uint8_t *)FreqStr, CENTER_MODE);
      }

      /* Wait for touch screen no touch detected */
      do
      {
        BSP_TS_GetState(&TS_State);
      }while(TS_State.touchDetected > 0);
    }

    if (TS_State.touchDetected >= 2)
    {
      /* Set Pause / Resume */
      if (uwPauseEnabledStatus == 1)
      { /* Pause is enabled, call Resume */
        BSP_AUDIO_OUT_Resume();
        uwPauseEnabledStatus = 0;
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 80, (uint8_t *)"       PLAYING...     ", CENTER_MODE);
      }
      else
      { /* Pause the playback */
        BSP_AUDIO_OUT_Pause();
        uwPauseEnabledStatus = 1;
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 80, (uint8_t *)"       PAUSE  ...     ", CENTER_MODE);
      }

      /* Wait for touch screen no touch detected */
      do
      {
        BSP_TS_GetState(&TS_State);
      }while(TS_State.touchDetected > 0);
    }
    
    if (CheckForUserInput() > 0)
    {
      BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
      BSP_AUDIO_OUT_DeInit();
      return;
    }
  }
}
Пример #16
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
 /* This sample code shows how to use STM32F7xx CEC HAL API to transmit and 
  * receive data. The device is set in waiting to receive mode and sends
  * messages when the evaluation board buttons are pushed by the user */

  /* Configure the MPU attributes as Write Through */
  MPU_Config();

  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
  
  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator
       - 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.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 200 MHz MHz */
  SystemClock_Config();


  /*##-1- Initialize the SDRAM  ##############################################*/
  BSP_SDRAM_Init();

  /*##-2- Initialize the LCD #################################################*/
  BSP_LCD_Init();
  BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER);

  /* Enable the LCD */
  BSP_LCD_DisplayOn();

  /* Select the LCD Foreground layer */
  BSP_LCD_SelectLayer(1);

  /* Display test description on screen */
  CEC_SetHint();

  /* -2- Configure touch screen */
  BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
  BSP_TS_ITConfig();  /* Touch screen interrupt configuration and enable */
  
  /* -3- CEC configuration (transfer will take place in Interrupt mode) */
#if defined (DEVICE_1)
  DestinationAddress = DEVICE_ADDRESS_2; /* follower address */
#elif defined (DEVICE_2)
  DestinationAddress = DEVICE_ADDRESS_1; /* follower address */
#endif  
  hcec.Instance = CEC;
  /* Deinitialize CEC to reinitialize from scratch */
  HAL_CEC_DeInit(&hcec);
  /* IP configuration */ 
  CEC_Config(&hcec);
  

  /* -4- CEC transfer general variables initialization */
  ReceivedFrame = 0;
  StartSending = 0;
  NbOfReceivedBytes = 0;
  CEC_FlushRxBuffer();
  
  
  /* Test start */
    
  /* Enter infinite reception loop: the CEC device is set in
   * waiting to receive mode. 
   * The CEC "background" state is HAL_CEC_STATE_STANDBY_RX.
   * Upon any message reception or transmission, the CEC 
   * comes back to that state.
   * It is up to the user to define exit conditions in modifying
   * accordingly the RX, TX or Error callback functions. */
  HAL_CEC_Receive_IT(&hcec, (uint8_t *)&Tab_Rx); 
  while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_READY)
  {
    
    /* if no reception has occurred and no error has been detected,
     * transmit a message if the user has pushed a button */
    if( (StartSending == 1) && (ReceivedFrame == 0))
    { 
      HAL_CEC_Transmit_IT(&hcec, DestinationAddress, (uint8_t *)&Tab_Tx, TxSize);
      /* loop until TX ends or TX error reported */
      while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_STANDBY_RX);
      StartSending = 0;
    }  
    
    /* if a frame has been received */
    if (ReceivedFrame == 1)
    { 
      if (Tab_Rx[1] == 0x44) /* Test on the opcode value */
      {
        /* Receive command is equal to Command 1 */
        if (Tab_Rx[2] == 0x41) /* Test on the operand value */
        {       
          BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
          BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
          BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+30, (uint8_t *)"  Received opcode 44, operand 41  ", CENTER_MODE);
        }
        else if (Tab_Rx[2] == 0x42) /* Receive command is equal to Command 2 */
        {
          BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
          BSP_LCD_SetBackColor(LCD_COLOR_GREEN);
          BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+30, (uint8_t *)"  Received opcode 44, operand 42  ", CENTER_MODE);
        }
      }
      else if (Tab_Rx[1] == 0x46) /* Test on the opcode value */
      {
        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        BSP_LCD_SetBackColor(LCD_COLOR_ORANGE);
        BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+30, (uint8_t *)"       Received opcode 46         ", CENTER_MODE);
      }
      else if (Tab_Rx[1] == 0x9F) /* Test on the opcode value */
      {
        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        BSP_LCD_SetBackColor(LCD_COLOR_DARKMAGENTA);
        BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+30, (uint8_t *)"       Received opcode 9F         ", CENTER_MODE);
      }
      ReceivedFrame = 0;
    }
    else if (ReceivedFrame == 2) /* means CEC error detected */
    { 
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
      BSP_LCD_SetBackColor(LCD_COLOR_RED);
      BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+45, (uint8_t *)"            CEC Error             ", CENTER_MODE);
      ReceivedFrame = 0;
    }
  }  /*  while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_READY) */
  return 0;
}
Пример #17
0
void initializeGUI(void) {

    BSP_LCD_Init();

    BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);

    BSP_LCD_DisplayOn();

    BSP_LCD_SelectLayer(0);

    BSP_LCD_Clear(LCD_COLOR_WHITE);

    BSP_LCD_SetTransparency(0, 200);

    BSP_LCD_SetFont(&Font20);

    button_home.x_pos = 5;
    button_home.y_pos = 5;
    button_home.hasBeenAcknowledged = 0;
    button_home.isEnabled = 1;
    button_home.isPushed = 0;
    memcpy(button_home.title, "<Home", 6);
    button_home.buttonEventHandler = backToHomeScreen;

    buttons[BUTTON_E0].x_pos = E0_BUTTON_X;
    buttons[BUTTON_E0].y_pos = E0_BUTTON_Y;
    buttons[BUTTON_E0].isPushed = 0;
    buttons[BUTTON_E0].hasBeenAcknowledged = 0;
    buttons[BUTTON_E0].isEnabled = 0;
    buttons[BUTTON_E0].buttonEventHandler = eventHandlerE0;
    memcpy(buttons[BUTTON_E0].title, "0xE0\0", 5);

    buttons[BUTTON_E1].x_pos = E1_BUTTON_X;
    buttons[BUTTON_E1].y_pos = E1_BUTTON_Y;
    buttons[BUTTON_E1].isPushed = 0;
    buttons[BUTTON_E1].hasBeenAcknowledged = 0;
    buttons[BUTTON_E1].buttonEventHandler = eventHandlerE1;
    memcpy(buttons[BUTTON_E1].title, "0xE1\0", 5);
    buttons[BUTTON_E1].isEnabled = 0;

    buttons[BUTTON_01].x_pos = O1_BUTTON_X;
    buttons[BUTTON_01].y_pos = O1_BUTTON_Y;
    buttons[BUTTON_01].isPushed = 0;
    buttons[BUTTON_01].isEnabled = 0;
    buttons[BUTTON_01].hasBeenAcknowledged = 0;
    buttons[BUTTON_01].buttonEventHandler = eventHandlerAdjust;
    memcpy(buttons[BUTTON_01].title, "0x01\0", 5);

    buttons[BUTTON_05].x_pos = O5_BUTTON_X;
    buttons[BUTTON_05].y_pos = O5_BUTTON_Y;
    buttons[BUTTON_05].isPushed = 0;
    buttons[BUTTON_05].hasBeenAcknowledged = 0;
    buttons[BUTTON_05].isEnabled = 0;
    buttons[BUTTON_05].buttonEventHandler = eventHandlerConfirm;
    memcpy(buttons[BUTTON_05].title, "0x05\0", 5);

    buttons[BUTTON_C8].x_pos = C8_BUTTON_X;
    buttons[BUTTON_C8].y_pos = C8_BUTTON_Y;
    buttons[BUTTON_C8].isPushed = 0;
    buttons[BUTTON_C8].hasBeenAcknowledged = 0;
    buttons[BUTTON_C8].isEnabled = 0;
    buttons[BUTTON_C8].buttonEventHandler = eventHandlerC8;
    memcpy(buttons[BUTTON_C8].title, "0xC8\0", 5);

    buttons[BUTTON_C9].x_pos = C9_BUTTON_X;
    buttons[BUTTON_C9].y_pos = C9_BUTTON_Y;
    buttons[BUTTON_C9].isPushed = 0;
    buttons[BUTTON_C9].hasBeenAcknowledged = 0;
    buttons[BUTTON_C9].isEnabled = 0;
    buttons[BUTTON_C9].buttonEventHandler = eventHandlerC9;
    memcpy(buttons[BUTTON_C9].title, "0xC9\0", 5);

    buttons[BUTTON_CB].x_pos = CB_BUTTON_X;
    buttons[BUTTON_CB].y_pos = CB_BUTTON_Y;
    buttons[BUTTON_CB].isPushed = 0;
    buttons[BUTTON_CB].hasBeenAcknowledged = 0;
    buttons[BUTTON_CB].isEnabled = 0;
    buttons[BUTTON_CB].buttonEventHandler = eventHandlerCB;
    memcpy(buttons[BUTTON_CB].title, "0xCB\0", 5);

    buttons[BUTTON_CC].x_pos = CC_BUTTON_X;
    buttons[BUTTON_CC].y_pos = CC_BUTTON_Y;
    buttons[BUTTON_CC].isPushed = 0;
    buttons[BUTTON_CC].hasBeenAcknowledged = 0;
    buttons[BUTTON_CC].isEnabled = 0;
    buttons[BUTTON_CC].buttonEventHandler = eventHandlerCC;
    memcpy(buttons[BUTTON_CC].title, "0xCC\0", 5);

    buttons[BUTTON_CONNECT].x_pos = CONNECT_BUTTON_X;
    buttons[BUTTON_CONNECT].y_pos = CONNECT_BUTTON_Y;
    buttons[BUTTON_CONNECT].isPushed = 0;
    buttons[BUTTON_CONNECT].hasBeenAcknowledged = 0;
    buttons[BUTTON_CONNECT].buttonEventHandler = buttonConnectPressed;
    buttons[BUTTON_CONNECT].isEnabled = 1;
    memcpy(buttons[BUTTON_CONNECT].title, "Conn.\0", 6);

    buttons_ramp_cycle[0].x_pos = 400;
    buttons_ramp_cycle[0].y_pos = 205;
    buttons_ramp_cycle[0].isPushed = 0;
    buttons_ramp_cycle[0].hasBeenAcknowledged= 0;
    buttons_ramp_cycle[0].isEnabled = 0;
    buttons_ramp_cycle[0].buttonEventHandler = decreaseRampID;
    memcpy(buttons_ramp_cycle[0].title, "<<", 2);

    buttons_ramp_cycle[1].x_pos = 440;
    buttons_ramp_cycle[1].y_pos = 205;
    buttons_ramp_cycle[1].isPushed = 0;
    buttons_ramp_cycle[1].isEnabled = 0;
    buttons_ramp_cycle[1].hasBeenAcknowledged= 0;
    buttons_ramp_cycle[1].buttonEventHandler = increaseRampID;
    memcpy(buttons_ramp_cycle[1].title, ">>", 2);

    buttons_ramp_cycle[2].x_pos = 400;
    buttons_ramp_cycle[2].y_pos = 235;
    buttons_ramp_cycle[2].isPushed = 0;
    buttons_ramp_cycle[2].hasBeenAcknowledged= 0;
    buttons_ramp_cycle[2].buttonEventHandler = decreaseCycleID;
    buttons_ramp_cycle[2].isEnabled = 0;
    memcpy(buttons_ramp_cycle[2].title, "<<", 2);

    buttons_ramp_cycle[3].x_pos = 440;
    buttons_ramp_cycle[3].y_pos = 235;
    buttons_ramp_cycle[3].isPushed = 0;
    buttons_ramp_cycle[3].isEnabled = 0;
    buttons_ramp_cycle[3].hasBeenAcknowledged= 0;
    buttons_ramp_cycle[3].buttonEventHandler = increaseCycleID;
    memcpy(buttons_ramp_cycle[3].title, ">>", 2);

    buttons_ramp_cycle[4].x_pos = 400;
    buttons_ramp_cycle[4].y_pos = 145;
    buttons_ramp_cycle[4].isPushed = 0;
    buttons_ramp_cycle[4].hasBeenAcknowledged = 0;
    buttons_ramp_cycle[4].buttonEventHandler = decreaseAnalogInput;
    buttons_ramp_cycle[4].isEnabled = 0;
    memcpy(buttons_ramp_cycle[4].title, "<<", 2);

    buttons_ramp_cycle[5].x_pos = 440;
    buttons_ramp_cycle[5].y_pos = 145;
    buttons_ramp_cycle[5].isPushed = 0;
    buttons_ramp_cycle[5].isEnabled = 0;
    buttons_ramp_cycle[5].hasBeenAcknowledged= 0;
    buttons_ramp_cycle[5].buttonEventHandler = increaseAnalogInput;
    memcpy(buttons_ramp_cycle[5].title, ">>", 2);

    buttons_ramp_cycle[6].x_pos = 400;
    buttons_ramp_cycle[6].y_pos = 175;
    buttons_ramp_cycle[6].isPushed = 0;
    buttons_ramp_cycle[6].hasBeenAcknowledged = 0;
    buttons_ramp_cycle[6].buttonEventHandler = decreaseDigitalInput;
    buttons_ramp_cycle[6].isEnabled = 0;
    memcpy(buttons_ramp_cycle[6].title, "<<", 2);

    buttons_ramp_cycle[7].x_pos = 440;
    buttons_ramp_cycle[7].y_pos = 175;
    buttons_ramp_cycle[7].isPushed = 0;
    buttons_ramp_cycle[7].isEnabled = 0;
    buttons_ramp_cycle[7].hasBeenAcknowledged= 0;
    buttons_ramp_cycle[7].buttonEventHandler = increaseDigitalInput;
    memcpy(buttons_ramp_cycle[7].title, ">>", 2);

    pboards_c = 0;
    for (int i = 0; i < NUMBER_OF_BOARDS; i++) {
        pboards[i].board.module = NONE;

        pboards[i].isEnabled = 0;
        pboards[i].isPushed = 0;
        pboards[i].order = (uint8_t) i;
    }

    pboards[0].x = 25;
    pboards[0].y = 90;

    pboards[1].x = 25;
    pboards[1].y = 180;

    pboards[2].x = 240;
    pboards[2].y = 90;

    pboards[3].x = 240;
    pboards[3].y = 180;

    BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());

    aScreen = BOARD_SELECTION;

    drawHomeScreen();

    isReady = 0;
}
Пример #18
0
/**
  * @brief  Camera demo
  * @param  None
  * @retval None
  */
void Camera_demo (void)
{
  uint8_t  status = 0;
  uint32_t exit = 0;
  uint32_t camera_status = CAMERA_OK;
  uint32_t argb8888_Value = 0x00FF00FF; /* = 0xF81F in RGB565 format */
  TS_StateTypeDef  TS_State;
  uint32_t TS_command = TS_RESOLUTION;

  Camera_SetHint();

  status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());

  if (status != TS_OK)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 95, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 80, (uint8_t *)"Touchscreen cannot be initialized", CENTER_MODE);
  }

  /*## Camera Initialization and start capture ############################*/

  CameraResIndex = CAMERA_R160x120;     /* Set QQVGA default resolution */
  CameraResX = CAMERA_QQVGA_RES_X;
  CameraResY = CAMERA_QQVGA_RES_Y;

  /* Infinite loop */
  while (exit == 0)
  {
    if (TS_command == TS_RESOLUTION)  /* A camera change resolution has been asked */
    {
      TS_command = TS_NO_COMMAND;

      BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"Wait for camera initialization...", CENTER_MODE);

      BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
      BSP_LCD_SetTextColor(LCD_COLOR_BLUE);

      switch (CameraResIndex)
      {
        case CAMERA_R160x120:
          CameraResX = CAMERA_QQVGA_RES_X;
          CameraResY = CAMERA_QQVGA_RES_Y;
          /* Initialize the Camera */
          camera_status = BSP_CAMERA_Init(RESOLUTION_R160x120);
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"       QQVGA camera stream       ", CENTER_MODE);
          break;

        case CAMERA_R320x240:
          CameraResX = CAMERA_QVGA_RES_X;
          CameraResY = CAMERA_QVGA_RES_Y;
          /* Initialize the Camera */
          camera_status = BSP_CAMERA_Init(RESOLUTION_R320x240);
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"       QVGA camera stream        ", CENTER_MODE);
          break;

        case CAMERA_R480x272:
          CameraResX = CAMERA_480x272_RES_X;
          CameraResY = CAMERA_480x272_RES_Y;
          /* Initialize the Camera */
          camera_status = BSP_CAMERA_Init(RESOLUTION_R480x272);
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"      480x272 camera stream      ", CENTER_MODE);
          break;

        case CAMERA_R640x480:
          CameraResX = CAMERA_VGA_RES_X;
          CameraResY = CAMERA_VGA_RES_Y;
          /* Initialize the Camera */
          camera_status = BSP_CAMERA_Init(RESOLUTION_R640x480);
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"        VGA camera stream        ", CENTER_MODE);
          break;

        default :
          break;
      }

      if (camera_status != CAMERA_OK)
      {
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS - 15, (uint8_t *)"        CAMERA INIT ERROR        ", CENTER_MODE);
      }
      else
      {
        offset_cam = 0;
        offset_lcd = 0;
        display_line_counter = 0;

        special_effect = CAMERA_BLACK_WHITE;      /* No special effect applied */
        color_effect = CAMERA_BLACK_WHITE_NORMAL;
        contrast = CAMERA_CONTRAST_LEVEL2;        /* Mid-level brightness */
        brightness = CAMERA_BRIGHTNESS_LEVEL2;    /* Mid-level contrast */

        CameraFrameBufferInitComplete = 0;
        CameraFrameBufferInitError    = 0;

        /* Init or Re-Init Camera frame buffer by using DMA2D engine in mode Register to Memory */
        camera_status = CameraFrameBufferRgb565_Init(CAMERA_VGA_RES_X,
                                                     CAMERA_VGA_RES_Y,
                                                     argb8888_Value);
        ASSERT(camera_status != CAMERA_OK);

        /* Wait end of DMA2D operation of error : via IT callback update */
        while((CameraFrameBufferInitComplete == 0) && (CameraFrameBufferInitError == 0)) {;}

        /* Assert if error : no transfer complete */
        ASSERT(CameraFrameBufferInitComplete != 1);

        /* Start / Restart camera stream */
        BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FRAME_BUFFER);

        /* Allow DMA2D copy from Camera frame buffer to LCD Frame buffer location */
        Camera_AllowDma2dCopyCamFrmBuffToLcdFrmBuff = 1;
      }
    }  /* (CameraResIndex != CameraCurrentResIndex) */

    if (camera_status == CAMERA_OK)
    {
      /* Check in polling mode in touch screen the touch status and coordinates */
      /* if touch occurred                                                      */
      BSP_TS_GetState(&TS_State);
      if(TS_State.touchDetected >= 1)
      {
        /* Check touch position to apply brightness or contrast change */
        if (TS_State.touchDetected == 1)
        {
          if ((TS_State.touchY[0] < 30) && (brightness < CAMERA_BRIGHTNESS_MAX))
          {
            TS_command = TS_BRIGHTNESS_INC;
            brightness++;
          }
          else if ((TS_State.touchY[0] > (BSP_LCD_GetYSize() - 30)) && (brightness > CAMERA_BRIGHTNESS_MIN) )
          {
            TS_command = TS_BRIGHTNESS_DEC;
            brightness--;
          }
          else if ((TS_State.touchX[0] < 30) && (contrast > CAMERA_CONTRAST_MIN))
          {
            TS_command = TS_CONTRAST_DEC;
            contrast--;
          }
          else if ((TS_State.touchX[0] > (BSP_LCD_GetXSize() - 30)) && (contrast < CAMERA_CONTRAST_MAX))
          {
            TS_command = TS_CONTRAST_INC;
            contrast++;
          }
          else
          {
            TS_command = TS_NO_COMMAND;
          }
        }

        /* Special effect change */
        if (TS_State.touchDetected == 2)
        {
          TS_command = TS_EFFECT;
          switch (special_effect)
          {
            case CAMERA_BLACK_WHITE :
              if (color_effect < CAMERA_BLACK_WHITE_NORMAL)
              {
                /* From BW effect to another BW effect */
                color_effect++;
              }
              else
              {
                /* From BW or none effect to color effect */
                special_effect = CAMERA_COLOR_EFFECT;
                color_effect = CAMERA_COLOR_EFFECT_BLUE;
              }
              break;

            case CAMERA_COLOR_EFFECT :
              if (color_effect < CAMERA_COLOR_EFFECT_ANTIQUE)
              {
                /* From color effect to another color effect */
                color_effect++;
              }
              else
              {
                /* From color effect to BW effect */
                special_effect = CAMERA_BLACK_WHITE;
                color_effect = CAMERA_BLACK_WHITE_BW;
              }
              break;

            default :
              /* None effect */
              special_effect = CAMERA_BLACK_WHITE;
              color_effect = CAMERA_BLACK_WHITE_NORMAL;
              break;
          }
        }

        if (TS_command == TS_NO_COMMAND)
        {
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"                                 ", CENTER_MODE);
        }

        if ((TS_command == TS_BRIGHTNESS_INC) || (TS_command == TS_BRIGHTNESS_DEC) || (TS_command == TS_CONTRAST_INC) || (TS_command == TS_CONTRAST_DEC))
        {
          /* A brightness change has been asked */
          BSP_CAMERA_ContrastBrightnessConfig(contrast, brightness);
          if ((TS_command == TS_BRIGHTNESS_INC) || (TS_command == TS_BRIGHTNESS_DEC))
          {
            BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"        Brightness change        ", CENTER_MODE);
          }
          else
          {
            BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"         Contrast change         ", CENTER_MODE);
          }
        }

        if (TS_command == TS_EFFECT)
        {
          /* A color effect change has been asked */
          switch (special_effect)
          {
            case CAMERA_BLACK_WHITE :
              BSP_CAMERA_BlackWhiteConfig(color_effect);
              switch (color_effect)
              {
                case CAMERA_BLACK_WHITE_NORMAL :
                  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"        No effect applied        ", CENTER_MODE);
                  break;
                case CAMERA_BLACK_WHITE_BW :
                  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)" Black and white effect applied  ", CENTER_MODE);
                  break;
                case CAMERA_BLACK_WHITE_NEGATIVE :
                  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"     Negative effect applied     ", CENTER_MODE);
                  break;
                case CAMERA_BLACK_WHITE_BW_NEGATIVE :
                  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"   BW negative effect applied    ", CENTER_MODE);
                  break;
              }
              break;

            case CAMERA_COLOR_EFFECT :
              BSP_CAMERA_ColorEffectConfig(color_effect);
              switch (color_effect)
              {
                case CAMERA_COLOR_EFFECT_ANTIQUE :
                  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"   Sepia color effect applied    ", CENTER_MODE);
                  break;
                case CAMERA_COLOR_EFFECT_BLUE :
                  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"    Blue color effect applied    ", CENTER_MODE);
                  break;
                case CAMERA_COLOR_EFFECT_GREEN :
                  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"   Green color effect applied    ", CENTER_MODE);
                  break;
                case CAMERA_COLOR_EFFECT_RED :
                  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"     Red color effect applied    ", CENTER_MODE);
                  break;
              }
              break;
          }
        }

        if (TS_State.touchDetected >= 3)  /* 3 or more fingers touch to change resolution */
        {
          TS_command = TS_RESOLUTION;
          if (CameraResIndex < CAMERA_RES_INDEX_MAX)
          {
            CameraResIndex++;     /* Switch to higher resolution */
          }
          else
          {
            CameraResIndex = CAMERA_RES_INDEX_MIN;
          }

          /* Disallow DMA2D copy from Camera frame buffer to LCD Frame buffer location */
          Camera_AllowDma2dCopyCamFrmBuffToLcdFrmBuff = 0;

          /* Insert 10 ms delay */
          HAL_Delay(10);

          /* Stop camera stream */
          camera_status = BSP_CAMERA_Stop();
          ASSERT(camera_status != CAMERA_OK);

          /* Clear screen */
          Camera_SetHint();
        }

        /* Wait for touch screen no touch detected */
        do
        {
          BSP_TS_GetState(&TS_State);
        }while(TS_State.touchDetected > 0);
      }
    }

    if (CheckForUserInput() > 0)
    {
      exit = 1;
    }
  }

  if (camera_status == CAMERA_OK)
  {
    /* Stop camera stream */
    camera_status = BSP_CAMERA_Stop();
    ASSERT(camera_status != CAMERA_OK);
  }
  /* End of camera demo */
}
Пример #19
0
/**
  * @brief  Performs the TS calibration
  * @param  None
  * @retval Status (TS_OK = 0/ TS_ERROR = 1 / TS_TIMEOUT = 1 / TS_DEVICE_NOT_FOUND = 3)
  */
uint8_t Touchscreen_Calibration(void)
{
  uint8_t ts_status = TS_OK;
  uint8_t i;
  uint16_t ts_SizeX;
  uint16_t ts_SizeY;

  ts_SizeX = BSP_LCD_GetXSize();
  ts_SizeY = BSP_LCD_GetYSize();

  TouchscreenCalibration_SetHint();

  /* Start touchscreen internal calibration and configuration + start */
  ts_status = BSP_TS_Init(ts_SizeX, ts_SizeY);
  if (ts_status != TS_OK)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 95, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 80, (uint8_t *)"Touchscreen cannot be calibrated", CENTER_MODE);
    if(ts_status == TS_ERROR)
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"Touchscreen undefined error", CENTER_MODE);
    }
    else if(ts_status == TS_TIMEOUT)
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"Touchscreen Timeout", CENTER_MODE);
    }
    else
    {
      /* TS_DEVICE_NOT_FOUND */
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"Touchscreen Not Found", CENTER_MODE);
    }
  }
  else
  {
    /* status == TS_OK */
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"FT6x06 internal calibration passed", CENTER_MODE);

    /* Get touch points for SW calibration processing */
    aLogX[0] = 40;
    aLogY[0] = 40;
    aLogX[1] = BSP_LCD_GetXSize() - 40;
    aLogY[1] = BSP_LCD_GetYSize() - 40;

    for (i = 0; i < 2; i++)
    {
      TouchScreen_Calibration_GetPhysValues(aLogX[i], aLogY[i], &aPhysX[i], &aPhysY[i]);
    }

    /* Compute calibration coefficients */
    A1 = (1000 * ( aLogX[1] - aLogX[0])) / ( aPhysX[1] - aPhysX[0]);
    B1 = (1000 * aLogX[0]) - A1 * aPhysX[0];

    A2 = (1000 * ( aLogY[1] - aLogY[0])) / ( aPhysY[1] - aPhysY[0]);
    B2 = (1000 * aLogY[0]) - A2 * aPhysY[0];

    ts_calibration_done = 1;
  }

  return (ts_status);
}
Пример #20
0
/**
  * @brief  Touchscreen Demo
  * @param  None
  * @retval None
  */
void Touchscreen_demo (void)
{ 
  uint8_t  status = 0;
  uint16_t x,y;
  uint8_t state = 0;

  if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID)
  { 
  if(IsCalibrationDone() == 0)
  {
    Touchscreen_Calibration();
  }
  }
  
  Touchscreen_SetHint();
  
  status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
  
  if (status != TS_OK)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE); 
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 95, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 80, (uint8_t *)"Touchscreen cannot be initialized", CENTER_MODE);
  }
  else
  {
    Touchscreen_DrawBackground(state);
  }
  
  while (1)
  {
    if (status == TS_OK)
    {
      BSP_TS_GetState(&TS_State);
      
      if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID)
      {      
        x = Calibration_GetX(TS_State.x);
        y = Calibration_GetY(TS_State.y);
      }
      else
      {
        x = TS_State.x;
        y = TS_State.y;  
      }
      
      if((TS_State.TouchDetected) && 
         (y > (CIRCLE_YPOS(1) - CIRCLE_RADIUS))&&
           (y < (CIRCLE_YPOS(1) + CIRCLE_RADIUS)))
      {
        
        if((x > (CIRCLE_XPOS(1) - CIRCLE_RADIUS))&&
           (x < (CIRCLE_XPOS(1) + CIRCLE_RADIUS)))
        {
          if((state & 1) == 0)
          {
            Touchscreen_DrawBackground(state);
            BSP_LCD_SetTextColor(LCD_COLOR_BLUE); 
            BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS);
            state = 1;
          }
        }
        if((x > (CIRCLE_XPOS(2) - CIRCLE_RADIUS))&&
           (x < (CIRCLE_XPOS(2) + CIRCLE_RADIUS)))
        {
          if((state & 2) == 0)
          {          
            Touchscreen_DrawBackground(state);
            BSP_LCD_SetTextColor(LCD_COLOR_RED); 
            BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS);
            state = 2;
          }          
        }
        
        if((x > (CIRCLE_XPOS(3) - CIRCLE_RADIUS))&&
           (x < (CIRCLE_XPOS(3) + CIRCLE_RADIUS)))
        {
          if((state & 4) == 0)
          {           
            Touchscreen_DrawBackground(state);
            BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); 
            BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS);
            state = 4;
          }            
        }
        
        if((x > (CIRCLE_XPOS(4) - CIRCLE_RADIUS))&&
           (x < (CIRCLE_XPOS(4) + CIRCLE_RADIUS)))
        {
          if((state & 8) == 0)
          {           
            Touchscreen_DrawBackground(state);
            BSP_LCD_SetTextColor(LCD_COLOR_GREEN); 
            BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS);
            state = 8;
          }           
        }        
      }   
    }
    
    if(CheckForUserInput() > 0)
    {
      return;
    }
    
    HAL_Delay(10);
  }
}
Пример #21
0
/**
  * @brief  Touchscreen Demo
  * @param  None
  * @retval None
  */
void Touchscreen_demo (void)
{
  uint8_t  status = 0;
  uint16_t x, y;
  uint8_t  state = 0;
  uint8_t  text[30];
  uint8_t  radius;
  uint8_t  radius_previous = 0;

  Touchscreen_SetHint();

  status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());

  if (status != TS_OK)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 95, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 80, (uint8_t *)"Touchscreen cannot be initialized", CENTER_MODE);
  }
  else
  {
    Touchscreen_DrawBackground(state);
  }

  while (1)
  {
    if (status == TS_OK)
    {
      /* Check in polling mode in touch screen the touch status and coordinates */
      /* if touch occurred                                                      */
      BSP_TS_GetState(&TS_State);
      if(TS_State.touchDetected)
      {
        /* Get X and Y position of the touch post calibrated */
        x = TS_State.touchX[0];
        y = TS_State.touchY[0];

        BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
        BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
        sprintf((char*)text, "Nb touch detected = %d", TS_State.touchDetected);
        BSP_LCD_DisplayStringAt(15, BSP_LCD_GetYSize() - 40, (uint8_t *)&text, LEFT_MODE);

        /* Display 1st touch detected coordinates */
        sprintf((char*)text, "1[%d,%d]    ", x, y);
        BSP_LCD_DisplayStringAt(15,
                                BSP_LCD_GetYSize() - 25,
                                (uint8_t *)&text,
                                LEFT_MODE);

        if (TS_State.touchDetected >= 2)  /* Display 2nd touch detected coordinates if applicable */
        {
          sprintf((char*)text, "2[%d,%d]    ", TS_State.touchX[1], TS_State.touchY[1]);
        }
        else
        {
          sprintf((char*)text, "              ");
        }
        BSP_LCD_DisplayStringAt((((BSP_LCD_GetXSize() - 30) * 1) / 5) + 15,
                                BSP_LCD_GetYSize() - 25,
                                (uint8_t *)&text,
                                LEFT_MODE);

        if (TS_State.touchDetected >= 3)  /* Display 3rd touch detected coordinates if applicable */
        {
          sprintf((char*)text, "3[%d,%d]    ", TS_State.touchX[2], TS_State.touchY[2]);
        }
        else
        {
          sprintf((char*)text, "              ");
        }
        BSP_LCD_DisplayStringAt((((BSP_LCD_GetXSize() - 30) * 2) / 5) + 15,
                                BSP_LCD_GetYSize() - 25,
                                (uint8_t *)&text,
                                LEFT_MODE);

        if (TS_State.touchDetected >= 4)  /* Display 4th touch detected coordinates if applicable */
        {
          sprintf((char*)text, "4[%d,%d]    ", TS_State.touchX[3], TS_State.touchY[3]);
        }
        else
        {
          sprintf((char*)text, "              ");
        }
        BSP_LCD_DisplayStringAt((((BSP_LCD_GetXSize() - 30) * 3) / 5) + 15,
                                BSP_LCD_GetYSize() - 25,
                                (uint8_t *)&text,
                                LEFT_MODE);

        if (TS_State.touchDetected >= 5)  /* Display 5th touch detected coordinates if applicable */
        {
          sprintf((char*)text, "5[%d,%d]    ", TS_State.touchX[4], TS_State.touchY[4]);
        }
        else
        {
          sprintf((char*)text, "              ");
        }
        BSP_LCD_DisplayStringAt((((BSP_LCD_GetXSize() - 30) * 4) / 5) + 15,
                                BSP_LCD_GetYSize() - 25,
                                (uint8_t *)&text,
                                LEFT_MODE);

        /* Calculate circle radius to fill according to finger pressure applied on screen (weight) */
        radius = TS_State.touchWeight[0]/3;
        if (radius > CIRCLE_RADIUS)
        {
          radius = CIRCLE_RADIUS;
        }
        else if (radius < 1)
        {
          radius = 1;
        }


        if ((y > (CIRCLE_YPOS(1) - CIRCLE_RADIUS)) &&
            (y < (CIRCLE_YPOS(1) + CIRCLE_RADIUS)))
        {

          if ((x > (CIRCLE_XPOS(1) - CIRCLE_RADIUS)) &&
              (x < (CIRCLE_XPOS(1) + CIRCLE_RADIUS)))
          {
            if ((radius != radius_previous) || (state != 1))
            {
              if (state != 1) /* Erase previous filled circle */
              {
                Touchscreen_DrawBackground(state);
              }
              BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
              BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), radius);
              radius_previous = radius;
              state = 1;
            }
          }
          if ((x > (CIRCLE_XPOS(2) - CIRCLE_RADIUS)) &&
              (x < (CIRCLE_XPOS(2) + CIRCLE_RADIUS)))
          {
            if ((radius != radius_previous) || (state != 2))
            {
              if (state != 2) /* Erase previous filled circle */
              {
                Touchscreen_DrawBackground(state);
              }
              BSP_LCD_SetTextColor(LCD_COLOR_RED);
              BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), radius);
              radius_previous = radius;
              state = 2;
            }
          }

          if ((x > (CIRCLE_XPOS(3) - CIRCLE_RADIUS)) &&
              (x < (CIRCLE_XPOS(3) + CIRCLE_RADIUS)))
          {
            if ((radius != radius_previous) || (state != 4))
            {
              if (state != 4) /* Erase previous filled circle */
              {
                Touchscreen_DrawBackground(state);
              }
              BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
              BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), radius);
              radius_previous = radius;
              state = 4;
            }
          }

          if ((x > (CIRCLE_XPOS(4) - CIRCLE_RADIUS)) &&
              (x < (CIRCLE_XPOS(4) + CIRCLE_RADIUS)))
          {
            if ((radius != radius_previous) || (state != 8))
            {
              if (state != 8) /* Erase previous filled circle */
              {
                Touchscreen_DrawBackground(state);
              }
              BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
              BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), radius);
              radius_previous = radius;
              state = 8;
            }
          }
        }

      } /* of if(TS_State.touchDetected) */
    }

    if (CheckForUserInput() > 0)
    {
      return;
    }

    HAL_Delay(10);
  }
}