Files
microchip-application-bmd38…/le_gap.c
T
2023-08-03 21:26:53 +08:00

83 lines
2.5 KiB
C

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_ble_scan.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "app_error.h"
#ifdef __cplusplus
}
#endif
void le_gap_init(const char *device_name, uint16_t usAppearance)
{
// TODO...
}
void le_gap_connet(ble_gap_addr_t *p_peer_addr)
{
// If address is correct, stop scanning and initiate connection with peripheral device.
const ble_gap_conn_params_t conn_params = {
.conn_sup_timeout =
(uint16_t)MSEC_TO_UNITS(NRF_BLE_SCAN_SUPERVISION_TIMEOUT, UNIT_10_MS),
.min_conn_interval =
(uint16_t)MSEC_TO_UNITS(NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL, UNIT_1_25_MS),
.max_conn_interval =
(uint16_t)MSEC_TO_UNITS(NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL, UNIT_1_25_MS),
.slave_latency =
(uint16_t)NRF_BLE_SCAN_SLAVE_LATENCY,
};
extern ble_gap_scan_params_t *le_scan_params(void);
ret_code_t err_code = sd_ble_gap_connect(p_peer_addr,
le_scan_params(),
&conn_params,
APP_BLE_CONN_CFG_TAG);
APP_ERROR_CHECK(err_code);
}
void le_gap_disconnet(uint16_t conn_handle)
{
ret_code_t err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
}
void le_gap_phy_update(uint16_t conn_handle)
{
NRF_LOG_INFO("Send PHY update request.");
ble_gap_phys_t const phys = {
.rx_phys = BLE_GAP_PHY_AUTO,
.tx_phys = BLE_GAP_PHY_AUTO,
};
ret_code_t err_code = sd_ble_gap_phy_update(conn_handle, &phys);
APP_ERROR_CHECK(err_code);
}
void le_gap_conn_param_update(uint16_t conn_handle)
{
NRF_LOG_INFO("Central Preferred Connection Parameters.");
// Set GAP Central Preferred Connection Parameters.
ble_gap_conn_params_t const gap_conn_params = {
.min_conn_interval = MSEC_TO_UNITS(8, UNIT_1_25_MS), /**< Minimum connection interval (7.5 ms) */
.max_conn_interval = MSEC_TO_UNITS(20, UNIT_1_25_MS), /**< Maximum connection interval (20 ms). */
.slave_latency = 8, /**< Slave latency. */
.conn_sup_timeout = MSEC_TO_UNITS(10000, UNIT_10_MS) /**< Connection supervisory timeout (10s). */
};
sd_ble_gap_conn_param_update(conn_handle, &gap_conn_params);
}