Emulation of LocalFileSystem with virtual COM.
Dependents: KL46Z-lpc81isp lpcterm2
#include "USBLocalFileSystem.h" int main() { USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB) while(1) { usb_local->lock(true); usb_local->remount(); char filename[32]; if (usb_local->find(filename, sizeof(filename), "*.TXT")) { FILE* fp = fopen(filename, "r"); if (fp) { int c; while((c = fgetc(fp)) != EOF) { usb_local->putc(c); } fclose(fp); } } usb_local->lock(false); wait_ms(1000*5); } }
Sample application:
Import programKL46Z-lpc81isp
ISP example program.
Import programlpcterm2
semihost server example program
Diff: USBMSD2/USB_CDC.h
- Revision:
- 4:8f6857784854
- Parent:
- 0:39eb4d5b97df
- Child:
- 6:528036abfb02
--- a/USBMSD2/USB_CDC.h Tue May 06 16:05:57 2014 +0900 +++ b/USBMSD2/USB_CDC.h Thu May 08 23:43:46 2014 +0900 @@ -53,10 +53,6 @@ int writeable(); - void baud_callback(int baudrate); - void send_break_callback(uint16_t duration); - void control_line_callback(int rts, int dtr); - /* * Send a buffer * @@ -92,9 +88,35 @@ bool Request_callback(CONTROL_TRANSFER* transfer); bool RequestCompleted_callback(CONTROL_TRANSFER* transfer, uint8_t* buf, int length); bool EPBULK_OUT_callback(); + + /** + * Attach a callback to call when serial's settings are changed. + * + * @param fptr function pointer + */ + void attach(void (*fptr)(int baud, int bits, int parity, int stop)) { + settingsChangedCallback = fptr; + } + + void attachControlLineStateChanged(void (*fptr)(int rts, int dtr)) { + controlLineStateChangedCallback = fptr; + } + + void attachSendBreak(void (*fptr)(uint16_t duration)) { + sendBreakCallback = fptr; + } +protected: + void lineCodingChanged(int baud, int bits, int parity, int stop); + void controlLineStateChanged(int rts, int dtr); + void sendBreak(uint16_t duration); + private: USBDevice* _device; CircBuffer<uint8_t> _rx_buf; + void (*settingsChangedCallback)(int baud, int bits, int parity, int stop); + void (*controlLineStateChangedCallback)(int rts, int dtr); + void (*sendBreakCallback)(uint16_t duration); volatile bool terminal_connected; }; +