void wav_pre_read(void) { u32 index = 0; flash_bytes_read(index, (u8 *)buffer1, 0x100); while(WaveParsing()); WaveLen = WAVE_Format.DataSize; I2S_Freq_Config(WAVE_Format.SampleRate); }
void wav_play(void) { u32 index = 0; u8 i=0; WaveLen = 0; XferCplt = 0; DataOffset = 0; buffer_switch = 1; index = DataOffset; flash_bytes_read(index, (u8 *)buffer1, 1024); index += 1024; flash_bytes_read(index, (u8 *)buffer2, 1024); Audio_MAL_Play((u32)buffer1, 1024); buffer_switch=1; XferCplt=0; while(WaveLen!=0) { while(XferCplt==0);//??DMA???? XferCplt=0; if(buffer_switch==0) { Audio_MAL_Play((u32)buffer1,1024);//?buffer1?? index += 1024; flash_bytes_read(index, (u8 *)buffer2, 1024); buffer_switch=1; } else { Audio_MAL_Play((u32)buffer2,1024);//?buffer2?? index += 1024; flash_bytes_read(index, (u8 *)buffer1, 1024); buffer_switch=0; } i++; } }
void parse_commands(void) { uint8_t count = 0, tmp; if(page_write) { // Multiply nblock with 64 to get block start address in flash: flash_bytes_write(nblock << 6, out1buf, USB_EP1_SIZE); nblock++; nblocks++; in1buf[0] = 0; count = 1; if (nblocks == (FLASH_PAGE_SIZE/USB_EP1_SIZE)) { page_write = false; } } else { switch(out1buf[0]) { case CMD_FIRMWARE_VERSION: in1buf[0] = FW_VER_MAJOR; in1buf[1] = FW_VER_MINOR; count = 2; break; case CMD_FLASH_ERASE_PAGE: flash_page_erase(out1buf[1]); used_flash_pages[out1buf[1]] = false; in1buf[0] = 0; count = 1; break; case CMD_FLASH_WRITE_INIT: // Eight 64 bytes bulk packets <- PC follow after this command if (used_flash_pages[out1buf[1]]) { flash_page_erase(out1buf[1]); } used_flash_pages[out1buf[1]] = 1; nblock = (uint16_t)out1buf[1] << 3; // Multiply page number by 8 to get block number nblocks = 0; page_write = true; in1buf[0] = 0; count = 1; break; case CMD_FLASH_READ: // Read one USB_EP1_SIZE bytes block from the address given // by out1buf[1] << 6 and MS bit set by CMD_FLASH_SELECT_HALF // below: nblock = (nblock & 0xff00) | (uint16_t)out1buf[1]; if (RDIS) { // RDISMB is set. Will return 0x00 for pages that are in use and 0xff // for unused pages. if (used_flash_pages[nblock >> 3]) tmp = 0x00; else tmp = 0xff; for(count=0; count<USB_EP1_SIZE; count++) in1buf[count] = tmp; } else flash_bytes_read((uint16_t)nblock<<6, in1buf, USB_EP1_SIZE); count = USB_EP1_SIZE; break; case CMD_FLASH_SET_PROTECTED: count = 1; INFEN = 1; if (rdismb != 0xff) { in1buf[0] = 1; } else { flash_byte_write((uint16_t)&rdismb, 0x00); in1buf[0] = 0; } INFEN = 0; break; case CMD_FLASH_SELECT_HALF: // When outbuf[1] = 0 program the lower half of the 32K bytes flash // and when outbuf[1] = 1 program the upper part: if (out1buf[1] == 1) nblock = (nblock & 0x00ff) | 0x0100; else nblock &= 0x00ff; in1buf[0] = 0; count = 1; break; default: break; }