Open FFBoard
Open source force feedback firmware
bth_device.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2020 Jerzy Kasenberg
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_BTH_DEVICE_H_
28#define _TUSB_BTH_DEVICE_H_
29
30#include <common/tusb_common.h>
31#include <device/usbd.h>
32
33//--------------------------------------------------------------------+
34// Class Driver Configuration
35//--------------------------------------------------------------------+
36#ifndef CFG_TUD_BTH_EVENT_EPSIZE
37#define CFG_TUD_BTH_EVENT_EPSIZE 16
38#endif
39
40#ifndef CFG_TUD_BTH_DATA_EPSIZE
41#define CFG_TUD_BTH_DATA_EPSIZE 64
42#endif
43
44// Allow BTH class to work in historically compatibility mode where the bRequest is always 0xe0.
45// See Bluetooth Core v5.3, Vol. 4, Part B, Section 2.2
46#ifndef CFG_TUD_BTH_HISTORICAL_COMPATIBLE
47#define CFG_TUD_BTH_HISTORICAL_COMPATIBLE 0
48#endif
49
50typedef struct TU_ATTR_PACKED
51{
53 uint8_t param_length;
54 uint8_t param[255];
56
57#ifdef __cplusplus
58 extern "C" {
59#endif
60
61//--------------------------------------------------------------------+
62// Application Callback API (weak is optional)
63//--------------------------------------------------------------------+
64
65// Invoked when HCI command was received over USB from Bluetooth host.
66// Detailed format is described in Bluetooth core specification Vol 2,
67// Part E, 5.4.1.
68// Length of the command is from 3 bytes (2 bytes for OpCode,
69// 1 byte for parameter total length) to 258.
70TU_ATTR_WEAK void tud_bt_hci_cmd_cb(void *hci_cmd, size_t cmd_len);
71
72// Invoked when ACL data was received over USB from Bluetooth host.
73// Detailed format is described in Bluetooth core specification Vol 2,
74// Part E, 5.4.2.
75// Length is from 4 bytes, (12 bits for Handle, 4 bits for flags
76// and 16 bits for data total length) to endpoint size.
77TU_ATTR_WEAK void tud_bt_acl_data_received_cb(void *acl_data, uint16_t data_len);
78
79// Called when event sent with tud_bt_event_send() was delivered to BT stack.
80// Controller can release/reuse buffer with Event packet at this point.
81TU_ATTR_WEAK void tud_bt_event_sent_cb(uint16_t sent_bytes);
82
83// Called when ACL data that was sent with tud_bt_acl_data_send()
84// was delivered to BT stack.
85// Controller can release/reuse buffer with ACL packet at this point.
86TU_ATTR_WEAK void tud_bt_acl_data_sent_cb(uint16_t sent_bytes);
87
88// Bluetooth controller calls this function when it wants to send even packet
89// as described in Bluetooth core specification Vol 2, Part E, 5.4.4.
90// Event has at least 2 bytes, first is Event code second contains parameter
91// total length. Controller can release/reuse event memory after
92// tud_bt_event_sent_cb() is called.
93bool tud_bt_event_send(void *event, uint16_t event_len);
94
95// Bluetooth controller calls this to send ACL data packet
96// as described in Bluetooth core specification Vol 2, Part E, 5.4.2
97// Minimum length is 4 bytes, (12 bits for Handle, 4 bits for flags
98// and 16 bits for data total length). Upper limit is not limited
99// to endpoint size since buffer is allocate by controller
100// and must not be reused till tud_bt_acl_data_sent_cb() is called.
101bool tud_bt_acl_data_send(void *acl_data, uint16_t data_len);
102
103//--------------------------------------------------------------------+
104// Internal Class Driver API
105//--------------------------------------------------------------------+
106void btd_init (void);
107bool btd_deinit (void);
108void btd_reset (uint8_t rhport);
109uint16_t btd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
110bool btd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
111bool btd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
112
113#ifdef __cplusplus
114 }
115#endif
116
117#endif /* _TUSB_BTH_DEVICE_H_ */
bool tud_bt_event_send(void *event, uint16_t event_len)
Definition: bth_device.c:85
struct TU_ATTR_PACKED bt_hci_cmd_t
TU_ATTR_WEAK void tud_bt_acl_data_sent_cb(uint16_t sent_bytes)
void btd_init(void)
Definition: bth_device.c:98
void btd_reset(uint8_t rhport)
Definition: bth_device.c:106
bool btd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
Definition: bth_device.c:218
bool btd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes)
Definition: bth_device.c:259
uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
Definition: bth_device.c:111
bool tud_bt_acl_data_send(void *acl_data, uint16_t data_len)
Definition: bth_device.c:90
bool btd_deinit(void)
Definition: bth_device.c:102
TU_ATTR_WEAK void tud_bt_event_sent_cb(uint16_t sent_bytes)
TU_ATTR_WEAK void tud_bt_acl_data_received_cb(void *acl_data, uint16_t data_len)
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
uint8_t param_length
Definition: bth_device.h:53
uint16_t op_code
Definition: bth_device.h:52
volatile uint16_t
Definition: hcd_rusb2.c:58
uint8_t param[255]
Definition: bth_device.h:54
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