From 99c251b8462e7bc304e9e4a52bfc378d22804291 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 22 Jul 2010 18:24:51 -0400 Subject: added isConnected() to serialusb --- libmaple/usb/usb.c | 8 ++++++++ libmaple/usb/usb.h | 2 ++ wirish/usb_serial.cpp | 12 ++++++++++++ wirish/usb_serial.h | 1 + 4 files changed, 23 insertions(+) diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c index 881c7f9..23cde00 100644 --- a/libmaple/usb/usb.c +++ b/libmaple/usb/usb.c @@ -459,6 +459,14 @@ uint8 usbGetRTS() { return ((line_dtr_rts & CONTROL_LINE_RTS) != 0); } +uint8 usbIsConfigured() { + return (bDeviceState == CONFIGURED); +} + +uint8 usbIsConnected() { + return (bDeviceState != UNCONNECTED); +} + uint16 usbGetPending() { return countTx; } diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h index e0d4231..ec179b1 100644 --- a/libmaple/usb/usb.h +++ b/libmaple/usb/usb.h @@ -57,6 +57,8 @@ typedef enum uint8 usbReceiveBytes(uint8* recvBuf, uint8 len); uint8 usbGetDTR(void); uint8 usbGetRTS(void); + uint8 usbIsConnected(void); + uint8 usbIsConfigured(void); uint16 usbGetPending(void); void usbSendHello(void); diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp index 08cda55..c066112 100644 --- a/wirish/usb_serial.cpp +++ b/wirish/usb_serial.cpp @@ -103,5 +103,17 @@ uint8 USBSerial::pending(void) { return usbGetPending(); } +uint8 USBSerial::getDTR(void) { + return usbGetDTR(); +} + +uint8 USBSerial::getRTS(void) { + return usbGetRTS(); +} + +uint8 USBSerial::isConnected(void) { + return (usbIsConnected() && usbIsConfigured()); +} + USBSerial SerialUSB; diff --git a/wirish/usb_serial.h b/wirish/usb_serial.h index abb362b..7c87c04 100644 --- a/wirish/usb_serial.h +++ b/wirish/usb_serial.h @@ -50,6 +50,7 @@ class USBSerial : public Print { uint8 getRTS(); uint8 getDTR(); + uint8 isConnected(); uint8 pending(); }; -- cgit v1.2.3