mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-19 14:26:01 -04:00
Compare commits
7 Commits
f082886099
...
871d0c8c9a
Author | SHA1 | Date | |
---|---|---|---|
|
871d0c8c9a | ||
|
02e0c7a2b8 | ||
|
26a300b668 | ||
|
dc937198c9 | ||
|
bb9134aaf8 | ||
|
195f08112b | ||
|
9545b5480f |
@ -206,6 +206,28 @@ typedef enum {
|
|||||||
ESP_BT_COD_MAJOR_DEV_UNCATEGORIZED = 31, /*!< Uncategorized: device not specified */
|
ESP_BT_COD_MAJOR_DEV_UNCATEGORIZED = 31, /*!< Uncategorized: device not specified */
|
||||||
} esp_bt_cod_major_dev_t;
|
} esp_bt_cod_major_dev_t;
|
||||||
|
|
||||||
|
/// Minor device class field of Class of Device for Peripheral Major Class
|
||||||
|
typedef enum {
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_KEYBOARD = 0x10, /*!< Keyboard */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_POINTING = 0x20, /*!< Pointing */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_COMBO = 0x30, /*!< Combo
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_KEYBOARD, ESP_BT_COD_MINOR_PERIPHERAL_POINTING
|
||||||
|
and ESP_BT_COD_MINOR_PERIPHERAL_COMBO can be OR'd with one of the
|
||||||
|
following values to identify a multifunctional device. e.g.
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_KEYBOARD | ESP_BT_COD_MINOR_PERIPHERAL_GAMEPAD
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_POINTING | ESP_BT_COD_MINOR_PERIPHERAL_SENSING_DEVICE
|
||||||
|
*/
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_JOYSTICK = 0x01, /*!< Joystick */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_GAMEPAD = 0x02, /*!< Gamepad */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_REMOTE_CONTROL = 0x03, /*!< Remote Control */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_SENSING_DEVICE = 0x04, /*!< Sensing Device */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_DIGITIZING_TABLET = 0x05, /*!< Digitizing Tablet */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_CARD_READER = 0x06, /*!< Card Reader */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_DIGITAL_PAN = 0x07, /*!< Digital Pan */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_HAND_SCANNER = 0x08, /*!< Hand Scanner */
|
||||||
|
ESP_BT_COD_MINOR_PERIPHERAL_HAND_GESTURAL_INPUT = 0x09, /*!< Hand Gestural Input */
|
||||||
|
} esp_bt_cod_minor_peripheral_t;
|
||||||
|
|
||||||
/// Bits of major device class field
|
/// Bits of major device class field
|
||||||
#define ESP_BT_COD_MAJOR_DEV_BIT_MASK (0x1f00) /*!< Major device bit mask */
|
#define ESP_BT_COD_MAJOR_DEV_BIT_MASK (0x1f00) /*!< Major device bit mask */
|
||||||
#define ESP_BT_COD_MAJOR_DEV_BIT_OFFSET (8) /*!< Major device bit offset */
|
#define ESP_BT_COD_MAJOR_DEV_BIT_OFFSET (8) /*!< Major device bit offset */
|
||||||
|
@ -543,7 +543,7 @@ static tBTM_PM_MODE btm_pm_get_set_mode(UINT8 pm_id, tBTM_PM_MCB *p_cb, tBTM_PM_
|
|||||||
** Function btm_pm_snd_md_req
|
** Function btm_pm_snd_md_req
|
||||||
** Description get the resulting mode and send the resuest to host controller
|
** Description get the resulting mode and send the resuest to host controller
|
||||||
** Returns tBTM_STATUS
|
** Returns tBTM_STATUS
|
||||||
**, BOOLEAN *p_chg_ind
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
static tBTM_STATUS btm_pm_snd_md_req(UINT8 pm_id, UINT16 link_hdl, tBTM_PM_PWR_MD *p_mode)
|
static tBTM_STATUS btm_pm_snd_md_req(UINT8 pm_id, UINT16 link_hdl, tBTM_PM_PWR_MD *p_mode)
|
||||||
{
|
{
|
||||||
@ -565,6 +565,8 @@ static tBTM_STATUS btm_pm_snd_md_req(UINT8 pm_id, UINT16 link_hdl, tBTM_PM_PWR_M
|
|||||||
/* already in the resulting mode */
|
/* already in the resulting mode */
|
||||||
if ( (mode == BTM_PM_MD_ACTIVE) ||
|
if ( (mode == BTM_PM_MD_ACTIVE) ||
|
||||||
((md_res.max >= p_cb->interval) && (md_res.min <= p_cb->interval)) ) {
|
((md_res.max >= p_cb->interval) && (md_res.min <= p_cb->interval)) ) {
|
||||||
|
// Clear request change indication because already in result mode
|
||||||
|
p_cb->chg_ind = FALSE;
|
||||||
return BTM_CMD_STORED;
|
return BTM_CMD_STORED;
|
||||||
}
|
}
|
||||||
/* Otherwise, needs to wake, then sleep */
|
/* Otherwise, needs to wake, then sleep */
|
||||||
@ -689,7 +691,7 @@ static void btm_pm_check_stored(void)
|
|||||||
** Description This function is called when an HCI command status event occurs
|
** Description This function is called when an HCI command status event occurs
|
||||||
** for power manager related commands.
|
** for power manager related commands.
|
||||||
**
|
**
|
||||||
** Input Parms status - status of the event (HCI_SUCCESS if no errors)
|
** Input Params status - status of the event (HCI_SUCCESS if no errors)
|
||||||
**
|
**
|
||||||
** Returns none.
|
** Returns none.
|
||||||
**
|
**
|
||||||
@ -717,7 +719,7 @@ void btm_pm_proc_cmd_status(UINT8 status)
|
|||||||
#if BTM_PM_DEBUG == TRUE
|
#if BTM_PM_DEBUG == TRUE
|
||||||
BTM_TRACE_DEBUG( "btm_pm_proc_cmd_status new state:0x%x", p_cb->state);
|
BTM_TRACE_DEBUG( "btm_pm_proc_cmd_status new state:0x%x", p_cb->state);
|
||||||
#endif // BTM_PM_DEBUG
|
#endif // BTM_PM_DEBUG
|
||||||
} else { /* the command was not successfull. Stay in the same state */
|
} else { /* the command was not successful. Stay in the same state */
|
||||||
pm_status = BTM_PM_STS_ERROR;
|
pm_status = BTM_PM_STS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -743,7 +745,7 @@ void btm_pm_proc_cmd_status(UINT8 status)
|
|||||||
**
|
**
|
||||||
** Description This function is called when an HCI mode change event occurs.
|
** Description This function is called when an HCI mode change event occurs.
|
||||||
**
|
**
|
||||||
** Input Parms hci_status - status of the event (HCI_SUCCESS if no errors)
|
** Input Params hci_status - status of the event (HCI_SUCCESS if no errors)
|
||||||
** hci_handle - connection handle associated with the change
|
** hci_handle - connection handle associated with the change
|
||||||
** mode - HCI_MODE_ACTIVE, HCI_MODE_HOLD, HCI_MODE_SNIFF, or HCI_MODE_PARK
|
** mode - HCI_MODE_ACTIVE, HCI_MODE_HOLD, HCI_MODE_SNIFF, or HCI_MODE_PARK
|
||||||
** interval - number of baseband slots (meaning depends on mode)
|
** interval - number of baseband slots (meaning depends on mode)
|
||||||
|
@ -717,11 +717,9 @@ void bt_hidd_cb(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *param)
|
|||||||
}
|
}
|
||||||
case ESP_HIDD_SET_PROTOCOL_EVT: {
|
case ESP_HIDD_SET_PROTOCOL_EVT: {
|
||||||
if (param->set_protocol.protocol_mode != ESP_HIDD_UNSUPPORTED_MODE) {
|
if (param->set_protocol.protocol_mode != ESP_HIDD_UNSUPPORTED_MODE) {
|
||||||
if (s_hidd_param.dev->protocol_mode == param->set_protocol.protocol_mode) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
osi_mutex_lock(&s_hidd_param.mutex, OSI_MUTEX_MAX_TIMEOUT);
|
osi_mutex_lock(&s_hidd_param.mutex, OSI_MUTEX_MAX_TIMEOUT);
|
||||||
s_hidd_param.dev->protocol_mode = param->set_protocol.protocol_mode;
|
s_hidd_param.dev->protocol_mode =
|
||||||
|
param->set_protocol.protocol_mode ? ESP_HID_PROTOCOL_MODE_BOOT : ESP_HID_PROTOCOL_MODE_REPORT;
|
||||||
osi_mutex_unlock(&s_hidd_param.mutex);
|
osi_mutex_unlock(&s_hidd_param.mutex);
|
||||||
cb_param.protocol_mode.dev = s_hidd_param.dev->dev;
|
cb_param.protocol_mode.dev = s_hidd_param.dev->dev;
|
||||||
cb_param.protocol_mode.protocol_mode = s_hidd_param.dev->protocol_mode;
|
cb_param.protocol_mode.protocol_mode = s_hidd_param.dev->protocol_mode;
|
||||||
|
@ -435,8 +435,9 @@ void app_main(void)
|
|||||||
esp_bt_dev_set_device_name(local_device_name);
|
esp_bt_dev_set_device_name(local_device_name);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "setting cod major, peripheral");
|
ESP_LOGI(TAG, "setting cod major, peripheral");
|
||||||
esp_bt_cod_t cod;
|
esp_bt_cod_t cod = {0};
|
||||||
cod.major = ESP_BT_COD_MAJOR_DEV_PERIPHERAL;
|
cod.major = ESP_BT_COD_MAJOR_DEV_PERIPHERAL;
|
||||||
|
cod.minor = ESP_BT_COD_MINOR_PERIPHERAL_POINTING;
|
||||||
esp_bt_gap_set_cod(cod, ESP_BT_SET_COD_MAJOR_MINOR);
|
esp_bt_gap_set_cod(cod, ESP_BT_SET_COD_MAJOR_MINOR);
|
||||||
|
|
||||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
@ -447,7 +448,7 @@ void app_main(void)
|
|||||||
s_local_param.app_param.name = "Mouse";
|
s_local_param.app_param.name = "Mouse";
|
||||||
s_local_param.app_param.description = "Mouse Example";
|
s_local_param.app_param.description = "Mouse Example";
|
||||||
s_local_param.app_param.provider = "ESP32";
|
s_local_param.app_param.provider = "ESP32";
|
||||||
s_local_param.app_param.subclass = ESP_HID_CLASS_MIC;
|
s_local_param.app_param.subclass = ESP_HID_CLASS_MIC; // keep same with minor class of COD
|
||||||
s_local_param.app_param.desc_list = hid_mouse_descriptor;
|
s_local_param.app_param.desc_list = hid_mouse_descriptor;
|
||||||
s_local_param.app_param.desc_list_len = hid_mouse_descriptor_len;
|
s_local_param.app_param.desc_list_len = hid_mouse_descriptor_len;
|
||||||
|
|
||||||
|
@ -592,8 +592,9 @@ void app_main(void)
|
|||||||
ESP_LOGI(TAG, "setting device name");
|
ESP_LOGI(TAG, "setting device name");
|
||||||
esp_bt_dev_set_device_name(bt_hid_config.device_name);
|
esp_bt_dev_set_device_name(bt_hid_config.device_name);
|
||||||
ESP_LOGI(TAG, "setting cod major, peripheral");
|
ESP_LOGI(TAG, "setting cod major, peripheral");
|
||||||
esp_bt_cod_t cod;
|
esp_bt_cod_t cod = {0};
|
||||||
cod.major = ESP_BT_COD_MAJOR_DEV_PERIPHERAL;
|
cod.major = ESP_BT_COD_MAJOR_DEV_PERIPHERAL;
|
||||||
|
cod.minor = ESP_BT_COD_MINOR_PERIPHERAL_POINTING;
|
||||||
esp_bt_gap_set_cod(cod, ESP_BT_SET_COD_MAJOR_MINOR);
|
esp_bt_gap_set_cod(cod, ESP_BT_SET_COD_MAJOR_MINOR);
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
ESP_LOGI(TAG, "setting bt device");
|
ESP_LOGI(TAG, "setting bt device");
|
||||||
|
@ -26,6 +26,43 @@ uint16_t attribute_handle[CONFIG_BT_NIMBLE_MAX_CONNECTIONS + 1];
|
|||||||
static void ble_spp_client_scan(void);
|
static void ble_spp_client_scan(void);
|
||||||
static ble_addr_t connected_addr[CONFIG_BT_NIMBLE_MAX_CONNECTIONS + 1];
|
static ble_addr_t connected_addr[CONFIG_BT_NIMBLE_MAX_CONNECTIONS + 1];
|
||||||
|
|
||||||
|
static void ble_spp_client_write_subscribe(const struct peer *peer)
|
||||||
|
{
|
||||||
|
uint8_t value[2];
|
||||||
|
int rc;
|
||||||
|
const struct peer_dsc *dsc;
|
||||||
|
|
||||||
|
/* Subscribe to notifications for the SPP characteristic.
|
||||||
|
* A central enables notifications by writing two bytes (1, 0) to the
|
||||||
|
* characteristic's client-characteristic-configuration-descriptor (CCCD).
|
||||||
|
*/
|
||||||
|
dsc = peer_dsc_find_uuid(peer,
|
||||||
|
BLE_UUID16_DECLARE(GATT_SPP_SVC_UUID),
|
||||||
|
BLE_UUID16_DECLARE(GATT_SPP_CHR_UUID),
|
||||||
|
BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16));
|
||||||
|
if (dsc == NULL) {
|
||||||
|
MODLOG_DFLT(ERROR, "Error: Peer lacks a CCCD for the Unread Alert "
|
||||||
|
"Status characteristic\n");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
value[0] = 1;
|
||||||
|
value[1] = 0;
|
||||||
|
rc = ble_gattc_write_flat(peer->conn_handle, dsc->dsc.handle,
|
||||||
|
value, sizeof value, NULL, NULL);
|
||||||
|
|
||||||
|
if (rc != 0) {
|
||||||
|
MODLOG_DFLT(ERROR, "Error: Failed to subscribe to characteristic; "
|
||||||
|
"rc=%d\n", rc);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
err:
|
||||||
|
/* Terminate the connection. */
|
||||||
|
ble_gap_terminate(peer->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ble_spp_client_set_handle(const struct peer *peer)
|
ble_spp_client_set_handle(const struct peer *peer)
|
||||||
{
|
{
|
||||||
@ -34,8 +71,10 @@ ble_spp_client_set_handle(const struct peer *peer)
|
|||||||
BLE_UUID16_DECLARE(GATT_SPP_SVC_UUID),
|
BLE_UUID16_DECLARE(GATT_SPP_SVC_UUID),
|
||||||
BLE_UUID16_DECLARE(GATT_SPP_CHR_UUID));
|
BLE_UUID16_DECLARE(GATT_SPP_CHR_UUID));
|
||||||
attribute_handle[peer->conn_handle] = chr->chr.val_handle;
|
attribute_handle[peer->conn_handle] = chr->chr.val_handle;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when service discovery of the specified peer has completed.
|
* Called when service discovery of the specified peer has completed.
|
||||||
*/
|
*/
|
||||||
@ -58,6 +97,8 @@ ble_spp_client_on_disc_complete(const struct peer *peer, int status, void *arg)
|
|||||||
"conn_handle=%d\n", status, peer->conn_handle);
|
"conn_handle=%d\n", status, peer->conn_handle);
|
||||||
|
|
||||||
ble_spp_client_set_handle(peer);
|
ble_spp_client_set_handle(peer);
|
||||||
|
ble_spp_client_write_subscribe(peer);
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_MAX_CONNECTIONS > 1
|
#if CONFIG_BT_NIMBLE_MAX_CONNECTIONS > 1
|
||||||
ble_spp_client_scan();
|
ble_spp_client_scan();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user