From 19a85ae45beb97d5b260e80320e233f95c0e302b Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Tue, 3 Nov 2015 23:53:42 +0000 Subject: f0 working (one fixme) need scan mode upstream? --- shared/usart_stdio.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 shared/usart_stdio.c (limited to 'shared/usart_stdio.c') diff --git a/shared/usart_stdio.c b/shared/usart_stdio.c new file mode 100644 index 0000000..6a6866e --- /dev/null +++ b/shared/usart_stdio.c @@ -0,0 +1,34 @@ +/* + * support for stdio output to a usart + * Karl Palsson, 2015 + */ + +#include +#include +#include + +#include + +#ifndef STDIO_USART +#define STDIO_USART USART1 +#endif + +int _write(int file, char *ptr, int len); +int _write(int file, char *ptr, int len) +{ + int i; + + if (file == STDOUT_FILENO || file == STDERR_FILENO) { + for (i = 0; i < len; i++) { + if (ptr[i] == '\n') { + usart_send_blocking(STDIO_USART, '\r'); + } + usart_send_blocking(STDIO_USART, ptr[i]); + } + return i; + } + errno = EIO; + return -1; +} + + -- cgit