示例#1
0
/**
  * @brief  Joystick demo
  * @param  None
  * @retval None
  */
void Joystick_demo (void)
{ 
  static uint16_t xPtr = 12;
  static uint16_t yPtr = 92;
  static uint16_t old_xPtr = 12;
  static uint16_t old_yPtr = 92;  

  Joystick_SetHint();
  
  BSP_JOY_Init(JOY_MODE_GPIO);
  
  while (1)
  {
    /* Get the Joystick State */
    JoyState = BSP_JOY_GetState();
    
    switch(JoyState)
    {
    case JOY_UP:
      if(yPtr > 92)
      {
        yPtr--;
      }
      break;     
    case JOY_DOWN:
        if(yPtr < (BSP_LCD_GetYSize() - 12 - 11))
      {
        yPtr++;
      }
      break;          
    case JOY_LEFT:
      if(xPtr > 12)
      {
        xPtr--;
      }
      break;         
    case JOY_RIGHT:
        if(xPtr < (BSP_LCD_GetXSize() - 8 - 11))
      {
        xPtr++;
      }
      break;                 
    default:
      break;           
    }
    
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
    
    if(JoyState == JOY_SEL)
    {
      BSP_LCD_SetTextColor(LCD_COLOR_RED);
      BSP_LCD_DisplayChar(xPtr, yPtr, 'X');
      
    }
    else if(JoyState == JOY_NONE)
    {
      BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
      BSP_LCD_DisplayChar(xPtr, yPtr, 'X');   
    }
    else
    {
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
      BSP_LCD_DisplayChar(old_xPtr, old_yPtr, 'X');
      BSP_LCD_SetTextColor(LCD_COLOR_BLUE); 
      BSP_LCD_DisplayChar(xPtr, yPtr, 'X');
      
      old_xPtr = xPtr;
      old_yPtr = yPtr;
    }
    if(CheckForUserInput() > 0)
    {
      return;
    }
    HAL_Delay(5);
  }
}
示例#2
0
/**
  * @brief  Audio Play demo
  * @param  None
  * @retval None
  */
void AudioRec_demo (void)
{
  uint16_t NbRecord_done = 0;
  uint8_t FreqStr[256] = {0};
  AudioRec_State = REC_NONE_STATE;
  buffer_ctl.rec_length = 0;
  /* Initialize AudioRecFullBuff at the address of the audio_play reader */

  AudioRecFullBuff_addr = AUDIO_REC_START_ADDR;

  AudioRec_SetHint();

#ifdef JOYSTICK

  /* Initialize Joystick */
  if (BSP_JOY_Init(JOY_MODE_GPIO) != IO_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 *)"Joystick cannot be initialized", CENTER_MODE);
  }
#endif

  /* Initialize Audio Recorder */
  if (BSP_AUDIO_IN_Init(DEFAULT_AUDIO_IN_FREQ, DEFAULT_AUDIO_IN_BIT_RESOLUTION, DEFAULT_AUDIO_IN_CHANNEL_NBR) == AUDIO_OK)
  {
    AudioRec_State = REC_RESET_STATE;
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 95, (uint8_t *)"  AUDIO RECORD INIT OK  ", CENTER_MODE);
  }
  else
  {
    AudioRec_State = REC_ERROR_STATE;
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 95, (uint8_t *)"  AUDIO RECORD INIT FAIL", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 80, (uint8_t *)"  Try to reset board ", CENTER_MODE);
  }
  
  /* Infinite loop */
  while (buffer_ctl.rec_length < AUDIO_REC_TOTAL_SIZE)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_BLUE);

    if (buffer_ctl.it_state == TRANSFER_HALF)
    {
      /* PDM to PCM data convert */
      BSP_AUDIO_IN_PDMToPCM((uint16_t*)&buffer_ctl.pdm_buff[0],
                            &buffer_ctl.pcm_buff[buffer_ctl.pcm_ptr]);

      buffer_ctl.pcm_ptr+= AUDIO_IN_PDM_BUFFER_SIZE/4/2;

      if(buffer_ctl.pcm_ptr == AUDIO_IN_PCM_BUFFER_SIZE/2)
      {
        buffer_ctl.wr_state   =  BUFFER_FULL;
        buffer_ctl.offset  = 0;
      }

      if(buffer_ctl.pcm_ptr >= AUDIO_IN_PCM_BUFFER_SIZE)
      {
        buffer_ctl.wr_state   =  BUFFER_FULL;
        buffer_ctl.offset  = AUDIO_IN_PCM_BUFFER_SIZE/2;
        buffer_ctl.pcm_ptr = 0;
      }
      buffer_ctl.it_state = TRANSFER_NONE;
    }

    if (buffer_ctl.it_state == TRANSFER_FULL)
    {
      /* PDM to PCM data convert */
      if (BSP_AUDIO_IN_PDMToPCM((uint16_t*)&buffer_ctl.pdm_buff[INTERNAL_BUFF_SIZE/2], &buffer_ctl.pcm_buff[buffer_ctl.pcm_ptr]) == 0)
      {
        buffer_ctl.pcm_ptr+= AUDIO_IN_PDM_BUFFER_SIZE/4/2;

        if(buffer_ctl.pcm_ptr == AUDIO_IN_PCM_BUFFER_SIZE/2)
        {
          buffer_ctl.wr_state =  BUFFER_FULL;
          buffer_ctl.offset = 0;
        }

        if(buffer_ctl.pcm_ptr >= AUDIO_IN_PCM_BUFFER_SIZE)
        {
          buffer_ctl.wr_state =  BUFFER_FULL;
          buffer_ctl.offset = AUDIO_IN_PCM_BUFFER_SIZE/2;
          buffer_ctl.pcm_ptr = 0;
         }
      }
      buffer_ctl.it_state = TRANSFER_NONE;
      NbRecord_done++;

    }

    /* PCM buffer is full, copy it into the record_file */
    if (buffer_ctl.wr_state == BUFFER_FULL)
    {
      memcpy((uint32_t *)AudioRecFullBuff_addr, (uint8_t*)(buffer_ctl.pcm_buff + buffer_ctl.offset), AUDIO_IN_PCM_BUFFER_SIZE);
      AudioRecFullBuff_addr += AUDIO_IN_PCM_BUFFER_SIZE;
      buffer_ctl.rec_length += AUDIO_IN_PCM_BUFFER_SIZE;
      buffer_ctl.wr_state =  BUFFER_EMPTY;
    }

#ifdef JOYSTICK
    /* Get the Joystick State */
    JoyState = BSP_JOY_GetState();
    switch (JoyState)
    {
      case JOY_SEL:
#endif
        if (AudioRec_State == REC_RESET_STATE)
        {
          /* 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 *)"       RECORDING...     ", CENTER_MODE);
          /* Start Recording */
          buffer_ctl.rec_length = 0;
          buffer_ctl.wr_state = BUFFER_EMPTY;
          buffer_ctl.it_state = TRANSFER_NONE;
          BSP_AUDIO_IN_Record((uint16_t*)&buffer_ctl.pdm_buff[0], INTERNAL_BUFF_SIZE);
          AudioRec_State = RECORD_ONGOING;
        }
#ifdef JOYSTICK
        break;
      default:
        break;
    }
#endif

    if (CheckForUserInput() > 0)
    {
      /* Stop recorder and exit the test (go to next test) */
      BSP_AUDIO_IN_Stop();
      return;
    }
  }

  /* Stop recorder once buffer_ctl.rec_length < AUDIO_REC_TOTAL_SIZE*/
  BSP_AUDIO_IN_Stop();

  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  sprintf((char*)FreqStr, "RECORDING DONE, %d frames, START PLAYBACK", NbRecord_done);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)FreqStr, CENTER_MODE);
  NbRecord_done = buffer_ctl.rec_length / (DEFAULT_AUDIO_IN_FREQ * DEFAULT_AUDIO_IN_CHANNEL_NBR * 2);
  sprintf((char*)FreqStr, "Elapsed_time: %d frames", NbRecord_done);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 45, (uint8_t *)FreqStr, CENTER_MODE);



  /* -----------Start Playback -------------- */

  /* Initialize audio IN at REC_FREQ*/
  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, 95, DEFAULT_AUDIO_IN_FREQ/2) == 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);
  }

  /* Play the recorded buffer*/
  if(AUDIO_Play_Start((uint32_t *)AUDIO_REC_START_ADDR, (uint32_t)AUDIO_REC_TOTAL_SIZE) == 0)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 95, (uint8_t *)"  AUDIO PLAYBACK   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 PLAYBACK  FAIL ", CENTER_MODE);
  }
  
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 25, (uint8_t *)"PLAYBACK DONE", CENTER_MODE);

  while (1)
  {
    /* Toggle LED4 */
    BSP_LED_Toggle(LED4);

    /* Insert 100 ms delay */
    HAL_Delay(100);
    if (CheckForUserInput() > 0)
    {
      /* Set LED4 */
      BSP_LED_On(LED4);
      /* Stop recorder */
      BSP_AUDIO_IN_Stop();
      /* Stop Player before close Test */
      BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
      return;
    }
  }
}
示例#3
0
/**
  * @brief  TouchScreen_Calibration_WaitForPressedState : wait until a particular press/depress action
  *         The function is managing anti-rebound : that is the awaited state when detected
  *         needs to be stable for a sufficient time (timeout time), otherwise a new sense to search
  *         for awaited state is performed. When awaited state is found and state is stable for timeout
  *         duration, the function is exited.
  * @param  uint8_t Pressed :  Awaited pressed state
  *         - Await touch (single/multiple) detection if Pressed == 1
  *         - Await no touch detection if Pressed == 0
  * @retval None
  */
static void TouchScreen_Calibration_WaitForPressedState(uint8_t Pressed)
{
  uint16_t TimeStart = 0;
  uint8_t  status = TS_OK;
  uint32_t exitFirstLevelWhileLoopReq = 0;  /* By default no exit request from first level while loop  */
  uint32_t exitSecondLevelWhileLoopReq = 0; /* By default no exit request from second level while loop */

  /* First level while loop entry */
  do
  {
    /* reset exit second level while loop in case it was set */
    exitSecondLevelWhileLoopReq = 0;

    /* Sense of touch state from touch IC until get the awaited state in parameter 'Pressed' */
    status = BSP_TS_GetState(&TS_State);
    if(status == TS_OK)
    {
      if (((Pressed == 0) && (TS_State.touchDetected == 0)) ||
          ((Pressed == 1) && ((TS_State.touchDetected == 1) || (TS_State.touchDetected == 2))))
      {
        /* Got awaited press state */
        /* Record in 'TimeStart' the time of awaited touch event for anti-rebound calculation */
        /* The state should persist for a minimum sufficient time */
        TimeStart = HAL_GetTick();

        /* Is state of the touch changing ? */
        /* Second level while loop entry */
        do
        {
          /* New sense of touch state from touch IC : to evaluate if state was stable */
          status = BSP_TS_GetState(&TS_State);
          if(status == TS_OK)
          {
            /* Is there a state change compared since having found the awaited state ? */
            if (((Pressed == 0) && ((TS_State.touchDetected == 1) || (TS_State.touchDetected == 2))) ||
                ((Pressed == 1) && ((TS_State.touchDetected == 0))))
            {
              /* Too rapid state change => anti-rebound management : restart first touch search */
              exitSecondLevelWhileLoopReq = 1; /* exit request from second level while loop */
            }
            else if ((HAL_GetTick() - 100) > TimeStart)
            {
              /* State have not changed for the timeout duration (stable touch for 100 ms) */
              /* This means the touch state is stable : can exit function */

              /* found valid touch, exit both while levels */
              exitSecondLevelWhileLoopReq = 1;
              exitFirstLevelWhileLoopReq  = 1;
            }

            /* Wait 10 ms before next sense of touch at next loop iteration */
            HAL_Delay(10);

          } /* of if(status == TS_OK) */
        }
        while (!exitSecondLevelWhileLoopReq);

      } /* of if (((Pressed == 0) && .... */

    } /* of if(status == TS_OK) */

    if(!exitFirstLevelWhileLoopReq)
    {
      /* Wait some time before next sense of touch at next loop iteration */
      HAL_Delay(10);
    }

    /* Scan User button in case early exit requested by user to switch to an other use case while calibrating */
    /* the touch screen                                                                                       */
    if (CheckForUserInput() > 0)
    {
      exitSecondLevelWhileLoopReq = 1;
    }

  }
  while (!exitSecondLevelWhileLoopReq);
}
示例#4
0
/**
  * @brief  SDRAM Demo
  * @param  None
  * @retval None
  */
void IOE_GPIO_demo (void)
{ 
  uint32_t ioe_irq_pending_status, ioe_gpio_status; 
  uint32_t lcd_line = 85;
  uint8_t test_result = IOE_GPIO_TEST_PASSED;
  uint8_t all_test_fail = 1;
  GPIO_PinState mcu_pin_state;

  IOE_GPIO_SetHint();

  /* Enable the Leds */
  BSP_IO_Init();
  BSP_LED_Init(LED1); 
  BSP_LED_Init(LED2); 
  
  BSP_LED_On(LED1); 
  BSP_LED_On(LED2); 
 
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF);

  /* TEST IO_MODE_OUPUT mode */
  /* ---------------------------------- */

  /* SetUp a GPIO to be connected to one of the MFX GPIOS via a wire */
  SetMcuGpioToBeConnectedToMfxGPO();
  test_result = IOE_GPIO_TEST_PASSED;
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OUTPUT);

  BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_RESET);
  HAL_Delay(1);
  mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN);
  if (mcu_pin_state) 
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_SET);
  HAL_Delay(1);
  mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN);
  if (mcu_pin_state) 
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }

  BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_RESET);
  HAL_Delay(1);
  mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN);
  if (mcu_pin_state) 
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  lcd_line += 15;
  if (test_result) 
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_OUTPUT: FAILED", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_OUTPUT: PASSED", LEFT_MODE);
    all_test_fail = 0;
  }


  /* TEST IO_MODE_INPUT mode */
  /* ---------------------------------- */

  /* SetUp a GPIO to be connected to one of the MFX GPIOS via a wire */
  SetMcuGpioToBeConnectedToMfxGPI();
  test_result = IOE_GPIO_TEST_PASSED;
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_INPUT);

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  HAL_Delay(1);
  ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN);
  if (ioe_gpio_status) 
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET);
  HAL_Delay(1);
  ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN);
  if (ioe_gpio_status) 
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  HAL_Delay(1);
  ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN);
  if (ioe_gpio_status) 
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  lcd_line += 15;
  if (test_result) 
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_INPUT: FAILED", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_INPUT: PASSED", LEFT_MODE);
    all_test_fail = 0;
  }

  SetMcuGpioToBeConnectedToMfxGPI();
		
  /* TEST IO_MODE_IT_HIGH_LEVEL mode */
  /* ---------------------------------- */
  test_result = IOE_GPIO_TEST_PASSED;
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF);
  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  BSP_IO_ITClear();   

  /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_HIGH_LEVEL_PD);
  /* We just want to test the good functioning of pending bit and ack on the IOE */
  HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn));

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET);
  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  HAL_Delay(1);

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  lcd_line += 15;
  if (test_result) 
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_HIGH_LEVEL: FAILED", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_HIGH_LEVEL: PASSED", LEFT_MODE);
    all_test_fail = 0;
  }


  /* TEST IO_MODE_IT_LOW_LEVEL mode */
  /* ---------------------------------- */
  test_result = IOE_GPIO_TEST_PASSED;
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF);
  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET);
  BSP_IO_ITClear();   

  /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_LOW_LEVEL_PU);
  /* We just want to test the good functioning of pending bit and ack on the IOE */
  HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn));

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  HAL_Delay(1);

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  HAL_Delay(1);

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  lcd_line += 15;
  if (test_result) 
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_LOW_LEVEL: FAILED", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_LOW_LEVEL: PASSED", LEFT_MODE);
    all_test_fail = 0;
  }

  /* TEST IO_MODE_IT_RISING_EDGE mode */
  /* ---------------------------------- */
  test_result = IOE_GPIO_TEST_PASSED;
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF);
  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  BSP_IO_ITClear();   

  /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_RISING_EDGE_PD);
  /* We just want to test the good functioning of pending bit and ack on the IOE */
  HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn));

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET);
  HAL_Delay(1);
  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  HAL_Delay(1);

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  lcd_line += 15;
  if (test_result) 
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_RISING_EDGE: FAILED", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_RISING_EDGE: PASSED", LEFT_MODE);
    all_test_fail = 0;
  }

  /* TEST IO_MODE_IT_FALLING_EDGE mode */
  /* ---------------------------------- */
  test_result = IOE_GPIO_TEST_PASSED;
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF);
  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  BSP_IO_ITClear();   

  /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */
  BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_FALLING_EDGE_PU);
  /* We just want to test the good functioning of pending bit and ack on the IOE */
  HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn));

  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET);
  HAL_Delay(1);
  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_FAILED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_PASSED;
  }

  HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET);
  HAL_Delay(1);
  ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN);
  if (ioe_irq_pending_status) 
  {
    BSP_IO_ITClear();   
    test_result |= IOE_GPIO_TEST_PASSED;
  }
  else
  {
    test_result |= IOE_GPIO_TEST_FAILED;
  }

  lcd_line += 15;
  if (test_result) 
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_FALLING_EDGE: FAILED", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_FALLING_EDGE: PASSED", LEFT_MODE);
    all_test_fail = 0;
  }

  if (all_test_fail) 
  {
    BSP_LCD_DisplayStringAt(20, lcd_line + 20, (uint8_t *)"          all IOE tests FAILED !!!", LEFT_MODE);
    BSP_LCD_DisplayStringAt(15, lcd_line + 40, (uint8_t *)"Are you sure that MCU_PB4 pin is connected ", LEFT_MODE);
    BSP_LCD_DisplayStringAt(15, lcd_line + 55, (uint8_t *)"to TP9 probe with a wire on the board ??", LEFT_MODE);
  }

  /* We just want to test the good functioning of pending bit and ack on the IOE */
  HAL_NVIC_EnableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn));
	
  while (1)
  {    
    if(CheckForUserInput() > 0)
    {
      return;
    }
  }
}
示例#5
0
文件: log.c 项目: z80/stm32f429
/**
  * @brief  LCD Log demo
  * @param  None
  * @retval None
  */
