|
27 | 27 | #ifndef TUSB_VENDOR_DEVICE_H_ |
28 | 28 | #define TUSB_VENDOR_DEVICE_H_ |
29 | 29 |
|
| 30 | +#ifdef __cplusplus |
| 31 | +extern "C" { |
| 32 | +#endif |
| 33 | + |
30 | 34 | #include "common/tusb_common.h" |
31 | 35 |
|
| 36 | +//--------------------------------------------------------------------+ |
| 37 | +// Configuration |
| 38 | +//--------------------------------------------------------------------+ |
32 | 39 | #ifndef CFG_TUD_VENDOR_EPSIZE |
33 | 40 | #define CFG_TUD_VENDOR_EPSIZE 64 |
34 | 41 | #endif |
|
43 | 50 | #define CFG_TUD_VENDOR_TX_BUFSIZE 64 |
44 | 51 | #endif |
45 | 52 |
|
46 | | -#ifdef __cplusplus |
47 | | -extern "C" { |
| 53 | +// Application will manually schedule RX transfer. This can be useful when using with non-fifo (buffered) mode |
| 54 | +// i.e. CFG_TUD_VENDOR_RX_BUFSIZE = 0 |
| 55 | +#ifndef CFG_TUD_VENDOR_RX_MANUAL_XFER |
| 56 | + #define CFG_TUD_VENDOR_RX_MANUAL_XFER 0 |
48 | 57 | #endif |
49 | 58 |
|
50 | 59 | //--------------------------------------------------------------------+ |
51 | 60 | // Application API (Multiple Interfaces) i.e CFG_TUD_VENDOR > 1 |
52 | 61 | //--------------------------------------------------------------------+ |
53 | | -bool tud_vendor_n_mounted(uint8_t idx); |
| 62 | + |
| 63 | +// Return whether the vendor interface is mounted |
| 64 | +bool tud_vendor_n_mounted(uint8_t idx); |
54 | 65 |
|
55 | 66 | #if CFG_TUD_VENDOR_RX_BUFSIZE > 0 |
| 67 | +// Return number of available bytes for reading |
56 | 68 | uint32_t tud_vendor_n_available(uint8_t idx); |
57 | | -bool tud_vendor_n_peek(uint8_t idx, uint8_t *ui8); |
| 69 | + |
| 70 | +// Peek a byte from RX buffer |
| 71 | +bool tud_vendor_n_peek(uint8_t idx, uint8_t *ui8); |
| 72 | + |
| 73 | +// Read from RX FIFO |
58 | 74 | uint32_t tud_vendor_n_read(uint8_t idx, void *buffer, uint32_t bufsize); |
| 75 | + |
| 76 | +// Discard count bytes in RX FIFO |
59 | 77 | uint32_t tud_vendor_n_read_discard(uint8_t idx, uint32_t count); |
60 | | -void tud_vendor_n_read_flush(uint8_t idx); |
| 78 | + |
| 79 | +// Flush (clear) RX FIFO |
| 80 | +void tud_vendor_n_read_flush(uint8_t idx); |
| 81 | +#endif |
| 82 | + |
| 83 | +#if CFG_TUD_VENDOR_RX_MANUAL_XFER |
| 84 | +// Start a new RX transfer to fill the RX FIFO, return false if previous transfer is still ongoing |
| 85 | +bool tud_vendor_n_read_xfer(uint8_t idx); |
61 | 86 | #endif |
62 | 87 |
|
| 88 | +// Write to TX FIFO. This can be buffered and not sent immediately unless buffered bytes >= USB endpoint size |
63 | 89 | uint32_t tud_vendor_n_write(uint8_t idx, const void *buffer, uint32_t bufsize); |
64 | 90 |
|
65 | 91 | #if CFG_TUD_VENDOR_TX_BUFSIZE > 0 |
| 92 | +// Force sending buffered data, return number of bytes sent |
66 | 93 | uint32_t tud_vendor_n_write_flush(uint8_t idx); |
| 94 | + |
| 95 | +// Return number of bytes available for writing in TX FIFO |
67 | 96 | uint32_t tud_vendor_n_write_available(uint8_t idx); |
68 | 97 | #endif |
69 | 98 |
|
| 99 | +// Write a null-terminated string to TX FIFO |
70 | 100 | TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_n_write_str(uint8_t idx, const char *str) { |
71 | 101 | return tud_vendor_n_write(idx, str, strlen(str)); |
72 | 102 | } |
@@ -103,6 +133,12 @@ TU_ATTR_ALWAYS_INLINE static inline void tud_vendor_read_flush(void) { |
103 | 133 | } |
104 | 134 | #endif |
105 | 135 |
|
| 136 | +#if CFG_TUD_VENDOR_RX_MANUAL_XFER |
| 137 | +TU_ATTR_ALWAYS_INLINE static inline bool tud_vendor_read_xfer(void) { |
| 138 | + return tud_vendor_n_read_xfer(0); |
| 139 | +} |
| 140 | +#endif |
| 141 | + |
106 | 142 | TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_write(const void *buffer, uint32_t bufsize) { |
107 | 143 | return tud_vendor_n_write(0, buffer, bufsize); |
108 | 144 | } |
|
0 commit comments