#include "LD3320_BSP.h"
#include "User.h"//关键字的识别在这文件中
/*-------------------globle variable------------------------------------------*/
uint8 nLD_Mode = LD_MODE_IDLE; // 用来记录当前是在进行ASR识别还是在播放MP3
uint8 ucRegVal; //识别的值
uint8 nAsrStatus=0;
int Discern;//语音识别状态标志位,在中断置1,在外面再语音识别,识别后置0
int Mp3Play;//MP3播放状态标志位,在产生音乐中断置1,在外面再播放音乐,音乐播放完置0
uint8_t ucHighInt;
uint8_t ucLowInt;
uint8_t bMp3Play=0; // 用来记录播放MP3的状态
u32 nMp3Size=0;
u32 nMp3Pos=0;
uint8_t ucSPVol=10; // MAX=15 MIN=0 // Speaker喇叭输出的音量
extern LD_CMD_TypeDef LD3320_CMD; //命令数组 指针 索引
#if FATFS_ENABLE
static FIL fsrc;
#else
char* nMp3Data;
#endif
static void LD3320_GPIO_Cfg(void)
{
GPIO_InitTypeDef GPIO_InitStuct;
RCC_APB2PeriphClockCmd(LD_CS_CLK|LD_WR_CLK |LD_RST_CLK,ENABLE);
#if SOFT_LPT
RCC_APB2PeriphClockCmd(LD_LPT_CLK | LD_A0_CLK | LD_RD_CLK ,ENABLE);
GPIO_InitStuct.GPIO_Pin=LD_LPT_DATA_PIN;
GPIO_InitStuct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStuct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(LD_LPT_DATA_PORT,&GPIO_InitStuct);
//RD
GPIO_InitStuct.GPIO_Pin=LD_RD_PIN;
GPIO_InitStuct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStuct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(LD_RD_PORT,&GPIO_InitStuct);
///A0
GPIO_InitStuct.GPIO_Pin=LD_A0_PIN;
GPIO_InitStuct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStuct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(LD_A0_PORT,&GPIO_InitStuct);
#endif
GPIO_InitStuct.GPIO_Pin=LD_CS_PIN;
GPIO_InitStuct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStuct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(LD_CS_PORT,&GPIO_InitStuct);
GPIO_InitStuct.GPIO_Pin=LD_WR_PIN;
GPIO_InitStuct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStuct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(LD_WR_PORT,&GPIO_InitStuct);
GPIO_InitStuct.GPIO_Pin=LD_RST_PIN;
GPIO_InitStuct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStuct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(LD_RST_PORT,&GPIO_InitStuct);
}
#if SOFT_LPT
void LD_WriteReg( unsigned char address, unsigned char data )
{
#if GPIO_L
LD_LPT_DATA_PORT->CRL=0x33333333;
#else
LD_LPT_DATA_PORT->CRH=0x33333333;
#endif
//LD_RD(1);
LD_RD_PORT->BSRR = LD_RD_PIN;
//先把数据准备好,送入OI寄存器
#if GPIO_L
LD_LPT_DATA_PORT->ODR = ((LD_LPT_DATA_PORT->ODR&0xff00)|address);
#else
LD_LPT_DATA_PORT->ODR = ((LD_LPT_DATA_PORT->ODR&0x00ff)|(address<<8));
#endif
/*LD_A0(1);
LD_CS(0);
LD_WR(0);*/
LD_A0_PORT->BSRR = LD_A0_PIN;
LD_CS_PORT->BRR = LD_CS_PIN;
LD_WR_PORT->BRR = LD_WR_PIN;
//等待LD3320读走数据
/*LD_WR(1);
LD_CS(1);*/
LD_WR_PORT->BSRR = LD_WR_PIN;
LD_CS_PORT->BSRR = LD_CS_PIN;
//先把数据准备好,送入OI寄存器
#if GPIO_L
LD_LPT_DATA_PORT->ODR = ((LD_LPT_DATA_PORT->ODR&0xff00)|data);
#else
LD_LPT_DATA_PORT->ODR = ((LD_LPT_DATA_PORT->ODR&0x00ff)|(data<<8));
#endif
/*LD_A0(0);
LD_CS(0);
LD_WR(0);*/
LD_A0_PORT->BRR = LD_A0_PIN;
LD_CS_PORT->BRR = LD_CS_PIN;
LD_WR_PORT->BRR = LD_WR_PIN;
//等待LD3320读走数据
LD_RD_PORT->BSRR = LD_RD_PIN;
}
unsigned char LD_ReadReg(unsigned char address)
{
unsigned char data;
//LD_RD(1);
LD_RD_PORT->BSRR = LD_RD_PIN;
#if GPIO_L
LD_LPT_DATA_PORT->CRL=0x33333333;
#else
LD_LPT_DATA_PORT->CRH=0x33333333;
#endif
#if GPIO_L
LD_LPT_DATA_PORT->ODR = ((LD_LPT_DATA_PORT->ODR&0xff00)|address);
#else
LD_LPT_DATA_PORT->ODR = ((LD_LPT_DATA_PORT->ODR&0x00ff)|(address<<8));
#endif
/*LD_A0(1);
LD_CS(0);
LD_WR(0);*/
LD_A0_PORT->BSRR = LD_A0_PIN;
LD_CS_PORT->BRR = LD_CS_PIN;
LD_WR_PORT->BRR = LD_WR_PIN;
//等待LD3320读走数据
/*LD_WR(1);
LD_CS(1);*/
LD_WR_PORT->BSRR = LD_WR_PIN;
LD_CS_PORT->BSRR = LD_CS_PIN;
#if GPIO_L
LD_LPT_DATA_PORT->CRL=0x44444444;
#else
LD_LPT_DATA_PORT->CRH=0x44444444;
#endif
/*LD_A0(0);
LD_CS(0);
LD_RD(0);*/
LD_A0_PORT->BRR = LD_A0_PIN;
LD_CS_PORT->BRR = LD_CS_PIN;
LD_RD_PORT->BRR = LD_RD_PIN;//*/
//读取LD3320发过来的数据
data = LD_LPT_DATA_PORT->IDR;
#if GPIO_L
data=LD_LPT_DATA_PORT->IDR = ((LD_LPT_DATA_PORT->IDR->ODR&0x00ff));
#else
data= ((LD_LPT_DATA_PORT->IDR>>8));
#endif
/*LD_RD(1);
LD_CS(1);*/
LD_RD_PORT->BSRR = LD_RD_PIN;
LD_CS_PORT->BSRR = LD_CS_PIN;
return data;
}
#endif
#if HW_SPI
uint16_t SD_SPI_CR1=0x347,LD_SPI_CR1=0x346;
static void LD3320_SPI_cfg(void)
{
SD_SPI_CR1=SPI1->CR1;
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
#if LD3320_SPIx==1
#define LD_SPIx SPI1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOA,&GPIO_InitStructure);
SPI_Cmd(LD_SPIx, DISABLE);
#endif
#if LD3320_SPIx==2
#define LD_SPIx SPI2
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOB,&GPIO_InitStructure);
#endif
LD_CS(1);
SPI_Cmd(LD_SPIx, DISABLE);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //全双工
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //主模式
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //8位
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //时钟极性 空闲状态时,SCK保持低电平
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //时钟相位 数据采样从第一个时钟边沿开始
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //软件产生NSS
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; //波特率控制 SYSCLK/128
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //数据高位在前
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC多项式寄存器初始值为7
SPI_Init(LD_SPIx, &SPI_InitStructure);
SPI_Cmd(LD_SPIx, ENABLE);
}
unsigned char SPIx_RWByte(unsigned char byte)
{
//LD_SPIx->CR1 &= ~(0x1);
//LD_SPIx->CR1 |= (0x01<<6);
//LD_SPI_CR1
LD_SPIx->CR1=LD_SPI_CR1;
// 循环检测发送缓冲区是否是空
while(!(LD_SPIx->SR & 0x02));//非1
//通过SPI2外设发出数据
LD_SPIx->DR = byte;
// 等待接收数据,循环检查接收数据缓冲区
while(!(LD_SPIx->SR & 0x01));//非1
// 返回读出的数据
return LD_SPIx->DR ;
}
void LD_WriteReg( unsigned char address, unsigned char data )
{
LD_CS(OFF);
LD_WR(OFF);
SPIx_RWByte(0x04);
SPIx_RWByte(address);
SPIx_RWByte(data);
LD_WR(ON);
LD_CS(ON);
}
unsigned char LD_ReadReg(unsigned char address)
{
unsigned char redata;
LD_CS(OFF);
LD_WR(OFF);
SPIx_RWByte(0x05);
SPIx_RWByte(address);
redata=SPIx_RWByte(0x00); /*读SPI*/
LD_CS(ON);
return redata;
}
#endif
void LD3320_EXTI_Cfg(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(LD_IRQ_CLK, ENABLE);
GPIO_InitStructure.GPIO_Pin =LD_IRQ_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LD_IRQ_GPIO_PORT, &GPIO_InitStructure);
//外部中断线配置
GPIO_EXTIL