Open FFBoard
Open source force feedback firmware
net_device.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2020 Peter Lawrence
5 * Copyright (c) 2019 Ha Thach (tinyusb.org)
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 * This file is part of the TinyUSB stack.
26 */
27
28#ifndef _TUSB_NET_DEVICE_H_
29#define _TUSB_NET_DEVICE_H_
30
31#include <stdint.h>
32#include "class/cdc/cdc.h"
33
34#if CFG_TUD_ECM_RNDIS && CFG_TUD_NCM
35#error "Cannot enable both ECM_RNDIS and NCM network drivers"
36#endif
37
38/* declared here, NOT in usb_descriptors.c, so that the driver can intelligently ZLP as needed */
39#define CFG_TUD_NET_ENDPOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
40
41/* Maximum Transmission Unit (in bytes) of the network, including Ethernet header */
42#ifndef CFG_TUD_NET_MTU
43#define CFG_TUD_NET_MTU 1514
44#endif
45
46
47// Table 4.3 Data Class Interface Protocol Codes
48typedef enum
49{
52
53
54#ifdef __cplusplus
55 extern "C" {
56#endif
57
58//--------------------------------------------------------------------+
59// Application API
60//--------------------------------------------------------------------+
61
62// indicate to network driver that client has finished with the packet provided to network_recv_cb()
63void tud_network_recv_renew(void);
64
65// poll network driver for its ability to accept another packet to transmit
66bool tud_network_can_xmit(uint16_t size);
67
68// if network_can_xmit() returns true, network_xmit() can be called once
69void tud_network_xmit(void *ref, uint16_t arg);
70
71//--------------------------------------------------------------------+
72// Application Callbacks (WEAK is optional)
73//--------------------------------------------------------------------+
74
75// client must provide this: return false if the packet buffer was not accepted
76bool tud_network_recv_cb(const uint8_t *src, uint16_t size);
77
78// client must provide this: copy from network stack packet pointer to dst
79uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg);
80
81//------------- ECM/RNDIS -------------//
82
83// client must provide this: initialize any network state back to the beginning
85
86// client must provide this: 48-bit MAC address
87// TODO removed later since it is not part of tinyusb stack
88extern uint8_t tud_network_mac_address[6];
89
90//--------------------------------------------------------------------+
91// INTERNAL USBD-CLASS DRIVER API
92//--------------------------------------------------------------------+
93void netd_init (void);
94bool netd_deinit (void);
95void netd_reset (uint8_t rhport);
96uint16_t netd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
97bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
98bool netd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
99void netd_report (uint8_t *buf, uint16_t len);
100
101#ifdef __cplusplus
102 }
103#endif
104
105#endif /* _TUSB_NET_DEVICE_H_ */
void tud_network_recv_renew(void)
void netd_reset(uint8_t rhport)
void netd_report(uint8_t *buf, uint16_t len)
bool tud_network_recv_cb(const uint8_t *src, uint16_t size)
ncm_data_interface_protocol_code_t
Definition: net_device.h:49
@ NCM_DATA_PROTOCOL_NETWORK_TRANSFER_BLOCK
Definition: net_device.h:50
uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
void tud_network_xmit(void *ref, uint16_t arg)
void tud_network_init_cb(void)
uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg)
bool netd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
bool netd_deinit(void)
void netd_init(void)
uint8_t tud_network_mac_address[6]
bool tud_network_can_xmit(uint16_t size)
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
xfer_result_t
Definition: tusb_types.h:236
CFG_TUH_MEM_ALIGN tusb_control_request_t request
Definition: usbh.c:259
volatile uint8_t stage
Definition: usbh.c:265