From f26bd495ea0dad0a9b610752555ce428197e9cc8 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 2 Aug 2020 14:51:42 -0500 Subject: Fix interval update, add PHY update --- app/src/ble.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 559b04f..2afc983 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -37,7 +37,11 @@ static void connected(struct bt_conn *conn, u8_t err) printk("Connected %s\n", addr); - bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x000c, 5, 400)); + bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x000c, 30, 400)); + +#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) + bt_conn_le_phy_update(default_conn, BT_CONN_LE_PHY_PARAM_2M); +#endif if (bt_conn_set_security(conn, BT_SECURITY_L2)) { -- cgit v1.2.3 From 880c6e0601b6313e26bc73e913843805666f4cf3 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 2 Aug 2020 15:01:32 -0500 Subject: Fix variable name in peripheral PHY update --- app/src/ble.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 2afc983..3a7755f 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -40,7 +40,7 @@ static void connected(struct bt_conn *conn, u8_t err) bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x000c, 30, 400)); #if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) - bt_conn_le_phy_update(default_conn, BT_CONN_LE_PHY_PARAM_2M); + bt_conn_le_phy_update(conn, BT_CONN_LE_PHY_PARAM_2M); #endif if (bt_conn_set_security(conn, BT_SECURITY_L2)) -- cgit v1.2.3 From f23ca9d7ee7481ebdbbed3234e902e5b7753ae41 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 2 Aug 2020 15:51:38 -0500 Subject: Add two solutions to param updates --- app/src/ble.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 3a7755f..db80a36 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -76,10 +76,39 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, } } +static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) { + static struct bt_conn_info info; + + bt_conn_get_info(conn, &info); + + if (info.role == BT_CONN_ROLE_MASTER && (param->interval_min != 6 || param->latency != 30)) { + return false; + } + + return true; +} + +static void le_param_updated(struct bt_conn *conn, u16_t interval, + u16_t latency, u16_t timeout) { + static struct bt_conn_info info; + + bt_conn_get_info(conn, &info); + + if (info.role == BT_CONN_ROLE_MASTER && (interval != 6 || latency != 30)) { + bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400)); + } + + LOG_DBG("Params updated: Interval: %d, Latency: %d", interval, latency); +}; + static struct bt_conn_cb conn_callbacks = { .connected = connected, .disconnected = disconnected, .security_changed = security_changed, +#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) + .le_param_req = le_param_req, + .le_param_updated = le_param_updated, +#endif }; static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) -- cgit v1.2.3 From cfea5cceb1ecb5dc2984ac6e6c0a389d8392f79e Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 3 Aug 2020 17:22:11 -0500 Subject: Remove updated callback --- app/src/ble.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index db80a36..6526357 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -88,26 +88,12 @@ static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) { return true; } -static void le_param_updated(struct bt_conn *conn, u16_t interval, - u16_t latency, u16_t timeout) { - static struct bt_conn_info info; - - bt_conn_get_info(conn, &info); - - if (info.role == BT_CONN_ROLE_MASTER && (interval != 6 || latency != 30)) { - bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400)); - } - - LOG_DBG("Params updated: Interval: %d, Latency: %d", interval, latency); -}; - static struct bt_conn_cb conn_callbacks = { .connected = connected, .disconnected = disconnected, .security_changed = security_changed, #if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) .le_param_req = le_param_req, - .le_param_updated = le_param_updated, #endif }; -- cgit v1.2.3 From 370cfcc59fdf2900feba653d4ce5b55a90050426 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 5 Aug 2020 22:38:40 -0500 Subject: Add if block and param req callback comment --- app/src/ble.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 6526357..7d986d7 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -76,17 +76,21 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, } } +#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) { static struct bt_conn_info info; bt_conn_get_info(conn, &info); + /* This captures a param change from central half of a split board connection + to stop default params from getting set over the top of our preferred ones */ if (info.role == BT_CONN_ROLE_MASTER && (param->interval_min != 6 || param->latency != 30)) { return false; } return true; } +#endif static struct bt_conn_cb conn_callbacks = { .connected = connected, -- cgit v1.2.3 From 7e8a07e693431adfb64d12262b3c7614920c042c Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 14 Aug 2020 16:45:05 -0400 Subject: Remove use of printk. --- app/src/ble.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 7d986d7..488491c 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -31,11 +31,11 @@ static void connected(struct bt_conn *conn, u8_t err) if (err) { - printk("Failed to connect to %s (%u)\n", addr, err); + LOG_WRN("Failed to connect to %s (%u)", log_strdup(addr), err); return; } - printk("Connected %s\n", addr); + LOG_DBG("Connected %s", log_strdup(addr)); bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x000c, 30, 400)); @@ -45,7 +45,7 @@ static void connected(struct bt_conn *conn, u8_t err) if (bt_conn_set_security(conn, BT_SECURITY_L2)) { - printk("Failed to set security\n"); + LOG_ERR("Failed to set security"); } } @@ -55,7 +55,7 @@ static void disconnected(struct bt_conn *conn, u8_t reason) bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - printk("Disconnected from %s (reason 0x%02x)\n", addr, reason); + LOG_DBG("Disconnected from %s (reason 0x%02x)", log_strdup(addr), reason); } static void security_changed(struct bt_conn *conn, bt_security_t level, @@ -67,11 +67,11 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, if (!err) { - printk("Security changed: %s level %u\n", addr, level); + LOG_DBG("Security changed: %s level %u", log_strdup(addr), level); } else { - printk("Security failed: %s level %u err %d\n", addr, level, + LOG_ERR("Security failed: %s level %u err %d", log_strdup(addr), level, err); } } @@ -107,7 +107,7 @@ static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - printk("Passkey for %s: %06u\n", addr, passkey); + LOG_DBG("Passkey for %s: %06u", log_strdup(addr), passkey); } #ifdef CONFIG_ZMK_BLE_PASSKEY_ENTRY @@ -118,7 +118,7 @@ static void auth_passkey_entry(struct bt_conn *conn) bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - printk("Passkey entry requested for %s\n", addr); + LOG_DBG("Passkey entry requested for %s", log_strdup(addr)); auth_passkey_entry_conn = bt_conn_ref(conn); } @@ -138,7 +138,7 @@ static void auth_cancel(struct bt_conn *conn) passkey_digit = 0; - printk("Pairing cancelled: %s\n", addr); + LOG_DBG("Pairing cancelled: %s", log_strdup(addr)); } static struct bt_conn_auth_cb zmk_ble_auth_cb_display = { @@ -169,14 +169,14 @@ static void zmk_ble_ready(int err) LOG_DBG("ready? %d", err); if (err) { - printk("Bluetooth init failed (err %d)\n", err); + LOG_ERR("Bluetooth init failed (err %d)", err); return; } err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), NULL, 0); if (err) { - printk("Advertising failed to start (err %d)\n", err); + LOG_ERR("Advertising failed to start (err %d)", err); return; } } @@ -187,7 +187,7 @@ static int zmk_ble_init(struct device *_arg) if (err) { - printk("BLUETOOTH FAILED"); + LOG_ERR("BLUETOOTH FAILED (%d)", err); return err; } -- cgit v1.2.3 From 087574f607b4a500738b8155281cf24388ba4400 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Aug 2020 15:36:43 -0500 Subject: Create proper fix for split default conn bug --- app/src/ble.c | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 488491c..6d2903f 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -76,29 +76,10 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, } } -#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) -static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) { - static struct bt_conn_info info; - - bt_conn_get_info(conn, &info); - - /* This captures a param change from central half of a split board connection - to stop default params from getting set over the top of our preferred ones */ - if (info.role == BT_CONN_ROLE_MASTER && (param->interval_min != 6 || param->latency != 30)) { - return false; - } - - return true; -} -#endif - static struct bt_conn_cb conn_callbacks = { .connected = connected, .disconnected = disconnected, .security_changed = security_changed, -#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) - .le_param_req = le_param_req, -#endif }; static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) -- cgit v1.2.3 From d7dee20e8d9b0b566859304063df2176aef8c057 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 09:56:25 -0400 Subject: Add missing license header. --- app/src/ble.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 6d2903f..71bbccd 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ #include #include -- cgit v1.2.3 From 4402e4fbc7bc79206589d3006fde802c4ba70ec7 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 11:20:15 -0400 Subject: feeature(bt): Add "unpair combo" on startup. * Especially for splits, we need the ability to unpair all paired devices as sledgehammer if we need to "reset things", and doing so via keymaps isn't suitable. * Allows shields to define a collection of key positions that if all held 2 seconds after startup, will unpair all existing pairs for the device. --- app/src/ble.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 71bbccd..686a536 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -190,6 +190,12 @@ static int zmk_ble_init(struct device *_arg) return 0; } +int zmk_ble_unpair_all() +{ + LOG_DBG(""); + return bt_unpair(BT_ID_DEFAULT, NULL); +}; + bool zmk_ble_handle_key_user(struct zmk_key_event *key_event) { zmk_key key = key_event->key; -- cgit v1.2.3 From 05235ca96d021c1ec0fce60570d9786ee41aa437 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 16:18:16 -0400 Subject: fix(bluetooth): Stop peripheral half advertising once connected. --- app/src/ble.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/src/ble.c') diff --git a/app/src/ble.c b/app/src/ble.c index 71bbccd..bf1dee7 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -28,6 +28,16 @@ static struct bt_conn *auth_passkey_entry_conn; static u8_t passkey_entries[6] = {0, 0, 0, 0, 0, 0}; static u8_t passkey_digit = 0; +#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) +#define ZMK_ADV_PARAMS BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \ + BT_LE_ADV_OPT_USE_NAME | \ + BT_LE_ADV_OPT_ONE_TIME, \ + BT_GAP_ADV_FAST_INT_MIN_2, \ + BT_GAP_ADV_FAST_INT_MAX_2, NULL) +#else +#define ZMK_ADV_PARAMS BT_LE_ADV_CONN_NAME +#endif + static void connected(struct bt_conn *conn, u8_t err) { char addr[BT_ADDR_LE_STR_LEN]; @@ -159,7 +169,7 @@ static void zmk_ble_ready(int err) return; } - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), NULL, 0); + err = bt_le_adv_start(ZMK_ADV_PARAMS, zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), NULL, 0); if (err) { LOG_ERR("Advertising failed to start (err %d)", err); -- cgit v1.2.3