Пример #1
0
/**
  * @brief  Display interface touch screen buttons
  * @param  None
  * @retval None
  */
static void AUDIO_PlaybackDisplayButtons(void)
{
    BSP_LCD_SetFont(&LCD_LOG_HEADER_FONT);
    BSP_LCD_ClearStringLine(13);            /* Clear dedicated zone */
    BSP_LCD_ClearStringLine(14);
    BSP_LCD_ClearStringLine(15);

    BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
    BSP_LCD_FillPolygon(PreviousPoints, 3);   /* Previous track icon */
    BSP_LCD_FillRect(TOUCH_PREVIOUS_XMIN, TOUCH_PREVIOUS_YMIN , 10, TOUCH_PREVIOUS_YMAX - TOUCH_PREVIOUS_YMIN);
    BSP_LCD_FillPolygon(NextPoints, 3);       /* Next track icon */
    BSP_LCD_FillRect(TOUCH_NEXT_XMAX-9, TOUCH_NEXT_YMIN , 10, TOUCH_NEXT_YMAX - TOUCH_NEXT_YMIN);
    BSP_LCD_FillRect(TOUCH_PAUSE_XMIN, TOUCH_PAUSE_YMIN , 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN);    /* Pause rectangles */
    BSP_LCD_FillRect(TOUCH_PAUSE_XMIN + 20, TOUCH_PAUSE_YMIN, 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN);
    BSP_LCD_FillRect(TOUCH_STOP_XMIN, TOUCH_STOP_YMIN , /* Stop rectangle */
                     TOUCH_STOP_XMAX - TOUCH_STOP_XMIN,
                     TOUCH_STOP_YMAX - TOUCH_STOP_YMIN);
    BSP_LCD_DrawRect(TOUCH_VOL_MINUS_XMIN, TOUCH_VOL_MINUS_YMIN , /* VOl- rectangle */
                     TOUCH_VOL_MINUS_XMAX - TOUCH_VOL_MINUS_XMIN,
                     TOUCH_VOL_MINUS_YMAX - TOUCH_VOL_MINUS_YMIN);
    BSP_LCD_DisplayStringAt(24, LINE(14), (uint8_t *)"VOl-", LEFT_MODE);
    BSP_LCD_DrawRect(TOUCH_VOL_PLUS_XMIN, TOUCH_VOL_PLUS_YMIN , /* VOl+ rectangle */
                     TOUCH_VOL_PLUS_XMAX - TOUCH_VOL_PLUS_XMIN,
                     TOUCH_VOL_PLUS_YMAX - TOUCH_VOL_PLUS_YMIN);
    BSP_LCD_DisplayStringAt(24, LINE(14), (uint8_t *)"VOl+", RIGHT_MODE);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_SetFont(&LCD_LOG_TEXT_FONT);
    BSP_LCD_ClearStringLine(15);
    BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"Use stop button to exit");
    BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
}
Пример #2
0
/*
    Conditions:
      1
    Exit points:
      0
    M = 1 - 0 + 2 = 3
    Cyclomatic complexity
      3
  */
void gt511_startup(void)
{
  uint32_t gt511Err = -1;
  // GT511 startup sequence
  vTaskDelay(50);

  BSP_LCD_DisplayStringAtLine(0, (uint8_t*)"GT511 Init");

  GT511C1R_Init(&gt511, &uartEndpoint);

  BSP_LCD_ClearStringLine(0);
  BSP_LCD_DisplayStringAtLine(0, (uint8_t*)"GT511 Init - done");

  BSP_LCD_DisplayStringAtLine(1, (uint8_t*)"GT511 Open");

  BSP_LED_On(LED3);

  while (gt511Err != GT511C1R_ErrorCode_Success)
  {
    BSP_LED_On(LED3);
    gt511Err = GT511C1R_Open(&gt511);
    BSP_LED_Off(LED3);

    vTaskDelay(1000);
  }

  BSP_LCD_ClearStringLine(1);
  BSP_LCD_DisplayStringAtLine(1, (uint8_t*)"GT511 Open - done");
}
Пример #3
0
/**
  * @brief  Starts Audio streaming.    
  * @param  None
  * @retval Audio error
  */ 
AUDIO_ErrorTypeDef AUDIO_REC_Start(void)
{
  uint32_t byteswritten = 0;
  uint8_t str[FILEMGR_FILE_NAME_SIZE + 20]; 
  
  uwVolume = 100;

  /* Create a new file system */
  if(f_open(&WavFile, REC_WAVE_NAME, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
  {  
    /* Initialize header file */
    WavProcess_EncInit(DEFAULT_AUDIO_IN_FREQ, pHeaderBuff);
    
    /* Write header file */
    if(f_write(&WavFile, pHeaderBuff, 44, (void*)&byteswritten) == FR_OK)
    {
      AudioState = AUDIO_STATE_PRERECORD;
      
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 
      sprintf((char *)str, "Recording file: %s", 
              (char *)REC_WAVE_NAME);
      BSP_LCD_ClearStringLine(4);
      BSP_LCD_DisplayStringAtLine(4, str);
      
      BSP_LCD_SetTextColor(LCD_COLOR_CYAN); 
      sprintf((char *)str,  "Sample rate : %d Hz", (int)DEFAULT_AUDIO_IN_FREQ);
      BSP_LCD_ClearStringLine(6);
      BSP_LCD_DisplayStringAtLine(6, str);
      
      sprintf((char *)str,  "Channels number : %d", (int)DEFAULT_AUDIO_IN_CHANNEL_NBR);
      BSP_LCD_ClearStringLine(7);      
      BSP_LCD_DisplayStringAtLine(7, str);
      
      sprintf((char *)str,  "Volume : %d ", (int)uwVolume);
      BSP_LCD_ClearStringLine(7);
      BSP_LCD_DisplayStringAtLine(7, str);

      sprintf((char *)str, "File Size :");
      BSP_LCD_ClearStringLine(8);
      BSP_LCD_DisplayStringAtLine(8, str);
 
      AUDIO_REC_DisplayButtons();
     
      BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)"  [RECORD]", LEFT_MODE);
      { 
        if(byteswritten != 0)
        {
          BSP_AUDIO_IN_Init(DEFAULT_AUDIO_IN_FREQ, DEFAULT_AUDIO_IN_BIT_RESOLUTION, DEFAULT_AUDIO_IN_CHANNEL_NBR);
          BSP_AUDIO_IN_Record((uint16_t*)&BufferCtl.pdm_buff[0], AUDIO_IN_PDM_BUFFER_SIZE);
          BufferCtl.fptr = byteswritten;
          BufferCtl.pcm_ptr = 0;
          BufferCtl.offset = 0;
          BufferCtl.wr_state = BUFFER_EMPTY;
          return AUDIO_ERROR_NONE;
        }
      }
    }
  }
  return AUDIO_ERROR_IO; 
}
Пример #4
0
int main(void){

	uint8_t  lcd_status = LCD_OK;

	CPU_CACHE_Enable();

	HAL_Init();

	/* Configura el reloj del sistema en 200 Mhz */
	SystemClock_Config();

	BSP_LED_Init(LED1);

	/*Configura el botón de usuario en modo GPIO*/
	BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

	/*Inicializar LCD*/
	lcd_status = BSP_LCD_Init();
	if(lcd_status != LCD_OK)
		while(1);

	/*Inicializa LCD Layers*/
	BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, SDRAM_DEVICE_ADDR);

	Display_Description();

	uint8_t detectSD = 0;
	uint8_t SD_state = MSD_OK;

	while(1){
		if(BSP_PB_GetState(BUTTON_KEY) != 0){
			HAL_Delay(500);
			Display_Description();
			detectSD = 1;
		}
		if(detectSD){
			detectSD = 0;
			SD_state = BSP_SD_Init();
			if(SD_state != MSD_OK){
				BSP_LCD_ClearStringLine(11);
				BSP_LCD_ClearStringLine(12);
				BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2.5)+25, (uint8_t *)"Tarjeta SD no encontrada", CENTER_MODE);
			}
			else{
				BSP_LCD_ClearStringLine(11);
				BSP_LCD_ClearStringLine(12);
				BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2.5)+25, (uint8_t *)"Tarjeta SD encontrada", CENTER_MODE);
			}
		}
	}
}
Пример #5
0
/**
  * @brief  Handles CDC Receive Menu. 
  * @param  None
  * @retval None
  */