void Log_demo(void)
{
  TS_ActionTypeDef ts_action = TS_ACT_NONE;
  uint8_t ts_status = TS_OK;
  uint8_t i = 0;

  /* Wait For User inputs */
  while (CheckForUserInput() == 0);

  if (TouchScreen_IsCalibrationDone() == 0)
  {
    ts_status = Touchscreen_Calibration();
    if(ts_status == TS_OK)
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"Touchscreen calibration success.", CENTER_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"ERROR : touchscreen not yet calibrated.", CENTER_MODE);
      ts_status = TS_ERROR;
    }
  } /* of if (TouchScreen_IsCalibrationDone() == 0) */

  /* Initialize LCD Log module */
  LCD_LOG_Init();

  /* Show Header and Footer texts */
  LCD_LOG_SetHeader((uint8_t *)"Log Example");
  LCD_LOG_SetFooter((uint8_t *)"Use touch up/down to scroll");


  /* Output User logs */
  for (i = 0; i < 10; i++)
  {
    LCD_UsrLog ("This is Line %d \n", i);
  }

  HAL_Delay(1000);

  /* Clear Old logs */
  LCD_LOG_ClearTextZone();

  /* Output new user logs */
  for (i = 0; i < 30; i++)
  {
    LCD_UsrLog ("This is Line %d \n", i);
  }

  if(ts_status == TS_OK)
  {
    /* Set touchscreen in Interrupt mode and program EXTI accordingly on falling edge of TS_INT pin */
    ts_status = BSP_TS_ITConfig();
    BSP_TEST_APPLI_ASSERT(ts_status != TS_OK);
    Touchscreen_DrawBackground_Circle_Buttons(32);
    BSP_LCD_SetFont(&Font12);
  }

  /* Check for joystick user input for scroll (back and forward) */
  while (1)
  {
    ts_action = (TS_ActionTypeDef) TouchScreen_GetTouchPosition();

    switch (ts_action)
    {
      case TS_ACT_SCROLL_UP:
        LCD_LOG_ScrollBack();
        break;
      case TS_ACT_SCROLL_DOWN:
        LCD_LOG_ScrollForward();
        break;

      default:
        break;
    }

    if (CheckForUserInput() > 0)
    {
      return;
    }
    HAL_Delay (10);
  }
}
示例#6
0
/**
  * @brief  NOR Demo
  * @param  None
  * @retval None
  */
void NOR_demo(void)
{
  /* NOR IDs structure */
  static NOR_IDTypeDef pNOR_ID;

  NOR_SetHint();

  /* STM32F427x/437x/429x/439x "Revision 3" devices: FMC dynamic and static
     bank switching is allowed  */
  if (HAL_GetREVID() >= 0x2000) {}
  else
  {
    /* Disable the LCD to avoid the refrech from the SDRAM */
    BSP_LCD_DisplayOff();
  }

  /*##-1- Configure the NOR device ###########################################*/
  /* NOR device configuration */
  if(BSP_NOR_Init() != NOR_STATUS_OK)
  {
    ubInitStatus++;
  }

  /*##-2- Read & check the NOR device IDs ####################################*/
  /* Initialize the ID structure */
  pNOR_ID.Manufacturer_Code = (uint16_t)0x00;
  pNOR_ID.Device_Code1 = (uint16_t)0x00;
  pNOR_ID.Device_Code2 = (uint16_t)0x00;
  pNOR_ID.Device_Code3 = (uint16_t)0x00;

  /* Read the NOR memory ID */
  BSP_NOR_Read_ID(&pNOR_ID);

  /* Test the NOR ID correctness */
  if(pNOR_ID.Manufacturer_Code != (uint16_t)0x0020)
    ubIDStatus++;
  else if(pNOR_ID.Device_Code1 != (uint16_t)0x227E)
    ubIDStatus++;
  else if (pNOR_ID.Device_Code2 != (uint16_t)0x2221)
    ubIDStatus++;
  else if (pNOR_ID.Device_Code3 != (uint16_t)0x2200)
    ubIDStatus++;

  /*##-3- Erase NOR memory ###################################################*/
  /* Return to read mode */
  BSP_NOR_ReturnToReadMode();

  if(BSP_NOR_Erase_Block(WRITE_READ_ADDR) != NOR_STATUS_OK)
  {
    ubEraseStatus++;
  }

  /*##-4- NOR memory read/write access  ######################################*/
  /* Fill the buffer to write */
  Fill_Buffer(nor_aTxBuffer, BUFFER_SIZE, 0xC20F);

  /* Write data to the NOR memory */
  if(BSP_NOR_WriteData(WRITE_READ_ADDR, nor_aTxBuffer, BUFFER_SIZE) != NOR_STATUS_OK)
  {
    ubWriteStatus++;
  }

  /* Read back data from the NOR memory */
  if(BSP_NOR_ReadData(WRITE_READ_ADDR, nor_aRxBuffer, BUFFER_SIZE) != NOR_STATUS_OK)
  {
    ubReadStatus++;
  }

  /*##-5- Checking data integrity ############################################*/
  /* STM32F427x/437x/429x/439x "Revision 3" devices: FMC dynamic and static
     bank switching is allowed  */
  if (HAL_GetREVID() >= 0x2000) {}
  else
  {
    /* Enable the LCD */
    BSP_LCD_DisplayOn();

    /* SDRAM initialization */
    BSP_SDRAM_Init();
  }

  if(ubIDStatus != 0)
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"NOR Read ID : FAILED.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
  }
  else
  {
    if(ubInitStatus != 0)
    {
      BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"NOR Initialization : FAILED.", LEFT_MODE);
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"NOR Initialization : OK.", LEFT_MODE);
    }
    if(ubEraseStatus != 0)
    {
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"NOR ERASE : FAILED.", LEFT_MODE);
      BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"NOR ERASE : OK.   ", LEFT_MODE);
    }
    if(ubWriteStatus != 0)
    {
      BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"NOR WRITE : FAILED.", LEFT_MODE);
      BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"NOR WRITE : OK.     ", LEFT_MODE);
    }
    if(ubReadStatus != 0)
    {
      BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"NOR READ : FAILED.", LEFT_MODE);
      BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"NOR READ :  OK.    ", LEFT_MODE);
    }
    if(Buffercmp(nor_aRxBuffer, nor_aTxBuffer, BUFFER_SIZE) > 0)
    {
      BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"NOR COMPARE : FAILED.", LEFT_MODE);
      BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"NOR Test Aborted.", LEFT_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"NOR Test : OK.     ", LEFT_MODE);
    }
  }

  while (1)
  {
    if(CheckForUserInput() > 0)
    {
      return;
    }
  }
}
示例#7
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;
    }
  }
}
示例#8
0
/**
  * @brief Test Audio Hardware.
  *   The main objective of this test is to check the hardware connection of the 
  *   Audio peripheral.
  * @param  None
  * @retval None
  */
void AudioPlay_demo(void)
{  
  WAVE_FormatTypeDef *waveformat =  NULL;
  uint8_t Volume_string[20] = {0};

  AudioPlay_SetHint();

  /* Configuration of the EXTI for the joystick SEL push button for pause/resume */
  /* UP/DOWN push buttons for change the volume */
  BSP_PB_Init(BUTTON_SEL, BUTTON_MODE_EXTI);
  BSP_PB_Init(BUTTON_UP, BUTTON_MODE_EXTI);
  BSP_PB_Init(BUTTON_DOWN, BUTTON_MODE_EXTI);
  
  /* Retrieve Wave Sample rate*/
  waveformat = (WAVE_FormatTypeDef*) AUDIO_FILE_ADDRESS;
  AudioPlay_DisplayInfos(waveformat);

  /* Initialize Audio Device */
  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, volume, waveformat->SampleRate) != 0)
  {
    BSP_LCD_SetTextColor(LCD_COLOR_RED);    
    BSP_LCD_DisplayStringAt(0, 130, (uint8_t*)"Initialization problem", CENTER_MODE); 
    BSP_LCD_DisplayStringAt(0, 145, (uint8_t*)"Audio Codec not detected", CENTER_MODE); 
    BSP_LCD_DisplayStringAt(0, 160, (uint8_t*)"Verify that jumper JP5 and JP6", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, 175, (uint8_t*)"are well set to I2C2 position", CENTER_MODE);
    Error_Handler();
  }
  
  /* Set the total number of data to be played */
  AudioTotalSize = (AUDIO_FILE_SIZE / AUDIODATA_SIZE);  
  /* Set the current audio pointer position */
  CurrentPos = (uint16_t *)(AUDIO_FILE_ADDRESS);
  /* Start the audio player */
  if(BSP_AUDIO_OUT_Play(CurrentPos,DMA_MAX((AudioTotalSize))) != 0)
  {
    Error_Handler();
  }

  /* Turn ON LED green: start of Audio file play */
  BSP_LED_On(LED_GREEN);

  /* Update the remaining number of data to be played */
  AudioRemSize = AudioTotalSize - DMA_MAX(AudioTotalSize);  
  /* Update the current audio pointer position */
  CurrentPos += DMA_MAX(AudioTotalSize);

  BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"Playback on-going", LEFT_MODE);
  sprintf((char *) Volume_string, " Volume : %d%% ", volume);
  BSP_LCD_DisplayStringAt((uint16_t)(-20), BSP_LCD_GetYSize()-30, Volume_string, RIGHT_MODE);

  /* Infinite loop */
  while(!CheckForUserInput())
  { 
    if (PauseResumeStatus == PAUSE_STATUS)
    {
      /* Turn ON LED orange: Audio play in pause */
      BSP_LED_On(LED_ORANGE);
      
      /* Pause playing */
      if(BSP_AUDIO_OUT_Pause() != 0)
      {
        Error_Handler();
      }
      BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"Playback paused  ", LEFT_MODE);
      PauseResumeStatus = IDLE_STATUS;
    }
    else if (PauseResumeStatus == RESUME_STATUS)
    {
      /* Turn OFF LED orange: Audio play running */
      BSP_LED_Off(LED_ORANGE);
      
      /* Resume playing */
      if(BSP_AUDIO_OUT_Resume() != 0)
      {
        Error_Handler();
      }
      BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"Playback on-going", LEFT_MODE);
      PauseResumeStatus = IDLE_STATUS;
    }
  
    if (VolumeChange != 0)
    {
      VolumeChange = 0;
      if(BSP_AUDIO_OUT_SetVolume(volume) != 0)
      {
        Error_Handler();
      }
      sprintf((char *) Volume_string, " Volume : %d%% ", volume);
      BSP_LCD_DisplayStringAt((uint16_t)(-20), BSP_LCD_GetYSize()-30, Volume_string, RIGHT_MODE);
    }
  }
  
  /* Reset the EXTI configuration for Joystick SEL, UP and DOWN push buttons */
  /* Configuration of the joystick in GPIO mode and no more EXTI */
  BSP_PB_Init(BUTTON_SEL, BUTTON_MODE_GPIO);
  BSP_PB_Init(BUTTON_UP, BUTTON_MODE_GPIO);
  BSP_PB_Init(BUTTON_DOWN, BUTTON_MODE_GPIO);
  
  /* Stop Player before close Test */
  if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW) != AUDIO_OK)
  {
    /* Audio Stop error */
    Error_Handler();
  }
  else
  {
    /* Turn OFF LED green: stop of Audio file play */
    BSP_LED_Off(LED_GREEN);
    BSP_LED_Off(LED_ORANGE);
  }
}
示例#9
0
/**
  * @brief  SDRAM Demo
  * @param  None
  * @retval None
  */
