3#if CONFIG_BT_BLE_ENABLED
17#include <esp_gatt_defs.h>
23static const uint8_t MIDI_SERVICE_UUID_128[16] = {
24 0x00, 0xc7, 0xc4, 0x4e, 0xe3, 0x6c,
28 0x5a, 0x0e, 0xb8, 0x03,
33static const uint8_t MIDI_char_uuid128[16] = {
34 0xf3, 0x6b, 0x10, 0x9d, 0x66, 0xf2,
38 0xdb, 0xe5, 0x72, 0x77,
43const esp_gatt_char_prop_t MIDI_properties = ESP_GATT_CHAR_PROP_BIT_READ |
44 ESP_GATT_CHAR_PROP_BIT_WRITE_NR |
45 ESP_GATT_CHAR_PROP_BIT_NOTIFY;
50 MIDI_CHARACTERISTIC_DECLARATION_INDEX,
51 MIDI_CHARACTERISTIC_VALUE_INDEX,
52 MIDI_2902_DESCRIPTOR_INDEX,
53 MIDI_ATTRIBUTE_TABLE_SIZE,
58static const uint8_t MIDI_SERVICE_INSTANCE_ID = 0;
60static const uint16_t primary_service_uuid = ESP_GATT_UUID_PRI_SERVICE;
61static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE;
62static const uint16_t character_client_config_uuid =
63 ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
66static const esp_gatts_attr_db_t
67 midi_attribute_table[MIDI_ATTRIBUTE_TABLE_SIZE] = {
69 [MIDI_SERVICE_INDEX] =
71 .attr_control = {ESP_GATT_AUTO_RSP},
73 .uuid_length =
sizeof(primary_service_uuid),
74 .uuid_p = (uint8_t *)&primary_service_uuid,
75 .perm = ESP_GATT_PERM_READ,
76 .max_length =
sizeof(MIDI_SERVICE_UUID_128),
77 .length =
sizeof(MIDI_SERVICE_UUID_128),
78 .value = (uint8_t *)MIDI_SERVICE_UUID_128,
83 [MIDI_CHARACTERISTIC_DECLARATION_INDEX] =
85 .attr_control = {ESP_GATT_AUTO_RSP},
87 .uuid_length =
sizeof(character_declaration_uuid),
88 .uuid_p = (uint8_t *)&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,
97 [MIDI_CHARACTERISTIC_VALUE_INDEX] =
99 .attr_control = {ESP_GATT_RSP_BY_APP},
101 .uuid_length =
sizeof(MIDI_char_uuid128),
102 .uuid_p = (uint8_t *)&MIDI_char_uuid128,
103 .perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
111 [MIDI_2902_DESCRIPTOR_INDEX] =
113 .attr_control = {ESP_GATT_AUTO_RSP},
115 .uuid_length =
sizeof(character_client_config_uuid),
116 .uuid_p = (uint8_t *)&character_client_config_uuid,
117 .perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
125static uint16_t MIDI_handle_table[MIDI_ATTRIBUTE_TABLE_SIZE] = {};
127static uint16_t midi_gatts_if = ESP_GATT_IF_NONE;
130 midi_gatts_if = gatts_if;
134 esp_ble_gatts_cb_param_t *param) {
137 sizeof(MIDI_SERVICE_UUID_128));
140 esp_err_t ret = esp_ble_gatts_create_attr_tab(
141 midi_attribute_table, gatts_if, MIDI_ATTRIBUTE_TABLE_SIZE,
142 MIDI_SERVICE_INSTANCE_ID);
144 ESP_LOGE(
"MIDIBLE",
"Create attribute table failed, error code: %d",
150 esp_ble_gatts_cb_param_t *param) {
151 if (param->add_attr_tab.num_handle != MIDI_ATTRIBUTE_TABLE_SIZE) {
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);
159 "Created attribute table successfully, number of "
161 param->add_attr_tab.num_handle);
164 memcpy(MIDI_handle_table, param->add_attr_tab.handles,
165 sizeof(MIDI_handle_table));
171 return MIDI_handle_table[MIDI_SERVICE_INDEX];
175 return MIDI_handle_table[MIDI_CHARACTERISTIC_VALUE_INDEX];
179 return MIDI_handle_table[MIDI_2902_DESCRIPTOR_INDEX];
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.
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)