diff --git a/drivers/gpio/gpio_handlers.c b/drivers/gpio/gpio_handlers.c index 235df21c9ea..466ce18a5cf 100644 --- a/drivers/gpio/gpio_handlers.c +++ b/drivers/gpio/gpio_handlers.c @@ -76,6 +76,15 @@ static inline int z_vrfy_gpio_port_toggle_bits(struct device *port, } #include +static inline int z_vrfy_gpio_pin_interrupt_configure(struct device *port, + unsigned int pin, unsigned int flags) +{ + Z_OOPS(Z_SYSCALL_DRIVER_GPIO(port, pin_interrupt_configure)); + return z_impl_gpio_pin_interrupt_configure((struct device *)port, pin, + flags); +} +#include + static inline int z_vrfy_gpio_enable_callback(struct device *port, int access_op, u32_t pin) { diff --git a/include/drivers/gpio.h b/include/drivers/gpio.h index 0e41af3c50a..ba821a10dbd 100644 --- a/include/drivers/gpio.h +++ b/include/drivers/gpio.h @@ -450,6 +450,8 @@ struct gpio_driver_api { int (*port_set_bits_raw)(struct device *port, gpio_pins_t pins); int (*port_clear_bits_raw)(struct device *port, gpio_pins_t pins); int (*port_toggle_bits)(struct device *port, gpio_pins_t pins); + int (*pin_interrupt_configure)(struct device *port, unsigned int pin, + unsigned int flags); int (*manage_callback)(struct device *port, struct gpio_callback *cb, bool set); int (*enable_callback)(struct device *port, int access_op, u32_t pin); @@ -966,6 +968,41 @@ static inline int gpio_pin_read(struct device *port, u32_t pin, return gpio_read(port, GPIO_ACCESS_BY_PIN, pin, value); } +/** + * @brief Configure pin interrupt. + * + * @note This function can also be used to configure interrupts on pins + * not controlled directly by the GPIO module. That is, pins which are + * routed to other modules such as I2C, SPI, UART. + * + * @param port Pointer to device structure for the driver instance. + * @param pin Pin number. + * @param flags Interrupt configuration flags as defined by GPIO_INT_*. + * + * @retval 0 If successful. + * @retval -ENOTSUP If any of the configuration options is not supported. + * @retval -EINVAL Invalid argument. + * @retval -EBUSY Interrupt line required to configure pin interrupt is + * already in use. + */ +__syscall int gpio_pin_interrupt_configure(struct device *port, + unsigned int pin, unsigned int flags); + +static inline int z_impl_gpio_pin_interrupt_configure(struct device *port, + unsigned int pin, unsigned int flags) +{ + const struct gpio_driver_api *api = + (const struct gpio_driver_api *)port->driver_api; + + __ASSERT(pin < GPIO_MAX_PINS_PER_PORT, "Invalid pin number"); + + __ASSERT(((flags & GPIO_INT_ENABLE) == 0) || + ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) != 0), + "At least one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 has to be " + "enabled."); + return api->pin_interrupt_configure(port, pin, flags); +} + /** * @brief Helper to initialize a struct gpio_callback properly * @param callback A valid Application's callback structure pointer.