USB composite device example program, drag-and-drop flash writer.
Dependencies: SWD USBDevice mbed BaseDAP
main.cpp@1:ea8e179320d7, 2013-09-28 (annotated)
- Committer:
- va009039
- Date:
- Sat Sep 28 03:21:14 2013 +0000
- Revision:
- 1:ea8e179320d7
- Parent:
- 0:2385683c867a
add USBMSD_Drop class. add CDC(Virtual COM) and HID(for example CMSIS-DAP), but KL25Z not work.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 1:ea8e179320d7 | 1 | // main.cpp 2013/9/28 |
va009039 | 0:2385683c867a | 2 | #if 1 |
va009039 | 0:2385683c867a | 3 | #include "mbed.h" |
va009039 | 0:2385683c867a | 4 | #include "USBMSD_LPC.h" |
va009039 | 1:ea8e179320d7 | 5 | #include "BaseDAP.h" |
va009039 | 0:2385683c867a | 6 | |
va009039 | 0:2385683c867a | 7 | Serial pc(USBTX, USBRX); |
va009039 | 0:2385683c867a | 8 | |
va009039 | 0:2385683c867a | 9 | #ifdef TARGET_KL25Z |
va009039 | 1:ea8e179320d7 | 10 | SWD swd(PTB8,PTB9,PTB10); // SWDIO(dp12),SWCLK(dp3),nReset(dp23) |
va009039 | 0:2385683c867a | 11 | #endif |
va009039 | 0:2385683c867a | 12 | |
va009039 | 0:2385683c867a | 13 | #ifdef TARGET_LPC1768 |
va009039 | 1:ea8e179320d7 | 14 | SWD swd(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23) |
va009039 | 1:ea8e179320d7 | 15 | Serial target_uart(p9,p10); // RXD(dp15),TXD(dp16) |
va009039 | 1:ea8e179320d7 | 16 | DigitalOut connected(LED1); |
va009039 | 1:ea8e179320d7 | 17 | DigitalOut running(LED2); |
va009039 | 1:ea8e179320d7 | 18 | class myDAP : public BaseDAP { |
va009039 | 1:ea8e179320d7 | 19 | public: |
va009039 | 1:ea8e179320d7 | 20 | myDAP(SWD* swd):BaseDAP(swd){}; |
va009039 | 1:ea8e179320d7 | 21 | virtual void infoLED(int select, int value) { |
va009039 | 1:ea8e179320d7 | 22 | switch(select) { |
va009039 | 1:ea8e179320d7 | 23 | case 0: connected = value; break; |
va009039 | 1:ea8e179320d7 | 24 | case 1: running = value; break; |
va009039 | 1:ea8e179320d7 | 25 | } |
va009039 | 1:ea8e179320d7 | 26 | } |
va009039 | 1:ea8e179320d7 | 27 | }* dap = NULL; |
va009039 | 1:ea8e179320d7 | 28 | HID_REPORT send_report; |
va009039 | 1:ea8e179320d7 | 29 | HID_REPORT recv_report; |
va009039 | 0:2385683c867a | 30 | #endif |
va009039 | 0:2385683c867a | 31 | |
va009039 | 1:ea8e179320d7 | 32 | int main() { |
va009039 | 1:ea8e179320d7 | 33 | USBMSD_LPC* device = new USBMSD_LPC(&swd, &pc); |
va009039 | 1:ea8e179320d7 | 34 | while(1) { |
va009039 | 1:ea8e179320d7 | 35 | #ifdef TARGET_LPC1768 |
va009039 | 1:ea8e179320d7 | 36 | if (target_uart.readable()) { |
va009039 | 1:ea8e179320d7 | 37 | device->putc(target_uart.getc()); |
va009039 | 1:ea8e179320d7 | 38 | } |
va009039 | 1:ea8e179320d7 | 39 | if(device->readable()) { |
va009039 | 1:ea8e179320d7 | 40 | target_uart.putc(device->getc()); |
va009039 | 1:ea8e179320d7 | 41 | } |
va009039 | 1:ea8e179320d7 | 42 | |
va009039 | 1:ea8e179320d7 | 43 | if (dap == NULL) { |
va009039 | 1:ea8e179320d7 | 44 | dap = new myDAP(&swd); |
va009039 | 1:ea8e179320d7 | 45 | } |
va009039 | 1:ea8e179320d7 | 46 | if(device->readNB(&recv_report)) { |
va009039 | 1:ea8e179320d7 | 47 | dap->Command(recv_report.data, send_report.data); |
va009039 | 1:ea8e179320d7 | 48 | send_report.length = 64; |
va009039 | 1:ea8e179320d7 | 49 | device->send(&send_report); |
va009039 | 1:ea8e179320d7 | 50 | } |
va009039 | 1:ea8e179320d7 | 51 | #endif |
va009039 | 1:ea8e179320d7 | 52 | } |
va009039 | 0:2385683c867a | 53 | } |
va009039 | 1:ea8e179320d7 | 54 | |
va009039 | 0:2385683c867a | 55 | #endif |