Browse Source

AP_HAL_PX4: trivial console header

master
Pat Hickey 12 years ago committed by Andrew Tridgell
parent
commit
2d363e0683
  1. 26
      libraries/AP_HAL_PX4/AP_HAL_PX4.cpp
  2. 17
      libraries/AP_HAL_PX4/AP_HAL_PX4.h
  3. 12
      libraries/AP_HAL_PX4/AP_HAL_PX4_Namespace.h
  4. 35
      libraries/AP_HAL_PX4/Console.h
  5. 9
      libraries/AP_HAL_PX4/HAL_PX4.cpp
  6. 39
      libraries/AP_HAL_PX4/HAL_PX4.h
  7. 0
      libraries/AP_HAL_PX4/examples/simple/Arduino.h
  8. 1
      libraries/AP_HAL_PX4/examples/simple/Makefile
  9. 0
      libraries/AP_HAL_PX4/examples/simple/nocore.inoflag
  10. 25
      libraries/AP_HAL_PX4/examples/simple/simple.pde

26
libraries/AP_HAL_PX4/AP_HAL_PX4.cpp

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
#include <AP_HAL.h>
#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);

17
libraries/AP_HAL_PX4/AP_HAL_PX4.h

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
#ifndef __AP_HAL_PX4_H__
#define __AP_HAL_PX4_H__
#include <AP_HAL.h>
#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__

12
libraries/AP_HAL_PX4/AP_HAL_PX4_Namespace.h

@ -0,0 +1,12 @@ @@ -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__

35
libraries/AP_HAL_PX4/Console.h

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
#ifndef __AP_HAL_PX4_CONSOLE_DRIVER_H__
#define __AP_HAL_PX4_CONSOLE_DRIVER_H__
#include <AP_HAL.h>
#include <AP_HAL_PX4_Namespace.h>
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__

9
libraries/AP_HAL_PX4/HAL_PX4.cpp

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
#include "HAL_PX4.h"
using namespace AP_HAL_PX4;
void HAL_PX4::init(void* opts) const {
console->init(NULL);
};

39
libraries/AP_HAL_PX4/HAL_PX4.h

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
#ifndef __AP_HAL_PX4_HAL_PX4_H__
#define __AP_HAL_PX4_HAL_PX4_H__
#include <AP_HAL.h>
#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__

0
libraries/AP_HAL_PX4/examples/simple/Arduino.h

1
libraries/AP_HAL_PX4/examples/simple/Makefile

@ -0,0 +1 @@ @@ -0,0 +1 @@
include ../../../AP_Common/Arduino.mk

0
libraries/AP_HAL_PX4/examples/simple/nocore.inoflag

25
libraries/AP_HAL_PX4/examples/simple/simple.pde

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
#include <AP_Common.h>
#include <AP_Progmem.h>
#include <AP_HAL.h>
#include <AP_HAL_PX4.h>
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;
}
}
Loading…
Cancel
Save