void CDC_Handle_Receive_Menu(void)
{
  switch(CdcDemo.Receive_state)
  {
  case CDC_RECEIVE_IDLE:
    /* Start Reception */
    LCD_LOG_ClearTextZone();
    CdcDemo.Receive_state = CDC_RECEIVE_WAIT;
    USBH_CDC_Stop(&hUSBHost);
    LCD_DbgLog("Receiving data ...\n");
    
    xPos = 0;
    yLinePos = 5;
    
    memset(CDC_RX_Buffer, 0, RX_BUFF_SIZE); 
    USBH_CDC_Receive(&hUSBHost, CDC_RX_Buffer, RX_BUFF_SIZE);
    
    BSP_LCD_ClearStringLine(19);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start sending data ");
    break;
    
  case CDC_RECEIVE_WAIT:
    if((BSP_PB_GetState(BUTTON_KEY) == SET) && (Appli_state != APPLICATION_DISCONNECT))
    {
      CdcDemo.state =  CDC_DEMO_WAIT;
      CdcDemo.Receive_state = CDC_RECEIVE_IDLE;
    }
    break;
    
  default:
    break;
  }
}
Пример #6
0
/**
  * @brief  Display interface touch screen buttons
  * @param  None
  * @retval None
  */
static void AUDIO_REC_DisplayButtons(void)
{
  BSP_LCD_SetFont(&LCD_LOG_HEADER_FONT);
  BSP_LCD_ClearStringLine(14);            /* Clear dedicated zone */
  BSP_LCD_ClearStringLine(15);           
  BSP_LCD_ClearStringLine(16);
  BSP_LCD_ClearStringLine(17);
  BSP_LCD_ClearStringLine(18);
  BSP_LCD_ClearStringLine(19);
  BSP_LCD_ClearStringLine(20);

  BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
  BSP_LCD_FillCircle((TOUCH_RECORD_XMAX+TOUCH_RECORD_XMIN)/2, /* Record circle */
                     (TOUCH_RECORD_YMAX+TOUCH_RECORD_YMIN)/2,
                     (TOUCH_RECORD_XMAX-TOUCH_RECORD_XMIN)/2);
  BSP_LCD_FillRect(TOUCH_PAUSE_XMIN, TOUCH_PAUSE_YMIN , 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN);    /* Pause rectangles */
  BSP_LCD_FillRect(TOUCH_PAUSE_XMIN + 20, TOUCH_PAUSE_YMIN, 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN);
  BSP_LCD_FillRect(TOUCH_STOP_XMIN, TOUCH_STOP_YMIN , /* Stop rectangle */
                   TOUCH_STOP_XMAX - TOUCH_STOP_XMIN,
                   TOUCH_STOP_YMAX - TOUCH_STOP_YMIN);
  BSP_LCD_DrawRect(TOUCH_VOL_MINUS_XMIN, TOUCH_VOL_MINUS_YMIN , /* VOl- rectangle */
                   TOUCH_VOL_MINUS_XMAX - TOUCH_VOL_MINUS_XMIN,
                   TOUCH_VOL_MINUS_YMAX - TOUCH_VOL_MINUS_YMIN);
  BSP_LCD_DisplayStringAt(26, LINE(17), (uint8_t *)"VOl-", LEFT_MODE);
  BSP_LCD_DrawRect(TOUCH_VOL_PLUS_XMIN, TOUCH_VOL_PLUS_YMIN , /* VOl+ rectangle */
                   TOUCH_VOL_PLUS_XMAX - TOUCH_VOL_PLUS_XMIN,
                   TOUCH_VOL_PLUS_YMAX - TOUCH_VOL_PLUS_YMIN);
  BSP_LCD_DisplayStringAt(506, LINE(17), (uint8_t *)"VOl+", LEFT_MODE);
  BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  BSP_LCD_DisplayStringAtLine(22, (uint8_t *)"Use record button to start record, stop to exit");
  BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
  BSP_LCD_SetFont(&LCD_LOG_TEXT_FONT);
}
Пример #7
0
/**
  * @brief  Clear the Text Zone 
  * @param  None 
  * @retval None
  */
static void LCD_ClearTextZone(void)
{
  uint8_t i = 0;

  for(i = 0; i < 12; i++)
  {
    BSP_LCD_ClearStringLine(i + 3);
  }
}
Пример #8
0
/**
  * @brief  Handles Keyboard Menu.
  * @param  None
  * @retval None
  */
void HID_KeyboardMenuProcess(void)
{
  if(hid_demo.keyboard_state == HID_KEYBOARD_START)
  {
    LCD_LOG_ClearTextZone();
    BSP_LCD_ClearStringLine(19);
    USBH_HID_KeybdInit(&hUSBHost);
    USR_KEYBRD_Init();
  }
}
Пример #9
0
/**
  * @brief  Gets the file info.
  * @param  file_idx: File index
  * @param  info: Pointer to WAV file info
  * @retval Audio error
  */
static AUDIO_ErrorTypeDef GetFileInfo(uint16_t file_idx, WAVE_FormatTypeDef *info)
{
    uint32_t bytesread;
    uint32_t duration;
    uint8_t str[FILEMGR_FILE_NAME_SIZE + 20];

    if(f_open(&WavFile, (char *)FileList.file[file_idx].name, FA_OPEN_EXISTING | FA_READ) == FR_OK)
    {
        /* Fill the buffer to Send */
        if(f_read(&WavFile, info, sizeof(WaveFormat), (void *)&bytesread) == FR_OK)
        {
            BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
            sprintf((char *)str, "Playing file (%d/%d): %s",
                    file_idx + 1, FileList.ptr,
                    (char *)FileList.file[file_idx].name);
            BSP_LCD_ClearStringLine(4);
            BSP_LCD_DisplayStringAtLine(4, str);

            BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
            sprintf((char *)str,  "Sample rate : %d Hz", (int)(info->SampleRate));
            BSP_LCD_ClearStringLine(6);
            BSP_LCD_DisplayStringAtLine(6, str);

            sprintf((char *)str,  "Channels number : %d", info->NbrChannels);
            BSP_LCD_ClearStringLine(7);
            BSP_LCD_DisplayStringAtLine(7, str);

            duration = info->FileSize / info->ByteRate;
            sprintf((char *)str, "File Size : %d KB [%02d:%02d]", (int)(info->FileSize/1024), (int)(duration/60), (int)(duration%60));
            BSP_LCD_ClearStringLine(8);
            BSP_LCD_DisplayStringAtLine(8, str);
            BSP_LCD_DisplayStringAt(263, LINE(8), (uint8_t *)"[00:00]", LEFT_MODE);

            BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
            sprintf((char *)str,  "Volume : %lu", uwVolume);
            BSP_LCD_ClearStringLine(9);
            BSP_LCD_DisplayStringAtLine(9, str);
            return AUDIO_ERROR_NONE;
        }
        f_close(&WavFile);
    }
    return AUDIO_ERROR_IO;
}
Пример #10
0
/**
  * @brief  Gets the file info.
  * @param  file_idx: File index
  * @param  info: Pointer to WAV file info
  * @retval Audio error
  */