void SDRAM_DMA_demo (void)
{

  SDRAM_DMA_SetHint();

  /* -1- SDRAM device configuration */
  if (BSP_SDRAM_Init() != SDRAM_OK)
  {
    BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SDRAM Initialization : FAILED.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SDRAM Test Aborted.", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SDRAM Initialization : OK.", LEFT_MODE);
  }

  /* -2- Fill the buffer to write */
  Fill_Buffer(sdram_aTxBuffer, SDRAM_DMA_BUFFER_SIZE, 0xA244250F);

  /* -3- Write data to the SDRAM memory using DMA */
  uwDMA_Transfer_Complete = 0;
  if (BSP_SDRAM_WriteData_DMA((SDRAM_WRITE_READ_ADDR + SDRAM_WRITE_READ_ADDR_OFFSET), sdram_aTxBuffer, SDRAM_DMA_BUFFER_SIZE) != SDRAM_OK)
  {
    BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SDRAM WRITE dma : FAILED.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SDRAM Test Aborted.", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SDRAM WRITE DMA : REQUESTED", LEFT_MODE);
  }

  /* Wait until DMA transfer is complete */
  while (!uwDMA_Transfer_Complete)
  {}
  BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SDRAM WRITE DMA : COMPLETED", LEFT_MODE);

  /* -4- Read back data from the SDRAM memory using DMA */
  uwDMA_Transfer_Complete = 0;
  if (BSP_SDRAM_ReadData_DMA((SDRAM_WRITE_READ_ADDR + SDRAM_WRITE_READ_ADDR_OFFSET), sdram_aRxBuffer, SDRAM_DMA_BUFFER_SIZE) != SDRAM_OK)
  {
    BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SDRAM  READ DMA : FAILED", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SDRAM  Test Aborted", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SDRAM READ  DMA : REQUESTED", LEFT_MODE);
  }

  /* Wait until DMA transfer is complete */
  while (!uwDMA_Transfer_Complete)
  {}
  BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SDRAM READ  DMA : COMPLETED", LEFT_MODE);

  /* -5- Compare both buffers */
  if (Buffercmp(sdram_aTxBuffer, sdram_aRxBuffer, SDRAM_DMA_BUFFER_SIZE) > 0)
  {
    BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SDRAM COMPARE : FAILED.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 190, (uint8_t *)"SDRAM Test Aborted.", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SDRAM TEST      : SUCCESSFULL", LEFT_MODE);
  }

  while (1)
  {
    if (CheckForUserInput() > 0)
    {
      return;
    }
  }
}
示例#10
0
/**
  * @brief  Animation demo
  * @param  None
  * @retval None
  */
void Animation_demo (void)
{
  uint32_t exit = 0;
  uint32_t CameraChangeResolutionAsked = 1;
#ifdef USE_CAMERA_IN_ANIMATION
  uint32_t camera_status = CAMERA_OK;
  uint32_t argb8888_Value = 0x00556677;
  uint32_t CameraResX = CAMERA_VGA_RES_X;
  uint32_t CameraResY = CAMERA_VGA_RES_Y;
#endif /* USE_CAMERA_IN_ANIMATION */

  Animation_SetHint();

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

  BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  BSP_LCD_SetTextColor(LCD_COLOR_WHITE);

#ifdef USE_CAMERA_IN_ANIMATION
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - ANIMATION_STATUS_TEXT_POS, (uint8_t *)"Wait for camera initialization...", CENTER_MODE);
#endif /* USE_CAMERA_IN_ANIMATION */

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

      BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
      BSP_LCD_SetTextColor(LCD_COLOR_BLUE);

#ifdef USE_CAMERA_IN_ANIMATION
      /* Initialize the Camera */
      camera_status = BSP_CAMERA_Init(RESOLUTION_R640x480);
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - ANIMATION_STATUS_TEXT_POS, (uint8_t *)"        VGA camera stream        ", CENTER_MODE);
      if (camera_status != CAMERA_OK)
      {
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - ANIMATION_STATUS_TEXT_POS - 15, (uint8_t *)"        CAMERA INIT ERROR        ", CENTER_MODE);
      }
#endif /* USE_CAMERA_IN_ANIMATION */

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

#ifdef USE_CAMERA_IN_ANIMATION
      /* Init or Re-Init Camera frame buffer by using DMA2D engine in mode Register to Memory */
      camera_status = AnimationCameraFrameBufferRgb565_Init(CameraResX,
                                                            CameraResY,
                                                            argb8888_Value);
      BSP_TEST_APPLI_ASSERT(camera_status != CAMERA_OK);

      /* Start / Restart camera stream */
      BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FB_START_ADDR);
#endif /* USE_CAMERA_IN_ANIMATION */

      /* Forbid in that case the DMA2D copy from Camera frame buffer to LCD Frame buffer location by BSP_CAMERA_LineEventCallback() */
      Camera_AllowDma2dCopyCamFrmBuffToLcdFrmBuff = 0;

    }  /* of if (CameraChangeResolutionAsked) */

    /* Toggle LED4 */
    BSP_LED_Toggle(LED4);

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

    /* Toggle LED2 */
    BSP_LED_Toggle(LED2);

    /* Insert 400 ms delay */
    HAL_Delay(400);
    if(CheckForUserInput() > 0)
    {
      exit = 1;
    }

    anime_draw_scene(anime_lcd_frame_buffer);

  } /* of while (exit == 0) */

#ifdef USE_CAMERA_IN_ANIMATION
  /* Stop camera stream */
  camera_status = BSP_CAMERA_Stop();
  BSP_TEST_APPLI_ASSERT(camera_status != CAMERA_OK);
#endif /* USE_CAMERA_IN_ANIMATION */
}
示例#11
0
/**
  * @brief  Audio Play demo
  * @param  None
  * @retval None
  */
void AudioPlay_demo (void)
{
  uint8_t ts_status = TS_OK;
  uint32_t *AudioFreq_ptr;
  AudioFreq_ptr = AudioFreq+6; /*AF_48K*/
  uint8_t FreqStr[256] = {0};
  Point Points2[] = {{100, 140}, {160, 180}, {100, 220}};

  uwPauseEnabledStatus = 1; /* 0 when audio is running, 1 when Pause is on */
  uwVolume = AUDIO_DEFAULT_VOLUME;


  if (TouchScreen_IsCalibrationDone() == 0)
  {
    ts_status = Touchscreen_Calibration();
    if(ts_status == TS_OK)
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"Touchscreen calibration success.", CENTER_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"ERROR : touchscreen not yet calibrated.", CENTER_MODE);
      ts_status = TS_ERROR;
    }
  } /* of if (TouchScreen_IsCalibrationDone() == 0) */

  AudioPlay_SetHint();
  BSP_LCD_SetFont(&Font20);


