mikroSDK Reference Manual
vendor_device.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_VENDOR_DEVICE_H_
28#define _TUSB_VENDOR_DEVICE_H_
29
30#include "common/tusb_common.h"
31
32#ifndef CFG_TUD_VENDOR_EPSIZE
33#define CFG_TUD_VENDOR_EPSIZE 64
34#endif
35
36#ifdef __cplusplus
37 extern "C" {
38#endif
39
40//--------------------------------------------------------------------+
41// Application API (Multiple Interfaces)
42//--------------------------------------------------------------------+
43bool tud_vendor_n_mounted (uint8_t itf);
44
45uint32_t tud_vendor_n_available (uint8_t itf);
46uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
47bool tud_vendor_n_peek (uint8_t itf, uint8_t* ui8);
48void tud_vendor_n_read_flush (uint8_t itf);
49
50uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
51uint32_t tud_vendor_n_write_flush (uint8_t itf);
52uint32_t tud_vendor_n_write_available (uint8_t itf);
53
54static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
55
56// backward compatible
57#define tud_vendor_n_flush(itf) tud_vendor_n_write_flush(itf)
58
59//--------------------------------------------------------------------+
60// Application API (Single Port)
61//--------------------------------------------------------------------+
62static inline bool tud_vendor_mounted (void);
63static inline uint32_t tud_vendor_available (void);
64static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize);
65static inline bool tud_vendor_peek (uint8_t* ui8);
66static inline void tud_vendor_read_flush (void);
67static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize);
68static inline uint32_t tud_vendor_write_str (char const* str);
69static inline uint32_t tud_vendor_write_available (void);
70static inline uint32_t tud_vendor_write_flush (void);
71
72// backward compatible
73#define tud_vendor_flush() tud_vendor_write_flush()
74
75//--------------------------------------------------------------------+
76// Application Callback API (weak is optional)
77//--------------------------------------------------------------------+
78
79// Invoked when received new data
80TU_ATTR_WEAK void tud_vendor_rx_cb(uint8_t itf);
81// Invoked when last rx transfer finished
82TU_ATTR_WEAK void tud_vendor_tx_cb(uint8_t itf, uint32_t sent_bytes);
83
84//--------------------------------------------------------------------+
85// Inline Functions
86//--------------------------------------------------------------------+
87
88static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str)
89{
90 return tud_vendor_n_write(itf, str, strlen(str));
91}
92
93static inline bool tud_vendor_mounted (void)
94{
95 return tud_vendor_n_mounted(0);
96}
97
98static inline uint32_t tud_vendor_available (void)
99{
100 return tud_vendor_n_available(0);
101}
102
103static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize)
104{
105 return tud_vendor_n_read(0, buffer, bufsize);
106}
107
108static inline bool tud_vendor_peek (uint8_t* ui8)
109{
110 return tud_vendor_n_peek(0, ui8);
111}
112
113static inline void tud_vendor_read_flush(void)
114{
115 tud_vendor_n_read_flush(0);
116}
117
118static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize)
119{
120 return tud_vendor_n_write(0, buffer, bufsize);
121}
122
123static inline uint32_t tud_vendor_write_flush (void)
124{
125 return tud_vendor_n_write_flush(0);
126}
127
128static inline uint32_t tud_vendor_write_str (char const* str)
129{
130 return tud_vendor_n_write_str(0, str);
131}
132
133static inline uint32_t tud_vendor_write_available (void)
134{
135 return tud_vendor_n_write_available(0);
136}
137
138//--------------------------------------------------------------------+
139// Internal Class Driver API
140//--------------------------------------------------------------------+
141void vendord_init(void);
142void vendord_reset(uint8_t rhport);
143uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
144bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
145
146#ifdef __cplusplus
147 }
148#endif
149
150#endif /* _TUSB_VENDOR_DEVICE_H_ */
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647