Tool Libs
UMIT-TIROL Institute of Automation and Control Engineering library collection
 
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "hal.h"
8
9namespace TIMER {
11 class HW {
12 public:
20 HW(TIM_TypeDef *dTim, uint32_t prescaler, uint32_t period) {
21 handle = {
22 .Instance = dTim,
23 .Init = {
24 .Prescaler = prescaler,
25 .CounterMode = TIM_COUNTERMODE_UP,
26 .Period = period,
27 .ClockDivision = TIM_CLOCKDIVISION_DIV1,
28 .AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE,
29 },
30 };
31 while (HAL_TIM_Base_Init(&handle) != HAL_OK);
32
33 TIM_MasterConfigTypeDef sMasterConfig = {
34 .MasterOutputTrigger = TIM_TRGO_RESET,
35 .MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE,
36 };
37 while (HAL_TIMEx_MasterConfigSynchronization(&handle, &sMasterConfig) != HAL_OK);
38 }
39
44 void configCallback(void (*callback)(TIM_HandleTypeDef *)) {
45 HAL_TIM_RegisterCallback(&handle, HAL_TIM_PERIOD_ELAPSED_CB_ID, callback);
46 }
47
49 void start() {
50 while (HAL_TIM_Base_Start_IT(&handle) != HAL_OK);
51 }
52
54 void irqHandler() {
55 HAL_TIM_IRQHandler(&handle);
56 }
57
59 TIM_HandleTypeDef handle = {};
60 };
61}
wrapper for timer peripheral
Definition timer.h:11
void configCallback(void(*callback)(TIM_HandleTypeDef *))
configure callback on PERIOD ELAPSED event
Definition timer.h:44
HW(TIM_TypeDef *dTim, uint32_t prescaler, uint32_t period)
Initialize Timer Peripheral.
Definition timer.h:20
void irqHandler()
call directly in interrupt
Definition timer.h:54
TIM_HandleTypeDef handle
HAL handle, for use with unwrapped Timer capabilities.
Definition timer.h:59
void start()
start timer in interrupt mode
Definition timer.h:49
Copyright (c) 2020 IACE.