2018-03-26 21:46:12 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
|
2021-01-02 18:40:07 +01:00
|
|
|
* 2021 Gerson Fernando Budke <nandojve@gmail.com>
|
2018-03-26 21:46:12 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
2021-01-02 18:40:07 +01:00
|
|
|
* @brief Implements common avr8 libc stdio initialization
|
2018-03-26 21:46:12 +02:00
|
|
|
*
|
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2021-01-02 18:40:07 +01:00
|
|
|
* @author Gerson Fernando Budke <nandojve@gmail.com>
|
2018-03-26 21:46:12 +02:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
2018-07-05 14:09:08 +02:00
|
|
|
#include "stdio_uart.h"
|
2018-03-26 21:46:12 +02:00
|
|
|
|
|
|
|
static int _uart_putchar(char c, FILE *stream);
|
|
|
|
static int _uart_getchar(FILE *stream);
|
|
|
|
static FILE _uart_stdout = FDEV_SETUP_STREAM(_uart_putchar, NULL, _FDEV_SETUP_WRITE);
|
|
|
|
static FILE _uart_stdin = FDEV_SETUP_STREAM(NULL, _uart_getchar, _FDEV_SETUP_READ);
|
|
|
|
|
|
|
|
static int _uart_putchar(char c, FILE *stream)
|
|
|
|
{
|
|
|
|
(void) stream;
|
2018-07-05 14:09:08 +02:00
|
|
|
stdio_write(&c, 1);
|
2018-03-26 21:46:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _uart_getchar(FILE *stream)
|
|
|
|
{
|
|
|
|
(void) stream;
|
|
|
|
char c;
|
2018-07-05 14:09:08 +02:00
|
|
|
stdio_read(&c, 1);
|
2018-03-26 21:46:12 +02:00
|
|
|
return (int)c;
|
|
|
|
}
|
|
|
|
|
2021-01-02 18:40:07 +01:00
|
|
|
void avr8_stdio_init(void)
|
2018-03-26 21:46:12 +02:00
|
|
|
{
|
2018-07-05 14:09:08 +02:00
|
|
|
stdio_init();
|
2018-03-26 21:46:12 +02:00
|
|
|
|
|
|
|
stdout = &_uart_stdout;
|
|
|
|
stdin = &_uart_stdin;
|
|
|
|
|
|
|
|
/* Flush stdout */
|
|
|
|
puts("\f");
|
|
|
|
}
|