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 #define PIXART_SROM_CRC_RESULT 0xBEEF
// constructor // constructor
AP_OpticalFlow_Pixart::AP_OpticalFlow_Pixart(OpticalFlow &_frontend) : AP_OpticalFlow_Pixart::AP_OpticalFlow_Pixart(const char *devname, OpticalFlow &_frontend) :
OpticalFlow_backend(_frontend) OpticalFlow_backend(_frontend)
{ {
_dev = std::move(hal.spi->get_device("pixartflow")); _dev = std::move(hal.spi->get_device(devname));
} }
// detect the device // 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) { if (!sensor) {
return nullptr; return nullptr;
} }

View File

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

View File

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