Skip to content

Commit

Permalink
Add automatic send complete option to the uart double
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanplusplus committed Feb 8, 2024
1 parent a482d68 commit 566050f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/include/double/tiny_uart_double.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct {
i_tiny_uart_t interface;
tiny_event_t receive;
tiny_event_t send_complete;
bool automatic_send_complete;
bool sending;
} tiny_uart_double_t;

Expand All @@ -38,4 +39,9 @@ void tiny_uart_double_trigger_send_complete(tiny_uart_double_t* self);
*/
void tiny_uart_double_trigger_receive(tiny_uart_double_t* self, uint8_t byte);

/*!
* When enabled, the double will raise a send complete event when a byte is sent. Defaults to disabled.
*/
void tiny_uart_double_configure_automatic_send_complete(tiny_uart_double_t* self, bool enabled);

#endif
10 changes: 10 additions & 0 deletions test/src/tiny_uart_double.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ static void send(i_tiny_uart_t* _self, uint8_t byte)
auto self = reinterpret_cast<tiny_uart_double_t*>(_self);
self->sending = true;
mock().actualCall("send").onObject(self).withParameter("byte", byte);

if(self->automatic_send_complete) {
tiny_uart_double_trigger_send_complete(self);
}
}

static i_tiny_event_t* on_send_complete(i_tiny_uart_t* _self)
Expand All @@ -32,6 +36,7 @@ void tiny_uart_double_init(tiny_uart_double_t* self)
{
self->interface.api = &api;
self->sending = false;
self->automatic_send_complete = false;
tiny_event_init(&self->send_complete);
tiny_event_init(&self->receive);
}
Expand All @@ -52,3 +57,8 @@ void tiny_uart_double_trigger_receive(tiny_uart_double_t* self, uint8_t byte)
tiny_uart_on_receive_args_t args = { byte };
tiny_event_publish(&self->receive, &args);
}

void tiny_uart_double_configure_automatic_send_complete(tiny_uart_double_t* self, bool enabled)
{
self->automatic_send_complete = enabled;
}

0 comments on commit 566050f

Please sign in to comment.