⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waveplayer.c

📁 基于KEIL RVMDK开发环境的和基于ST公司的STM32系列MCU在音频方面的应用源代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name          : waveplayer.c
* Author             : MCD Application Team
* Version            : V1.1.1
* Date               : 06/13/2008
* Description        : Wave Player driver source file.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "waveplayer.h"
#include "lcd.h"
#include <stdio.h>

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define REPLAY  3

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u8 DemoTitle1[20] = "   EM_STM32E Demo   "; 
u8 DemoTitle2[20] = "     AUDIO_Test     ";
u8 CmdTitle0[20] = "  Control Buttons:  "; 
u8 CmdTitle1[20] = "    Progress bar    "; 

u8 CmdTitle1Playing[20] = "USER>Pause  UP >Vol+";

u8 CmdTitle2Playing[20] = "SEL>Stop   DOWN>Vol-";

u8 CmdTitle3Playing[20] = "LEFT>FRWD RIGHT>BACK";

u8 CmdTitle1Paused[20] =  "USER>Play  UP  >Spkr";

u8 CmdTitle2Paused[20] =  "SEL>Stop   DOWN>Spkr";

u8 CmdTitle1Stopped[20] = "    UP > Speaker    "; 

u8 CmdTitle2Stopped[20] = "  line 6 is status  ";
  
u8 StatusTitleStopped[20] = "      Stopped       ";

u8 StatusTitlePlaying[20] = "      Playing       ";

u8 StatusTitlePaused[20] = "       Paused       ";

u8 i2cerr[20] =  "ERROR:I2C com. ->RST";
u8 memerr[20] =  "ERROR: Memory  ->RST";
u8 fileerr[20] = "ERROR: No Wave File ";

static u8 previoustmp = 50;
static u8 player = 0;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : ReadKey
* Description    : Reads key from demoboard.
* Input          : None
* Output         : None
* Return         : Return RIGHT, LEFT, SEL, UP, DOWN or NOKEY
*******************************************************************************/
u8 ReadKey(void)
{
  /* "right" key is pressed */
  if(!GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_13))
  {
    while(GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_13) == Bit_RESET)
    {
    } 
    return RIGHT; 
  }	
  /* "left" key is pressed */
  if(!GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_14))
  {
    while(GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_14) == Bit_RESET)
    {
    }
    return LEFT; 
  }
  /* "up" key is pressed */
  if(!GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_15))
  {
    while(GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_15) == Bit_RESET)
    {
    }
    return UP; 
  }
  /* "down" key is pressed */
  if(!GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3))
  {
    while(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_3) == Bit_RESET)
    {
    } 
    return DOWN; 
  }
  /* "sel" key is pressed */
  if(!GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_7))
  {
    while(GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7) == Bit_RESET)
    {
    } 
    return SEL; 
  }
  /* "KEY" key is pressed */
  if(!GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_8))
  {
    while(GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_8) == Bit_RESET)
    {
    } 
    return KEY; 
  }
  /* No key is pressed */
  else 
  {
    return NOKEY;
  }
}


/*******************************************************************************
* Function Name  : WavePlayer_StartSpeaker
* Description    : Starts the wave player application.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void WavePlayer_StartSpeaker(void)
{
  u8 MyKey = 0;
  u32 err = 0, Counter = 0x0;

  LCD_Clear(White);

  while(ReadKey() != NOKEY)
  {
  }  

  /* Display the welcome screen and the commands */
  LCD_Update(ALL);

  DAC_CODEC_Init(AUDIO_FILE_ADDRESS);


  /* Endless loop */
  while(1)
  {
    /* Check which key is pressed */
    MyKey = ReadKey();
   
    player = 0; /* initial player */    

    if(Counter == 0)
    { 
      /* Update the displayed progression information */
      LCD_Update(PROGRESS);
      Counter = 0x5FFFF;
    }
    Counter--;
    /* If "UP" pushbutton is pressed */
    if(MyKey == UP)
    {
      /* Check if the Codec is PLAYING audio file */
      if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING)
      {
         DAC_CODEC_ControlVolume(VolumeDirection_HIGH, VOLStep);
         /* Update the display information */
		 player = 0; /*NOW PLAYING*/
         LCD_Update(VOL);
      }
      /* UP bottomn pushed in PAUSE mode => Enable the Speaker device output ---*/
      else
      {
	    player = 1;	 /*now STOPPED*/
        /* Update the display information */
        LCD_Update(PLAY); 
        /* Error message display if failure */
        if (err != 0)
        {
          LCD_DisplayError(err);

          /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */
          RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

          /* Clear the LCD */
          LCD_Clear(White);

          return; 
        }      
      } 
    }

    /* If "DOWN" pushbutton is pressed */
    if(MyKey == DOWN)
    {
      /* If the Codec is PLAYING => Decrease Volume*/
      if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING)
      {
        DAC_CODEC_ControlVolume(VolumeDirection_LOW, VOLStep);
		player = 0; /*NOW PLAYING*/
        /* Update the LCD display */ 
        LCD_Update(VOL); 
      }
      else /* If the Codec is PAUSED => UPDATE PLAY MENU */
      {
        /* Update the LCD display */ 
		player = 1; /*NOW STOPPED*/
        LCD_Update(PLAY);
        /* Error message display if failure */
        if (err != 0)
        {
          LCD_DisplayError(err);

          /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */
          RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

          /* Clear the LCD */
          LCD_Clear(White);

          return; 
        }  
      }
    }

    /* If "RIGHT" pushbutton is pressed */
    if(MyKey == RIGHT)
    {
      /* Check if the Codec is PLAYING audio file */
      if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING)
      {
        DAC_CODEC_ForwardPlay(STEP_FORWARD); 
        /* Update the display information */
        LCD_Update(FRWD); 
      }
    }
    /* If "LEFT" pushbutton is pressed */
    if(MyKey == LEFT)
    {
      /* Check if the Codec is PLAYING audio file */
      if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING)
      {
        DAC_CODEC_RewindPlay(STEP_BACK);
        /* Update the display information */
        LCD_Update(FRWD);  
      } 
    }

    /* If "SEL" pushbutton is pressed */
    if(MyKey == SEL)
    {
      /* Update the display information */
      LCD_Update(STOP);

      /* Command the Stop of the current audio stream */
      SetVar_AudioPlayStatus(AudioPlayStatus_STOPPED);

      DAC_CODEC_Stop();

      /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */
      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

      /* Clear the LCD */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -