예제 #1
0
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
  /* Check if the audio player state has changed */
  if (PrevState != AUDIO_OUT_fops.GetState())
  {
    /* Information panel */
    LCD_SetTextColor(Green);
    LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 48, USER_INFORMATION1[AUDIO_OUT_fops.GetState()]);  
    LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR);
    
    /* Update the previous state variable */
    PrevState = AUDIO_OUT_fops.GetState();
  }
  
  if (OutputState != PrevOutput)
  {
    Codec_SwitchOutput(OutputState);
    PrevOutput = OutputState;
    
    /* Information panel */
    LCD_SetTextColor(Green);
    if (OutputState == OUTPUT_DEVICE_HEADPHONE)
    {
      LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 32, USER_INFORMATION2[0]);
    }
    else
    {
      LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 32, USER_INFORMATION2[1]);
    }
    LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); 
  }
}
예제 #2
0
void SysTick_Handler(void)
{
  clock++;
  if (OutputState != PrevOutput)
  {
    Codec_SwitchOutput(OutputState);
    PrevOutput = OutputState;
  }
}
예제 #3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{ 
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
  
  /* Initialize LEDs, Key Button, LCD available on
     STM324xG-EVAL board ******************************************************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Initialize the Push buttons */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);     /* Key button for Pause/Resume */
  STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_GPIO);  /* Key button for Volume High */
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO);  /* Key button for Volume Low */
    
  /* Initialize the LCD */
  STM324xG_LCD_Init();
  
  /* Display message on STM324xG-EVAL LCD *************************************/
  /* Clear the LCD */ 
  LCD_Clear(LCD_COLOR_BLUE);  

  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  LCD_DisplayStringLine(Line0, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line2, MESSAGE3);

  /* Turn on leds available on STM324xG-EVAL **********************************/
  STM_EVAL_LEDOn(LED1);
  STM_EVAL_LEDOn(LED2);
  STM_EVAL_LEDOn(LED3);
  STM_EVAL_LEDOn(LED4);

  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

  /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */  
  if (EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, volume, I2S_AudioFreq_48k) == 0)
  {
    LCD_DisplayStringLine(Line3, "====================");
    LCD_DisplayStringLine(Line4, "Key   : Play/Pause ");
    LCD_DisplayStringLine(Line5, "Tamper: Vol+/Headph");
    LCD_DisplayStringLine(Line6, "Wakeup: Vol-/Spkr  ");
    LCD_DisplayStringLine(Line7, "====================");
    LCD_DisplayStringLine(Line8, "  AUDIO CODEC   OK  ");    
  }
  else
  {
    LCD_DisplayStringLine(Line4, "  AUDIO CODEC  FAIL ");
    LCD_DisplayStringLine(Line5, " Try to reset board ");
  }
  
  
  /* 
  Normal mode description:
      Start playing the audio file (using DMA stream) .
      Using this mode, the application can run other tasks in parallel since 
      the DMA is handling the Audio Transfer instead of the CPU.
      The only task remaining for the CPU will be the management of the DMA 
      Transfer Complete interrupt or the Half Transfer Complete interrupt in 
      order to load again the buffer and to calculate the remaining data.  
  Circular mode description:
     Start playing the file from a circular buffer, once the DMA is enabled it 
     always run. User has to fill periodically 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()...
     In this case the audio data file is smaller than the DMA max buffer 
     size 65535 so there is no need to load buffer continuously or manage the 
     transfer complete or Half transfer interrupts callbacks. */
  EVAL_AUDIO_Play((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS), (AUDIO_FILE_SZE - AUIDO_START_ADDRESS));
 
  /* Display the state on the screen */
  LCD_DisplayStringLine(Line8, "       PLAYING      ");
  
  /* Infinite loop */
  while (1)
  {    
    /* Check on the Pause/Resume button */
    if (STM_EVAL_PBGetState(BUTTON_KEY) != Bit_SET)
    {
      /* wait to avoid rebound */
      while (STM_EVAL_PBGetState(BUTTON_KEY) != Bit_SET);
      
      EVAL_AUDIO_PauseResume(cmd);
      if (cmd == AUDIO_PAUSE)
      {
        /* Display the current state of the player */
        LCD_DisplayStringLine(Line8, "       PAUSED       ");
        
        /* Next time Resume command should be processed */
        cmd = AUDIO_RESUME;
        
        /* Push buttons will be used to switch between Speaker and Headphone modes */
        SpHpSwitch = 1;
      }
      else
      {
        /* Display the current state of the player */
        LCD_DisplayStringLine(Line8, "       PLAYING      ");
        
        /* Next time Pause command should be processed */
        cmd = AUDIO_PAUSE;
        
        /* Push buttons will be used to control volume level */
        SpHpSwitch = 0;
      }
    }
    
    /* Check on the Volume high button */
    if (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET)
    {
      /* Check if the current state is paused (push buttons are used for volume control or for 
         speaker/headphone mode switching) */
      if (SpHpSwitch)
      {
        /* Set output to Speaker */
        Codec_SwitchOutput(OUTPUT_DEVICE_SPEAKER);
        
        /* Display the current state of the player */
        LCD_DisplayStringLine(Line9, "       SPEAKER      ");
      }
      else
      {
        /* wait to avoid rebound */
        while (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET);
        
        /* Decrease volume by 5% */
        if (volume > 5)
          volume -= 5; 
        else
          volume = 0; 
        
        /* Apply the new volume to the codec */
        EVAL_AUDIO_VolumeCtl(volume);
        LCD_DisplayStringLine(Line9, "       VOL:   -     ");
      }
    }    
    
    /* Check on the Volume high button */
    if (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET)
    {
      /* Check if the current state is paused (push buttons are used for volume control or for 
         speaker/headphone mode switching) */
      if (SpHpSwitch)
      {
        /* Set output to Headphone */
        Codec_SwitchOutput(OUTPUT_DEVICE_HEADPHONE);
        
        /* Display the current state of the player */
        LCD_DisplayStringLine(Line9, "      HEADPHONE     ");
      }
      else
      {
        /* wait to avoid rebound */
        while (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET);
        
        /* Increase volume by 5% */
        if (volume < 95)
          volume += 5; 
        else
          volume = 100; 
        
        /* Apply the new volume to the codec */
        EVAL_AUDIO_VolumeCtl(volume);
        LCD_DisplayStringLine(Line9, "       VOL:   +     ");  
      }
    }  
    
    /* Toggle LD4 */
    STM_EVAL_LEDToggle(LED3);

    /* Insert 50 ms delay */
    Delay(5);

    /* Toggle LD2 */
    STM_EVAL_LEDToggle(LED2);

    /* Insert 50 ms delay */
    Delay(5);
  }
}