Merge branch 'refactor/esp_hid_astyle' into 'master'

refactor(esp_hid): Format the code with astyle

See merge request espressif/esp-idf!29302
This commit is contained in:
Tomas Rezucha 2024-03-04 15:41:10 +08:00
commit 93fc17575f
11 changed files with 148 additions and 159 deletions

View File

@ -41,15 +41,15 @@ struct esp_hidd_dev_s {
void *dev;
esp_hid_transport_t transport;
bool (*connected) (void *dev);
esp_err_t (*deinit) (void *dev);
esp_err_t (*disconnect) (void *dev);
esp_err_t (*virtual_unplug) (void *dev);
esp_err_t (*battery_set) (void *dev, uint8_t level);
esp_err_t (*input_set) (void *dev, size_t map_index, size_t report_id, uint8_t *data, size_t length);
esp_err_t (*feature_set) (void *dev, size_t map_index, size_t report_id, uint8_t *data, size_t length);
esp_err_t (*event_handler_register) (void *dev, esp_event_handler_t callback, esp_hidd_event_t event);
esp_err_t (*event_handler_unregister) (void *dev, esp_event_handler_t callback, esp_hidd_event_t event);
bool (*connected)(void *dev);
esp_err_t (*deinit)(void *dev);
esp_err_t (*disconnect)(void *dev);
esp_err_t (*virtual_unplug)(void *dev);
esp_err_t (*battery_set)(void *dev, uint8_t level);
esp_err_t (*input_set)(void *dev, size_t map_index, size_t report_id, uint8_t *data, size_t length);
esp_err_t (*feature_set)(void *dev, size_t map_index, size_t report_id, uint8_t *data, size_t length);
esp_err_t (*event_handler_register)(void *dev, esp_event_handler_t callback, esp_hidd_event_t event);
esp_err_t (*event_handler_unregister)(void *dev, esp_event_handler_t callback, esp_hidd_event_t event);
};
typedef struct esp_hidd_dev_s esp_hidd_dev_t;

View File

