5
0
mirror of https://github.com/ArduPilot/ardupilot synced 2025-01-05 23:48:31 -04:00

AP_OpticalFlow: support SP01 board

This commit is contained in:
Andrew Tridgell 2018-02-14 16:41:37 +11:00
parent 4d0c3b6581
commit ead72214ac
3 changed files with 12 additions and 8 deletions

View File

@ -80,17 +80,17 @@ extern const AP_HAL::HAL& hal;
#define PIXART_SROM_CRC_RESULT 0xBEEF
// constructor
AP_OpticalFlow_Pixart::AP_OpticalFlow_Pixart(OpticalFlow &_frontend) :
AP_OpticalFlow_Pixart::AP_OpticalFlow_Pixart(const char *devname, OpticalFlow &_frontend) :
OpticalFlow_backend(_frontend)
{
_dev = std::move(hal.spi->get_device("pixartflow"));
_dev = std::move(hal.spi->get_device(devname));
}
// detect the device
AP_OpticalFlow_Pixart *AP_OpticalFlow_Pixart::detect(OpticalFlow &_frontend)
AP_OpticalFlow_Pixart *AP_OpticalFlow_Pixart::detect(const char *devname, OpticalFlow &_frontend)
{
AP_OpticalFlow_Pixart *sensor = new AP_OpticalFlow_Pixart(_frontend);
AP_OpticalFlow_Pixart *sensor = new AP_OpticalFlow_Pixart(devname, _frontend);
if (!sensor) {
return nullptr;
}

View File

@ -7,7 +7,7 @@ class AP_OpticalFlow_Pixart : public OpticalFlow_backend
{
public:
/// constructor
AP_OpticalFlow_Pixart(OpticalFlow &_frontend);
AP_OpticalFlow_Pixart(const char *devname, OpticalFlow &_frontend);
// init - initialise the sensor
void init() override {}
@ -16,7 +16,7 @@ public:
void update(void) override;
// detect if the sensor is available
static AP_OpticalFlow_Pixart *detect(OpticalFlow &_frontend);
static AP_OpticalFlow_Pixart *detect(const char *devname, OpticalFlow &_frontend);
private:
AP_HAL::OwnPtr<AP_HAL::SPIDevice> _dev;

View File

@ -91,9 +91,13 @@ void OpticalFlow::init(void)
if (!backend) {
#if AP_FEATURE_BOARD_DETECT
if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PIXHAWK ||
AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PIXHAWK2 ||
AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PCNC1) {
// possibly have pixhart on external SPI
backend = AP_OpticalFlow_Pixart::detect(*this);
backend = AP_OpticalFlow_Pixart::detect("pixartflow", *this);
}
if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_SP01) {
backend = AP_OpticalFlow_Pixart::detect("pixartPC15", *this);
}
if (backend == nullptr) {
backend = AP_OpticalFlow_PX4Flow::detect(*this);
@ -106,7 +110,7 @@ void OpticalFlow::init(void)
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
backend = AP_OpticalFlow_PX4Flow::detect(*this);
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412
backend = AP_OpticalFlow_Pixart::detect(*this);
backend = AP_OpticalFlow_Pixart::detect("pixartflow", *this);
#endif
}