Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
midi-app.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
13#include "advertising.h"
14#include "logging.h"
15#include "midi-private.h"
16
17#include <esp_gatt_defs.h>
18#include <stddef.h> // NULL
19#include <string.h> // memcpy
20
23static const uint8_t MIDI_SERVICE_UUID_128[16] = {
24 0x00, 0xc7, 0xc4, 0x4e, 0xe3, 0x6c, //
25 0x51, 0xa7, //
26 0x33, 0x4b, //
27 0xe8, 0xed, //
28 0x5a, 0x0e, 0xb8, 0x03, //
29};
30
33static const uint8_t MIDI_char_uuid128[16] = {
34 0xf3, 0x6b, 0x10, 0x9d, 0x66, 0xf2, //
35 0xa9, 0xa1, //
36 0x12, 0x41, //
37 0x68, 0x38, //
38 0xdb, 0xe5, 0x72, 0x77, //
39};
40
46
48enum {
54};
55
56// <?> What does this do?
57// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/bluetooth/esp_gatts.html#_CPPv429esp_ble_gatts_create_attr_tabPK19esp_gatts_attr_db_t13esp_gatt_if_t7uint8_t7uint8_t
58static const uint8_t MIDI_SERVICE_INSTANCE_ID = 0;
59
64
65/* Full Database Description - Used to add attributes into the database */
66static const esp_gatts_attr_db_t
68 // Service Declaration
70 {
71 .attr_control = {ESP_GATT_AUTO_RSP},
72 {
73 .uuid_length = sizeof(primary_service_uuid),
75 .perm = ESP_GATT_PERM_READ,
76 .max_length = sizeof(MIDI_SERVICE_UUID_128),
77 .length = sizeof(MIDI_SERVICE_UUID_128),
79 },
80 },
81
82 // Characteristic Declaration
84 {
85 .attr_control = {ESP_GATT_AUTO_RSP},
86 {
87 .uuid_length = sizeof(character_declaration_uuid),
89 .perm = ESP_GATT_PERM_READ,
90 .max_length = sizeof(MIDI_properties),
91 .length = sizeof(MIDI_properties),
92 .value = (uint8_t *)&MIDI_properties,
93 },
94 },
95
96 // Characteristic Value
98 {
99 .attr_control = {ESP_GATT_RSP_BY_APP},
100 {
101 .uuid_length = sizeof(MIDI_char_uuid128),
104 .max_length = 0,
105 .length = 0,
106 .value = NULL,
107 },
108 },
109
110 // Client Characteristic Configuration Descriptor (0x2902)
112 {
113 .attr_control = {ESP_GATT_AUTO_RSP},
114 {
115 .uuid_length = sizeof(character_client_config_uuid),
118 .max_length = 2,
119 .length = 0,
120 .value = NULL,
121 },
122 },
123};
124
126
128
131}
132
135 // Set the Service UUID for advertisement
137 sizeof(MIDI_SERVICE_UUID_128));
138
139 // Register the GATTS service table
143 if (ret) {
144 ESP_LOGE("MIDIBLE", "Create attribute table failed, error code: %d",
145 ret);
146 }
147}
148
151 if (param->add_attr_tab.num_handle != MIDI_ATTRIBUTE_TABLE_SIZE) {
152 ESP_LOGE("MIDIBLE",
153 "Create attribute table error, num_handle (%d) "
154 "doesn't equal MIDI_ATTRIBUTE_TABLE_SIZE (%d)",
155 param->add_attr_tab.num_handle, MIDI_ATTRIBUTE_TABLE_SIZE);
156 return;
157 }
158 ESP_LOGI("MIDIBLE",
159 "Created attribute table successfully, number of "
160 "handles: %d\n",
161 param->add_attr_tab.num_handle);
162 // Save the handles to the created services, characteristics and
163 // desriptors
164 memcpy(MIDI_handle_table, param->add_attr_tab.handles,
165 sizeof(MIDI_handle_table));
166 // Start the MIDI service.
168}
169
172}
173
176}
177
180}
181
182uint16_t midi_get_app_id(void) { return 0x55; }
184
185#endif
186#endif
Advertising the MIDI service for Bluetooth Low Energy.
void advertising_set_service_uuid(const uint8_t uuid[], uint16_t length)
Set the UUID of the service to be advertised.
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-*....
void midi_handle_register_app_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void midi_register_interface(esp_gatt_if_t gatts_if)
uint16_t midi_get_app_id(void)
uint16_t midi_get_gatts_if(void)
void midi_handle_create_attribute_table_event(esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
uint16_t midi_get_service_handle(void)
uint16_t midi_get_descriptor_handle(void)
uint16_t midi_get_characteristic_handle(void)