fix(bluetooth): Switch to Zephyr auto conn param.

* Don't explicitly set conn. params, instead defer to the built
  in Zephyr support for this, which properly defers this update
  for several seconds to avoid disruption to initial interactions
  between central and peripheral.
This commit is contained in:
Peter Johanson 2021-08-23 23:19:42 -04:00
parent 33fa15a235
commit 9e189d5be7
2 changed files with 16 additions and 7 deletions

View file

@ -78,6 +78,18 @@ config ZMK_BLE_CLEAR_BONDS_ON_START
bool "Configuration that clears all bond information from the keyboard on startup."
default n
config BT_PERIPHERAL_PREF_MIN_INT
default 12
config BT_PERIPHERAL_PREF_MAX_INT
default 12
config BT_PERIPHERAL_PREF_SLAVE_LATENCY
default 30
config BT_PERIPHERAL_PREF_TIMEOUT
default 400
# HID GATT notifications sent this way are *not* picked up by Linux, and possibly others.
config BT_GATT_NOTIFY_MULTIPLE
default n

View file

@ -61,6 +61,7 @@ enum advertising_type {
static struct zmk_ble_profile profiles[PROFILE_COUNT];
static uint8_t active_profile;
#define DEVICE_SECURITY_LEVEL BT_SECURITY_L2
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
@ -380,19 +381,15 @@ static void connected(struct bt_conn *conn, uint8_t err) {
LOG_DBG("Connected %s", log_strdup(addr));
err = bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x000c, 30, 400));
if (err) {
LOG_WRN("Failed to update LE parameters (err %d)", err);
uint8_t set_security_err = bt_conn_set_security(conn, DEVICE_SECURITY_LEVEL);
if (set_security_err) {
LOG_ERR("Failed to set security %d", set_security_err);
}
#if IS_SPLIT_PERIPHERAL
bt_conn_le_phy_update(conn, BT_CONN_LE_PHY_PARAM_2M);
#endif
if (bt_conn_set_security(conn, BT_SECURITY_L2)) {
LOG_ERR("Failed to set security");
}
update_advertising();
if (is_conn_active_profile(conn)) {