Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions drivers/sensor/mcp9808/mcp9808_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ static inline void setup_int(struct device *dev,
{
const struct mcp9808_data *data = dev->driver_data;
const struct mcp9808_config *cfg = dev->config->config_info;
unsigned int flags = enable
? GPIO_INT_EDGE_TO_ACTIVE
: GPIO_INT_DISABLE;

if (enable) {
gpio_pin_enable_callback(data->alert_gpio, cfg->alert_pin);
} else {
gpio_pin_disable_callback(data->alert_gpio, cfg->alert_pin);
}
gpio_pin_interrupt_configure(data->alert_gpio, cfg->alert_pin, flags);
}

static void handle_int(struct device *dev)
Expand Down Expand Up @@ -110,13 +109,12 @@ int mcp9808_trigger_set(struct device *dev,
data->trigger_handler = handler;

if (handler != NULL) {
u32_t val;

setup_int(dev, true);

rv = gpio_pin_read(data->alert_gpio, cfg->alert_pin, &val);
if ((rv == 0) && (val == 0)) {
rv = gpio_pin_get(data->alert_gpio, cfg->alert_pin);
if (rv > 0) {
handle_int(dev);
rv = 0;
}
}

Expand Down Expand Up @@ -196,9 +194,7 @@ int mcp9808_setup_interrupt(struct device *dev)

if (rc == 0) {
rc = gpio_pin_configure(gpio, cfg->alert_pin,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_PUD_PULL_UP |
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
GPIO_INPUT | cfg->alert_flags);
}

if (rc == 0) {
Expand Down
5 changes: 5 additions & 0 deletions dts/bindings/sensor/microchip,mcp9808.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ properties:
int-gpios:
type: phandle-array
required: false
description: |
The alert pin defaults to active low when produced by the
sensor, and is open-drain. A pull-up may be appropriate. The
property value should ensure the flags properly describe the
signal that is presented to the driver.
2 changes: 1 addition & 1 deletion samples/sensor/mcp9808/boards/frdm_k64f.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mcp9808@18 {
compatible = "microchip,mcp9808";
reg = <0x18>;
int-gpios = <&gpioc 16 0>;
int-gpios = <&gpioc 16 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "MCP9808";
};
};
2 changes: 1 addition & 1 deletion samples/sensor/mcp9808/boards/particle_xenon.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mcp9808@18 {
compatible = "microchip,mcp9808";
reg = <0x18>;
int-gpios = <&gpio1 1 0>;
int-gpios = <&gpio1 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "MCP9808";
};
};