15#include <esp_gatt_defs.h>
21static const uint8_t MIDI_SERVICE_UUID_128[16] = {
22 0x00, 0xc7, 0xc4, 0x4e, 0xe3, 0x6c,
26 0x5a, 0x0e, 0xb8, 0x03,
31static const uint8_t MIDI_char_uuid128[16] = {
32 0xf3, 0x6b, 0x10, 0x9d, 0x66, 0xf2,
36 0xdb, 0xe5, 0x72, 0x77,
41const esp_gatt_char_prop_t MIDI_properties = ESP_GATT_CHAR_PROP_BIT_READ |
42 ESP_GATT_CHAR_PROP_BIT_WRITE_NR |
43 ESP_GATT_CHAR_PROP_BIT_NOTIFY;
48 MIDI_CHARACTERISTIC_DECLARATION_INDEX,
49 MIDI_CHARACTERISTIC_VALUE_INDEX,
50 MIDI_2902_DESCRIPTOR_INDEX,
51 MIDI_ATTRIBUTE_TABLE_SIZE,
56static const uint8_t MIDI_SERVICE_INSTANCE_ID = 0;
58static const uint16_t primary_service_uuid = ESP_GATT_UUID_PRI_SERVICE;
59static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE;
60static const uint16_t character_client_config_uuid =
61 ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
64static const esp_gatts_attr_db_t
65 midi_attribute_table[MIDI_ATTRIBUTE_TABLE_SIZE] = {
67 [MIDI_SERVICE_INDEX] =
69 .attr_control = {ESP_GATT_AUTO_RSP},
71 .uuid_length =
sizeof(primary_service_uuid),
72 .uuid_p = (uint8_t *)&primary_service_uuid,
73 .perm = ESP_GATT_PERM_READ,
74 .max_length =
sizeof(MIDI_SERVICE_UUID_128),
75 .length =
sizeof(MIDI_SERVICE_UUID_128),
76 .value = (uint8_t *)MIDI_SERVICE_UUID_128,
81 [MIDI_CHARACTERISTIC_DECLARATION_INDEX] =
83 .attr_control = {ESP_GATT_AUTO_RSP},
85 .uuid_length =
sizeof(character_declaration_uuid),
86 .uuid_p = (uint8_t *)&character_declaration_uuid,
87 .perm = ESP_GATT_PERM_READ,
88 .max_length =
sizeof(MIDI_properties),
89 .length =
sizeof(MIDI_properties),
90 .value = (uint8_t *)&MIDI_properties,
95 [MIDI_CHARACTERISTIC_VALUE_INDEX] =
97 .attr_control = {ESP_GATT_RSP_BY_APP},
99 .uuid_length =
sizeof(MIDI_char_uuid128),
100 .uuid_p = (uint8_t *)&MIDI_char_uuid128,
101 .perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
109 [MIDI_2902_DESCRIPTOR_INDEX] =
111 .attr_control = {ESP_GATT_AUTO_RSP},
113 .uuid_length =
sizeof(character_client_config_uuid),
114 .uuid_p = (uint8_t *)&character_client_config_uuid,
115 .perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
123static uint16_t MIDI_handle_table[MIDI_ATTRIBUTE_TABLE_SIZE] = {};
125static uint16_t midi_gatts_if = ESP_GATT_IF_NONE;
126static uint16_t midi_conn_id = 0;
129 midi_gatts_if = gatts_if;
136 esp_ble_gatts_cb_param_t *param) {
139 sizeof(MIDI_SERVICE_UUID_128));
144 esp_err_t ret = esp_ble_gatts_create_attr_tab(
145 midi_attribute_table, gatts_if, MIDI_ATTRIBUTE_TABLE_SIZE,
146 MIDI_SERVICE_INSTANCE_ID);
148 ESP_LOGE(
"MIDIBLE",
"Create attribute table failed, error code: %d",
154 esp_ble_gatts_cb_param_t *param) {
155 if (param->add_attr_tab.num_handle != MIDI_ATTRIBUTE_TABLE_SIZE) {
157 "Create attribute table error, num_handle (%d) "
158 "doesn't equal MIDI_ATTRIBUTE_TABLE_SIZE (%d)",
159 param->add_attr_tab.num_handle, MIDI_ATTRIBUTE_TABLE_SIZE);
163 "Created attribute table successfully, number of "
165 param->add_attr_tab.num_handle);
168 memcpy(MIDI_handle_table, param->add_attr_tab.handles,
169 sizeof(MIDI_handle_table));
175 return MIDI_handle_table[MIDI_SERVICE_INDEX];
179 return MIDI_handle_table[MIDI_CHARACTERISTIC_VALUE_INDEX];
183 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.
bool advertising_config(void)
Configure the advertising data, register with the Bluetooth driver.
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)
void midi_set_connection_id(uint16_t conn_id)
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)
uint16_t midi_get_connection_id(void)