中等容量使用定时器TIM3
This commit is contained in:
parent
a04264683c
commit
ec75ca6910
9
Time.cpp
9
Time.cpp
|
@ -1,4 +1,5 @@
|
|||
#include "Time.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#include "Platform\stm32.h"
|
||||
|
||||
|
@ -28,7 +29,10 @@ TTime::TTime()
|
|||
Index = 13;
|
||||
#else
|
||||
Div = 0;
|
||||
if(Sys.FlashSize > 0x80)
|
||||
Index = 5;
|
||||
else
|
||||
Index = 3;
|
||||
#endif
|
||||
BaseSeconds = 0;
|
||||
|
||||
|
@ -60,11 +64,12 @@ void TTime::Init()
|
|||
//Interrupt.Disable(SysTick_IRQn);
|
||||
|
||||
TIM_TypeDef* tim = g_Timers[Index];
|
||||
#if defined(STM32F0) || defined(GD32F150)
|
||||
/*#if defined(STM32F0) || defined(GD32F150)
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
|
||||
#else
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
|
||||
#endif
|
||||
#endif*/
|
||||
Timer::ClockCmd(Index, true);
|
||||
|
||||
// 获取当前频率
|
||||
#if defined(STM32F0) || defined(GD32F150)
|
||||
|
|
|
@ -117,7 +117,7 @@ void Timer::Open()
|
|||
#endif
|
||||
|
||||
// 打开时钟
|
||||
ClockCmd(true);
|
||||
ClockCmd(_index, true);
|
||||
|
||||
// 关闭。不再需要,跟上面ClockCmd的效果一样
|
||||
//TIM_DeInit((TIM_TypeDef*)_Timer);
|
||||
|
@ -143,15 +143,15 @@ void Timer::Close()
|
|||
TIM_Cmd(ti, DISABLE);
|
||||
TIM_ITConfig(ti, TIM_IT_Update, DISABLE);
|
||||
TIM_ClearITPendingBit(ti, TIM_IT_Update); // 仅清除中断标志位 关闭不可靠
|
||||
ClockCmd(false); // 关闭定时器时钟
|
||||
ClockCmd(_index, false); // 关闭定时器时钟
|
||||
|
||||
Opened = false;
|
||||
}
|
||||
|
||||
void Timer::ClockCmd(bool state)
|
||||
void Timer::ClockCmd(int idx, bool state)
|
||||
{
|
||||
FunctionalState st = state ? ENABLE : DISABLE;
|
||||
switch(_index + 1)
|
||||
switch(idx + 1)
|
||||
{
|
||||
case 1: RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, st); break;
|
||||
case 2: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, st); break;
|
||||
|
|
3
Timer.h
3
Timer.h
|
@ -9,7 +9,6 @@ class Timer
|
|||
protected:
|
||||
byte _index; // 第几个定时器,从0开始
|
||||
|
||||
void ClockCmd(bool state);
|
||||
void SetHandler(bool set);
|
||||
public:
|
||||
void* _Timer;
|
||||
|
@ -32,6 +31,8 @@ public:
|
|||
|
||||
void Register(EventHandler handler, void* param = nullptr);
|
||||
|
||||
static void ClockCmd(int idx, bool state);
|
||||
|
||||
private:
|
||||
static void OnHandler(ushort num, void* param);
|
||||
EventHandler _Handler;
|
||||
|
|
Loading…
Reference in New Issue