summaryrefslogtreecommitdiff
path: root/bsp/swm320/drivers/drv_uart.h
blob: 66c6535a5b4741dd6168948619d5d98af5b5c64a (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright (c) 2006-2018, Synwit Technology Co.,Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-12-10     Zohar_Lee    first version
 * 2020-07-10     lik          rewrite
 */

#ifndef __DRV_UART_H__
#define __DRV_UART_H__

#include "board.h"

/* swm config class */
struct swm_uart_cfg
{
    const char *name;
    UART_TypeDef *UARTx;
    IRQn_Type irq;
    UART_InitStructure uart_initstruct;
};

/* swm uart dirver class */
struct swm_uart
{
    struct swm_uart_cfg *cfg;
    struct rt_serial_device serial_device;
};

#ifdef BSP_USING_UART0
#ifndef UART0_CFG
#define UART0_CFG                                   \
    {                                               \
        .name = "uart0",                            \
        .UARTx = UART0,                             \
        .irq = UART0_IRQn,                          \
        .uart_initstruct.Baudrate = 115200,         \
        .uart_initstruct.DataBits = UART_DATA_8BIT, \
        .uart_initstruct.Parity = UART_PARITY_NONE, \
        .uart_initstruct.StopBits = UART_STOP_1BIT, \
        .uart_initstruct.RXThreshold = 0,           \
        .uart_initstruct.RXThresholdIEn = 1,        \
        .uart_initstruct.TXThresholdIEn = 0,        \
        .uart_initstruct.TimeoutTime = 10,          \
        .uart_initstruct.TimeoutIEn = 1,            \
    }
#endif /* UART0_CFG */
#endif /* BSP_USING_UART0 */

#ifdef BSP_USING_UART1
#ifndef UART1_CFG
#define UART1_CFG                                   \
    {                                               \
        .name = "uart1",                            \
        .UARTx = UART1,                             \
        .irq = UART1_IRQn,                          \
        .uart_initstruct.Baudrate = 115200,         \
        .uart_initstruct.DataBits = UART_DATA_8BIT, \
        .uart_initstruct.Parity = UART_PARITY_NONE, \
        .uart_initstruct.StopBits = UART_STOP_1BIT, \
        .uart_initstruct.RXThreshold = 0,           \
        .uart_initstruct.RXThresholdIEn = 1,        \
        .uart_initstruct.TXThresholdIEn = 0,        \
        .uart_initstruct.TimeoutTime = 10,          \
        .uart_initstruct.TimeoutIEn = 1,            \
    }
#endif /* UART1_CFG */
#endif /* BSP_USING_UART1 */

#ifdef BSP_USING_UART2
#ifndef UART2_CFG
#define UART2_CFG                                   \
    {                                               \
        .name = "uart2",                            \
        .UARTx = UART2,                             \
        .irq = UART2_IRQn,                          \
        .uart_initstruct.Baudrate = 115200,         \
        .uart_initstruct.DataBits = UART_DATA_8BIT, \
        .uart_initstruct.Parity = UART_PARITY_NONE, \
        .uart_initstruct.StopBits = UART_STOP_1BIT, \
        .uart_initstruct.RXThreshold = 0,           \
        .uart_initstruct.RXThresholdIEn = 1,        \
        .uart_initstruct.TXThresholdIEn = 0,        \
        .uart_initstruct.TimeoutTime = 10,          \
        .uart_initstruct.TimeoutIEn = 1,            \
    }
#endif /* UART2_CFG */
#endif /* BSP_USING_UART2 */

#ifdef BSP_USING_UART3
#ifndef UART3_CFG
#define UART3_CFG                                   \
    {                                               \
        .name = "uart3",                            \
        .UARTx = UART3,                             \
        .irq = UART3_IRQn,                          \
        .uart_initstruct.Baudrate = 115200,         \
        .uart_initstruct.DataBits = UART_DATA_8BIT, \
        .uart_initstruct.Parity = UART_PARITY_NONE, \
        .uart_initstruct.StopBits = UART_STOP_1BIT, \
        .uart_initstruct.RXThreshold = 0,           \
        .uart_initstruct.RXThresholdIEn = 1,        \
        .uart_initstruct.TXThresholdIEn = 0,        \
        .uart_initstruct.TimeoutTime = 10,          \
        .uart_initstruct.TimeoutIEn = 1,            \
    }
#endif /* UART3_CFG */
#endif /* BSP_USING_UART3 */

int rt_hw_serial_init(void);

#endif /* __DRV_UART_H__ */