Christian Lerche
/
EA_DoorPlayer
EA BaseBoard, playing wav, PC see\'s SD-card through USB port.
main.cpp@0:fef366d2ed20, 2011-11-22 (annotated)
- Committer:
- Lerche
- Date:
- Tue Nov 22 05:45:58 2011 +0000
- Revision:
- 0:fef366d2ed20
Thanks to those who provided EA_WavPlayer and USB_MSC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lerche | 0:fef366d2ed20 | 1 | #include "mbed.h" |
Lerche | 0:fef366d2ed20 | 2 | #include "dbg.h" |
Lerche | 0:fef366d2ed20 | 3 | #include "USBMSC.h" |
Lerche | 0:fef366d2ed20 | 4 | |
Lerche | 0:fef366d2ed20 | 5 | #include "msc_bot.h" |
Lerche | 0:fef366d2ed20 | 6 | #include "SDFileSystem.h" |
Lerche | 0:fef366d2ed20 | 7 | #include "wavplayer.h" |
Lerche | 0:fef366d2ed20 | 8 | #include <new> |
Lerche | 0:fef366d2ed20 | 9 | |
Lerche | 0:fef366d2ed20 | 10 | Serial pc(USBTX, USBRX); |
Lerche | 0:fef366d2ed20 | 11 | DigitalOut myled(LED1); |
Lerche | 0:fef366d2ed20 | 12 | SDFileSystem sd(p5, p6, p7, p24, "sd"); |
Lerche | 0:fef366d2ed20 | 13 | DigitalIn button(p21); |
Lerche | 0:fef366d2ed20 | 14 | USBMSC usbdev; |
Lerche | 0:fef366d2ed20 | 15 | |
Lerche | 0:fef366d2ed20 | 16 | DigitalOut volCLK(p22); |
Lerche | 0:fef366d2ed20 | 17 | //USBMSC usbdev(0xFFFF, 0x0003, 0x0100); |
Lerche | 0:fef366d2ed20 | 18 | |
Lerche | 0:fef366d2ed20 | 19 | extern "C" |
Lerche | 0:fef366d2ed20 | 20 | void HardFault_Handler() { |
Lerche | 0:fef366d2ed20 | 21 | printf("Hard Fault!\n"); |
Lerche | 0:fef366d2ed20 | 22 | exit(-1); |
Lerche | 0:fef366d2ed20 | 23 | } |
Lerche | 0:fef366d2ed20 | 24 | |
Lerche | 0:fef366d2ed20 | 25 | void no_memory () { |
Lerche | 0:fef366d2ed20 | 26 | printf("panic: can't allocate to memory!\r\n"); |
Lerche | 0:fef366d2ed20 | 27 | exit(-1); |
Lerche | 0:fef366d2ed20 | 28 | } |
Lerche | 0:fef366d2ed20 | 29 | |
Lerche | 0:fef366d2ed20 | 30 | void msc_evt (uint8_t endpoint) { |
Lerche | 0:fef366d2ed20 | 31 | switch (endpoint) { |
Lerche | 0:fef366d2ed20 | 32 | case EPBULK_OUT: |
Lerche | 0:fef366d2ed20 | 33 | MSCBotBulkOut(); |
Lerche | 0:fef366d2ed20 | 34 | break; |
Lerche | 0:fef366d2ed20 | 35 | case EPBULK_IN: |
Lerche | 0:fef366d2ed20 | 36 | MSCBotBulkIn(); |
Lerche | 0:fef366d2ed20 | 37 | break; |
Lerche | 0:fef366d2ed20 | 38 | case 0xFF: |
Lerche | 0:fef366d2ed20 | 39 | MSCBotReset(); |
Lerche | 0:fef366d2ed20 | 40 | break; |
Lerche | 0:fef366d2ed20 | 41 | } |
Lerche | 0:fef366d2ed20 | 42 | } |
Lerche | 0:fef366d2ed20 | 43 | |
Lerche | 0:fef366d2ed20 | 44 | int main() { |
Lerche | 0:fef366d2ed20 | 45 | button.mode(PullUp); |
Lerche | 0:fef366d2ed20 | 46 | WavPlayer myWavPlayer; |
Lerche | 0:fef366d2ed20 | 47 | |
Lerche | 0:fef366d2ed20 | 48 | set_new_handler(no_memory); // new handler function |
Lerche | 0:fef366d2ed20 | 49 | FILE *fp = fopen("/sd/settings.txt", "r"); |
Lerche | 0:fef366d2ed20 | 50 | char array[17]; |
Lerche | 0:fef366d2ed20 | 51 | if (fp) { |
Lerche | 0:fef366d2ed20 | 52 | while(fgets(array, 17, fp)){ |
Lerche | 0:fef366d2ed20 | 53 | pc.printf("file: %s\r\n",array); |
Lerche | 0:fef366d2ed20 | 54 | } |
Lerche | 0:fef366d2ed20 | 55 | fclose(fp); |
Lerche | 0:fef366d2ed20 | 56 | } |
Lerche | 0:fef366d2ed20 | 57 | if (fp == NULL) { |
Lerche | 0:fef366d2ed20 | 58 | pc.printf("Could not open file for write\n"); |
Lerche | 0:fef366d2ed20 | 59 | fclose(fp); |
Lerche | 0:fef366d2ed20 | 60 | } |
Lerche | 0:fef366d2ed20 | 61 | |
Lerche | 0:fef366d2ed20 | 62 | MSCBotReset(); |
Lerche | 0:fef366d2ed20 | 63 | usbdev.attach(&msc_evt); |
Lerche | 0:fef366d2ed20 | 64 | |
Lerche | 0:fef366d2ed20 | 65 | |
Lerche | 0:fef366d2ed20 | 66 | while(1) { |
Lerche | 0:fef366d2ed20 | 67 | if(button == 0){ |
Lerche | 0:fef366d2ed20 | 68 | myWavPlayer.play_wave(array); // 8 bit sample size |
Lerche | 0:fef366d2ed20 | 69 | } |
Lerche | 0:fef366d2ed20 | 70 | myled = 1; |
Lerche | 0:fef366d2ed20 | 71 | wait(0.5); |
Lerche | 0:fef366d2ed20 | 72 | myled = 0; |
Lerche | 0:fef366d2ed20 | 73 | wait(0.5); |
Lerche | 0:fef366d2ed20 | 74 | } |
Lerche | 0:fef366d2ed20 | 75 | } |