2013-01-10 19:23:51 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2012-12-30 04:57:39 -04:00
|
|
|
#include <AP_HAL.h>
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
2012-09-14 14:58:55 -03:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
2012-12-19 18:01:26 -04:00
|
|
|
#include "print_vprintf.h"
|
2012-09-14 14:58:55 -03:00
|
|
|
|
|
|
|
#include "Console.h"
|
|
|
|
using namespace AP_HAL_AVR;
|
|
|
|
|
|
|
|
// ConsoleDriver method implementations ///////////////////////////////////////
|
|
|
|
void AVRConsoleDriver::init(void* base_uart) {
|
|
|
|
_base_uart = (AP_HAL::UARTDriver*) base_uart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AVRConsoleDriver::backend_open() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void AVRConsoleDriver::backend_close() {
|
|
|
|
}
|
|
|
|
|
2012-12-06 15:02:28 -04:00
|
|
|
size_t AVRConsoleDriver::backend_read(uint8_t *data, size_t len) {
|
2013-01-10 19:23:51 -04:00
|
|
|
return 0;
|
2012-09-14 14:58:55 -03:00
|
|
|
}
|
|
|
|
|
2012-12-06 15:02:28 -04:00
|
|
|
size_t AVRConsoleDriver::backend_write(const uint8_t *data, size_t len) {
|
2013-01-10 19:23:51 -04:00
|
|
|
return 0;
|
2012-09-14 14:58:55 -03:00
|
|
|
}
|
|
|
|
|
2012-09-14 21:07:28 -03:00
|
|
|
// AVRConsoleDriver private method implementations ////////////////////////////
|
|
|
|
|
2012-09-14 14:58:55 -03:00
|
|
|
// BetterStream method implementations /////////////////////////////////////////
|
|
|
|
void AVRConsoleDriver::print_P(const prog_char_t *s) {
|
2013-01-10 19:23:51 -04:00
|
|
|
_base_uart->print_P(s);
|
2012-09-14 14:58:55 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AVRConsoleDriver::println_P(const prog_char_t *s) {
|
2013-01-10 19:23:51 -04:00
|
|
|
_base_uart->println_P(s);
|
2012-09-14 14:58:55 -03:00
|
|
|
}
|
|
|
|
|
2012-12-19 18:01:26 -04:00
|
|
|
|
2012-09-14 14:58:55 -03:00
|
|
|
void AVRConsoleDriver::printf(const char *fmt, ...) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2012-12-19 18:01:26 -04:00
|
|
|
vprintf(fmt, ap);
|
2012-09-14 14:58:55 -03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AVRConsoleDriver::_printf_P(const prog_char *fmt, ...) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2012-12-19 18:01:26 -04:00
|
|
|
vprintf_P(fmt, ap);
|
2012-09-14 14:58:55 -03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2012-12-19 18:01:26 -04:00
|
|
|
void AVRConsoleDriver::vprintf(const char *fmt, va_list ap){
|
|
|
|
print_vprintf((AP_HAL::Print*)this, 0, fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AVRConsoleDriver::vprintf_P(const prog_char *fmt, va_list ap){
|
|
|
|
print_vprintf((AP_HAL::Print*)this, 1, fmt, ap);
|
|
|
|
}
|
|
|
|
|
2012-09-14 14:58:55 -03:00
|
|
|
// Stream method implementations /////////////////////////////////////////
|
2012-12-06 15:02:28 -04:00
|
|
|
int16_t AVRConsoleDriver::available(void) {
|
2013-01-10 19:23:51 -04:00
|
|
|
return _base_uart->available();
|
2012-09-14 14:58:55 -03:00
|
|
|
}
|
|
|
|
|
2012-12-06 15:02:28 -04:00
|
|
|
int16_t AVRConsoleDriver::txspace(void) {
|
2013-01-10 19:23:51 -04:00
|
|
|
return _base_uart->txspace();
|
2012-09-14 14:58:55 -03:00
|
|
|
}
|
|
|
|
|
2012-12-06 15:02:28 -04:00
|
|
|
int16_t AVRConsoleDriver::read() {
|
2013-01-10 19:23:51 -04:00
|
|
|
return _base_uart->read();
|
2012-09-14 14:58:55 -03:00
|
|
|
}
|
|
|
|
|
2012-09-14 21:07:28 -03:00
|
|
|
// Print method implementations /////////////////////////////////////////
|
|
|
|
|
|
|
|
size_t AVRConsoleDriver::write(uint8_t c) {
|
2013-01-10 19:23:51 -04:00
|
|
|
return _base_uart->write(c);
|
2012-09-14 21:30:39 -03:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:23:51 -04:00
|
|
|
#endif // CONFIG_HAL_BOARD
|
2012-09-14 21:30:39 -03:00
|
|
|
|