99#include <zephyr/bluetooth/audio/bap.h>
1010#include <zephyr/logging/log.h>
1111#include <zephyr/sys/byteorder.h>
12+ #include <zephyr/drivers/gpio.h>
1213
1314#include "webusb.h"
1415#include "message_handler.h"
@@ -80,6 +81,9 @@ static uint32_t ba_source_broadcast_id;
8081static uint8_t ba_source_id ; /* Source ID of the receive state */
8182static struct bt_bap_scan_delegator_recv_state recv_state = {0 };
8283
84+ const struct gpio_dt_spec sinkLed = GPIO_DT_SPEC_GET (DT_ALIAS (led0 ), gpios );
85+ const struct gpio_dt_spec sourceLed = GPIO_DT_SPEC_GET (DT_ALIAS (led1 ), gpios );
86+
8387/*
8488 * Private functions
8589 */
@@ -250,6 +254,8 @@ static void broadcast_assistant_add_src_cb(struct bt_conn *conn, int err)
250254 net_buf_add_le32 (evt_msg , err );
251255
252256 send_net_buf_event (MESSAGE_SUBTYPE_SOURCE_ADDED , evt_msg );
257+
258+ gpio_pin_set (sourceLed .port , sourceLed .pin , 1 );
253259}
254260
255261static void broadcast_assistant_mod_src_cb (struct bt_conn * conn , int err )
@@ -271,6 +277,8 @@ static void broadcast_assistant_rem_src_cb(struct bt_conn *conn, int err)
271277{
272278 LOG_INF ("BASS remove source (err: %d)" , err );
273279 ba_source_id = 0 ;
280+
281+ gpio_pin_set (sourceLed .port , sourceLed .pin , 0 );
274282}
275283
276284static void connected (struct bt_conn * conn , uint8_t err )
@@ -311,6 +319,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
311319 LOG_ERR ("Setting security failed (err %d)" , err );
312320 }
313321
322+ gpio_pin_set (sinkLed .port , sinkLed .pin , 1 );
314323}
315324
316325static void disconnected (struct bt_conn * conn , uint8_t reason )
@@ -340,6 +349,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
340349 ba_sink_conn = NULL ;
341350
342351 send_net_buf_event (MESSAGE_SUBTYPE_SINK_DISCONNECTED , evt_msg );
352+
353+ gpio_pin_set (sinkLed .port , sinkLed .pin , 0 );
343354}
344355
345356static void security_changed_cb (struct bt_conn * conn , bt_security_t level , enum bt_security_err err )
@@ -879,6 +890,22 @@ int broadcast_assistant_init(void)
879890 bt_bap_broadcast_assistant_register_cb (& broadcast_assistant_callbacks );
880891 LOG_INF ("Bluetooth scan callback registered" );
881892
893+ if (!device_is_ready (sinkLed .port ) ||
894+ !device_is_ready (sourceLed .port )) {
895+ return -1 ;
896+ }
897+ err = gpio_pin_configure_dt (& sinkLed , GPIO_OUTPUT_INACTIVE );
898+ if (err < 0 ) {
899+ return err ;
900+ }
901+ err = gpio_pin_configure_dt (& sourceLed , GPIO_OUTPUT_INACTIVE );
902+ if (err < 0 ) {
903+ return err ;
904+ }
905+ gpio_pin_set (sinkLed .port , sinkLed .pin , 0 );
906+ gpio_pin_set (sourceLed .port , sourceLed .pin , 0 );
907+ LOG_INF ("LED's initialzed" );
908+
882909 ba_scan_target = 0 ;
883910
884911 return 0 ;
0 commit comments