aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmaple/usb/usb.c30
-rw-r--r--libmaple/usb/usb.h2
-rw-r--r--wirish/usb_serial.cpp3
3 files changed, 28 insertions, 7 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 7cca37f..8dbf9c9 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -339,29 +339,39 @@ void usbWaitReset(void) {
systemHardReset();
}
+
+/* todo, change this function to behave like below */
/* copies data out of sendBuf into the packet memory for
usb, but waits until any previous usb transmissions have
completed before doing this. It returns without waiting
for its data to be sent. most efficient when 64 bytes are copied
at a time. users responsible for not overflowing sendbuf
with len! if > 64 bytes are being sent, then the function
- will block at every 64 byte packet
+ will simply send the first 64 and return. It is the USERS JOB
+ to implement any blocking. return -1 implies connection failure,
+ return 0 implies buffer filled, return < len implies another
+ transaction is needed to complete the send.
*/
+
+/* current behavior:
+ sendBytes will block until bytes are actually sent over the pipe.
+ broken pipes could stall this function. DTR and RTS are used to check
+ for a valid connection.
+ */
int16 usbSendBytes(uint8* sendBuf, uint16 len) {
- if (((line_dtr_rts & CONTROL_LINE_RTS) == 0) || bDeviceState != CONFIGURED) {
+ if (bDeviceState != CONFIGURED || (!usbGetDTR() && !usbGetRTS())) {
return -1; /* indicates to caller to stop trying, were not connected */
}
- /* This may be the correct behavior but it's undocumented
+ /*
if (countTx >= VCOM_TX_EPSIZE) {
return 0; // indicates to caller that the buffer is full
}
- */
+ */
- /* Block for any pending writes */
while (countTx)
- ;
+ ;
uint16 sent = len;
@@ -435,3 +445,11 @@ void usbSendHello(void) {
uint8 recv[64];
usbReceiveBytes(&recv[0],1);
}
+
+uint8 usbGetDTR() {
+ return ((line_dtr_rts & CONTROL_LINE_DTR) != 0);
+}
+
+uint8 usbGetRTS() {
+ return ((line_dtr_rts & CONTROL_LINE_RTS) != 0);
+}
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index ac8dc40..6451f7e 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -54,6 +54,8 @@ typedef enum
int16 usbSendBytes(uint8* sendBuf,uint16 len);
uint8 usbBytesAvailable(void);
uint8 usbReceiveBytes(uint8* recvBuf, uint8 len);
+ uint8 usbGetDTR(void);
+ uint8 usbGetRTS(void);
void usbSendHello(void);
diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp
index fe88d6e..f186dea 100644
--- a/wirish/usb_serial.cpp
+++ b/wirish/usb_serial.cpp
@@ -36,11 +36,12 @@ USBSerial :: USBSerial(void) {
}
void USBSerial::write(uint8 ch) {
- usbSendBytes(&ch, 1);
+ usbSendBytes(&ch, 1);
}
void USBSerial::write(const char *str) {
uint32 len = strlen(str);
+
usbSendBytes((uint8*)str, len);
}