summaryrefslogtreecommitdiff
path: root/bsp/wch/risc-v/libraries/ch32_drivers/drv_usart.h
blob: 97d2e31626c9fb35cebcfe0ab27a40ab9f01ca67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-08-27     liYony       the first version
 */

#ifndef __DRV_USART_H__
#define __DRV_USART_H__
#include <rtthread.h>
#include "rtdevice.h"
#include <rthw.h>

/* Do not use GPIO_Remap*/
#define GPIO_Remap_NONE 0

/* ch32 hardware config class */
struct ch32_uart_hw_config
{
    rt_uint32_t uart_periph_clock;
    rt_uint32_t gpio_periph_clock;
    GPIO_TypeDef *tx_gpio_port;
    rt_uint16_t tx_gpio_pin;
    GPIO_TypeDef *rx_gpio_port;
    rt_uint16_t rx_gpio_pin;
    rt_uint32_t remap;
};

/* ch32 config class */
struct ch32_uart_config
{
    const char *name;
    USART_TypeDef *Instance;
    IRQn_Type irq_type;
};

/* ch32 uart dirver class */
struct ch32_uart
{
    struct ch32_uart_hw_config *hw_config;
    struct ch32_uart_config *config;
    USART_InitTypeDef Init;
    struct rt_serial_device serial;
};

int rt_hw_usart_init(void);
#endif