50 lines
1.5 KiB
C
50 lines
1.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_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)
|
|
{
|
|
ret_code_t err_code;
|
|
|
|
ble_gap_conn_sec_mode_t sec_mode;
|
|
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
|
|
if (device_name != NULL)
|
|
{
|
|
// Set GAP device name
|
|
err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)device_name, strlen(device_name));
|
|
APP_ERROR_CHECK(err_code);
|
|
}
|
|
|
|
// Set GAP Appearance value
|
|
err_code = sd_ble_gap_appearance_set(usAppearance);
|
|
APP_ERROR_CHECK(err_code);
|
|
|
|
// Set GAP Peripheral Preferred Connection Parameters.
|
|
ble_gap_conn_params_t gap_conn_params;
|
|
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
|
|
gap_conn_params.min_conn_interval = MSEC_TO_UNITS(8, UNIT_1_25_MS); /**< Minimum connection interval (7.5 ms) */
|
|
gap_conn_params.max_conn_interval = MSEC_TO_UNITS(40, UNIT_1_25_MS); /**< Maximum connection interval (40 ms). */
|
|
gap_conn_params.slave_latency = 16; /**< Slave latency. */
|
|
gap_conn_params.conn_sup_timeout = MSEC_TO_UNITS(5000, UNIT_10_MS); /**< Connection supervisory timeout (5000 ms). */
|
|
|
|
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
|
|
APP_ERROR_CHECK(err_code);
|
|
} |