@@ -165,6 +165,8 @@ void Serial_::end(void)
165
165
166
166
void Serial_::accept (void )
167
167
{
168
+ if (!Is_otg_enabled ()) return ;
169
+
168
170
static uint32_t guard = 0 ;
169
171
170
172
// synchronized access to guard
@@ -202,12 +204,16 @@ void Serial_::accept(void)
202
204
203
205
int Serial_::available (void )
204
206
{
207
+ if (!Is_otg_enabled ()) return 0 ;
208
+
205
209
ring_buffer *buffer = &cdc_rx_buffer;
206
210
return (unsigned int )(CDC_SERIAL_BUFFER_SIZE + buffer->head - buffer->tail ) % CDC_SERIAL_BUFFER_SIZE;
207
211
}
208
212
209
213
int Serial_::peek (void )
210
214
{
215
+ if (!Is_otg_enabled ()) return -1 ;
216
+
211
217
ring_buffer *buffer = &cdc_rx_buffer;
212
218
213
219
if (buffer->head == buffer->tail )
@@ -222,6 +228,8 @@ int Serial_::peek(void)
222
228
223
229
int Serial_::read (void )
224
230
{
231
+ if (!Is_otg_enabled ()) return -1 ;
232
+
225
233
ring_buffer *buffer = &cdc_rx_buffer;
226
234
227
235
// if the head isn't ahead of the tail, we don't have any characters
@@ -241,11 +249,15 @@ int Serial_::read(void)
241
249
242
250
void Serial_::flush (void )
243
251
{
252
+ if (!Is_otg_enabled ()) return ;
253
+
244
254
USBD_Flush (CDC_TX);
245
255
}
246
256
247
257
size_t Serial_::write (const uint8_t *buffer, size_t size)
248
258
{
259
+ if (!Is_otg_enabled ()) return 0 ;
260
+
249
261
/* only try to send bytes if the high-level CDC connection itself
250
262
is open (not just the pipe) - the OS should set lineState when the port
251
263
is opened and clear lineState when the port is closed.
0 commit comments