mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 05:53:34 +08:00
i2c spi: add type to I2CSPIInstance
Needed to distinguish runtime instance types of the same driver (e.g. bmi055 accel vs gyro).
This commit is contained in:
@@ -59,8 +59,8 @@ enum class I2CSPIBusOption : uint8_t {
|
||||
class I2CSPIInstance
|
||||
{
|
||||
public:
|
||||
I2CSPIInstance(I2CSPIBusOption bus_option, int bus)
|
||||
: _bus_option(bus_option), _bus(bus) {}
|
||||
I2CSPIInstance(I2CSPIBusOption bus_option, int bus, int type)
|
||||
: _bus_option(bus_option), _bus(bus), _type(type) {}
|
||||
|
||||
virtual ~I2CSPIInstance() = default;
|
||||
|
||||
@@ -70,15 +70,20 @@ private:
|
||||
|
||||
const I2CSPIBusOption _bus_option;
|
||||
const int _bus;
|
||||
const int _type; ///< device type (driver-specific)
|
||||
};
|
||||
|
||||
struct BusCLIArguments {
|
||||
I2CSPIBusOption bus_option{I2CSPIBusOption::All};
|
||||
int type{0}; ///< device type (driver-specific)
|
||||
int requested_bus{-1};
|
||||
int chipselect_index{1};
|
||||
Rotation rotation{ROTATION_NONE};
|
||||
int custom1; ///< driver-specific custom argument
|
||||
int custom2; ///< driver-specific custom argument
|
||||
int bus_frequency{0};
|
||||
int spi_mode{-1};
|
||||
int custom1{0}; ///< driver-specific custom argument
|
||||
int custom2{0}; ///< driver-specific custom argument
|
||||
void *custom_data{nullptr}; ///< driver-specific custom argument
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -103,7 +108,7 @@ public:
|
||||
board_bus_types busType() const;
|
||||
int bus() const;
|
||||
uint32_t devid() const;
|
||||
uint32_t DRDYGPIO() const;
|
||||
spi_drdy_gpio_t DRDYGPIO() const;
|
||||
bool external() const;
|
||||
|
||||
static I2CBusIterator::FilterType i2cFilter(I2CSPIBusOption bus_option);
|
||||
@@ -112,6 +117,7 @@ private:
|
||||
I2CSPIInstance **_instances;
|
||||
const int _max_num_instances;
|
||||
const I2CSPIBusOption _bus_option;
|
||||
const int _type;
|
||||
SPIBusIterator _spi_bus_iterator;
|
||||
I2CBusIterator _i2c_bus_iterator;
|
||||
int _current_instance{-1};
|
||||
@@ -124,9 +130,9 @@ private:
|
||||
class I2CSPIDriverBase : public px4::ScheduledWorkItem, public I2CSPIInstance
|
||||
{
|
||||
public:
|
||||
I2CSPIDriverBase(const char *module_name, const px4::wq_config_t &config, I2CSPIBusOption bus_option, int bus)
|
||||
I2CSPIDriverBase(const char *module_name, const px4::wq_config_t &config, I2CSPIBusOption bus_option, int bus, int type)
|
||||
: ScheduledWorkItem(module_name, config),
|
||||
I2CSPIInstance(bus_option, bus) {}
|
||||
I2CSPIInstance(bus_option, bus, type) {}
|
||||
|
||||
static int module_stop(BusInstanceIterator &iterator);
|
||||
static int module_status(BusInstanceIterator &iterator);
|
||||
@@ -178,8 +184,8 @@ public:
|
||||
static I2CSPIInstance **instances() { return _instances; }
|
||||
|
||||
protected:
|
||||
I2CSPIDriver(const char *module_name, const px4::wq_config_t &config, I2CSPIBusOption bus_option, int bus)
|
||||
: I2CSPIDriverBase(module_name, config, bus_option, bus) {}
|
||||
I2CSPIDriver(const char *module_name, const px4::wq_config_t &config, I2CSPIBusOption bus_option, int bus, int type = 0)
|
||||
: I2CSPIDriverBase(module_name, config, bus_option, bus, type) {}
|
||||
|
||||
virtual ~I2CSPIDriver() = default;
|
||||
|
||||
|
||||
@@ -46,10 +46,12 @@
|
||||
//#define PX4_SPI_DEV_ID(devid) ((devid) & 0xffff)
|
||||
#define PX4_SPIDEVID_TYPE(devid) (((uint32_t)(devid) >> 16) & 0xffff)
|
||||
|
||||
typedef uint32_t spi_drdy_gpio_t;
|
||||
|
||||
#define SPI_BUS_MAX_DEVICES 5
|
||||
struct px4_spi_bus_device_t {
|
||||
uint32_t cs_gpio; ///< chip-select GPIO (0 if this device is not used)
|
||||
uint32_t drdy_gpio; ///< data ready GPIO (0 if not set)
|
||||
spi_drdy_gpio_t drdy_gpio; ///< data ready GPIO (0 if not set)
|
||||
uint32_t devid; ///< SPIDEV_ID(type,index). For PX4 devices on NuttX: index is the device type, and for external buses the CS index
|
||||
uint16_t devtype_driver; ///< driver device type, e.g. DRV_IMU_DEVTYPE_ICM20689 (on NuttX: PX4_SPI_DEV_ID(devid) == devtype_driver)
|
||||
};
|
||||
@@ -148,7 +150,7 @@ public:
|
||||
bool next();
|
||||
|
||||
const px4_spi_bus_t &bus() const { return px4_spi_buses[_index]; }
|
||||
uint32_t DRDYGPIO() const { return px4_spi_buses[_index].devices[_bus_device_index].drdy_gpio; }
|
||||
spi_drdy_gpio_t DRDYGPIO() const { return px4_spi_buses[_index].devices[_bus_device_index].drdy_gpio; }
|
||||
|
||||
uint32_t devid() const { return px4_spi_buses[_index].devices[_bus_device_index].devid; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user