1 /*
2  * Copyright (c) 2022 OpenLuat & AirM2M
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of
5  * this software and associated documentation files (the "Software"), to deal in
6  * the Software without restriction, including without limitation the rights to
7  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8  * the Software, and to permit persons to whom the Software is furnished to do so,
9  * subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  */
21 
22 
23 
24 #ifndef __AIR105_TIMER_H
25 #define __AIR105_TIMER_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /* Includes ------------------------------------------------------------------*/
32 #include "air105.h"
33 
34 /* Exported types ------------------------------------------------------------*/
35 typedef enum
36 {
37     TIM_0 = 0,
38     TIM_1,
39     TIM_2,
40     TIM_3,
41     TIM_4,
42     TIM_5,
43     TIM_6,
44     TIM_7,
45 }TIM_NumTypeDef;
46 
47 typedef struct
48 {
49     TIM_NumTypeDef TIMx;
50     uint32_t TIM_Period;            /*!< Specifies the period value to be loaded into the active
51                                        Auto-Reload Register at the next update event.
52                                        This parameter must be a number between 0x0000 and 0xFFFFFFFF.  */
53 }TIM_InitTypeDef;
54 
55 typedef struct
56 {
57     TIM_NumTypeDef TIMx;
58     uint32_t TIM_LowLevelPeriod;
59     uint32_t TIM_HighLevelPeriod;
60 }TIM_PWMInitTypeDef;
61 
62 typedef enum
63 {
64     TIM_Mode_General    = 0,
65     TIM_Mode_PWM        = 1
66 }TIM_ModeTypeDef;
67 #define IS_TIM_MODE(MODE)           (MODE == TIM_Mode_General || MODE == TIM_Mode_PWM)
68 
69 
70 void TIM_DeInit(TIM_Module_TypeDef *TIMMx);
71 void TIM_Init(TIM_Module_TypeDef* TIMMx, TIM_InitTypeDef* TIM_InitStruct);
72 
73 void TIM_PWMInit(TIM_Module_TypeDef* TIMMx, TIM_PWMInitTypeDef* TIM_PWMInitStruct);
74 void TIM_Cmd(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx, FunctionalState NewState);
75 void TIM_ModeConfig(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx, TIM_ModeTypeDef TIM_Mode);
76 void TIM_SetPeriod(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx, uint32_t Period);
77 void TIM_SetPWMPeriod(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx, uint32_t PWM_LowLevelPeriod, uint32_t PWM_HighLevelPeriod);
78 void TIM_ITConfig(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx, FunctionalState NewState);
79 void TIM_ClearITPendingBit(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx);
80 void TIM_PWMSinglePulseConfig(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx, FunctionalState NewState);
81 void TIM_PWMReloadSinglePulse(TIM_Module_TypeDef *TIMMx, TIM_NumTypeDef TIMx);
82 
83 ITStatus TIM_GetITStatus(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx);
84 uint32_t TIM_GetAllITStatus(TIM_Module_TypeDef* TIMMx);
85 ITStatus TIM_GetRawITStatus(TIM_Module_TypeDef* TIMMx, TIM_NumTypeDef TIMx);
86 uint32_t TIM_GetAllRawITStatus(TIM_Module_TypeDef* TIMMx);
87 
88 uint32_t TIM_GetCounter(TIM_Module_TypeDef *TIMMx, TIM_NumTypeDef TIMx);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif
95 
96 /**************************      (C) COPYRIGHT Megahunt    *****END OF FILE****/
97