static AUDIO_ErrorTypeDef AUDIO_GetFileInfo(uint16_t file_idx, WAV_InfoTypedef *info)
{
  uint8_t str [FILE_NAME_SIZE + 20];  
  uint8_t fname [FILE_NAME_SIZE];    
  uint32_t bytesread;
  uint32_t duration;
  
  if(MTP_GetWavObjectName(file_idx, fname) == 0)
  {
    if(MTP_GetData(file_idx, 
                   0,
                   sizeof(WAV_InfoTypedef), 
                   (uint8_t*)&wav_info,
                   &bytesread) == 0)
    {
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 
      sprintf((char *)str, "Playing file (%d/%d): %s", 
              file_idx + 1, MTP_GetWavObjectNumber(),
              (char *)fname);
      BSP_LCD_ClearStringLine(4);
      BSP_LCD_DisplayStringAtLine(4 ,str);
      
      BSP_LCD_SetTextColor(LCD_COLOR_CYAN); 
      sprintf((char *)str , "Sample rate : %lu Hz", info->SampleRate);
      BSP_LCD_ClearStringLine(6);
      BSP_LCD_DisplayStringAtLine(6 ,str);
      
      sprintf((char *)str , "Channels number : %d", info->NbrChannels);
      BSP_LCD_ClearStringLine(7);      
      BSP_LCD_DisplayStringAtLine(7 ,str);
      
      duration = info->FileSize / info->ByteRate; 
      sprintf((char *)str , "File Size : %lu MB [%02lu:%02lu]", info->FileSize/1024/1024, duration/60, duration%60 );
      BSP_LCD_ClearStringLine(8);
      BSP_LCD_DisplayStringAtLine(8 ,str);
      BSP_LCD_DisplayStringAt(263, LINE(8), (uint8_t *)"[00:00]", LEFT_MODE);
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 
      return AUDIO_ERROR_NONE;
    }
  }
  return AUDIO_ERROR_IO;
}
Пример #11
0
/**
  * @brief  Manages Mouse Menu Process.  
  * @param  None
  * @retval None
  */
void HID_MouseMenuProcess(void)
{
  if(hid_demo.mouse_state == HID_MOUSE_START)
  {
    LCD_LOG_ClearTextZone();
    BSP_LCD_ClearStringLine(19);
    USBH_HID_MouseInit(&hUSBHost);
    USR_MOUSE_Init();
    HID_MOUSE_UpdatePosition(0,0);
  }
}  
Пример #12
0
/**
  * @brief  Clear the Text Zone
  * @param  None
  * @retval None
  */
void LCD_LOG_ClearTextZone(void)
{
  uint8_t i=0;

  for (i= 0 ; i < YWINDOW_SIZE; i++)
  {
    BSP_LCD_ClearStringLine(i + YWINDOW_MIN);
  }

  LCD_LOG_DeInit();
}
Пример #13
0
/**
  * @brief  Manages CDC Menu Process.
  * @param  None
  * @retval None
  */
void CDC_MenuProcess(void)
{
  switch(CdcDemo.state)
  {
  case CDC_DEMO_WAIT:
    if(Appli_state == APPLICATION_READY)
    {
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start sending data ");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_TAMPER) != SET) && (Appli_state != APPLICATION_DISCONNECT))
      {
      }
      CdcDemo.state = CDC_DEMO_SEND;
     
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
      
      BSP_LCD_ClearStringLine(19);
    }
    break;
    
  case CDC_DEMO_SEND:
    /* Read and Write File Here */
    if(Appli_state == APPLICATION_READY)
    {
      CDC_Handle_Send_Menu();
    }
    break; 
    
    case CDC_DEMO_RECEIVE:
    if(Appli_state == APPLICATION_READY)
    {
      CDC_Handle_Receive_Menu();
    }
    break;
    
  default:
    break;
  }
  
  if(Appli_state == APPLICATION_DISCONNECT)
  {
    Appli_state = APPLICATION_IDLE;
    LCD_LOG_ClearTextZone();
    LCD_ErrLog("CDC device disconnected!\n");
    CdcDemo.state = CDC_DEMO_WAIT;
    CdcDemo.Receive_state = CDC_RECEIVE_IDLE;
    CdcDemo.Send_state = CDC_SEND_IDLE;
    CdcDemo.select = 0;
  }
}
Пример #14
0
/**
  * @brief  Manages the DMA FIFO error event.
  * @param  None
  * @retval None
  */
void BSP_AUDIO_OUT_Error_CallBack(void)
{
  /* Display message on the LCD screen */
  BSP_LCD_SetBackColor(LCD_COLOR_RED);
  BSP_LCD_DisplayStringAt(0, LINE(12), (uint8_t *)"       DMA ERROR      ", CENTER_MODE);
  BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  BSP_LCD_ClearStringLine(10);

  /* Stop the program with an infinite loop */
  while (1)
  {}

  /* could also generate a system reset to recover from the error */
  /* .... */
}
Пример #15
0
/**
 * @brief  Check for user input.
 * @param  None
 * @retval Input state (1 : active / 0 : Inactive)
 */
static uint8_t CheckForUserInput(void)
{
  if(BSP_PB_GetState(BUTTON_WAKEUP) == GPIO_PIN_RESET)
  {
    HAL_Delay(10);
    do
    {
      /* Clear previous line */
      BSP_LCD_ClearStringLine(460);

      /* New text to display */
      sprintf(str_display, ">> Frame Nb : %lu", frameCnt);

      /* Print updated frame number */
      BSP_LCD_DisplayStringAt(0, 460, (uint8_t *)str_display, CENTER_MODE);

    } while (BSP_PB_GetState(BUTTON_WAKEUP) == GPIO_PIN_RESET);

    return 1 ;
  }
  return 0;
}
Пример #16
0
/**
  * @brief  Handles CDC Send Menu. 
  * @param  None
  * @retval None
*/
void CDC_Handle_Send_Menu(void)
{
  switch(CdcDemo.Send_state)
  {
  case CDC_SEND_IDLE:
    CdcDemo.Send_state = CDC_SEND_WAIT;
    CDC_SendState = 0;
    USBH_CDC_Stop(&hUSBHost);
    memset(CDC_TX_Buffer, 0x5A, TX_BUFF_SIZE);
    LCD_LOG_ClearTextZone();
    LCD_DbgLog("Sending data ...\n"); 
    USBH_CDC_Transmit(&hUSBHost, CDC_TX_Buffer, TX_BUFF_SIZE);
    break;
  
  case CDC_SEND_WAIT:
    if(CDC_SendState == 1) /* Data sent */
    {
      BSP_LCD_ClearStringLine(19);
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start receiving data ");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_KEY) != SET) && (Appli_state != APPLICATION_DISCONNECT))
      {
      }
      HAL_Delay(400);
      
      CdcDemo.state = CDC_DEMO_RECEIVE;
      CdcDemo.Send_state = CDC_SEND_IDLE;
    }
    break;
    
  default:
    break;
  }
}
Пример #17
0
/**
  * @brief  Notify the User about the nework interface config status 
  * @param  netif: the network interface
  * @retval None
  */