/*  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_SPEAKER, uwVolume, *AudioFreq_ptr) == 0)
  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_BOTH, uwVolume, *AudioFreq_ptr) == 0)*/
  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_BOTH, uwVolume, *AudioFreq_ptr) == 0)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"  AUDIO CODEC   OK  ", CENTER_MODE);
  }
  else
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"  AUDIO CODEC  FAIL ", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)" Try to reset board ", 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_Play_Start((uint32_t *)AUDIO_SRC_FILE_ADDRESS, (uint32_t)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, LINE(8), (uint8_t *)"       PLAYING...     ", CENTER_MODE);

  sprintf((char*)FreqStr, "       VOL:    %3lu     ", uwVolume);
  BSP_LCD_DisplayStringAt(0,  LINE(9), (uint8_t *)FreqStr, CENTER_MODE);

  sprintf((char*)FreqStr, "      FREQ: %6lu     ", *AudioFreq_ptr);
  BSP_LCD_DisplayStringAt(0, LINE(10), (uint8_t *)FreqStr, CENTER_MODE);

  BSP_LCD_SetFont(&Font16);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 40, (uint8_t *)"Hear nothing ? Have you copied the audio file with STM-LINK UTILITY ?", CENTER_MODE);

  if(ts_status == TS_OK)
  {
    /* Set touchscreen in Interrupt mode and program EXTI accordingly on falling edge of TS_INT pin */
    ts_status = BSP_TS_ITConfig();
    BSP_TEST_APPLI_ASSERT(ts_status != TS_OK);
    Touchscreen_DrawBackground_Circle_Buttons(16);
  }

  BSP_LCD_SetFont(&Font20);

  /* draw play triangle */
  BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  BSP_LCD_FillPolygon(Points2, 3);

/* IMPORTANT:
     AUDIO_Play_Process() is called by the SysTick Handler, as it should be called
     within a periodic process */

  /* Infinite loop */
  while (1)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_BLUE);

    /* Get the TouchScreen State */
    ts_action = (TS_ActionTypeDef) TouchScreen_GetTouchPosition();

    switch (ts_action)
    {
      case TS_ACT_VOLUME_UP:
        /* 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, LINE(9), (uint8_t *)FreqStr, CENTER_MODE);
        break;
      case TS_ACT_VOLUME_DOWN:
        /* 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, LINE(9), (uint8_t *)FreqStr, CENTER_MODE);
        break;
      case TS_ACT_FREQ_DOWN:
        /*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, LINE(10), (uint8_t *)FreqStr, CENTER_MODE);
        break;
      case TS_ACT_FREQ_UP:
        /* 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, LINE(10), (uint8_t *)FreqStr, CENTER_MODE);
        break;
      case TS_ACT_PAUSE:
        /* Set Pause / Resume */
        if (uwPauseEnabledStatus == 1)
        { /* Pause is enabled, call Resume */
          BSP_AUDIO_OUT_Resume();
          uwPauseEnabledStatus = 0;
          BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"       PLAYING...     ", CENTER_MODE);
          BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
          BSP_LCD_FillPolygon(Points2, 3);
          BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
          BSP_LCD_FillRect(100, 140, 25 , 80);
          BSP_LCD_FillRect(140, 140, 25 , 80);
        }
        else
        { /* Pause the playback */
          BSP_AUDIO_OUT_Pause();
          uwPauseEnabledStatus = 1;
          BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"       PAUSE  ...     ", CENTER_MODE);
          BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
          BSP_LCD_FillRect(100, 140, 80 , 80);
          BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
          BSP_LCD_FillPolygon(Points2, 3);
        }
        HAL_Delay(200);
        break;

      default:
        break;
    }



    /* Toggle LED4 */
    BSP_LED_Toggle(LED4);

    /* Insert 100 ms delay */
    HAL_Delay(100);
    if (CheckForUserInput() > 0)
    {
      /* Set LED4 */
      BSP_LED_On(LED4);

      BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
      return;
    }
  }
}
示例#12
0
/**
  * @brief  Touchscreen Demo1 : test touchscreen calibration and single touch in polling mode
  * @param  None
  * @retval None
  */
void Touchscreen_demo1(void)
{
  uint16_t x1, y1;
  uint8_t state = 0;
  uint8_t exitTsUseCase = 0;
  uint32_t ts_status = TS_OK;

  /* Reset touch data information */
  BSP_TEST_APPLI_ASSERT(BSP_TS_ResetTouchData(&TS_State));

  /* If calibration is not yet done, proceed with calibration */
  if (TouchScreen_IsCalibrationDone() == 0)
  {
    ts_status = Touchscreen_Calibration();
    if (ts_status == TS_OK)
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *) "Touchscreen calibration success.", CENTER_MODE);
    }
  } /* of if (TouchScreen_IsCalibrationDone() == 0) */

  if(ts_status == TS_OK)
  {
    /* Display touch screen demo description */
    Touchscreen_SetHint_Demo(TOUCHSCREEN_DEMO_1);
    Touchscreen_DrawBackground_Demo1(state);

    while (exitTsUseCase == 0)
    {
      if (ts_status == TS_OK)
      {
        /* Check in polling mode in touch screen the touch status and coordinates */
        /* of touches if touch occurred                                           */
        ts_status = BSP_TS_GetState(&TS_State);
        if(TS_State.touchDetected)
        {
          /* One or dual touch have been detected          */
          /* Only take into account the first touch so far */

          /* Get X and Y position of the first touch post calibrated */
          x1 = TouchScreen_Get_Calibrated_X(TS_State.touchX[0]);
          y1 = TouchScreen_Get_Calibrated_Y(TS_State.touchY[0]);

          if ((y1 > (CIRCLE_YPOS(1) - CIRCLE_RADIUS)) &&
              (y1 < (CIRCLE_YPOS(1) + CIRCLE_RADIUS)))
          {
            if ((x1 > (CIRCLE_XPOS(1) - CIRCLE_RADIUS)) &&
                (x1 < (CIRCLE_XPOS(1) + CIRCLE_RADIUS)))
            {
              if ((state & 1) == 0)
              {
                Touchscreen_DrawBackground_Demo1(state);
                BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
                BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS);
                state = 1;
              }
            }
            if ((x1 > (CIRCLE_XPOS(2) - CIRCLE_RADIUS)) &&
                (x1 < (CIRCLE_XPOS(2) + CIRCLE_RADIUS)))
            {
              if ((state & 2) == 0)
              {
                Touchscreen_DrawBackground_Demo1(state);
                BSP_LCD_SetTextColor(LCD_COLOR_RED);
                BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS);
                state = 2;
              }
            }

            if ((x1 > (CIRCLE_XPOS(3) - CIRCLE_RADIUS)) &&
                (x1 < (CIRCLE_XPOS(3) + CIRCLE_RADIUS)))
            {
              if ((state & 4) == 0)
              {
                Touchscreen_DrawBackground_Demo1(state);
                BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
                BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS);
                state = 4;
              }
            }

            if ((x1 > (CIRCLE_XPOS(4) - CIRCLE_RADIUS)) &&
                (x1 < (CIRCLE_XPOS(4) + CIRCLE_RADIUS)))
            {
              if ((state & 8) == 0)
              {
                Touchscreen_DrawBackground_Demo1(state);
                BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
                BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS);
                state = 8;
              }
            }
          }

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

      } /* of if (ts_status == TS_OK) */

      /* Wait for a key button press to switch to next test case of BSP validation application */
      /* Otherwise stay in the test */
      exitTsUseCase = CheckForUserInput();

      HAL_Delay(20);

    } /* of while (exitTsUseCase == 0) */

  } /* of if(status == TS_OK) */
}
示例#13
0
/**
  * @brief  Camera demo
  * @param  None
  * @retval None
  */
