Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #378 from majenkotech/master

Switched CDC to using line status to determine endpoint presence.
  • Loading branch information...
commit 31e43c9f13c68d492b7f53689e48bb2e880715a0 2 parents 106c852 + 76a4078
@ricklon ricklon authored
View
4 hardware/pic32/cores/pic32/HardwareSerial.cpp
@@ -582,6 +582,10 @@ USBSerial::USBSerial(ring_buffer *rx_buffer)
_rx_buffer->tail = 0;
}
+USBSerial::operator int() {
+ return gConnected ? 1 : 0;
+}
+
#ifdef _DEBUG_USB_VIA_SERIAL0_
#define DebugViaSerial0(x) Serial0.println(x)
#else
View
1  hardware/pic32/cores/pic32/HardwareSerial.h
@@ -141,6 +141,7 @@ class USBSerial : public Stream
virtual void write(uint8_t);
virtual void write(const char *str);
virtual void write(const uint8_t *buffer, size_t size);
+ operator int();
using Print::write; // pull in write(str) and write(buf, size) from Print
};
View
16 hardware/pic32/cores/pic32/HardwareSerial_cdcacm.c
@@ -164,7 +164,7 @@ static int gRX_length[NRX];
static volatile byte gRX_in;
static volatile byte gRX_out;
-static boolean gDiscard; // true when we don't think anyone is listening
+boolean gConnected = false;
//*******************************************************************************
@@ -205,14 +205,14 @@ static int SPLX(int level)
//************************************************************************
void cdcacm_print(const byte *buffer, int length)
{
-int availableBuffers;
-int buffersNeeded;
-int m;
-int previousInterrutLevel;
+ int availableBuffers;
+ int buffersNeeded;
+ int m;
+ int previousInterrutLevel;
// ASSERT(length);
- if (! gCdcacm_attached || gDiscard || (length <= 0))
+ if (! gCdcacm_attached || !gConnected || (length <= 0))
{
return;
}
@@ -245,7 +245,6 @@ int previousInterrutLevel;
delay(1);
if (m++ > 1000)
{
- gDiscard = true;
return;
}
previousInterrutLevel = SPLX(7);
@@ -353,6 +352,7 @@ static int cdcacm_control_transfer(struct setup *setup, byte *buffer, int length
break;
case CDCRQ_SET_CONTROL_LINE_STATE:
assert(! (setup->requesttype & 0x80));
+ gConnected = setup->value & 0x01;
length = 0;
break;
case CDCRQ_SEND_BREAK:
@@ -397,8 +397,6 @@ static int cdcacm_bulk_transfer(boolean in, byte *buffer, int length)
{
if (! in)
{
- gDiscard = false;
-
gCdcacm_active = true;
// accumulate commands
View
1  hardware/pic32/cores/pic32/HardwareSerial_cdcacm.h
@@ -7,6 +7,7 @@
#define USB_SERIAL_MIN_BUFFER_FREE 128
extern boolean gCdcacm_active;
+extern boolean gConnected;
typedef void (*cdcacm_reset_cbfn)(void);
typedef boolean (*cdcacm_storedata_cbfn)(const byte *buffer, int length);
Please sign in to comment.
Something went wrong with that request. Please try again.