Skip to content

Commit a0eb4c0

Browse files
authored
feat(hwcdc): add 2 methods
Adds 2 new methods: - isPlugged() will return true when USB cable is plugged, false otherwise. - isConnected() will return true when USB CDC is connected to a application in the USB Host side and communication is stablished.
1 parent 32b2fa7 commit a0eb4c0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: cores/esp32/HWCDC.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <inttypes.h>
2222
#include "esp_event.h"
2323
#include "Stream.h"
24+
#include "driver/usb_serial_jtag.h"
2425

2526
ESP_EVENT_DECLARE_BASE(ARDUINO_HW_CDC_EVENTS);
2627

@@ -46,7 +47,7 @@ class HWCDC: public Stream
4647
{
4748
private:
4849
static bool deinit(void * busptr);
49-
static bool isCDC_Connected();
50+
bool isCDC_Connected();
5051

5152
public:
5253
HWCDC();
@@ -69,7 +70,17 @@ class HWCDC: public Stream
6970
size_t write(uint8_t);
7071
size_t write(const uint8_t *buffer, size_t size);
7172
void flush(void);
72-
73+
74+
inline bool isPlugged(void)
75+
{
76+
return usb_serial_jtag_is_connected();
77+
}
78+
79+
inline bool isConnected(void)
80+
{
81+
return isCDC_Connected();
82+
}
83+
7384
inline size_t read(char * buffer, size_t size)
7485
{
7586
return read((uint8_t*) buffer, size);

0 commit comments

Comments
 (0)