1 // Copyright 2019 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 #pragma once 15 16 #include "soc/soc_caps.h" 17 #include "soc/uart_reg.h" 18 #include "soc/uart_struct.h" 19 #include "soc/periph_defs.h" 20 #include "soc/gpio_sig_map.h" 21 #include "soc/io_mux_reg.h" 22 #include "soc/uart_pins.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define SOC_UART_TX_PIN_IDX (0) 29 #define SOC_UART_RX_PIN_IDX (1) 30 #define SOC_UART_RTS_PIN_IDX (2) 31 #define SOC_UART_CTS_PIN_IDX (3) 32 33 /** 34 * @brief Macro that can be used to retrieve the signal of a certain pin for a 35 * certain UART. 36 */ 37 #define UART_PERIPH_SIGNAL(IDX, PIN) (uart_periph_signal[(IDX)].pins[(PIN)].signal) 38 39 typedef struct { 40 /* Default GPIO number for this UART pin in the IOMUX. 41 * This value can be -1 if there is no default GPIO for a pin. 42 * For example, ESP32-C3 doesn't have any default GPIO for 43 * U0CTS and U0RTS. */ 44 int32_t default_gpio : 15; 45 /* Func which should be assigned to the GPIO to be used as UART */ 46 int32_t iomux_func : 4; 47 /* Marks if the current UART pin is input (or not) */ 48 uint32_t input : 1; 49 /* Signal in the GPIO signal map. */ 50 uint32_t signal : 12; 51 } uart_periph_sig_t; 52 53 typedef struct { 54 const uart_periph_sig_t pins[SOC_UART_PINS_COUNT]; 55 const uint8_t irq; 56 const periph_module_t module; 57 } uart_signal_conn_t; 58 59 extern const uart_signal_conn_t uart_periph_signal[SOC_UART_NUM]; 60 61 #ifdef __cplusplus 62 } 63 #endif 64