mikroSDK Reference Manual
bth_device.h
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#ifndef CFG_TUD_BTH_DATA_EPSIZE
40#define CFG_TUD_BTH_DATA_EPSIZE 64
41#endif
42
43typedef struct TU_ATTR_PACKED
44{
45 uint16_t op_code;
46 uint8_t param_length;
47 uint8_t param[255];
49
50#ifdef __cplusplus
51 extern "C" {
52#endif
53
54//--------------------------------------------------------------------+
55// Application Callback API (weak is optional)
56//--------------------------------------------------------------------+
57
58// Invoked when HCI command was received over USB from Bluetooth host.
59// Detailed format is described in Bluetooth core specification Vol 2,
60// Part E, 5.4.1.
61// Length of the command is from 3 bytes (2 bytes for OpCode,
62// 1 byte for parameter total length) to 258.
63TU_ATTR_WEAK void tud_bt_hci_cmd_cb(void *hci_cmd, size_t cmd_len);
64
65// Invoked when ACL data was received over USB from Bluetooth host.
66// Detailed format is described in Bluetooth core specification Vol 2,
67// Part E, 5.4.2.
68// Length is from 4 bytes, (12 bits for Handle, 4 bits for flags
69// and 16 bits for data total length) to endpoint size.
70TU_ATTR_WEAK void tud_bt_acl_data_received_cb(void *acl_data, uint16_t data_len);
71
72// Called when event sent with tud_bt_event_send() was delivered to BT stack.
73// Controller can release/reuse buffer with Event packet at this point.
74TU_ATTR_WEAK void tud_bt_event_sent_cb(uint16_t sent_bytes);
75
76// Called when ACL data that was sent with tud_bt_acl_data_send()
77// was delivered to BT stack.
78// Controller can release/reuse buffer with ACL packet at this point.
79TU_ATTR_WEAK void tud_bt_acl_data_sent_cb(uint16_t sent_bytes);
80
81// Bluetooth controller calls this function when it wants to send even packet
82// as described in Bluetooth core specification Vol 2, Part E, 5.4.4.
83// Event has at least 2 bytes, first is Event code second contains parameter
84// total length. Controller can release/reuse event memory after
85// tud_bt_event_sent_cb() is called.
86bool tud_bt_event_send(void *event, uint16_t event_len);
87
88// Bluetooth controller calls this to send ACL data packet
89// as described in Bluetooth core specification Vol 2, Part E, 5.4.2
90// Minimum length is 4 bytes, (12 bits for Handle, 4 bits for flags
91// and 16 bits for data total length). Upper limit is not limited
92// to endpoint size since buffer is allocate by controller
93// and must not be reused till tud_bt_acl_data_sent_cb() is called.
94bool tud_bt_acl_data_send(void *acl_data, uint16_t data_len);
95
96//--------------------------------------------------------------------+
97// Internal Class Driver API
98//--------------------------------------------------------------------+
99void btd_init (void);
100void btd_reset (uint8_t rhport);
101uint16_t btd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
102bool btd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
103bool btd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
104
105#ifdef __cplusplus
106 }
107#endif
108
109#endif /* _TUSB_BTH_DEVICE_H_ */
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647