Skip to content

Commit b51d4d2

Browse files
committed
Merge branch 'feat/support_config_task_size_in_hid_example' into 'master'
Support change HID task size by Kconfig in HID example Closes IDFGH-14561 See merge request espressif/esp-idf!36796
2 parents d65d2fd + d4b3a7e commit b51d4d2

File tree

7 files changed

+89
-23
lines changed

7 files changed

+89
-23
lines changed

components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,6 @@ void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
723723
} else {
724724
APPL_TRACE_ERROR("%s, malloc failed", __func__);
725725
}
726-
} else {
727-
APPL_TRACE_ERROR("%s, incorrect length", __func__);
728726
}
729727
(*p_rcb->p_cback)(BTA_GATTS_CONF_EVT, &cb_data);
730728
if (cb_data.req_data.value != NULL) {
@@ -733,7 +731,7 @@ void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
733731
}
734732
}
735733
} else {
736-
APPL_TRACE_ERROR("Not an registered servce attribute ID: 0x%04x",
734+
APPL_TRACE_ERROR("Not a registered service attribute ID: 0x%04x",
737735
p_msg->api_indicate.attr_id);
738736
}
739737
}
@@ -923,7 +921,7 @@ void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
923921
**
924922
** Function bta_gatts_show_local_database
925923
**
926-
** Description print loacl service database
924+
** Description print local service database
927925
**
928926
** Returns none.
929927
**

components/bt/host/bluedroid/stack/gatt/gatt_sr.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static BOOLEAN process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status,
200200
*p++ = GATT_RSP_READ_MULTI;
201201
p_buf->len = 1;
202202

