File tree Expand file tree Collapse file tree 3 files changed +29
-10
lines changed
examples/DualRole/serial_host_bridge Expand file tree Collapse file tree 3 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -138,14 +138,15 @@ void loop1()
138
138
// idx is index of cdc interface in the internal pool.
139
139
void tuh_cdc_mount_cb (uint8_t idx) {
140
140
// bind SerialHost object to this interface index
141
- SerialHost.begin (idx);
141
+ SerialHost.setInterfaceIndex (idx);
142
+ SerialHost.begin (115200 );
142
143
143
144
Serial.println (" SerialHost is connected to a new CDC device" );
144
145
}
145
146
146
147
// Invoked when a device with CDC interface is unmounted
147
148
void tuh_cdc_umount_cb (uint8_t idx) {
148
- if (idx == SerialHost.getIndex ()) {
149
+ if (idx == SerialHost.getInterfaceIndex ()) {
149
150
// unbind SerialHost if this interface is unmounted
150
151
SerialHost.end ();
151
152
Original file line number Diff line number Diff line change 32
32
33
33
Adafruit_USBH_CDC::Adafruit_USBH_CDC (void ) { _idx = TUSB_INDEX_INVALID; }
34
34
35
- void Adafruit_USBH_CDC::begin (uint8_t idx) { _idx = idx; }
35
+ void Adafruit_USBH_CDC::begin (unsigned long baud) {
36
+
37
+ // default to index 0 when begin
38
+ if (_idx == TUSB_INDEX_INVALID) {
39
+ _idx = 0 ;
40
+ }
41
+
42
+ _baud = baud;
43
+ if (_baud == 0 ) {
44
+ _baud = 115200 ; // default, backward compatible with previous API begin(0)
45
+ }
46
+ }
47
+
48
+ void Adafruit_USBH_CDC::begin (unsigned long baudrate, uint16_t config) {
49
+ (void )config; // TODO support line coding later
50
+ begin (115200 );
51
+ }
36
52
37
53
void Adafruit_USBH_CDC::end (void ) { _idx = TUSB_INDEX_INVALID; }
38
54
Original file line number Diff line number Diff line change 25
25
#ifndef ADAFRUIT_USBH_CDC_H_
26
26
#define ADAFRUIT_USBH_CDC_H_
27
27
28
- #include " Stream .h"
28
+ #include " HardwareSerial .h"
29
29
30
- class Adafruit_USBH_CDC : public Stream {
30
+ class Adafruit_USBH_CDC : public HardwareSerial {
31
31
public:
32
32
Adafruit_USBH_CDC (void );
33
33
34
- // Init/Bind to an specific cdc interface
35
- void begin (uint8_t idx = 0 );
34
+ // Set/Get index of cdc interface
35
+ void setInterfaceIndex (uint8_t idx) { _idx = idx; }
36
+ uint8_t getInterfaceIndex (void ) { return _idx; }
37
+
38
+ void begin (unsigned long baudrate);
39
+ void begin (unsigned long baudrate, uint16_t config);
36
40
37
41
// unbind cdc interface
38
42
void end (void );
39
43
40
- // Get index of cdc interface
41
- uint8_t getIndex (void ) { return _idx; }
42
-
43
44
// If cdc is mounted
44
45
bool mounted (void );
45
46
operator bool () { return mounted (); }
@@ -67,6 +68,7 @@ class Adafruit_USBH_CDC : public Stream {
67
68
68
69
private:
69
70
uint8_t _idx; // TinyUSB CDC Interface Index
71
+ uint32_t _baud;
70
72
};
71
73
72
74
#endif
You can’t perform that action at this time.
0 commit comments