-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathble_midi_server.h
100 lines (93 loc) · 3.5 KB
/
ble_midi_server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @brief This library wraps the ble_midi_service_lib to make
* a Bluetooth LE MIDI server without any other services
* in the profile. In makes use of the ATT database stored
* in the global profile_data[] array that the application
* provides. This data is usually generated by the
* CMake function pico_btstack_make_gatt_header().
*/
/**
* MIT License
*
* Copyright (c) 2024 rppicomidi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#pragma once
#include <stdint.h>
#include "btstack.h"
#include "pico/cyw43_arch.h"
#include "pico/btstack_cyw43.h"
#include "midi_service_stream_handler.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief initialize BT hardware and stack and then start advertising
*
* @param profile_data is automatically generated from the .gatt file
* @param resp_data is the data to send in response to active scanning
* @param resp_data_len is the number of bytes in the resp_data buffer
*/
void ble_midi_server_init(const uint8_t* profile_data, const uint8_t* resp_data, uint8_t resp_data_len, io_capability_t iocaps, uint8_t secmask);
/**
* @brief disconnect if needed. stop advertising if needed.
*
* de-initialize the BT stack and hardware in preparation to switch to client mode
*/
void ble_midi_server_deinit();
/**
* @brief read a MIDI stream from Bluetooth if connected and data is available
*
* @param max_bytes is the maximum number of bytes that can be returned in the midi_stream_bytes buffer
* @param midi_stream_bytes is buffer to receive bytes read
* @param timestamp is the Bluetooth MIDI timestamp value
* @returns the number of bytes stored in the midi_stream_bytes buffer
*/
uint8_t ble_midi_server_stream_read(uint8_t max_bytes, uint8_t* midi_stream_bytes, uint16_t* timestamp);
/**
* @brief write a MIDI stream to Bluetooth if connected
*
* @param nbytes is the number of bytes to write
* @param midi_stream_bytes is the buffer of bytes to write
* @return the number of bytes from the stream actually written
*/
uint8_t ble_midi_server_stream_write(uint8_t nbytes, const uint8_t* midi_stream_bytes);
/**
* @brief request disconnection from currently connected Bluetooth client
*
* This function returns before the disconnection is complete.
*/
void ble_midi_server_request_disconnect();
/**
* @brief
*
* @return true if a Bluetooth client is connected to the server
*/
bool ble_midi_server_is_connected();
/**
* @brief
*
* @return true if the Bluetooth server is initialized
*/
bool ble_midi_server_is_initialized();
#ifdef __cplusplus
}
#endif