summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-09-02 19:26:31 +0200
committerChristian Pointner <equinox@spreadspace.org>2017-09-02 19:26:31 +0200
commit52a42de2c34f9eb0dd8cd81bad755db6c4857537 (patch)
tree31da5b3dc92b7df2cd37f86c85207700698b81dc /lib
parentfix programmer and led pin for stm8blue (diff)
serial-led example works now tooHEADmaster
Diffstat (limited to 'lib')
-rw-r--r--lib/serialio.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/serialio.c b/lib/serialio.c
index 899ca3e..eec6193 100644
--- a/lib/serialio.c
+++ b/lib/serialio.c
@@ -24,18 +24,38 @@
#include "serialio.h"
+
void putchar(char c) {
+#if defined(SERIAL_IO_UART1)
+ while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
+ UART1_SendData8(c);
+#elif defined(SERIAL_IO_UART2)
while (UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET);
UART2_SendData8(c);
+#else
+ #error "serial-io library is not usable for this board"
+#endif
}
char getchar(void) {
+#if defined(SERIAL_IO_UART1)
+ return UART1_ReceiveData8();
+#elif defined(SERIAL_IO_UART2)
return UART2_ReceiveData8();
+#else
+ #error "serial-io library is not usable for this board"
+#endif
}
void serialio_init(const uint32_t baudrate)
{
+#if defined(SERIAL_IO_UART1)
+ UART1_Init(baudrate, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
+#elif defined(SERIAL_IO_UART2)
UART2_Init(baudrate, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE);
+#else
+ #error "serial-io library is not usable for this board"
+#endif
}
void serialio_task(void)
@@ -44,5 +64,11 @@ void serialio_task(void)
uint8_t serialio_bytes_received(void)
{
+#if defined(SERIAL_IO_UART1)
+ return (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET) ? 0 : 1;
+#elif defined(SERIAL_IO_UART2)
return (UART2_GetFlagStatus(UART2_FLAG_RXNE) == RESET) ? 0 : 1;
+#else
+ #error "serial-io library is not usable for this board"
+#endif
}