MG32L003 Standard Peripherals Firmware Library

mg32l003_pca.h
浏览该文件的文档.
1
10 /* Define to prevent recursive inclusion -------------------------------------*/
11 #ifndef __MG32L003_PCA_H
12 #define __MG32L003_PCA_H
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /* Includes ------------------------------------------------------------------*/
19 #include "mg32l003.h"
20
25 /* Exported types ------------------------------------------------------------*/
26
31 typedef struct
32 {
33 uint32_t ClkSrcSel;
36 uint32_t RunInIdleMode;
38 } PCA_BaseInitTypeDef;
39
43 typedef struct
44 {
45 uint32_t ICPolarity;
48 uint32_t Channel;
50 } PCA_IC_InitTypeDef;
51
55 typedef struct
56 {
57 uint32_t CompareEnable;
60 uint32_t TogEnable;
64 uint32_t PwmEnable;
68 uint32_t Period;
72 uint32_t Channel;
75 } PCA_OC_InitTypeDef;
76
77 /* Exported constants --------------------------------------------------------*/
78
86 #define PCA_CLOCK_SOURCE_PCLKDIV32 0x00000000U
87 #define PCA_CLOCK_SOURCE_PCLKDIV16 (PCA_MOD_CPS_0)
88 #define PCA_CLOCK_SOURCE_PCLKDIV8 (PCA_MOD_CPS_1)
89 #define PCA_CLOCK_SOURCE_PCLKDIV4 (PCA_MOD_CPS_1 | PCA_MOD_CPS_0)
90 #define PCA_CLOCK_SOURCE_PCLKDIV2 (PCA_MOD_CPS_2)
91 #define PCA_CLOCK_SOURCE_TIM10_OVERFLOW (PCA_MOD_CPS_2 | PCA_MOD_CPS_0)
92 #define PCA_CLOCK_SOURCE_TIM11_OVERFLOW (PCA_MOD_CPS_2 | PCA_MOD_CPS_1)
93 #define PCA_CLOCK_SOURCE_ECI (PCA_MOD_CPS_2 | PCA_MOD_CPS_1 | PCA_MOD_CPS_0)
95 #define IS_PCA_CLOCK_COURCE(CLOCK_SOURCE) (((CLOCK_SOURCE) == PCA_CLOCK_SOURCE_PCLKDIV32) || ((CLOCK_SOURCE) == PCA_CLOCK_SOURCE_PCLKDIV16) || \
96 ((CLOCK_SOURCE) == PCA_CLOCK_SOURCE_PCLKDIV8) || ((CLOCK_SOURCE) == PCA_CLOCK_SOURCE_PCLKDIV4) || \
97 ((CLOCK_SOURCE) == PCA_CLOCK_SOURCE_PCLKDIV2) || ((CLOCK_SOURCE) == PCA_CLOCK_SOURCE_TIM10_OVERFLOW) || \
98 ((CLOCK_SOURCE) == PCA_CLOCK_SOURCE_TIM11_OVERFLOW) || ((CLOCK_SOURCE) == PCA_CLOCK_SOURCE_ECI))
99
106 #define PCA_IDLEMODE_DISABLE (0x00000000)
107 #define PCA_IDLEMODE_ENABLE (0x00000080)
108
109 #define IS_PCA_IDLEMODE(IDLE_MODE) (((IDLE_MODE) == PCA_IDLEMODE_DISABLE) || ((IDLE_MODE) == PCA_IDLEMODE_ENABLE))
110
118 #define PCA_INPUT_POLARITY_NONE (0x00000000)
119 #define PCA_INPUT_POLARITY_FALLING (PCA_CCAPM0_CAPN)
120 #define PCA_INPUT_POLARITY_RISING (PCA_CCAPM0_CAPP)
121 #define PCA_INPUT_POLARITY_BOTH (PCA_CCAPM0_CAPN | PCA_CCAPM0_CAPP)
122
123 #define IS_PCA_INPUT_POLARATY(INPUT_POLARATY) (((INPUT_POLARATY) == PCA_INPUT_POLARITY_NONE) || ((INPUT_POLARATY) == PCA_INPUT_POLARITY_FALLING) || \
124 ((INPUT_POLARATY) == PCA_INPUT_POLARITY_RISING) || ((INPUT_POLARATY) == PCA_INPUT_POLARITY_BOTH))
125
132 #define PCA_FLAG_CC0 (PCA_CR_CCF0)
133 #define PCA_FLAG_CC1 (PCA_CR_CCF1)
134 #define PCA_FLAG_CC2 (PCA_CR_CCF2)
135 #define PCA_FLAG_CC3 (PCA_CR_CCF3)
136 #define PCA_FLAG_CC4 (PCA_CR_CCF4)
137 #define PCA_FLAG_OVERFLOW (PCA_CR_CF)
138
139 #define IS_PCA_FLAG(FLAG) (((FLAG) == PCA_FLAG_CC0) || ((FLAG) == PCA_FLAG_CC1) || \
140 ((FLAG) == PCA_FLAG_CC2) || ((FLAG) == PCA_FLAG_CC3) || \
141 ((FLAG) == PCA_FLAG_CC4) || ((FLAG) == PCA_FLAG_OVERFLOW))
142
149 #define PCA_IT_CC0 (0x01)
150 #define PCA_IT_CC1 (0x02)
151 #define PCA_IT_CC2 (0x04)
152 #define PCA_IT_CC3 (0x08)
153 #define PCA_IT_CC4 (0x10)
154 #define PCA_IT_OVERFLOW (0x80)
155
156 #define IS_PCA_IT(PCA_IT) (((PCA_IT) == PCA_IT_CC0) || ((PCA_IT) == PCA_IT_CC1) || \
157 ((PCA_IT) == PCA_IT_CC2) || ((PCA_IT) == PCA_IT_CC3) || \
158 ((PCA_IT) == PCA_IT_CC4) || ((PCA_IT) == PCA_IT_OVERFLOW))
159
166 #define PCA_CHANNEL_0 (0x01)
167 #define PCA_CHANNEL_1 (0x02)
168 #define PCA_CHANNEL_2 (0x04)
169 #define PCA_CHANNEL_3 (0x08)
170 #define PCA_CHANNEL_4 (0x10)
171 #define PCA_CHANNEL_MASK (0x1F)
172
173 #define IS_PCA_CHANNEL(CHANNEL) (((CHANNEL) & PCA_CHANNEL_MASK) != 0x00)
174
181 #define PCA_OC_ENABLE (PCA_CCAPM0_ECOM)
182 #define PCA_OC_DISABLE 0x00000000U
184 #define IS_PCA_OC_ENABLE(OC_ENABLE) (((OC_ENABLE) == PCA_OC_ENABLE) || ((OC_ENABLE) == PCA_OC_DISABLE))
185
192 #define PCA_TOG_ENABLE (PCA_CCAPM0_MAT | PCA_CCAPM0_TOG)
193 #define PCA_TOG_DISABLE 0x00000000U
195 #define IS_PCA_TOG_ENABLE(TOG_ENABLE) (((TOG_ENABLE) == PCA_TOG_ENABLE) || ((TOG_ENABLE) == PCA_TOG_DISABLE))
196
203 #define PCA_PWM_ENABLE (PCA_CCAPM0_PWM)
204 #define PCA_PWM_DISABLE 0x00000000U
206 #define IS_PCA_PWM_ENABLE(PWM_ENABLE) (((PWM_ENABLE) == PCA_PWM_ENABLE) || ((PWM_ENABLE) == PCA_PWM_DISABLE))
207
215 /* Exported macros -----------------------------------------------------------*/
216 /* Exported functions --------------------------------------------------------*/
217
218 void PCA_BaseInit(PCA_BaseInitTypeDef *PCA_InitStruct);
219 void PCA_OC_Config(PCA_OC_InitTypeDef *OC_Config);
220 void PCA_IC_Config(PCA_IC_InitTypeDef *IC_Config);
221 uint16_t PCA_GetCompareValue(uint32_t Channel);
222 void PCA_Cmd(FunctionalState NewState);
223 void PCA_OC_Cmd(uint32_t Channel, FunctionalState NewState);
224 void PCA_OC_INVCmd(uint32_t Channel, FunctionalState NewState);
225 void PCA_DeInit(void);
226 void PCA_ITConfig(uint8_t PCA_IT, FunctionalState NewState);
227 FlagStatus PCA_GetFlagStatus(uint8_t PCA_FLAG);
228 ITStatus PCA_GetITStatus(uint8_t PCA_IT);
229 void PCA_ClearITPendingBit(uint8_t PCA_IT);
230 void PCA_ClearFlag(uint8_t PCA_FLAG);
231 void PCA_SetPWMDuty(uint32_t Channel, uint8_t Duty);
232 void PCA_IC0_TriggerConfig(uint32_t PCA_Trigger_ICPolarity);
233 void PCA_IC1_TriggerConfig(uint32_t PCA_Trigger_ICPolarity);
234 void PCA_IC2_TriggerConfig(uint32_t PCA_Trigger_ICPolarity);
235 void PCA_IC3_TriggerConfig(uint32_t PCA_Trigger_ICPolarity);
236 void PCA_IC4_TriggerConfig(uint32_t PCA_Trigger_ICPolarity);
237
246 #ifdef __cplusplus
247 }
248 #endif
249
250 #endif /* __MG32L003_PCA_H */
PCA_BaseInitTypeDef::RunInIdleMode
uint32_t RunInIdleMode
Definition: mg32l003_pca.h:36
PCA_IC1_TriggerConfig
void PCA_IC1_TriggerConfig(uint32_t PCA_Trigger_ICPolarity)
Configures the Channel1 (PCA Input capture).
Definition: mg32l003_pca.c:472
PCA_IC4_TriggerConfig
void PCA_IC4_TriggerConfig(uint32_t PCA_Trigger_ICPolarity)
Configures the Channel4 (PCA Input capture).
Definition: mg32l003_pca.c:520
PCA_OC_InitTypeDef::TogEnable
uint32_t TogEnable
Definition: mg32l003_pca.h:60
PCA_IC_InitTypeDef::Channel
uint32_t Channel
Definition: mg32l003_pca.h:48
PCA_OC_InitTypeDef::PwmEnable
uint32_t PwmEnable
Definition: mg32l003_pca.h:64
PCA_OC_INVCmd
void PCA_OC_INVCmd(uint32_t Channel, FunctionalState NewState)
Enables or disables the PCA inverse output compare generation.
Definition: mg32l003_pca.c:192
PCA_GetITStatus
ITStatus PCA_GetITStatus(uint8_t PCA_IT)
Checks whether the specified PCA interrupt is set or not.
Definition: mg32l003_pca.c:311
PCA_DeInit
void PCA_DeInit(void)
Deinitializes the PCA peripheral registers to their default reset values.
Definition: mg32l003_pca.c:38
PCA_OC_InitTypeDef::Period
uint32_t Period
Definition: mg32l003_pca.h:68
PCA_OC_InitTypeDef::CompareEnable
uint32_t CompareEnable
Definition: mg32l003_pca.h:57
PCA_IC_InitTypeDef::ICPolarity
uint32_t ICPolarity
Definition: mg32l003_pca.h:45
PCA_IC_InitTypeDef
PCA Input Capture Configuration Structure definition
Definition: mg32l003_pca.h:43
PCA_IC_Config
void PCA_IC_Config(PCA_IC_InitTypeDef *IC_Config)
Initializes the PCA input capture Channels according to the specified parameters in the PCA_IC_InitTy...
Definition: mg32l003_pca.c:214
PCA_Cmd
void PCA_Cmd(FunctionalState NewState)
Enables or disables the PCA peripheral.
Definition: mg32l003_pca.c:50
PCA_BaseInitTypeDef::ClkSrcSel
uint32_t ClkSrcSel
Definition: mg32l003_pca.h:33
PCA_GetFlagStatus
FlagStatus PCA_GetFlagStatus(uint8_t PCA_FLAG)
Checks whether the specified PCA flag is set or not.
Definition: mg32l003_pca.c:355
PCA_OC_InitTypeDef
PCA Output Compare Configuration Structure definition
Definition: mg32l003_pca.h:55
PCA_OC_InitTypeDef::Channel
uint32_t Channel
Definition: mg32l003_pca.h:72
PCA_BaseInit
void PCA_BaseInit(PCA_BaseInitTypeDef *PCA_InitStruct)
Initializes the PCA Unit basic function according to the specified parameters in the PCA_HandleTypeDe...
Definition: mg32l003_pca.c:71
PCA_ITConfig
void PCA_ITConfig(uint8_t PCA_IT, FunctionalState NewState)
Enables or disables the specified PCA interrupt.
Definition: mg32l003_pca.c:261
PCA_BaseInitTypeDef
PCA Configuration Structure definition
Definition: mg32l003_pca.h:31
PCA_GetCompareValue
uint16_t PCA_GetCompareValue(uint32_t Channel)
Gets the PCA Capture Compare Register value on runtime
Definition: mg32l003_pca.c:537
PCA_OC_Config
void PCA_OC_Config(PCA_OC_InitTypeDef *OC_Config)
Initializes the PCA output compare Channels according to the specified parameters in the PCA_OC_InitT...
Definition: mg32l003_pca.c:91
PCA_IC3_TriggerConfig
void PCA_IC3_TriggerConfig(uint32_t PCA_Trigger_ICPolarity)
Configures the Channel3 (PCA Input capture).
Definition: mg32l003_pca.c:504
PCA_ClearFlag
void PCA_ClearFlag(uint8_t PCA_FLAG)
Clears the PCA's pending flags.
Definition: mg32l003_pca.c:408
PCA_SetPWMDuty
void PCA_SetPWMDuty(uint32_t Channel, uint8_t Duty)
Sets PCA PWM ouput duty cycle.
Definition: mg32l003_pca.c:429
PCA_IC0_TriggerConfig
void PCA_IC0_TriggerConfig(uint32_t PCA_Trigger_ICPolarity)
Configures the Channel0 (PCA Input capture).
Definition: mg32l003_pca.c:456
PCA_ClearITPendingBit
void PCA_ClearITPendingBit(uint8_t PCA_IT)
Clears the PCA's interrupt pending bits.
Definition: mg32l003_pca.c:388
PCA_IC2_TriggerConfig
void PCA_IC2_TriggerConfig(uint32_t PCA_Trigger_ICPolarity)
Configures the Channel2 (PCA Input capture).
Definition: mg32l003_pca.c:488
PCA_OC_Cmd
void PCA_OC_Cmd(uint32_t Channel, FunctionalState NewState)
Enables or disables the PCA output compare generation.
Definition: mg32l003_pca.c:163