synth/uart/uart.c

30 lines
562 B
C
Raw Permalink Normal View History

2021-02-17 21:20:30 +00:00
#include "uart.h"
2021-03-13 23:49:28 +00:00
int uart_rx_available(struct uart* uart) {
return uart->flags & UART_STATUS_RXNE_msk != 0;
2021-02-17 21:20:30 +00:00
}
2021-03-13 23:49:28 +00:00
int uart_tx_available(struct uart* uart) {
return uart->flags & UART_STATUS_TXE_msk != 0;
2021-02-17 21:20:30 +00:00
}
2021-03-13 23:49:28 +00:00
void uart_write(struct uart* uart, const char c) {
while (!uart_tx_available(uart)) {
2021-02-17 21:20:30 +00:00
}
2021-03-13 23:49:28 +00:00
uart->data = c;
2021-02-17 21:20:30 +00:00
}
2021-03-13 23:49:28 +00:00
char uart_read(struct uart* uart) {
while (!uart_rx_available(uart)) {
2021-02-17 21:20:30 +00:00
}
2021-03-13 23:49:28 +00:00
return uart->data;
2021-02-17 21:20:30 +00:00
}
2021-03-14 19:17:48 +00:00
void uart_writen(struct uart* uart, const char* data, int len) {
for (int i = 0; i < len; ++i) {
uart_write(uart, data[i]);
}
}