void Camera_demo (void)
{ 
  uint8_t status = 0;
  uint16_t  *ptrCamera;
  uint32_t  i;
  uint32_t  exit = 0;

  Camera_SetHint();

  status = BSP_JOY_Init(JOY_MODE_GPIO);

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

  if (status != IO_OK)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- CAMERA_STATUS_TEXT_POS, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- CAMERA_STATUS_TEXT_POS - 15, (uint8_t *)"Joystick cannot be initialized", CENTER_MODE);
    status = 0;
  }

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

  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);

  /* Init Camera buffer */
  ptrCamera = (uint16_t*)(CAMERA_FRAME_BUFFER);
  CameraResIndex = CAMERA_R160x120;     /* Set QQVGA default resolution */
  CameraChangeResolutionAsked = 1;
  for (i=0; i<(CAMERA_QVGA_RES_X * CAMERA_QVGA_RES_Y); i++)   /* Camera buffer initialization */
  {
    ptrCamera[i]=0xFFFF;
  }

  /* Initialize IO */
  BSP_IO_Init();

  /* Infinite loop */
  while(exit == 0)
  {
    if (CameraChangeResolutionAsked)  /* A camera change resolution has been asked */
    {
      CameraChangeResolutionAsked = 0;
      if (CameraResIndex > CAMERA_R160x120)
      { /* If camera stream already started, it has to be stopped before reconfiguration */
        /* Stop camera stream */
        status = BSP_CAMERA_Stop();
        ASSERT(status != CAMERA_OK);

        /* Clear screen */
        Camera_SetHint();

        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);

      status = 0;

      switch (CameraResIndex)
      {
        case CAMERA_R160x120:
          /* Initialize the 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:
          /* Initialize the 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;
      }

      if (status != CAMERA_OK)
      {
        BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- CAMERA_STATUS_TEXT_POS - 15, (uint8_t *)"        CAMERA INIT ERROR        ", CENTER_MODE);
      }


      /* Start / Restart camera stream */
      BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FRAME_BUFFER);
    }  /* (CameraResIndex != CameraCurrentResIndex) */


    /* Toggle LED4 */
    BSP_LED_Toggle(LED3);

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

    /* Toggle LED2 */
    BSP_LED_Toggle(LED2);

    /* Insert 100 ms delay */
    HAL_Delay(100);
    if(CheckForUserInput() > 0)
    {
      if (CameraResIndex < CAMERA_RES_INDEX_MAX)
      {
        CameraResIndex++;     /* Switch to higher resolution */
        CameraChangeResolutionAsked = 1;
      }
      else
      {
        BSP_CAMERA_DeInit();
        exit = 1;
      }
    }
  }

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

  /* End of camera demo */
}
示例#14
0
文件: camera.c 项目: z80/stm32f429
/**
  * @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 = 0x00556677;

  Camera_SetHint();

  /* Activate joystick as used for contrast, brightness and visual effect settings */
  /* on image from camera sensor                                                   */
  status = BSP_JOY_Init(JOY_MODE_GPIO);
  if (status != IO_OK)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - CAMERA_STATUS_TEXT_POS - 15, (uint8_t *)"Joystick cannot be initialized", CENTER_MODE);
  }

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

  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);

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

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

      if (CameraResIndex > CAMERA_R160x120)
      { /* If camera stream already started, it has to be stopped before reconfiguration */
        /* Stop camera stream */
        refresh_authorized = 0;
        camera_status = BSP_CAMERA_Stop();
        BSP_TEST_APPLI_ASSERT(camera_status != CAMERA_OK);

        /* Clear screen */
        Camera_SetHint();

        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);
      }

      offset_cam = 0;
      offset_lcd = 0;
      display_line_counter = 0;
      display_rotated_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 */

      refresh_authorized = 1;

      CameraFrameBufferInitComplete = 0;
      CameraFrameBufferInitError    = 0;

      if(CameraResIndex == CAMERA_R640x480)
      {
        /* Clear first the LCD */
        BSP_LCD_Clear(LCD_COLOR_WHITE);
      }

      /* 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);
      BSP_TEST_APPLI_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 */
      BSP_TEST_APPLI_ASSERT(CameraFrameBufferInitComplete != 1);

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

      /* Allow DMA2D copy from Camera frame buffer to LCD Frame buffer location */
      Camera_AllowDma2dCopyCamFrmBuffToLcdFrmBuff = 1;

    }  /* (CameraResIndex != CameraCurrentResIndex) */

    /* Get the Joystick State */
    JoyState = BSP_JOY_GetState();

    switch (JoyState)
    {
      case JOY_UP:
        if (brightness < CAMERA_BRIGHTNESS_MAX)
        {
          brightness++;
        }
        else
        {
          JoyState = JOY_NONE;  /* Cancel brightness change */
        }
        break;

      case JOY_DOWN:
        if (brightness > CAMERA_BRIGHTNESS_MIN)
        {
          brightness--;
        }
        else
        {
          JoyState = JOY_NONE;  /* Cancel brightness change */
        }
        break;

      case JOY_LEFT:
        if (contrast > CAMERA_CONTRAST_MIN)
        {
          contrast--;
        }
        else
        {
          JoyState = JOY_NONE;  /* Cancel contrast change */
        }
        break;

      case JOY_RIGHT:
        if (contrast < CAMERA_CONTRAST_MAX)
        {
          contrast++;
        }
        else
        {
          JoyState = JOY_NONE;  /* Cancel contrast change */
        }
        break;

      case JOY_SEL:
        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_ANTIQUE;
            }
            break;

          case CAMERA_COLOR_EFFECT :
            if (color_effect < CAMERA_COLOR_EFFECT_RED)
            {
              /* 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;
        }
        break;

      default:
        break;
    }

    if ((JoyState == JOY_UP) || (JoyState == JOY_DOWN) || (JoyState == JOY_LEFT) || (JoyState == JOY_RIGHT))
    {
      /* A brightness change has been asked */
      BSP_CAMERA_ContrastBrightnessConfig(contrast, brightness);
      if ((JoyState == JOY_UP) || (JoyState == JOY_DOWN))
      {
        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 (JoyState == JOY_SEL)
    {
      /* 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;
      }
    }

    /* Toggle LED4 */
    BSP_LED_Toggle(LED3);

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

    /* Toggle LED2 */
    BSP_LED_Toggle(LED2);

    /* Insert 100 ms delay */
    HAL_Delay(100);
    if (CheckForUserInput() > 0)
    {
      if (CameraResIndex < CAMERA_RES_INDEX_MAX)
      {
        CameraResIndex++;     /* Switch to higher resolution */
        CameraChangeResolutionAsked = 1;

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

        /* Insert 10 ms delay */
        HAL_Delay(10);
      }
      else
      {
        BSP_CAMERA_DeInit();
        exit = 1;
      }
    }
  }

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

  /* End of camera demo */
}
示例#15
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(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);

      x = Calibration_GetX(TS_State.x);
      y = Calibration_GetX(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(100);
  }
}
示例#16
0
/**
  * @brief Test Audio Hardware.
  *   The main objective of this test is to check the hardware connection of the 
  *   Audio peripheral.
  * @param  None
  * @retval None
  */
void AudioPlay_demo(void)
{  
  WAVE_FormatTypeDef *waveformat =  NULL;
  uint8_t Volume_string[20] = {0};

  AudioPlay_SetHint();

  /* Configuration of the EXTI for the joystick SEL push button for pause/resume */
  /* UP/DOWN push buttons for change the volume */
  BSP_JOY_Init(JOY_MODE_EXTI);
  
  /* Retrieve Wave Sample rate */
  waveformat = (WAVE_FormatTypeDef*) AUDIO_FILE_ADDRESS;
  
  /* Check waveformat validity */
  /* In case of audio file pre-loaded into Flash memory, to check audio data  */
  /* integrity.                                                               */
  if ((waveformat->SampleRate < SAMPLE_RATE_MIN) || (waveformat->SampleRate > SAMPLE_RATE_MAX))
  {
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, 130, (uint8_t*)"Audio file not valid", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, 145, (uint8_t*)"Check audio data integrity", CENTER_MODE);
    Error_Handler();
  }
  
  /* Display audio file Wave parameters */
  AudioPlay_DisplayInfos(waveformat);

  /* Initialize Audio Device */
  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_BOTH, volume, waveformat->SampleRate) != 0)
  {
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, 130, (uint8_t*)"Initialization problem", CENTER_MODE); 
    BSP_LCD_DisplayStringAt(0, 145, (uint8_t*)"Audio Codec not detected", CENTER_MODE); 
    Error_Handler();
  }

  /* Set the total number of data to be played */
  AudioTotalSize = (AUDIO_FILE_SIZE - AUDIO_START_ADDRESS) / 2;
  
  /* Set the current audio pointer position */
  CurrentPos = (uint16_t *)(AUDIO_FILE_ADDRESS);

  /* Initialize Volume */
  if(BSP_AUDIO_OUT_SetVolume(volume) != 0)
  {
    Error_Handler();
  }

  /* Start the audio player */
  if(BSP_AUDIO_OUT_Play(CurrentPos, DMA_MAX(AudioTotalSize)) != 0)
  {
    Error_Handler();
  }

  /* Turn ON LED green: start of Audio file play */
  BSP_LED_On(LED_GREEN);

  /* Update the remaining number of data to be played */
  AudioRemSize = AudioTotalSize - DMA_MAX(AudioTotalSize);
  /* Update the current audio pointer position */
  CurrentPos += DMA_MAX(AudioTotalSize);

  BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"Playback on-going", LEFT_MODE);
  sprintf((char *) Volume_string, " Volume : %d%% ", volume);
  BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, Volume_string, RIGHT_MODE);

  /* Infinite loop */
  while(!CheckForUserInput())
  { 
    if (PauseResumeStatus == PAUSE_STATUS)
    {
      /* Turn ON LED orange: Audio play in pause */
      BSP_LED_On(LED_ORANGE);
      
      /* Pause playing */
      if(BSP_AUDIO_OUT_Pause() != 0)
      {
        Error_Handler();
      }
      BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"Playback paused  ", LEFT_MODE);
      PauseResumeStatus = IDLE_STATUS;
    }
    else if (PauseResumeStatus == RESUME_STATUS)
    {
      /* Turn OFF LED orange: Audio play running */
      BSP_LED_Off(LED_ORANGE);
      
      /* Resume playing */
      if(BSP_AUDIO_OUT_Resume() != 0)
      {
        Error_Handler();
      }
      BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"Playback on-going", LEFT_MODE);
      PauseResumeStatus = IDLE_STATUS;
    }
  
    if (VolumeChange != 0)
    {
      VolumeChange = 0;
      if(BSP_AUDIO_OUT_SetVolume(volume) != 0)
      {
        Error_Handler();
      }
      sprintf((char *) Volume_string, " Volume : %d%% ", volume);
      BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, Volume_string, RIGHT_MODE);
    }

    if (UserOutputMode != UserOutputModePreviousState)
    {
      /* Change audio output */
      BSP_AUDIO_OUT_SetOutputMode(UserOutputMode);
      
      UserOutputModePreviousState = UserOutputMode;
    }
  }
  
  /* Reset the EXTI configuration for Joystick SEL, UP and DOWN push buttons */
  /* Configuration of the joystick in GPIO mode and no more EXTI */
  BSP_PB_Init(BUTTON_SEL, BUTTON_MODE_GPIO);
  BSP_PB_Init(BUTTON_UP, BUTTON_MODE_GPIO);
  BSP_PB_Init(BUTTON_DOWN, BUTTON_MODE_GPIO);
  
  /* Stop Player before close Test */
  if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW) != AUDIO_OK)
  {
    /* Audio Stop error */
    Error_Handler();
  }
  else
  {
    /* Turn OFF LED green: stop of Audio file play */
    BSP_LED_Off(LED_GREEN);
    BSP_LED_Off(LED_ORANGE);
  }
}
示例#17
0
/**
  * @brief  MEMS demo
  * @param  None
  * @retval None
  */
