Skip to content

Commit

Permalink
Changed to current GIT esp-idf. (removed bt_trace & LOG_ERROR/LOG_xxx)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminaigner committed May 2, 2018
1 parent ae191af commit 09509cd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
34 changes: 17 additions & 17 deletions main/ble_hidd_demo_main.c
Expand Up @@ -37,7 +37,6 @@
#include "esp_gatt_defs.h"
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include "bt_trace.h"
#include "driver/gpio.h"
#include "driver/uart.h"
#include "hid_dev.h"
Expand Down Expand Up @@ -189,17 +188,18 @@ static void hidd_event_callback(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *
case ESP_HIDD_EVENT_BLE_CONNECT: {
hid_conn_id = param->connect.conn_id;
sec_conn = true; //TODO: right here?!?
LOG_ERROR("%s(), ESP_HIDD_EVENT_BLE_CONNECT", __func__);
ESP_LOGE(GATTS_TAG,"%s(), ESP_HIDD_EVENT_BLE_CONNECT", __func__);
break;
}
case ESP_HIDD_EVENT_BLE_DISCONNECT: {
sec_conn = false;
hid_conn_id = 0;
LOG_ERROR("%s(), ESP_HIDD_EVENT_BLE_DISCONNECT", __func__);
ESP_LOGE(GATTS_TAG,"%s(), ESP_HIDD_EVENT_BLE_DISCONNECT", __func__);
esp_ble_gap_start_advertising(&hidd_adv_params);
break;
}
default:
ESP_LOGE(GATTS_TAG,"%s(), unhandled event: %d", __func__,event);
break;
}
return;
Expand All @@ -221,9 +221,9 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
sec_conn = true;
if(param->ble_security.auth_cmpl.success)
{
LOG_INFO("status = success, ESP_GAP_BLE_AUTH_CMPL_EVT");
ESP_LOGI(GATTS_TAG,"status = success, ESP_GAP_BLE_AUTH_CMPL_EVT");
} else {
LOG_INFO("status = fail, ESP_GAP_BLE_AUTH_CMPL_EVT");
ESP_LOGI(GATTS_TAG,"status = fail, ESP_GAP_BLE_AUTH_CMPL_EVT");
}
break;
//unused events
Expand All @@ -233,38 +233,38 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param

case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */
//esp_ble_passkey_reply(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, true, 0x00);
LOG_INFO("ESP_GAP_BLE_PASSKEY_REQ_EVT");
ESP_LOGI(GATTS_TAG,"ESP_GAP_BLE_PASSKEY_REQ_EVT");
break;
case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */
LOG_INFO("ESP_GAP_BLE_OOB_REQ_EVT");
ESP_LOGI(GATTS_TAG,"ESP_GAP_BLE_OOB_REQ_EVT");
break;
case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */
LOG_INFO("ESP_GAP_BLE_LOCAL_IR_EVT");
ESP_LOGI(GATTS_TAG,"ESP_GAP_BLE_LOCAL_IR_EVT");
break;
case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */
LOG_INFO("ESP_GAP_BLE_LOCAL_ER_EVT");
ESP_LOGI(GATTS_TAG,"ESP_GAP_BLE_LOCAL_ER_EVT");
break;
case ESP_GAP_BLE_NC_REQ_EVT:
LOG_INFO("ESP_GAP_BLE_NC_REQ_EVT");
ESP_LOGI(GATTS_TAG,"ESP_GAP_BLE_NC_REQ_EVT");
break;
case ESP_GAP_BLE_SEC_REQ_EVT:
/* send the positive(true) security response to the peer device to accept the security request.
If not accept the security request, should sent the security response with negative(false) accept value*/
esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, true);
LOG_INFO("ESP_GAP_BLE_SEC_REQ_EVT");
ESP_LOGI(GATTS_TAG,"ESP_GAP_BLE_SEC_REQ_EVT");
break;

case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: ///the app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
///show the passkey number to the user to input it in the peer deivce.
LOG_INFO("The passkey Notify number:%d", param->ble_security.key_notif.passkey);
ESP_LOGI(GATTS_TAG,"The passkey Notify number:%d", param->ble_security.key_notif.passkey);
break;
case ESP_GAP_BLE_KEY_EVT:
//shows the ble key info share with peer device to the user.
LOG_INFO("key type = %d", param->ble_security.ble_key.key_type);
ESP_LOGI(GATTS_TAG,"key type = %d", param->ble_security.ble_key.key_type);
break;

default:
LOG_WARN("unhandled event: %d",event);
ESP_LOGW(GATTS_TAG,"unhandled event: %d",event);
break;
}
}
Expand Down Expand Up @@ -682,21 +682,21 @@ void app_main()

ret = esp_bluedroid_init();
if (ret) {
LOG_ERROR("%s init bluedroid failed\n", __func__);
ESP_LOGE(GATTS_TAG,"%s init bluedroid failed\n", __func__);
return;
}

ret = esp_bluedroid_enable();
if (ret) {
LOG_ERROR("%s init bluedroid failed\n", __func__);
ESP_LOGE(GATTS_TAG,"%s init bluedroid failed\n", __func__);
return;
}

//load HID country code for locale before initialising HID
hidd_set_countrycode(get_hid_country_code(config.locale));

if((ret = esp_hidd_profile_init()) != ESP_OK) {
LOG_ERROR("%s init bluedroid failed\n", __func__);
ESP_LOGE(GATTS_TAG,"%s init bluedroid failed\n", __func__);
}

///register the callback function to the gap module
Expand Down
14 changes: 7 additions & 7 deletions main/esp_hidd_prf_api.c
Expand Up @@ -17,7 +17,7 @@
#include "hid_dev.h"
#include <stdlib.h>
#include <string.h>
#include "bt_trace.h"
//#include "bt_trace.h"

