Skip to content

Commit

Permalink
Added echoing for UART test double (#13)
Browse files Browse the repository at this point in the history
* added tiny

* lol whoops

* whitespace
  • Loading branch information
KaitlynAnn99 authored Nov 22, 2024
1 parent addc159 commit 4c5eb00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/include/double/tiny_uart_double.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef struct {
tiny_event_t send_complete;
bool automatic_send_complete;
bool sending;
bool echoing;
} tiny_uart_double_t;

/*!
Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions test/src/tiny_uart_double.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
Expand All @@ -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;
}

0 comments on commit 4c5eb00

Please sign in to comment.