diff --git a/app/Kconfig b/app/Kconfig index 397585cf4aa..97162cb1e0b 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -164,6 +164,16 @@ config ZMK_BLE_CLEAR_BONDS_ON_START bool "Configuration that clears all bond information from the keyboard on startup." default n +config ZMK_BLE_DEVICE_NAME_APPEND_SN + bool "Append the device serial number to the Bluetooth device name" + default n + select BT_DEVICE_NAME_DYNAMIC + +config ZMK_BLE_DEVICE_NAME_SN_CHARS + int "Number of hexadecimal digits of serial number to append to the BT device name" + default 6 + depends on ZMK_BLE_DEVICE_NAME_APPEND_SN + # HID GATT notifications sent this way are *not* picked up by Linux, and possibly others. config BT_GATT_NOTIFY_MULTIPLE default n diff --git a/app/boards/arm/glove80/Kconfig b/app/boards/arm/glove80/Kconfig index a00c37e4083..f1c12e7e314 100644 --- a/app/boards/arm/glove80/Kconfig +++ b/app/boards/arm/glove80/Kconfig @@ -6,13 +6,3 @@ config BOARD_ENABLE_DCDC select SOC_DCDC_NRF52X default y depends on (BOARD_GLOVE80_LH || BOARD_GLOVE80_RH) - -config BT_DEVICE_NAME_APPEND_SN - bool "Append serial number to BT device name" - default n - depends on BT_DEVICE_NAME_DYNAMIC - -config BT_DEVICE_NAME_SN_BYTES - int "Number of bytes of serial number to append to the BT device name" - default 4 - depends on BT_DEVICE_NAME_APPEND_SN diff --git a/app/boards/arm/glove80/glove80_lh_defconfig b/app/boards/arm/glove80/glove80_lh_defconfig index ff0994c2f65..ea1065cf45b 100644 --- a/app/boards/arm/glove80/glove80_lh_defconfig +++ b/app/boards/arm/glove80/glove80_lh_defconfig @@ -16,10 +16,7 @@ CONFIG_USB_DEVICE_VID=0x16c0 CONFIG_USB_DEVICE_MANUFACTURER="MoErgo" CONFIG_USB_DEVICE_SN="moergo.com:GLV80-0123456789ABCDEF" -CONFIG_BT_DEVICE_NAME="Glove80 " -CONFIG_BT_DEVICE_NAME_DYNAMIC=y -CONFIG_BT_DEVICE_NAME_APPEND_SN=y -CONFIG_BT_DEVICE_NAME_SN_BYTES=6 +CONFIG_BT_DEVICE_NAME="Glove80" CONFIG_BT_DIS_PNP_PID=0x27db CONFIG_BT_DIS_PNP_VID=0x16c0 diff --git a/app/src/ble.c b/app/src/ble.c index 6f330eafcf2..d9b8946afe4 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -62,9 +62,9 @@ enum advertising_type { static struct zmk_ble_profile profiles[ZMK_BLE_PROFILE_COUNT]; static uint8_t active_profile; -#if IS_ENABLED(CONFIG_BT_DEVICE_NAME_APPEND_SN) +#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN) -static char bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME) + CONFIG_BT_DEVICE_NAME_SN_BYTES]; +static char bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME) + CONFIG_ZMK_BLE_DEVICE_NAME_SN_CHARS + 1]; void fill_serial_number(char *buf, int length); @@ -72,8 +72,9 @@ void fill_serial_number(char *buf, int length); // CONFIG_BT_DEVICE_NAME void init_bt_device_name() { strncpy(bt_device_name, CONFIG_BT_DEVICE_NAME, sizeof(bt_device_name)); - fill_serial_number(bt_device_name + sizeof(CONFIG_BT_DEVICE_NAME) - 1, - CONFIG_BT_DEVICE_NAME_SN_BYTES); + bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME) - 1] = ' '; + fill_serial_number(&bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME)], + CONFIG_ZMK_BLE_DEVICE_NAME_SN_CHARS); bt_device_name[sizeof(bt_device_name) - 1] = '\0'; } @@ -648,7 +649,7 @@ static void zmk_ble_ready(int err) { } static int zmk_ble_init(const struct device *_arg) { -#if IS_ENABLED(CONFIG_BT_DEVICE_NAME_APPEND_SN) +#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN) init_bt_device_name(); #endif @@ -674,7 +675,7 @@ static int zmk_ble_init(const struct device *_arg) { settings_load_subtree("bt"); #endif -#if IS_ENABLED(CONFIG_BT_DEVICE_NAME_APPEND_SN) +#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN) if (strcmp(bt_get_name(), bt_device_name) != 0) { bt_set_name(bt_device_name); }