Skip to content

Commit 4a9ecd8

Browse files
authored
Merge pull request #5095 from charlown/master
support ch32f10x pwm driver.
2 parents cbf0cd1 + 9ec326f commit 4a9ecd8

File tree

6 files changed

+572
-31
lines changed

6 files changed

+572
-31
lines changed

bsp/wch/arm/Libraries/ch32_drivers/SConscript

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ if GetDepend('SOC_ARM_SERIES_CH32F103'):
3232
if GetDepend(['RT_USING_HWTIMER', 'BSP_USING_HWTIMER']):
3333
src += ['drv_hwtimer_ch32f10x.c']
3434

35+
if GetDepend(['RT_USING_PWM', 'BSP_USING_PWM']):
36+
src += ['drv_pwm_ch32f10x.c']
37+
3538
src += ['drv_common.c']
3639

3740
path = [cwd]

bsp/wch/arm/Libraries/ch32_drivers/drv_hwtimer_ch32f10x.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,16 @@ static void ch32f1_hwtimer_init(struct rt_hwtimer_device *device, rt_uint32_t st
7373

7474
if (state)
7575
{
76-
ch32f1_hwtimer_clock_init(hwtimer_dev->periph);
76+
ch32f1_tim_clock_init(hwtimer_dev->periph);
7777

7878
hwtimer_info = ch32f1_hwtimer_info_config_get(hwtimer_dev->periph);
7979

80-
clk = ch32f1_hwtimer_clock_get(hwtimer_dev->periph);
80+
clk = ch32f1_tim_clock_get(hwtimer_dev->periph);
8181

8282
prescaler_value = (rt_uint16_t)(clk / hwtimer_info->minfreq) - 1;
8383

8484
/*
85-
* set interrupt callback one or each time need total time =
86-
* (cnt + 1) * (1 / (clk/(prescaler_value + 1) ) )
85+
* (1 / freq) = (cnt + 1) * (1 / (clk/(prescaler_value + 1) ) )
8786
*/
8887

8988
TIM_TimeBaseInitType.TIM_Period = hwtimer_info->maxcnt - 1;
@@ -132,8 +131,7 @@ static rt_err_t ch32f1_hwtimer_start(struct rt_hwtimer_device *device, rt_uint32
132131
hwtimer_dev = (struct hwtimer_device *)device;
133132

134133
/*
135-
* interrupt callback one or each time need total time =
136-
* (cnt + 1) * (1 / (clk/(prescaler_value + 1) ) )
134+
* (1 / freq) = (cnt + 1) * (1 / (clk/(prescaler_value + 1) ) )
137135
*/
138136

139137
TIM_SetCounter(hwtimer_dev->periph, 0);
@@ -197,15 +195,14 @@ static rt_err_t ch32f1_hwtimer_control(struct rt_hwtimer_device *device, rt_uint
197195
rt_uint16_t prescaler_value = 0;
198196

199197
/*
200-
*set interrupt callback one or each time need total time =
201-
* (cnt + 1) * (1 / (clk/(prescaler_value + 1) ) )
198+
* (1 / freq) = (cnt + 1) * (1 / (clk/(prescaler_value + 1) ) )
202199
*/
203200
if (arg != RT_NULL)
204201
{
205202

206203
freq = *((rt_uint32_t *)arg);
207204

208-
clk = ch32f1_hwtimer_clock_get(hwtimer_dev->periph);
205+
clk = ch32f1_tim_clock_get(hwtimer_dev->periph);
209206

210207
prescaler_value = (rt_uint16_t)(clk / freq) - 1;
211208

@@ -369,4 +366,3 @@ void TIM4_IRQHandler(void)
369366
#endif
370367

371368
#endif /* BSP_USING_HWTIMER */
372-

0 commit comments

Comments
 (0)