Lines Matching +full:port +full:- +full:pin
2 * Copyright (c) 2019-2020 Nordic Semiconductor ASA
5 * Copyright (c) 2015-2016 Intel Corporation.
7 * SPDX-License-Identifier: Apache-2.0
26 #include <zephyr/dt-bindings/gpio/gpio.h>
46 /** Enables pin as input. */
49 /** Enables pin as output, no change to the output state. */
52 /** Disables pin for both input and output. */
68 /** Configures GPIO pin as output and initializes it to a low state. */
70 /** Configures GPIO pin as output and initializes it to a high state. */
72 /** Configures GPIO pin as output and initializes it to a logic 0. */
76 /** Configures GPIO pin as output and initializes it to a logic 1. */
86 * interrupts. The interrupts can be sensitive to pin physical or logical level.
87 * Interrupts sensitive to pin logical level take into account GPIO_ACTIVE_LOW
88 * flag. If a pin was configured as Active Low, physical level low will be
95 * pin without changing any GPIO settings.
99 /** Disables GPIO pin interrupt. */
104 /* Enables GPIO pin interrupt. */
158 /** Configures GPIO interrupt to be triggered on pin rising edge and enables it.
164 /** Configures GPIO interrupt to be triggered on pin falling edge and enables
171 /** Configures GPIO interrupt to be triggered on pin rising or falling edge and
179 /** Configures GPIO interrupt to be triggered on pin physical level low and
185 /** Configures GPIO interrupt to be triggered on pin physical level high and
191 /** Configures GPIO interrupt to be triggered on pin state change to logical
199 /** Configures GPIO interrupt to be triggered on pin state change to logical
207 /** Configures GPIO interrupt to be triggered on pin logical level 0 and enables
214 /** Configures GPIO interrupt to be triggered on pin logical level 1 and enables
228 * @brief Identifies a set of pins associated with a port.
230 * The pin with index n is present in the set if and only if the bit
236 * @brief Provides values for a set of pins associated with a port.
238 * The value for a pin with index n is high (physical mode) or active
240 * Otherwise the value for the pin is low (physical mode) or inactive
244 * that specifies which encoded pin values are valid for the operation.
249 * @brief Provides a type to hold a GPIO pin index.
251 * This reduced-size type is sufficient to record a pin number,
260 * bits of the full flags field, so use a reduced-size type to record
272 * configuration, whether pin or interrupt.
277 * @brief Container for GPIO pin information specified in devicetree
279 * This type contains a pointer to a GPIO device, pin number for a pin
280 * controlled by that device, and the subset of pin configuration
289 /** GPIO device controlling the pin */
290 const struct device *port; member
291 /** The pin's number on the device */
292 gpio_pin_t pin; member
293 /** The pin's configuration flags as specified in devicetree */
306 * foo-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>,
316 * // .port = DEVICE_DT_GET(DT_NODELABEL(gpio1)),
317 * // .pin = 2,
324 * controller, pin number, and flags as shown above.
327 * @param prop lowercase-and-underscores property name
333 .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
334 .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
349 * @param prop lowercase-and-underscores property name
364 * @param prop lowercase-and-underscores property name
376 * @param prop lowercase-and-underscores property name
389 * @param prop lowercase-and-underscores property name
402 * @param prop lowercase-and-underscores property name
417 * @param prop lowercase-and-underscores property name
429 * @param prop lowercase-and-underscores property name
447 * @param prop lowercase-and-underscores array property name
456 DT_PROP_BY_IDX(node_id, prop, sz_idx) - 1, \
462 * from @p "gpio-reserved-ranges"
480 * @brief Makes a bitmask of reserved GPIOs from DT @p "gpio-reserved-ranges"
483 * This macro returns the value as a bitmask of the @p "gpio-reserved-ranges"
485 * range @p 0...ngpios-1 and is specified as an array of value's pairs that
488 * For example, setting "gpio-reserved-ranges = <3 2>, <10 1>;"
506 * compatible = "some,gpio-controller";
508 * gpio-reserved-ranges = <0 4>, <5 3>, <9 5>, <11 2>, <15 2>,
513 * compatible = "some,gpio-controller";
515 * gpio-reserved-ranges = <3 2>, <10 1>;
569 (GENMASK64(BITS_PER_LONG_LONG - 1, ngpios) \
577 * @brief Makes a bitmask of reserved GPIOs from the @p "gpio-reserved-ranges"
588 * @p "gpio-reserved-ranges" property and @p "ngpios" argument
600 * @p "gpio-reserved-ranges" and @p "ngpios" properties
610 * @brief Makes a bitmask of allowed GPIOs from DT @p "gpio-reserved-ranges"
620 * compatible = "some,gpio-controller";
622 * gpio-reserved-ranges = <0 8>, <9 5>, <15 16>;
662 ((GENMASK64(ngpios - 1, 0) & \
664 (GENMASK64(ngpios - 1, 0))) \
670 * @p "gpio-reserved-ranges" property and @p "ngpios" argument
718 * @param port Device struct for the GPIO device.
726 typedef void (*gpio_callback_handler_t)(const struct device *port,
786 /* Trigger detection on pin rising or falling edge. */
793 int (*pin_configure)(const struct device *port, gpio_pin_t pin,
796 int (*pin_get_config)(const struct device *port, gpio_pin_t pin,
799 int (*port_get_raw)(const struct device *port,
801 int (*port_set_masked_raw)(const struct device *port,
804 int (*port_set_bits_raw)(const struct device *port,
806 int (*port_clear_bits_raw)(const struct device *port,
808 int (*port_toggle_bits)(const struct device *port,
810 int (*pin_interrupt_configure)(const struct device *port,
811 gpio_pin_t pin,
813 int (*manage_callback)(const struct device *port,
818 int (*port_get_direction)(const struct device *port, gpio_port_pins_t map,
828 * @brief Validate that GPIO port is ready.
837 /* Validate port is ready */ in gpio_is_ready_dt()
838 return device_is_ready(spec->port); in gpio_is_ready_dt()
842 * @brief Configure pin interrupt.
848 * @param port Pointer to device structure for the driver instance.
849 * @param pin Pin number.
853 * @retval -ENOSYS If the operation is not implemented by the driver.
854 * @retval -ENOTSUP If any of the configuration options is not supported
856 * @retval -EINVAL Invalid argument.
857 * @retval -EBUSY Interrupt line required to configure pin interrupt is
859 * @retval -EIO I/O error when accessing an external GPIO chip.
860 * @retval -EWOULDBLOCK if operation would block.
862 __syscall int gpio_pin_interrupt_configure(const struct device *port,
863 gpio_pin_t pin,
866 static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port, in z_impl_gpio_pin_interrupt_configure() argument
867 gpio_pin_t pin, in z_impl_gpio_pin_interrupt_configure() argument
871 (const struct gpio_driver_api *)port->api; in z_impl_gpio_pin_interrupt_configure()
873 (const struct gpio_driver_config *)port->config; in z_impl_gpio_pin_interrupt_configure()
875 (const struct gpio_driver_data *)port->data; in z_impl_gpio_pin_interrupt_configure()
879 if (api->pin_interrupt_configure == NULL) { in z_impl_gpio_pin_interrupt_configure()
880 return -ENOSYS; in z_impl_gpio_pin_interrupt_configure()
907 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in z_impl_gpio_pin_interrupt_configure()
908 "Unsupported pin"); in z_impl_gpio_pin_interrupt_configure()
911 ((data->invert & (gpio_port_pins_t)BIT(pin)) != 0)) { in z_impl_gpio_pin_interrupt_configure()
924 return api->pin_interrupt_configure(port, pin, mode, trig); in z_impl_gpio_pin_interrupt_configure()
928 * @brief Configure pin interrupts from a @p gpio_dt_spec.
932 * gpio_pin_interrupt_configure(spec->port, spec->pin, flags);
934 * The <tt>spec->dt_flags</tt> value is not used.
943 return gpio_pin_interrupt_configure(spec->port, spec->pin, flags); in gpio_pin_interrupt_configure_dt()
947 * @brief Configure a single pin.
949 * @param port Pointer to device structure for the driver instance.
950 * @param pin Pin number to configure.
951 * @param flags Flags for pin configuration: 'GPIO input/output configuration
952 * flags', 'GPIO pin drive flags', 'GPIO pin bias flags'.
955 * @retval -ENOTSUP if any of the configuration options is not supported
957 * @retval -EINVAL Invalid argument.
958 * @retval -EIO I/O error when accessing an external GPIO chip.
959 * @retval -EWOULDBLOCK if operation would block.
961 __syscall int gpio_pin_configure(const struct device *port,
962 gpio_pin_t pin,
965 static inline int z_impl_gpio_pin_configure(const struct device *port, in z_impl_gpio_pin_configure() argument
966 gpio_pin_t pin, in z_impl_gpio_pin_configure() argument
970 (const struct gpio_driver_api *)port->api; in z_impl_gpio_pin_configure()
972 (const struct gpio_driver_config *)port->config; in z_impl_gpio_pin_configure()
974 (struct gpio_driver_data *)port->data; in z_impl_gpio_pin_configure()
1005 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in z_impl_gpio_pin_configure()
1006 "Unsupported pin"); in z_impl_gpio_pin_configure()
1009 data->invert |= (gpio_port_pins_t)BIT(pin); in z_impl_gpio_pin_configure()
1011 data->invert &= ~(gpio_port_pins_t)BIT(pin); in z_impl_gpio_pin_configure()
1014 return api->pin_configure(port, pin, flags); in z_impl_gpio_pin_configure()
1018 * @brief Configure a single pin from a @p gpio_dt_spec and some extra flags.
1022 * gpio_pin_configure(spec->port, spec->pin, spec->dt_flags | extra_flags);
1031 return gpio_pin_configure(spec->port, in gpio_pin_configure_dt()
1032 spec->pin, in gpio_pin_configure_dt()
1033 spec->dt_flags | extra_flags); in gpio_pin_configure_dt()
1037 * @brief Get direction of select pins in a port.
1039 * Retrieve direction of each pin specified in @p map.
1044 * @param port Pointer to the device structure for the driver instance.
1045 * @param map Bitmap of pin directions to query.
1050 * @retval -ENOSYS if the underlying driver does not support this call.
1051 * @retval -EIO I/O error when accessing an external GPIO chip.
1052 * @retval -EWOULDBLOCK if operation would block.
1054 __syscall int gpio_port_get_direction(const struct device *port, gpio_port_pins_t map,
1058 static inline int z_impl_gpio_port_get_direction(const struct device *port, gpio_port_pins_t map, in z_impl_gpio_port_get_direction() argument
1062 const struct gpio_driver_api *api = (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_get_direction()
1064 if (api->port_get_direction == NULL) { in z_impl_gpio_port_get_direction()
1065 return -ENOSYS; in z_impl_gpio_port_get_direction()
1068 return api->port_get_direction(port, map, inputs, outputs); in z_impl_gpio_port_get_direction()
1073 * @brief Check if @p pin is configured for input
1075 * @param port Pointer to device structure for the driver instance.
1076 * @param pin Pin number to query the direction of
1078 * @retval 1 if @p pin is configured as @ref GPIO_INPUT.
1079 * @retval 0 if @p pin is not configured as @ref GPIO_INPUT.
1080 * @retval -ENOSYS if the underlying driver does not support this call.
1081 * @retval -EIO I/O error when accessing an external GPIO chip.
1082 * @retval -EWOULDBLOCK if operation would block.
1084 static inline int gpio_pin_is_input(const struct device *port, gpio_pin_t pin) in gpio_pin_is_input() argument
1089 (const struct gpio_driver_config *)port->config; in gpio_pin_is_input()
1091 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, "Unsupported pin"); in gpio_pin_is_input()
1093 rv = gpio_port_get_direction(port, BIT(pin), &pins, NULL); in gpio_pin_is_input()
1098 return (int)!!((gpio_port_pins_t)BIT(pin) & pins); in gpio_pin_is_input()
1102 * @brief Check if a single pin from @p gpio_dt_spec is configured for input
1106 * gpio_pin_is_input(spec->port, spec->pin);
1114 return gpio_pin_is_input(spec->port, spec->pin); in gpio_pin_is_input_dt()
1118 * @brief Check if @p pin is configured for output
1120 * @param port Pointer to device structure for the driver instance.
1121 * @param pin Pin number to query the direction of
1123 * @retval 1 if @p pin is configured as @ref GPIO_OUTPUT.
1124 * @retval 0 if @p pin is not configured as @ref GPIO_OUTPUT.
1125 * @retval -ENOSYS if the underlying driver does not support this call.
1126 * @retval -EIO I/O error when accessing an external GPIO chip.
1127 * @retval -EWOULDBLOCK if operation would block.
1129 static inline int gpio_pin_is_output(const struct device *port, gpio_pin_t pin) in gpio_pin_is_output() argument
1134 (const struct gpio_driver_config *)port->config; in gpio_pin_is_output()
1136 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, "Unsupported pin"); in gpio_pin_is_output()
1138 rv = gpio_port_get_direction(port, BIT(pin), NULL, &pins); in gpio_pin_is_output()
1143 return (int)!!((gpio_port_pins_t)BIT(pin) & pins); in gpio_pin_is_output()
1147 * @brief Check if a single pin from @p gpio_dt_spec is configured for output
1151 * gpio_pin_is_output(spec->port, spec->pin);
1159 return gpio_pin_is_output(spec->port, spec->pin); in gpio_pin_is_output_dt()
1163 * @brief Get a configuration of a single pin.
1165 * @param port Pointer to device structure for the driver instance.
1166 * @param pin Pin number which configuration is get.
1171 * @retval -ENOSYS if getting current pin configuration is not implemented
1173 * @retval -EINVAL Invalid argument.
1174 * @retval -EIO I/O error when accessing an external GPIO chip.
1175 * @retval -EWOULDBLOCK if operation would block.
1177 __syscall int gpio_pin_get_config(const struct device *port, gpio_pin_t pin,
1181 static inline int z_impl_gpio_pin_get_config(const struct device *port, in z_impl_gpio_pin_get_config() argument
1182 gpio_pin_t pin, in z_impl_gpio_pin_get_config() argument
1186 (const struct gpio_driver_api *)port->api; in z_impl_gpio_pin_get_config()
1188 if (api->pin_get_config == NULL) in z_impl_gpio_pin_get_config()
1189 return -ENOSYS; in z_impl_gpio_pin_get_config()
1191 return api->pin_get_config(port, pin, flags); in z_impl_gpio_pin_get_config()
1196 * @brief Get a configuration of a single pin from a @p gpio_dt_spec.
1200 * gpio_pin_get_config(spec->port, spec->pin, flags);
1210 return gpio_pin_get_config(spec->port, spec->pin, flags); in gpio_pin_get_config_dt()
1214 * @brief Get physical level of all input pins in a port.
1216 * A low physical level on the pin will be interpreted as value 0. A high
1220 * Value of a pin with index n will be represented by bit n in the returned
1221 * port value.
1223 * @param port Pointer to the device structure for the driver instance.
1224 * @param value Pointer to a variable where pin values will be stored.
1227 * @retval -EIO I/O error when accessing an external GPIO chip.
1228 * @retval -EWOULDBLOCK if operation would block.
1230 __syscall int gpio_port_get_raw(const struct device *port,
1233 static inline int z_impl_gpio_port_get_raw(const struct device *port, in z_impl_gpio_port_get_raw() argument
1237 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_get_raw()
1239 return api->port_get_raw(port, value); in z_impl_gpio_port_get_raw()
1243 * @brief Get logical level of all input pins in a port.
1245 * Get logical level of an input pin taking into account GPIO_ACTIVE_LOW flag.
1246 * If pin is configured as Active High, a low physical level will be interpreted
1247 * as logical value 0. If pin is configured as Active Low, a low physical level
1250 * Value of a pin with index n will be represented by bit n in the returned
1251 * port value.
1253 * @param port Pointer to the device structure for the driver instance.
1254 * @param value Pointer to a variable where pin values will be stored.
1257 * @retval -EIO I/O error when accessing an external GPIO chip.
1258 * @retval -EWOULDBLOCK if operation would block.
1260 static inline int gpio_port_get(const struct device *port, in gpio_port_get() argument
1264 (const struct gpio_driver_data *)port->data; in gpio_port_get()
1267 ret = gpio_port_get_raw(port, value); in gpio_port_get()
1269 *value ^= data->invert; in gpio_port_get()
1276 * @brief Set physical level of output pins in a port.
1278 * Writing value 0 to the pin will set it to a low physical level. Writing
1282 * Pin with index n is represented by bit n in mask and value parameter.
1284 * @param port Pointer to the device structure for the driver instance.
1289 * @retval -EIO I/O error when accessing an external GPIO chip.
1290 * @retval -EWOULDBLOCK if operation would block.
1292 __syscall int gpio_port_set_masked_raw(const struct device *port,
1296 static inline int z_impl_gpio_port_set_masked_raw(const struct device *port, in z_impl_gpio_port_set_masked_raw() argument
1301 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_set_masked_raw()
1303 return api->port_set_masked_raw(port, mask, value); in z_impl_gpio_port_set_masked_raw()
1307 * @brief Set logical level of output pins in a port.
1309 * Set logical level of an output pin taking into account GPIO_ACTIVE_LOW flag.
1310 * Value 0 sets the pin in logical 0 / inactive state. Value 1 sets the pin in
1311 * logical 1 / active state. If pin is configured as Active High, the default,
1312 * setting it in inactive state will force the pin to a low physical level. If
1313 * pin is configured as Active Low, setting it in inactive state will force the
1314 * pin to a high physical level.
1316 * Pin with index n is represented by bit n in mask and value parameter.
1318 * @param port Pointer to the device structure for the driver instance.
1323 * @retval -EIO I/O error when accessing an external GPIO chip.
1324 * @retval -EWOULDBLOCK if operation would block.
1326 static inline int gpio_port_set_masked(const struct device *port, in gpio_port_set_masked() argument
1331 (const struct gpio_driver_data *)port->data; in gpio_port_set_masked()
1333 value ^= data->invert; in gpio_port_set_masked()
1335 return gpio_port_set_masked_raw(port, mask, value); in gpio_port_set_masked()
1341 * @param port Pointer to the device structure for the driver instance.
1345 * @retval -EIO I/O error when accessing an external GPIO chip.
1346 * @retval -EWOULDBLOCK if operation would block.
1348 __syscall int gpio_port_set_bits_raw(const struct device *port,
1351 static inline int z_impl_gpio_port_set_bits_raw(const struct device *port, in z_impl_gpio_port_set_bits_raw() argument
1355 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_set_bits_raw()
1357 return api->port_set_bits_raw(port, pins); in z_impl_gpio_port_set_bits_raw()
1363 * @param port Pointer to the device structure for the driver instance.
1367 * @retval -EIO I/O error when accessing an external GPIO chip.
1368 * @retval -EWOULDBLOCK if operation would block.
1370 static inline int gpio_port_set_bits(const struct device *port, in gpio_port_set_bits() argument
1373 return gpio_port_set_masked(port, pins, pins); in gpio_port_set_bits()
1379 * @param port Pointer to the device structure for the driver instance.
1383 * @retval -EIO I/O error when accessing an external GPIO chip.
1384 * @retval -EWOULDBLOCK if operation would block.
1386 __syscall int gpio_port_clear_bits_raw(const struct device *port,
1389 static inline int z_impl_gpio_port_clear_bits_raw(const struct device *port, in z_impl_gpio_port_clear_bits_raw() argument
1393 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_clear_bits_raw()
1395 return api->port_clear_bits_raw(port, pins); in z_impl_gpio_port_clear_bits_raw()
1401 * @param port Pointer to the device structure for the driver instance.
1405 * @retval -EIO I/O error when accessing an external GPIO chip.
1406 * @retval -EWOULDBLOCK if operation would block.
1408 static inline int gpio_port_clear_bits(const struct device *port, in gpio_port_clear_bits() argument
1411 return gpio_port_set_masked(port, pins, 0); in gpio_port_clear_bits()
1417 * @param port Pointer to the device structure for the driver instance.
1421 * @retval -EIO I/O error when accessing an external GPIO chip.
1422 * @retval -EWOULDBLOCK if operation would block.
1424 __syscall int gpio_port_toggle_bits(const struct device *port,
1427 static inline int z_impl_gpio_port_toggle_bits(const struct device *port, in z_impl_gpio_port_toggle_bits() argument
1431 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_toggle_bits()
1433 return api->port_toggle_bits(port, pins); in z_impl_gpio_port_toggle_bits()
1439 * @param port Pointer to the device structure for the driver instance.
1444 * @retval -EIO I/O error when accessing an external GPIO chip.
1445 * @retval -EWOULDBLOCK if operation would block.
1447 static inline int gpio_port_set_clr_bits_raw(const struct device *port, in gpio_port_set_clr_bits_raw() argument
1453 return gpio_port_set_masked_raw(port, set_pins | clear_pins, set_pins); in gpio_port_set_clr_bits_raw()
1459 * @param port Pointer to the device structure for the driver instance.
1464 * @retval -EIO I/O error when accessing an external GPIO chip.
1465 * @retval -EWOULDBLOCK if operation would block.
1467 static inline int gpio_port_set_clr_bits(const struct device *port, in gpio_port_set_clr_bits() argument
1473 return gpio_port_set_masked(port, set_pins | clear_pins, set_pins); in gpio_port_set_clr_bits()
1477 * @brief Get physical level of an input pin.
1479 * A low physical level on the pin will be interpreted as value 0. A high
1483 * @param port Pointer to the device structure for the driver instance.
1484 * @param pin Pin number.
1486 * @retval 1 If pin physical level is high.
1487 * @retval 0 If pin physical level is low.
1488 * @retval -EIO I/O error when accessing an external GPIO chip.
1489 * @retval -EWOULDBLOCK if operation would block.
1491 static inline int gpio_pin_get_raw(const struct device *port, gpio_pin_t pin) in gpio_pin_get_raw() argument
1494 (const struct gpio_driver_config *)port->config; in gpio_pin_get_raw()
1498 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_get_raw()
1499 "Unsupported pin"); in gpio_pin_get_raw()
1501 ret = gpio_port_get_raw(port, &value); in gpio_pin_get_raw()
1503 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0; in gpio_pin_get_raw()
1510 * @brief Get logical level of an input pin.
1512 * Get logical level of an input pin taking into account GPIO_ACTIVE_LOW flag.
1513 * If pin is configured as Active High, a low physical level will be interpreted
1514 * as logical value 0. If pin is configured as Active Low, a low physical level
1517 * Note: If pin is configured as Active High, the default, gpio_pin_get()
1520 * @param port Pointer to the device structure for the driver instance.
1521 * @param pin Pin number.
1523 * @retval 1 If pin logical value is 1 / active.
1524 * @retval 0 If pin logical value is 0 / inactive.
1525 * @retval -EIO I/O error when accessing an external GPIO chip.
1526 * @retval -EWOULDBLOCK if operation would block.
1528 static inline int gpio_pin_get(const struct device *port, gpio_pin_t pin) in gpio_pin_get() argument
1531 (const struct gpio_driver_config *)port->config; in gpio_pin_get()
1535 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_get()
1536 "Unsupported pin"); in gpio_pin_get()
1538 ret = gpio_port_get(port, &value); in gpio_pin_get()
1540 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0; in gpio_pin_get()
1547 * @brief Get logical level of an input pin from a @p gpio_dt_spec.
1551 * gpio_pin_get(spec->port, spec->pin);
1558 return gpio_pin_get(spec->port, spec->pin); in gpio_pin_get_dt()
1562 * @brief Set physical level of an output pin.
1564 * Writing value 0 to the pin will set it to a low physical level. Writing any
1568 * @param port Pointer to the device structure for the driver instance.
1569 * @param pin Pin number.
1570 * @param value Value assigned to the pin.
1573 * @retval -EIO I/O error when accessing an external GPIO chip.
1574 * @retval -EWOULDBLOCK if operation would block.
1576 static inline int gpio_pin_set_raw(const struct device *port, gpio_pin_t pin, in gpio_pin_set_raw() argument
1580 (const struct gpio_driver_config *)port->config; in gpio_pin_set_raw()
1583 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_set_raw()
1584 "Unsupported pin"); in gpio_pin_set_raw()
1587 ret = gpio_port_set_bits_raw(port, (gpio_port_pins_t)BIT(pin)); in gpio_pin_set_raw()
1589 ret = gpio_port_clear_bits_raw(port, (gpio_port_pins_t)BIT(pin)); in gpio_pin_set_raw()
1596 * @brief Set logical level of an output pin.
1598 * Set logical level of an output pin taking into account GPIO_ACTIVE_LOW flag.
1599 * Value 0 sets the pin in logical 0 / inactive state. Any value other than 0
1600 * sets the pin in logical 1 / active state. If pin is configured as Active
1601 * High, the default, setting it in inactive state will force the pin to a low
1602 * physical level. If pin is configured as Active Low, setting it in inactive
1603 * state will force the pin to a high physical level.
1605 * Note: If pin is configured as Active High, gpio_pin_set() function is
1608 * @param port Pointer to the device structure for the driver instance.
1609 * @param pin Pin number.
1610 * @param value Value assigned to the pin.
1613 * @retval -EIO I/O error when accessing an external GPIO chip.
1614 * @retval -EWOULDBLOCK if operation would block.
1616 static inline int gpio_pin_set(const struct device *port, gpio_pin_t pin, in gpio_pin_set() argument
1620 (const struct gpio_driver_config *)port->config; in gpio_pin_set()
1622 (const struct gpio_driver_data *)port->data; in gpio_pin_set()
1624 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_set()
1625 "Unsupported pin"); in gpio_pin_set()
1627 if (data->invert & (gpio_port_pins_t)BIT(pin)) { in gpio_pin_set()
1631 return gpio_pin_set_raw(port, pin, value); in gpio_pin_set()
1635 * @brief Set logical level of a output pin from a @p gpio_dt_spec.
1639 * gpio_pin_set(spec->port, spec->pin, value);
1642 * @param value Value assigned to the pin.
1647 return gpio_pin_set(spec->port, spec->pin, value); in gpio_pin_set_dt()
1651 * @brief Toggle pin level.
1653 * @param port Pointer to the device structure for the driver instance.
1654 * @param pin Pin number.
1657 * @retval -EIO I/O error when accessing an external GPIO chip.
1658 * @retval -EWOULDBLOCK if operation would block.
1660 static inline int gpio_pin_toggle(const struct device *port, gpio_pin_t pin) in gpio_pin_toggle() argument
1663 (const struct gpio_driver_config *)port->config; in gpio_pin_toggle()
1665 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_toggle()
1666 "Unsupported pin"); in gpio_pin_toggle()
1668 return gpio_port_toggle_bits(port, (gpio_port_pins_t)BIT(pin)); in gpio_pin_toggle()
1672 * @brief Toggle pin level from a @p gpio_dt_spec.
1676 * gpio_pin_toggle(spec->port, spec->pin);
1683 return gpio_pin_toggle(spec->port, spec->pin); in gpio_pin_toggle_dt()
1699 callback->handler = handler; in gpio_init_callback()
1700 callback->pin_mask = pin_mask; in gpio_init_callback()
1705 * @param port Pointer to the device structure for the driver instance.
1708 * @retval -ENOSYS If driver does not implement the operation
1709 * @retval -errno Other negative errno code on failure.
1715 * Note: enables to add as many callback as needed on the same port.
1717 static inline int gpio_add_callback(const struct device *port, in gpio_add_callback() argument
1721 (const struct gpio_driver_api *)port->api; in gpio_add_callback()
1723 if (api->manage_callback == NULL) { in gpio_add_callback()
1724 return -ENOSYS; in gpio_add_callback()
1727 return api->manage_callback(port, callback, true); in gpio_add_callback()
1735 * gpio_add_callback(spec->port, callback);
1744 return gpio_add_callback(spec->port, callback); in gpio_add_callback_dt()
1749 * @param port Pointer to the device structure for the driver instance.
1752 * @retval -ENOSYS If driver does not implement the operation
1753 * @retval -errno Other negative errno code on failure.
1765 static inline int gpio_remove_callback(const struct device *port, in gpio_remove_callback() argument
1769 (const struct gpio_driver_api *)port->api; in gpio_remove_callback()
1771 if (api->manage_callback == NULL) { in gpio_remove_callback()
1772 return -ENOSYS; in gpio_remove_callback()
1775 return api->manage_callback(port, callback, false); in gpio_remove_callback()
1783 * gpio_remove_callback(spec->port, callback);
1792 return gpio_remove_callback(spec->port, callback); in gpio_remove_callback_dt()
1807 * @retval -ENOSYS If driver does not implement the operation
1814 (const struct gpio_driver_api *)dev->api; in z_impl_gpio_get_pending_int()
1816 if (api->get_pending_int == NULL) { in z_impl_gpio_get_pending_int()
1817 return -ENOSYS; in z_impl_gpio_get_pending_int()
1820 return api->get_pending_int(dev); in z_impl_gpio_get_pending_int()