Selaa lähdekoodia

add tuh_cdc_peek()

hathach 3 vuotta sitten
vanhempi
sitoutus
48d4a67ec5

+ 1 - 1
src/class/cdc/cdc_device.h

@@ -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

+ 8 - 0
src/class/cdc/cdc_host.c

@@ -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);

+ 3 - 0
src/class/cdc/cdc_host.h

@@ -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);
 

+ 0 - 2
src/common/tusb_fifo.c

@@ -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
 

+ 5 - 0
src/common/tusb_private.h

@@ -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
  }