Control Surface 2.1.1
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
midi-init.c
Go to the documentation of this file.
1#ifdef ESP32
2#include <sdkconfig.h>
3#if CONFIG_BT_BLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED
4
14#include "events.h"
15#include "midi-private.h"
16
17#include <esp32-hal-bt.h>
18#include <esp_bt_main.h>
19#include <esp_gap_ble_api.h>
20#include <esp_gatt_common_api.h>
21
22#include <assert.h>
23
24// https://github.com/espressif/arduino-esp32/issues/12371
25#if __has_include("esp32-hal-bt-mem.h")
26#include "esp32-hal-bt-mem.h"
27#endif
28
29const char *midi_ble_name = "Control Surface (BLE)";
30
31void set_midi_ble_name(const char *name) { midi_ble_name = name; }
32
33bool midi_init(void) {
34 ESP_LOGI("MIDIBLE", "Ensure Bluetooth started");
35 if (!btStarted() && !btStart())
36 return false;
37 ESP_LOGI("MIDIBLE", "Bluetooth started");
38
40
43 ESP_LOGI("MIDIBLE", "Initializing Bluedroid");
45 if (ret != ESP_OK) {
46 ESP_LOGE("MIDIBLE", "Init bluetooth failed: %s",
48 return false;
49 }
50 }
51
53 ESP_LOGI("MIDIBLE", "Enabling Bluedroid");
55 if (ret != ESP_OK) {
56 ESP_LOGE("MIDIBLE", "Enable bluetooth failed: %s",
58 return false;
59 }
60 }
61
63 if (ret != ESP_OK) {
64 ESP_LOGE("MIDIBLE", "set local MTU failed: %s", esp_err_to_name(ret));
65 return false;
66 }
67
69 if (ret != ESP_OK) {
70 ESP_LOGE("MIDIBLE", "set device name failed: %s", esp_err_to_name(ret));
71 return false;
72 }
73
75 if (ret != ESP_OK) {
76 ESP_LOGE("MIDIBLE", "gap register error: %s", esp_err_to_name(ret));
77 return false;
78 }
79
81 if (ret != ESP_OK) {
82 ESP_LOGE("MIDIBLE", "GATTS register error: %s", esp_err_to_name(ret));
83 return false;
84 }
85
87 if (ret != ESP_OK) {
88 ESP_LOGE("MIDIBLE", "GATTS app register error: %s",
90 return false;
91 }
92
93 // Authentication and security
94
95 // Bonding with peer device after authentication
97 // Set the IO capability to No output No input
100 uint8_t key_size = 16;
104
106 sizeof(auth_req));
107 if (ret != ESP_OK) {
108 ESP_LOGE("MIDIBLE", "Failed to set ESP_BLE_SM_AUTHEN_REQ_MODE: %s",
110 return false;
111 }
112
114 sizeof(iocap));
115 if (ret != ESP_OK) {
116 ESP_LOGE("MIDIBLE", "Failed to set ESP_BLE_SM_IOCAP_MODE: %s",
118 return false;
119 }
120
123 sizeof(auth_option));
124 if (ret != ESP_OK) {
125 ESP_LOGE("MIDIBLE",
126 "Failed to set ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH: %s",
128 return false;
129 }
130
132 sizeof(key_size));
133 if (ret != ESP_OK) {
134 ESP_LOGE("MIDIBLE", "Failed to set ESP_BLE_SM_MAX_KEY_SIZE: %s",
136 return false;
137 }
138
140 sizeof(oob_support));
141 if (ret != ESP_OK) {
142 ESP_LOGE("MIDIBLE", "Failed to set ESP_BLE_SM_OOB_SUPPORT: %s",
144 return false;
145 }
146
148 sizeof(init_key));
149 if (ret != ESP_OK) {
150 ESP_LOGE("MIDIBLE", "Failed to set ESP_BLE_SM_SET_INIT_KEY: %s",
152 return false;
153 }
154
156 sizeof(rsp_key));
157 if (ret != ESP_OK) {
158 ESP_LOGE("MIDIBLE", "Failed to set ESP_BLE_SM_SET_RSP_KEY: %s",
160 return false;
161 }
162
164
165 return true;
166}
167
168bool midi_deinit(void) {
169 assert(!"Not implemented");
170 return false;
171}
172
173#endif
174#endif
Handlers for Bluetooth and BLE events.
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
Declarations of internal functions for the MIDI over BLE system, used in the midi-*....
uint16_t midi_get_app_id(void)
bool midi_deinit()
Cleanup the MIDI BLE application and de-initialize the Bluetooth stack.
bool midi_init()
Initialize the Bluetooth stack and register the MIDI BLE application with the Bluedroid driver.
void set_midi_ble_name(const char *name)
Set the name of the BLE device. Must be set before calling midi_init().