📄 waveplayer.c
字号:
/******************** (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 "main.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define REPLAY 3
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u8 DemoTitle[20] = "STM32 I2S Codec Demo";
u8 CmdTitle0[20] = " Control Buttons: ";
u8 CmdTitle1Playing[20] = "KEY>Pause UP >Vol+";
u8 CmdTitle2Playing[20] = "SEL>Stop DOWN>Vol-";
u8 CmdTitle1Paused[20] = "KEY>Play UP >Spkr";
u8 CmdTitle2Paused[20] = "SEL>Stop DOWN>Head";
u8 CmdTitle1Stopped[20] = " UP > Speaker ";
u8 CmdTitle2Stopped[20] = " DOWN > Headphone ";
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;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* 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);
/* Disable the JoyStick interrupts */
IntExtOnOffConfig(DISABLE);
while(ReadKey() != NOKEY)
{
}
/* Display the welcome screen and the commands */
LCD_Update(ALL);
#if STM3210E
/* Choose number of repetitions: 0 => infinite repetitions */
I2S_CODEC_ReplayConfig(0);
I2S_CODEC_Init(OutputDevice_SPEAKER, AUDIO_FILE_ADDRESS);
#else
DAC_CODEC_Init(AUDIO_FILE_ADDRESS);
#endif
/* Endless loop */
while(1)
{
/* Check which key is pressed */
MyKey = ReadKey();
if(Counter == 0)
{ /* Mask All Interrupts */
NVIC_SETPRIMASK();
/* Update the displayed progression information */
LCD_Update(PROGRESS);
Counter = 0x5FFFF;
/* Disable mask of all interrupts */
NVIC_RESETPRIMASK();
}
Counter--;
/* If "UP" pushbutton is pressed */
if(MyKey == UP)
{
/* Mask All Interrupts */
NVIC_SETPRIMASK();
/* Check if the Codec is PLAYING audio file */
if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING)
{
#if STM3210E
I2S_CODEC_ControlVolume(VolumeDirection_HIGH, VOLStep);
#else
DAC_CODEC_ControlVolume(VolumeDirection_HIGH, VOLStep);
#endif
/* Update the display information */
LCD_Update(VOL);
}
/* UP bottomn pushed in PAUSE mode => Enable the Speaker device output ---*/
else
{
/* Update the display information */
LCD_Update(PLAY);
#if STM3210E
/* Configure the Speaker as output and reinitialize all devices */
err = I2S_CODEC_SpeakerHeadphoneSwap(OutputDevice_SPEAKER, AUDIO_FILE_ADDRESS);
#else
#endif
/* 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);
/* Display the previous menu */
DisplayMenu();
/* Disable mask of all interrupts */
NVIC_RESETPRIMASK();
/* Enable the JoyStick interrupts */
IntExtOnOffConfig(ENABLE);
return;
}
}
/* Disable mask of all interrupts */
NVIC_RESETPRIMASK();
}
/* If "DOWN" pushbutton is pressed */
if(MyKey == DOWN)
{
/* Mask All Interrupts */
NVIC_SETPRIMASK();
/* If the Codec is PLAYING => Decrease Volume*/
if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING)
{
#if STM3210E
/* Increase the audio codec digital volume */
I2S_CODEC_ControlVolume(VolumeDirection_LOW, VOLStep);
#else
DAC_CODEC_ControlVolume(VolumeDirection_LOW, VOLStep);
#endif
/* Update the LCD display */
LCD_Update(VOL);
}
else /* If the Codec is PAUSED => Headphone Enable */
{
/* Update the LCD display */
LCD_Update(PLAY);
#if STM3210E
/* Enable the Headphone output and reinitialize all devices */
err = I2S_CODEC_SpeakerHeadphoneSwap(OutputDevice_HEADPHONE, AUDIO_FILE_ADDRESS);
#endif
/* 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);
/* Display the previous menu */
DisplayMenu();
/* Disable mask of all interrupts */
NVIC_RESETPRIMASK();
/* Enable the JoyStick interrupts */
IntExtOnOffConfig(ENABLE);
return;
}
}
/* Disable mask of all interrupts */
NVIC_RESETPRIMASK();
}
/* If "RIGHT" pushbutton is pressed */
if(MyKey == RIGHT)
{
/* Mask All Interrupts */
NVIC_SETPRIMASK();
/* Check if the Codec is PLAYING audio file */
if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING)
{
#if STM3210E
I2S_CODEC_ForwardPlay(STEP_FORWARD);
#else
DAC_CODEC_ForwardPlay(STEP_FORWARD);
#endif
/* Update the display information */
LCD_Update(FRWD);
}
/* Disable mask of all interrupts */
NVIC_RESETPRIMASK();
}
/* If "LEFT" pushbutton is pressed */
if(MyKey == LEFT)
{
/* Mask All Interrupts */
NVIC_SETPRIMASK();
/* Check if the Codec is PLAYING audio file */
if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING)
{
#if STM3210E
I2S_CODEC_RewindPlay(STEP_BACK);
#else
DAC_CODEC_RewindPlay(STEP_BACK);
#endif
/* Update the display information */
LCD_Update(FRWD);
}
/* Disable mask of all interrupts */
NVIC_RESETPRIMASK();
}
/* If "SEL" pushbutton is pressed */
if(MyKey == SEL)
{
/* Mask All Interrupts */
NVIC_SETPRIMASK();
/* Update the display information */
LCD_Update(STOP);
/* Command the Stop of the current audio stream */
SetVar_AudioPlayStatus(AudioPlayStatus_STOPPED);
/* Disable mask of all interrupts */
NVIC_RESETPRIMASK();
#if STM3210E
I2S_CODEC_Stop();
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, DISABLE);
#else
DAC_CODEC_Stop();
#endif
/* Enable the FSMC that share a pin w/ I2C1 (LBAR) */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/* Clear the LCD */
LCD_Clear(White);
/* Display the previous menu */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -