aboutsummaryrefslogtreecommitdiff
path: root/src/components/uart/simple_uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/uart/simple_uart.c')
-rw-r--r--src/components/uart/simple_uart.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/components/uart/simple_uart.c b/src/components/uart/simple_uart.c
new file mode 100644
index 0000000..5c97ccd
--- /dev/null
+++ b/src/components/uart/simple_uart.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <gran/uart/simple_uart.h>
+
+struct simple_uart {
+ struct component component;
+};
+
+static stat simple_uart_write(struct simple_uart *uart, struct packet *pkt)
+{
+ (void)uart;
+ size_t size = packet_size(pkt);
+ if (size != 1)
+ return EBUS;
+
+ putchar(*(uint8_t *)packet_data(pkt));
+ packet_set_state(pkt, PACKET_DONE);
+ return OK;
+}
+
+struct component *create_simple_uart()
+{
+ struct simple_uart *uart = calloc(1, sizeof(struct simple_uart));
+ if (!uart)
+ return NULL;
+
+ uart->component.write = (write_callback)simple_uart_write;
+ return (struct component *)uart;
+}