aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/usb_serial.cpp
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@mit.edu>2010-09-26 21:47:55 -0400
committerMarti Bolivar <mbolivar@mit.edu>2010-09-26 21:47:55 -0400
commit849bc0f8f6abf42567a152cf6e01bf7349902aac (patch)
tree8d7dd363d7978e320fb71626e9ddc23285c26205 /wirish/usb_serial.cpp
parentc13e850abe053edaa1aad6ef7b928c6bf9288cb3 (diff)
downloadlibrambutan-849bc0f8f6abf42567a152cf6e01bf7349902aac.tar.gz
librambutan-849bc0f8f6abf42567a152cf6e01bf7349902aac.zip
wirish reformatted and code-styled
Diffstat (limited to 'wirish/usb_serial.cpp')
-rw-r--r--wirish/usb_serial.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp
index fafdf49..405220a 100644
--- a/wirish/usb_serial.cpp
+++ b/wirish/usb_serial.cpp
@@ -1,4 +1,4 @@
-/* *****************************************************************************
+/******************************************************************************
* The MIT License
*
* Copyright (c) 2010 Perry Hung.
@@ -20,10 +20,10 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- * ****************************************************************************/
+ *****************************************************************************/
/**
- * @brief wirish usb class for easy goin communication, uses libmaple's
+ * @brief Wirish USB class for easy communication, uses libmaple's
* virtual com port implementation
*/
@@ -49,8 +49,10 @@ void USBSerial::write(uint8 ch) {
if(!(usbIsConnected() && usbIsConfigured())) {
return;
}
+
uint16 status = 0;
uint32 start = millis();
+
while(status == 0 && (millis() - start <= USB_TIMEOUT)) {
status = usbSendBytes(&ch, 1);
}
@@ -60,13 +62,15 @@ void USBSerial::write(const char *str) {
if(!(usbIsConnected() && usbIsConfigured())) {
return;
}
+
uint32 len = strlen(str);
uint16 status = 0;
uint16 oldstatus = 0;
uint32 start = millis();
+
while(status < len && (millis() - start < USB_TIMEOUT)) {
status += usbSendBytes((uint8*)str+status, len-status);
- if(oldstatus != status)
+ if(oldstatus != status)
start = millis();
oldstatus = status;
}
@@ -76,52 +80,55 @@ void USBSerial::write(void *buf, uint32 size) {
if(!(usbIsConnected() && usbIsConfigured())) {
return;
}
+
if (!buf) {
return;
}
+
uint16 status = 0;
uint16 oldstatus = 0;
uint32 start = millis();
+
while(status < size && (millis() - start < USB_TIMEOUT)) {
status += usbSendBytes((uint8*)buf+status, size-status);
- if(oldstatus != status)
+ if(oldstatus != status)
start = millis();
oldstatus = status;
}
}
uint32 USBSerial::available(void) {
- return usbBytesAvailable();
+ return usbBytesAvailable();
}
uint32 USBSerial::read(void *buf, uint32 len) {
- if (!buf) {
- return 0;
- }
+ if (!buf) {
+ return 0;
+ }
- return usbReceiveBytes((uint8*)buf, len);
+ return usbReceiveBytes((uint8*)buf, len);
}
uint8 USBSerial::read(void) {
- uint8 ch;
- usbReceiveBytes(&ch, 1);
- return ch;
+ uint8 ch;
+ usbReceiveBytes(&ch, 1);
+ return ch;
}
uint8 USBSerial::pending(void) {
- return usbGetPending();
+ return usbGetPending();
}
uint8 USBSerial::getDTR(void) {
- return usbGetDTR();
+ return usbGetDTR();
}
uint8 USBSerial::getRTS(void) {
- return usbGetRTS();
+ return usbGetRTS();
}
uint8 USBSerial::isConnected(void) {
- return (usbIsConnected() && usbIsConfigured());
+ return (usbIsConnected() && usbIsConfigured());
}
USBSerial SerialUSB;