diff --git a/README.md b/README.md index a56573a..339fc86 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # build for USB CDC ```sh -west build -b nrf5340dk_nrf5340_cpuapp -- -DDTC_OVERLAY_FILE=usb.overlay -DOVERLAY_CONFIG=overlay-usb.conf +west build -b nrf5340dk_nrf5340_cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=usb.overlay -DOVERLAY_CONFIG=overlay-usb.conf ``` # build for build in serial adapter of the nrf5340_audio_dk a.k. uart0 @@ -10,10 +10,10 @@ west build -b nrf5340_audio_dk_nrf5340_cpuapp # build for uart1 a.k. arduino_serial ```sh -west build -b nrf5340_audio_dk_nrf5340_cpuapp -- -DDTC_OVERLAY_FILE=uart1.overlay +west build -b nrf5340_audio_dk_nrf5340_cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=uart1.overlay ``` # build for debug and uart1 ```sh -west build -b nrf5340_audio_dk_nrf5340_cpuapp -- -DDTC_OVERLAY_FILE=uart1.overlay -DOVERLAY_CONFIG=debug.conf +west build -b nrf5340_audio_dk_nrf5340_cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=uart1.overlay -DOVERLAY_CONFIG=debug.conf ``` diff --git a/boards/nrf5340_audio_dk_nrf5340_cpuapp.overlay b/boards/nrf5340_audio_dk_nrf5340_cpuapp.overlay new file mode 100644 index 0000000..6411227 --- /dev/null +++ b/boards/nrf5340_audio_dk_nrf5340_cpuapp.overlay @@ -0,0 +1,10 @@ +/ { + host_interface { + compatible = "gpio-outputs"; + status = "okay"; + timesync: pin_0 { + gpios = <&arduino_header 10 GPIO_ACTIVE_HIGH>; + label = "Controller to host timesync pin"; + }; + }; +}; diff --git a/src/main.c b/src/main.c index b778bc3..160880a 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include @@ -258,7 +260,8 @@ static void tx_thread(void *p1, void *p2, void *p3) buf = net_buf_get(&tx_queue, K_FOREVER); /* Pass buffer to the stack */ err = bt_send(buf); - if (err) { + if ((err!=BT_HCI_ERR_SUCCESS) && + (err!=BT_HCI_ERR_EXT_HANDLED)) { LOG_ERR("Unable to send (err %d)", err); net_buf_unref(buf); } @@ -356,6 +359,14 @@ static int hci_uart_init(void) SYS_INIT(hci_uart_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +#define TIMESYNC_GPIO DT_NODELABEL(timesync) + +#if DT_NODE_HAS_STATUS(TIMESYNC_GPIO, okay) +static const struct gpio_dt_spec timesync_pin = GPIO_DT_SPEC_GET(TIMESYNC_GPIO, gpios); +#else +#error "No timesync gpio available!" +#endif + #define HCI_CMD_ISO_TIMESYNC (0x100) struct hci_cmd_iso_timestamp_response { @@ -363,8 +374,6 @@ struct hci_cmd_iso_timestamp_response { uint32_t timestamp; } __packed; -#include - uint8_t hci_cmd_iso_timesync_cb(struct net_buf *buf) { struct net_buf *rsp; @@ -384,7 +393,9 @@ uint8_t hci_cmd_iso_timesync_cb(struct net_buf *buf) h4_send( rsp ); -// gpio_pin_configure_dt(&led, (buf->data[0] != 0) ? GPIO_OUTPUT_ACTIVE : GPIO_OUTPUT_INACTIVE); +#if DT_NODE_HAS_STATUS(TIMESYNC_GPIO, okay) + gpio_pin_toggle_dt( ×ync_pin ); +#endif return BT_HCI_ERR_EXT_HANDLED; } @@ -427,13 +438,17 @@ int main(void) } } - /* Register set_led_state command */ + /* Register iso_timesync command */ static struct bt_hci_raw_cmd_ext cmd_list = { .op = BT_OP(BT_OGF_VS, HCI_CMD_ISO_TIMESYNC), .min_len = 1, .func = hci_cmd_iso_timesync_cb }; +#if DT_NODE_HAS_STATUS(TIMESYNC_GPIO, okay) + gpio_pin_configure_dt(×ync_pin, GPIO_OUTPUT_INACTIVE); +#endif + bt_hci_raw_cmd_ext_register(&cmd_list, 1); /* Spawn the TX thread and start feeding commands and data to the @@ -444,7 +459,16 @@ int main(void) NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); k_thread_name_set(&tx_thread_data, "HCI uart TX"); - while (1) { +#if 0 + while (1) { + uint8_t c = 'A'; + uart_fifo_fill(hci_uart_dev, &c, 1); + uart_irq_tx_enable(hci_uart_dev); + k_sleep( K_MSEC(100) ); + } +#endif + + while (1) { struct net_buf *buf; buf = net_buf_get(&rx_queue, K_FOREVER); diff --git a/uart1.overlay b/uart1.overlay index 27fda09..995e1c7 100644 --- a/uart1.overlay +++ b/uart1.overlay @@ -1,4 +1,8 @@ +&gpio_fwd { + status = "disabled"; +}; + &uart1 { status = "okay"; current-speed = <115200>;