71223ad0d0
Use devicetree instead of Kconfig to configure the board control switches in nRF9160 DK: - add binding for the switches that provide optional signal routings on this board - add binding for the GPIO interface that can be used for communication (e.g. UART based) between the nRF9160 and the nRF52840 on the DK, and add GPIO mapping for this interface so that its lines can be used without caring about of actual pin numbers on both sides - add binding for one GPIO line chosen from the above interface that is to allow the nRF9160 to reset the nRF52840 - update accordingly dts files and board specific code for both board definitions associated with the DK - introduce .dtsi files that can be included from dts overlays in order to facilitate the use of the above GPIO interface; modify the overlay in the hci_uart sample to provide an example of use of those files Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
68 lines
1.5 KiB
C
68 lines
1.5 KiB
C
/*
|
|
* Copyright (c) 2019 Nordic Semiconductor ASA.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <drivers/gpio.h>
|
|
#include <drivers/uart.h>
|
|
#include <device.h>
|
|
#include <devicetree.h>
|
|
|
|
#define RESET_NODE DT_NODELABEL(nrf52840_reset)
|
|
|
|
#if DT_NODE_HAS_STATUS(RESET_NODE, okay)
|
|
|
|
#define RESET_GPIO_CTRL DT_GPIO_CTLR(RESET_NODE, gpios)
|
|
#define RESET_GPIO_PIN DT_GPIO_PIN(RESET_NODE, gpios)
|
|
#define RESET_GPIO_FLAGS DT_GPIO_FLAGS(RESET_NODE, gpios)
|
|
|
|
int bt_hci_transport_setup(const struct device *h4)
|
|
{
|
|
int err;
|
|
char c;
|
|
const struct device *port = DEVICE_DT_GET(RESET_GPIO_CTRL);
|
|
|
|
if (!device_is_ready(port)) {
|
|
return -EIO;
|
|
}
|
|
|
|
/* Configure pin as output and initialize it to inactive state. */
|
|
err = gpio_pin_configure(port, RESET_GPIO_PIN,
|
|
RESET_GPIO_FLAGS | GPIO_OUTPUT_INACTIVE);
|
|
if (err) {
|
|
return err;
|
|
}
|
|
|
|
/* Reset the nRF52840 and let it wait until the pin is inactive again
|
|
* before running to main to ensure that it won't send any data until
|
|
* the H4 device is setup and ready to receive.
|
|
*/
|
|
err = gpio_pin_set(port, RESET_GPIO_PIN, 1);
|
|
if (err) {
|
|
return err;
|
|
}
|
|
|
|
/* Wait for the nRF52840 peripheral to stop sending data.
|
|
*
|
|
* It is critical (!) to wait here, so that all bytes
|
|
* on the lines are received and drained correctly.
|
|
*/
|
|
k_sleep(K_MSEC(10));
|
|
|
|
/* Drain bytes */
|
|
while (uart_fifo_read(h4, &c, 1)) {
|
|
continue;
|
|
}
|
|
|
|
/* We are ready, let the nRF52840 run to main */
|
|
err = gpio_pin_set(port, RESET_GPIO_PIN, 0);
|
|
if (err) {
|
|
return err;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#endif /* DT_NODE_HAS_STATUS(RESET_NODE, okay) */
|