void User_notification(struct netif *netif) 
{
  if (netif_is_up(netif))
 {
#ifdef USE_DHCP
    /* Update DHCP state machine */
    DHCP_state = DHCP_START;
#else
#ifdef USE_LCD
    uint8_t iptxt[20];
    
    sprintf((char*)iptxt, "  %d.%d.%d.%d", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
    
    BSP_LCD_ClearStringLine(7);
    BSP_LCD_ClearStringLine(8);
    BSP_LCD_ClearStringLine(9);
    BSP_LCD_DisplayStringAtLine(8,(uint8_t *) "  Static IP address:");
    BSP_LCD_DisplayStringAtLine(9,(uint8_t *) iptxt);
#else    
    /* Turn On LED 1 to indicate ETH and LwIP init success*/
    BSP_LED_On(LED1);
#endif /* USE_LCD */
#endif /* USE_DHCP */
 }
 else
  {  
#ifdef USE_DHCP
    /* Update DHCP state machine */
    DHCP_state = DHCP_LINK_DOWN;
#endif  /* USE_DHCP */
#ifdef USE_LCD
    BSP_LCD_ClearStringLine(7);
    BSP_LCD_ClearStringLine(8);
    BSP_LCD_ClearStringLine(9);
    BSP_LCD_DisplayStringAtLine(8,(uint8_t *) "  The network cable");
    BSP_LCD_DisplayStringAtLine(9,(uint8_t *) "  is not connected");
#else    
    /* Turn On LED 2 to indicate ETH and LwIP init error */
    BSP_LED_On(LED2);
#endif /* USE_LCD */
  } 
}
Пример #18
0
/**
  * @brief  Saves the picture in microSD.
  * @param  None
  * @retval None
  */
static void Save_Picture(void)
{
  FRESULT res1 = FR_OK;
  FRESULT res2 = FR_OK;
  FRESULT res3 = FR_OK;      /* FatFs function common result code */
  uint32_t byteswritten = 0;     /* File write count */
  uint32_t bmpHeaderByteCnt = 0;
  uint32_t bmpFileInfoHeaderByteCnt = 0;
  uint32_t bmpFilePixelBytesCnt = 0;
  static uint32_t counter = 0;
  uint8_t str[30];
  uint16_t tmp_size;

  /* Check if the SD card is plugged in the slot */
  if(BSP_SD_IsDetected() != SD_PRESENT)
  {
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 20, (uint8_t*)"No SD card detected !!", RIGHT_MODE);
    Error_Handler();
  }
  else
  {
    BSP_LCD_SetFont(&Font16);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 20, (uint8_t*)"Saving BMP to SD card", RIGHT_MODE);

    /* Format the string */
    sprintf((char *)str, "image_%lu.bmp", counter);

    /* -- Prepare Bitmap file (BMP) header */

    bmpFileHeader.bfType = 0x4D42; /* BMP file type */

    /* Offset in bytes from start of file to first pixel data = size in bytes of complete BMP header          */
    /* careful the structure is padded on multiple of 32 bits by the compiler : the Padding should be removed */
    bmpFileHeader.bOffBits = sizeof(BitMapFileHeader_Typedef) +
                         sizeof(BitMapFileInfoHeader_Typedef) - sizeof(uint32_t) - sizeof(uint16_t);

    /* BMP complete file size is size of pad in RGB888 : 24bpp = 3 bytes per pixel + complete header size */
    bmpFileHeader.bfSize = ((BSP_LCD_GetXSize() - 80) * (BSP_LCD_GetYSize() - 80) * RGB888_BYTE_PER_PIXEL);
    bmpFileHeader.bfSize += bmpFileHeader.bOffBits;

    bmpFileHeader.bfReserved1 = 0x0000;
    bmpFileHeader.bfReserved2 = 0x0000;

    bmpFileInfoHeader.biSize = 40; /* 40 bytes in bitmap info header */
    bmpFileInfoHeader.biWidth = (BSP_LCD_GetXSize() - 80);
    bmpFileInfoHeader.biHeight = (BSP_LCD_GetYSize() - 80);
    bmpFileInfoHeader.biPlanes = 1; /* one single plane */
    bmpFileInfoHeader.biBitCount = 24; /* RGB888 : 24 bits per pixel */
    bmpFileInfoHeader.biCompression = 0; /* no compression */

    /* This is number of pixel bytes in file : sizeX * sizeY * RGB888_BYTE_PER_PIXEL */
    bmpFileInfoHeader.biSizeImage = ((BSP_LCD_GetXSize() - 80) * (BSP_LCD_GetYSize() - 80) * RGB888_BYTE_PER_PIXEL);

    bmpFileInfoHeader.biXPelsPerMeter = 0; /* not used */
    bmpFileInfoHeader.biYPelsPerMeter = 0; /* not used */
    bmpFileInfoHeader.biClrUsed = 0; /* not used */
    bmpFileInfoHeader.biClrImportant = 0; /* not used */

    /* -- End Prepare Bitmap file (BMP) header */

    /*##-1- Prepare the image to be saved ####################################*/
    Prepare_Picture();

    /* Disable the LTDC to avoid charging the bandwidth for nothing while the BMP file is */
    /* written to SD card */
    LTDC_Operation(0);

    /*##-2- Create and Open a new bmp file object with write access ##########*/
    if(f_open(&MyFile, (const char*)str, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
    {
      /* 'image.bmp' file Open for write Error */
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 20, (uint8_t*)"     BMP File Creation Error !!", RIGHT_MODE);
      Error_Handler();
    }
    else
    {
      /*##-3- Write data to the BMP file #####################################*/
      /* Write the BMP header step 1 : first write BMP header : all but padding is written to file */
        res1 = f_write(&MyFile, (uint16_t *)&(bmpFileHeader.bfType),
                       sizeof(uint16_t),
                       (void *)&bmpHeaderByteCnt);
        byteswritten += bmpHeaderByteCnt;

        /* LSB of size in bytes of BMP file */
        tmp_size = (uint16_t)(bmpFileHeader.bfSize & 0x0000FFFF);
        res1 = f_write(&MyFile, (uint16_t *)&(tmp_size),
                       sizeof(uint16_t),
                       (void *)&bmpHeaderByteCnt);
        byteswritten += bmpHeaderByteCnt;

        /* MSB of size in bytes of BMP file */
        tmp_size = (uint16_t)((bmpFileHeader.bfSize & 0xFFFF0000) >> 16);
        res1 = f_write(&MyFile, (uint16_t *)&(tmp_size),
                       sizeof(uint16_t),
                       (void *)&bmpHeaderByteCnt);
        byteswritten += bmpHeaderByteCnt;

        res1 = f_write(&MyFile, (uint16_t *)&(bmpFileHeader.bfReserved1),
                       sizeof(uint16_t),
                       (void *)&bmpHeaderByteCnt);
        byteswritten += bmpHeaderByteCnt;

        res1 = f_write(&MyFile, (uint16_t *)&(bmpFileHeader.bfReserved2),
                       sizeof(uint16_t),
                       (void *)&bmpHeaderByteCnt);
        byteswritten += bmpHeaderByteCnt;

        res1 = f_write(&MyFile, (uint32_t *)&(bmpFileHeader.bOffBits),
                       sizeof(uint32_t),
                       (void *)&bmpHeaderByteCnt);
        byteswritten += bmpHeaderByteCnt;

      if(res1 != FR_OK)
      {
      /* Reactivate LTDC */
        LTDC_Operation(1);
        f_close(&MyFile);
        BSP_LCD_ClearStringLine(BSP_LCD_GetYSize() - 20);
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 20, (uint8_t*)"     BMP File Header Saving Error !!", RIGHT_MODE);
        Error_Handler();
      }

      byteswritten += bmpHeaderByteCnt;

      if(res1 == FR_OK)
      {
        /* Write the BMP header step 2 : second write BMP file info header */
        res2 = f_write(&MyFile, (BitMapFileInfoHeader_Typedef *)&bmpFileInfoHeader,
                       sizeof(BitMapFileInfoHeader_Typedef),
                       (void *)&bmpFileInfoHeaderByteCnt);


          if(res2 != FR_OK)
          {
            /* Reactivate LTDC */
            LTDC_Operation(1);
            f_close(&MyFile);
            BSP_LCD_ClearStringLine(BSP_LCD_GetYSize() - 20);
            BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 20, (uint8_t*)"     BMP File Header Info Saving Error !!", RIGHT_MODE);
            Error_Handler();
          }
      }

      byteswritten += bmpFileInfoHeaderByteCnt;

      if((res1 == FR_OK) && (res2 == FR_OK))
      {
        /* Write pixel data in the the BMP file */
        res3 = f_write(&MyFile, (uint8_t *)p_bmp_converted_pixel_data,
                       bmpFileInfoHeader.biSizeImage,
                       (void *)&bmpFilePixelBytesCnt);

          /* Reactivate LTDC */
          LTDC_Operation(1);

        if(res3 != FR_OK)
        {
          if(res3 == FR_DISK_ERR)
          {
              f_close(&MyFile);
              BSP_LCD_ClearStringLine(BSP_LCD_GetYSize() - 20);
              BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 20, (uint8_t*)"     File Saving Error DISKERR !!", RIGHT_MODE);
          }

          Error_Handler();
        }

      }

      byteswritten += bmpFilePixelBytesCnt;

      if((res1 != FR_OK) || (res2 != FR_OK) || (res3 != FR_OK) || (byteswritten == 0))
      {
        /* 'image.bmp' file Write or EOF Error */
        BSP_LCD_ClearStringLine(BSP_LCD_GetYSize() - 20);
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 20, (uint8_t*)"     BMP File Saving Error !!", RIGHT_MODE);
        Error_Handler();
      }
      else
      {
        /*##-4- Close the open BMP file ######################################*/
        f_close(&MyFile);

        /* Success of the demo: no error occurrence */
        BSP_LED_On(LED1);

        BSP_LCD_ClearStringLine(BSP_LCD_GetYSize() - 20);
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 20, (uint8_t*)"             BMP File Saved.", RIGHT_MODE);

        /* Wait for 2s */
        HAL_Delay(2000);

        BSP_LCD_ClearStringLine(BSP_LCD_GetYSize() - 20);

        /* Select Layer 1 */
        BSP_LED_Off(LED1);
        counter++;
      }
    }
  }
}
Пример #19
0
/**
 * @brief  Main program
 * @param  None
 * @retval None
 */
int main(void)
{
  uint8_t  lcd_status = LCD_OK;

  /* This sample code displays a fixed image 800x480 on LCD KoD in */
  /* orientation mode landscape and DSI mode video burst           */

  /* 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();

  /* Initialize used LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /* Configure user push-button */
  BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_GPIO);
  
  /* Initialize the LCD DSI in Video Burst mode with LANDSCAPE orientation */
  lcd_status = BSP_LCD_Init();
  OnError_Handler(lcd_status != LCD_OK);
  
  /* Program a line event at line 0 */
  HAL_LTDC_ProgramLineEvent(&hltdc_eval, 0);  
  
  /* Copy texture to be displayed on LCD from Flash to SDRAM */
  CopyPicture((uint32_t *)&candies_800x480_argb8888, (uint32_t *)LCD_FB_START_ADDRESS, 0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
  
  BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER_BACKGROUND, LCD_FB_START_ADDRESS);
  BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_BACKGROUND);
  
  /* Prepare area to display frame number in the image displayed on LCD */
  BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  BSP_LCD_FillRect(0, 400, BSP_LCD_GetXSize(), 80);
  BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  BSP_LCD_SetFont(&Font16);
  
  /* Display title */
  BSP_LCD_DisplayStringAt(0, 420, (uint8_t *) "LCD_DSI_ULPM_Data example", CENTER_MODE);
  BSP_LCD_DisplayStringAt(0, 440, (uint8_t *) "Press TAMPER button to enter ULPM", CENTER_MODE);
  
  BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  BSP_LCD_SetFont(&Font16);
  
  /* Infinite loop */
  while (1)
  {
    /* Clear previous line */
    BSP_LCD_ClearStringLine(460);
    
    /* New text to display */
    sprintf(str_display, ">> Frame Nb : %lu", frameCnt);
    
    /* Print updated frame number */
    BSP_LCD_DisplayStringAt(0, 460, (uint8_t *)str_display, CENTER_MODE);
    
    if (CheckForUserInput() > 0)
    {
      /* Clear previous line */
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_ClearStringLine(440);
      BSP_LCD_DisplayStringAt(0, 440, (uint8_t *) "Enter ULPM - switch Off LCD 6 seconds", CENTER_MODE);
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
      
      /* Display Off with ULPM management Data lane only integrated */
      BSP_LCD_DisplayOff();
      HAL_Delay(1000); 
      
      /* Switch Off bit LTDCEN */
      __HAL_LTDC_DISABLE(&hltdc_eval); 
      
      /* Enter ultra low power mode (data lane only integrated) */
      HAL_DSI_EnterULPMData(&hdsi_eval);
      BSP_LED_On(LED1);
      
      HAL_Delay(6000);
      
      BSP_LCD_ClearStringLine(440);
      BSP_LCD_DisplayStringAt(0, 440, (uint8_t *) " Exited ULPM with success - Press To enter Again ULPM. ", CENTER_MODE);
      
      /* Exit ultra low power mode (data lane only integrated) */
      HAL_DSI_ExitULPMData(&hdsi_eval);
      BSP_LED_Off(LED1);
      
      /* Switch On bit LTDCEN */
      __HAL_LTDC_ENABLE(&hltdc_eval); 
      
      /* Display On with ULPM exit Data lane only integrated */
      BSP_LCD_DisplayOn();          
    }
  }
}
Пример #20
0
/**
  * @brief  Manages HID Menu Process.
  * @param  None
  * @retval None
  */
void HID_MenuProcess(void)
{
  switch(hid_demo.state)
  {
  case HID_DEMO_START:
    if(Appli_state == APPLICATION_HID)
    {
      if(USBH_HID_GetDeviceType(&hUSBHost) == HID_KEYBOARD)
      {
        hid_demo.keyboard_state = HID_KEYBOARD_IDLE; 
        hid_demo.state = HID_DEMO_KEYBOARD;
        BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
        BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start");
        
        /* Wait for User Input */
        while((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT))
        {
        }
        BSP_LCD_ClearStringLine(19);
        
        HID_KeyboardMenuProcess();
      }
      else if(USBH_HID_GetDeviceType(&hUSBHost) == HID_MOUSE)
      {
        hid_demo.mouse_state = HID_MOUSE_IDLE;
        hid_demo.state = HID_DEMO_MOUSE;
        
        BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
        BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start");
        
        /* Wait for User Input */
        while((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT))
        {
        }
        BSP_LCD_ClearStringLine(19);
        
        HID_MouseMenuProcess();
      }
    }
    else
    {
      LCD_ErrLog("No supported HID device!\n");
      hid_demo.state = HID_DEMO_START;
    }
    break;
    
  case HID_DEMO_MOUSE:
    if( Appli_state == APPLICATION_HID)
    {
      USBH_MouseDemo(&hUSBHost);
    }
    break; 
    
  case HID_DEMO_KEYBOARD:
    if( Appli_state == APPLICATION_HID)  
    {
      USBH_KeybdDemo(&hUSBHost);
    }   
    break;
    
  default:
    break;
  }
}
Пример #21
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint8_t  lcd_status = LCD_OK;
  mfx_toggle_led = 0;
  CameraResX = 320;
  CameraResY = 240;
  LcdResX    = 800; /* WVGA landscape */
  LcdResY    = 480;
  offset_cam = 0;
  offset_lcd = 0;
  display_line_counter = 0;
  lcd_frame_buffer_ready = 0;
  start_the_camera_capture = 0;
  end_the_camera_capture = 0;

  /* 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();

  /* Initialize MFX */
  BSP_IO_Init();
  
  /* Initialize used Leds */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);

  /*##-1- Initialise the LCD #################################################*/

  /* Initialize and start the LCD display in mode LCD_MODE_ADAPTED_COMMAND_TE_DSI_LINK
   * and orientation mode LCD_ORIENTATION_LANDSCAPE, using LCD_FRAME_BUFFER
   * as LCD frame buffer address.
   */
  BSP_LCD_Init();
  BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);   
  OnError_Handler(lcd_status != LCD_OK);

  /* Prepare using DMA2D the 800x480 LCD frame buffer to display background color black */
  /* and title of the example                                                           */
  BSP_LCD_Clear(LCD_COLOR_BLACK);
  BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  BSP_LCD_SetFont(&Font16);

  /* Print example description */
  BSP_LCD_DisplayStringAt(0, 440, (uint8_t *)"DCMI Snapshot example", CENTER_MODE);
  BSP_LCD_DisplayStringAt(0, 460, (uint8_t *)"Initialize Camera", CENTER_MODE);

  /* Initialize the camera frame buffer 320x240 in RGB565 to a fixed grey pattern */
  lcd_status = CameraFrameBufferRgb565_Init(CameraResX, CameraResY, 0x55555555);
  OnError_Handler(lcd_status != LCD_OK);

  /*##-2- Camera Initialization and start capture ############################*/
  /* Initialize the Camera in QVGA mode */
  BSP_CAMERA_Init(CAMERA_R320x240);

  /* Wait 1s to let auto-loops in the camera module converge and lead to correct exposure */
  HAL_Delay(1000);

  /* Start the Camera Snapshot Capture */
  BSP_CAMERA_SnapshotStart((uint8_t *)CAMERA_FRAME_BUFFER);

  /* Wait until LCD frame buffer is ready */
  while(lcd_frame_buffer_ready == 0) {;}

  /* Stop the camera to avoid having the DMA2D work in parallel of Display */
  /* which cause perturbation of LTDC                                      */
  BSP_CAMERA_Stop();

  BSP_LCD_ClearStringLine(460);
  BSP_LCD_DisplayStringAt(0, 460, (uint8_t *)"Capture OK - Test End", CENTER_MODE);
  
  /* Notify Test OK */
  BSP_LED_On(LED1);

  while (1)
  {
    if ( mfx_toggle_led == 1)
    {
      BSP_LED_Toggle(LED3);
      mfx_toggle_led = 0;
    }
  }
}
/**
  * @brief  DHCP Process
* @param  argument: network interface
  * @retval None
  */
void DHCP_thread(void const * argument)
{
  struct netif *netif = (struct netif *) argument;
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;
  uint32_t IPaddress;
  
  for (;;)
  {
    switch (DHCP_state)
    {
    case DHCP_START:
      {
        netif->ip_addr.addr = 0;
        netif->netmask.addr = 0;
        netif->gw.addr = 0;
        IPaddress = 0;
        dhcp_start(netif);
        DHCP_state = DHCP_WAIT_ADDRESS;
#ifdef USE_LCD
        BSP_LCD_ClearStringLine(7);
        BSP_LCD_ClearStringLine(8);
        BSP_LCD_ClearStringLine(9);
        BSP_LCD_DisplayStringAtLine(8,(uint8_t *) "  Looking for");
        BSP_LCD_DisplayStringAtLine(9,(uint8_t *) "  DHCP sever ...");
#endif
      }
      break;
      
    case DHCP_WAIT_ADDRESS:
      {        
        /* Read the new IP address */
        IPaddress = netif->ip_addr.addr;
        
        if (IPaddress!=0) 
        {
          DHCP_state = DHCP_ADDRESS_ASSIGNED;	
          
          /* Stop DHCP */
          dhcp_stop(netif);
          
#ifdef USE_LCD 
        uint8_t iptab[4];
        uint8_t iptxt[20];
  
        iptab[0] = (uint8_t)(IPaddress >> 24);
        iptab[1] = (uint8_t)(IPaddress >> 16);
        iptab[2] = (uint8_t)(IPaddress >> 8);
        iptab[3] = (uint8_t)(IPaddress);

        sprintf((char*)iptxt, "  %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);       
        
        BSP_LCD_ClearStringLine(7);
        BSP_LCD_ClearStringLine(8);
        BSP_LCD_ClearStringLine(9);
        BSP_LCD_DisplayStringAtLine(7,(uint8_t *) "  IP address assigned");
        BSP_LCD_DisplayStringAtLine(8,(uint8_t *) "  by a DHCP server:");
        BSP_LCD_DisplayStringAtLine(9,(uint8_t *) iptxt);
#else
     BSP_LED_On(LED1);   
#endif 
        }
        else
        {
          /* DHCP timeout */
          if (netif->dhcp->tries > MAX_DHCP_TRIES)
          {
            DHCP_state = DHCP_TIMEOUT;
            
            /* Stop DHCP */
            dhcp_stop(netif);
            
            /* Static address used */
            IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
            IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
            IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
            netif_set_addr(netif, &ipaddr , &netmask, &gw);
            
#ifdef USE_LCD  
          uint8_t iptxt[20];
          
          sprintf((char*)iptxt, "  %d.%d.%d.%d", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);

          BSP_LCD_ClearStringLine(7);
          BSP_LCD_ClearStringLine(8);
          BSP_LCD_ClearStringLine(9);
          BSP_LCD_DisplayStringAtLine(7,(uint8_t *) "  DHCP timeout !!");
          BSP_LCD_DisplayStringAtLine(8,(uint8_t *) "  Static IP address  :");
          BSP_LCD_DisplayStringAtLine(9,(uint8_t *) iptxt);
#else
     BSP_LED_On(LED1);  
#endif
          }
        }
      }
      break;
      
    default: break;
    }
/**
  * @brief  This function notify user about link status changement.
  * @param  netif: the network interface
  * @retval None
  */
void ethernetif_notify_conn_changed(struct netif *netif)
{
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;

  if(netif_is_link_up(netif))
  {
#ifdef USE_DHCP
#ifndef USE_LCD
    BSP_LED_Off(LED2);
    BSP_LED_On(LED1);
#endif /* USE_LCD */
    /* Update DHCP state machine */
    DHCP_state = DHCP_START;
#else
    IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
    IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
    IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);    

#ifdef USE_LCD        
    uint8_t iptxt[20];

    sprintf((char*)iptxt, "  %d.%d.%d.%d", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
    BSP_LCD_ClearStringLine(7);
    BSP_LCD_ClearStringLine(8);
    BSP_LCD_ClearStringLine(9);
    BSP_LCD_DisplayStringAtLine(8,(uint8_t *) "  Static IP address:");
    BSP_LCD_DisplayStringAtLine(9,(uint8_t *) iptxt);
#else
    BSP_LED_Off(LED2);
    BSP_LED_On(LED1);
#endif /* USE_LCD */
#endif /* USE_DHCP */   
    
    netif_set_addr(netif, &ipaddr , &netmask, &gw);
    
    /* When the netif is fully configured this function must be called.*/
    netif_set_up(netif);     
  }
  else
  {
#ifdef USE_DHCP
    /* Update DHCP state machine */
    DHCP_state = DHCP_LINK_DOWN;
#endif /* USE_DHCP */
    
    /*  When the netif link is down this function must be called.*/
    netif_set_down(netif);
    
#ifdef USE_LCD
    BSP_LCD_ClearStringLine(7);
    BSP_LCD_ClearStringLine(8);
    BSP_LCD_ClearStringLine(9);
    BSP_LCD_DisplayStringAtLine(8,(uint8_t *) "  The network cable");
    BSP_LCD_DisplayStringAtLine(9,(uint8_t *) "  is not connected");
#else
    BSP_LED_Off(LED1);
    BSP_LED_On(LED2);
#endif /* USE_LCD */    
  }
  
  /* Clear IO Expander Interrupt flag */
  BSP_IO_ITClear();
}
Пример #24
0
/**
  * @brief  Manages MSC Menu Process.
  * @param  None
  * @retval None
  */
void MSC_MenuProcess(void)
{
  switch(msc_demo.state)
  {
  case MSC_DEMO_START:
    if(Appli_state == APPLICATION_MSC)
    {
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start read and write operations");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_TAMPER) != SET) && (Appli_state != APPLICATION_DISCONNECT))
      {
      }
      msc_demo.state = MSC_DEMO_FILE_OPERATIONS;
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
      
      BSP_LCD_ClearStringLine(19);
    }
    break;
    
  case MSC_DEMO_FILE_OPERATIONS:  
    /* Read and Write File Here */
    if(Appli_state == APPLICATION_MSC)
    {
      MSC_File_Operations();
      
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to display disk content");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_TAMPER) != SET) && (Appli_state != APPLICATION_DISCONNECT))
      {
      }
      msc_demo.state = MSC_DEMO_EXPLORER;
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
      
      BSP_LCD_ClearStringLine(19);
    }
    break; 
    
  case MSC_DEMO_EXPLORER:
    /* Display disk content */
    if(Appli_state == APPLICATION_MSC)
    {
      /* Register the file system object to the FatFs module */
      if(f_mount(&USBH_fatfs, "", 0 ) != FR_OK )
      {
        LCD_ErrLog("Cannot Initialize FatFs! \n");
      }
      else
      {
        Explore_Disk("0:/", 1);
        msc_demo.state = MSC_DEMO_START;
        
        /* Prevent debounce effect for user key */
        HAL_Delay(400);
      }
    }
    break;

  default:
    break;
  }
} 
Пример #25
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 LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /* Turn LED1 on */
  BSP_LED_On(LED1);
  
#ifdef USE_LCD 
  BSP_LCD_Init();
  BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS);
  BSP_LCD_SelectLayer(1);
    
  BSP_LCD_Clear(LCD_COLOR_WHITE);
  
  BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  BSP_LCD_ClearStringLine(0);
  BSP_LCD_DisplayStringAtLine(0, (uint8_t*)"       TimeStamp Example     ");
#endif /* USE_LCD */

  /*##-1- Configure the RTC peripheral #######################################*/
  RtcHandle.Instance = RTC;

  /* Configure RTC prescaler and RTC data registers */
  /* RTC configured as follow:
  - Hour Format    = Format 12
  - Asynch Prediv  = Value according to source clock
  - Synch Prediv   = Value according to source clock
  - OutPut         = Output Disable
  - OutPutPolarity = High Polarity
  - OutPutType     = Open Drain */ 
  RtcHandle.Init.HourFormat = RTC_HOURFORMAT_12;
  RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
  RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
  RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
  RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  
  if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  }

  /*##-2- Configure RTC TimeStamp#############################################*/
  RTC_TimeStampConfig();
  
  /* Infinite loop */  
  while (1)
  {
    /*##-3- Display the updated Time and Date ################################*/
    RTC_CalendarShow();
  }
}
Пример #26
0
/**
  * @brief  Manages AUDIO Menu Process.
  * @param  None
  * @retval None
  */
