Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed USBMSD_SD USBDevice
Diff: USBDevice/USBSERIAL/USBSerial.cpp
- Revision:
- 2:27a7e7f8d399
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice/USBSERIAL/USBSerial.cpp Fri Nov 11 15:22:53 2011 +0000
@@ -0,0 +1,55 @@
+// USBSerial.c
+// USB device example: virtual serial port
+// Copyright (c) 2011 ARM Limited. All rights reserved
+
+#include "stdint.h"
+#include "USBSerial.h"
+#include "USBBusInterface.h"
+
+
+int USBSerial::_putc(int c) {
+ send(EPBULK_IN, (uint8_t *)&c, 1);
+ return 1;
+}
+
+int USBSerial::_getc() {
+ uint8_t c;
+ while (buf.isEmpty());
+ buf.dequeue(&c);
+ return c;
+}
+
+void USBSerial::attach(void (*ptr)(void)) {
+ handler = true;
+ proc = true;
+ fn = ptr;
+}
+
+
+bool USBSerial::EP2_OUT_callback() {
+ uint8_t c[65];
+ uint16_t size = 0;
+
+ //we read the packet received and put it on the circular buffer
+ USBCDC::read(EPBULK_OUT, c, &size, MAX_PACKET_SIZE_EPBULK);
+ for (int i = 0; i < size; i++) {
+ buf.queue(c[i]);
+ }
+
+ //call a potential handler
+ if (handler) {
+ if (proc) {
+ (*fn)();
+ } else {
+ rx.call();
+ }
+ }
+
+ // We reactivate the endpoint to receive next characters
+ readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
+ return true;
+}
+
+uint8_t USBSerial::available() {
+ return buf.available();
+}