Norimasa Okamoto / Mbed 2 deprecated USBMSD_LPC_HelloWorld

Dependencies:   SWD USBDevice mbed BaseDAP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // main.cpp 2013/9/28
00002 #if 1
00003 #include "mbed.h"
00004 #include "USBMSD_LPC.h"
00005 #include "BaseDAP.h"
00006 
00007 Serial pc(USBTX, USBRX);
00008 
00009 #ifdef TARGET_KL25Z
00010 SWD swd(PTB8,PTB9,PTB10); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
00011 #endif
00012 
00013 #ifdef TARGET_LPC1768
00014 SWD swd(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
00015 Serial target_uart(p9,p10); // RXD(dp15),TXD(dp16)
00016 DigitalOut connected(LED1);
00017 DigitalOut running(LED2);
00018 class myDAP : public BaseDAP {
00019 public:
00020     myDAP(SWD* swd):BaseDAP(swd){};
00021     virtual void infoLED(int select, int value) {
00022         switch(select) {
00023             case 0: connected = value; break;
00024             case 1: running = value; break;
00025         }
00026     } 
00027 }* dap = NULL;
00028 HID_REPORT send_report;
00029 HID_REPORT recv_report;
00030 #endif
00031 
00032 int main() {
00033     USBMSD_LPC* device = new USBMSD_LPC(&swd, &pc); 
00034     while(1) {
00035 #ifdef TARGET_LPC1768 
00036         if (target_uart.readable()) {
00037             device->putc(target_uart.getc());
00038         }
00039         if(device->readable()) {
00040             target_uart.putc(device->getc());
00041         }
00042 
00043         if (dap == NULL) {
00044             dap = new myDAP(&swd);
00045         }
00046         if(device->readNB(&recv_report)) {
00047             dap->Command(recv_report.data, send_report.data);
00048             send_report.length = 64;
00049             device->send(&send_report);
00050         }
00051 #endif
00052     }
00053 }
00054 
00055 #endif