drivers: sensor: tmp007: Update driver to use gpio_dt_spec
Move driver to use gpio_dt_spec for GPIO interrupt handling. Signed-off-by: Kumar Gala <galak@kernel.org>
This commit is contained in:
parent
d184190863
commit
2c60426639
3 changed files with 15 additions and 15 deletions
|
@ -125,6 +125,9 @@ int tmp007_init(const struct device *dev)
|
||||||
|
|
||||||
static const struct tmp007_config tmp007_config = {
|
static const struct tmp007_config tmp007_config = {
|
||||||
.i2c = I2C_DT_SPEC_INST_GET(0),
|
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||||
|
#ifdef CONFIG_TMP007_TRIGGER
|
||||||
|
.int_gpio = GPIO_DT_SPEC_INST_GET(0, int_gpios),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tmp007_data tmp007_driver;
|
struct tmp007_data tmp007_driver;
|
||||||
|
|
|
@ -34,13 +34,15 @@
|
||||||
|
|
||||||
struct tmp007_config {
|
struct tmp007_config {
|
||||||
struct i2c_dt_spec i2c;
|
struct i2c_dt_spec i2c;
|
||||||
|
#ifdef CONFIG_TMP007_TRIGGER
|
||||||
|
struct gpio_dt_spec int_gpio;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tmp007_data {
|
struct tmp007_data {
|
||||||
int16_t sample;
|
int16_t sample;
|
||||||
|
|
||||||
#ifdef CONFIG_TMP007_TRIGGER
|
#ifdef CONFIG_TMP007_TRIGGER
|
||||||
const struct device *gpio;
|
|
||||||
struct gpio_callback gpio_cb;
|
struct gpio_callback gpio_cb;
|
||||||
const struct device *dev;
|
const struct device *dev;
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,9 @@ LOG_MODULE_DECLARE(TMP007, CONFIG_SENSOR_LOG_LEVEL);
|
||||||
static inline void setup_int(const struct device *dev,
|
static inline void setup_int(const struct device *dev,
|
||||||
bool enable)
|
bool enable)
|
||||||
{
|
{
|
||||||
struct tmp007_data *data = dev->data;
|
const struct tmp007_config *cfg = dev->config;
|
||||||
|
|
||||||
gpio_pin_interrupt_configure(data->gpio,
|
gpio_pin_interrupt_configure_dt(&cfg->int_gpio,
|
||||||
DT_INST_GPIO_PIN(0, int_gpios),
|
|
||||||
enable
|
enable
|
||||||
? GPIO_INT_LEVEL_ACTIVE
|
? GPIO_INT_LEVEL_ACTIVE
|
||||||
: GPIO_INT_DISABLE);
|
: GPIO_INT_DISABLE);
|
||||||
|
@ -155,23 +154,19 @@ int tmp007_init_interrupt(const struct device *dev)
|
||||||
|
|
||||||
drv_data->dev = dev;
|
drv_data->dev = dev;
|
||||||
|
|
||||||
/* setup gpio interrupt */
|
if (!device_is_ready(cfg->int_gpio.port)) {
|
||||||
drv_data->gpio = device_get_binding(DT_INST_GPIO_LABEL(0, int_gpios));
|
LOG_ERR("%s: device %s is not ready", dev->name,
|
||||||
if (drv_data->gpio == NULL) {
|
cfg->int_gpio.port->name);
|
||||||
LOG_DBG("Failed to get pointer to %s device!",
|
return -ENODEV;
|
||||||
DT_INST_GPIO_LABEL(0, int_gpios));
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_pin_configure(drv_data->gpio, DT_INST_GPIO_PIN(0, int_gpios),
|
gpio_pin_configure_dt(&cfg->int_gpio, GPIO_INT_LEVEL_ACTIVE);
|
||||||
DT_INST_GPIO_FLAGS(0, int_gpios)
|
|
||||||
| GPIO_INT_LEVEL_ACTIVE);
|
|
||||||
|
|
||||||
gpio_init_callback(&drv_data->gpio_cb,
|
gpio_init_callback(&drv_data->gpio_cb,
|
||||||
tmp007_gpio_callback,
|
tmp007_gpio_callback,
|
||||||
BIT(DT_INST_GPIO_PIN(0, int_gpios)));
|
BIT(cfg->int_gpio.pin));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(cfg->int_gpio.port, &drv_data->gpio_cb) < 0) {
|
||||||
LOG_DBG("Failed to set gpio callback!");
|
LOG_DBG("Failed to set gpio callback!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue