Skip to content

Instantly share code, notes, and snippets.

@dagon666
Created October 8, 2013 20:41
Show Gist options
  • Save dagon666/6891271 to your computer and use it in GitHub Desktop.
Save dagon666/6891271 to your computer and use it in GitHub Desktop.
serial_stdio
void _serial_putc(char c, FILE *stream) {
if ('\n' == c) {
_serial_putc('\r', stream);
}
while (!serial_sendc(c));
}
char _serial_getc(FILE *stream) {
unsigned char c = 0x00;
while (!serial_getc(&c));
return (char)c;
}
void serial_install_stdio() {
static FILE uart_stdout = FDEV_SETUP_STREAM(_serial_putc, NULL, _FDEV_SETUP_WRITE);
static FILE uart_stdin = FDEV_SETUP_STREAM(NULL, _serial_getc, _FDEV_SETUP_READ);
stdout = &uart_stdout;
stdin = &uart_stdin;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment