summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2015-11-03 23:53:42 +0000
committerKarl Palsson <karlp@tweak.net.au>2016-03-04 00:43:21 +0000
commit19a85ae45beb97d5b260e80320e233f95c0e302b (patch)
treea4686cd846ae987a0e355ab7d2d047c9653982ca /shared
parentc522c29dcab2be8c8ee629e22a3f632d8c614282 (diff)
downloadolsndot-19a85ae45beb97d5b260e80320e233f95c0e302b.tar.gz
olsndot-19a85ae45beb97d5b260e80320e233f95c0e302b.tar.bz2
olsndot-19a85ae45beb97d5b260e80320e233f95c0e302b.zip
f0 working (one fixme)
need scan mode upstream?
Diffstat (limited to 'shared')
-rw-r--r--shared/usart_stdio.c34
1 files changed, 34 insertions, 0 deletions
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 <karlp@tweak.net.au>
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <libopencm3/stm32/usart.h>
+
+#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;
+}
+
+