1# Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd. 2# SPDX-License-Identifier: Apache-2.0 3 4description: | 5 Espressif's pin controller is in charge of controlling pin configurations, pin 6 functionalities and pin properties as defined by pin states. In its turn, pin 7 states are composed by groups of pre-defined pin muxing definitions and user 8 provided pin properties. 9 10 Each Zephyr-based application has its own set of pin muxing/pin configuration 11 requirements. The next steps use ESP-WROVER-KIT's I2C_0 to illustrate how one 12 could change a node's pin state properties. Though based on a particular board, 13 the same steps can be tweaked to address specifics of any other target board. 14 15 Suppose an application running on top of the ESP-WROVER-KIT board, for some 16 reason it needs I2C_0's SDA signal to be routed to GPIO_33. When looking at 17 that board's original device tree source file (i.e., 'esp_wrover_kit.dts'), 18 you'll notice that the I2C_0 node is already assigned to a pre-defined state. 19 Below is highlighted the information that most interests us on that file 20 21 22 #include "esp_wrover_kit-pinctrl.dtsi" 23 24 &i2c0 { 25 ... 26 pinctrl-0 = <&i2c0_default>; 27 pinctrl-names = "default"; 28 }; 29 30 31 From the above excerpt, the pincrl-0 property is assigned the 'i2c0_default' 32 state value. This and other pin states of the board are defined on another file 33 (in this case, 'esp_wrover_kit-pinctrl.dtsi') on the same folder of the DTS file. 34 Check below the excerpt describing I2C_0's default state on that file 35 36 37 i2c0_default: i2c0_default { 38 group1 { 39 pinmux = <I2C0_SDA_GPIO21>, 40 <I2C0_SCL_GPIO22>; 41 bias-pull-up; 42 drive-open-drain; 43 output-high; 44 }; 45 }; 46 47 48 Only the 'pinmux' property above is actually required, other properties can 49 be chosen if meaningful for the target application and, of course, supported 50 by your target hardware. For example, some custom board may have an external 51 pull-up resistor soldered to GPIO_21's pin pad, in which case, 'bias-pull-up' 52 could be no longer required. 53 54 Back to our fictional application, the previous I2C_0 state definition does not 55 meet our expectations as we would like to route I2C_0's SDA signal to GPIO_33 56 instead of to GPIO_21. To achieve it, we need to update the 'pinmux' property 57 accordingly. 58 59 Note that replacing 'I2C0_SDA_GPIO21' by 'I2C0_SDA_GPIO33' is very tempting and 60 may even work, however, unless you have checked the hardware documentation first, 61 it is not recommended. That's because there are no guarantees that a particular 62 IO pin has the capability to route any specific signal. 63 64 The recommendation is to check the pinmux macros definitions available for the 65 target SoC in the following URL 66 67 68 https://github.com/zephyrproject-rtos/hal_espressif/tree/zephyr/include/dt-bindings/pinctrl 69 70 71 The ESP-WROVER-KIT board is based on the ESP32 SoC, in that case, we search 72 through the file 'esp32-pinctrl.h' in the above URL. Luckily for us, there is 73 one definition on that file that corresponds to our needs 74 75 76 #define I2C0_SDA_GPIO33 \ 77 ESP32_PINMUX(33, ESP_I2CEXT0_SDA_IN, ESP_I2CEXT0_SDA_OUT) 78 79 80 Now, we go back to edit 'esp_wrover_kit-pinctrl.dtsi' and create a new pin state 81 on that file (or replace/update the one already defined) using the pinmux macro 82 definition above, yielding 83 84 85 i2c0_default: i2c0_default { 86 group1 { 87 pinmux = <I2C0_SDA_GPIO33>, 88 <I2C0_SCL_GPIO22>; 89 bias-pull-up; 90 drive-open-drain; 91 output-high; 92 }; 93 }; 94 95 96 With proper modifications, the same steps above apply when using different 97 combinations of boards, SoCs, peripherals and peripheral pins. 98 99 Note: Not all pins are available for a given peripheral, it depends if that 100 pin supports a set of properties required by the target peripheral. 101 102 When defining a state, the pin muxing information is constrained to 103 the definitions at 'hal_espressif', however, pin properties (like 104 bias-push-pull, drive-open-drain, etc) can be freely chosen, given the 105 property is meaningful to the peripheral signal and that it is also 106 available in the target GPIO. 107 108 Another thing worth noting is that all pin properties should be grouped. 109 All pins sharing common properties go under a common group (in the above 110 example, all pins are in 'group1'). Other peripherals can have more than 111 one group. 112 113compatible: "espressif,esp32-pinctrl" 114 115include: base.yaml 116 117child-binding: 118 description: | 119 Espressif pin controller pin configuration state nodes. 120 child-binding: 121 description: 122 Espressif pin controller pin configuration group. 123 124 include: 125 - name: pincfg-node.yaml 126 property-allowlist: 127 - bias-disable 128 - bias-pull-down 129 - bias-pull-up 130 - drive-push-pull 131 - drive-open-drain 132 - input-enable 133 - output-enable 134 - output-high 135 - output-low 136 137 properties: 138 pinmux: 139 required: true 140 type: array 141 description: | 142 Each array element represents pin muxing information of an individual 143 pin. The array elements are pre-declared macros taken from Espressif's 144 HAL. 145