From 017f592eef52dcc602b9f592aad922fb2e3f625a Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 14 Sep 2012 10:58:19 -0700 Subject: [PATCH] AP_HAL: add ConsoleDriver interface --- libraries/AP_HAL/AP_HAL.h | 1 + libraries/AP_HAL/AP_HAL_Namespace.h | 1 + libraries/AP_HAL/Console.h | 16 ++++++++++++++++ libraries/AP_HAL/HAL.h | 5 +++-- libraries/AP_HAL_AVR/AP_HAL_AVR.cpp | 6 ++++-- 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 libraries/AP_HAL/Console.h diff --git a/libraries/AP_HAL/AP_HAL.h b/libraries/AP_HAL/AP_HAL.h index e3349ad09d..c9e9058809 100644 --- a/libraries/AP_HAL/AP_HAL.h +++ b/libraries/AP_HAL/AP_HAL.h @@ -11,6 +11,7 @@ #include "AnalogIn.h" #include "Storage.h" #include "Dataflash.h" +#include "Console.h" #include "GPIO.h" #include "RCInput.h" #include "RCOutput.h" diff --git a/libraries/AP_HAL/AP_HAL_Namespace.h b/libraries/AP_HAL/AP_HAL_Namespace.h index 2d2fdcbed8..1315e5b45c 100644 --- a/libraries/AP_HAL/AP_HAL_Namespace.h +++ b/libraries/AP_HAL/AP_HAL_Namespace.h @@ -17,6 +17,7 @@ namespace AP_HAL { class AnalogIn; class Storage; class Dataflash; + class ConsoleDriver; class GPIO; class RCInput; class RCOutput; diff --git a/libraries/AP_HAL/Console.h b/libraries/AP_HAL/Console.h new file mode 100644 index 0000000000..c0e7095cc5 --- /dev/null +++ b/libraries/AP_HAL/Console.h @@ -0,0 +1,16 @@ + +#ifndef __AP_HAL_CONSOLE_DRIVER_H__ +#define __AP_HAL_CONSOLE_DRIVER_H__ + +#include "AP_HAL_Namespace.h" + +class AP_HAL::ConsoleDriver : public AP_HAL::BetterStream { +public: + virtual void init(void*implspecific) = 0; + virtual void backend_open() = 0; + virtual void backend_close() = 0; + virtual int backend_read(uint8_t *data, int len) = 0; + virtual int backend_write(const uint8_t *data, int len) = 0; +}; + +#endif // __AP_HAL_CONSOLE_DRIVER_H__ diff --git a/libraries/AP_HAL/HAL.h b/libraries/AP_HAL/HAL.h index 2636e85752..e1756697c7 100644 --- a/libraries/AP_HAL/HAL.h +++ b/libraries/AP_HAL/HAL.h @@ -9,6 +9,7 @@ #include "../AP_HAL/AnalogIn.h" #include "../AP_HAL/Storage.h" #include "../AP_HAL/Dataflash.h" +#include "../AP_HAL/Console.h" #include "../AP_HAL/GPIO.h" #include "../AP_HAL/RCInput.h" #include "../AP_HAL/RCOutput.h" @@ -24,7 +25,7 @@ public: AP_HAL::AnalogIn* _analogin, AP_HAL::Storage* _storage, AP_HAL::Dataflash* _dataflash, - AP_HAL::BetterStream* _console, + AP_HAL::ConsoleDriver* _console, AP_HAL::GPIO* _gpio, AP_HAL::RCInput* _rcin, AP_HAL::RCOutput* _rcout, @@ -57,7 +58,7 @@ public: AP_HAL::AnalogIn* analogin; AP_HAL::Storage* storage; AP_HAL::Dataflash* dataflash; - AP_HAL::BetterStream* console; + AP_HAL::ConsoleDriver* console; AP_HAL::GPIO* gpio; AP_HAL::RCInput* rcin; AP_HAL::RCOutput* rcout; diff --git a/libraries/AP_HAL_AVR/AP_HAL_AVR.cpp b/libraries/AP_HAL_AVR/AP_HAL_AVR.cpp index 5234c78693..479bb07d44 100644 --- a/libraries/AP_HAL_AVR/AP_HAL_AVR.cpp +++ b/libraries/AP_HAL_AVR/AP_HAL_AVR.cpp @@ -10,6 +10,7 @@ #include "AnalogIn.h" #include "Storage.h" #include "Dataflash.h" +#include "Console.h" #include "GPIO.h" #include "RCInput.h" #include "RCOutput.h" @@ -34,6 +35,7 @@ static APM2AnalogIn apm2AnalogIn; static AVREEPROMStorage avrEEPROMStorage; static APM1Dataflash apm1Dataflash; static APM2Dataflash apm2Dataflash; +static AVRConsoleDriver consoleDriver; static ArduinoGPIO arduinoGPIO; static APM1RCInput apm1RCInput; static APM2RCInput apm2RCInput; @@ -51,7 +53,7 @@ const HAL_AVR AP_HAL_AVR_APM1( &apm1AnalogIn, &avrEEPROMStorage, &apm1Dataflash, - (BetterStream*) &avrUart0Driver, + &consoleDriver, &arduinoGPIO, &apm1RCInput, &apm1RCOutput, @@ -67,7 +69,7 @@ const HAL_AVR AP_HAL_AVR_APM2( &apm2AnalogIn, &avrEEPROMStorage, &apm2Dataflash, - (BetterStream *) &avrUart0Driver, + &consoleDriver, &arduinoGPIO, &apm2RCInput, &apm2RCOutput,