AP_HAL_AVR: Refactor APM1 and APM2 instances to use CONFIG_HAL_BOARD
This commit is contained in:
parent
fa02ad7d4c
commit
25e597d3b3
@ -1,73 +0,0 @@
|
|||||||
|
|
||||||
#include <AP_HAL.h>
|
|
||||||
#include "AP_HAL_AVR.h"
|
|
||||||
|
|
||||||
/* Include AVR-specific implementations of the HAL classes */
|
|
||||||
#include "HAL_AVR.h"
|
|
||||||
#include "UARTDriver.h"
|
|
||||||
#include "I2CDriver.h"
|
|
||||||
#include "SPIDriver.h"
|
|
||||||
#include "AnalogIn.h"
|
|
||||||
#include "Storage.h"
|
|
||||||
#include "Console.h"
|
|
||||||
#include "GPIO.h"
|
|
||||||
#include "RCInput.h"
|
|
||||||
#include "RCOutput.h"
|
|
||||||
#include "Scheduler.h"
|
|
||||||
|
|
||||||
using namespace AP_HAL;
|
|
||||||
using namespace AP_HAL_AVR;
|
|
||||||
|
|
||||||
AVRUARTDriverISRs(0);
|
|
||||||
AVRUARTDriverISRs(1);
|
|
||||||
AVRUARTDriverISRs(2);
|
|
||||||
AVRUARTDriverISRs(3);
|
|
||||||
|
|
||||||
static AVRUARTDriverInstance(avrUart0Driver, 0);
|
|
||||||
static AVRUARTDriverInstance(avrUart1Driver, 1);
|
|
||||||
static AVRUARTDriverInstance(avrUart2Driver, 2);
|
|
||||||
static AVRUARTDriverInstance(avrUart3Driver, 3);
|
|
||||||
|
|
||||||
static AVRI2CDriver avrI2CDriver;
|
|
||||||
static APM1SPIDeviceManager apm1SPIDriver;
|
|
||||||
static APM2SPIDeviceManager apm2SPIDriver;
|
|
||||||
static AVRAnalogIn avrAnalogIn;
|
|
||||||
static AVREEPROMStorage avrEEPROMStorage;
|
|
||||||
static AVRConsoleDriver consoleDriver;
|
|
||||||
static AVRGPIO avrGPIO;
|
|
||||||
static APM1RCInput apm1RCInput;
|
|
||||||
static APM2RCInput apm2RCInput;
|
|
||||||
static APM1RCOutput apm1RCOutput;
|
|
||||||
static APM2RCOutput apm2RCOutput;
|
|
||||||
static AVRScheduler avrScheduler;
|
|
||||||
|
|
||||||
/* On APM1 the physical UART2 is used for SPI. */
|
|
||||||
const HAL_AVR AP_HAL_AVR_APM1(
|
|
||||||
(UARTDriver*) &avrUart0Driver, /* phys UART0 -> uartA */
|
|
||||||
(UARTDriver*) &avrUart1Driver, /* phys UART1 -> uartB */
|
|
||||||
(UARTDriver*) &avrUart3Driver, /* phys UART3 -> uartC */
|
|
||||||
&avrI2CDriver,
|
|
||||||
&apm1SPIDriver,
|
|
||||||
&avrAnalogIn,
|
|
||||||
&avrEEPROMStorage,
|
|
||||||
&consoleDriver,
|
|
||||||
&avrGPIO,
|
|
||||||
&apm1RCInput,
|
|
||||||
&apm1RCOutput,
|
|
||||||
&avrScheduler );
|
|
||||||
|
|
||||||
/* On APM1 the physical UART3 is used for SPI. */
|
|
||||||
const HAL_AVR AP_HAL_AVR_APM2(
|
|
||||||
(UARTDriver*) &avrUart0Driver, /* phys UART0 -> uartA */
|
|
||||||
(UARTDriver*) &avrUart1Driver, /* phys UART1 -> uartB */
|
|
||||||
(UARTDriver*) &avrUart2Driver, /* phys UART2 -> uartC */
|
|
||||||
&avrI2CDriver,
|
|
||||||
&apm2SPIDriver,
|
|
||||||
&avrAnalogIn,
|
|
||||||
&avrEEPROMStorage,
|
|
||||||
&consoleDriver,
|
|
||||||
&avrGPIO,
|
|
||||||
&apm2RCInput,
|
|
||||||
&apm2RCOutput,
|
|
||||||
&avrScheduler );
|
|
||||||
|
|
@ -3,7 +3,9 @@
|
|||||||
#define __AP_HAL_AVR_H__
|
#define __AP_HAL_AVR_H__
|
||||||
|
|
||||||
#include <AP_HAL.h>
|
#include <AP_HAL.h>
|
||||||
#include "HAL_AVR.h"
|
|
||||||
|
#include "HAL_AVR_APM1_Class.h"
|
||||||
|
#include "HAL_AVR_APM2_Class.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module exports AP_HAL instances only.
|
* This module exports AP_HAL instances only.
|
||||||
@ -11,9 +13,6 @@
|
|||||||
* and not expose implementation details.
|
* and not expose implementation details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern const AP_HAL_AVR::HAL_AVR AP_HAL_AVR_APM1;
|
|
||||||
extern const AP_HAL_AVR::HAL_AVR AP_HAL_AVR_APM2;
|
|
||||||
|
|
||||||
#define AP_HAL_MAIN() extern "C" {\
|
#define AP_HAL_MAIN() extern "C" {\
|
||||||
int main (void) {\
|
int main (void) {\
|
||||||
hal.init(NULL);\
|
hal.init(NULL);\
|
||||||
|
17
libraries/AP_HAL_AVR/AP_HAL_AVR_private.h
Normal file
17
libraries/AP_HAL_AVR/AP_HAL_AVR_private.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
#ifndef __AP_HAL_AVR_PRIVATE_H__
|
||||||
|
#define __AP_HAL_AVR_PRIVATE_H__
|
||||||
|
|
||||||
|
#include "UARTDriver.h"
|
||||||
|
#include "I2CDriver.h"
|
||||||
|
#include "SPIDriver.h"
|
||||||
|
#include "AnalogIn.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
#include "Console.h"
|
||||||
|
#include "GPIO.h"
|
||||||
|
#include "RCInput.h"
|
||||||
|
#include "RCOutput.h"
|
||||||
|
#include "Scheduler.h"
|
||||||
|
#include "utility/ISRRegistry.h"
|
||||||
|
|
||||||
|
#endif // __AP_HAL_AVR_PRIVATE_H__
|
73
libraries/AP_HAL_AVR/HAL_AVR_APM1_Class.cpp
Normal file
73
libraries/AP_HAL_AVR/HAL_AVR_APM1_Class.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
#include <AP_HAL.h>
|
||||||
|
|
||||||
|
/* To save linker space, we need to make sure the HAL_AVR_APM1 class
|
||||||
|
* is built iff we are building for HAL_BOARD_APM1. These defines must
|
||||||
|
* wrap the whole HAL_AVR_APM1 class declaration and definition. */
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
||||||
|
|
||||||
|
#include <AP_HAL_AVR.h>
|
||||||
|
#include "AP_HAL_AVR_private.h"
|
||||||
|
#include "HAL_AVR_APM1_Class.h"
|
||||||
|
|
||||||
|
using namespace AP_HAL;
|
||||||
|
using namespace AP_HAL_AVR;
|
||||||
|
|
||||||
|
AVRUARTDriverISRs(0);
|
||||||
|
AVRUARTDriverISRs(1);
|
||||||
|
AVRUARTDriverISRs(3);
|
||||||
|
|
||||||
|
AVRUARTDriverInstance(avrUart0Driver, 0);
|
||||||
|
AVRUARTDriverInstance(avrUart1Driver, 1);
|
||||||
|
AVRUARTDriverInstance(avrUart3Driver, 3);
|
||||||
|
|
||||||
|
static AVRI2CDriver avrI2CDriver;
|
||||||
|
static APM1SPIDeviceManager apm1SPIDriver;
|
||||||
|
static AVRAnalogIn avrAnalogIn;
|
||||||
|
static AVREEPROMStorage avrEEPROMStorage;
|
||||||
|
static AVRConsoleDriver consoleDriver;
|
||||||
|
static AVRGPIO avrGPIO;
|
||||||
|
static APM1RCInput apm1RCInput;
|
||||||
|
static APM1RCOutput apm1RCOutput;
|
||||||
|
static AVRScheduler avrScheduler;
|
||||||
|
|
||||||
|
static ISRRegistry isrRegistry;
|
||||||
|
|
||||||
|
/* On APM1 the physical UART2 is used for SPI. */
|
||||||
|
HAL_AVR_APM1::HAL_AVR_APM1() :
|
||||||
|
AP_HAL::HAL(
|
||||||
|
&avrUart0Driver, /* phys UART0 -> uartA */
|
||||||
|
&avrUart1Driver, /* phys UART1 -> uartB */
|
||||||
|
&avrUart3Driver, /* phys UART3 -> uartC */
|
||||||
|
&avrI2CDriver,
|
||||||
|
&apm1SPIDriver,
|
||||||
|
&avrAnalogIn,
|
||||||
|
&avrEEPROMStorage,
|
||||||
|
&consoleDriver,
|
||||||
|
&avrGPIO,
|
||||||
|
&apm1RCInput,
|
||||||
|
&apm1RCOutput,
|
||||||
|
&avrScheduler )
|
||||||
|
{}
|
||||||
|
|
||||||
|
void HAL_AVR_APM1::init(void* opts) const {
|
||||||
|
|
||||||
|
scheduler->init((void*)&isrRegistry);
|
||||||
|
|
||||||
|
/* uartA is the serial port used for the console, so lets make sure
|
||||||
|
* it is initialized at boot */
|
||||||
|
uartA->begin(115200);
|
||||||
|
console->init((void*)uartA);
|
||||||
|
/* The AVR RCInput drivers take an AP_HAL_AVR::ISRRegistry*
|
||||||
|
* as the init argument */
|
||||||
|
rcin->init((void*)&isrRegistry);
|
||||||
|
rcout->init(NULL);
|
||||||
|
spi->init(NULL);
|
||||||
|
i2c->begin();
|
||||||
|
i2c->setTimeout(100);
|
||||||
|
analogin->init(NULL);
|
||||||
|
};
|
||||||
|
|
||||||
|
const HAL_AVR_APM1 AP_HAL_AVR_APM1;
|
||||||
|
|
||||||
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
33
libraries/AP_HAL_AVR/HAL_AVR_APM1_Class.h
Normal file
33
libraries/AP_HAL_AVR/HAL_AVR_APM1_Class.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
#ifndef __AP_HAL_AVR_APM1_HAL_AVR_H__
|
||||||
|
#define __AP_HAL_AVR_APM1_HAL_AVR_H__
|
||||||
|
|
||||||
|
#include <AP_HAL.h>
|
||||||
|
|
||||||
|
/* To save linker space, we need to make sure the HAL_AVR_APM1 class
|
||||||
|
* is built iff we are building for HAL_BOARD_APM1. These defines must
|
||||||
|
* wrap the whole HAL_AVR_APM1 class declaration and definition. */
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
||||||
|
|
||||||
|
#include <AP_HAL_AVR.h>
|
||||||
|
#include "AP_HAL_AVR_Namespace.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HAL_AVR_APM1 class derives from HAL but provides a constructor to use the
|
||||||
|
* correct drivers for the APM1, and an init to set them all up properly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class HAL_AVR_APM1 : public AP_HAL::HAL {
|
||||||
|
public:
|
||||||
|
HAL_AVR_APM1();
|
||||||
|
void init(void* opts) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static instance exported here, defined in the Class.cpp file
|
||||||
|
*/
|
||||||
|
extern const HAL_AVR_APM1 AP_HAL_AVR_APM1;
|
||||||
|
|
||||||
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
||||||
|
#endif // __AP_HAL_AVR_APM1_HAL_AVR_H__
|
||||||
|
|
72
libraries/AP_HAL_AVR/HAL_AVR_APM2_Class.cpp
Normal file
72
libraries/AP_HAL_AVR/HAL_AVR_APM2_Class.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
|
||||||
|
#include <AP_HAL.h>
|
||||||
|
|
||||||
|
/* To save linker space, we need to make sure the HAL_AVR_APM2 class
|
||||||
|
* is built iff we are building for HAL_BOARD_APM2. These defines must
|
||||||
|
* wrap the whole HAL_AVR_APM2 class declaration and definition. */
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
||||||
|
|
||||||
|
#include <AP_HAL_AVR.h>
|
||||||
|
#include "AP_HAL_AVR_private.h"
|
||||||
|
#include "HAL_AVR_APM2_Class.h"
|
||||||
|
|
||||||
|
using namespace AP_HAL;
|
||||||
|
using namespace AP_HAL_AVR;
|
||||||
|
|
||||||
|
AVRUARTDriverISRs(0);
|
||||||
|
AVRUARTDriverISRs(1);
|
||||||
|
AVRUARTDriverISRs(2);
|
||||||
|
|
||||||
|
AVRUARTDriverInstance(avrUart0Driver, 0);
|
||||||
|
AVRUARTDriverInstance(avrUart1Driver, 1);
|
||||||
|
AVRUARTDriverInstance(avrUart2Driver, 2);
|
||||||
|
|
||||||
|
static AVRI2CDriver avrI2CDriver;
|
||||||
|
static APM2SPIDeviceManager apm2SPIDriver;
|
||||||
|
static AVRAnalogIn avrAnalogIn;
|
||||||
|
static AVREEPROMStorage avrEEPROMStorage;
|
||||||
|
static AVRConsoleDriver consoleDriver;
|
||||||
|
static AVRGPIO avrGPIO;
|
||||||
|
static APM2RCInput apm2RCInput;
|
||||||
|
static APM2RCOutput apm2RCOutput;
|
||||||
|
static AVRScheduler avrScheduler;
|
||||||
|
|
||||||
|
static ISRRegistry isrRegistry;
|
||||||
|
|
||||||
|
HAL_AVR_APM2::HAL_AVR_APM2() :
|
||||||
|
AP_HAL::HAL(
|
||||||
|
&avrUart0Driver, /* phys UART0 -> uartA */
|
||||||
|
&avrUart1Driver, /* phys UART1 -> uartB */
|
||||||
|
&avrUart2Driver, /* phys UART2 -> uartC */
|
||||||
|
&avrI2CDriver,
|
||||||
|
&apm2SPIDriver,
|
||||||
|
&avrAnalogIn,
|
||||||
|
&avrEEPROMStorage,
|
||||||
|
&consoleDriver,
|
||||||
|
&avrGPIO,
|
||||||
|
&apm2RCInput,
|
||||||
|
&apm2RCOutput,
|
||||||
|
&avrScheduler )
|
||||||
|
{}
|
||||||
|
|
||||||
|
void HAL_AVR_APM2::init(void* opts) const {
|
||||||
|
|
||||||
|
scheduler->init((void*)&isrRegistry);
|
||||||
|
|
||||||
|
/* uartA is the serial port used for the console, so lets make sure
|
||||||
|
* it is initialized at boot */
|
||||||
|
uartA->begin(115200);
|
||||||
|
console->init((void*)uartA);
|
||||||
|
/* The AVR RCInput drivers take an AP_HAL_AVR::ISRRegistry*
|
||||||
|
* as the init argument */
|
||||||
|
rcin->init((void*)&isrRegistry);
|
||||||
|
rcout->init(NULL);
|
||||||
|
spi->init(NULL);
|
||||||
|
i2c->begin();
|
||||||
|
i2c->setTimeout(100);
|
||||||
|
analogin->init(NULL);
|
||||||
|
};
|
||||||
|
|
||||||
|
const HAL_AVR_APM2 AP_HAL_AVR_APM2;
|
||||||
|
|
||||||
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
33
libraries/AP_HAL_AVR/HAL_AVR_APM2_Class.h
Normal file
33
libraries/AP_HAL_AVR/HAL_AVR_APM2_Class.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
#ifndef __AP_HAL_AVR_APM2_HAL_AVR_H__
|
||||||
|
#define __AP_HAL_AVR_APM2_HAL_AVR_H__
|
||||||
|
|
||||||
|
#include <AP_HAL.h>
|
||||||
|
|
||||||
|
/* To save linker space, we need to make sure the HAL_AVR_APM2 class
|
||||||
|
* is built iff we are building for HAL_BOARD_APM2. These defines must
|
||||||
|
* wrap the whole HAL_AVR_APM2 class declaration and definition. */
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
||||||
|
|
||||||
|
#include <AP_HAL_AVR.h>
|
||||||
|
#include "AP_HAL_AVR_Namespace.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HAL_AVR_APM2 class derives from HAL but provides an AVR-specific
|
||||||
|
* init method.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class HAL_AVR_APM2 : public AP_HAL::HAL {
|
||||||
|
public:
|
||||||
|
HAL_AVR_APM2();
|
||||||
|
void init(void* opts) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static instance exported here, defined in the Class.cpp file
|
||||||
|
*/
|
||||||
|
extern const HAL_AVR_APM2 AP_HAL_AVR_APM2;
|
||||||
|
|
||||||
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
||||||
|
#endif // __AP_HAL_AVR_APM2_HAL_AVR_H__
|
||||||
|
|
@ -1,42 +0,0 @@
|
|||||||
|
|
||||||
#include <AP_Common.h>
|
|
||||||
#include <AP_Progmem.h>
|
|
||||||
#include <AP_HAL.h>
|
|
||||||
#include <AP_HAL_AVR.h>
|
|
||||||
|
|
||||||
const AP_HAL::HAL& hal = AP_HAL_AVR_APM1;
|
|
||||||
|
|
||||||
void loop (void) {
|
|
||||||
hal.console->println(".");
|
|
||||||
hal.gpio->write(3, 0);
|
|
||||||
hal.scheduler->delay(1000);
|
|
||||||
hal.gpio->write(3, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup (void) {
|
|
||||||
hal.gpio->pinMode(1, GPIO_OUTPUT);
|
|
||||||
hal.gpio->pinMode(2, GPIO_OUTPUT);
|
|
||||||
hal.gpio->pinMode(3, GPIO_OUTPUT);
|
|
||||||
hal.gpio->pinMode(13, GPIO_OUTPUT);
|
|
||||||
|
|
||||||
hal.gpio->write(1, 1);
|
|
||||||
hal.gpio->write(2, 1);
|
|
||||||
hal.gpio->write(3, 1);
|
|
||||||
hal.gpio->write(13, 1);
|
|
||||||
|
|
||||||
hal.scheduler->delay(1000);
|
|
||||||
|
|
||||||
hal.gpio->write(1, 0);
|
|
||||||
hal.gpio->write(2, 0);
|
|
||||||
hal.gpio->write(13, 0);
|
|
||||||
|
|
||||||
hal.scheduler->delay(1000);
|
|
||||||
|
|
||||||
hal.gpio->write(13, 1);
|
|
||||||
|
|
||||||
hal.gpio->write(1, 0);
|
|
||||||
hal.console->println("Hello World");
|
|
||||||
hal.gpio->write(2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
AP_HAL_MAIN();
|
|
@ -1 +0,0 @@
|
|||||||
include ../../../AP_Common/Arduino.mk
|
|
@ -1,10 +1,17 @@
|
|||||||
|
|
||||||
#include <AP_Common.h>
|
#include <AP_Common.h>
|
||||||
|
#include <AP_Math.h>
|
||||||
|
#include <AP_Param.h>
|
||||||
#include <AP_Progmem.h>
|
#include <AP_Progmem.h>
|
||||||
|
|
||||||
#include <AP_HAL.h>
|
#include <AP_HAL.h>
|
||||||
#include <AP_HAL_AVR.h>
|
#include <AP_HAL_AVR.h>
|
||||||
|
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
||||||
const AP_HAL::HAL& hal = AP_HAL_AVR_APM1;
|
const AP_HAL::HAL& hal = AP_HAL_AVR_APM1;
|
||||||
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
||||||
|
const AP_HAL::HAL& hal = AP_HAL_AVR_APM2;
|
||||||
|
#endif
|
||||||
|
|
||||||
AP_HAL::DigitalSource *a_led;
|
AP_HAL::DigitalSource *a_led;
|
||||||
AP_HAL::DigitalSource *b_led;
|
AP_HAL::DigitalSource *b_led;
|
||||||
|
Loading…
Reference in New Issue
Block a user