📄 voicerecorder.c
字号:
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : voicerecorder.c
* Author : MCD Application Team
* Date First Issued : mm/dd/yyyy
* Description : This file includes the voice recorder driver for the
* STR91x-EVAL demonstration.
********************************************************************************
* History:
* mm/dd/yyyy
********************************************************************************
* THE PRESENT SOFTWARE 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 SOFTWARE 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 ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Peripherals InitStructure define */
extern GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
TIM_InitTypeDef TIM_InitStructure;
extern vu8 SelectedWave; /* Osiris or recorded wave playing select */
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : VoiceRec_Init
* Description : Initialize
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void VoiceRec_Init(void)
{
/* ADC Channel 7 pin configuration */
GPIO_ANAPinConfig(GPIO_ANAChannel7, ENABLE);
TIM_StructInit(&TIM_InitStructure);
/* 22.050 KHz generation */
TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;
TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;
TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
TIM_InitStructure.TIM_Prescaler = 0x1;
TIM_InitStructure.TIM_Pulse_Length_1 = 0x440;
/* Initialize the Timer 1 */
TIM_Init (TIM1, &TIM_InitStructure);
/* ADC configuration */
/* ADC Structure Initialization */
ADC_StructInit(&ADC_InitStructure);
/* Configure the ADC in continuous mode conversion */
ADC_InitStructure.ADC_Channel_7_Mode = ADC_NoThreshold_Conversion;
ADC_InitStructure.ADC_Select_Channel = ADC_Channel_7;
ADC_InitStructure.ADC_Scan_Mode = DISABLE;
ADC_InitStructure.ADC_Conversion_Mode = ADC_Continuous_Mode;
/* Enable the ADC */
ADC_Cmd(ENABLE);
/* Prescaler config */
ADC_PrescalerConfig(0x0);
/* Configure the ADC */
ADC_Init(&ADC_InitStructure);
}
/*******************************************************************************
* Function Name : VoiceRec_Start
* Description : Start Voice recording
* Input : None
* Output : None
* Return : None.
*******************************************************************************/
void VoiceRec_Start(void)
{
/* Start the conversion */
ADC_ConversionCmd(ADC_Conversion_Start);
/* Enable TIM0 update interrupt */
TIM_ITConfig(TIM1, TIM_IT_OC1, ENABLE);
/* Start the Timer counter */
TIM_CounterCmd(TIM1, TIM_START);
/* Displayed when recording: to stop recording*/
LCD_DisplayString(Line2, "Stop: in 30s/KEY ", BlackText);
}
/*******************************************************************************
* Function Name : VoiceRec_Stop
* Description : Stop Voice recording
* Input : None
* Output : None
* Return : None.
*******************************************************************************/
void VoiceRec_Stop(void)
{
/* Disable TIM0 update interrupt */
TIM_ITConfig(TIM1, TIM_IT_OC1, DISABLE);
/* Stop the Timer counter */
TIM_CounterCmd(TIM1, TIM_STOP);
/* Stop conversion */
ADC_ConversionCmd(ADC_Conversion_Stop);
/* Display " Voice REC Start " to start recording */
LCD_DisplayString(Line2, " Voice REC Start ", BlackText);
}
/*******************************************************************************
* Function Name : VoiceRec_SSPFLASHErase
* Description : Erase the SSP FLASH sectors reserved for voice recording
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void VoiceRec_SSPFLASHErase(void)
{
u32 Sect = 0;
u8 i = 0;
/* Stop wave playing: protect the dual SMI Flash access */
WavePlayer_Stop();
/* Display SMI erasing message */
LCD_DisplayString(Line2, "Wait FLASH erase", BlackText);
/* Erase the sector to write on */
for(i = 0; i < 11; i++)
{
SSP_FLASH_SectorErase(Sect);
Sect += 0x10000;
}
/* Display message to start voice recording */
LCD_DisplayString(Line2, "Record:Press KEY", BlackText);
}
/*******************************************************************************
* Function Name : VoiceRec_GlobalVarReset
* Description : Resets the global variable SelectedWave.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void VoiceRec_GlobalVarReset(void)
{
/* Reset SelectedWave for voice recording */
SelectedWave = 0;
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -