-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_port.c
45 lines (35 loc) · 1.15 KB
/
serial_port.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "serial_port.h"
#include "peripherals/uart.h"
/* ************************************************************************** */
EMPTY_UART_INTERFACE(uart);
void serial_port_init(uart_config_t *config) {
uart = UART_init(config); //
}
/* -------------------------------------------------------------------------- */
// Print a single character to the console
// Also needed for compiler provided printf
// this is a horrible workaround for uart.tx_char() being magically broken
// TODO: definitely have to figure out what's happening here
char wtf[2] = {0, 0};
void putch(char data) {
wtf[0] = data;
print(wtf);
// uart.tx_char(data); //
}
// Read a single character from the console
GETCH_RETURN_TYPE getch(void) {
return uart.rx_char(); //
}
// Print a string
void print(const char *string) {
/* Wrap UART_TX_STRING() to provide both a portability layer, and to keep
the user from having to add the termination character every time they
print
*/
uart.tx_string(string, '\0');
}
// Print a string and append a newline
void println(const char *string) {
uart.tx_string(string, '\0');
print("\r\n");
}