1 /*
2 * Copyright (c) 2024 Croxel, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/bluetooth/bluetooth.h>
9 #include <zephyr/bluetooth/services/nus.h>
10
11 #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
12 #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
13
14 static const struct bt_data ad[] = {
15 BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
16 BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
17 };
18
19 static const struct bt_data sd[] = {
20 BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_SRV_VAL),
21 };
22
bt_nus_auto_start(void)23 static int bt_nus_auto_start(void)
24 {
25 int err;
26
27 err = bt_enable(NULL);
28 __ASSERT_NO_MSG(!err);
29
30 err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
31 __ASSERT_NO_MSG(!err);
32
33 return 0;
34 }
35
36 SYS_INIT(bt_nus_auto_start, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
37