aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/usb_serial.cpp
diff options
context:
space:
mode:
authorMichael Hope <michael.hope@linaro.org>2010-09-29 20:45:57 +1300
committerMichael Hope <michael.hope@linaro.org>2010-09-29 20:45:57 +1300
commit6fcd4cd306dbecf56f5b0b506a3c23762d1219fa (patch)
tree467125eca5a2e6706001cad8e09bc475e58a12d9 /wirish/usb_serial.cpp
parent368e4fc1662c2594b2a0908900713a2555a3ed8e (diff)
parentadde11b099ff5dad176e410279d21feac39d2c7e (diff)
downloadlibrambutan-6fcd4cd306dbecf56f5b0b506a3c23762d1219fa.tar.gz
librambutan-6fcd4cd306dbecf56f5b0b506a3c23762d1219fa.zip
Merge remote branch 'upstream/master'
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;