Skip to content

Commit 76ad641

Browse files
authored
Merge pull request #226 from adafruit/add-cdc-host-peek
Add cdc host peek
2 parents 3a2e592 + 2c34029 commit 76ad641

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

src/arduino/cdc/Adafruit_USBH_CDC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ int Adafruit_USBH_CDC::available(void) {
4949
}
5050

5151
int Adafruit_USBH_CDC::peek(void) {
52-
// TODO support later
53-
return -1;
52+
uint8_t ch;
53+
return tuh_cdc_peek(_idx, &ch) ? (int)ch : -1;
5454
}
5555

5656
int Adafruit_USBH_CDC::read(void) {

src/class/cdc/cdc_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int32_t tud_cdc_n_read_char (uint8_t itf);
8080
// Clear the received FIFO
8181
void tud_cdc_n_read_flush (uint8_t itf);
8282

83-
// Get a byte from FIFO at the specified position without removing it
83+
// Get a byte from FIFO without removing it
8484
bool tud_cdc_n_peek (uint8_t itf, uint8_t* ui8);
8585

8686
// Write bytes to TX FIFO, data may remain in the FIFO for a while

src/class/cdc/cdc_host.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ uint32_t tuh_cdc_read_available(uint8_t idx)
228228
return tu_edpt_stream_read_available(&p_cdc->stream.rx);
229229
}
230230

231+
bool tuh_cdc_peek(uint8_t idx, uint8_t* ch)
232+
{
233+
cdch_interface_t* p_cdc = get_itf(idx);
234+
TU_VERIFY(p_cdc);
235+
236+
return tu_edpt_stream_peek(&p_cdc->stream.rx, ch);
237+
}
238+
231239
bool tuh_cdc_read_clear (uint8_t idx)
232240
{
233241
cdch_interface_t* p_cdc = get_itf(idx);

src/class/cdc/cdc_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ uint32_t tuh_cdc_read_available(uint8_t idx);
134134
// Read from cdc interface
135135
uint32_t tuh_cdc_read (uint8_t idx, void* buffer, uint32_t bufsize);
136136

137+
// Get a byte from RX FIFO without removing it
138+
bool tuh_cdc_peek(uint8_t idx, uint8_t* ch);
139+
137140
// Clear the received FIFO
138141
bool tuh_cdc_read_clear (uint8_t idx);
139142

src/common/tusb_fifo.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,6 @@ uint16_t tu_fifo_read_n_const_addr_full_words(tu_fifo_t* f, void * buffer, uint1
682682
683683
@param[in] f
684684
Pointer to the FIFO buffer to manipulate
685-
@param[in] offset
686-
Position to read from in the FIFO buffer with respect to read pointer
687685
@param[in] p_buffer
688686
Pointer to the place holder for data read from the buffer
689687

src/common/tusb_private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ uint32_t tu_edpt_stream_read_available(tu_edpt_stream_t* s)
160160
return (uint32_t) tu_fifo_count(&s->ff);
161161
}
162162

163+
TU_ATTR_ALWAYS_INLINE static inline
164+
bool tu_edpt_stream_peek(tu_edpt_stream_t* s, uint8_t* ch)
165+
{
166+
return tu_fifo_peek(&s->ff, ch);
167+
}
163168

164169
#ifdef __cplusplus
165170
}

0 commit comments

Comments
 (0)