#include "esp_gatt_defs.h"
#include "esp_bt_main.h"
#include "esp_bt_device.h"
-#include "bt_trace.h"
#include "driver/gpio.h"
#include "hid_dev.h"
*
*/
-#define GATTS_TAG "HID_DEMO"
+#define HID_DEMO_TAG "HID_DEMO"
#define GPIO_OUTPUT_IO_0 18
uint32_t io_num;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
- ESP_LOGI(GATTS_TAG, "GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
+ ESP_LOGI(HID_DEMO_TAG, "GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
if(i == 0) {
++i;
}
}
case ESP_HIDD_EVENT_BLE_DISCONNECT: {
sec_conn = false;
- LOG_ERROR("%s(), ESP_HIDD_EVENT_BLE_DISCONNECT", __func__);
+ ESP_LOGE(HID_DEMO_TAG, "%s(), ESP_HIDD_EVENT_BLE_DISCONNECT", __func__);
esp_ble_gap_start_advertising(&hidd_adv_params);
break;
}
case ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT: {
- LOG_ERROR("%s, ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT", __func__);
- ESP_LOG_BUFFER_HEX(GATTS_TAG, param->vendor_write.data, param->vendor_write.length);
+ ESP_LOGE(HID_DEMO_TAG, "%s, ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT", __func__);
+ ESP_LOG_BUFFER_HEX(HID_DEMO_TAG, param->vendor_write.data, param->vendor_write.length);
}
default:
break;
break;
case ESP_GAP_BLE_SEC_REQ_EVT:
for(int i = 0; i < ESP_BD_ADDR_LEN; i++) {
- LOG_DEBUG("%x:",param->ble_security.ble_req.bd_addr[i]);
+ ESP_LOGD(HID_DEMO_TAG, "%x:",param->ble_security.ble_req.bd_addr[i]);
}
esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, true);
break;
case ESP_GAP_BLE_AUTH_CMPL_EVT:
sec_conn = true;
- LOG_ERROR("staus =%s, ESP_GAP_BLE_AUTH_CMPL_EVT",param->ble_security.auth_cmpl.success ? "success" : "fail");
+ ESP_LOGE(HID_DEMO_TAG, "staus =%s, ESP_GAP_BLE_AUTH_CMPL_EVT",param->ble_security.auth_cmpl.success ? "success" : "fail");
break;
default:
break;
while(1) {
vTaskDelay(2000 / portTICK_PERIOD_MS);
if (sec_conn) {
- LOG_ERROR("Send the volume");
+ ESP_LOGE(HID_DEMO_TAG, "Send the volume");
send_volum_up = true;
//uint8_t key_vaule = {HID_KEY_A};
//esp_hidd_send_keyboard_value(hid_conn_id, 0, &key_vaule, 1);
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
- ESP_LOGE(GATTS_TAG, "%s initialize controller failed\n", __func__);
+ ESP_LOGE(HID_DEMO_TAG, "%s initialize controller failed\n", __func__);
return;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
if (ret) {
- ESP_LOGE(GATTS_TAG, "%s enable controller failed\n", __func__);
+ ESP_LOGE(HID_DEMO_TAG, "%s enable controller failed\n", __func__);
return;
}
ret = esp_bluedroid_init();
if (ret) {
- LOG_ERROR("%s init bluedroid failed\n", __func__);
+ ESP_LOGE(HID_DEMO_TAG, "%s init bluedroid failed\n", __func__);
return;
}
ret = esp_bluedroid_enable();
if (ret) {
- LOG_ERROR("%s init bluedroid failed\n", __func__);
+ ESP_LOGE(HID_DEMO_TAG, "%s init bluedroid failed\n", __func__);
return;
}
if((ret = esp_hidd_profile_init()) != ESP_OK) {
- LOG_ERROR("%s init bluedroid failed\n", __func__);
+ ESP_LOGE(HID_DEMO_TAG, "%s init bluedroid failed\n", __func__);
}
///register the callback function to the gap module
#include "hid_dev.h"
#include <stdlib.h>
#include <string.h>
-#include "bt_trace.h"
+#include "esp_log.h"
// HID keyboard input report length
#define HID_KEYBOARD_IN_RPT_LEN 8
// HID consumer control input report length
#define HID_CC_IN_RPT_LEN 2
-
esp_err_t esp_hidd_register_callbacks(esp_hidd_event_cb_t callbacks)
{
esp_err_t hidd_status;
esp_err_t esp_hidd_profile_init(void)
{
if (hidd_le_env.enabled) {
- LOG_ERROR("HID device profile already initialized");
+ ESP_LOGE(HID_LE_PRF_TAG, "HID device profile already initialized");
return ESP_FAIL;
}
// Reset the hid device target environment
{
uint16_t hidd_svc_hdl = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_SVC];
if (!hidd_le_env.enabled) {
- LOG_ERROR("HID device profile already initialized");
+ ESP_LOGE(HID_LE_PRF_TAG, "HID device profile already initialized");
return ESP_OK;
}
{
uint8_t buffer[HID_CC_IN_RPT_LEN] = {0, 0};
if (key_pressed) {
- LOG_DEBUG("hid_consumer_build_report");
+ ESP_LOGD(HID_LE_PRF_TAG, "hid_consumer_build_report");
hid_consumer_build_report(buffer, key_cmd);
}
- LOG_DEBUG("buffer[0] = %x, buffer[1] = %x", buffer[0], buffer[1]);
+ ESP_LOGD(HID_LE_PRF_TAG, "buffer[0] = %x, buffer[1] = %x", buffer[0], buffer[1]);
hid_dev_send_report(hidd_le_env.gatt_if, conn_id,
HID_RPT_ID_CC_IN, HID_REPORT_TYPE_INPUT, HID_CC_IN_RPT_LEN, buffer);
return;
void esp_hidd_send_keyboard_value(uint16_t conn_id, key_mask_t special_key_mask, uint8_t *keyboard_cmd, uint8_t num_key)
{
if (num_key > HID_KEYBOARD_IN_RPT_LEN - 2) {
- LOG_ERROR("%s(), the number key should not be more than %d", __func__, HID_KEYBOARD_IN_RPT_LEN);
+ ESP_LOGE(HID_LE_PRF_TAG, "%s(), the number key should not be more than %d", __func__, HID_KEYBOARD_IN_RPT_LEN);
return;
}
buffer[i+2] = keyboard_cmd[i];
}
- LOG_DEBUG("the key vaule = %d,%d,%d, %d, %d, %d,%d, %d", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
+ ESP_LOGD(HID_LE_PRF_TAG, "the key vaule = %d,%d,%d, %d, %d, %d,%d, %d", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
hid_dev_send_report(hidd_le_env.gatt_if, conn_id,
HID_RPT_ID_KEY_IN, HID_REPORT_TYPE_INPUT, HID_KEYBOARD_IN_RPT_LEN, buffer);
return;
// limitations under the License.
#include "hid_dev.h"
-#include "bt_trace.h"
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "esp_log.h"
static hid_report_map_t *hid_dev_rpt_tbl;
static uint8_t hid_dev_rpt_tbl_Len;
// get att handle for report
if ((p_rpt = hid_dev_rpt_by_id(id, type)) != NULL) {
// if notifications are enabled
- LOG_DEBUG("%s(), send the report, handle = %d", __func__, p_rpt->handle);
+ ESP_LOGD(HID_LE_PRF_TAG, "%s(), send the report, handle = %d", __func__, p_rpt->handle);
esp_ble_gatts_send_indicate(gatts_if, conn_id, p_rpt->handle, length, data, false);
}
void hid_consumer_build_report(uint8_t *buffer, consumer_cmd_t cmd)
{
if (!buffer) {
- LOG_ERROR("%s(), the buffer is NULL, hid build report failed.", __func__);
+ ESP_LOGE(HID_LE_PRF_TAG, "%s(), the buffer is NULL, hid build report failed.", __func__);
return;
}
#include "hidd_le_prf_int.h"
#include <string.h>
-#include "bt_types.h"
-#include "bt_trace.h"
-//#include "esp_gap_ble_api.h"
-
+#include "esp_log.h"
/// characteristic presentation information
struct prf_char_pres_fmt
break;
case ESP_GATTS_CONNECT_EVT: {
esp_hidd_cb_param_t cb_param = {0};
- LOG_ERROR("the connection establish, conn_id = %x",param->connect.conn_id);
+ ESP_LOGE(HID_LE_PRF_TAG, "the connection establish, conn_id = %x",param->connect.conn_id);
memcpy(cb_param.connect.remote_bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
cb_param.connect.conn_id = param->connect.conn_id;
hidd_clcb_alloc(param->connect.conn_id, param->connect.remote_bda);
param->add_attr_tab.status == ESP_GATT_OK) {
incl_svc.start_hdl = param->add_attr_tab.handles[BAS_IDX_SVC];
incl_svc.end_hdl = incl_svc.start_hdl + BAS_IDX_NB -1;
- LOG_ERROR("%s(), start added the hid service to the stack database. incl_handle = %d",
+ ESP_LOGE(HID_LE_PRF_TAG, "%s(), start added the hid service to the stack database. incl_handle = %d",
__func__, incl_svc.start_hdl);
esp_ble_gatts_create_attr_tab(hidd_le_gatt_db, gatts_if, HIDD_LE_IDX_NB, 0);
}
param->add_attr_tab.status == ESP_GATT_OK) {
memcpy(hidd_le_env.hidd_inst.att_tbl, param->add_attr_tab.handles,
HIDD_LE_IDX_NB*sizeof(uint16_t));
- LOG_ERROR("hid svc handle = %x",hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_SVC]);
+ ESP_LOGE(HID_LE_PRF_TAG, "hid svc handle = %x",hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_SVC]);
hid_add_id_tbl();
esp_ble_gatts_start_service(hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_SVC]);
} else {
for (i_clcb = 0, p_clcb= hidd_le_env.hidd_clcb; i_clcb < HID_MAX_APPS; i_clcb++, p_clcb++) {
if (!p_clcb->in_use) {
- p_clcb->in_use = TRUE;
+ p_clcb->in_use = true;
p_clcb->conn_id = conn_id;
- p_clcb->connected = TRUE;
+ p_clcb->connected = true;
memcpy (p_clcb->remote_bda, bda, ESP_BD_ADDR_LEN);
break;
}
for (i_clcb = 0, p_clcb= hidd_le_env.hidd_clcb; i_clcb < HID_MAX_APPS; i_clcb++, p_clcb++) {
memset(p_clcb, 0, sizeof(hidd_clcb_t));
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
esp_err_t hidd_register_cb(void)
hidd_inst->att_tbl[HIDD_LE_IDX_REPORT_REP_REF] >= handle) {
esp_ble_gatts_set_attr_value(handle, val_len, value);
} else {
- LOG_ERROR("%s error:Invalid handle value.",__func__);
+ ESP_LOGE(HID_LE_PRF_TAG, "%s error:Invalid handle value.",__func__);
}
return;
}
hidd_inst->att_tbl[HIDD_LE_IDX_REPORT_REP_REF] >= handle){
esp_ble_gatts_get_attr_value(handle, length, (const uint8_t **)value);
} else {
- LOG_ERROR("%s error:Invalid handle value.", __func__);
+ ESP_LOGE(HID_LE_PRF_TAG, "%s error:Invalid handle value.", __func__);
}
return;
#include "esp_gap_ble_api.h"
#include "hid_dev.h"
+//HID BLE profile log tag
+#define HID_LE_PRF_TAG "HID_LE_PRF"
/// Maximal number of HIDS that can be added in the DB
#ifndef USE_ONE_HIDS_INSTANCE