drivers: sensor: bma280: Add multi-instance support
Move driver to use DT_INST_FOREACH_STATUS_OKAY to add multi-instance support. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
This commit is contained in:
parent
ab1124481d
commit
4e0dbc7c14
@ -151,23 +151,28 @@ int bma280_init(const struct device *dev)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BMA280_TRIGGER
|
||||
if (bma280_init_interrupt(dev) < 0) {
|
||||
LOG_DBG("Could not initialize interrupts");
|
||||
return -EIO;
|
||||
if (config->int1_gpio.port) {
|
||||
if (bma280_init_interrupt(dev) < 0) {
|
||||
LOG_DBG("Could not initialize interrupts");
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct bma280_data bma280_inst_data;
|
||||
#define BMA280_DEFINE(inst) \
|
||||
static struct bma280_data bma280_data_##inst; \
|
||||
\
|
||||
static const struct bma280_config bma280_config##inst = { \
|
||||
.i2c = I2C_DT_SPEC_INST_GET(inst), \
|
||||
IF_ENABLED(CONFIG_BMA280_TRIGGER, \
|
||||
(.int1_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, int1_gpios, { 0 }),)) \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, bma280_init, NULL, &bma280_data_##inst, \
|
||||
&bma280_config##inst, POST_KERNEL, \
|
||||
CONFIG_SENSOR_INIT_PRIORITY, &bma280_driver_api); \
|
||||
|
||||
static const struct bma280_config bma280_inst_config = {
|
||||
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||
IF_ENABLED(CONFIG_BMA280_TRIGGER,
|
||||
(.int1_gpio = GPIO_DT_SPEC_INST_GET(0, int1_gpios),))
|
||||
};
|
||||
|
||||
DEVICE_DT_INST_DEFINE(0, bma280_init, NULL, &bma280_inst_data,
|
||||
&bma280_inst_config, POST_KERNEL,
|
||||
CONFIG_SENSOR_INIT_PRIORITY, &bma280_driver_api);
|
||||
DT_INST_FOREACH_STATUS_OKAY(BMA280_DEFINE)
|
||||
|
||||
@ -34,6 +34,10 @@ int bma280_attr_set(const struct device *dev,
|
||||
const struct bma280_config *config = dev->config;
|
||||
uint64_t slope_th;
|
||||
|
||||
if (!config->int1_gpio.port) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (chan != SENSOR_CHAN_ACCEL_XYZ) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
@ -149,6 +153,10 @@ int bma280_trigger_set(const struct device *dev,
|
||||
struct bma280_data *drv_data = dev->data;
|
||||
const struct bma280_config *config = dev->config;
|
||||
|
||||
if (!config->int1_gpio.port) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (trig->type == SENSOR_TRIG_DATA_READY) {
|
||||
/* disable data ready interrupt while changing trigger params */
|
||||
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user