drivers: serial: pipe: init device at compile time and check if ready

Initialize UART pipe device at compile time, allowing to constify the
device pointer. Also fix device ready check (was checking for NULL, an
always true condition when using DEVICE_DT_GET).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-08-17 13:23:21 +02:00 committed by Carles Cufí
commit f9ab078dd0

View file

@ -21,7 +21,8 @@ LOG_MODULE_REGISTER(uart_pipe);
#include <zephyr/drivers/uart_pipe.h>
#include <zephyr/sys/printk.h>
static const struct device *uart_pipe_dev;
static const struct device *const uart_pipe_dev =
DEVICE_DT_GET(DT_CHOSEN(zephyr_uart_pipe));
static uint8_t *recv_buf;
static size_t recv_buf_len;
@ -98,9 +99,7 @@ void uart_pipe_register(uint8_t *buf, size_t len, uart_pipe_recv_cb cb)
recv_buf_len = len;
app_cb = cb;
uart_pipe_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_uart_pipe));
if (uart_pipe_dev != NULL) {
if (device_is_ready(uart_pipe_dev)) {
uart_pipe_setup(uart_pipe_dev);
}
}