1 /* 2 * Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * ESP32S3 SoC specific helpers for pinctrl driver 10 */ 11 12 #ifndef ZEPHYR_SOC_XTENSA_ESP32S3_PINCTRL_SOC_H_ 13 #define ZEPHYR_SOC_XTENSA_ESP32S3_PINCTRL_SOC_H_ 14 15 #include <zephyr/devicetree.h> 16 #include <zephyr/types.h> 17 18 #include <zephyr/dt-bindings/pinctrl/esp-pinctrl-common.h> 19 20 /** @cond INTERNAL_HIDDEN */ 21 22 /** Type for ESP32 pin. */ 23 struct pinctrl_soc_pin { 24 /** Pinmux settings (pin, direction and signal). */ 25 uint32_t pinmux; 26 /** Pincfg settings (bias). */ 27 uint32_t pincfg; 28 }; 29 30 typedef struct pinctrl_soc_pin pinctrl_soc_pin_t; 31 32 /** 33 * @brief Utility macro to initialize pinmux field in #pinctrl_pin_t. 34 * 35 * @param node_id Node identifier. 36 */ 37 #define Z_PINCTRL_ESP32_PINMUX_INIT(node_id, prop, idx) DT_PROP_BY_IDX(node_id, prop, idx) 38 39 /** 40 * @brief Utility macro to initialize pincfg field in #pinctrl_pin_t. 41 * 42 * @param node_id Node identifier. 43 */ 44 #define Z_PINCTRL_ESP32_PINCFG_INIT(node_id) \ 45 (((ESP32_NO_PULL * DT_PROP(node_id, bias_disable)) << ESP32_PIN_BIAS_SHIFT) | \ 46 ((ESP32_PULL_UP * DT_PROP(node_id, bias_pull_up)) << ESP32_PIN_BIAS_SHIFT) | \ 47 ((ESP32_PULL_DOWN * DT_PROP(node_id, bias_pull_down)) << ESP32_PIN_BIAS_SHIFT) | \ 48 ((ESP32_PUSH_PULL * DT_PROP(node_id, drive_push_pull)) << ESP32_PIN_DRV_SHIFT) | \ 49 ((ESP32_OPEN_DRAIN * DT_PROP(node_id, drive_open_drain)) << ESP32_PIN_DRV_SHIFT) | \ 50 ((ESP32_PIN_OUT_HIGH * DT_PROP(node_id, output_high)) << ESP32_PIN_OUT_SHIFT) | \ 51 ((ESP32_PIN_OUT_LOW * DT_PROP(node_id, output_low)) << ESP32_PIN_OUT_SHIFT) | \ 52 ((ESP32_PIN_OUT_EN * DT_PROP(node_id, output_enable)) << ESP32_PIN_EN_DIR_SHIFT) | \ 53 ((ESP32_PIN_IN_EN * DT_PROP(node_id, input_enable)) << ESP32_PIN_EN_DIR_SHIFT)) 54 55 /** 56 * @brief Utility macro to initialize each pin. 57 * 58 * @param node_id Node identifier. 59 * @param prop Property name. 60 * @param idx Property entry index. 61 */ 62 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ 63 {.pinmux = Z_PINCTRL_ESP32_PINMUX_INIT(node_id, prop, idx), \ 64 .pincfg = Z_PINCTRL_ESP32_PINCFG_INIT(node_id)}, 65 66 /** 67 * @brief Utility macro to initialize state pins contained in a given property. 68 * 69 * @param node_id Node identifier. 70 * @param prop Property name describing state pins. 71 */ 72 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ 73 { \ 74 DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \ 75 Z_PINCTRL_STATE_PIN_INIT) \ 76 } 77 78 /** @endcond */ 79 80 #endif /* ZEPHYR_SOC_XTENSA_ESP32S3_PINCTRL_SOC_H_ */ 81