void AUDIO_MenuProcess(void)
{
  AUDIO_ErrorTypeDef  status;
  TS_StateTypeDef  TS_State;
  Point PlaybackLogoPoints[] = {{TOUCH_PLAYBACK_XMIN, TOUCH_PLAYBACK_YMIN},
                                {TOUCH_PLAYBACK_XMAX, (TOUCH_PLAYBACK_YMIN+TOUCH_PLAYBACK_YMAX)/2},
                                {TOUCH_PLAYBACK_XMIN, TOUCH_PLAYBACK_YMAX}};
  
  if(appli_state == APPLICATION_READY)
  { 
    switch(AudioDemo.state)
    {
    case AUDIO_DEMO_IDLE:
      if(AUDIO_ShowWavFiles() > 0)
      {
        LCD_ErrLog("There is no WAV file on the USB Key.\n");         
        AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); 
        AudioDemo.state = AUDIO_DEMO_IDLE;
      }
      else
      {
        AudioDemo.state = AUDIO_DEMO_WAIT;
      }
      
      BSP_LCD_SetFont(&LCD_LOG_HEADER_FONT);
      BSP_LCD_ClearStringLine(13);     /* Clear touch screen buttons dedicated zone */
      BSP_LCD_ClearStringLine(14);
      BSP_LCD_ClearStringLine(15);
      BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
      BSP_LCD_FillPolygon(PlaybackLogoPoints, 3);                 /* Playback sign */
      BSP_LCD_FillCircle((TOUCH_RECORD_XMAX+TOUCH_RECORD_XMIN)/2, /* Record circle */
                         (TOUCH_RECORD_YMAX+TOUCH_RECORD_YMIN)/2,
                         (TOUCH_RECORD_XMAX-TOUCH_RECORD_XMIN)/2);
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_SetFont(&LCD_LOG_TEXT_FONT);
      BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"Use touch screen to enter playback or record menu");
      break;    
      
    case AUDIO_DEMO_WAIT:

      BSP_TS_GetState(&TS_State);
      if(TS_State.touchDetected == 1)
      {
        if ((TS_State.touchX[0] > TOUCH_RECORD_XMIN) && (TS_State.touchX[0] < TOUCH_RECORD_XMAX) &&
            (TS_State.touchY[0] > TOUCH_RECORD_YMIN) && (TS_State.touchY[0] < TOUCH_RECORD_YMAX))
        {
          AudioDemo.state = AUDIO_DEMO_IN;
        }
        else if ((TS_State.touchX[0] > TOUCH_PLAYBACK_XMIN) && (TS_State.touchX[0] < TOUCH_PLAYBACK_XMAX) &&
                 (TS_State.touchY[0] > TOUCH_PLAYBACK_YMIN) && (TS_State.touchY[0] < TOUCH_PLAYBACK_YMAX))
        {
          AudioDemo.state = AUDIO_DEMO_PLAYBACK;
        }
        else
        {
          AudioDemo.state = AUDIO_DEMO_EXPLORE;
        }

        /* Wait for touch released */
        do
        {
          BSP_TS_GetState(&TS_State);
        }while(TS_State.touchDetected > 0);
      }
      break;
      
    case AUDIO_DEMO_EXPLORE: 
      if(appli_state == APPLICATION_READY)
      {
        if(AUDIO_ShowWavFiles() > 0)
        {
          LCD_ErrLog("There is no WAV file on the USB Key.\n");         
          AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); 
          AudioDemo.state = AUDIO_DEMO_IDLE;
        }
        else
        {
          AudioDemo.state = AUDIO_DEMO_WAIT;
        }
      }
      else
      {
        AudioDemo.state = AUDIO_DEMO_WAIT;
      }
      break;
      
    case AUDIO_DEMO_PLAYBACK:
      if(appli_state == APPLICATION_READY)
      {
        if(AudioState == AUDIO_STATE_IDLE)
        {
          /* Start Playing */
          AudioState = AUDIO_STATE_INIT;

          /* Clear the LCD */
          LCD_ClearTextZone();

          if(AUDIO_PLAYER_Start(0) == AUDIO_ERROR_IO)
          {
            AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); 
            AudioDemo.state = AUDIO_DEMO_IDLE;
          }
        }
        else /* Not idle */
        {
          if(AUDIO_PLAYER_Process() == AUDIO_ERROR_IO)
          {
            /* Clear the LCD */
            LCD_ClearTextZone();

            AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);  
            AudioDemo.state = AUDIO_DEMO_IDLE;
          }
        }
      }
      else
      {
        AudioDemo.state = AUDIO_DEMO_WAIT;
      }
      break; 
      
    case AUDIO_DEMO_IN:
      if(appli_state == APPLICATION_READY)
      {
        if(AudioState == AUDIO_STATE_IDLE)
        {
          /* Start Playing */
          AudioState = AUDIO_STATE_INIT;

          /* Clear the LCD */
          LCD_ClearTextZone();

          /* Configure the audio recorder: sampling frequency, bits-depth, number of channels */
          if(AUDIO_REC_Start() == AUDIO_ERROR_IO)
          {
            AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); 
            AudioDemo.state = AUDIO_DEMO_IDLE;
          }
        }
        else /* Not idle */
        {
          status = AUDIO_REC_Process();
          if((status == AUDIO_ERROR_IO) || (status == AUDIO_ERROR_EOF))
          {
            /* Clear the LCD */
            LCD_ClearTextZone();

            AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU);  
            AudioDemo.state = AUDIO_DEMO_IDLE;
          }
        }
      }
      else
      {
        AudioDemo.state = AUDIO_DEMO_WAIT;
      }
      break;
      
    default:
      break;
    }
  }
  
  if(appli_state == APPLICATION_DISCONNECT)
  {
    appli_state = APPLICATION_IDLE;     
    AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); 
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);    
  }
}
Пример #27
0
/**
  * @brief  Manages HID Menu Process.
  * @param  None
  * @retval None
  */
