drivers: gpio: add GPIO_DT_SPEC_GET_OR and friends
These helper macros avoid boilerplate when constructing a gpio_dt_spec structure from optional devicetree properties. Update the release notes while we're here. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
5af20cd258
commit
60ab0af5db
2 changed files with 73 additions and 0 deletions
|
@ -225,6 +225,17 @@ Drivers and Sensors
|
|||
|
||||
* GPIO
|
||||
|
||||
* :c:struct:`gpio_dt_spec`: a new structure which makes it more convenient to
|
||||
access GPIO configuration in the :ref:`devicetree <dt-guide>`.
|
||||
* New macros for initializing ``gpio_dt_spec`` values:
|
||||
:c:macro:`GPIO_DT_SPEC_GET_BY_IDX`, :c:macro:`GPIO_DT_SPEC_GET_BY_IDX_OR`,
|
||||
:c:macro:`GPIO_DT_SPEC_GET`, :c:macro:`GPIO_DT_SPEC_GET_OR`,
|
||||
:c:macro:`GPIO_DT_SPEC_INST_GET_BY_IDX`,
|
||||
:c:macro:`GPIO_DT_SPEC_INST_GET_BY_IDX_OR`,
|
||||
:c:macro:`GPIO_DT_SPEC_INST_GET`, and :c:macro:`GPIO_DT_SPEC_INST_GET_OR`
|
||||
* New helper functions for using ``gpio_dt_spec`` values:
|
||||
:c:func:`gpio_pin_configure_dt`, :c:func:`gpio_pin_interrupt_configure_dt`
|
||||
|
||||
* Hardware Info
|
||||
|
||||
* I2C
|
||||
|
|
|
@ -358,6 +358,28 @@ struct gpio_dt_spec {
|
|||
.dt_flags = DT_GPIO_FLAGS_BY_IDX(node_id, prop, idx), \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Like GPIO_DT_SPEC_GET_BY_IDX(), with a fallback to a default value
|
||||
*
|
||||
* If the devicetree node identifier 'node_id' refers to a node with a
|
||||
* property 'prop', this expands to
|
||||
* <tt>GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)</tt>. The @p
|
||||
* default_value parameter is not expanded in this case.
|
||||
*
|
||||
* Otherwise, this expands to @p default_value.
|
||||
*
|
||||
* @param node_id devicetree node identifier
|
||||
* @param prop lowercase-and-underscores property name
|
||||
* @param idx logical index into "prop"
|
||||
* @param default_value fallback value to expand to
|
||||
* @return static initializer for a struct gpio_dt_spec for the property,
|
||||
* or default_value if the node or property do not exist
|
||||
*/
|
||||
#define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
|
||||
COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
|
||||
(GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), \
|
||||
(default_value))
|
||||
|
||||
/**
|
||||
* @brief Equivalent to GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0).
|
||||
*
|
||||
|
@ -369,6 +391,19 @@ struct gpio_dt_spec {
|
|||
#define GPIO_DT_SPEC_GET(node_id, prop) \
|
||||
GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to
|
||||
* GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value).
|
||||
*
|
||||
* @param node_id devicetree node identifier
|
||||
* @param prop lowercase-and-underscores property name
|
||||
* @param default_value fallback value to expand to
|
||||
* @return static initializer for a struct gpio_dt_spec for the property
|
||||
* @see GPIO_DT_SPEC_GET_BY_IDX_OR()
|
||||
*/
|
||||
#define GPIO_DT_SPEC_GET_OR(node_id, prop, default_value) \
|
||||
GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
|
||||
|
||||
/**
|
||||
* @brief Static initializer for a @p gpio_dt_spec from a DT_DRV_COMPAT
|
||||
* instance's GPIO property at an index.
|
||||
|
@ -382,6 +417,20 @@ struct gpio_dt_spec {
|
|||
#define GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) \
|
||||
GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
|
||||
|
||||
/**
|
||||
* @brief Static initializer for a @p gpio_dt_spec from a DT_DRV_COMPAT
|
||||
* instance's GPIO property at an index, with fallback
|
||||
*
|
||||
* @param inst DT_DRV_COMPAT instance number
|
||||
* @param prop lowercase-and-underscores property name
|
||||
* @param idx logical index into "prop"
|
||||
* @param default_value fallback value to expand to
|
||||
* @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_OR(inst, prop, idx, default_value) \
|
||||
GPIO_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0).
|
||||
*
|
||||
|
@ -393,6 +442,19 @@ struct gpio_dt_spec {
|
|||
#define GPIO_DT_SPEC_INST_GET(inst, prop) \
|
||||
GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
|
||||
|
||||
/**
|
||||
* @brief Equivalent to
|
||||
* GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value).
|
||||
*
|
||||
* @param inst DT_DRV_COMPAT instance number
|
||||
* @param prop lowercase-and-underscores property name
|
||||
* @param default_value fallback value to expand to
|
||||
* @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_OR(inst, prop, default_value) \
|
||||
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
|
||||
|
||||
/**
|
||||
* @brief Maximum number of pins that are supported by `gpio_port_pins_t`.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue