mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
refactor(uart): split UART HAL into separate component
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// The LL layer for UHCI register operations.
|
||||
// Note that most of the register operations in this layer are non-atomic operations.
|
||||
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include "hal/uhci_types.h"
|
||||
#include "soc/uhci_struct.h"
|
||||
#include "soc/dport_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for UHCI module
|
||||
*
|
||||
* @param group_id Group ID
|
||||
* @param enable true to enable, false to disable
|
||||
*/
|
||||
static inline void _uhci_ll_enable_bus_clock(int group_id, bool enable)
|
||||
{
|
||||
uint32_t reg_val = DPORT_READ_PERI_REG(DPORT_PERIP_CLK_EN_REG);
|
||||
if (group_id == 0) {
|
||||
reg_val &= ~DPORT_UHCI0_CLK_EN;
|
||||
reg_val |= enable << 8;
|
||||
} else {
|
||||
reg_val &= ~DPORT_UHCI1_CLK_EN;
|
||||
reg_val |= enable << 12;
|
||||
}
|
||||
DPORT_WRITE_PERI_REG(DPORT_PERIP_CLK_EN_REG, reg_val);
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define uhci_ll_enable_bus_clock(...) do { \
|
||||
(void)__DECLARE_RCC_ATOMIC_ENV; \
|
||||
_uhci_ll_enable_bus_clock(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Reset the UHCI module
|
||||
*
|
||||
* @param group_id Group ID
|
||||
*/
|
||||
static inline void _uhci_ll_reset_register(int group_id)
|
||||
{
|
||||
if (group_id == 0) {
|
||||
DPORT_WRITE_PERI_REG(DPORT_PERIP_RST_EN_REG, DPORT_UHCI0_RST);
|
||||
DPORT_WRITE_PERI_REG(DPORT_PERIP_RST_EN_REG, 0);
|
||||
} else {
|
||||
DPORT_WRITE_PERI_REG(DPORT_PERIP_RST_EN_REG, DPORT_UHCI1_RST);
|
||||
DPORT_WRITE_PERI_REG(DPORT_PERIP_RST_EN_REG, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define uhci_ll_reset_register(...) do { \
|
||||
(void)__DECLARE_RCC_ATOMIC_ENV; \
|
||||
_uhci_ll_reset_register(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "hal/uart_periph.h"
|
||||
|
||||
/*
|
||||
Bunch of constants for every UART peripheral: GPIO signals, irqs, hw addr of registers etc
|
||||
*/
|
||||
const uart_signal_conn_t uart_periph_signal[SOC_UART_NUM] = {
|
||||
{
|
||||
.pins = {
|
||||
[SOC_UART_PERIPH_SIGNAL_TX] = {
|
||||
.default_gpio = U0TXD_GPIO_NUM,
|
||||
.iomux_func = U0TXD_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = U0TXD_OUT_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_RX] = {
|
||||
.default_gpio = U0RXD_GPIO_NUM,
|
||||
.iomux_func = U0RXD_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = U0RXD_IN_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_RTS] = {
|
||||
.default_gpio = U0RTS_GPIO_NUM,
|
||||
.iomux_func = U0RTS_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = U0RTS_OUT_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_CTS] = {
|
||||
.default_gpio = U0CTS_GPIO_NUM,
|
||||
.iomux_func = U0CTS_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = U0CTS_IN_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_DTR] = {
|
||||
.default_gpio = U0DTR_GPIO_NUM,
|
||||
.iomux_func = U0DTR_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = U0DTR_OUT_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_DSR] = {
|
||||
.default_gpio = U0DSR_GPIO_NUM,
|
||||
.iomux_func = U0DSR_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = U0DSR_IN_IDX,
|
||||
},
|
||||
},
|
||||
.irq = ETS_UART0_INTR_SOURCE,
|
||||
},
|
||||
|
||||
{
|
||||
.pins = {
|
||||
[SOC_UART_PERIPH_SIGNAL_TX] = {
|
||||
.default_gpio = U1TXD_GPIO_NUM,
|
||||
.iomux_func = U1TXD_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = U1TXD_OUT_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_RX] = {
|
||||
.default_gpio = U1RXD_GPIO_NUM,
|
||||
.iomux_func = U1RXD_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = U1RXD_IN_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_RTS] = {
|
||||
.default_gpio = U1RTS_GPIO_NUM,
|
||||
.iomux_func = U1RTS_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = U1RTS_OUT_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_CTS] = {
|
||||
.default_gpio = U1CTS_GPIO_NUM,
|
||||
.iomux_func = U1CTS_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = U1CTS_IN_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_DTR] = {
|
||||
.default_gpio = U1DTR_GPIO_NUM,
|
||||
.iomux_func = U1DTR_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = UINT8_MAX, // No DTR signal on ESP32 UART1
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_DSR] = {
|
||||
.default_gpio = U1DSR_GPIO_NUM,
|
||||
.iomux_func = U1DSR_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = UINT8_MAX, // No DSR signal on ESP32 UART1
|
||||
},
|
||||
},
|
||||
.irq = ETS_UART1_INTR_SOURCE,
|
||||
},
|
||||
|
||||
{
|
||||
.pins = {
|
||||
[SOC_UART_PERIPH_SIGNAL_TX] = {
|
||||
.default_gpio = U2TXD_GPIO_NUM,
|
||||
.iomux_func = U2TXD_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = U2TXD_OUT_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_RX] = {
|
||||
.default_gpio = U2RXD_GPIO_NUM,
|
||||
.iomux_func = U2RXD_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = U2RXD_IN_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_RTS] = {
|
||||
.default_gpio = U2RTS_GPIO_NUM,
|
||||
.iomux_func = U2RTS_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = U2RTS_OUT_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_CTS] = {
|
||||
.default_gpio = U2CTS_GPIO_NUM,
|
||||
.iomux_func = U2CTS_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = U2CTS_IN_IDX,
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_DTR] = {
|
||||
.default_gpio = U2DTR_GPIO_NUM,
|
||||
.iomux_func = U2DTR_MUX_FUNC,
|
||||
.input = 0,
|
||||
.signal = UINT8_MAX, // No DTR signal on ESP32 UART2
|
||||
},
|
||||
|
||||
[SOC_UART_PERIPH_SIGNAL_DSR] = {
|
||||
.default_gpio = U2DSR_GPIO_NUM,
|
||||
.iomux_func = U2DSR_MUX_FUNC,
|
||||
.input = 1,
|
||||
.signal = UINT8_MAX, // No DSR signal on ESP32 UART2
|
||||
},
|
||||
},
|
||||
.irq = ETS_UART2_INTR_SOURCE,
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user