Skip to content

Instantly share code, notes, and snippets.

@Lncn
Created November 13, 2018 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lncn/49174feb32c2d96dc4e82924b6163c8f to your computer and use it in GitHub Desktop.
Save Lncn/49174feb32c2d96dc4e82924b6163c8f to your computer and use it in GitHub Desktop.
Zephyr GPIO IRQ callback init sample
struct gpio_callback x_irq_cb;
struct device *x_irq;
void x_disable_irq(void)
{
gpio_pin_disable_callback(x_irq, CONFIG_x_IRQ_GPIO_PIN);
}
void x_enable_irq(void(*handler)(void))
{
gpio_pin_configure(x_irq, CONFIG_x_IRQ_GPIO_PIN, GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH);
gpio_init_callback(&x_irq_cb, x_irq_handler, BIT(CONFIG_x_IRQ_GPIO_PIN));
gpio_add_callback(x_irq, &x_irq_cb);
gpio_pin_enable_callback(x_irq, CONFIG_x_IRQ_GPIO_PIN);
}
void x_irq_handler(struct device *gpio, struct gpio_callback *cb, uint32_t pins)
{
/* Does something */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment