Skip to content

Commit

Permalink
drivers: sensor: bmc150_magn: convert to new GPIO API
Browse files Browse the repository at this point in the history
Use the new pin and interrupt configuration API.

NOTE: Because hardware is not available this has been build-tested
only.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
  • Loading branch information
pabigot committed Jan 23, 2020
1 parent 1b1f7bc commit 933dbbc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
5 changes: 3 additions & 2 deletions drivers/sensor/bmc150_magn/bmc150_magn.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,13 @@ static int bmc150_magn_init(struct device *dev)
}

static const struct bmc150_magn_config bmc150_magn_config = {
.i2c_master_dev_name = DT_INST_0_BOSCH_BMC150_MAGN_BUS_NAME,
.i2c_slave_addr = BMC150_MAGN_I2C_ADDR,
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
.gpio_drdy_dev_name = DT_INST_0_BOSCH_BMC150_MAGN_DRDY_GPIOS_CONTROLLER,
.gpio_drdy_int_pin = DT_INST_0_BOSCH_BMC150_MAGN_DRDY_GPIOS_PIN,
.gpio_drdy_int_flags = DT_INST_0_BOSCH_BMC150_MAGN_DRDY_GPIOS_FLAGS,
#endif
.i2c_master_dev_name = DT_INST_0_BOSCH_BMC150_MAGN_BUS_NAME,
.i2c_slave_addr = BMC150_MAGN_I2C_ADDR,
};

static struct bmc150_magn_data bmc150_magn_data;
Expand Down
8 changes: 4 additions & 4 deletions drivers/sensor/bmc150_magn/bmc150_magn.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@
#endif

struct bmc150_magn_config {
char *i2c_master_dev_name;
u16_t i2c_slave_addr;

#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
char *gpio_drdy_dev_name;
u8_t gpio_drdy_int_pin;
gpio_pin_t gpio_drdy_int_pin;
gpio_devicetree_flags_t gpio_drdy_int_flags;
#endif
u16_t i2c_slave_addr;
char *i2c_master_dev_name;
};

struct bmc150_magn_trim_regs {
Expand Down
33 changes: 21 additions & 12 deletions drivers/sensor/bmc150_magn/bmc150_magn_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
#include <logging/log.h>
LOG_MODULE_DECLARE(BMC150_MAGN, CONFIG_SENSOR_LOG_LEVEL);

static inline void setup_drdy(struct device *dev,
bool enable)
{
struct bmc150_magn_data *data = dev->driver_data;
const struct bmc150_magn_config *const cfg =
dev->config->config_info;

gpio_pin_interrupt_configure(data->gpio_drdy,
cfg->gpio_drdy_int_pin,
enable
? GPIO_INT_EDGE_TO_ACTIVE
: GPIO_INT_DISABLE);
}


int bmc150_magn_trigger_set(struct device *dev,
const struct sensor_trigger *trig,
sensor_trigger_handler_t handler)
Expand All @@ -26,8 +41,7 @@ int bmc150_magn_trigger_set(struct device *dev,

#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
if (trig->type == SENSOR_TRIG_DATA_READY) {
gpio_pin_disable_callback(data->gpio_drdy,
config->gpio_drdy_int_pin);
setup_drdy(dev, false);

state = 0U;
if (handler) {
Expand All @@ -47,8 +61,7 @@ int bmc150_magn_trigger_set(struct device *dev,
return -EIO;
}

gpio_pin_enable_callback(data->gpio_drdy,
config->gpio_drdy_int_pin);
setup_drdy(dev, true);
}
#endif

Expand All @@ -61,12 +74,10 @@ static void bmc150_magn_gpio_drdy_callback(struct device *dev,
{
struct bmc150_magn_data *data =
CONTAINER_OF(cb, struct bmc150_magn_data, gpio_cb);
const struct bmc150_magn_config * const config =
data->dev->config->config_info;

ARG_UNUSED(pins);

gpio_pin_disable_callback(dev, config->gpio_drdy_int_pin);
setup_drdy(data->dev, false);

k_sem_give(&data->sem);
}
Expand All @@ -78,8 +89,6 @@ static void bmc150_magn_thread_main(void *arg1, void *arg2, void *arg3)
const struct bmc150_magn_config *config = dev->config->config_info;
u8_t reg_val;

int gpio_pin = config->gpio_drdy_int_pin;

while (1) {
k_sem_take(&data->sem, K_FOREVER);

Expand All @@ -94,7 +103,7 @@ static void bmc150_magn_thread_main(void *arg1, void *arg2, void *arg3)
data->handler_drdy(dev, &data->trigger_drdy);
}

gpio_pin_enable_callback(data->gpio_drdy, gpio_pin);
setup_drdy(dev, true);
}
}

Expand Down Expand Up @@ -152,8 +161,8 @@ int bmc150_magn_init_interrupt(struct device *dev)
}

gpio_pin_configure(data->gpio_drdy, config->gpio_drdy_int_pin,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
config->gpio_drdy_int_flags
| GPIO_INT_EDGE_TO_ACTIVE);

gpio_init_callback(&data->gpio_cb,
bmc150_magn_gpio_drdy_callback,
Expand Down

0 comments on commit 933dbbc

Please sign in to comment.