From 4c5eb005f46ba6583a082baf38ece0a99f258e7d Mon Sep 17 00:00:00 2001 From: Kaitlyn Bultemeier <39197578+KaitlynAnn99@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:23:53 -0500 Subject: [PATCH] Added echoing for UART test double (#13) * added tiny * lol whoops * whitespace --- test/include/double/tiny_uart_double.hpp | 6 ++++++ test/src/tiny_uart_double.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/test/include/double/tiny_uart_double.hpp b/test/include/double/tiny_uart_double.hpp index 615bc94..62451c4 100644 --- a/test/include/double/tiny_uart_double.hpp +++ b/test/include/double/tiny_uart_double.hpp @@ -17,6 +17,7 @@ typedef struct { tiny_event_t send_complete; bool automatic_send_complete; bool sending; + bool echoing; } tiny_uart_double_t; /*! @@ -44,4 +45,9 @@ void tiny_uart_double_trigger_receive(tiny_uart_double_t* self, uint8_t byte); */ void tiny_uart_double_configure_automatic_send_complete(tiny_uart_double_t* self, bool enabled); +/*! + * When enabled, the double will raise a receive event when a byte is sent. Defaults to disabled. + */ +void tiny_uart_double_enable_echo(tiny_uart_double_t* self); + #endif diff --git a/test/src/tiny_uart_double.cpp b/test/src/tiny_uart_double.cpp index f49d3c6..cfac8f8 100644 --- a/test/src/tiny_uart_double.cpp +++ b/test/src/tiny_uart_double.cpp @@ -16,6 +16,10 @@ static void send(i_tiny_uart_t* _self, uint8_t byte) if(self->automatic_send_complete) { tiny_uart_double_trigger_send_complete(self); } + + if(self->echoing) { + tiny_uart_double_trigger_receive(self, byte); + } } static i_tiny_event_t* on_send_complete(i_tiny_uart_t* _self) @@ -37,6 +41,8 @@ void tiny_uart_double_init(tiny_uart_double_t* self) self->interface.api = &api; self->sending = false; self->automatic_send_complete = false; + self->echoing = false; + tiny_event_init(&self->send_complete); tiny_event_init(&self->receive); } @@ -62,3 +68,8 @@ void tiny_uart_double_configure_automatic_send_complete(tiny_uart_double_t* self { self->automatic_send_complete = enabled; } + +void tiny_uart_double_enable_echo(tiny_uart_double_t* self) +{ + self->echoing = true; +}