Browse Source

drivers: gpio: provide typedefs for flags and devicetree properties

The public API for GPIO flags should use unsigned values, and for
MISRA compliance the size should not be platform-dependent.  Add a
typedef for generic flags.

Also add typedefs for pin indexes and devicetree flags so these can
be safely recorded from devicetree property values without risking
loss of information if more flags are added in the future.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
pull/22369/head
Peter Bigot 6 years ago committed by Carles Cufí
parent
commit
2016cc64aa
  1. 2
      drivers/gpio/gpio_handlers.c
  2. 39
      include/drivers/gpio.h

2
drivers/gpio/gpio_handlers.c

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
#include <syscall_handler.h>
static inline int z_vrfy_gpio_config(struct device *port, int access_op,
u32_t pin, int flags)
u32_t pin, gpio_flags_t flags)
{
Z_OOPS(Z_SYSCALL_DRIVER_GPIO(port, config));
return z_impl_gpio_config((struct device *)port, access_op, pin, flags);

39
include/drivers/gpio.h

@ -406,6 +406,31 @@ typedef u32_t gpio_port_pins_t; @@ -406,6 +406,31 @@ typedef u32_t gpio_port_pins_t;
*/
typedef u32_t gpio_port_value_t;
/**
* @brief Provides a type to hold a GPIO pin index.
*
* This can be used to record the pin number from a devicetree GPIOS
* property.
*/
typedef u8_t gpio_pin_t;
/**
* @brief Provides a type to hold GPIO devicetree flags.
*
* All GPIO flags that can be expressed in devicetree fit in the low 8
* bits of the full flags field, so use a reduced-size type to record
* that part of a GPIOS property.
*/
typedef u8_t gpio_devicetree_flags_t;
/**
* @brief Provides a type to hold GPIO configuration flags.
*
* This type is sufficient to hold all flags used to control GPIO
* configuration, whether pin or interrupt.
*/
typedef u32_t gpio_flags_t;
/**
* @brief Maximum number of pins that are supported by `gpio_port_pins_t`.
*/
@ -473,7 +498,7 @@ struct gpio_callback { @@ -473,7 +498,7 @@ struct gpio_callback {
*/
/* Used by driver api function pin_interrupt_configure, these are defined
* in terms of the public int flags so we can just mask and pass them
* in terms of the public flags so we can just mask and pass them
* through to the driver api
*/
enum gpio_int_mode {
@ -515,15 +540,15 @@ struct gpio_driver_api { @@ -515,15 +540,15 @@ struct gpio_driver_api {
};
__syscall int gpio_config(struct device *port, int access_op, u32_t pin,
int flags);
gpio_flags_t flags);
static inline int z_impl_gpio_config(struct device *port, int access_op,
u32_t pin, int flags)
u32_t pin, gpio_flags_t flags)
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
return api->config(port, access_op, pin, flags);
return api->config(port, access_op, pin, (int)flags);
}
__syscall int gpio_write(struct device *port, int access_op, u32_t pin,
@ -606,10 +631,10 @@ static inline int z_impl_gpio_disable_callback(struct device *port, @@ -606,10 +631,10 @@ static inline int z_impl_gpio_disable_callback(struct device *port,
* @retval -EWOULDBLOCK if operation would block.
*/
__syscall int gpio_pin_interrupt_configure(struct device *port,
unsigned int pin, unsigned int flags);
unsigned int pin, gpio_flags_t flags);
static inline int z_impl_gpio_pin_interrupt_configure(struct device *port,
unsigned int pin, unsigned int flags)
unsigned int pin, gpio_flags_t flags)
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
@ -670,7 +695,7 @@ static inline int z_impl_gpio_pin_interrupt_configure(struct device *port, @@ -670,7 +695,7 @@ static inline int z_impl_gpio_pin_interrupt_configure(struct device *port,
* @retval -EWOULDBLOCK if operation would block.
*/
static inline int gpio_pin_configure(struct device *port, u32_t pin,
unsigned int flags)
gpio_flags_t flags)
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;

Loading…
Cancel
Save