void MEMS_demo(void)
{
  MEMS_SetHint();
  
  if (BSP_GYRO_Init() != GYRO_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*)"MEMS cannot be initialized", CENTER_MODE);
  }
  else
  {
    Gyroscope_DrawBackground(state);
  }
  
  BSP_GYRO_Reset();
  
  while (1)
  {	
    /* Read Gyro Angular data */
    BSP_GYRO_GetXYZ(Buffer);
    
    /* Update autoreload and capture compare registers value */
    Xval = ABS((Buffer[0]));
    Yval = ABS((Buffer[1])); 
    Zval = ABS((Buffer[2])); 
    
    if((Xval>Yval) && (Xval>Zval))
    {
      if(Buffer[0] > 10000.0f)
      { 
        if((state & 1) == 0)
        {
          Gyroscope_DrawBackground(1);			
          state |= 1;
          HAL_Delay(1000);
        }        
      }
      else if(Buffer[0] < -10000.0f)
      { 
        if((state & 2) == 0)
        {          
          Gyroscope_DrawBackground(2);            
          state |= 2;
          HAL_Delay(1000);
        }           
      }      
    }
    else if ((Yval>Xval) && (Yval>Zval))
    {
      if(Buffer[1] < -10000.0f)
      {
        if((state & 4) == 0)
        {                     
          Gyroscope_DrawBackground(4);            
          state |= 4;
          HAL_Delay(1000);
        }   
      }
      else if(Buffer[1] > 10000.0f)
      {
        if((state & 8) == 0)
        {          
          Gyroscope_DrawBackground(8);            
          state |= 8;
          HAL_Delay(1000);
        }
      }     
    } 
    else if ((Zval>Xval) && (Zval>Yval))
    {
      if(Buffer[2] < -10000.0f)
      {
        if((state & 16) == 0)
        {                     
          Gyroscope_DrawBackground(16);            
          state |= 16;
          HAL_Delay(1000);
        }   
      }		 
      else if(Buffer[2] > 10000.0f)
      {
        if((state & 32) == 0)
        {          
          Gyroscope_DrawBackground(32);            
          state |= 32;
          HAL_Delay(1000);			
        }
      }  	
    } 
    if (state != 0x3F)	
    {
    }
    else if (CheckForUserInput() > 0)
    { 
      state = 0;    
      return;
    }
  }
}
示例#18
0
/**
  * @brief  SD Demo
  * @param  None
  * @retval None
  */
void SD_demo (void)
{ 
  uint8_t SD_state = MSD_OK;
  __IO uint8_t prev_status = 0; 

  SD_SetHint();

  SD_state = BSP_SD_Init();

   /* Check if the SD card is plugged in the slot */
  if(BSP_SD_IsDetected() == SD_PRESENT)
  {
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Connected    ", LEFT_MODE);
  }
  else 
  {
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Not Connected", LEFT_MODE);
  }
  BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
  
  if(SD_state != MSD_OK)
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD INITIALIZATION : FAIL.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD INITIALIZATION : OK.", LEFT_MODE); 
    
    BSP_SD_GetCardInfo(&CardInfo);

  if(SD_state != MSD_OK)
    {
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD GET CARD INFO : FAIL.", LEFT_MODE);
      BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD GET CARD INFO : OK.", LEFT_MODE);

      SD_state = BSP_SD_Erase(BLOCK_START_ADDR, (BLOCKSIZE * NUM_OF_BLOCKS));
    
      /* Verify that SD card is ready to use after the Erase */
      SD_state |= BSP_SD_GetStatus();

      if(SD_state != MSD_OK)
      {
        BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD ERASE : FAILED.", LEFT_MODE);
        BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
      }
      else
      {
        BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD ERASE : OK.", LEFT_MODE);
      
        /* Fill the buffer to write */
        Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF);
        SD_state = BSP_SD_WriteBlocks((uint32_t *)aTxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS);
      
        if(SD_state != MSD_OK)
        {
          BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD WRITE : FAILED.", LEFT_MODE);
          BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
        }
        else
        {
          BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD WRITE : OK.", LEFT_MODE);
          SD_state = BSP_SD_ReadBlocks((uint32_t *)aRxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS);
          if(SD_state != MSD_OK)
          {
            BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD READ : FAILED.", LEFT_MODE);
            BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
          }
          else
          {
            BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD READ : OK.", LEFT_MODE);
            if(Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) > 0)
            {
              BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD COMPARE : FAILED.", LEFT_MODE);
              BSP_LCD_DisplayStringAt(20, 190, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
            }
            else
            {
              BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD TEST : OK.", LEFT_MODE);
            }
          }
        }
      }
    }
  }
  
  while (1)
  {
    /* Check if the SD card is plugged in the slot */
    if(BSP_SD_IsDetected() != SD_PRESENT)
    {
      if(prev_status == 0)
      {
        prev_status = 1; 
        BSP_LCD_SetTextColor(LCD_COLOR_RED);
        BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Not Connected", LEFT_MODE);
      }
    }
    else if (prev_status == 1)
    {
      BSP_SD_Init();
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Connected    ", LEFT_MODE);
      prev_status = 0;
    }
    
    if(CheckForUserInput() > 0)
    {
      return;
    }
  }
}
示例#19
0
/**
* @brief  QSPI Demo
* @param  None
* @retval None
*/
void QSPI_demo (void)
{ 
  /* QSPI info structure */
  static QSPI_Info pQSPI_Info;
  uint8_t status;
  
  QSPI_SetHint();
  
  /*##-1- Configure the QSPI device ##########################################*/
  /* QSPI device configuration */ 
  status = BSP_QSPI_Init();
  
  if (status == QSPI_NOT_SUPPORTED)
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t*)"QSPI Initialization : FAILED.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 145, (uint8_t*)"Check the hardware configuration :", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 160, (uint8_t*)"  refer to the UM of the board", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 175, (uint8_t*)"  for the hardware modifications", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 190, (uint8_t*)"  to connect the QSPI memory", LEFT_MODE);
  }
  else if (status == QSPI_ERROR)
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t*)"QSPI Initialization : FAILED.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t*)"QSPI Initialization : OK.", LEFT_MODE);
    
    /*##-2- Read & check the QSPI info #######################################*/
    /* Initialize the structure */
    pQSPI_Info.FlashSize        = (uint32_t)0x00;
    pQSPI_Info.EraseSectorSize    = (uint32_t)0x00;
    pQSPI_Info.EraseSectorsNumber = (uint32_t)0x00;
    pQSPI_Info.ProgPageSize       = (uint32_t)0x00;
    pQSPI_Info.ProgPagesNumber    = (uint32_t)0x00;
    
    /* Read the QSPI memory info */
    BSP_QSPI_GetInfo(&pQSPI_Info);
    
    /* Test the correctness */
    if((pQSPI_Info.FlashSize != 0x2000000) || (pQSPI_Info.EraseSectorSize != 0x1000)  || 
       (pQSPI_Info.ProgPageSize != 0x100)  || (pQSPI_Info.EraseSectorsNumber != 8192) ||
       (pQSPI_Info.ProgPagesNumber != 131072))
    {
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI GET INFO : FAILED.", LEFT_MODE);
      BSP_LCD_DisplayStringAt(20, 130, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t*)"QSPI GET INFO : OK.   ", LEFT_MODE);
      
      /*##-3- Erase QSPI memory ################################################*/ 
      if(BSP_QSPI_Erase_Block(WRITE_READ_ADDR) != QSPI_OK)
      {
        BSP_LCD_DisplayStringAt(20, 130, (uint8_t*)"QSPI ERASE : FAILED.", LEFT_MODE);
        BSP_LCD_DisplayStringAt(20, 145, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
      }
      else
      {
        BSP_LCD_DisplayStringAt(20, 130, (uint8_t*)"QSPI ERASE : OK.   ", LEFT_MODE);
        
        /*##-4- QSPI memory read/write access  #################################*/   
        /* Fill the buffer to write */
        Fill_Buffer(qspi_aTxBuffer, BUFFER_SIZE, 0xD20F);   
        
        /* Write data to the QSPI memory */
        if(BSP_QSPI_Write(qspi_aTxBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != QSPI_OK)
        {
          BSP_LCD_DisplayStringAt(20, 145, (uint8_t*)"QSPI WRITE : FAILED.", LEFT_MODE);
          BSP_LCD_DisplayStringAt(20, 160, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
        }
        else
        {
          BSP_LCD_DisplayStringAt(20, 145, (uint8_t*)"QSPI WRITE : OK.     ", LEFT_MODE);
          
          /* Read back data from the QSPI memory */
          if(BSP_QSPI_Read(qspi_aRxBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != QSPI_OK)
          {
            BSP_LCD_DisplayStringAt(20, 160, (uint8_t*)"QSPI READ : FAILED.", LEFT_MODE);
            BSP_LCD_DisplayStringAt(20, 175, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
          }
          else
          {
            BSP_LCD_DisplayStringAt(20, 160, (uint8_t*)"QSPI READ :  OK.    ", LEFT_MODE);
            
            /*##-5- Checking data integrity ############################################*/  
            if(Buffercmp(qspi_aRxBuffer, qspi_aTxBuffer, BUFFER_SIZE) > 0)
            {
              BSP_LCD_DisplayStringAt(20, 175, (uint8_t*)"QSPI COMPARE : FAILED.", LEFT_MODE);
              BSP_LCD_DisplayStringAt(20, 190, (uint8_t*)"QSPI Test Aborted.", LEFT_MODE);
            }
            else
            {    
              BSP_LCD_DisplayStringAt(20, 175, (uint8_t*)"QSPI Test : OK.     ", LEFT_MODE);
            }  
          }
        }
      }
    }
  }
  
  while (1)
  {    
    if(CheckForUserInput() > 0)
    {
      BSP_QSPI_DeInit();
      return;
    }
  }
}
示例#20
0
/**
 * @brief  Main program
 * @param  None
 * @retval None
 */
int main(void)
{
  uint8_t  lcd_status = LCD_OK;
  uint8_t  sdram_status = SDRAM_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 MFX */
  BSP_IO_Init();

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

  /* Configure Tamper push-button */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);

  /* Initialize the SDRAM */
  sdram_status = BSP_SDRAM_Init();
  OnError_Handler(sdram_status != SDRAM_OK);



  /*##-1- Initialize the LCD depending on 'lcd_mode' #################################################*/

  /* Get DSI configuration for mode Video Burst  */
  lcd_status = BSP_LCD_Init();
  OnError_Handler(lcd_status != LCD_OK);

  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);
      
      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);
      
      /* Switch On bit LTDCEN */
      __HAL_LTDC_ENABLE(&hltdc_eval); 

      /* Display On with ULPM exit Data lane only integrated */
      BSP_LCD_DisplayOn();      
    }
  }
}
示例#21
0
文件: sd.c 项目: z80/stm32f429
/**
  * @brief  SD Demo
  * @param  None
  * @retval None
  */
void SD_demo(void)
{ 
  uint8_t SD_state = MSD_OK;
  static uint8_t prev_status = 0; 
  
  SD_SetHint();
  SD_state = BSP_SD_Init();
  
  if(SD_state != MSD_OK)
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD Initialization : FAIL.", LEFT_MODE);
    BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
  }
  else
  {
    BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD Initialization : OK.", LEFT_MODE);
    
    SD_state = BSP_SD_Erase(BLOCK_START_ADDR, (BLOCKSIZE * NUM_OF_BLOCKS));
    
    if(SD_state != MSD_OK)
    {
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD ERASE : FAILED.", LEFT_MODE);
      BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD ERASE : OK.", LEFT_MODE);
      
      /* Fill the buffer to write */
      Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF);
      SD_state = BSP_SD_WriteBlocks(aTxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS);
      
      if(SD_state != MSD_OK)
      {
        BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD WRITE : FAILED.", LEFT_MODE);
        BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
      }
      else
      {
        BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD WRITE : OK.", LEFT_MODE);
        SD_state = BSP_SD_ReadBlocks(aRxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS);
        if(SD_state != MSD_OK)
        {
          BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD READ : FAILED.", LEFT_MODE);
          BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
        }
        else
        {
          BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD READ : OK.", LEFT_MODE);
          if(Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) > 0)
          {
            BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD COMPARE : FAILED.", LEFT_MODE);
            BSP_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD Test Aborted.", LEFT_MODE);
          }
          else
          {
            BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD Test : OK.", LEFT_MODE);
          }
        }
      }
    }
  }
  
  /* Check if the SD card is plugged in the slot */
  if(BSP_SD_IsDetected() == SD_PRESENT)
  {
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Connected    ", LEFT_MODE);
  }
  else 
  {
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30,   (uint8_t *)"SD Not Connected", LEFT_MODE);
  }
  
  
  while (1)
  {
    /* Check if the SD card is plugged in the slot */
    if(BSP_SD_IsDetected() != SD_PRESENT)
    {
      if(prev_status == 0)
      {
        BSP_SD_Init();
        prev_status = 1; 
        BSP_LCD_SetTextColor(LCD_COLOR_RED);
        BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Not Connected", LEFT_MODE);
      }
    }
    else if (prev_status == 1)
    {
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30,   (uint8_t *)"SD Connected    ", LEFT_MODE);
      prev_status = 0;
    }
    
    if(CheckForUserInput() > 0)
    {
      return;
    }
  }
}
示例#22
0
文件: audio.c 项目: z80/stm32f429
/**
  * @brief  Audio Play demo
  * @param  None
  * @retval None
  */
void AudioPlay_demo (void)
{ 
  uint32_t *AudioFreq_ptr;
  uint8_t status = 0;
  uint8_t FreqStr[256] = {0};
 
  AudioFreq_ptr = AudioFreq+6; /*AF_48K*/
  uwPauseEnabledStatus = 1; /* 0 when audio is running, 1 when Pause is on */
  uwVolume = 50;

  Audio_SetHint();
    
  status = BSP_JOY_Init(JOY_MODE_GPIO);

  if (status != IO_OK)
  {    
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE); 
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 100, (uint8_t *)"ERROR", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 85, (uint8_t *)"Joystick cannot be initialized", CENTER_MODE);
  }

  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_BOTH, uwVolume, *AudioFreq_ptr) == 0)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 100, (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()- 100, (uint8_t *)"  AUDIO CODEC  FAIL ", CENTER_MODE);
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 85, (uint8_t *)" Try to reset board ", 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 
  (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()...
  */
  AUDIO_Start();

  /* 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()- 85, (uint8_t *)"       PLAYING...     ", CENTER_MODE);

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

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

  /* IMPORTANT:
     AUDIO_Process() is called by the SysTick Handler, as it should be called 
     within a periodic process */

  /* Infinite loop */
  while(1)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
    /* Get the Joystick State */
    JoyState = BSP_JOY_GetState();

    switch(JoyState)
    {
      case JOY_UP:
        /* Increase volume by 5% */
        if (uwVolume < 95)
          uwVolume += 5;
        else
          uwVolume = 100;
          sprintf((char*)FreqStr,"       VOL:    %lu     ",uwVolume);
          BSP_AUDIO_OUT_SetVolume(uwVolume);
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 55, (uint8_t *)FreqStr, CENTER_MODE);
          BSP_LCD_DisplayStringAt(0, LINE(14), (uint8_t *)"                      ", CENTER_MODE);
        break;

      case JOY_DOWN:
        /* Decrease volume by 5% */
        if (uwVolume > 5)
          uwVolume -= 5;
        else
          uwVolume = 0;
          sprintf((char*)FreqStr,"       VOL:    %lu     ",uwVolume);
          BSP_AUDIO_OUT_SetVolume(uwVolume);
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 55, (uint8_t *)FreqStr, CENTER_MODE);
          BSP_LCD_DisplayStringAt(0, LINE(14), (uint8_t *)"                      ", CENTER_MODE);
        break;

      case JOY_LEFT:
        /*Decrease Frequency */
          if (*AudioFreq_ptr != 8000)
          {
            AudioFreq_ptr--;
            sprintf((char*)FreqStr,"      FREQ: %lu     ", *AudioFreq_ptr);
            BSP_AUDIO_OUT_Pause();
            BSP_AUDIO_OUT_SetFrequency(*AudioFreq_ptr);
            BSP_AUDIO_OUT_Resume();
          }
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 40, (uint8_t *)FreqStr, CENTER_MODE);
          BSP_LCD_DisplayStringAt(0, LINE(14), (uint8_t *)"                      ", CENTER_MODE);
        break;

      case JOY_RIGHT:
        /* Increase Frequency */
          if (*AudioFreq_ptr != 96000)
          {
            AudioFreq_ptr++;
            sprintf((char*)FreqStr,"      FREQ: %lu     ",*AudioFreq_ptr);
            BSP_AUDIO_OUT_Pause();
            BSP_AUDIO_OUT_SetFrequency(*AudioFreq_ptr);
            BSP_AUDIO_OUT_Resume();
          }
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 40, (uint8_t *)FreqStr, CENTER_MODE);
          BSP_LCD_DisplayStringAt(0, LINE(14), (uint8_t *)"                      ", CENTER_MODE);
        break;

      case JOY_SEL:
        /* Set Pause / Resume */
        if (uwPauseEnabledStatus == 1)
        { /* Pause is enabled, call Resume */
          BSP_AUDIO_OUT_Resume();
          uwPauseEnabledStatus = 0;
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 85, (uint8_t *)"       PLAYING...     ", CENTER_MODE);
        } else
        { /* Pause the playback */
          BSP_AUDIO_OUT_Pause();
          uwPauseEnabledStatus = 1;
          BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 85, (uint8_t *)"       PAUSE  ...     ", CENTER_MODE);
        }
        BSP_LCD_DisplayStringAt(0, LINE(14), (uint8_t *)"                      ", CENTER_MODE);
        HAL_Delay(200);
        break;
        
      default:
        break;
    }
    
    /* Toggle LED3 */
    BSP_LED_Toggle(LED3);

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

    /* Toggle LED2 */
    BSP_LED_Toggle(LED2);

    /* Insert 100 ms delay */
    HAL_Delay(100);
    if(CheckForUserInput() > 0)
    {
      BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
      BSP_AUDIO_OUT_DeInit();
      return;
    }
  }
}