Open FFBoard
Open source force feedback firmware
vendor_device.h
Go to the documentation of this file.
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// RX FIFO can be disabled by setting this value to 0
37#ifndef CFG_TUD_VENDOR_RX_BUFSIZE
38#define CFG_TUD_VENDOR_RX_BUFSIZE 64
39#endif
40
41// TX FIFO can be disabled by setting this value to 0
42#ifndef CFG_TUD_VENDOR_TX_BUFSIZE
43#define CFG_TUD_VENDOR_TX_BUFSIZE 64
44#endif
45
46#ifdef __cplusplus
47 extern "C" {
48#endif
49
50//--------------------------------------------------------------------+
51// Application API (Multiple Interfaces) i.e CFG_TUD_VENDOR > 1
52//--------------------------------------------------------------------+
53bool tud_vendor_n_mounted (uint8_t itf);
54uint32_t tud_vendor_n_available (uint8_t itf);
55uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
56bool tud_vendor_n_peek (uint8_t itf, uint8_t* ui8);
57void tud_vendor_n_read_flush (uint8_t itf);
58
59uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
60uint32_t tud_vendor_n_write_flush (uint8_t itf);
61uint32_t tud_vendor_n_write_available (uint8_t itf);
62
63TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
64
65// backward compatible
66#define tud_vendor_n_flush(itf) tud_vendor_n_write_flush(itf)
67
68//--------------------------------------------------------------------+
69// Application API (Single Port) i.e CFG_TUD_VENDOR = 1
70//--------------------------------------------------------------------+
71
72TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_n_write_str(uint8_t itf, char const* str) {
73 return tud_vendor_n_write(itf, str, strlen(str));
74}
75
76TU_ATTR_ALWAYS_INLINE static inline bool tud_vendor_mounted(void) {
77 return tud_vendor_n_mounted(0);
78}
79
80TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_available(void) {
81 return tud_vendor_n_available(0);
82}
83
84TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_read(void* buffer, uint32_t bufsize) {
86}
87
88TU_ATTR_ALWAYS_INLINE static inline bool tud_vendor_peek(uint8_t* ui8) {
89 return tud_vendor_n_peek(0, ui8);
90}
91
92TU_ATTR_ALWAYS_INLINE static inline void tud_vendor_read_flush(void) {
94}
95
96TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_write(void const* buffer, uint32_t bufsize) {
98}
99
100TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_write_str(char const* str) {
101 return tud_vendor_n_write_str(0, str);
102}
103
104TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_write_flush(void) {
105 return tud_vendor_n_write_flush(0);
106}
107
108#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
109TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_write_available(void) {
111}
112#endif
113
114// backward compatible
115#define tud_vendor_flush() tud_vendor_write_flush()
116
117//--------------------------------------------------------------------+
118// Application Callback API (weak is optional)
119//--------------------------------------------------------------------+
120
121// Invoked when received new data
122TU_ATTR_WEAK void tud_vendor_rx_cb(uint8_t itf, uint8_t const* buffer, uint16_t bufsize);
123// Invoked when last rx transfer finished
124TU_ATTR_WEAK void tud_vendor_tx_cb(uint8_t itf, uint32_t sent_bytes);
125
126//--------------------------------------------------------------------+
127// Inline Functions
128//--------------------------------------------------------------------+
129
130
131//--------------------------------------------------------------------+
132// Internal Class Driver API
133//--------------------------------------------------------------------+
134void vendord_init(void);
135bool vendord_deinit(void);
136void vendord_reset(uint8_t rhport);
137uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
138bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
139
140#ifdef __cplusplus
141 }
142#endif
143
144#endif /* _TUSB_VENDOR_DEVICE_H_ */
uint8_t const * buffer
Definition: midi_device.h:100
uint32_t bufsize
Definition: midi_device.h:95
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
xfer_result_t
Definition: tusb_types.h:236
bool tud_vendor_n_mounted(uint8_t itf)
Definition: vendor_device.c:71
bool vendord_deinit(void)
static TU_ATTR_ALWAYS_INLINE uint32_t tud_vendor_read(void *buffer, uint32_t bufsize)
Definition: vendor_device.h:84
uint32_t tud_vendor_n_available(uint8_t itf)
Definition: vendor_device.c:80
static TU_ATTR_ALWAYS_INLINE void tud_vendor_read_flush(void)
Definition: vendor_device.h:92
void vendord_reset(uint8_t rhport)
static TU_ATTR_ALWAYS_INLINE uint32_t tud_vendor_write_str(char const *str)
static TU_ATTR_ALWAYS_INLINE bool tud_vendor_mounted(void)
Definition: vendor_device.h:76
uint32_t tud_vendor_n_read(uint8_t itf, void *buffer, uint32_t bufsize)
Definition: vendor_device.c:94
TU_ATTR_WEAK void tud_vendor_tx_cb(uint8_t itf, uint32_t sent_bytes)
static TU_ATTR_ALWAYS_INLINE uint32_t tud_vendor_write_available(void)
uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
void tud_vendor_n_read_flush(uint8_t itf)
static TU_ATTR_ALWAYS_INLINE uint32_t tud_vendor_write(void const *buffer, uint32_t bufsize)
Definition: vendor_device.h:96
bool tud_vendor_n_peek(uint8_t itf, uint8_t *ui8)
Definition: vendor_device.c:87
static TU_ATTR_ALWAYS_INLINE uint32_t tud_vendor_available(void)
Definition: vendor_device.h:80
static TU_ATTR_ALWAYS_INLINE bool tud_vendor_peek(uint8_t *ui8)
Definition: vendor_device.h:88
static TU_ATTR_ALWAYS_INLINE uint32_t tud_vendor_n_write_str(uint8_t itf, char const *str)
Definition: vendor_device.h:72
static TU_ATTR_ALWAYS_INLINE uint32_t tud_vendor_write_flush(void)
uint32_t tud_vendor_n_write(uint8_t itf, void const *buffer, uint32_t bufsize)
uint32_t tud_vendor_n_write_available(uint8_t itf)
TU_ATTR_WEAK void tud_vendor_rx_cb(uint8_t itf, uint8_t const *buffer, uint16_t bufsize)
void vendord_init(void)
uint32_t tud_vendor_n_write_flush(uint8_t itf)