@ -69,15 +69,15 @@ struct esp_hidh_dev_s {
SemaphoreHandle_t semaphore;
SemaphoreHandle_t mutex;
esp_err_t (*close) (esp_hidh_dev_t *dev);
esp_err_t (*report_write) (esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, uint8_t *data, size_t len);
esp_err_t (*report_read) (esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, size_t max_length, uint8_t *value, size_t *value_len);
esp_err_t (*set_report) (esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, uint8_t *data, size_t len);
esp_err_t (*get_idle) (esp_hidh_dev_t *dev);
esp_err_t (*set_idle) (esp_hidh_dev_t *dev, uint8_t idle_time);
esp_err_t (*get_protocol) (esp_hidh_dev_t *dev);
esp_err_t (*set_protocol) (esp_hidh_dev_t *dev, uint8_t protocol_mode);
void (*dump) (esp_hidh_dev_t *dev, FILE *fp);
esp_err_t (*close)(esp_hidh_dev_t *dev);
esp_err_t (*report_write)(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, uint8_t *data, size_t len);
esp_err_t (*report_read)(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, size_t max_length, uint8_t *value, size_t *value_len);
esp_err_t (*set_report)(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, uint8_t *data, size_t len);
esp_err_t (*get_idle)(esp_hidh_dev_t *dev);
esp_err_t (*set_idle)(esp_hidh_dev_t *dev, uint8_t idle_time);
esp_err_t (*get_protocol)(esp_hidh_dev_t *dev);
esp_err_t (*set_protocol)(esp_hidh_dev_t *dev, uint8_t protocol_mode);
void (*dump)(esp_hidh_dev_t *dev, FILE *fp);
union {
#if CONFIG_BT_HID_HOST_ENABLED

View File

@ -141,7 +141,6 @@ struct esp_ble_hidd_dev_s {
esp_hid_device_config_t config;
uint16_t appearance;
bool connected;
uint16_t conn_id;
esp_bd_addr_t remote_bda;
@ -158,7 +157,6 @@ struct esp_ble_hidd_dev_s {
uint16_t bat_level_handle;
uint16_t bat_ccc_handle;
uint8_t pnp[7];
hidd_dev_map_t *devices;
@ -173,7 +171,6 @@ static const uint8_t hidInfo[4] = {
ESP_HID_FLAGS_REMOTE_WAKE | ESP_HID_FLAGS_NORMALLY_CONNECTABLE // Flags
};
#define WAIT_CB(d) xSemaphoreTake(d->sem, portMAX_DELAY)
#define SEND_CB(d) xSemaphoreGive(d->sem)
@ -181,7 +178,7 @@ static const char *gatts_evt_names[25] = { "REG", "READ", "WRITE", "EXEC_WRITE",
static const char *gatts_evt_str(uint8_t event)
{
if (event >= (sizeof(gatts_evt_names)/sizeof(*gatts_evt_names))) {
if (event >= (sizeof(gatts_evt_names) / sizeof(*gatts_evt_names))) {
return "UNKNOWN";
}
return gatts_evt_names[event];
@ -335,7 +332,6 @@ static esp_err_t create_hid_db(esp_ble_hidd_dev_t *dev, int device_index)
return err;
}
static void link_report_handles(hidd_dev_map_t *dev, uint16_t *handles)
{
@ -601,7 +597,7 @@ static void hid_event_handler(esp_ble_hidd_dev_t *dev, int device_index, esp_gat
}
}
static int get_device_map_index_by_gatts_if (esp_ble_hidd_dev_t *dev, esp_gatt_if_t gatts_if)
static int get_device_map_index_by_gatts_if(esp_ble_hidd_dev_t *dev, esp_gatt_if_t gatts_if)
{
for (uint8_t d = 0; d < dev->devices_len; d++) {
if (dev->devices[d].hid_svc.gatt_if && gatts_if == dev->devices[d].hid_svc.gatt_if) {
@ -780,7 +776,7 @@ void esp_hidd_gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatt
} else if (s_dev->info_svc.gatt_if && gatts_if == s_dev->info_svc.gatt_if) {
info_event_handler(s_dev, event, gatts_if, param);
} else {
int devi = get_device_map_index_by_gatts_if (s_dev, gatts_if);
int devi = get_device_map_index_by_gatts_if(s_dev, gatts_if);
if (devi >= 0) {
hid_event_handler(s_dev, devi, event, gatts_if, param);
} else {
@ -971,7 +967,6 @@ esp_err_t esp_ble_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_conf
return ESP_FAIL;
}
esp_event_loop_args_t event_task_args = {
.queue_size = 5,
.task_name = "ble_hidd_events",

View File

@ -28,7 +28,7 @@ static const char *s_gattc_evt_names[] = {"REG", "UNREG", "OPEN", "READ_CHAR", "
const char *gattc_evt_str(uint8_t event)
{
if (event >= (sizeof(s_gattc_evt_names)/sizeof(*s_gattc_evt_names))) {
if (event >= (sizeof(s_gattc_evt_names) / sizeof(*s_gattc_evt_names))) {
return "UNKNOWN";
}
return s_gattc_evt_names[event];
@ -396,7 +396,6 @@ void esp_hidh_gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gatt
SEND_CB();//return from open
break;
case ESP_GATTC_READ_CHAR_EVT:
case ESP_GATTC_READ_DESCR_EVT: {
dev = esp_hidh_dev_get_by_conn_id(p_data->read.conn_id);

View File

@ -43,8 +43,7 @@ typedef struct {
uint8_t devices_len;
} esp_bt_hidd_dev_t;
typedef struct
{
typedef struct {
osi_mutex_t mutex;
esp_bt_hidd_dev_t *dev;
esp_hidd_app_param_t app_param;
@ -313,7 +312,7 @@ static bool esp_bt_hidd_dev_connected(void *devp)
ret = false;
break;
}
} while(0);
} while (0);
if (ret) {
ret = dev->connected;
}
@ -337,7 +336,7 @@ static esp_err_t esp_bt_hidd_dev_deinit(void *devp)
ESP_LOGE(TAG, "Wrong HID device provided");
ret = ESP_FAIL;
}
} while(0);
} while (0);
osi_mutex_unlock(&s_hidd_param.mutex);
if (ret == ESP_OK) {
@ -369,7 +368,7 @@ static esp_err_t esp_bt_hidd_dev_disconnect(void *devp)
ESP_LOGW(TAG, "already disconnected");
return ESP_OK;
}
} while(0);
} while (0);
osi_mutex_unlock(&s_hidd_param.mutex);
if (ret == ESP_OK) {
@ -423,7 +422,7 @@ static esp_err_t esp_bt_hidd_dev_input_set(void *devp, size_t index, size_t id,
ret = ESP_FAIL;
break;
}
} while(0);
} while (0);
osi_mutex_unlock(&s_hidd_param.mutex);
if (ret == ESP_OK) {
@ -469,7 +468,7 @@ static esp_err_t esp_bt_hidd_dev_feature_set(void *devp, size_t index, size_t id
ret = ESP_FAIL;
break;
}
} while(0);
} while (0);
osi_mutex_unlock(&s_hidd_param.mutex);
if (ret == ESP_OK) {

View File

@ -55,7 +55,8 @@ static const char *s_esp_hh_status_names[] = {"OK",
"NO_DATA",
"NEED_INIT",
"NEED_DEINIT",
"NO_CONNECTION"};
"NO_CONNECTION"
};
static esp_hidh_dev_t *hidh_dev_ctor(esp_bd_addr_t bda);
@ -418,7 +419,7 @@ static void esp_hh_cb(esp_hidh_cb_event_t event, esp_hidh_cb_param_t *param)
esp_hidh_dev_lock(dev);
dev->added = param->add_dev.status == ESP_HIDH_OK ? true : false;
esp_hidh_dev_unlock(dev);
} while(0);
} while (0);
if (param->add_dev.status != ESP_HIDH_OK) {
ESP_LOGE(TAG, "ADD_DEV ERROR: %s", s_esp_hh_status_names[param->add_dev.status]);
@ -460,7 +461,7 @@ static void esp_hh_cb(esp_hidh_cb_event_t event, esp_hidh_cb_param_t *param)
// free the device in the wrapper event handler
dev->in_use = false;
esp_hidh_dev_unlock(dev);
} while(0);
} while (0);
if (param->close.status != ESP_HIDH_OK) {
ESP_LOGE(TAG, "CLOSE ERROR: %s", s_esp_hh_status_names[param->close.status]);
@ -535,7 +536,7 @@ static void esp_hh_cb(esp_hidh_cb_event_t event, esp_hidh_cb_param_t *param)
reset_trans(dev);
break;
}
case ESP_HIDH_GET_IDLE_EVT:{
case ESP_HIDH_GET_IDLE_EVT: {
if (param->get_idle.status != ESP_HIDH_OK) {
ESP_LOGE(TAG, "GET_IDLE ERROR: handle: %d, status: %s", param->get_idle.handle,
s_esp_hh_status_names[param->get_idle.status]);
@ -903,7 +904,7 @@ static esp_err_t esp_bt_hidh_dev_get_idle(esp_hidh_dev_t *dev)
if (ret == ESP_OK) {
set_trans(dev, ESP_HID_TRANS_GET_IDLE);
}
} while(0);
} while (0);
return ret;
}
@ -926,7 +927,7 @@ static esp_err_t esp_bt_hidh_dev_set_idle(esp_hidh_dev_t *dev, uint8_t idle_time
if (ret == ESP_OK) {
set_trans(dev, ESP_HID_TRANS_SET_IDLE);
}
} while(0);
} while (0);
return ret;
}
@ -949,7 +950,7 @@ static esp_err_t esp_bt_hidh_dev_get_protocol(esp_hidh_dev_t *dev)
if (ret == ESP_OK) {
set_trans(dev, ESP_HID_TRANS_GET_PROTOCOL);
}
} while(0);
} while (0);
return ret;
}
@ -973,7 +974,7 @@ static esp_err_t esp_bt_hidh_dev_set_protocol(esp_hidh_dev_t *dev, uint8_t proto
if (ret == ESP_OK) {
set_trans(dev, ESP_HID_TRANS_SET_PROTOCOL);
}
} while(0);
} while (0);
return ret;
}

