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