mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-04 15:08:28 -04:00
2e464a53c2
The switching between different AP_HAL was happening by giving different definitions of AP_HAL_BOARD_DRIVER, and the programs would use it to instantiate. A program or library code would have to explicitly include (and depend) on the concrete implementation of the HAL, even when using it only via interface. The proposed change move this dependency to be link time. There is a AP_HAL::get_HAL() function that is used by the client code. Each implementation of HAL provides its own definition of this function, returning the appropriate concrete instance. Since this replaces the job of AP_HAL_BOARD_DRIVER, the definition was removed. The static variables for PX4 and VRBRAIN were named differently to avoid shadowing the extern symbol 'hal'.
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
|
|
#include <AP_HAL/AP_HAL.h>
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_EMPTY
|
|
|
|
#include "HAL_Empty_Class.h"
|
|
#include "AP_HAL_Empty_Private.h"
|
|
|
|
using namespace Empty;
|
|
|
|
static EmptyUARTDriver uartADriver;
|
|
static EmptyUARTDriver uartBDriver;
|
|
static EmptyUARTDriver uartCDriver;
|
|
static EmptySemaphore i2cSemaphore;
|
|
static EmptyI2CDriver i2cDriver(&i2cSemaphore);
|
|
static EmptySPIDeviceManager spiDeviceManager;
|
|
static EmptyAnalogIn analogIn;
|
|
static EmptyStorage storageDriver;
|
|
static EmptyGPIO gpioDriver;
|
|
static EmptyRCInput rcinDriver;
|
|
static EmptyRCOutput rcoutDriver;
|
|
static EmptyScheduler schedulerInstance;
|
|
static EmptyUtil utilInstance;
|
|
|
|
HAL_Empty::HAL_Empty() :
|
|
AP_HAL::HAL(
|
|
&uartADriver,
|
|
&uartBDriver,
|
|
&uartCDriver,
|
|
NULL, /* no uartD */
|
|
NULL, /* no uartE */
|
|
&i2cDriver,
|
|
NULL, /* only one i2c */
|
|
NULL, /* only one i2c */
|
|
&spiDeviceManager,
|
|
&analogIn,
|
|
&storageDriver,
|
|
&uartADriver,
|
|
&gpioDriver,
|
|
&rcinDriver,
|
|
&rcoutDriver,
|
|
&schedulerInstance,
|
|
&utilInstance),
|
|
_member(new EmptyPrivateMember(123))
|
|
{}
|
|
|
|
void HAL_Empty::init(int argc,char* const argv[]) const {
|
|
/* initialize all drivers and private members here.
|
|
* up to the programmer to do this in the correct order.
|
|
* Scheduler should likely come first. */
|
|
scheduler->init(NULL);
|
|
uartA->begin(115200);
|
|
_member->init();
|
|
}
|
|
|
|
const AP_HAL::HAL& AP_HAL::get_HAL() {
|
|
static const HAL_Empty hal;
|
|
return hal;
|
|
}
|
|
|
|
#endif
|