File tree 3 files changed +32
-33
lines changed
3 files changed +32
-33
lines changed Original file line number Diff line number Diff line change @@ -80,41 +80,40 @@ size_t _SerialUSB::write(uint8_t c) {
80
80
return write (&c, 1 );
81
81
}
82
82
83
- size_t _SerialUSB::write (const uint8_t *buf, size_t length) {
84
- if (!_running) {
83
+ #include " device/usbd_pvt.h"
84
+
85
+ size_t _SerialUSB::write (const uint8_t *buf, size_t size) {
86
+ if (!_running) {
85
87
return 0 ;
86
88
}
87
89
88
- static uint64_t last_avail_time;
89
- int written = 0 ;
90
- if ( connected ()) {
91
- for ( size_t i = 0 ; i < length;) {
92
- int n = length - i ;
93
- int avail = tud_cdc_write_available ();
94
- if (n > avail) {
95
- n = avail;
96
- }
97
- if (n) {
98
- int n2 = tud_cdc_write (buf + i, n) ;
99
- tud_task ();
100
- tud_cdc_write_flush ();
101
- i += n2 ;
102
- written += n2;
103
- last_avail_time = millis ( );
104
- } else {
105
- tud_task ();
106
- tud_cdc_write_flush () ;
107
- if ( connected () ||
108
- (! tud_cdc_write_available () && millis () > last_avail_time + 1000 /* 1 second */ )) {
109
- break ;
110
- }
111
- }
90
+ if (! connected ()) {
91
+ return 0 ;
92
+ }
93
+ usbd_int_set ( false );
94
+ size_t to_send = size, so_far = 0 ;
95
+ while (to_send){
96
+ size_t space = tud_cdc_write_available ();
97
+ if (!space){
98
+ usbd_int_set ( true );
99
+ tud_cdc_write_flush ();
100
+ continue ;
101
+ }
102
+ if (space > to_send){
103
+ space = to_send ;
104
+ }
105
+ size_t sent = tud_cdc_write ( buf+so_far, space );
106
+ usbd_int_set ( true );
107
+ if (sent){
108
+ so_far += sent ;
109
+ to_send -= sent;
110
+ tud_cdc_write_flush ();
111
+ } else {
112
+ size = so_far;
113
+ break ;
112
114
}
113
- } else {
114
- // reset our timeout
115
- last_avail_time = 0 ;
116
115
}
117
- return written ;
116
+ return size ;
118
117
}
119
118
120
119
_SerialUSB::operator bool () {
Original file line number Diff line number Diff line change 109
109
110
110
111
111
// CDC FIFO size of TX and RX
112
- #define CFG_TUD_CDC_RX_BUFSIZE ((TUD_OPT_HIGH_SPEED ? 512 : 64) * 8 )
113
- #define CFG_TUD_CDC_TX_BUFSIZE ((TUD_OPT_HIGH_SPEED ? 512 : 64) * 8 )
112
+ #define CFG_TUD_CDC_RX_BUFSIZE (4096 )
113
+ #define CFG_TUD_CDC_TX_BUFSIZE (64 )
114
114
115
115
// CDC Endpoint transfer buffer size, more is faster
116
116
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
You can’t perform that action at this time.
0 commit comments