Lines Matching +full:int +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
27 #include <zephyr/dt-bindings/gpio/gpio.h>
47 /** Enables pin as input. */
50 /** Enables pin as output, no change to the output state. */
53 /** Disables pin for both input and output. */
69 /** Configures GPIO pin as output and initializes it to a low state. */
71 /** Configures GPIO pin as output and initializes it to a high state. */
73 /** Configures GPIO pin as output and initializes it to a logic 0. */
77 /** Configures GPIO pin as output and initializes it to a logic 1. */
87 * interrupts. The interrupts can be sensitive to pin physical or logical level.
88 * Interrupts sensitive to pin logical level take into account GPIO_ACTIVE_LOW
89 * flag. If a pin was configured as Active Low, physical level low will be
96 * pin without changing any GPIO settings.
100 /** Disables GPIO pin interrupt. */
105 /* Enables GPIO pin interrupt. */
159 /** Configures GPIO interrupt to be triggered on pin rising edge and enables it.
165 /** Configures GPIO interrupt to be triggered on pin falling edge and enables
172 /** Configures GPIO interrupt to be triggered on pin rising or falling edge and
180 /** Configures GPIO interrupt to be triggered on pin physical level low and
186 /** Configures GPIO interrupt to be triggered on pin physical level high and
192 /** Configures GPIO interrupt to be triggered on pin state change to logical
200 /** Configures GPIO interrupt to be triggered on pin state change to logical
208 /** Configures GPIO interrupt to be triggered on pin logical level 0 and enables
215 /** Configures GPIO interrupt to be triggered on pin logical level 1 and enables
231 * The pin with index n is present in the set if and only if the bit
239 * The value for a pin with index n is high (physical mode) or active
241 * Otherwise the value for the pin is low (physical mode) or inactive
245 * that specifies which encoded pin values are valid for the operation.
250 * @brief Provides a type to hold a GPIO pin index.
252 * This reduced-size type is sufficient to record a pin number,
261 * bits of the full flags field, so use a reduced-size type to record
273 * configuration, whether pin or interrupt.
278 * @brief Container for GPIO pin information specified in devicetree
280 * This type contains a pointer to a GPIO device, pin number for a pin
281 * controlled by that device, and the subset of pin configuration
290 /** GPIO device controlling the pin */
292 /** The pin's number on the device */
293 gpio_pin_t pin; member
294 /** The pin's configuration flags as specified in devicetree */
307 * foo-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>,
318 * // .pin = 2,
325 * controller, pin number, and flags as shown above.
328 * @param prop lowercase-and-underscores property name
335 .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
350 * @param prop lowercase-and-underscores property name
365 * @param prop lowercase-and-underscores property name
377 * @param prop lowercase-and-underscores property name
390 * @param prop lowercase-and-underscores property name
403 * @param prop lowercase-and-underscores property name
418 * @param prop lowercase-and-underscores property name
430 * @param prop lowercase-and-underscores property name
448 * @param prop lowercase-and-underscores array property name
457 DT_PROP_BY_IDX(node_id, prop, sz_idx) - 1, \
463 * from @p "gpio-reserved-ranges"
481 * @brief Makes a bitmask of reserved GPIOs from DT @p "gpio-reserved-ranges"
484 * This macro returns the value as a bitmask of the @p "gpio-reserved-ranges"
486 * range @p 0...ngpios-1 and is specified as an array of value's pairs that
489 * For example, setting "gpio-reserved-ranges = <3 2>, <10 1>;"
499 * Also be aware that if @p ngpios is less than 32 (bit size of DT int type),
507 * compatible = "some,gpio-controller";
509 * gpio-reserved-ranges = <0 4>, <5 3>, <9 5>, <11 2>, <15 2>,
514 * compatible = "some,gpio-controller";
516 * gpio-reserved-ranges = <3 2>, <10 1>;
570 (GENMASK64(BITS_PER_LONG_LONG - 1, ngpios) \
578 * @brief Makes a bitmask of reserved GPIOs from the @p "gpio-reserved-ranges"
589 * @p "gpio-reserved-ranges" property and @p "ngpios" argument
601 * @p "gpio-reserved-ranges" and @p "ngpios" properties
611 * @brief Makes a bitmask of allowed GPIOs from DT @p "gpio-reserved-ranges"
621 * compatible = "some,gpio-controller";
623 * gpio-reserved-ranges = <0 8>, <9 5>, <15 16>;
663 ((GENMASK64(ngpios - 1, 0) & \
665 (GENMASK64(ngpios - 1, 0))) \
671 * @p "gpio-reserved-ranges" property and @p "ngpios" argument
787 /* Trigger detection on pin rising or falling edge. */
794 int (*pin_configure)(const struct device *port, gpio_pin_t pin,
797 int (*pin_get_config)(const struct device *port, gpio_pin_t pin,
800 int (*port_get_raw)(const struct device *port,
802 int (*port_set_masked_raw)(const struct device *port,
805 int (*port_set_bits_raw)(const struct device *port,
807 int (*port_clear_bits_raw)(const struct device *port,
809 int (*port_toggle_bits)(const struct device *port,
811 int (*pin_interrupt_configure)(const struct device *port,
812 gpio_pin_t pin,
814 int (*manage_callback)(const struct device *port,
819 int (*port_get_direction)(const struct device *port, gpio_port_pins_t map,
839 return device_is_ready(spec->port); in gpio_is_ready_dt()
843 * @brief Configure pin interrupt.
852 * @param pin Pin number.
856 * @retval -ENOSYS If the operation is not implemented by the driver.
857 * @retval -ENOTSUP If any of the configuration options is not supported
859 * @retval -EINVAL Invalid argument.
860 * @retval -EBUSY Interrupt line required to configure pin interrupt is
862 * @retval -EIO I/O error when accessing an external GPIO chip.
863 * @retval -EWOULDBLOCK if operation would block.
865 __syscall int gpio_pin_interrupt_configure(const struct device *port,
866 gpio_pin_t pin,
869 static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port, in z_impl_gpio_pin_interrupt_configure()
870 gpio_pin_t pin, in z_impl_gpio_pin_interrupt_configure() argument
874 (const struct gpio_driver_api *)port->api; in z_impl_gpio_pin_interrupt_configure()
876 (const struct gpio_driver_config *)port->config; in z_impl_gpio_pin_interrupt_configure()
878 (const struct gpio_driver_data *)port->data; in z_impl_gpio_pin_interrupt_configure()
881 int ret; in z_impl_gpio_pin_interrupt_configure()
883 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, interrupt_configure, port, pin, flags); in z_impl_gpio_pin_interrupt_configure()
885 if (api->pin_interrupt_configure == NULL) { in z_impl_gpio_pin_interrupt_configure()
886 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, -ENOSYS); in z_impl_gpio_pin_interrupt_configure()
887 return -ENOSYS; in z_impl_gpio_pin_interrupt_configure()
914 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in z_impl_gpio_pin_interrupt_configure()
915 "Unsupported pin"); in z_impl_gpio_pin_interrupt_configure()
918 ((data->invert & (gpio_port_pins_t)BIT(pin)) != 0)) { in z_impl_gpio_pin_interrupt_configure()
931 ret = api->pin_interrupt_configure(port, pin, mode, trig); in z_impl_gpio_pin_interrupt_configure()
932 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, ret); in z_impl_gpio_pin_interrupt_configure()
937 * @brief Configure pin interrupts from a @p gpio_dt_spec.
943 * gpio_pin_interrupt_configure(spec->port, spec->pin, flags);
945 * The <tt>spec->dt_flags</tt> value is not used.
951 static inline int gpio_pin_interrupt_configure_dt(const struct gpio_dt_spec *spec, in gpio_pin_interrupt_configure_dt()
954 return gpio_pin_interrupt_configure(spec->port, spec->pin, flags); in gpio_pin_interrupt_configure_dt()
958 * @brief Configure a single pin.
961 * @param pin Pin number to configure.
962 * @param flags Flags for pin configuration: 'GPIO input/output configuration
963 * flags', 'GPIO pin drive flags', 'GPIO pin bias flags'.
966 * @retval -ENOTSUP if any of the configuration options is not supported
968 * @retval -EINVAL Invalid argument.
969 * @retval -EIO I/O error when accessing an external GPIO chip.
970 * @retval -EWOULDBLOCK if operation would block.
972 __syscall int gpio_pin_configure(const struct device *port,
973 gpio_pin_t pin,
976 static inline int z_impl_gpio_pin_configure(const struct device *port, in z_impl_gpio_pin_configure()
977 gpio_pin_t pin, in z_impl_gpio_pin_configure() argument
981 (const struct gpio_driver_api *)port->api; in z_impl_gpio_pin_configure()
983 (const struct gpio_driver_config *)port->config; in z_impl_gpio_pin_configure()
985 (struct gpio_driver_data *)port->data; in z_impl_gpio_pin_configure()
986 int ret; in z_impl_gpio_pin_configure()
988 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, configure, port, pin, flags); in z_impl_gpio_pin_configure()
1019 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in z_impl_gpio_pin_configure()
1020 "Unsupported pin"); in z_impl_gpio_pin_configure()
1023 data->invert |= (gpio_port_pins_t)BIT(pin); in z_impl_gpio_pin_configure()
1025 data->invert &= ~(gpio_port_pins_t)BIT(pin); in z_impl_gpio_pin_configure()
1028 ret = api->pin_configure(port, pin, flags); in z_impl_gpio_pin_configure()
1029 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, configure, port, pin, ret); in z_impl_gpio_pin_configure()
1034 * @brief Configure a single pin from a @p gpio_dt_spec and some extra flags.
1038 * gpio_pin_configure(spec->port, spec->pin, spec->dt_flags | extra_flags);
1044 static inline int gpio_pin_configure_dt(const struct gpio_dt_spec *spec, in gpio_pin_configure_dt()
1047 return gpio_pin_configure(spec->port, in gpio_pin_configure_dt()
1048 spec->pin, in gpio_pin_configure_dt()
1049 spec->dt_flags | extra_flags); in gpio_pin_configure_dt()
1055 * Retrieve direction of each pin specified in @p map.
1061 * @param map Bitmap of pin directions to query.
1066 * @retval -ENOSYS if the underlying driver does not support this call.
1067 * @retval -EIO I/O error when accessing an external GPIO chip.
1068 * @retval -EWOULDBLOCK if operation would block.
1070 __syscall int gpio_port_get_direction(const struct device *port, gpio_port_pins_t map,
1074 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()
1078 const struct gpio_driver_api *api = (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_get_direction()
1079 int ret; in z_impl_gpio_port_get_direction()
1083 if (api->port_get_direction == NULL) { in z_impl_gpio_port_get_direction()
1084 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_direction, port, -ENOSYS); in z_impl_gpio_port_get_direction()
1085 return -ENOSYS; in z_impl_gpio_port_get_direction()
1088 ret = api->port_get_direction(port, map, inputs, outputs); in z_impl_gpio_port_get_direction()
1095 * @brief Check if @p pin is configured for input
1098 * @param pin Pin number to query the direction of
1100 * @retval 1 if @p pin is configured as @ref GPIO_INPUT.
1101 * @retval 0 if @p pin is not configured as @ref GPIO_INPUT.
1102 * @retval -ENOSYS if the underlying driver does not support this call.
1103 * @retval -EIO I/O error when accessing an external GPIO chip.
1104 * @retval -EWOULDBLOCK if operation would block.
1106 static inline int gpio_pin_is_input(const struct device *port, gpio_pin_t pin) in gpio_pin_is_input() argument
1108 int rv; in gpio_pin_is_input()
1111 (const struct gpio_driver_config *)port->config; in gpio_pin_is_input()
1113 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, "Unsupported pin"); in gpio_pin_is_input()
1115 rv = gpio_port_get_direction(port, BIT(pin), &pins, NULL); in gpio_pin_is_input()
1120 return (int)!!((gpio_port_pins_t)BIT(pin) & pins); in gpio_pin_is_input()
1124 * @brief Check if a single pin from @p gpio_dt_spec is configured for input
1128 * gpio_pin_is_input(spec->port, spec->pin);
1134 static inline int gpio_pin_is_input_dt(const struct gpio_dt_spec *spec) in gpio_pin_is_input_dt()
1136 return gpio_pin_is_input(spec->port, spec->pin); in gpio_pin_is_input_dt()
1140 * @brief Check if @p pin is configured for output
1143 * @param pin Pin number to query the direction of
1145 * @retval 1 if @p pin is configured as @ref GPIO_OUTPUT.
1146 * @retval 0 if @p pin is not configured as @ref GPIO_OUTPUT.
1147 * @retval -ENOSYS if the underlying driver does not support this call.
1148 * @retval -EIO I/O error when accessing an external GPIO chip.
1149 * @retval -EWOULDBLOCK if operation would block.
1151 static inline int gpio_pin_is_output(const struct device *port, gpio_pin_t pin) in gpio_pin_is_output() argument
1153 int rv; in gpio_pin_is_output()
1156 (const struct gpio_driver_config *)port->config; in gpio_pin_is_output()
1158 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, "Unsupported pin"); in gpio_pin_is_output()
1160 rv = gpio_port_get_direction(port, BIT(pin), NULL, &pins); in gpio_pin_is_output()
1165 return (int)!!((gpio_port_pins_t)BIT(pin) & pins); in gpio_pin_is_output()
1169 * @brief Check if a single pin from @p gpio_dt_spec is configured for output
1173 * gpio_pin_is_output(spec->port, spec->pin);
1179 static inline int gpio_pin_is_output_dt(const struct gpio_dt_spec *spec) in gpio_pin_is_output_dt()
1181 return gpio_pin_is_output(spec->port, spec->pin); in gpio_pin_is_output_dt()
1185 * @brief Get a configuration of a single pin.
1188 * @param pin Pin number which configuration is get.
1193 * @retval -ENOSYS if getting current pin configuration is not implemented
1195 * @retval -EINVAL Invalid argument.
1196 * @retval -EIO I/O error when accessing an external GPIO chip.
1197 * @retval -EWOULDBLOCK if operation would block.
1199 __syscall int gpio_pin_get_config(const struct device *port, gpio_pin_t pin,
1203 static inline int z_impl_gpio_pin_get_config(const struct device *port, in z_impl_gpio_pin_get_config()
1204 gpio_pin_t pin, in z_impl_gpio_pin_get_config() argument
1208 (const struct gpio_driver_api *)port->api; in z_impl_gpio_pin_get_config()
1209 int ret; in z_impl_gpio_pin_get_config()
1211 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, get_config, port, pin, *flags); in z_impl_gpio_pin_get_config()
1213 if (api->pin_get_config == NULL) { in z_impl_gpio_pin_get_config()
1214 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, -ENOSYS); in z_impl_gpio_pin_get_config()
1215 return -ENOSYS; in z_impl_gpio_pin_get_config()
1218 ret = api->pin_get_config(port, pin, flags); in z_impl_gpio_pin_get_config()
1219 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, ret); in z_impl_gpio_pin_get_config()
1225 * @brief Get a configuration of a single pin from a @p gpio_dt_spec.
1229 * gpio_pin_get_config(spec->port, spec->pin, flags);
1236 static inline int gpio_pin_get_config_dt(const struct gpio_dt_spec *spec, in gpio_pin_get_config_dt()
1239 return gpio_pin_get_config(spec->port, spec->pin, flags); in gpio_pin_get_config_dt()
1245 * A low physical level on the pin will be interpreted as value 0. A high
1249 * Value of a pin with index n will be represented by bit n in the returned
1253 * @param value Pointer to a variable where pin values will be stored.
1256 * @retval -EIO I/O error when accessing an external GPIO chip.
1257 * @retval -EWOULDBLOCK if operation would block.
1259 __syscall int gpio_port_get_raw(const struct device *port,
1262 static inline int z_impl_gpio_port_get_raw(const struct device *port, gpio_port_value_t *value) in z_impl_gpio_port_get_raw()
1264 const struct gpio_driver_api *api = (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_get_raw()
1265 int ret; in z_impl_gpio_port_get_raw()
1269 ret = api->port_get_raw(port, value); in z_impl_gpio_port_get_raw()
1277 * Get logical level of an input pin taking into account GPIO_ACTIVE_LOW flag.
1278 * If pin is configured as Active High, a low physical level will be interpreted
1279 * as logical value 0. If pin is configured as Active Low, a low physical level
1282 * Value of a pin with index n will be represented by bit n in the returned
1286 * @param value Pointer to a variable where pin values will be stored.
1289 * @retval -EIO I/O error when accessing an external GPIO chip.
1290 * @retval -EWOULDBLOCK if operation would block.
1292 static inline int gpio_port_get(const struct device *port, in gpio_port_get()
1296 (const struct gpio_driver_data *)port->data; in gpio_port_get()
1297 int ret; in gpio_port_get()
1301 *value ^= data->invert; in gpio_port_get()
1310 * Writing value 0 to the pin will set it to a low physical level. Writing
1314 * Pin with index n is represented by bit n in mask and value parameter.
1321 * @retval -EIO I/O error when accessing an external GPIO chip.
1322 * @retval -EWOULDBLOCK if operation would block.
1324 __syscall int gpio_port_set_masked_raw(const struct device *port,
1328 static inline int z_impl_gpio_port_set_masked_raw(const struct device *port, in z_impl_gpio_port_set_masked_raw()
1333 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_set_masked_raw()
1334 int ret; in z_impl_gpio_port_set_masked_raw()
1338 ret = api->port_set_masked_raw(port, mask, value); in z_impl_gpio_port_set_masked_raw()
1346 * Set logical level of an output pin taking into account GPIO_ACTIVE_LOW flag.
1347 * Value 0 sets the pin in logical 0 / inactive state. Value 1 sets the pin in
1348 * logical 1 / active state. If pin is configured as Active High, the default,
1349 * setting it in inactive state will force the pin to a low physical level. If
1350 * pin is configured as Active Low, setting it in inactive state will force the
1351 * pin to a high physical level.
1353 * Pin with index n is represented by bit n in mask and value parameter.
1360 * @retval -EIO I/O error when accessing an external GPIO chip.
1361 * @retval -EWOULDBLOCK if operation would block.
1363 static inline int gpio_port_set_masked(const struct device *port, in gpio_port_set_masked()
1368 (const struct gpio_driver_data *)port->data; in gpio_port_set_masked()
1370 value ^= data->invert; in gpio_port_set_masked()
1382 * @retval -EIO I/O error when accessing an external GPIO chip.
1383 * @retval -EWOULDBLOCK if operation would block.
1385 __syscall int gpio_port_set_bits_raw(const struct device *port,
1388 static inline int z_impl_gpio_port_set_bits_raw(const struct device *port, in z_impl_gpio_port_set_bits_raw()
1392 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_set_bits_raw()
1393 int ret; in z_impl_gpio_port_set_bits_raw()
1397 ret = api->port_set_bits_raw(port, pins); in z_impl_gpio_port_set_bits_raw()
1409 * @retval -EIO I/O error when accessing an external GPIO chip.
1410 * @retval -EWOULDBLOCK if operation would block.
1412 static inline int gpio_port_set_bits(const struct device *port, in gpio_port_set_bits()
1425 * @retval -EIO I/O error when accessing an external GPIO chip.
1426 * @retval -EWOULDBLOCK if operation would block.
1428 __syscall int gpio_port_clear_bits_raw(const struct device *port,
1431 static inline int z_impl_gpio_port_clear_bits_raw(const struct device *port, in z_impl_gpio_port_clear_bits_raw()
1435 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_clear_bits_raw()
1436 int ret; in z_impl_gpio_port_clear_bits_raw()
1440 ret = api->port_clear_bits_raw(port, pins); in z_impl_gpio_port_clear_bits_raw()
1452 * @retval -EIO I/O error when accessing an external GPIO chip.
1453 * @retval -EWOULDBLOCK if operation would block.
1455 static inline int gpio_port_clear_bits(const struct device *port, in gpio_port_clear_bits()
1468 * @retval -EIO I/O error when accessing an external GPIO chip.
1469 * @retval -EWOULDBLOCK if operation would block.
1471 __syscall int gpio_port_toggle_bits(const struct device *port,
1474 static inline int z_impl_gpio_port_toggle_bits(const struct device *port, in z_impl_gpio_port_toggle_bits()
1478 (const struct gpio_driver_api *)port->api; in z_impl_gpio_port_toggle_bits()
1479 int ret; in z_impl_gpio_port_toggle_bits()
1483 ret = api->port_toggle_bits(port, pins); in z_impl_gpio_port_toggle_bits()
1496 * @retval -EIO I/O error when accessing an external GPIO chip.
1497 * @retval -EWOULDBLOCK if operation would block.
1499 static inline int gpio_port_set_clr_bits_raw(const struct device *port, in gpio_port_set_clr_bits_raw()
1516 * @retval -EIO I/O error when accessing an external GPIO chip.
1517 * @retval -EWOULDBLOCK if operation would block.
1519 static inline int gpio_port_set_clr_bits(const struct device *port, in gpio_port_set_clr_bits()
1529 * @brief Get physical level of an input pin.
1531 * A low physical level on the pin will be interpreted as value 0. A high
1536 * @param pin Pin number.
1538 * @retval 1 If pin physical level is high.
1539 * @retval 0 If pin physical level is low.
1540 * @retval -EIO I/O error when accessing an external GPIO chip.
1541 * @retval -EWOULDBLOCK if operation would block.
1543 static inline int gpio_pin_get_raw(const struct device *port, gpio_pin_t pin) in gpio_pin_get_raw() argument
1546 (const struct gpio_driver_config *)port->config; in gpio_pin_get_raw()
1548 int ret; in gpio_pin_get_raw()
1550 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_get_raw()
1551 "Unsupported pin"); in gpio_pin_get_raw()
1555 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0; in gpio_pin_get_raw()
1562 * @brief Get logical level of an input pin.
1564 * Get logical level of an input pin taking into account GPIO_ACTIVE_LOW flag.
1565 * If pin is configured as Active High, a low physical level will be interpreted
1566 * as logical value 0. If pin is configured as Active Low, a low physical level
1569 * Note: If pin is configured as Active High, the default, gpio_pin_get()
1573 * @param pin Pin number.
1575 * @retval 1 If pin logical value is 1 / active.
1576 * @retval 0 If pin logical value is 0 / inactive.
1577 * @retval -EIO I/O error when accessing an external GPIO chip.
1578 * @retval -EWOULDBLOCK if operation would block.
1580 static inline int gpio_pin_get(const struct device *port, gpio_pin_t pin) in gpio_pin_get() argument
1583 (const struct gpio_driver_config *)port->config; in gpio_pin_get()
1585 int ret; in gpio_pin_get()
1587 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_get()
1588 "Unsupported pin"); in gpio_pin_get()
1592 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0; in gpio_pin_get()
1599 * @brief Get logical level of an input pin from a @p gpio_dt_spec.
1603 * gpio_pin_get(spec->port, spec->pin);
1608 static inline int gpio_pin_get_dt(const struct gpio_dt_spec *spec) in gpio_pin_get_dt()
1610 return gpio_pin_get(spec->port, spec->pin); in gpio_pin_get_dt()
1614 * @brief Set physical level of an output pin.
1616 * Writing value 0 to the pin will set it to a low physical level. Writing any
1621 * @param pin Pin number.
1622 * @param value Value assigned to the pin.
1625 * @retval -EIO I/O error when accessing an external GPIO chip.
1626 * @retval -EWOULDBLOCK if operation would block.
1628 static inline int gpio_pin_set_raw(const struct device *port, gpio_pin_t pin, in gpio_pin_set_raw() argument
1629 int value) in gpio_pin_set_raw()
1632 (const struct gpio_driver_config *)port->config; in gpio_pin_set_raw()
1633 int ret; in gpio_pin_set_raw()
1635 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_set_raw()
1636 "Unsupported pin"); in gpio_pin_set_raw()
1639 ret = gpio_port_set_bits_raw(port, (gpio_port_pins_t)BIT(pin)); in gpio_pin_set_raw()
1641 ret = gpio_port_clear_bits_raw(port, (gpio_port_pins_t)BIT(pin)); in gpio_pin_set_raw()
1648 * @brief Set logical level of an output pin.
1650 * Set logical level of an output pin taking into account GPIO_ACTIVE_LOW flag.
1651 * Value 0 sets the pin in logical 0 / inactive state. Any value other than 0
1652 * sets the pin in logical 1 / active state. If pin is configured as Active
1653 * High, the default, setting it in inactive state will force the pin to a low
1654 * physical level. If pin is configured as Active Low, setting it in inactive
1655 * state will force the pin to a high physical level.
1657 * Note: If pin is configured as Active High, gpio_pin_set() function is
1661 * @param pin Pin number.
1662 * @param value Value assigned to the pin.
1665 * @retval -EIO I/O error when accessing an external GPIO chip.
1666 * @retval -EWOULDBLOCK if operation would block.
1668 static inline int gpio_pin_set(const struct device *port, gpio_pin_t pin, in gpio_pin_set() argument
1669 int value) in gpio_pin_set()
1672 (const struct gpio_driver_config *)port->config; in gpio_pin_set()
1674 (const struct gpio_driver_data *)port->data; in gpio_pin_set()
1676 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_set()
1677 "Unsupported pin"); in gpio_pin_set()
1679 if (data->invert & (gpio_port_pins_t)BIT(pin)) { in gpio_pin_set()
1683 return gpio_pin_set_raw(port, pin, value); in gpio_pin_set()
1687 * @brief Set logical level of a output pin from a @p gpio_dt_spec.
1691 * gpio_pin_set(spec->port, spec->pin, value);
1694 * @param value Value assigned to the pin.
1697 static inline int gpio_pin_set_dt(const struct gpio_dt_spec *spec, int value) in gpio_pin_set_dt()
1699 return gpio_pin_set(spec->port, spec->pin, value); in gpio_pin_set_dt()
1703 * @brief Toggle pin level.
1706 * @param pin Pin number.
1709 * @retval -EIO I/O error when accessing an external GPIO chip.
1710 * @retval -EWOULDBLOCK if operation would block.
1712 static inline int gpio_pin_toggle(const struct device *port, gpio_pin_t pin) in gpio_pin_toggle() argument
1715 (const struct gpio_driver_config *)port->config; in gpio_pin_toggle()
1717 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, in gpio_pin_toggle()
1718 "Unsupported pin"); in gpio_pin_toggle()
1720 return gpio_port_toggle_bits(port, (gpio_port_pins_t)BIT(pin)); in gpio_pin_toggle()
1724 * @brief Toggle pin level from a @p gpio_dt_spec.
1728 * gpio_pin_toggle(spec->port, spec->pin);
1733 static inline int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec) in gpio_pin_toggle_dt()
1735 return gpio_pin_toggle(spec->port, spec->pin); in gpio_pin_toggle_dt()
1753 callback->handler = handler; in gpio_init_callback()
1754 callback->pin_mask = pin_mask; in gpio_init_callback()
1764 * @retval -ENOSYS If driver does not implement the operation
1765 * @retval -errno Other negative errno code on failure.
1773 static inline int gpio_add_callback(const struct device *port, in gpio_add_callback()
1777 (const struct gpio_driver_api *)port->api; in gpio_add_callback()
1778 int ret; in gpio_add_callback()
1782 if (api->manage_callback == NULL) { in gpio_add_callback()
1783 SYS_PORT_TRACING_FUNC_EXIT(gpio, add_callback, port, -ENOSYS); in gpio_add_callback()
1784 return -ENOSYS; in gpio_add_callback()
1787 ret = api->manage_callback(port, callback, true); in gpio_add_callback()
1797 * gpio_add_callback(spec->port, callback);
1803 static inline int gpio_add_callback_dt(const struct gpio_dt_spec *spec, in gpio_add_callback_dt()
1806 return gpio_add_callback(spec->port, callback); in gpio_add_callback_dt()
1814 * @retval -ENOSYS If driver does not implement the operation
1815 * @retval -errno Other negative errno code on failure.
1827 static inline int gpio_remove_callback(const struct device *port, in gpio_remove_callback()
1831 (const struct gpio_driver_api *)port->api; in gpio_remove_callback()
1832 int ret; in gpio_remove_callback()
1836 if (api->manage_callback == NULL) { in gpio_remove_callback()
1837 SYS_PORT_TRACING_FUNC_EXIT(gpio, remove_callback, port, -ENOSYS); in gpio_remove_callback()
1838 return -ENOSYS; in gpio_remove_callback()
1841 ret = api->manage_callback(port, callback, false); in gpio_remove_callback()
1851 * gpio_remove_callback(spec->port, callback);
1857 static inline int gpio_remove_callback_dt(const struct gpio_dt_spec *spec, in gpio_remove_callback_dt()
1860 return gpio_remove_callback(spec->port, callback); in gpio_remove_callback_dt()
1875 * @retval -ENOSYS If driver does not implement the operation
1877 __syscall int gpio_get_pending_int(const struct device *dev);
1879 static inline int z_impl_gpio_get_pending_int(const struct device *dev) in z_impl_gpio_get_pending_int()
1882 (const struct gpio_driver_api *)dev->api; in z_impl_gpio_get_pending_int()
1883 int ret; in z_impl_gpio_get_pending_int()
1887 if (api->get_pending_int == NULL) { in z_impl_gpio_get_pending_int()
1888 SYS_PORT_TRACING_FUNC_EXIT(gpio, get_pending_int, dev, -ENOSYS); in z_impl_gpio_get_pending_int()
1889 return -ENOSYS; in z_impl_gpio_get_pending_int()
1892 ret = api->get_pending_int(dev); in z_impl_gpio_get_pending_int()