mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
component bt:added the button profile event & process method to the project
This commit is contained in:
parent
2fdd9ba930
commit
2182b69b3d
@ -271,6 +271,7 @@ void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
|
|||||||
APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d",p_msg->int_start_if.client_if );
|
APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d",p_msg->int_start_if.client_if );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
** Function bta_gattc_deregister
|
** Function bta_gattc_deregister
|
||||||
|
@ -364,7 +364,7 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg)
|
|||||||
tBTA_GATTC_RCB *p_clreg;
|
tBTA_GATTC_RCB *p_clreg;
|
||||||
BOOLEAN rt = TRUE;
|
BOOLEAN rt = TRUE;
|
||||||
#if BTA_GATT_DEBUG == TRUE
|
#if BTA_GATT_DEBUG == TRUE
|
||||||
APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]", gattc_evt_code(p_msg->event));
|
APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]\n", gattc_evt_code(p_msg->event));
|
||||||
#endif
|
#endif
|
||||||
switch (p_msg->event)
|
switch (p_msg->event)
|
||||||
{
|
{
|
||||||
@ -424,7 +424,7 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
APPL_TRACE_DEBUG("Ignore unknown conn ID: %d", p_msg->layer_specific);
|
APPL_TRACE_DEBUG("Ignore unknown conn ID: %d\n", p_msg->layer_specific);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -284,32 +284,23 @@ UINT16 button_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda)
|
|||||||
** Returns True the deallocation is successful
|
** Returns True the deallocation is successful
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
|
||||||
BOOLEAN button_env_clcb_dealloc(UINT16 conn_id)
|
BOOLEAN button_env_clcb_dealloc(UINT16 conn_id)
|
||||||
{
|
{
|
||||||
UINT8 i_clcb = 0;
|
UINT8 i_clcb = 0;
|
||||||
tBUT_CLCB *p_clcb = NULL;
|
tBUT_CLCB *p_clcb = NULL;
|
||||||
|
|
||||||
for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < BUTT_MAX_APPS; i_clcb++, p_clcb++)
|
for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < 1; i_clcb++, p_clcb++)
|
||||||
{
|
{
|
||||||
if(p_clcb->in_use && p_clcb->connected && (p_clcb->conn_id == conn_id))
|
if(p_clcb->in_use && p_clcb->connected && (p_clcb->conn_id == conn_id))
|
||||||
{
|
{
|
||||||
unsigned j;
|
|
||||||
for(j = 0; j < ARRAY_SIZE(p_clcb->button_value.data_string);j++)
|
|
||||||
{
|
|
||||||
if(p_clcb->button_value.data_string[j])
|
|
||||||
{
|
|
||||||
GKI_freebuf(p_clcb->button_value.data_string[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
memset(p_clcb, 0, sizeof(tBUT_CLCB));
|
memset(p_clcb, 0, sizeof(tBUT_CLCB));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
@ -348,6 +339,12 @@ tGATT_STATUS button_init (tBU_CBACK *call_back)
|
|||||||
return GATT_SUCCESS;
|
return GATT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void button_disable(UINT16 connid)
|
||||||
|
{
|
||||||
|
button_env_clcb_dealloc(connid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void button_msg_notify(UINT8 len, UINT8 *button_msg)
|
void button_msg_notify(UINT8 len, UINT8 *button_msg)
|
||||||
{
|
{
|
||||||
BOOLEAN conn_status = button_cb_env.clcb.connected;
|
BOOLEAN conn_status = button_cb_env.clcb.connected;
|
||||||
|
@ -115,6 +115,8 @@ BOOLEAN button_env_clcb_dealloc(UINT16 conn_id);
|
|||||||
|
|
||||||
tGATT_STATUS button_init(tBU_CBACK *call_back);
|
tGATT_STATUS button_init(tBU_CBACK *call_back);
|
||||||
|
|
||||||
|
void button_disable(UINT16 connid);
|
||||||
|
|
||||||
void button_msg_notify(UINT8 len, UINT8 *button_msg);
|
void button_msg_notify(UINT8 len, UINT8 *button_msg);
|
||||||
|
|
||||||
extern tBUTTON_CB_ENV button_cb_env;
|
extern tBUTTON_CB_ENV button_cb_env;
|
||||||
|
@ -50,7 +50,7 @@ typedef void (tAIRSYNC_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data)
|
|||||||
WX_IDX_AIRSYNC_READ_VAL,
|
WX_IDX_AIRSYNC_READ_VAL,
|
||||||
WX_IDX_AIRSYNC_NTF_CFG,
|
WX_IDX_AIRSYNC_NTF_CFG,
|
||||||
|
|
||||||
KEY_IDX_NB,
|
WX_IDX_NB,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -184,7 +184,7 @@ void AirSync_CreateService(void)
|
|||||||
{
|
{
|
||||||
tBTA_GATTS_IF server_if ;
|
tBTA_GATTS_IF server_if ;
|
||||||
tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}};
|
tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}};
|
||||||
UINT16 num_handle = KEY_IDX_NB;
|
UINT16 num_handle = WX_IDX_NB;
|
||||||
UINT8 inst = 0x00;
|
UINT8 inst = 0x00;
|
||||||
server_if = airsync_cb_env.gatt_if;
|
server_if = airsync_cb_env.gatt_if;
|
||||||
airsync_cb_env.inst_id = inst;
|
airsync_cb_env.inst_id = inst;
|
||||||
|
@ -458,7 +458,7 @@ void hidd_le_CreateService(BOOLEAN is_primary)
|
|||||||
tBTA_GATTS_IF server_if ;
|
tBTA_GATTS_IF server_if ;
|
||||||
tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_HID}};
|
tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_HID}};
|
||||||
//the number of the hid device attributes in the hid service.
|
//the number of the hid device attributes in the hid service.
|
||||||
UINT16 num_handle = HIDD_LE_IDX_NB+5;
|
UINT16 num_handle = HIDD_LE_IDX_NB;
|
||||||
UINT8 inst = 0x00;
|
UINT8 inst = 0x00;
|
||||||
server_if = hidd_le_env.gatt_if;
|
server_if = hidd_le_env.gatt_if;
|
||||||
hidd_le_env.inst_id = inst;
|
hidd_le_env.inst_id = inst;
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
#define ATT_UUID_128_LEN 0x0010
|
#define ATT_UUID_128_LEN 0x0010
|
||||||
#define ATT_UUID_32_LEN 0x0004
|
#define ATT_UUID_32_LEN 0x0004
|
||||||
|
|
||||||
#define WX_AIRSYNC_CFG 0
|
#define WX_AIRSYNC_CFG 1
|
||||||
#define BUT_PROFILE_CFG 0
|
#define BUT_PROFILE_CFG 1
|
||||||
#define HIDD_LE_PROFILE_CFG 1
|
#define HIDD_LE_PROFILE_CFG 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -760,14 +760,14 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec)
|
|||||||
BOOLEAN rt = FALSE;
|
BOOLEAN rt = FALSE;
|
||||||
UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state;
|
UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state;
|
||||||
|
|
||||||
BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__,
|
BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d\n", __func__,
|
||||||
btm_cb.ble_ctr_cb.privacy_mode);
|
btm_cb.ble_ctr_cb.privacy_mode);
|
||||||
|
|
||||||
/* if controller does not support RPA offloading or privacy 1.2, skip */
|
/* if controller does not support RPA offloading or privacy 1.2, skip */
|
||||||
if (controller_get_interface()->get_ble_resolving_list_max_size() == 0)
|
if (controller_get_interface()->get_ble_resolving_list_max_size() == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d",
|
BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d\n",
|
||||||
__func__, btm_cb.ble_ctr_cb.privacy_mode);
|
__func__, btm_cb.ble_ctr_cb.privacy_mode);
|
||||||
|
|
||||||
/* only add RPA enabled device into resolving list */
|
/* only add RPA enabled device into resolving list */
|
||||||
@ -801,7 +801,7 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec)
|
|||||||
p_dev_rec->ble.static_addr_type = p_dev_rec->ble.ble_addr_type;
|
p_dev_rec->ble.static_addr_type = p_dev_rec->ble.ble_addr_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
BTM_TRACE_DEBUG("%s:adding device to controller resolving list", __func__);
|
BTM_TRACE_DEBUG("%s:adding device to controller resolving list\n", __func__);
|
||||||
// use identical IRK for now
|
// use identical IRK for now
|
||||||
rt = btsnd_hcic_ble_add_device_resolving_list(p_dev_rec->ble.static_addr_type,
|
rt = btsnd_hcic_ble_add_device_resolving_list(p_dev_rec->ble.static_addr_type,
|
||||||
p_dev_rec->ble.static_addr, peer_irk, local_irk);
|
p_dev_rec->ble.static_addr, peer_irk, local_irk);
|
||||||
@ -837,13 +837,13 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BTM_TRACE_ERROR("Device already in Resolving list");
|
BTM_TRACE_ERROR("Device already in Resolving list\n");
|
||||||
rt = TRUE;
|
rt = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BTM_TRACE_DEBUG("Device not a RPA enabled device");
|
BTM_TRACE_DEBUG("Device not a RPA enabled device\n");
|
||||||
}
|
}
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
@ -863,7 +863,7 @@ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec)
|
|||||||
{
|
{
|
||||||
UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state;
|
UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state;
|
||||||
|
|
||||||
BTM_TRACE_EVENT ("%s", __func__);
|
BTM_TRACE_EVENT ("%s\n", __func__);
|
||||||
if (rl_mask)
|
if (rl_mask)
|
||||||
{
|
{
|
||||||
if (!btm_ble_disable_resolving_list (rl_mask, FALSE))
|
if (!btm_ble_disable_resolving_list (rl_mask, FALSE))
|
||||||
@ -879,7 +879,7 @@ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BTM_TRACE_DEBUG("Device not in resolving list");
|
BTM_TRACE_DEBUG("Device not in resolving list\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if resolving list has been turned on, re-enable it */
|
/* if resolving list has been turned on, re-enable it */
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
****************************************************************************************
|
||||||
|
*
|
||||||
|
* @file bt_app_api.c
|
||||||
|
*
|
||||||
|
* @brief Application entry point
|
||||||
|
*
|
||||||
|
* Copyright (C) Espressif 2016
|
||||||
|
* Created by Yulong at 2016/10/17
|
||||||
|
*
|
||||||
|
*
|
||||||
|
****************************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bt_app_api.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
|||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*********
|
*********
|
||||||
*/
|
*/
|
||||||
#if 0
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -33,6 +32,52 @@
|
|||||||
|
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
#include "button_pro.h"
|
#include "button_pro.h"
|
||||||
|
#include "app_button_int.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
** Function ble_but_prf_hdl_event
|
||||||
|
**
|
||||||
|
** Description button profile main event handling function.
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** Returns BOOLEAN
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data)
|
||||||
|
{
|
||||||
|
UINT16 connid = 0;
|
||||||
|
switch(msg_data->event)
|
||||||
|
{
|
||||||
|
case BLE_BUT_CREATE_DB_REQ_EVT:
|
||||||
|
Button_CreateService();
|
||||||
|
break;
|
||||||
|
case BLE_BUT_VAL_SEND_CFM_EVT:
|
||||||
|
break;
|
||||||
|
case BLE_BUT_SET_CHAR_VAL_REQ_EVT:
|
||||||
|
button_msg_notify(msg_data->len,msg_data->data);
|
||||||
|
break;
|
||||||
|
case BLE_BUT_ENABLE_REQ_EVT:
|
||||||
|
button_init(NULL);
|
||||||
|
break;
|
||||||
|
case BLE_BUT_DISABLE_IND_EVT:
|
||||||
|
button_disable(connid);
|
||||||
|
break;
|
||||||
|
case BLE_BUT_CHAR_WRITE_IND_EVT:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case BLE_BUT_ERROR_IND_EVT:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
#define GPIO_INUM 8
|
#define GPIO_INUM 8
|
||||||
#define TABLE_ELEMENT_CNT(table) ((sizeof(table))/(sizeof(table[0])));
|
#define TABLE_ELEMENT_CNT(table) ((sizeof(table))/(sizeof(table[0])));
|
||||||
app_key_env key_press;
|
app_key_env key_press;
|
||||||
|
@ -238,7 +238,7 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status)
|
|||||||
DIS_SrInit(dis_attr_mask);
|
DIS_SrInit(dis_attr_mask);
|
||||||
*/
|
*/
|
||||||
/*instantiate a battery service*/
|
/*instantiate a battery service*/
|
||||||
//bas_register();
|
bas_register();
|
||||||
/*instantiate the driver for button profile*/
|
/*instantiate the driver for button profile*/
|
||||||
//app_button_init();
|
//app_button_init();
|
||||||
#if (BUT_PROFILE_CFG)
|
#if (BUT_PROFILE_CFG)
|
||||||
|
@ -0,0 +1,117 @@
|
|||||||
|
/**
|
||||||
|
|
||||||
|
*******************************************************************************
|
||||||
|
*********
|
||||||
|
*
|
||||||
|
* @file app_button_int.h
|
||||||
|
*
|
||||||
|
* @brief button Service Application entry point
|
||||||
|
*
|
||||||
|
* Copyright (C) ESPRESSSIF 2016
|
||||||
|
* Created by Yulong at 2016/10/17
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
**********/
|
||||||
|
|
||||||
|
#include "prf_defs.h"
|
||||||
|
#include "bt_prf_sys.h"
|
||||||
|
#include "bt_types.h"
|
||||||
|
|
||||||
|
#if (BUT_PROFILE_CFG)
|
||||||
|
|
||||||
|
/// Messages for Device Information Service Server
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
///Add a BUTTON instance into the database
|
||||||
|
BLE_BUT_CREATE_DB_REQ_EVT = BT_PRF_SYS_EVT_START(PRF_ID_BUT_LE),
|
||||||
|
///Send key value confirm to APP so stable values can be erased
|
||||||
|
///if correctly sent.
|
||||||
|
BLE_BUT_VAL_SEND_CFM_EVT,
|
||||||
|
///Set the value of an attribute
|
||||||
|
BLE_BUT_SET_CHAR_VAL_REQ_EVT,
|
||||||
|
|
||||||
|
///Start the button notify Service Task - at connection
|
||||||
|
BLE_BUT_ENABLE_REQ_EVT,
|
||||||
|
|
||||||
|
/// Inform the application that the profile service role task has been disabled after a disconnection
|
||||||
|
BLE_BUT_DISABLE_IND_EVT,
|
||||||
|
/// Inform the application that the profile service has been reiceivd the charateristic write commamd from Client
|
||||||
|
BLE_BUT_CHAR_WRITE_IND_EVT,
|
||||||
|
///Error indication to Host
|
||||||
|
BLE_BUT_ERROR_IND_EVT,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Parameters of the @ref KEY_CREATE_DB_REQ message
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
///Database configuration
|
||||||
|
uint16_t features;
|
||||||
|
}tBUT_CRT_DB_REQ;
|
||||||
|
|
||||||
|
/// Parameters of the @ref KEY_CREATE_DB_CFM message
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
///Status
|
||||||
|
uint8_t status;
|
||||||
|
}tBUT_CRT_DB_CFM;
|
||||||
|
|
||||||
|
///Parameters of the @ref key_CFG_INDNTF_IND message
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
///Connection handle
|
||||||
|
uint16_t conhdl;
|
||||||
|
///Stop/notify/indicate value to configure into the peer characteristic
|
||||||
|
uint16_t cfg_val;
|
||||||
|
/// characteristics
|
||||||
|
uint8_t char_code;
|
||||||
|
}tBUT_CFG_NTF_IND;
|
||||||
|
|
||||||
|
|
||||||
|
/// Parameters of the @ref KEY_SET_CHAR_VAL_REQ message - shall be dynamically allocated
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
/// Characteristic Code
|
||||||
|
//uint8_t char_code;
|
||||||
|
uint8_t conhdl;
|
||||||
|
uint8_t key_val_len;
|
||||||
|
uint8_t key_val[2];
|
||||||
|
}tBUT_SND_CHAR_VAL_REQ;
|
||||||
|
|
||||||
|
/// Parameters of the @ref KEY_ENABLE_REQ message
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
///Connection handle
|
||||||
|
uint16_t conhdl;
|
||||||
|
/// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together
|
||||||
|
uint8_t sec_lvl;
|
||||||
|
///Type of connection
|
||||||
|
uint8_t con_type;
|
||||||
|
}tBUT_ENABLE_REQ;
|
||||||
|
|
||||||
|
///Parameters of the @ref KEY_VAL_SEND_CFM message
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
///Connection handle
|
||||||
|
uint16_t conhdl;
|
||||||
|
///Status
|
||||||
|
uint8_t status;
|
||||||
|
}tBUT_VAL_SND_CFM;
|
||||||
|
|
||||||
|
|
||||||
|
/// Parameters of the @ref KEY_DISABLE_IND message
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
///Connection handle
|
||||||
|
uint16_t conhdl;
|
||||||
|
}tBUT_DISABLE_IND;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif ///BUT_PROFILE_CFG
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
#define __APP_WECHAT_UTIL_H__
|
#define __APP_WECHAT_UTIL_H__
|
||||||
|
|
||||||
#include "prf_defs.h"
|
#include "prf_defs.h"
|
||||||
if (WX_AIRSYNC_CFG)
|
#if (WX_AIRSYNC_CFG)
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user