1 /* main.c - Application main entry point */
2
3 /*
4 * Copyright (c) 2015-2016 Intel Corporation
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include <zephyr/types.h>
10 #include <stddef.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <zephyr/sys/printk.h>
14 #include <zephyr/sys/byteorder.h>
15 #include <zephyr/kernel.h>
16
17 #include <zephyr/bluetooth/bluetooth.h>
18 #include <zephyr/bluetooth/conn.h>
19 #include <zephyr/bluetooth/classic/hfp_hf.h>
20 #include <zephyr/settings/settings.h>
21
connected(struct bt_conn * conn)22 static void connected(struct bt_conn *conn)
23 {
24 printk("HFP HF Connected!\n");
25 }
26
disconnected(struct bt_conn * conn)27 static void disconnected(struct bt_conn *conn)
28 {
29 printk("HFP HF Disconnected!\n");
30 }
31
service(struct bt_conn * conn,uint32_t value)32 static void service(struct bt_conn *conn, uint32_t value)
33 {
34 printk("Service indicator value: %u\n", value);
35 }
36
call(struct bt_conn * conn,uint32_t value)37 static void call(struct bt_conn *conn, uint32_t value)
38 {
39 printk("Call indicator value: %u\n", value);
40 }
41
call_setup(struct bt_conn * conn,uint32_t value)42 static void call_setup(struct bt_conn *conn, uint32_t value)
43 {
44 printk("Call Setup indicator value: %u\n", value);
45 }
46
call_held(struct bt_conn * conn,uint32_t value)47 static void call_held(struct bt_conn *conn, uint32_t value)
48 {
49 printk("Call Held indicator value: %u\n", value);
50 }
51
signal(struct bt_conn * conn,uint32_t value)52 static void signal(struct bt_conn *conn, uint32_t value)
53 {
54 printk("Signal indicator value: %u\n", value);
55 }
56
roam(struct bt_conn * conn,uint32_t value)57 static void roam(struct bt_conn *conn, uint32_t value)
58 {
59 printk("Roaming indicator value: %u\n", value);
60 }
61
battery(struct bt_conn * conn,uint32_t value)62 static void battery(struct bt_conn *conn, uint32_t value)
63 {
64 printk("Battery indicator value: %u\n", value);
65 }
66
ring_cb(struct bt_conn * conn)67 static void ring_cb(struct bt_conn *conn)
68 {
69 printk("Incoming Call...\n");
70 }
71
72 static struct bt_hfp_hf_cb hf_cb = {
73 .connected = connected,
74 .disconnected = disconnected,
75 .service = service,
76 .call = call,
77 .call_setup = call_setup,
78 .call_held = call_held,
79 .signal = signal,
80 .roam = roam,
81 .battery = battery,
82 .ring_indication = ring_cb,
83 };
84
bt_ready(int err)85 static void bt_ready(int err)
86 {
87 if (err) {
88 printk("Bluetooth init failed (err %d)\n", err);
89 return;
90 }
91
92 if (IS_ENABLED(CONFIG_SETTINGS)) {
93 settings_load();
94 }
95
96 printk("Bluetooth initialized\n");
97
98 err = bt_br_set_connectable(true);
99 if (err) {
100 printk("BR/EDR set/rest connectable failed (err %d)\n", err);
101 return;
102 }
103 err = bt_br_set_discoverable(true);
104 if (err) {
105 printk("BR/EDR set discoverable failed (err %d)\n", err);
106 return;
107 }
108
109 printk("BR/EDR set connectable and discoverable done\n");
110 }
111
handsfree_enable(void)112 static void handsfree_enable(void)
113 {
114 int err;
115
116 err = bt_hfp_hf_register(&hf_cb);
117 if (err < 0) {
118 printk("HFP HF Registration failed (err %d)\n", err);
119 }
120 }
121
main(void)122 int main(void)
123 {
124 int err;
125
126 handsfree_enable();
127
128 err = bt_enable(bt_ready);
129 if (err) {
130 printk("Bluetooth init failed (err %d)\n", err);
131 }
132 return 0;
133 }
134