wave player pwm & covox

Dependencies:   wave_player_pwm_and_covox mbed USBHost

Committer:
vsolonar
Date:
Thu Jan 03 13:50:44 2019 +0000
Revision:
11:d2099045bdc9
Parent:
10:c3614ed19126
tested, done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsolonar 9:d0a3b4c7b261 1 /*
vsolonar 11:d2099045bdc9 2 Big green ugly etc. Free for use bla bla bla. Do not eat.
vsolonar 9:d0a3b4c7b261 3 Tested on stm32f746zg
vsolonar 10:c3614ed19126 4
vsolonar 11:d2099045bdc9 5 Fast creepy transformation DAC_PWM WavePlayer SD_Card
vsolonar 11:d2099045bdc9 6 to usb_flash_stick PWM_Covox WavePlayer
vsolonar 11:d2099045bdc9 7
vsolonar 11:d2099045bdc9 8 Based on Lucy Lenhardt wave_player_pwm_and_dac
vsolonar 11:d2099045bdc9 9 https://os.mbed.com/users/lenhardt/code/wave_player_pwm_and_dac/
vsolonar 9:d0a3b4c7b261 10 */
vsolonar 9:d0a3b4c7b261 11
samux 0:0d68fe822228 12 #include "mbed.h"
vsolonar 11:d2099045bdc9 13 //#include "pinout.h"
samux 0:0d68fe822228 14 #include "USBHostMSD.h"
vsolonar 10:c3614ed19126 15 #include "wave_player.h"
samux 0:0d68fe822228 16
vsolonar 11:d2099045bdc9 17 Serial pc(USBTX, USBRX, 115200); // tx, rx, baud rate
vsolonar 9:d0a3b4c7b261 18
vsolonar 10:c3614ed19126 19 AnalogOut dac(PA_5);
vsolonar 11:d2099045bdc9 20 PwmOut enb(PA_6);
vsolonar 11:d2099045bdc9 21 wave_player player(&dac, &enb);
vsolonar 9:d0a3b4c7b261 22
vsolonar 9:d0a3b4c7b261 23 int main() {
vsolonar 9:d0a3b4c7b261 24
vsolonar 10:c3614ed19126 25 USBHostMSD msd("usb");
vsolonar 9:d0a3b4c7b261 26
vsolonar 9:d0a3b4c7b261 27 while(1) {
samux 1:473f339c54c1 28 while(!msd.connect()) {
vsolonar 9:d0a3b4c7b261 29 pc.printf("Waiting for USB\r\n");
vsolonar 9:d0a3b4c7b261 30 wait_ms(500);
samux 1:473f339c54c1 31 }
vsolonar 10:c3614ed19126 32
vsolonar 9:d0a3b4c7b261 33 pc.printf("Flash mounted\r\n");
vsolonar 9:d0a3b4c7b261 34
vsolonar 10:c3614ed19126 35 FILE * fp = fopen("/usb/test1.wav", "rb");
samux 1:473f339c54c1 36
samux 1:473f339c54c1 37 if (fp != NULL) {
vsolonar 9:d0a3b4c7b261 38 pc.printf("File opened, reading...\r\n");
vsolonar 9:d0a3b4c7b261 39
vsolonar 10:c3614ed19126 40 player.play(fp);
vsolonar 9:d0a3b4c7b261 41
vsolonar 9:d0a3b4c7b261 42 fclose(fp);
vsolonar 9:d0a3b4c7b261 43 pc.printf("File closed\r\n");
vsolonar 9:d0a3b4c7b261 44
vsolonar 9:d0a3b4c7b261 45
samux 1:473f339c54c1 46 } else {
vsolonar 9:d0a3b4c7b261 47 pc.printf("FILE == NULL\r\n");
samux 1:473f339c54c1 48 }
vsolonar 9:d0a3b4c7b261 49
samux 1:473f339c54c1 50 if (!msd.connected())
samux 1:473f339c54c1 51 break;
samux 0:0d68fe822228 52 }
samux 0:0d68fe822228 53 }