Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/board/rtl8730e: add connection parameter update for BLE #6586

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
os/board/rtl8730e: add connection parameter update for BLE
- add function to update BLE connection parameter for slave and master
  • Loading branch information
yeetee179 committed Dec 17, 2024
commit e937dd59f7187e9c196f9afc88e4032296a8207a
27 changes: 27 additions & 0 deletions apps/examples/ble_rmc/ble_rmc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,33 @@ int ble_rmc_main(int argc, char *argv[])
}
}

//connection parameter update, use this when AI-Lite is slave
if (strncmp(argv[1], "updates", 8) == 0) {
ble_conn_handle conn_handle = 24;
ble_conn_param conn_param;
conn_param.min_conn_interval = 0x0010;
conn_param.max_conn_interval = 0x0010;
conn_param.slave_latency = 2;
conn_param.supervision_timeout = 0x00aa;
conn_param.role = BLE_SLAVE_CONN_PARAM_UPDATE;

ble_manager_conn_param_update(&conn_handle, &conn_param);
}

//connection parameter update, use this when TPdual is master
if (strncmp(argv[1], "updatem", 8) == 0) {
ble_conn_handle conn_handle = 16;
ble_conn_param conn_param;
conn_param.min_conn_interval = 0x0010;
conn_param.max_conn_interval = 0x0010;
conn_param.slave_latency = 2;
conn_param.supervision_timeout = 0x00aa;
conn_param.role = BLE_SLAVE_CONN_PARAM_UPDATE;

ble_manager_conn_param_update(&conn_handle, &conn_param);

}

if (strncmp(argv[1], "advon", 6) == 0) {
ret = ble_server_one_shot_adv_init();
uint8_t type1 = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,30 @@ trble_result_e rtw_ble_client_connect(trble_conn_info* conn_info, bool is_secure
return TRBLE_SUCCESS;
}

trble_result_e rtw_ble_client_conn_param_update(trble_conn_handle *conn_handle, trble_conn_param *conn_param)
{
rtk_bt_le_update_conn_param_t param;

if(conn_handle == NULL || conn_param == NULL)
{
debug_print("Invalid input \n");
return TRBLE_INVALID_ARGS;
}

param.conn_handle = *conn_handle;
param.conn_interval_min = conn_param->min_conn_interval;
param.conn_interval_max = conn_param->max_conn_interval;
param.conn_latency = conn_param->slave_latency;
param.supv_timeout = conn_param->supervision_timeout;

if(RTK_BT_FAIL == rtk_bt_le_gap_update_conn_param(&param))
{
debug_print("connection update fail \n");
return TRBLE_FAIL;
}
return TRBLE_SUCCESS;
}

trble_result_e rtw_ble_client_read_connected_device_list(trble_connected_list* out_connected_list)
{
if (out_connected_list == NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,24 +311,24 @@ trble_result_e rtw_ble_server_charact_indicate(trble_attr_handle attr_handle, tr
osif_mem_free(param.data);
return TRBLE_SUCCESS;
}

extern rtk_bt_gatts_app_priv_t *g_rtk_bt_gatts_priv;
trble_result_e rtw_ble_server_indicate_queue_cnt(trble_conn_handle *con_handle, uint8_t *indication_count)
{
uint8_t con_id;
rtk_bt_le_gap_get_conn_id(*con_handle, &con_id);
uint8_t con_id;
rtk_bt_le_gap_get_conn_id(*con_handle, &con_id);
rtk_bt_gatt_queue_t *queue;
queue = &g_rtk_bt_gatts_priv->indicate_queue[con_id];
*indication_count = queue->pending_ele_num;

/* The number of element in pending queue should be limited, otherwise
the notification of high frequnce will use up memory */
if (queue->pending_ele_num >= BT_QUEUE_PENDING_ELEMENT_MAX)
{
{
printf("Error: GATTS pending queue full, wait a moment to send data again !!!\r\n");
return TRBLE_BUSY;
}
}

return TRBLE_SUCCESS;
}

Expand Down Expand Up @@ -402,13 +402,13 @@ trble_conn_handle rtw_ble_server_get_conn_handle_by_address(uint8_t* mac)
trble_result_e rtw_ble_server_set_device_name(uint8_t* name)
{
if(RTK_BT_OK == rtk_bt_le_gap_set_device_name(name))
{
debug_print("Set device name success \n");
} else {
debug_print("Set device name fail \n");
return TRBLE_FAIL;
}
return TRBLE_SUCCESS;
{
debug_print("Set device name success \n");
} else {
debug_print("Set device name fail \n");
return TRBLE_FAIL;
}
return TRBLE_SUCCESS;
}

trble_result_e rtw_ble_server_adv_into_idle(void)
Expand Down Expand Up @@ -575,6 +575,30 @@ bool rtw_ble_server_conn_is_any_active(void)

trble_result_e rtw_ble_server_conn_param_update(trble_conn_handle *conn_handle, trble_conn_param *conn_param)
{
if (is_server_init != true)
{
return TRBLE_INVALID_STATE;
}

if(conn_handle == NULL || conn_param == NULL)
{
debug_print("Invalid input \n");
return TRBLE_INVALID_ARGS;
}

rtk_bt_le_update_conn_param_t param;

param.conn_handle = *conn_handle;
param.conn_interval_min = conn_param->min_conn_interval;
param.conn_interval_max = conn_param->max_conn_interval;
param.conn_latency = conn_param->slave_latency;
param.supv_timeout = conn_param->supervision_timeout;

if(RTK_BT_FAIL == rtk_bt_le_gap_update_conn_param(&param))
{
debug_print("connection parameter update fail \n");
return TRBLE_FAIL;
}
return TRBLE_SUCCESS;
}

Expand Down Expand Up @@ -615,7 +639,7 @@ trble_result_e rtw_ble_server_start_adv(void)
}
}
}

