Skip to content

Commit

Permalink
gpio: add gpio_pin_interrupt_configure function
Browse files Browse the repository at this point in the history
This commit moves interrupt configuration for a single pin from
gpio_pin_configure to gpio_pin_interrupt_configure function.

Signed-off-by: Piotr Mienkowski <[email protected]>
  • Loading branch information
mnkp authored and carlescufi committed Feb 5, 2020
1 parent d6191b5 commit 33193a5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/gpio/gpio_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ static inline int z_vrfy_gpio_port_toggle_bits(struct device *port,
}
#include <syscalls/gpio_port_toggle_bits_mrsh.c>

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 <syscalls/gpio_pin_interrupt_configure_mrsh.c>

static inline int z_vrfy_gpio_enable_callback(struct device *port,
int access_op, u32_t pin)
{
Expand Down
37 changes: 37 additions & 0 deletions include/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 33193a5

Please sign in to comment.