From d79dd219ce4b2e9cbd1b7e95c82e857d24c7c43a Mon Sep 17 00:00:00 2001 From: Jonathan Reichelt Gjertsen Date: Mon, 24 May 2021 23:37:31 +0200 Subject: [PATCH] Implement `uart_write_blocking` and `uart_read_blocking` for host (#438) --- src/host/hardware_uart/uart.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/host/hardware_uart/uart.c b/src/host/hardware_uart/uart.c index db28889..e610402 100644 --- a/src/host/hardware_uart/uart.c +++ b/src/host/hardware_uart/uart.c @@ -88,10 +88,18 @@ size_t uart_is_readable(uart_inst_t *uart) { } // Write len bytes directly from src to the UART -//void uart_write_blocking(uart_inst_t uart, const uint8_t *src, size_t len); +void uart_write_blocking(uart_inst_t *uart, const uint8_t *src, size_t len) { + for (size_t i = 0; i < len; i++) { + uart_putc(uart, src[i]); + } +} // Read len bytes directly from the UART to dst -//void uart_read_blocking(uart_inst_t uart, uint8_t *dst, size_t len); +void uart_read_blocking(uart_inst_t *uart, uint8_t *dst, size_t len) { + for (size_t i = 0; i < len; i++) { + dst[i] = uart_getc(uart); + } +} // ---------------------------------------------------------------------------- // UART-specific operations and aliases