2012-12-11 15:24:27 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2012-12-11 15:24:27 -04:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_HAL_AVR.h"
|
2012-12-11 15:24:27 -04:00
|
|
|
#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);
|
|
|
|
|
2013-01-04 20:19:38 -04:00
|
|
|
static AVRSemaphore i2cSemaphore;
|
|
|
|
static AVRI2CDriver avrI2CDriver(&i2cSemaphore);
|
2012-12-11 15:24:27 -04:00
|
|
|
static APM2SPIDeviceManager apm2SPIDriver;
|
|
|
|
static AVRAnalogIn avrAnalogIn;
|
|
|
|
static AVREEPROMStorage avrEEPROMStorage;
|
|
|
|
static AVRGPIO avrGPIO;
|
|
|
|
static APM2RCInput apm2RCInput;
|
|
|
|
static APM2RCOutput apm2RCOutput;
|
|
|
|
static AVRScheduler avrScheduler;
|
2012-12-18 20:09:40 -04:00
|
|
|
static AVRUtil avrUtil;
|
2012-12-11 15:24:27 -04:00
|
|
|
|
|
|
|
static ISRRegistry isrRegistry;
|
|
|
|
|
|
|
|
HAL_AVR_APM2::HAL_AVR_APM2() :
|
|
|
|
AP_HAL::HAL(
|
|
|
|
&avrUart0Driver, /* phys UART0 -> uartA */
|
|
|
|
&avrUart1Driver, /* phys UART1 -> uartB */
|
|
|
|
&avrUart2Driver, /* phys UART2 -> uartC */
|
2013-11-22 04:15:53 -04:00
|
|
|
NULL, /* no uartD */
|
2013-12-21 07:25:59 -04:00
|
|
|
NULL, /* no uartE */
|
2012-12-11 15:24:27 -04:00
|
|
|
&avrI2CDriver,
|
2015-06-15 14:46:31 -03:00
|
|
|
NULL, /* only one i2c */
|
|
|
|
NULL, /* only one i2c */
|
2012-12-11 15:24:27 -04:00
|
|
|
&apm2SPIDriver,
|
|
|
|
&avrAnalogIn,
|
|
|
|
&avrEEPROMStorage,
|
2013-10-05 05:32:12 -03:00
|
|
|
&avrUart0Driver,
|
2012-12-11 15:24:27 -04:00
|
|
|
&avrGPIO,
|
|
|
|
&apm2RCInput,
|
|
|
|
&apm2RCOutput,
|
2012-12-18 20:09:40 -04:00
|
|
|
&avrScheduler,
|
|
|
|
&avrUtil )
|
2012-12-11 15:24:27 -04:00
|
|
|
{}
|
|
|
|
|
2012-12-13 18:56:26 -04:00
|
|
|
void HAL_AVR_APM2::init(int argc, char * const argv[]) const {
|
2012-12-11 15:24:27 -04:00
|
|
|
|
|
|
|
scheduler->init((void*)&isrRegistry);
|
|
|
|
|
|
|
|
/* uartA is the serial port used for the console, so lets make sure
|
|
|
|
* it is initialized at boot */
|
2013-01-10 20:16:09 -04:00
|
|
|
uartA->begin(115200, 128, 128);
|
2012-12-11 15:24:27 -04:00
|
|
|
/* 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);
|
2013-01-06 01:00:54 -04:00
|
|
|
|
|
|
|
/* Enable the pullups on the RX pins of the 3 UARTs This is important when
|
|
|
|
* the RX line is high-Z: capacitive coupling between input and output pins
|
|
|
|
* can cause bytes written to show up as an input. Occasionally this causes
|
|
|
|
* us to detect a phantom GPS by seeing our own outgoing config message.
|
|
|
|
* PE0 : RX0 (uartA)
|
|
|
|
* PD2 : RX1 (uartB)
|
|
|
|
* PH0 : RX2 (uartC)
|
|
|
|
*/
|
|
|
|
|
|
|
|
PORTE |= _BV(0);
|
|
|
|
PORTD |= _BV(2);
|
|
|
|
PORTH |= _BV(0);
|
2012-12-11 15:24:27 -04:00
|
|
|
};
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& AP_HAL::get_HAL() {
|
|
|
|
static const HAL_AVR_APM2 hal;
|
|
|
|
return hal;
|
|
|
|
}
|
2012-12-11 15:24:27 -04:00
|
|
|
|
|
|
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_APM2
|