void HID_MenuProcess(void)
{
  switch(demo.hid_state)
  {
  case APPLI_HID_START:
    if(Appli_FS_state == APPLICATION_FS_READY)
    {
      if(USBH_HID_GetDeviceType(&hUSBHost_FS) == HID_KEYBOARD)
      {
        demo.keyboard_state = HID_KEYBOARD_IDLE; 
        demo.hid_state = APPLI_HID_KEYBOARD;
        
        BSP_LCD_ClearStringLine(19);
        BSP_LCD_ClearStringLine(20);
        BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
        BSP_LCD_DisplayStringAtLine(20, (uint8_t *)"Press User button to exit");
        HID_KeyboardMenuProcess();
      }
      else if(USBH_HID_GetDeviceType(&hUSBHost_FS) == HID_MOUSE)
      {
        demo.mouse_state = HID_MOUSE_IDLE;  
        demo.hid_state = APPLI_HID_MOUSE;
        
        BSP_LCD_ClearStringLine(19);
        BSP_LCD_ClearStringLine(20);
        BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
        BSP_LCD_DisplayStringAtLine(20, (uint8_t *)"Press User button to exit");
        
        HID_MouseMenuProcess();        
      }
    }
    else
    {
      LCD_ErrLog("No supported HID device!\n");
      demo.hid_state = APPLI_HID_START;
    }
    break;
    
  case APPLI_HID_MOUSE:
    if(Appli_FS_state == APPLICATION_FS_READY)
    {
      USBH_MouseDemo(&hUSBHost_FS);
      
      if(BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET)
      {
        demo.hid_state = APPLI_HID_START;
        demo.state = DEMO_IDLE;
      }
    }
    break; 
    
  case APPLI_HID_KEYBOARD:
    if(Appli_FS_state == APPLICATION_FS_READY)
    {
      USBH_KeybdDemo(&hUSBHost_FS);
      
      if(BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET)
      {
        demo.hid_state = APPLI_HID_START;
        demo.state = DEMO_IDLE;
      }
    }
    break;
    
  default:
    break;
  } 
}
Пример #28
0
/*
    Conditions:
      9
    Exit points:
      0
    M = 9 - 0 + 2 = 11
    Cyclomatic complexity
      11
  */
void Fingerprint_Task(void* arg)
{
  //TickType_t lastWake = 0;
  Packet_t packet, response;
  uint32_t i = 0;

  UNUSED_ARG(arg);

  InitLCD();
  InitUART();

  BSP_LCD_Clear(LCD_COLOR_WHITE);
  BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);

  gt511_startup();

  response.Data = NULL;
  response.Length = 0;
  packet.Data = NULL;
  packet.Length = 0;

  //*
  //fp_test();
  // */

  while (1)
  {
    BSP_LCD_ClearStringLine(2);
    BSP_LCD_DisplayStringAtLine(2, (uint8_t*)"Waiting on PC");

    i = 0;

    while (xQueueReceive(ctrlDataQueue.Rx, &packet, 500) != pdTRUE)
    {
      i += 1;

      BSP_LCD_ClearStringLine(2);

      switch (i & 3)
      {
        default:
        case 0:
          BSP_LCD_DisplayStringAtLine(2, (uint8_t*)"Waiting on PC");
          break;
        case 1:
          BSP_LCD_DisplayStringAtLine(2, (uint8_t*)"Waiting on PC.");
          break;
        case 2:
          BSP_LCD_DisplayStringAtLine(2, (uint8_t*)"Waiting on PC..");
          break;
        case 3:
          BSP_LCD_DisplayStringAtLine(2, (uint8_t*)"Waiting on PC...");
          break;
      }
    }

    fp_handle_packet(&packet, &response);

    if (response.Data != NULL)
      while (xQueueSendToBack(ctrlDataQueue.Tx, &response, -1) != pdTRUE);

    packet_free(&packet);

    response.Data = NULL;
    response.Length = 0;
    packet.Data = NULL;
    packet.Length = 0;

    BSP_LCD_Clear(LCD_COLOR_WHITE);
  }
}
Пример #29
0
/**
  * @brief  Manages MSC Menu Process.
  * @param  None
  * @retval None
  */
void MSC_MenuProcess(void)
{
  switch(demo.msc_state)
  {  
  case APPLI_MSC_START:
    if(Appli_HS_state == APPLICATION_HS_READY)
    {
      BSP_LCD_ClearStringLine(19);
      BSP_LCD_ClearStringLine(20);
       
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start read and write operations");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_TAMPER) != SET) && (Appli_HS_state != APPLICATION_HS_DISCONNECT))
      {
      }
      demo.msc_state = APPLI_MSC_FILE_OPERATIONS;
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
      
      BSP_LCD_ClearStringLine(19);
    }
    break;
    
  case APPLI_MSC_FILE_OPERATIONS:  
    /* Read and Write File Here */
    if(Appli_HS_state == APPLICATION_HS_READY)
    {
      MSC_File_Operations();
      
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to display disk content");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_TAMPER) != SET) && (Appli_HS_state != APPLICATION_HS_DISCONNECT))
      {
      }
      demo.msc_state = APPLI_MSC_EXPLORER;
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
      
      BSP_LCD_ClearStringLine(19);
    }
    break; 
    
  case APPLI_MSC_EXPLORER:
    /* Display disk content */
    if(Appli_HS_state == APPLICATION_HS_READY)
    {        
      Explore_Disk("0:/", 1);
      demo.msc_state = APPLI_MSC_START;
      demo.state = DEMO_IDLE;
      
      BSP_LCD_ClearStringLine(19);
      BSP_LCD_ClearStringLine(20);
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(20, (uint8_t *)"Press User button to exit");
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_TAMPER) != SET) && (Appli_HS_state != APPLICATION_HS_DISCONNECT))
      {
      }
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
    }
    break; 
    
  default:
    break;
  }
} 
Пример #30
0
/**
  * @brief  Manages MSC Menu Process.
  * @param  None
  * @retval None
  */
void MSC_MenuProcess(void)
{
  switch(msc_demo.state)
  {
  case MSC_DEMO_START:
    if(Appli_state == APPLICATION_READY)
    {
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start read and write operations");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT))
      {
      }
      msc_demo.state = MSC_DEMO_FILE_OPERATIONS;
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
      
      BSP_LCD_ClearStringLine(19);
    }
    break;
    
  case MSC_DEMO_FILE_OPERATIONS:
    /* Read and Write File Here */
    if(Appli_state == APPLICATION_READY)
    {
      MSC_File_Operations();
      
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to display disk content");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT))
      {
      }
      msc_demo.state = MSC_DEMO_EXPLORER;
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
      
      BSP_LCD_ClearStringLine(19);
    }
    break; 
    
  case MSC_DEMO_EXPLORER:
    /* Display disk content */
    if(Appli_state == APPLICATION_READY)
    {
      Explore_Disk("0:/", 1);
      msc_demo.state = MSC_DEMO_START;
      
      /* Prevent debounce effect for user key */
      HAL_Delay(400);
    }
    break;
    
  default:
    break;
  }
  
  if(Appli_state == APPLICATION_DISCONNECT)
  {
    Appli_state = APPLICATION_IDLE;
    LCD_LOG_ClearTextZone();
    LCD_ErrLog("MSC device disconnected!\n");
    msc_demo.state = MSC_DEMO_START;
    msc_demo.select = 0;
  }
}