1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <autoconf.h>
8 #include <stddef.h>
9 
10 #include <zephyr/bluetooth/bluetooth.h>
11 #include <zephyr/kernel.h>
12 #include <zephyr/logging/log.h>
13 #include <zephyr/logging/log_core.h>
14 #include <zephyr/sys/util_macro.h>
15 
16 #include "cap_initiator.h"
17 
18 LOG_MODULE_REGISTER(cap_initiator, LOG_LEVEL_INF);
19 
main(void)20 int main(void)
21 {
22 	int err;
23 
24 	err = bt_enable(NULL);
25 	if (err != 0) {
26 		LOG_ERR("Bluetooth enable failed: %d", err);
27 
28 		return 0;
29 	}
30 
31 	LOG_INF("Bluetooth initialized");
32 
33 	/* Broadcast is started first as the unicast part is run as loop */
34 	if (IS_ENABLED(CONFIG_SAMPLE_BROADCAST)) {
35 		err = cap_initiator_broadcast();
36 
37 		if (err != 0) {
38 			LOG_ERR("Failed to run CAP Initiator as broadcaster: %d", err);
39 		}
40 	}
41 
42 	/* If the CONFIG_SAMPLE_UNICAST is enabled we call the cap_initiator_unicast
43 	 * function that runs the application as a CAP Initiator for unicast. This will attempt to
44 	 * scan for and connect to a CAP acceptor to set up a stream
45 	 *
46 	 * Since cap_initiator_unicast runs as a while (true) loop, this shall be done as the last
47 	 * thing in this function
48 	 */
49 	if (IS_ENABLED(CONFIG_SAMPLE_UNICAST)) {
50 		err = cap_initiator_unicast();
51 
52 		if (err != 0) {
53 			LOG_ERR("Failed to run CAP Initiator as unicast: %d", err);
54 		}
55 	}
56 
57 	return 0;
58 }
59