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()
138138// idx is index of cdc interface in the internal pool.
139139void tuh_cdc_mount_cb (uint8_t idx) {
140140 // bind SerialHost object to this interface index
141- SerialHost.begin (idx);
141+ SerialHost.setInterfaceIndex (idx);
142+ SerialHost.begin (115200 );
142143
143144 Serial.println (" SerialHost is connected to a new CDC device" );
144145}
145146
146147// Invoked when a device with CDC interface is unmounted
147148void tuh_cdc_umount_cb (uint8_t idx) {
148- if (idx == SerialHost.getIndex ()) {
149+ if (idx == SerialHost.getInterfaceIndex ()) {
149150 // unbind SerialHost if this interface is unmounted
150151 SerialHost.end ();
151152
Original file line number Diff line number Diff line change 3232
3333Adafruit_USBH_CDC::Adafruit_USBH_CDC (void ) { _idx = TUSB_INDEX_INVALID; }
3434
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+ }
3652
3753void Adafruit_USBH_CDC::end (void ) { _idx = TUSB_INDEX_INVALID; }
3854
Original file line number Diff line number Diff line change 2525#ifndef ADAFRUIT_USBH_CDC_H_
2626#define ADAFRUIT_USBH_CDC_H_
2727
28- #include " Stream .h"
28+ #include " HardwareSerial .h"
2929
30- class Adafruit_USBH_CDC : public Stream {
30+ class Adafruit_USBH_CDC : public HardwareSerial {
3131public:
3232 Adafruit_USBH_CDC (void );
3333
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);
3640
3741 // unbind cdc interface
3842 void end (void );
3943
40- // Get index of cdc interface
41- uint8_t getIndex (void ) { return _idx; }
42-
4344 // If cdc is mounted
4445 bool mounted (void );
4546 operator bool () { return mounted (); }
@@ -67,6 +68,7 @@ class Adafruit_USBH_CDC : public Stream {
6768
6869private:
6970 uint8_t _idx; // TinyUSB CDC Interface Index
71+ uint32_t _baud;
7072};
7173
7274#endif
You can’t perform that action at this time.
0 commit comments