Merge pull request #1814 from hathach/more-host-cdc

add tuh_cdc_peek()
This commit is contained in:
Ha Thach 2022-12-25 00:50:18 +07:00 committed by GitHub
commit 4b5880671c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 3 deletions

View File

@ -80,7 +80,7 @@ int32_t tud_cdc_n_read_char (uint8_t itf);
// Clear the received FIFO
void tud_cdc_n_read_flush (uint8_t itf);
// Get a byte from FIFO at the specified position without removing it
// Get a byte from FIFO without removing it
bool tud_cdc_n_peek (uint8_t itf, uint8_t* ui8);
// Write bytes to TX FIFO, data may remain in the FIFO for a while

View File

@ -228,6 +228,14 @@ uint32_t tuh_cdc_read_available(uint8_t idx)
return tu_edpt_stream_read_available(&p_cdc->stream.rx);
}
bool tuh_cdc_peek(uint8_t idx, uint8_t* ch)
{
cdch_interface_t* p_cdc = get_itf(idx);
TU_VERIFY(p_cdc);
return tu_edpt_stream_peek(&p_cdc->stream.rx, ch);
}
bool tuh_cdc_read_clear (uint8_t idx)
{
cdch_interface_t* p_cdc = get_itf(idx);

View File

@ -134,6 +134,9 @@ uint32_t tuh_cdc_read_available(uint8_t idx);
// Read from cdc interface
uint32_t tuh_cdc_read (uint8_t idx, void* buffer, uint32_t bufsize);
// Get a byte from RX FIFO without removing it
bool tuh_cdc_peek(uint8_t idx, uint8_t* ch);
// Clear the received FIFO
bool tuh_cdc_read_clear (uint8_t idx);

View File

@ -682,8 +682,6 @@ uint16_t tu_fifo_read_n_const_addr_full_words(tu_fifo_t* f, void * buffer, uint1
@param[in] f
Pointer to the FIFO buffer to manipulate
@param[in] offset
Position to read from in the FIFO buffer with respect to read pointer
@param[in] p_buffer
Pointer to the place holder for data read from the buffer

View File

@ -160,6 +160,11 @@ uint32_t tu_edpt_stream_read_available(tu_edpt_stream_t* s)
return (uint32_t) tu_fifo_count(&s->ff);
}
TU_ATTR_ALWAYS_INLINE static inline
bool tu_edpt_stream_peek(tu_edpt_stream_t* s, uint8_t* ch)
{
return tu_fifo_peek(&s->ff, ch);
}
#ifdef __cplusplus
}