From 2d363e0683534ae3de444cb8fbf7b61adbfa1c66 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 26 Oct 2012 22:18:51 -0700 Subject: [PATCH] AP_HAL_PX4: trivial console header --- libraries/AP_HAL_PX4/AP_HAL_PX4.cpp | 26 +++++++++++++ libraries/AP_HAL_PX4/AP_HAL_PX4.h | 17 ++++++++ libraries/AP_HAL_PX4/AP_HAL_PX4_Namespace.h | 12 ++++++ libraries/AP_HAL_PX4/Console.h | 35 +++++++++++++++++ libraries/AP_HAL_PX4/HAL_PX4.cpp | 9 +++++ libraries/AP_HAL_PX4/HAL_PX4.h | 39 +++++++++++++++++++ .../AP_HAL_PX4/examples/simple/Arduino.h | 0 libraries/AP_HAL_PX4/examples/simple/Makefile | 1 + .../AP_HAL_PX4/examples/simple/nocore.inoflag | 0 .../AP_HAL_PX4/examples/simple/simple.pde | 25 ++++++++++++ 10 files changed, 164 insertions(+) create mode 100644 libraries/AP_HAL_PX4/AP_HAL_PX4.cpp create mode 100644 libraries/AP_HAL_PX4/AP_HAL_PX4.h create mode 100644 libraries/AP_HAL_PX4/AP_HAL_PX4_Namespace.h create mode 100644 libraries/AP_HAL_PX4/Console.h create mode 100644 libraries/AP_HAL_PX4/HAL_PX4.cpp create mode 100644 libraries/AP_HAL_PX4/HAL_PX4.h create mode 100644 libraries/AP_HAL_PX4/examples/simple/Arduino.h create mode 100644 libraries/AP_HAL_PX4/examples/simple/Makefile create mode 100644 libraries/AP_HAL_PX4/examples/simple/nocore.inoflag create mode 100644 libraries/AP_HAL_PX4/examples/simple/simple.pde diff --git a/libraries/AP_HAL_PX4/AP_HAL_PX4.cpp b/libraries/AP_HAL_PX4/AP_HAL_PX4.cpp new file mode 100644 index 0000000000..d963729236 --- /dev/null +++ b/libraries/AP_HAL_PX4/AP_HAL_PX4.cpp @@ -0,0 +1,26 @@ + +#include +#include "AP_HAL_PX4.h" + +#include "HAL_PX4.h" +#include "UARTDriver.h" + +using namespace AP_HAL; +using namespace AP_HAL_PX4; + + +const HAL_PX4 AP_HAL_PX4_Instance( + (UARTDriver*) NULL, + (UARTDriver*) NULL, + (UARTDriver*) NULL, + (UARTDriver*) NULL, + (I2CDriver*) NULL, + (SPIDriver*) NULL, + (AnalogIn*) NULL, + (Storage*) NULL, + (Dataflash*) NULL, + (ConsoleDriver*) NULL, + (GPIO*) NULL, + (RCInput*) NULL, + (RCOutput*) NULL, + (Scheduler*) NULL); diff --git a/libraries/AP_HAL_PX4/AP_HAL_PX4.h b/libraries/AP_HAL_PX4/AP_HAL_PX4.h new file mode 100644 index 0000000000..a556faaa73 --- /dev/null +++ b/libraries/AP_HAL_PX4/AP_HAL_PX4.h @@ -0,0 +1,17 @@ + +#ifndef __AP_HAL_PX4_H__ +#define __AP_HAL_PX4_H__ + +#include +#include "HAL_PX4.h" + +/** + * This module exports AP_HAL instances only. + * All internal drivers must conform to AP_HAL interfaces + * and not expose implementation details. + */ + +extern const AP_HAL_PX4::HAL_PX4 AP_HAL_PX4_Instance; + +#endif // __AP_HAL_PX4_H__ + diff --git a/libraries/AP_HAL_PX4/AP_HAL_PX4_Namespace.h b/libraries/AP_HAL_PX4/AP_HAL_PX4_Namespace.h new file mode 100644 index 0000000000..b8ccab3720 --- /dev/null +++ b/libraries/AP_HAL_PX4/AP_HAL_PX4_Namespace.h @@ -0,0 +1,12 @@ + +#ifndef __AP_HAL_PX4_NAMESPACE_H__ +#define __AP_HAL_PX4_NAMESPACE_H__ + +namespace AP_HAL_PX4 { + class HAL_PX4; + + class PX4ConsoleDriver; +} + +#endif //__AP_HAL_PX4_NAMESPACE_H__ + diff --git a/libraries/AP_HAL_PX4/Console.h b/libraries/AP_HAL_PX4/Console.h new file mode 100644 index 0000000000..3370638362 --- /dev/null +++ b/libraries/AP_HAL_PX4/Console.h @@ -0,0 +1,35 @@ + +#ifndef __AP_HAL_PX4_CONSOLE_DRIVER_H__ +#define __AP_HAL_PX4_CONSOLE_DRIVER_H__ + +#include +#include + +class AP_HAL_PX4::PX4ConsoleDriver : public AP_HAL::ConsoleDriver { + PX4ConsoleDriver(); + void init(void*); + void backend_open(); + void backend_close(); + int backend_read(uint8_t *data, int len); + int backend_write(const uint8_t *data, int len); + + /* Implementations of BetterStream virtual methods */ + void print_P(const prog_char_t *s); + void println_P(const prog_char_t *s); + void printf(const char *s, ...) + __attribute__ ((format(__printf__, 2, 3))); + void _printf_P(const prog_char *s, ...) + __attribute__ ((format(__printf__, 2, 3))); + + /* Implementations of Stream virtual methods */ + int available(); + int txspace(); + int read(); + int peek(); + + /* Implementations of Print virtual methods */ + size_t write(uint8_t c); + +}; + +#endif // __AP_HAL_PX4_CONSOLE_DRIVER_H__ diff --git a/libraries/AP_HAL_PX4/HAL_PX4.cpp b/libraries/AP_HAL_PX4/HAL_PX4.cpp new file mode 100644 index 0000000000..fdbe443625 --- /dev/null +++ b/libraries/AP_HAL_PX4/HAL_PX4.cpp @@ -0,0 +1,9 @@ + +#include "HAL_PX4.h" +using namespace AP_HAL_PX4; + +void HAL_PX4::init(void* opts) const { + + console->init(NULL); +}; + diff --git a/libraries/AP_HAL_PX4/HAL_PX4.h b/libraries/AP_HAL_PX4/HAL_PX4.h new file mode 100644 index 0000000000..0097c51113 --- /dev/null +++ b/libraries/AP_HAL_PX4/HAL_PX4.h @@ -0,0 +1,39 @@ + + +#ifndef __AP_HAL_PX4_HAL_PX4_H__ +#define __AP_HAL_PX4_HAL_PX4_H__ + +#include +#include "AP_HAL_PX4_Namespace.h" + +/** + * HAL_PX4 class derives from HAL but provides an PX4-specific + * init method. + */ + +class AP_HAL_PX4::HAL_PX4 : public AP_HAL::HAL { +public: + HAL_PX4( + AP_HAL::UARTDriver* _uart0, + AP_HAL::UARTDriver* _uart1, + AP_HAL::UARTDriver* _uart2, + AP_HAL::UARTDriver* _uart3, + AP_HAL::I2CDriver* _i2c, + AP_HAL::SPIDriver* _spi, + AP_HAL::AnalogIn* _analogin, + AP_HAL::Storage* _storage, + AP_HAL::Dataflash* _dataflash, + AP_HAL::ConsoleDriver* _console, + AP_HAL::GPIO* _gpio, + AP_HAL::RCInput* _rcin, + AP_HAL::RCOutput* _rcout, + AP_HAL::Scheduler* _scheduler) + : AP_HAL::HAL( _uart0, _uart1, _uart2, _uart3, + _i2c, _spi, _analogin, _storage, + _dataflash, _console, _gpio, _rcin, + _rcout, _scheduler) {} + + void init(void* opts) const; +}; +#endif // __AP_HAL_PX4_HAL_PX4_H__ + diff --git a/libraries/AP_HAL_PX4/examples/simple/Arduino.h b/libraries/AP_HAL_PX4/examples/simple/Arduino.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libraries/AP_HAL_PX4/examples/simple/Makefile b/libraries/AP_HAL_PX4/examples/simple/Makefile new file mode 100644 index 0000000000..d1f40fd90f --- /dev/null +++ b/libraries/AP_HAL_PX4/examples/simple/Makefile @@ -0,0 +1 @@ +include ../../../AP_Common/Arduino.mk diff --git a/libraries/AP_HAL_PX4/examples/simple/nocore.inoflag b/libraries/AP_HAL_PX4/examples/simple/nocore.inoflag new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libraries/AP_HAL_PX4/examples/simple/simple.pde b/libraries/AP_HAL_PX4/examples/simple/simple.pde new file mode 100644 index 0000000000..5e3147b024 --- /dev/null +++ b/libraries/AP_HAL_PX4/examples/simple/simple.pde @@ -0,0 +1,25 @@ + +#include +#include +#include +#include + +const AP_HAL::HAL& hal = AP_HAL_PX4_Instance; + +void loop (void) { + hal.console->println("."); +} + +void setup (void) { + hal.console->println("Hello World"); +} + + +extern "C" { +int main (void) { + hal.init(NULL); + setup(); + for(;;) loop(); + return 0; +} +}