203-
/* Now walk through the buffers puting the data into the response in order */
203+
/* Now walk through the buffers putting the data into the response in order */
204204
list_t *list = NULL;
205205
const list_node_t *node = NULL;
206206
if (! fixed_queue_is_empty(p_cmd->multi_rsp_q)) {
@@ -321,7 +321,7 @@ static BOOLEAN process_read_multi_var_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS sta
321321
*p++ = GATT_RSP_READ_MULTI_VAR;
322322
p_buf->len = 1;
323323

324-
/* Now walk through the buffers puting the data into the response in order */
324+
/* Now walk through the buffers putting the data into the response in order */
325325
list_t *list = NULL;
326326
const list_node_t *node = NULL;
327327
if (! fixed_queue_is_empty(p_cmd->multi_rsp_q)) {
@@ -735,7 +735,7 @@ static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_
735735
handle_len = 4 + p_uuid->len;
736736
}
737737

738-
/* get the length byte in the repsonse */
738+
/* get the length byte in the response */
739739
if (p_msg->offset == 0) {
740740
*p ++ = op_code + 1;
741741
p_msg->len ++;
@@ -788,7 +788,7 @@ static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_
788788
** buffer.
789789
**
790790
** Returns TRUE: if data filled successfully.
791-
** FALSE: packet full, or format mismatch.
791+
** FALSE: packet full.
792792
**
793793
*******************************************************************************/
794794
static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg, UINT16 *p_len,
@@ -831,10 +831,9 @@ static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg,
831831
gatt_convert_uuid32_to_uuid128(p, ((tGATT_ATTR32 *) p_attr)->uuid);
832832
p += LEN_UUID_128;
833833
} else {
834-
GATT_TRACE_ERROR("format mismatch");
835-
status = GATT_NO_RESOURCES;
834+
// UUID format mismatch in sequential attributes
835+
// A new request will be sent with the starting handle of the next attribute
836836
break;
837-
/* format mismatch */
838837
}
839838
p_msg->len += info_pair_len[p_msg->offset - 1];
840839
len -= info_pair_len[p_msg->offset - 1];
@@ -889,7 +888,7 @@ static tGATT_STATUS gatts_validate_packet_format(UINT8 op_code, UINT16 *p_len,
889888
/* parse uuid now */
890889
if (gatt_parse_uuid_from_cmd (p_uuid_filter, uuid_len, &p) == FALSE ||
891890
p_uuid_filter->len == 0) {
892-
GATT_TRACE_DEBUG("UUID filter does not exsit");
891+
GATT_TRACE_DEBUG("UUID filter does not exist");
893892
reason = GATT_INVALID_PDU;
894893
} else {
895894
len -= p_uuid_filter->len;
@@ -1042,7 +1041,7 @@ static void gatts_process_find_info(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len,
10421041
**
10431042
** Function gatts_process_mtu_req
10441043
**
1045-
** Description This function is called to process excahnge MTU request.
1044+
** Description This function is called to process exchange MTU request.
10461045
** Only used on LE.
10471046
**
10481047
** Returns void
@@ -1055,7 +1054,7 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data)
10551054
BT_HDR *p_buf;
10561055
UINT16 conn_id;
10571056

1058-
/* BR/EDR conenction, send error response */
1057+
/* BR/EDR connection, send error response */
10591058
if (p_tcb->att_lcid != L2CAP_ATT_CID) {
10601059
gatt_send_error_rsp (p_tcb, GATT_REQ_NOT_SUPPORTED, GATT_REQ_MTU, 0, FALSE);
10611060
} else if (len < GATT_MTU_REQ_MIN_LEN) {
@@ -1081,7 +1080,7 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data)
10811080
attp_send_sr_msg (p_tcb, p_buf);
10821081

10831082
/* Notify all registered application with new MTU size. Us a transaction ID */
1084-
/* of 0, as no response is allowed from applcations */
1083+
/* of 0, as no response is allowed from applications */
10851084

10861085
for (i = 0; i < GATT_MAX_APPS; i ++) {
10871086
if (gatt_cb.cl_rcb[i].in_use ) {
@@ -1448,7 +1447,7 @@ void gatt_attr_process_prepare_write (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 hand
14481447
}
14491448

14501449
if ((prepare_record->error_code_app == GATT_SUCCESS)
1451-
// update prepare write status for excute write request
1450+
// update prepare write status for execute write request
14521451
&& (status == GATT_INVALID_OFFSET || status == GATT_INVALID_ATTR_LEN || status == GATT_REQ_NOT_SUPPORTED)) {
14531452
prepare_record->error_code_app = status;
14541453
}
@@ -1855,7 +1854,7 @@ void gatt_server_handle_client_req (tGATT_TCB *p_tcb, UINT8 op_code,
18551854
gatts_process_primary_service_req (p_tcb, op_code, len, p_data);
18561855
break;
18571856

1858-
case GATT_REQ_FIND_INFO: /* discover char descrptor */
1857+
case GATT_REQ_FIND_INFO: /* discover char descriptor */
18591858
gatts_process_find_info(p_tcb, op_code, len, p_data);
18601859
break;
18611860

components/esp_hid/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
menu "ESP HID"
2+
config ESPHID_TASK_SIZE_BT
3+
int "Task stack size for ESP HID BR/EDR"
4+
range 2048 10240
5+
default 2048
6+
help
7+
This is the stack size for the BT HID task.
8+
Default is 2048 bytes.
9+
10+
config ESPHID_TASK_SIZE_BLE
11+
int "Task stack size for ESP HID BLE"
12+
range 2048 10240
13+
default 4096
14+
help
15+
This is the stack size for the BLE HID task.
16+
Default is 4096 bytes.
17+
endmenu

components/esp_hid/include/esp_hid_common.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -85,6 +85,19 @@ extern "C" {
8585
#define ESP_HID_CCC_NOTIFICATIONS_ENABLED 0x01 // Notifications enabled
8686
#define ESP_HID_CCC_INDICATIONS_ENABLED 0x02 // Indications enabled
8787

88+
/* HID Task Size configuration */
89+
#ifdef CONFIG_ESPHID_TASK_SIZE_BT
90+
#define BT_HID_DEVICE_TASK_SIZE_BT CONFIG_ESPHID_TASK_SIZE_BT
91+
#else
92+
#define BT_HID_DEVICE_TASK_SIZE_BT 2048
93+
#endif
94+
95+
#ifdef CONFIG_ESPHID_TASK_SIZE_BLE
96+
#define BT_HID_DEVICE_TASK_SIZE_BLE CONFIG_ESPHID_TASK_SIZE_BLE
97+
#else
98+
#define BT_HID_DEVICE_TASK_SIZE_BLE 4096
99+
#endif
100+
88101
/* HID Transports */
89102
typedef enum {
90103
ESP_HID_TRANSPORT_BT,
@@ -202,8 +215,8 @@ esp_hid_report_map_t *esp_hid_parse_report_map(const uint8_t *hid_rm, size_t hid
202215
void esp_hid_free_report_map(esp_hid_report_map_t *map);
203216

204217
/**
205-
* @brief Calculate the HID Device usage type from the BLE Apperance
206-
* @param appearance : BLE Apperance value
218+
* @brief Calculate the HID Device usage type from the BLE Appearance
219+
* @param appearance : BLE Appearance value
207220
*
208221
* @return: the hid usage type
209222
*/

components/esp_hid/src/ble_hidd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ esp_err_t esp_ble_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_conf
971971
.queue_size = 5,
972972
.task_name = "ble_hidd_events",
973973
.task_priority = uxTaskPriorityGet(NULL),
974-
.task_stack_size = 4096,
974+
.task_stack_size = BT_HID_DEVICE_TASK_SIZE_BLE,
975975
.task_core_id = tskNO_AFFINITY
976976
};
977977
ret = esp_event_loop_create(&event_task_args, &s_dev->event_loop_handle);

components/esp_hid/src/bt_hidd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ esp_err_t esp_bt_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_confi
809809
.queue_size = 5,
810810
.task_name = "bt_hidd_events",
811811
.task_priority = uxTaskPriorityGet(NULL),
812-
.task_stack_size = 2048,
812+
.task_stack_size = BT_HID_DEVICE_TASK_SIZE_BT,
813813
.task_core_id = tskNO_AFFINITY
814814
};
815815
ret = esp_event_loop_create(&event_task_args, &s_hidd_param.dev->event_loop_handle);

examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,46 @@ static const esp_gatts_attr_db_t heart_rate_gatt_db[HRS_IDX_NB] =
441441
};
442442
```
443443
444+
### 128-bit UUID
445+
446+
To add characteristics with 128-bit UUIDs, a similar approach is used, but with minor differences.
447+
448+
Let's suppose we have the following UUID: `12345678-a1b2-c3d4-e5f6-9fafd205e457` and we want to assign it to
449+
the `HRS_IDX_128_BIT_LEN_UUID_CHAR` characteristic we also have.
450+
451+
Here is an example of how this can be done:
452+
453+
- First, let's declare our UUID
454+
455+
```c
456+
static const uint8_t our_128_bit_uuid_characteristic_uuid[ESP_UUID_LEN_128] = { // ESP_UUID_LEN_128 defined as 16
457+
0x57, 0xe4, 0x05, 0xd2, 0xaf, 0x9f, 0xf6, 0xe5, 0xd4, 0xc3, 0xb2, 0xa1, 0x78, 0x56, 0x34, 0x12
458+
};
459+
```
460+
461+
> ##### `0x57 0xe4 0x05 0xd2 0xaf 0x9f 0xf6 0xe5 0xd4 0xc3 0xb2 0xa1 0x78 0x56 0x34 0x12` - reversed version of the original UUID represented by uuid_byte_array.
462+
463+
- Now, all we need is to set `uuid_length` to `ESP_UUID_LEN_128` in the *Characteristic Value* setup.
464+
465+
> ##### Not to be confused with the *Characteristic Declaration*!
466+
467+
```c
468+
static const esp_gatts_attr_db_t heart_rate_gatt_db[HRS_IDX_NB] =
469+
{
470+
<...>
471+
// 128-bit UUID Characteristic Declaration
472+
[HRS_IDX_128_BIT_LEN_UUID_CHAR] =
473+
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
474+
CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_notify}},
475+
476+
// 128-bit UUID Characteristic Value
477+
[HRS_IDX_128_BIT_LEN_UUID_VAL] =
478+
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&our_128_bit_uuid_characteristic_uuid, ESP_GATT_PERM_READ,
479+
THIS_CHAR_VAL_MAX_LEN,0, NULL}},
480+
<...>
481+
};
482+
```
483+
444484
## Starting the Service
445485
When the attribute table is created, an ``ESP_GATTS_CREAT_ATTR_TAB_EVT`` event is triggered. This event has the following parameters:
446486
@@ -495,4 +535,3 @@ struct gatts_profile_inst {
495535
This document explains the work flow of the GATT Server Service Table example code that implements a Heart Rate Profile. This example begins by defining a table of attributes which include all the services and characteristics of the server, then it registers the Application Profile which triggers events that are used to configure GAP parameters and to create the service table. A service table is initialized with all the parameters required for each attribute and the service is started. This example shows a practical way of defining the server attributes by using a table instead of adding characteristic one by one.
496536
497537
498-

0 commit comments

Comments
 (0)