使用rtthread
This commit is contained in:
55
source/interface/if_pwm.c
Normal file
55
source/interface/if_pwm.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
|
||||
// 使用定时器14
|
||||
|
||||
// PF7,8,9 是输出口
|
||||
|
||||
typedef struct{
|
||||
TIM_HandleTypeDef htim;
|
||||
}self_def;
|
||||
|
||||
|
||||
static self_def g_self;
|
||||
|
||||
|
||||
static int init(pwm_def *p)
|
||||
{
|
||||
self_def *s=&g_self;
|
||||
if(p->private_data) return 0;
|
||||
p->private_data=s;
|
||||
|
||||
s->htim.Instance = TIM14;
|
||||
s->htim.Init.Prescaler = 209-1;
|
||||
s->htim.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
s->htim.Init.Period = 65535;
|
||||
s->htim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
s->htim.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||
if (HAL_TIM_Base_Init(&s->htim) != HAL_OK)
|
||||
{
|
||||
DBG_ERR("time init failed.");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void TIM14_IRQHandler(void)
|
||||
{
|
||||
self_def *s=&g_self;
|
||||
HAL_TIM_IRQHandler(&s->htim);
|
||||
}
|
||||
|
||||
|
||||
|
17
source/interface/if_pwm.h
Normal file
17
source/interface/if_pwm.h
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
#ifndef if_pwm_h__
|
||||
#define if_pwm_h__
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user