Motion_EC_HC32_archived/drivers/drv_usart.h

161 lines
5.4 KiB
C
Raw Normal View History

/*
* @Description:
* @Date: 2022-01-10 17:36:12
* @LastEditors: CK.Zh
* @LastEditTime: 2022-01-10 19:58:24
* @FilePath: /motion_ec_rtt/drivers/drv_usart.h
*/
/*
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-9-1 DongBowen first version
*/
#ifndef __DRV_USART_H__
#define __DRV_USART_H__
#include <rtthread.h>
#include "rtdevice.h"
#include "board_config.h"
/* hc config class */
struct hc_uart_cfg
{
const char *name;
M0P_UART_TypeDef *uart;
en_sysctrl_peripheral_gate_t uart_periph;
IRQn_Type irqn;
en_gpio_port_t rx_port;
en_gpio_pin_t rx_pin;
en_gpio_af_t rx_af;
en_gpio_port_t tx_port;
en_gpio_pin_t tx_pin;
en_gpio_af_t tx_af;
};
/* hc uart dirver class */
struct hc_uart
{
struct hc_uart_cfg *cfg;
struct rt_serial_device serial_device;
};
#ifdef BSP_USING_UART0
#ifndef UART0_CFG
#define UART0_CFG \
{ \
.name = "uart0", \
.uart = M0P_UART0, \
.uart_periph = SysctrlPeripheralUart0, \
.irqn = UART0_2_IRQn, \
.rx_port = UART0_RX_PORT, \
.rx_pin = UART0_RX_PIN, \
.rx_af = UART0_RX_AF, \
.tx_port = UART0_TX_PORT, \
.tx_pin = UART0_TX_PIN, \
.tx_af = UART0_TX_AF, \
}
#endif /* UART0_CFG */
#endif /* BSP_USING_UART0 */
#ifdef BSP_USING_UART1
#ifndef UART1_CFG
#define UART1_CFG \
{ \
.name = "uart1", \
.uart = M0P_UART1, \
.uart_periph = SysctrlPeripheralUart1, \
.irqn = UART1_3_IRQn, \
.rx_port = UART1_RX_PORT, \
.rx_pin = UART1_RX_PIN, \
.rx_af = UART1_RX_AF, \
.tx_port = UART1_TX_PORT, \
.tx_pin = UART1_TX_PIN, \
.tx_af = UART1_TX_AF, \
}
#endif /* UART1_CFG */
#endif /* BSP_USING_UART1 */
#ifdef BSP_USING_UART2
#ifndef UART2_CFG
#define UART2_CFG \
{ \
.name = "uart2", \
.uart = M0P_UART2, \
.uart_periph = SysctrlPeripheralUart2, \
.irqn = UART0_2_IRQn, \
.rx_port = UART2_RX_PORT, \
.rx_pin = UART2_RX_PIN, \
.rx_af = UART2_RX_AF, \
.tx_port = UART2_TX_PORT, \
.tx_pin = UART2_TX_PIN, \
.tx_af = UART2_TX_AF, \
}
#endif /* UART2_CFG */
#endif /* BSP_USING_UART2 */
#ifdef BSP_USING_UART3
#ifndef UART3_CFG
#define UART3_CFG \
{ \
.name = "uart3", \
.uart = M0P_UART3, \
.uart_periph = SysctrlPeripheralUart3, \
.irqn = UART1_3_IRQn, \
.rx_port = UART3_RX_PORT, \
.rx_pin = UART3_RX_PIN, \
.rx_af = UART3_RX_AF, \
.tx_port = UART3_TX_PORT, \
.tx_pin = UART3_TX_PIN, \
.tx_af = UART3_TX_AF, \
}
#endif /* UART3_CFG */
#endif /* BSP_USING_UART3 */
#ifdef BSP_USING_LPUART0
#ifndef LPUART0_CFG
#define LPUART0_CFG \
{ \
.name = "lpuart0", \
.uart = M0P_LPUART0, \
.uart_periph = SysctrlPeripheralLpUart0, \
.irqn = LPUART0_IRQn, \
.rx_port = LPUART0_RX_PORT, \
.rx_pin = LPUART0_RX_PIN, \
.rx_af = LPUART0_RX_AF, \
.tx_port = LPUART0_TX_PORT, \
.tx_pin = LPUART0_TX_PIN, \
.tx_af = LPUART0_TX_AF, \
}
#endif /* LPUART0_CFG */
#endif /* BSP_USING_LPUART0 */
#ifdef BSP_USING_LPUART1
#ifndef LPUART1_CFG
#define LPUART1_CFG \
{ \
.name = "lpuart1", \
.uart = M0P_LPUART1, \
.uart_periph = SysctrlPeripheralLpUart1, \
.irqn = LPUART1_IRQn, \
.rx_port = LPUART1_RX_PORT, \
.rx_pin = LPUART1_RX_PIN, \
.rx_af = LPUART1_RX_AF, \
.tx_port = LPUART1_TX_PORT, \
.tx_pin = LPUART1_TX_PIN, \
.tx_af = LPUART1_TX_AF, \
}
#endif /* LPUART1_CFG */
#endif /* BSP_USING_LPUART1 */
int rt_hw_uart_init(void);
#endif /* __DRV_USART_H__ */