Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | /**
* @file
* @brief GPIO Devicetree macro public API header file.
*/
/*
* Copyright (c) 2020, Linaro Ltd.
* Copyright (c) 2020 Nordic Semiconductor
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DEVICETREE_GPIO_H_
#define ZEPHYR_INCLUDE_DEVICETREE_GPIO_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup devicetree-gpio Devicetree GPIO API
* @ingroup devicetree
* @{
*/
/**
* @brief Get the node identifier for the controller phandle from a
* gpio phandle-array property at an index
*
* Example devicetree fragment:
*
* gpio1: gpio@... { };
*
* gpio2: gpio@... { };
*
* n: node {
* gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
* <&gpio2 30 GPIO_ACTIVE_HIGH>;
* };
*
* Example usage:
*
* DT_GPIO_CTLR_BY_IDX(DT_NODELABEL(n), gpios, 1) // DT_NODELABEL(gpio2)
*
* @param node_id node identifier
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @param idx logical index into "gpio_pha"
* @return the node identifier for the gpio controller referenced at
* index "idx"
* @see DT_PHANDLE_BY_IDX()
*/
#define DT_GPIO_CTLR_BY_IDX(node_id, gpio_pha, idx) \
DT_PHANDLE_BY_IDX(node_id, gpio_pha, idx)
/**
* @brief Equivalent to DT_GPIO_CTLR_BY_IDX(node_id, gpio_pha, 0)
* @param node_id node identifier
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @return a node identifier for the gpio controller at index 0
* in "gpio_pha"
* @see DT_GPIO_CTLR_BY_IDX()
*/
#define DT_GPIO_CTLR(node_id, gpio_pha) \
DT_GPIO_CTLR_BY_IDX(node_id, gpio_pha, 0)
/**
* @brief Get a label property from a gpio phandle-array property
* at an index
*
* It's an error if the GPIO controller node referenced by the phandle
* in node_id's "gpio_pha" property at index "idx" has no label
* property.
*
* Example devicetree fragment:
*
* gpio1: gpio@... {
* label = "GPIO_1";
* };
*
* gpio2: gpio@... {
* label = "GPIO_2";
* };
*
* n: node {
* gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
* <&gpio2 30 GPIO_ACTIVE_HIGH>;
* };
*
* Example usage:
*
* DT_GPIO_LABEL_BY_IDX(DT_NODELABEL(n), gpios, 1) // "GPIO_2"
*
* @param node_id node identifier
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @param idx logical index into "gpio_pha"
* @return the label property of the node referenced at index "idx"
* @see DT_PHANDLE_BY_IDX()
*/
#define DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, idx) \
DT_PROP(DT_GPIO_CTLR_BY_IDX(node_id, gpio_pha, idx), label)
/**
* @brief Equivalent to DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, 0)
* @param node_id node identifier
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @return the label property of the node referenced at index 0
* @see DT_GPIO_LABEL_BY_IDX()
*/
#define DT_GPIO_LABEL(node_id, gpio_pha) \
DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, 0)
/**
* @brief Get a GPIO specifier's pin cell at an index
*
* This macro only works for GPIO specifiers with cells named "pin".
* Refer to the node's binding to check if necessary.
*
* Example devicetree fragment:
*
* gpio1: gpio@... {
* compatible = "vnd,gpio";
* #gpio-cells = <2>;
* };
*
* gpio2: gpio@... {
* compatible = "vnd,gpio";
* #gpio-cells = <2>;
* };
*
* n: node {
* gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
* <&gpio2 30 GPIO_ACTIVE_HIGH>;
* };
*
* Bindings fragment for the vnd,gpio compatible:
*
* gpio-cells:
* - pin
* - flags
*
* Example usage:
*
* DT_GPIO_PIN_BY_IDX(DT_NODELABEL(n), gpios, 0) // 10
* DT_GPIO_PIN_BY_IDX(DT_NODELABEL(n), gpios, 1) // 30
*
* @param node_id node identifier
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @param idx logical index into "gpio_pha"
* @return the pin cell value at index "idx"
* @see DT_PHA_BY_IDX()
*/
#define DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, idx) \
DT_PHA_BY_IDX(node_id, gpio_pha, idx, pin)
/**
* @brief Equivalent to DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, 0)
* @param node_id node identifier
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @return the pin cell value at index 0
* @see DT_GPIO_PIN_BY_IDX()
*/
#define DT_GPIO_PIN(node_id, gpio_pha) \
DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, 0)
/**
* @brief Get a GPIO specifier's flags cell at an index
*
* This macro expects GPIO specifiers with cells named "flags".
* If there is no "flags" cell in the GPIO specifier, zero is returned.
* Refer to the node's binding to check specifier cell names if necessary.
*
* Example devicetree fragment:
*
* gpio1: gpio@... {
* compatible = "vnd,gpio";
* #gpio-cells = <2>;
* };
*
* gpio2: gpio@... {
* compatible = "vnd,gpio";
* #gpio-cells = <2>;
* };
*
* n: node {
* gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
* <&gpio2 30 GPIO_ACTIVE_HIGH>;
* };
*
* Bindings fragment for the vnd,gpio compatible:
*
* gpio-cells:
* - pin
* - flags
*
* Example usage:
*
* DT_GPIO_FLAGS_BY_IDX(DT_NODELABEL(n), gpios, 0) // GPIO_ACTIVE_LOW
* DT_GPIO_FLAGS_BY_IDX(DT_NODELABEL(n), gpios, 1) // GPIO_ACTIVE_HIGH
*
* @param node_id node identifier
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @param idx logical index into "gpio_pha"
* @return the flags cell value at index "idx", or zero if there is none
* @see DT_PHA_BY_IDX()
*/
#define DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, idx) \
DT_PHA_BY_IDX_OR(node_id, gpio_pha, idx, flags, 0)
/**
* @brief Equivalent to DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, 0)
* @param node_id node identifier
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @return the flags cell value at index 0, or zero if there is none
* @see DT_GPIO_FLAGS_BY_IDX()
*/
#define DT_GPIO_FLAGS(node_id, gpio_pha) \
DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, 0)
/**
* @brief Get a label property from a DT_DRV_COMPAT instance's GPIO
* property at an index
* @param inst DT_DRV_COMPAT instance number
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @param idx logical index into "gpio_pha"
* @return the label property of the node referenced at index "idx"
*/
#define DT_INST_GPIO_LABEL_BY_IDX(inst, gpio_pha, idx) \
DT_GPIO_LABEL_BY_IDX(DT_DRV_INST(inst), gpio_pha, idx)
/**
* @brief Equivalent to DT_INST_GPIO_LABEL_BY_IDX(inst, gpio_pha, 0)
* @param inst DT_DRV_COMPAT instance number
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @return the label property of the node referenced at index 0
*/
#define DT_INST_GPIO_LABEL(inst, gpio_pha) \
DT_INST_GPIO_LABEL_BY_IDX(inst, gpio_pha, 0)
/**
* @brief Get a DT_DRV_COMPAT instance's GPIO specifier's pin cell value
* at an index
* @param inst DT_DRV_COMPAT instance number
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @param idx logical index into "gpio_pha"
* @return the pin cell value at index "idx"
* @see DT_GPIO_PIN_BY_IDX()
*/
#define DT_INST_GPIO_PIN_BY_IDX(inst, gpio_pha, idx) \
DT_GPIO_PIN_BY_IDX(DT_DRV_INST(inst), gpio_pha, idx)
/**
* @brief Equivalent to DT_INST_GPIO_PIN_BY_IDX(inst, gpio_pha, 0)
* @param inst DT_DRV_COMPAT instance number
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @return the pin cell value at index 0
* @see DT_INST_GPIO_PIN_BY_IDX()
*/
#define DT_INST_GPIO_PIN(inst, gpio_pha) \
DT_INST_GPIO_PIN_BY_IDX(inst, gpio_pha, 0)
/**
* @brief Get a DT_DRV_COMPAT instance's GPIO specifier's flags cell
* at an index
* @param inst DT_DRV_COMPAT instance number
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @param idx logical index into "gpio_pha"
* @return the flags cell value at index "idx", or zero if there is none
* @see DT_GPIO_FLAGS_BY_IDX()
*/
#define DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, idx) \
DT_GPIO_FLAGS_BY_IDX(DT_DRV_INST(inst), gpio_pha, idx)
/**
* @brief Equivalent to DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, 0)
* @param inst DT_DRV_COMPAT instance number
* @param gpio_pha lowercase-and-underscores GPIO property with
* type "phandle-array"
* @return the flags cell value at index 0, or zero if there is none
* @see DT_INST_GPIO_FLAGS_BY_IDX()
*/
#define DT_INST_GPIO_FLAGS(inst, gpio_pha) \
DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, 0)
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_DEVICETREE_GPIO_H_ */
|