aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/usb_serial.cpp
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-09-23 17:56:24 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-10-18 13:30:18 -0400
commitbbcbf65fd7d074268f4e25ae014965bceb995b79 (patch)
treed027563c1d4b860d3e77119ee26f75943ced80a2 /wirish/usb_serial.cpp
parent2e392bbf59c4c746714d71c99757f02da4c57179 (diff)
downloadlibrambutan-bbcbf65fd7d074268f4e25ae014965bceb995b79.tar.gz
librambutan-bbcbf65fd7d074268f4e25ae014965bceb995b79.zip
usb: Disentangle CDC ACM functionality.
Add new usb_cdcacm.h, which provides the virtual serial port API. This file (and new usb_cdcacm.c) consolidate the VCOM support, which was previously distributed through descriptors.[hc], usb.[hc], usb_callbacks.[hc], and usb_config.h. Add usb_init_usblib() to usb.h, as a way of initializing the USB peripheral in terms of the data structures required by usb_lib. This is used by the new usb_cdcacm_enable(). Create new usb_lib_globals.h, with declarations for the usb_lib global state which is most used throughout the rest of the libmaple USB stack. Remove descriptors.c and usb_callbacks.[hc]; they are no longer necessary. Update the USB README accordingly. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'wirish/usb_serial.cpp')
-rw-r--r--wirish/usb_serial.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp
index 9d9cd59..ccca4b4 100644
--- a/wirish/usb_serial.cpp
+++ b/wirish/usb_serial.cpp
@@ -31,6 +31,7 @@
#include <string.h>
#include "wirish.h"
+#include "usb_cdcacm.h"
#include "usb.h"
#define USB_TIMEOUT 50
@@ -65,7 +66,7 @@ void USBSerial::write(const void *buf, uint32 len) {
uint32 start = millis();
while (txed < len && (millis() - start < USB_TIMEOUT)) {
- txed += usbSendBytes((const uint8*)buf + txed, len - txed);
+ txed += usb_cdcacm_tx((const uint8*)buf + txed, len - txed);
if (old_txed != txed) {
start = millis();
}
@@ -74,7 +75,7 @@ void USBSerial::write(const void *buf, uint32 len) {
}
uint32 USBSerial::available(void) {
- return usbBytesAvailable();
+ return usb_cdcacm_data_available();
}
uint32 USBSerial::read(void *buf, uint32 len) {
@@ -84,7 +85,7 @@ uint32 USBSerial::read(void *buf, uint32 len) {
uint32 rxed = 0;
while (rxed < len) {
- rxed += usbReceiveBytes((uint8*)buf + rxed, len - rxed);
+ rxed += usb_cdcacm_rx((uint8*)buf + rxed, len - rxed);
}
return rxed;
@@ -92,13 +93,13 @@ uint32 USBSerial::read(void *buf, uint32 len) {
/* Blocks forever until 1 byte is received */
uint8 USBSerial::read(void) {
- uint8 buf[1];
- this->read(buf, 1);
- return buf[0];
+ uint8 b;
+ this->read(&b, 1);
+ return b;
}
uint8 USBSerial::pending(void) {
- return usbGetPending();
+ return usb_cdcacm_get_pending();
}
uint8 USBSerial::isConnected(void) {
@@ -106,11 +107,11 @@ uint8 USBSerial::isConnected(void) {
}
uint8 USBSerial::getDTR(void) {
- return usbGetDTR();
+ return usb_cdcacm_get_dtr();
}
uint8 USBSerial::getRTS(void) {
- return usbGetRTS();
+ return usb_cdcacm_get_rts();
}
USBSerial SerialUSB;