summaryrefslogtreecommitdiff
path: root/bsp/swm320/drivers/drv_pwm.h
blob: 0e27cb2e7b0ffefa2efddac6061e97df1806def2 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * 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_PWM_H__
#define __DRV_PWM_H__

#include "board.h"

struct swm_pwm_cfg
{
    const char *name;
    PWM_TypeDef *PWMx;
    PWM_InitStructure pwm_initstruct;
};

struct swm_pwm
{
    struct swm_pwm_cfg *cfg;
    struct rt_device_pwm pwm_device;
};

#ifdef BSP_USING_PWM0
#ifndef PWM0_CFG
#define PWM0_CFG                                \
    {                                           \
        .name = "pwm0",                         \
        .PWMx = PWM0,                           \
        .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
        .pwm_initstruct.mode = PWM_MODE_INDEP,  \
        .pwm_initstruct.cycleA = 10000,         \
        .pwm_initstruct.hdutyA = 5000,          \
        .pwm_initstruct.initLevelA = 1,         \
        .pwm_initstruct.cycleB = 10000,         \
        .pwm_initstruct.hdutyB = 5000,          \
        .pwm_initstruct.initLevelB = 1,         \
        .pwm_initstruct.HEndAIEn = 0,           \
        .pwm_initstruct.NCycleAIEn = 0,         \
        .pwm_initstruct.HEndBIEn = 0,           \
        .pwm_initstruct.NCycleBIEn = 0,         \
    }
#endif /* PWM0_CFG */
#endif /* BSP_USING_PWM0 */

#ifdef BSP_USING_PWM1
#ifndef PWM1_CFG
#define PWM1_CFG                                \
    {                                           \
        .name = "pwm1",                         \
        .PWMx = PWM1,                           \
        .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
        .pwm_initstruct.mode = PWM_MODE_INDEP,  \
        .pwm_initstruct.cycleA = 10000,         \
        .pwm_initstruct.hdutyA = 5000,          \
        .pwm_initstruct.initLevelA = 1,         \
        .pwm_initstruct.cycleB = 10000,         \
        .pwm_initstruct.hdutyB = 5000,          \
        .pwm_initstruct.initLevelB = 1,         \
        .pwm_initstruct.HEndAIEn = 0,           \
        .pwm_initstruct.NCycleAIEn = 0,         \
        .pwm_initstruct.HEndBIEn = 0,           \
        .pwm_initstruct.NCycleBIEn = 0,         \
    }
#endif /* PWM1_CFG */
#endif /* BSP_USING_PWM1 */

#ifdef BSP_USING_PWM2
#ifndef PWM2_CFG
#define PWM2_CFG                                \
    {                                           \
        .name = "pwm2",                         \
        .PWMx = PWM2,                           \
        .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
        .pwm_initstruct.mode = PWM_MODE_INDEP,  \
        .pwm_initstruct.cycleA = 10000,         \
        .pwm_initstruct.hdutyA = 5000,          \
        .pwm_initstruct.initLevelA = 1,         \
        .pwm_initstruct.cycleB = 10000,         \
        .pwm_initstruct.hdutyB = 5000,          \
        .pwm_initstruct.initLevelB = 1,         \
        .pwm_initstruct.HEndAIEn = 0,           \
        .pwm_initstruct.NCycleAIEn = 0,         \
        .pwm_initstruct.HEndBIEn = 0,           \
        .pwm_initstruct.NCycleBIEn = 0,         \
    }
#endif /* PWM2_CFG */
#endif /* BSP_USING_PWM2 */

#ifdef BSP_USING_PWM3
#ifndef PWM3_CFG
#define PWM3_CFG                                \
    {                                           \
        .name = "pwm3",                         \
        .PWMx = PWM3,                           \
        .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
        .pwm_initstruct.mode = PWM_MODE_INDEP,  \
        .pwm_initstruct.cycleA = 10000,         \
        .pwm_initstruct.hdutyA = 5000,          \
        .pwm_initstruct.initLevelA = 1,         \
        .pwm_initstruct.cycleB = 10000,         \
        .pwm_initstruct.hdutyB = 5000,          \
        .pwm_initstruct.initLevelB = 1,         \
        .pwm_initstruct.HEndAIEn = 0,           \
        .pwm_initstruct.NCycleAIEn = 0,         \
        .pwm_initstruct.HEndBIEn = 0,           \
        .pwm_initstruct.NCycleBIEn = 0,         \
    }
#endif /* PWM3_CFG */
#endif /* BSP_USING_PWM3 */

#ifdef BSP_USING_PWM4
#ifndef PWM4_CFG
#define PWM4_CFG                                \
    {                                           \
        .name = "pwm4",                         \
        .PWMx = PWM4,                           \
        .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
        .pwm_initstruct.mode = PWM_MODE_INDEP,  \
        .pwm_initstruct.cycleA = 10000,         \
        .pwm_initstruct.hdutyA = 5000,          \
        .pwm_initstruct.initLevelA = 1,         \
        .pwm_initstruct.cycleB = 10000,         \
        .pwm_initstruct.hdutyB = 5000,          \
        .pwm_initstruct.initLevelB = 1,         \
        .pwm_initstruct.HEndAIEn = 0,           \
        .pwm_initstruct.NCycleAIEn = 0,         \
        .pwm_initstruct.HEndBIEn = 0,           \
        .pwm_initstruct.NCycleBIEn = 0,         \
    }
#endif /* PWM4_CFG */
#endif /* BSP_USING_PWM4 */

#ifdef BSP_USING_PWM5
#ifndef PWM5_CFG
#define PWM5_CFG                                \
    {                                           \
        .name = "pwm5",                         \
        .PWMx = PWM5,                           \
        .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
        .pwm_initstruct.mode = PWM_MODE_INDEP,  \
        .pwm_initstruct.cycleA = 10000,         \
        .pwm_initstruct.hdutyA = 5000,          \
        .pwm_initstruct.initLevelA = 1,         \
        .pwm_initstruct.cycleB = 10000,         \
        .pwm_initstruct.hdutyB = 5000,          \
        .pwm_initstruct.initLevelB = 1,         \
        .pwm_initstruct.HEndAIEn = 0,           \
        .pwm_initstruct.NCycleAIEn = 0,         \
        .pwm_initstruct.HEndBIEn = 0,           \
        .pwm_initstruct.NCycleBIEn = 0,         \
    }
#endif /* PWM5_CFG */
#endif /* BSP_USING_PWM5 */

int rt_hw_pwm_init(void);

#endif /* __DRV_PWM_H__ */