View File

@ -45,7 +45,6 @@ typedef enum {
PARSE_WAIT_USAGE_PAGE, PARSE_WAIT_USAGE, PARSE_WAIT_COLLECTION_APPLICATION, PARSE_WAIT_END_COLLECTION
} s_parse_step_t;
static s_parse_step_t s_parse_step = PARSE_WAIT_USAGE_PAGE;
static uint8_t s_collection_depth = 0;
static hid_report_params_t s_report_params = {0,};
@ -192,7 +191,6 @@ static int handle_report(hid_report_params_t *report, bool first)
return 0;
}
static int parse_cmd(const uint8_t *data, size_t len, size_t index, hid_report_cmd_t **out)
{
if (index == len) {
@ -334,7 +332,6 @@ static int handle_cmd(hid_report_cmd_t *cmd)
return 0;
}
esp_hid_report_map_t *esp_hid_parse_report_map(const uint8_t *hid_rm, size_t hid_rm_len)
{
size_t index = 0;
@ -405,7 +402,7 @@ esp_hid_report_map_t *esp_hid_parse_report_map(const uint8_t *hid_rm, size_t hid
void esp_hid_free_report_map(esp_hid_report_map_t *map)
{
if (map != NULL){
if (map != NULL) {
free(map->reports);
free(map);
}
@ -444,7 +441,7 @@ const char *esp_hid_usage_str(esp_hid_usage_t usage)
const char *esp_hid_protocol_mode_str(uint8_t protocol)
{
if (protocol >= (sizeof(s_hid_protocol_names)/sizeof(s_hid_protocol_names[0]))) {
if (protocol >= (sizeof(s_hid_protocol_names) / sizeof(s_hid_protocol_names[0]))) {
return s_unknown_str;
}
return s_hid_protocol_names[protocol];
@ -452,7 +449,7 @@ const char *esp_hid_protocol_mode_str(uint8_t protocol)
const char *esp_hid_report_type_str(uint8_t report_type)
{
if (report_type >= (sizeof(s_hid_report_type_names)/sizeof(s_hid_report_type_names[0]))) {
if (report_type >= (sizeof(s_hid_report_type_names) / sizeof(s_hid_report_type_names[0]))) {
return s_unknown_str;
}
return s_hid_report_type_names[report_type];
@ -460,7 +457,7 @@ const char *esp_hid_report_type_str(uint8_t report_type)
const char *esp_hid_cod_major_str(uint8_t cod_major)
{
if (cod_major >= (sizeof(s_hid_cod_major_names)/sizeof(s_hid_cod_major_names[0]))) {
if (cod_major >= (sizeof(s_hid_cod_major_names) / sizeof(s_hid_cod_major_names[0]))) {
return s_unknown_str;
}
return s_hid_cod_major_names[cod_major];

View File

@ -37,7 +37,6 @@ static inline void unlock_devices(void)
}
}
/*
* Public Functions
* */
@ -504,7 +503,6 @@ esp_err_t esp_hidh_dev_report_maps_get(esp_hidh_dev_t *dev, size_t *num_maps, es
return ESP_OK;
}
/*
* Private Functions
* */

View File

@ -32,7 +32,6 @@
static const char *TAG = "NIMBLE_HIDD";
#define BLE_SVC_BAS_UUID16 0x180F
typedef struct esp_ble_hidd_dev_s esp_ble_hidd_dev_t;
// there can be only one BLE HID device
static esp_ble_hidd_dev_t *s_dev = NULL;
@ -48,8 +47,6 @@ typedef struct {
uint16_t hid_protocol_handle;
} hidd_dev_map_t;
struct esp_ble_hidd_dev_s {
esp_hidd_dev_t *dev;
esp_event_loop_handle_t event_loop_handle;
@ -129,14 +126,14 @@ static int create_hid_db(int device_index)
hparams.rpts_len = report_mode_rpts;
/* Add service */
rc = ble_svc_hid_add(hparams);
if(rc != 0) {
if (rc != 0) {
return rc;
}
return rc;
}
static int ble_hid_create_info_db() {
static int ble_hid_create_info_db()
{
int rc;
rc = 0;
@ -170,7 +167,7 @@ static int nimble_hid_start_gatts(void)
for (uint8_t d = 0; d < s_dev->devices_len; d++) {
rc = create_hid_db(d);
if(rc != 0) {
if (rc != 0) {
return rc;
}
}
@ -273,7 +270,8 @@ static int ble_hid_free_config(esp_ble_hidd_dev_t *dev)
return ESP_OK;
}
static int nimble_hidd_dev_deinit(void *devp) {
static int nimble_hidd_dev_deinit(void *devp)
{
esp_ble_hidd_dev_t *dev = (esp_ble_hidd_dev_t *)devp;
if (!s_dev) {
ESP_LOGE(TAG, "HID device profile already uninitialized");
@ -322,24 +320,26 @@ static int nimble_hidd_dev_battery_set(void *devp, uint8_t level)
}
/* if mode is NULL, find the first matching report */
static hidd_le_report_item_t* find_report(uint8_t id, uint8_t type, uint8_t *mode) {
static hidd_le_report_item_t* find_report(uint8_t id, uint8_t type, uint8_t *mode)
{
hidd_le_report_item_t *rpt;
for (uint8_t d = 0; d < s_dev->devices_len; d++) {
for (uint8_t i = 0; i < s_dev->devices[d].reports_len; i++) {
rpt = &s_dev->devices[d].reports[i];
if(rpt->report_id == id && rpt->report_type == type && (!mode || (mode && *mode == rpt->protocol_mode))) {
if (rpt->report_id == id && rpt->report_type == type && (!mode || (mode && *mode == rpt->protocol_mode))) {
return rpt;
}
}
}
return NULL;
}
static hidd_le_report_item_t* find_report_by_usage_and_type(uint8_t usage, uint8_t type, uint8_t *mode) {
static hidd_le_report_item_t* find_report_by_usage_and_type(uint8_t usage, uint8_t type, uint8_t *mode)
{
hidd_le_report_item_t *rpt;
for (uint8_t d = 0; d < s_dev->devices_len; d++) {
for (uint8_t i = 0; i < s_dev->devices[d].reports_len; i++) {
rpt = &s_dev->devices[d].reports[i];
if(rpt->usage == usage && rpt->report_type == type && (!mode || (mode && *mode == rpt->protocol_mode))) {
if (rpt->usage == usage && rpt->report_type == type && (!mode || (mode && *mode == rpt->protocol_mode))) {
return rpt;
}
}
@ -365,12 +365,12 @@ static int nimble_hidd_dev_input_set(void *devp, size_t index, size_t id, uint8_
/* check the protocol mode */
/* as the protocol mode is always present, its safe to read the characteristic */
rc = ble_att_svr_read_local(s_dev->devices[index].hid_protocol_handle, &om);
if(rc != 0) {
if (rc != 0) {
ESP_LOGE(TAG, "Unable to fetch protocol_mode\n");
return ESP_FAIL;
}
rc = ble_hs_mbuf_to_flat(om, &dev->protocol, sizeof(dev->protocol), NULL);
if(rc != 0) {
if (rc != 0) {
return ESP_FAIL;
}
/* free the mbuf */
@ -409,12 +409,12 @@ static int nimble_hidd_dev_feature_set(void *devp, size_t index, size_t id, uint
/* check the protocol mode */
/* as the protocol mode is always present, its safe to read the characteristic */
rc = ble_att_svr_read_local(s_dev->devices[index].hid_protocol_handle, &om);
if(rc != 0) {
if (rc != 0) {
ESP_LOGE(TAG, "Unable to fetch protocol_mode\n");
return ESP_FAIL;
}
rc = ble_hs_mbuf_to_flat(om, &dev->protocol, sizeof(dev->protocol), NULL);
if(rc != 0) {
if (rc != 0) {
return ESP_FAIL;
}
/* free the mbuf */
@ -488,11 +488,11 @@ static int nimble_hid_gap_event(struct ble_gap_event *event, void *arg)
/* reset the protocol mode value */
data = ESP_HID_PROTOCOL_MODE_REPORT;
om = ble_hs_mbuf_from_flat(&data, 1);
if(om == NULL) {
if (om == NULL) {
ESP_LOGD(TAG, "No memory to allocate mbuf");
}
/* NOTE : om is freed by stack */
for(int i = 0; i < s_dev->devices_len; i++) {
for (int i = 0; i < s_dev->devices_len; i++) {
rc = ble_att_svr_write_local(s_dev->devices[i].hid_protocol_handle, om);
if (rc != 0) {
ESP_LOGE(TAG, "Write on Protocol Mode Failed: %d", rc);
@ -541,7 +541,7 @@ static void nimble_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, voi
ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
ctxt->svc.handle);
uuid16 = ble_uuid_u16(ctxt->svc.svc_def->uuid);
if(uuid16 == BLE_SVC_HID_UUID16) {
if (uuid16 == BLE_SVC_HID_UUID16) {
++service_index;
s_dev->devices[service_index].hid_svc = ctxt->svc.handle;
}
@ -555,36 +555,36 @@ static void nimble_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, voi
ctxt->chr.def_handle,
ctxt->chr.val_handle);
uuid16 = ble_uuid_u16(ctxt->chr.chr_def->uuid);
if(uuid16 == BLE_SVC_HID_CHR_UUID16_HID_CTRL_PT) {
if (uuid16 == BLE_SVC_HID_CHR_UUID16_HID_CTRL_PT) {
/* assuming this characteristic is from the last registered hid service */
s_dev->devices[service_index].hid_control_handle = ctxt->chr.val_handle;
}
if(uuid16 == BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE) {
if (uuid16 == BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE) {
/* assuming this characteristic is from the last registered hid service */
s_dev->devices[service_index].hid_protocol_handle = ctxt->chr.val_handle;
}
if(uuid16 == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_INP) {
if (uuid16 == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_INP) {
protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT;
rpt = find_report_by_usage_and_type(ESP_HID_USAGE_KEYBOARD, ESP_HID_REPORT_TYPE_INPUT, &protocol_mode);
if(rpt == NULL) {
if (rpt == NULL) {
ESP_LOGE(TAG, "Unknown boot kbd input report registration");
return;
}
rpt->handle = ctxt->chr.val_handle;
}
if(uuid16 == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_OUT) {
if (uuid16 == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_OUT) {
protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT;
rpt = find_report_by_usage_and_type(ESP_HID_USAGE_KEYBOARD, ESP_HID_REPORT_TYPE_OUTPUT, &protocol_mode);
if(rpt == NULL) {
if (rpt == NULL) {
ESP_LOGE(TAG, "Unknown boot kbd output report registration");
return;
}
rpt->handle = ctxt->chr.val_handle;
}
if(uuid16 == BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INP) {
if (uuid16 == BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INP) {
protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT;
rpt = find_report_by_usage_and_type(ESP_HID_USAGE_MOUSE, ESP_HID_REPORT_TYPE_INPUT, &protocol_mode);
if(rpt == NULL) {
if (rpt == NULL) {
ESP_LOGE(TAG, "Unknown boot mouse input report registration");
return;
}
@ -597,7 +597,7 @@ static void nimble_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, voi
ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
ctxt->dsc.handle);
uuid16 = ble_uuid_u16(ctxt->dsc.dsc_def->uuid);
if(uuid16 == BLE_SVC_HID_DSC_UUID16_RPT_REF) {
if (uuid16 == BLE_SVC_HID_DSC_UUID16_RPT_REF) {
rc = ble_att_svr_read_local(ctxt->dsc.handle, &om);
assert(rc == 0);
@ -621,7 +621,8 @@ static void nimble_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, voi
}
}
static void nimble_host_synced(void) {
static void nimble_host_synced(void)
{
esp_event_post_to(s_dev->event_loop_handle, ESP_HIDD_EVENTS, ESP_HIDD_START_EVENT, NULL, 0, portMAX_DELAY);
}
@ -699,7 +700,7 @@ esp_err_t esp_ble_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_conf
ble_hs_cfg.sync_cb = nimble_host_synced;
ble_hs_cfg.gatts_register_cb = nimble_gatt_svr_register_cb;
rc = nimble_hid_start_gatts();
if(rc != ESP_OK) {
if (rc != ESP_OK) {
return rc;
}
ble_gap_event_listener_register(&nimble_gap_event_listener,

View File

@ -101,7 +101,7 @@ nimble_on_read(uint16_t conn_handle,
MODLOG_DFLT(INFO, "Read complete; status=%d conn_handle=%d", error->status,
conn_handle);
s_read_status = error->status;
switch(s_read_status) {
switch (s_read_status) {
case 0:
MODLOG_DFLT(DEBUG, " attr_handle=%d value=", attr->handle);
old_offset = s_read_data_len;
@ -221,8 +221,8 @@ chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
status = error->status;
switch (error->status) {
case 0:
ESP_LOGD(TAG,"Char discovered : def handle : %04x, val_handle : %04x, properties : %02x\n, uuid : %04x",
chr->def_handle, chr->val_handle,chr->properties, ble_uuid_u16(&chr->uuid.u));
ESP_LOGD(TAG, "Char discovered : def handle : %04x, val_handle : %04x, properties : %02x\n, uuid : %04x",
chr->def_handle, chr->val_handle, chr->properties, ble_uuid_u16(&chr->uuid.u));
memcpy(chrs + chrs_discovered, chr, sizeof(struct ble_gatt_chr));
chrs_discovered++;
break;
@ -260,7 +260,7 @@ desc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
status = error->status;
switch (error->status) {
case 0:
ESP_LOGD(TAG,"DISC discovered : handle : %04x, uuid : %04x",
ESP_LOGD(TAG, "DISC discovered : handle : %04x, uuid : %04x",
dsc->handle, ble_uuid_u16(&dsc->uuid.u));
memcpy(dscr + dscs_discovered, dsc, sizeof(struct ble_gatt_dsc));
dscs_discovered++;
@ -307,12 +307,12 @@ static void read_device_services(esp_hidh_dev_t *dev)
int rc;
rc = ble_gattc_disc_all_svcs(dev->ble.conn_id, svc_disced, service_result);
if(rc != 0) {
if (rc != 0) {
ESP_LOGD(TAG, "Error discovering services : %d", rc);
assert(rc != 0);
}
WAIT_CB();
if(status != 0) {
if (status != 0) {
ESP_LOGE(TAG, "failed to find services");
assert(status == 0);
}
@ -351,8 +351,8 @@ static void read_device_services(esp_hidh_dev_t *dev)
rc = ble_gattc_disc_all_chrs(dev->ble.conn_id, service_result[s].start_handle,
service_result[s].end_handle, chr_disced, char_result);
WAIT_CB();
if(status != 0) {
ESP_LOGE(TAG, "failed to find chars for service : %d",s);
if (status != 0) {
ESP_LOGE(TAG, "failed to find chars for service : %d", s);
assert(status == 0);
}
ccount = chrs_discovered;
@ -366,7 +366,7 @@ static void read_device_services(esp_hidh_dev_t *dev)
if (suuid == BLE_SVC_GAP_UUID16) {
if (dev->config.device_name == NULL && cuuid == BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME
&& (char_result[c].properties & BLE_GATT_CHR_PROP_READ) != 0) {
if (read_char(dev->ble.conn_id, chandle,&rdata, &rlen) == 0 && rlen) {
if (read_char(dev->ble.conn_id, chandle, &rdata, &rlen) == 0 && rlen) {
dev->config.device_name = (const char *)rdata;
}
} else {
@ -400,7 +400,7 @@ static void read_device_services(esp_hidh_dev_t *dev)
}
continue;
} else {
if(cuuid == BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE) {
if (cuuid == BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE) {
if (char_result[c].properties & BLE_GATT_CHR_PROP_READ) {
if (read_char(dev->ble.conn_id, chandle, &rdata, &rlen) == 0 && rlen) {
dev->protocol_mode[hidindex] = *((uint8_t *)rdata);
@ -457,17 +457,16 @@ static void read_device_services(esp_hidh_dev_t *dev)
struct ble_gatt_dsc descr_result[20];
uint16_t dcount = 20;
uint16_t chr_end_handle;
if(c + 1 < ccount) {
if (c + 1 < ccount) {
chr_end_handle = char_result[c + 1].def_handle;
}
else {
} else {
chr_end_handle = service_result[s].end_handle;
}
rc = ble_gattc_disc_all_dscs(dev->ble.conn_id, char_result[c].val_handle,
chr_end_handle, desc_disced, descr_result);
WAIT_CB();
if(status != 0) {
ESP_LOGE(TAG, "failed to find discriptors for characteristic : %d",c);
if (status != 0) {
ESP_LOGE(TAG, "failed to find discriptors for characteristic : %d", c);
assert(status == 0);
}
dcount = dscs_discovered;
@ -554,7 +553,7 @@ on_subscribe(uint16_t conn_handle,
void *arg)
{
uint16_t conn_id;
conn_id =*((uint16_t*) arg);
conn_id = *((uint16_t*) arg);
assert(conn_id == conn_handle);
@ -572,7 +571,7 @@ static void register_for_notify(uint16_t conn_handle, uint16_t handle)
int rc;
value[0] = 1;
value[1] = 0;
rc = ble_gattc_write_flat(conn_handle, handle, value, sizeof value, on_subscribe,(void *)&conn_handle);
rc = ble_gattc_write_flat(conn_handle, handle, value, sizeof value, on_subscribe, (void *)&conn_handle);
if (rc != 0) {
ESP_LOGE(TAG, "Error: Failed to subscribe to characteristic; "
"rc=%d\n", rc);
@ -587,7 +586,7 @@ on_write(uint16_t conn_handle,
void *arg)
{
uint16_t conn_id;
conn_id =*((uint16_t*) arg);
conn_id = *((uint16_t*) arg);
assert(conn_id == conn_handle);
@ -652,7 +651,7 @@ esp_hidh_gattc_event_handler(struct ble_gap_event *event, void *arg)
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
assert(rc == 0);
dev = esp_hidh_dev_get_by_bda(desc.peer_ota_addr.val);
if(!dev) {
if (!dev) {
ESP_LOGE(TAG, "Connect received for unknown device");
}
dev->status = -1; // set to not found and clear if HID service is found
@ -660,7 +659,7 @@ esp_hidh_gattc_event_handler(struct ble_gap_event *event, void *arg)
/* Try to set the mtu to the max value */
rc = ble_att_set_preferred_mtu(BLE_ATT_MTU_MAX);
if(rc != 0) {
if (rc != 0) {
ESP_LOGE(TAG, "att preferred mtu set failed");
}
rc = ble_gattc_exchange_mtu(event->connect.conn_handle, NULL, NULL);
@ -738,7 +737,7 @@ esp_hidh_gattc_event_handler(struct ble_gap_event *event, void *arg)
esp_hidh_event_data_t *p_param = NULL;
size_t event_data_size = sizeof(esp_hidh_event_data_t);
if(report->protocol_mode != dev->protocol_mode[report->map_index]) {
if (report->protocol_mode != dev->protocol_mode[report->map_index]) {
/* only pass the notifications in the current protocol mode */
ESP_LOGD(TAG, "Wrong protocol mode, dropping notification");
return 0;
@ -883,10 +882,11 @@ static void esp_ble_hidh_event_handler_wrapper(void *event_handler_arg, esp_even
esp_hidh_post_process_event_handler(event_handler_arg, event_base, event_id, event_data);
}
static void nimble_host_synced(void) {
/*
static void nimble_host_synced(void)
{
/*
no need to perform anything here
*/
*/
}
static void nimble_host_reset(int reason)

View File

@ -55,7 +55,6 @@ components_not_formatted_temporary:
- "/components/esp_coex/"
- "/components/esp_eth/"
- "/components/esp_gdbstub/"
- "/components/esp_hid/"
- "/components/esp_http_client/"
- "/components/esp_http_server/"
- "/components/esp_https_ota/"