drivers: gpio: extend struct gpio_dt_spec initializers
Extend the number of available initializers for the `struct gpio_dt_spec` with: - GPIO_DT_SPEC_GET_BY_IDX(): allows initialization from a specific index - GPIO_DT_SPEC_INST_GET_BY_IDX(): instance version of GPIO_DT_SPEC_GET_BY_IDX() - GPIO_DT_SPEC_INST_GET(): instance version of GPIO_DT_SPEC_GET() Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
496cdac71d
commit
6a6ebcec11
1 changed files with 47 additions and 11 deletions
|
@ -320,20 +320,20 @@ struct gpio_dt_spec {
|
||||||
/**
|
/**
|
||||||
* @brief Static initializer for a @p gpio_dt_spec
|
* @brief Static initializer for a @p gpio_dt_spec
|
||||||
*
|
*
|
||||||
* This returns a static initializer for a @p gpio_dt_spec structure
|
* This returns a static initializer for a @p gpio_dt_spec structure given a
|
||||||
* given a devicetree node identifier and a property specifying a
|
* devicetree node identifier, a property specifying a GPIO and an index.
|
||||||
* GPIO.
|
|
||||||
*
|
*
|
||||||
* Example devicetree fragment:
|
* Example devicetree fragment:
|
||||||
*
|
*
|
||||||
* n: node {
|
* n: node {
|
||||||
* foo-gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
|
* foo-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>,
|
||||||
|
* <&gpio1 2 GPIO_ACTIVE_LOW>;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
*
|
*
|
||||||
* const struct gpio_dt_spec spec = GPIO_DT_SPEC_GET(DT_NODELABEL(n),
|
* const struct gpio_dt_spec spec = GPIO_DT_SPEC_GET_BY_IDX(DT_NODELABEL(n),
|
||||||
* foo_gpios);
|
* foo_gpios, 1);
|
||||||
* // Initializes 'spec' to:
|
* // Initializes 'spec' to:
|
||||||
* // {
|
* // {
|
||||||
* // .port = DEVICE_DT_GET(DT_NODELABEL(gpio1)),
|
* // .port = DEVICE_DT_GET(DT_NODELABEL(gpio1)),
|
||||||
|
@ -348,15 +348,51 @@ struct gpio_dt_spec {
|
||||||
*
|
*
|
||||||
* @param node_id devicetree node identifier
|
* @param node_id devicetree node identifier
|
||||||
* @param prop lowercase-and-underscores property name
|
* @param prop lowercase-and-underscores property name
|
||||||
|
* @param idx logical index into "prop"
|
||||||
* @return static initializer for a struct gpio_dt_spec for the property
|
* @return static initializer for a struct gpio_dt_spec for the property
|
||||||
*/
|
*/
|
||||||
#define GPIO_DT_SPEC_GET(node_id, prop) \
|
#define GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx) \
|
||||||
{ \
|
{ \
|
||||||
.port = DEVICE_DT_GET(DT_GPIO_CTLR(node_id, prop)), \
|
.port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
|
||||||
.pin = DT_GPIO_PIN(node_id, prop), \
|
.pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
|
||||||
.dt_flags = DT_GPIO_FLAGS(node_id, prop), \
|
.dt_flags = DT_GPIO_FLAGS_BY_IDX(node_id, prop, idx), \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equivalent to GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0).
|
||||||
|
*
|
||||||
|
* @param node_id devicetree node identifier
|
||||||
|
* @param prop lowercase-and-underscores property name
|
||||||
|
* @return static initializer for a struct gpio_dt_spec for the property
|
||||||
|
* @see GPIO_DT_SPEC_GET_BY_IDX()
|
||||||
|
*/
|
||||||
|
#define GPIO_DT_SPEC_GET(node_id, prop) \
|
||||||
|
GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Static initializer for a @p gpio_dt_spec from a DT_DRV_COMPAT
|
||||||
|
* instance's GPIO property at an index.
|
||||||
|
*
|
||||||
|
* @param inst DT_DRV_COMPAT instance number
|
||||||
|
* @param prop lowercase-and-underscores property name
|
||||||
|
* @param idx logical index into "prop"
|
||||||
|
* @return static initializer for a struct gpio_dt_spec for the property
|
||||||
|
* @see GPIO_DT_SPEC_GET_BY_IDX()
|
||||||
|
*/
|
||||||
|
#define GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) \
|
||||||
|
GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0).
|
||||||
|
*
|
||||||
|
* @param inst DT_DRV_COMPAT instance number
|
||||||
|
* @param prop lowercase-and-underscores property name
|
||||||
|
* @return static initializer for a struct gpio_dt_spec for the property
|
||||||
|
* @see GPIO_DT_SPEC_INST_GET_BY_IDX()
|
||||||
|
*/
|
||||||
|
#define GPIO_DT_SPEC_INST_GET(inst, prop) \
|
||||||
|
GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Maximum number of pins that are supported by `gpio_port_pins_t`.
|
* @brief Maximum number of pins that are supported by `gpio_port_pins_t`.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue