//播放音乐 void audio_play(void) { WM8978_ADDA_Cfg(1,0); //开启DAC WM8978_Input_Cfg(0,0,0);//关闭输入通道 WM8978_Output_Cfg(1,0); //开启DAC输出 audio_play_song("0:/wav/1.wav"); //播放这个音频文件 }
//播放音乐 void audio_play(void) { u8 res; DIR wavdir; //目录 FILINFO wavfileinfo;//文件信息 u8 *fn; //长文件名 u8 *pname; //带路径的文件名 u16 totwavnum; //音乐文件总数 u16 curindex; //图片当前索引 u8 key; //键值 u16 temp; u16 *wavindextbl; //音乐索引表 WM8978_ADDA_Cfg(1,0); //开启DAC WM8978_Input_Cfg(0,0,0);//关闭输入通道 WM8978_Output_Cfg(1,0); //开启DAC输出 while(f_opendir(&wavdir,"0:/MUSIC"))//打开音乐文件夹 { Show_Str(60,190,240,16,"MUSIC文件夹错误!",16,0); delay_ms(200); LCD_Fill(60,190,240,206,WHITE);//清除显示 delay_ms(200); } totwavnum=audio_get_tnum("0:/MUSIC"); //得到总有效文件数 while(totwavnum==NULL)//音乐文件总数为0 { Show_Str(60,190,240,16,"没有音乐文件!",16,0); delay_ms(200); LCD_Fill(60,190,240,146,WHITE);//清除显示 delay_ms(200); } wavfileinfo.lfsize=_MAX_LFN*2+1; //长文件名最大长度 wavfileinfo.lfname=mymalloc(SRAMIN,wavfileinfo.lfsize); //为长文件缓存区分配内存 pname=mymalloc(SRAMIN,wavfileinfo.lfsize); //为带路径的文件名分配内存 wavindextbl=mymalloc(SRAMIN,2*totwavnum); //申请2*totwavnum个字节的内存,用于存放音乐文件索引 while(wavfileinfo.lfname==NULL||pname==NULL||wavindextbl==NULL)//内存分配出错 { Show_Str(60,190,240,16,"内存分配失败!",16,0); delay_ms(200); LCD_Fill(60,190,240,146,WHITE);//清除显示 delay_ms(200); } //记录索引 res=f_opendir(&wavdir,"0:/MUSIC"); //打开目录 if(res==FR_OK) { curindex=0;//当前索引为0 while(1)//全部查询一遍 { temp=wavdir.index; //记录当前index res=f_readdir(&wavdir,&wavfileinfo); //读取目录下的一个文件 if(res!=FR_OK||wavfileinfo.fname[0]==0)break; //错误了/到末尾了,退出 fn=(u8*)(*wavfileinfo.lfname?wavfileinfo.lfname:wavfileinfo.fname); res=f_typetell(fn); if((res&0XF0)==0X40)//取高四位,看看是不是音乐文件 { wavindextbl[curindex]=temp;//记录索引 curindex++; } } } curindex=0; //从0开始显示 res=f_opendir(&wavdir,(const TCHAR*)"0:/MUSIC"); //打开目录 while(res==FR_OK)//打开成功 { dir_sdi(&wavdir,wavindextbl[curindex]); //改变当前目录索引 res=f_readdir(&wavdir,&wavfileinfo); //读取目录下的一个文件 if(res!=FR_OK||wavfileinfo.fname[0]==0)break; //错误了/到末尾了,退出 fn=(u8*)(*wavfileinfo.lfname?wavfileinfo.lfname:wavfileinfo.fname); strcpy((char*)pname,"0:/MUSIC/"); //复制路径(目录) strcat((char*)pname,(const char*)fn); //将文件名接在后面 LCD_Fill(60,190,240,190+16,WHITE); //清除之前的显示 Show_Str(60,190,240-60,16,fn,16,0); //显示歌曲名字 audio_index_show(curindex+1,totwavnum); key=audio_play_song(pname); //播放这个音频文件 if(key==KEY2_PRES) //上一曲 { if(curindex)curindex--; else curindex=totwavnum-1; }else if(key==KEY0_PRES)//下一曲 { curindex++; if(curindex>=totwavnum)curindex=0;//到末尾的时候,自动从头开始 }else break; //产生了错误 } myfree(SRAMIN,wavfileinfo.lfname); //释放内存 myfree(SRAMIN,pname); //释放内存 myfree(SRAMIN,wavindextbl); //释放内存 }
//------------------------------------------------------------------------------ // @fn send_sensor_values //! //! An Identifier value (CAN2.0A) is given to DVK90CAN1 board (ex: 0x080). //! 1) The first operation is to detect a CAN receive remote frame with //! ID == MY_ID_TAG. //! 2) The second operation is to send a CAN data frame with the same ID and as //! data: //! - the temperatue value (1 byte ), //! - the luminosity value (1 byte ), //! - the VCC-IN value (2 bytes). //! 3) IAP detection. //! //! @warning - Use DVK90CAN1 board, //! - can_init() must be perform before, //! - CAN_Bootloader_IAR Ver3 needed. //! //! @param none //! //! @return none //! //------------------------------------------------------------------------------ void send_sensor_values(void) { U8 temp, expected_nnb; U8 iap_buffer[8]; U8 sensor_buffer[8]; U16 v_in; st_cmd_t iap_message; st_cmd_t sensor_message; U16 ack_jingle[] = { 100, 30, A7, 0 }; // --- Init data and command for IAP detection expected_nnb = Farflash_rd_byte(NNB_ADDRESS); iap_message.pt_data = &iap_buffer[0]; iap_message.ctrl.ide = 0; //-- CAN 2.0A iap_message.dlc = 1; //-- Message with 1-byte data = NNB iap_message.id.std = 0x7FF & (((U16)(Farflash_rd_byte(CRIS_ADDRESS)))<< 4); iap_message.cmd = CMD_RX_DATA_MASKED; // --- Init data and command for REPLY-sensor message sensor_message.pt_data = &sensor_buffer[0]; sensor_message.ctrl.ide = 0; //-- CAN 2.0A sensor_message.dlc = 4; //-- Message with 4-byte data sensor_message.id.std = MY_ID_TAG; sensor_message.cmd = CMD_REPLY_MASKED; sensor_buffer[0] = (U8)(get_temperature()); sensor_buffer[1] = get_luminosity(); v_in = get_vin(); sensor_buffer[2] = (U8)(v_in >> 8 ); sensor_buffer[3] = (U8)(v_in ); // --- Enable IAP detection while(can_cmd(&iap_message) != CAN_CMD_ACCEPTED); // --- Enable REPLY for sensor message while(can_cmd(&sensor_message) != CAN_CMD_ACCEPTED); while(1) { // --- Test REPLY completed temp = can_get_status(&sensor_message); if(temp == CAN_STATUS_COMPLETED) { // --- Re-prepare data for the reply sensor_buffer[0] = (U8)(get_temperature()); sensor_buffer[1] = get_luminosity(); v_in = get_vin(); sensor_buffer[2] = (U8)(v_in >> 8 ); sensor_buffer[3] = (U8)(v_in ); // --- Re-enable REPLY for sensor message while(can_cmd(&sensor_message) != CAN_CMD_ACCEPTED); // --- Acoustic acknowledge (must be short !) audio_play_song(ack_jingle); } // --- Test IAP detected temp = can_get_status(&iap_message); if(temp == CAN_STATUS_COMPLETED) { // --- Control of length & data if((iap_buffer[0] == expected_nnb) && (iap_message.dlc == 1)) { Indirect_jump_to(BOOT_W_ADDRESS); //-- Bye ! } else { // --- Re-enable IAP detection while(can_cmd(&iap_message) != CAN_CMD_ACCEPTED); } } } // while(