// HID keyboard input report length
#define HID_KEYBOARD_IN_RPT_LEN 8
Expand Down Expand Up @@ -58,7 +58,7 @@ esp_err_t esp_hidd_register_callbacks(esp_hidd_event_cb_t callbacks)
esp_err_t esp_hidd_profile_init(void)
{
if (hidd_le_env.enabled) {
LOG_ERROR("HID device profile already initialized");
ESP_LOGE(LOG_TAG,"HID device profile already initialized");
return ESP_FAIL;
}
// Reset the hid device target environment
Expand All @@ -71,7 +71,7 @@ esp_err_t esp_hidd_profile_deinit(void)
{
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(LOG_TAG,"HID device profile already initialized");
return ESP_OK;
}

Expand All @@ -97,10 +97,10 @@ void esp_hidd_send_consumer_value(uint16_t conn_id, uint8_t key_cmd, bool key_pr
{
uint8_t buffer[HID_CC_IN_RPT_LEN] = {0, 0};
if (key_pressed) {
LOG_DEBUG("hid_consumer_build_report");
ESP_LOGD(LOG_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(LOG_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;
Expand All @@ -109,7 +109,7 @@ void esp_hidd_send_consumer_value(uint16_t conn_id, uint8_t key_cmd, bool key_pr
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(LOG_TAG,"%s(), the number key should not be more than %d", __func__, HID_KEYBOARD_IN_RPT_LEN);
return;
}

Expand All @@ -121,7 +121,7 @@ void esp_hidd_send_keyboard_value(uint16_t conn_id, key_mask_t special_key_mask,
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(LOG_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;
Expand Down
3 changes: 3 additions & 0 deletions main/esp_hidd_prf_api.h
Expand Up @@ -18,11 +18,14 @@
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
#include "esp_err.h"
#include "esp_log.h"

#ifdef __cplusplus
extern "C" {
#endif

#define LOG_TAG "HIDD"

typedef enum {
ESP_HIDD_EVENT_REG_FINISH = 0,
ESP_BAT_EVENT_REG,
Expand Down
6 changes: 3 additions & 3 deletions main/hid_dev.c
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

#include "hid_dev.h"
#include "bt_trace.h"
#include "esp_log.h"
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
Expand Down Expand Up @@ -55,7 +55,7 @@ void hid_dev_send_report(esp_gatt_if_t gatts_if, uint16_t conn_id,
// get att handle for report
if ((p_rpt = hid_dev_rpt_by_id(id, type)) != NULL) {
// if notifications are enabled
LOG_ERROR("%s(), send the report, handle = %d", __func__, p_rpt->handle);
ESP_LOGI("hid_dev","%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);
}

Expand All @@ -65,7 +65,7 @@ void hid_dev_send_report(esp_gatt_if_t gatts_if, uint16_t conn_id,
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_dev","%s(), the buffer is NULL, hid build report failed.", __func__);
return;
}

Expand Down
21 changes: 10 additions & 11 deletions main/hid_device_le_prf.c
Expand Up @@ -14,8 +14,7 @@

#include "hidd_le_prf_int.h"
#include <string.h>
#include "bt_types.h"
#include "bt_trace.h"
#include "esp_log.h"
//#include "esp_gap_ble_api.h"


Expand Down Expand Up @@ -535,7 +534,7 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
//if(param->connect.is_connected) {
if(param->connect.conn_id != 0) {
esp_hidd_cb_param_t cb_param = {0};
LOG_ERROR("the connection establish, conn_id = %x",param->connect.conn_id);
ESP_LOGE("HID_DEVICE","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);
Expand Down Expand Up @@ -563,15 +562,15 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
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_LOGI("HID_DEVICE","%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);
}
if (param->add_attr_tab.num_handle == HIDD_LE_IDX_NB &&
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_LOGI("HID_DEVICE","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 {
Expand Down Expand Up @@ -615,9 +614,9 @@ void hidd_clcb_alloc (uint16_t conn_id, esp_bd_addr_t bda)

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;
}
Expand All @@ -632,10 +631,10 @@ bool hidd_clcb_dealloc (uint16_t conn_id)

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)
Expand All @@ -652,7 +651,7 @@ void hidd_set_attr_value(uint16_t handle, uint16_t val_len, const uint8_t *value
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_DEVICE","%s error:Invalid handle value.",__func__);
}
return;
}
Expand All @@ -664,7 +663,7 @@ void hidd_get_attr_value(uint16_t handle, uint16_t *length, uint8_t **value)
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_DEVICE","%s error:Invalid handle value.", __func__);
}

return;
Expand Down
14 changes: 12 additions & 2 deletions sdkconfig
Expand Up @@ -20,7 +20,8 @@ CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG=
CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE=
CONFIG_LOG_BOOTLOADER_LEVEL=3
CONFIG_BOOTLOADER_VDDSDIO_BOOST=y
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V=
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y

#
# Security features
Expand Down Expand Up @@ -99,6 +100,7 @@ CONFIG_STACK_CHECK_NORM=
CONFIG_STACK_CHECK_STRONG=
CONFIG_STACK_CHECK_ALL=
CONFIG_STACK_CHECK=
CONFIG_WARN_WRITE_STRINGS=

#
# Component config
Expand Down Expand Up @@ -138,21 +140,27 @@ CONFIG_BT_SPP_ENABLED=
CONFIG_GATTS_ENABLE=y
CONFIG_GATTC_ENABLE=y
CONFIG_BLE_SMP_ENABLE=y
CONFIG_BLE_ENABLE_SRVCHG_REG=y
CONFIG_BT_STACK_NO_LOG=
CONFIG_BT_ACL_CONNECTIONS=4
CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=
CONFIG_SMP_ENABLE=y
CONFIG_BT_RESERVE_DRAM=0x10000

#
# ADC configuration
#
CONFIG_ADC_FORCE_XPD_FSM=
CONFIG_ADC2_DISABLE_DAC=y

#
# ESP32-specific
#
CONFIG_ESP32_DEFAULT_CPU_FREQ_80=
CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160
CONFIG_MEMMAP_SMP=y
CONFIG_SPIRAM_SUPPORT=
CONFIG_MEMMAP_TRACEMEM=
CONFIG_MEMMAP_TRACEMEM_TWOBANKS=
Expand Down Expand Up @@ -214,6 +222,7 @@ CONFIG_ESP32_TIME_SYSCALL_USE_NONE=
CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=
CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024
CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES=100
CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=2000
CONFIG_ESP32_XTAL_FREQ_40=
CONFIG_ESP32_XTAL_FREQ_26=
Expand All @@ -222,6 +231,7 @@ CONFIG_ESP32_XTAL_FREQ=0
CONFIG_DISABLE_BASIC_ROM_CONSOLE=
CONFIG_ESP_TIMER_PROFILING=
CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS=
CONFIG_ESP_ERR_TO_NAME_LOOKUP=y

#
# Wi-Fi
Expand Down

0 comments on commit 09509cd

Please sign in to comment.