stm32f30x_comp.c
Go to the documentation of this file.
1 
166 /* Includes ------------------------------------------------------------------*/
167 #include "stm32f30x_comp.h"
168 
178 /* Private typedef -----------------------------------------------------------*/
179 /* Private define ------------------------------------------------------------*/
180 /* CSR register Mask */
181 #define COMP_CSR_CLEAR_MASK ((uint32_t)0x00000003)
182 
183 /* Private macro -------------------------------------------------------------*/
184 /* Private variables ---------------------------------------------------------*/
185 /* Private function prototypes -----------------------------------------------*/
186 /* Private functions ---------------------------------------------------------*/
187 
214 void COMP_DeInit(uint32_t COMP_Selection)
215 {
217  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) = ((uint32_t)0x00000000);
218 }
219 
242 void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef* COMP_InitStruct)
243 {
244  uint32_t tmpreg = 0;
245 
246  /* Check the parameters */
247  assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
250  assert_param(IS_COMP_OUTPUT(COMP_InitStruct->COMP_Output));
254  assert_param(IS_COMP_MODE(COMP_InitStruct->COMP_Mode));
255 
257  tmpreg = *(__IO uint32_t *) (COMP_BASE + COMP_Selection);
258 
260  tmpreg &= (uint32_t) (COMP_CSR_CLEAR_MASK);
261 
270  tmpreg |= (uint32_t)(COMP_InitStruct->COMP_InvertingInput | COMP_InitStruct->COMP_NonInvertingInput |
271  COMP_InitStruct->COMP_Output | COMP_InitStruct->COMP_OutputPol | COMP_InitStruct->COMP_BlankingSrce |
272  COMP_InitStruct->COMP_Hysteresis | COMP_InitStruct->COMP_Mode);
273 
275  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) = tmpreg;
276 }
277 
284 void COMP_StructInit(COMP_InitTypeDef* COMP_InitStruct)
285 {
288  COMP_InitStruct->COMP_Output = COMP_Output_None;
289  COMP_InitStruct->COMP_BlankingSrce = COMP_BlankingSrce_None;
290  COMP_InitStruct->COMP_OutputPol = COMP_OutputPol_NonInverted;
291  COMP_InitStruct->COMP_Hysteresis = COMP_Hysteresis_No;
292  COMP_InitStruct->COMP_Mode = COMP_Mode_UltraLowPower;
293 }
294 
311 void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState)
312 {
313  /* Check the parameters */
314  assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
316 
317  if (NewState != DISABLE)
318  {
319  /* Enable the selected COMPx peripheral */
320  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) |= (uint32_t) (COMP_CSR_COMPxEN);
321  }
322  else
323  {
324  /* Disable the selected COMP peripheral */
325  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) &= (uint32_t)(~COMP_CSR_COMPxEN);
326  }
327 }
328 
341 void COMP_SwitchCmd(uint32_t COMP_Selection, FunctionalState NewState)
342 {
343  /* Check the parameter */
345 
346  if (NewState != DISABLE)
347  {
348  /* Close SW1 switch */
349  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) |= (uint32_t) (COMP_CSR_COMP1SW1);
350  }
351  else
352  {
353  /* Open SW1 switch */
354  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) &= (uint32_t)(~COMP_CSR_COMP1SW1);
355  }
356 }
357 
377 uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection)
378 {
379  uint32_t compout = 0x0;
380 
381  /* Check the parameters */
382  assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
383 
384  /* Check if selected comparator output is high */
385  if ((*(__IO uint32_t *) (COMP_BASE + COMP_Selection) & (COMP_CSR_COMPxOUT)) != 0)
386  {
387  compout = COMP_OutputLevel_High;
388  }
389  else
390  {
391  compout = COMP_OutputLevel_Low;
392  }
393 
394  /* Return the comparator output level */
395  return (uint32_t)(compout);
396 }
397 
434 void COMP_WindowCmd(uint32_t COMP_Selection, FunctionalState NewState)
435 {
436  /* Check the parameters */
438  assert_param(IS_COMP_WINDOW(COMP_Selection));
439 
440  if (NewState != DISABLE)
441  {
442  /* Enable the window mode */
443  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) |= (uint32_t) COMP_CSR_COMPxWNDWEN;
444  }
445  else
446  {
447  /* Disable the window mode */
448  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) &= (uint32_t)(~COMP_CSR_COMPxWNDWEN);
449  }
450 }
451 
479 void COMP_LockConfig(uint32_t COMP_Selection)
480 {
481  /* Check the parameter */
482  assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
483 
484  /* Set the lock bit corresponding to selected comparator */
485  *(__IO uint32_t *) (COMP_BASE + COMP_Selection) |= (uint32_t) (COMP_CSR_COMPxLOCK);
486 }
487 
504 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
uint32_t COMP_NonInvertingInput
#define COMP_Hysteresis_No
FunctionalState
Definition: stm32f4xx.h:708
uint32_t COMP_Hysteresis
uint32_t COMP_Output
uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection)
Return the output level (high or low) of the selected comparator. The output level depends on the sel...
#define IS_COMP_HYSTERESIS(HYSTERESIS)
void assert_param(int val)
#define IS_COMP_MODE(MODE)
void COMP_WindowCmd(uint32_t COMP_Selection, FunctionalState NewState)
Enables or disables the window mode. Window mode for comparators makes use of two comparators: COMP1 ...
void COMP_SwitchCmd(uint32_t COMP_Selection, FunctionalState NewState)
Close or Open the SW1 switch.
void COMP_StructInit(COMP_InitTypeDef *COMP_InitStruct)
Fills each COMP_InitStruct member with its default value.
#define IS_FUNCTIONAL_STATE(STATE)
Definition: stm32f4xx.h:709
#define COMP_InvertingInput_1_4VREFINT
#define IS_COMP_WINDOW(WINDOW)
uint32_t COMP_BlankingSrce
#define __IO
Definition: core_cm0.h:198
void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef *COMP_InitStruct)
Initializes the COMP peripheral according to the specified parameters in COMP_InitStruct.
#define IS_COMP_INVERTING_INPUT(INPUT)
#define COMP_CSR_CLEAR_MASK
void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState)
Enable or disable the COMP peripheral.
This file contains all the functions prototypes for the COMP firmware library.
#define IS_COMP_BLANKING_SOURCE(SOURCE)
uint32_t COMP_OutputPol
#define COMP_Output_None
COMP Init structure definition.
#define COMP_BlankingSrce_None
void COMP_LockConfig(uint32_t COMP_Selection)
Lock the selected comparator (COMP1/COMP2) configuration.
#define COMP_OutputLevel_Low
void COMP_DeInit(uint32_t COMP_Selection)
Deinitializes COMP peripheral registers to their default reset values.
uint32_t COMP_InvertingInput
#define COMP_NonInvertingInput_IO1
#define IS_COMP_OUTPUT_POL(POL)
#define COMP_OutputPol_NonInverted
#define COMP_Mode_UltraLowPower
#define IS_COMP_ALL_PERIPH(PERIPH)
#define COMP_OutputLevel_High
#define IS_COMP_OUTPUT(OUTPUT)
#define IS_COMP_NONINVERTING_INPUT(INPUT)


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:19