forked from Archive/PX4-Autopilot
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:
parent
b70289c536
commit
f851f65f8d
|
@ -15,7 +15,8 @@ class ModuleDocumentation(object):
|
||||||
# TOC in https://github.com/PX4/Devguide/blob/master/en/SUMMARY.md
|
# TOC in https://github.com/PX4/Devguide/blob/master/en/SUMMARY.md
|
||||||
valid_categories = ['driver', 'estimator', 'controller', 'system',
|
valid_categories = ['driver', 'estimator', 'controller', 'system',
|
||||||
'communication', 'command', 'template', 'simulation']
|
'communication', 'command', 'template', 'simulation']
|
||||||
valid_subcategories = ['', 'distance_sensor']
|
valid_subcategories = ['', 'distance_sensor', 'imu', 'airspeed_sensor',
|
||||||
|
'magnetometer', 'baro']
|
||||||
|
|
||||||
max_line_length = 80 # wrap lines that are longer than this
|
max_line_length = 80 # wrap lines that are longer than this
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
BusInstanceIterator::BusInstanceIterator(I2CSPIInstance **instances, int max_num_instances,
|
BusInstanceIterator::BusInstanceIterator(I2CSPIInstance **instances, int max_num_instances,
|
||||||
const BusCLIArguments &cli_arguments, uint16_t devid_driver_index)
|
const BusCLIArguments &cli_arguments, uint16_t devid_driver_index)
|
||||||
: _instances(instances), _max_num_instances(max_num_instances),
|
: _instances(instances), _max_num_instances(max_num_instances),
|
||||||
_bus_option(cli_arguments.bus_option),
|
_bus_option(cli_arguments.bus_option), _type(cli_arguments.type),
|
||||||
_spi_bus_iterator(spiFilter(cli_arguments.bus_option),
|
_spi_bus_iterator(spiFilter(cli_arguments.bus_option),
|
||||||
cli_arguments.bus_option == I2CSPIBusOption::SPIExternal ? cli_arguments.chipselect_index : devid_driver_index,
|
cli_arguments.bus_option == I2CSPIBusOption::SPIExternal ? cli_arguments.chipselect_index : devid_driver_index,
|
||||||
cli_arguments.requested_bus),
|
cli_arguments.requested_bus),
|
||||||
|
@ -58,7 +58,8 @@ bool BusInstanceIterator::next()
|
||||||
int bus = -1;
|
int bus = -1;
|
||||||
|
|
||||||
if (busType() == BOARD_INVALID_BUS) {
|
if (busType() == BOARD_INVALID_BUS) {
|
||||||
while (++_current_instance < _max_num_instances && _instances[_current_instance] == nullptr) {}
|
while (++_current_instance < _max_num_instances && (_instances[_current_instance] == nullptr
|
||||||
|
|| _type != _instances[_current_instance]->_type)) {}
|
||||||
|
|
||||||
return _current_instance < _max_num_instances;
|
return _current_instance < _max_num_instances;
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ bool BusInstanceIterator::next()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_bus_option == _instances[i]->_bus_option && bus == _instances[i]->_bus) {
|
if (_bus_option == _instances[i]->_bus_option && bus == _instances[i]->_bus && _type == _instances[i]->_type) {
|
||||||
_current_instance = i;
|
_current_instance = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +165,7 @@ uint32_t BusInstanceIterator::devid() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BusInstanceIterator::DRDYGPIO() const
|
spi_drdy_gpio_t BusInstanceIterator::DRDYGPIO() const
|
||||||
{
|
{
|
||||||
if (busType() == BOARD_INVALID_BUS) {
|
if (busType() == BOARD_INVALID_BUS) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -233,7 +234,8 @@ int I2CSPIDriverBase::module_start(const BusCLIArguments &cli, BusInstanceIterat
|
||||||
|
|
||||||
while (iterator.next()) {
|
while (iterator.next()) {
|
||||||
if (iterator.instance()) {
|
if (iterator.instance()) {
|
||||||
continue; // already running
|
PX4_WARN("Already running on bus %i", iterator.bus());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int free_index = iterator.nextFreeInstance();
|
const int free_index = iterator.nextFreeInstance();
|
||||||
|
|
|
@ -59,8 +59,8 @@ enum class I2CSPIBusOption : uint8_t {
|
||||||
class I2CSPIInstance
|
class I2CSPIInstance
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
I2CSPIInstance(I2CSPIBusOption bus_option, int bus)
|
I2CSPIInstance(I2CSPIBusOption bus_option, int bus, int type)
|
||||||
: _bus_option(bus_option), _bus(bus) {}
|
: _bus_option(bus_option), _bus(bus), _type(type) {}
|
||||||
|
|
||||||
virtual ~I2CSPIInstance() = default;
|
virtual ~I2CSPIInstance() = default;
|
||||||
|
|
||||||
|
@ -70,15 +70,20 @@ private:
|
||||||
|
|
||||||
const I2CSPIBusOption _bus_option;
|
const I2CSPIBusOption _bus_option;
|
||||||
const int _bus;
|
const int _bus;
|
||||||
|
const int _type; ///< device type (driver-specific)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BusCLIArguments {
|
struct BusCLIArguments {
|
||||||
I2CSPIBusOption bus_option{I2CSPIBusOption::All};
|
I2CSPIBusOption bus_option{I2CSPIBusOption::All};
|
||||||
|
int type{0}; ///< device type (driver-specific)
|
||||||
int requested_bus{-1};
|
int requested_bus{-1};
|
||||||
int chipselect_index{1};
|
int chipselect_index{1};
|
||||||
Rotation rotation{ROTATION_NONE};
|
Rotation rotation{ROTATION_NONE};
|
||||||
int custom1; ///< driver-specific custom argument
|
int bus_frequency{0};
|
||||||
int custom2; ///< driver-specific custom argument
|
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;
|
board_bus_types busType() const;
|
||||||
int bus() const;
|
int bus() const;
|
||||||
uint32_t devid() const;
|
uint32_t devid() const;
|
||||||
uint32_t DRDYGPIO() const;
|
spi_drdy_gpio_t DRDYGPIO() const;
|
||||||
bool external() const;
|
bool external() const;
|
||||||
|
|
||||||
static I2CBusIterator::FilterType i2cFilter(I2CSPIBusOption bus_option);
|
static I2CBusIterator::FilterType i2cFilter(I2CSPIBusOption bus_option);
|
||||||
|
@ -112,6 +117,7 @@ private:
|
||||||
I2CSPIInstance **_instances;
|
I2CSPIInstance **_instances;
|
||||||
const int _max_num_instances;
|
const int _max_num_instances;
|
||||||
const I2CSPIBusOption _bus_option;
|
const I2CSPIBusOption _bus_option;
|
||||||
|
const int _type;
|
||||||
SPIBusIterator _spi_bus_iterator;
|
SPIBusIterator _spi_bus_iterator;
|
||||||
I2CBusIterator _i2c_bus_iterator;
|
I2CBusIterator _i2c_bus_iterator;
|
||||||
int _current_instance{-1};
|
int _current_instance{-1};
|
||||||
|
@ -124,9 +130,9 @@ private:
|
||||||
class I2CSPIDriverBase : public px4::ScheduledWorkItem, public I2CSPIInstance
|
class I2CSPIDriverBase : public px4::ScheduledWorkItem, public I2CSPIInstance
|
||||||
{
|
{
|
||||||
public:
|
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),
|
: ScheduledWorkItem(module_name, config),
|
||||||
I2CSPIInstance(bus_option, bus) {}
|
I2CSPIInstance(bus_option, bus, type) {}
|
||||||
|
|
||||||
static int module_stop(BusInstanceIterator &iterator);
|
static int module_stop(BusInstanceIterator &iterator);
|
||||||
static int module_status(BusInstanceIterator &iterator);
|
static int module_status(BusInstanceIterator &iterator);
|
||||||
|
@ -178,8 +184,8 @@ public:
|
||||||
static I2CSPIInstance **instances() { return _instances; }
|
static I2CSPIInstance **instances() { return _instances; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
I2CSPIDriver(const char *module_name, const px4::wq_config_t &config, I2CSPIBusOption bus_option, int 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) {}
|
: I2CSPIDriverBase(module_name, config, bus_option, bus, type) {}
|
||||||
|
|
||||||
virtual ~I2CSPIDriver() = default;
|
virtual ~I2CSPIDriver() = default;
|
||||||
|
|
||||||
|
|
|
@ -46,10 +46,12 @@
|
||||||
//#define PX4_SPI_DEV_ID(devid) ((devid) & 0xffff)
|
//#define PX4_SPI_DEV_ID(devid) ((devid) & 0xffff)
|
||||||
#define PX4_SPIDEVID_TYPE(devid) (((uint32_t)(devid) >> 16) & 0xffff)
|
#define PX4_SPIDEVID_TYPE(devid) (((uint32_t)(devid) >> 16) & 0xffff)
|
||||||
|
|
||||||
|
typedef uint32_t spi_drdy_gpio_t;
|
||||||
|
|
||||||
#define SPI_BUS_MAX_DEVICES 5
|
#define SPI_BUS_MAX_DEVICES 5
|
||||||
struct px4_spi_bus_device_t {
|
struct px4_spi_bus_device_t {
|
||||||
uint32_t cs_gpio; ///< chip-select GPIO (0 if this device is not used)
|
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
|
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)
|
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();
|
bool next();
|
||||||
|
|
||||||
const px4_spi_bus_t &bus() const { return px4_spi_buses[_index]; }
|
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; }
|
uint32_t devid() const { return px4_spi_buses[_index].devices[_bus_device_index].devid; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue