#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(main);
#define MCP9808_INT_PIN DT_GPIO_PIN(DT_NODELABEL(gpio0), int_pin)
void sensor_isr(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
LOG_INF("Interrupt triggered");
// Read sensor data here
}
void main(void)
{
const struct device *gpio_dev = device_get_binding(DT_LABEL(DT_NODELABEL(gpio0)));
static struct gpio_callback sensor_cb;
gpio_pin_configure(gpio_dev, MCP9808_INT_PIN, GPIO_INPUT | GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&sensor_cb, sensor_isr, BIT(MCP9808_INT_PIN));
gpio_add_callback(gpio_dev, &sensor_cb);
gpio_pin_interrupt_configure(gpio_dev, MCP9808_INT_PIN, GPIO_INT_EDGE_TO_ACTIVE);
while (1) {
k_sleep(K_MSEC(1000));
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(main);
#define MCP9808_INT_PIN DT_GPIO_PIN(DT_NODELABEL(gpio0), int_pin)
void sensor_isr(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
LOG_INF("Interrupt triggered");
// Read sensor data here
}
void main(void)
{
const struct device *gpio_dev = device_get_binding(DT_LABEL(DT_NODELABEL(gpio0)));
static struct gpio_callback sensor_cb;
gpio_pin_configure(gpio_dev, MCP9808_INT_PIN, GPIO_INPUT | GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&sensor_cb, sensor_isr, BIT(MCP9808_INT_PIN));
gpio_add_callback(gpio_dev, &sensor_cb);
gpio_pin_interrupt_configure(gpio_dev, MCP9808_INT_PIN, GPIO_INT_EDGE_TO_ACTIVE);
while (1) {
k_sleep(K_MSEC(1000));
}
}