#if !defined (RTK_BLE_5_0_AE_ADV_SUPPORT) && RTK_BLE_5_0_AE_ADV_SUPPORT
rtk_bt_le_gap_dev_state_t new_state;
if(RTK_BT_OK != rtk_bt_le_gap_get_dev_state(&new_state))
Expand All @@ -639,7 +663,7 @@ trble_result_e rtw_ble_server_start_adv(void)
}
} while(new_state.gap_adv_state != GAP_ADV_STATE_IDLE);
}
#endif
#endif

rtk_bt_le_adv_param_t adv_param;
adv_param.interval_min = rtw_ble_server_adv_interval;
Expand All @@ -663,7 +687,7 @@ trble_result_e rtw_ble_server_start_adv(void)
debug_print("start adv fail \n");
return TRBLE_FAIL;
}

#if !defined (RTK_BLE_5_0_AE_ADV_SUPPORT) && RTK_BLE_5_0_AE_ADV_SUPPORT
do
{
Expand All @@ -674,7 +698,7 @@ trble_result_e rtw_ble_server_start_adv(void)
debug_print("get dev state fail \n");
}
} while(new_state.gap_adv_state != GAP_ADV_STATE_ADVERTISING);
#endif
#endif

return TRBLE_SUCCESS;
}
Expand Down
12 changes: 12 additions & 0 deletions os/board/rtl8730e/src/component/os/tizenrt/rtk_blemgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ trble_result_e trble_netmgr_conn_is_any_active(struct bledev *dev, bool *is_acti

trble_result_e trble_netmgr_conn_param_update(struct bledev *dev, trble_conn_handle *conn_handle, trble_conn_param *conn_param)
{
if (conn_param->role == TRBLE_SLAVE_CONN_PARAM_UPDATE)
{
return rtw_ble_server_conn_param_update(conn_handle, conn_param);
}
else if (conn_param->role == TRBLE_MASTER_CONN_PARAM_UPDATE)
{
return rtw_ble_client_conn_param_update(conn_handle, conn_param);
}
else
{
return TRBLE_FAIL;
}
return TRBLE_SUCCESS;
}

Expand Down