gpio, uart0 and uart1 working
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
10
boards/nrf5340_audio_dk_nrf5340_cpuapp.overlay
Normal file
10
boards/nrf5340_audio_dk_nrf5340_cpuapp.overlay
Normal file
@@ -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";
|
||||
};
|
||||
};
|
||||
};
|
||||
36
src/main.c
36
src/main.c
@@ -19,6 +19,8 @@
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/drivers/bluetooth/hci_driver.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#include <zephyr/usb/usb_device.h>
|
||||
|
||||
@@ -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 <zephyr/drivers/bluetooth/hci_driver.h>
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
|
||||
&gpio_fwd {
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
&uart1 {
|
||||
status = "okay";
|
||||
current-speed = <115200>;
|
||||
|
||||
Reference in New Issue
Block a user