stm32f30x_opamp.c
Go to the documentation of this file.
1 
95 /* Includes ------------------------------------------------------------------*/
96 #include "stm32f30x_opamp.h"
97 
107 /* Private typedef -----------------------------------------------------------*/
108 /* Private define ------------------------------------------------------------*/
109 #define OPAMP_CSR_DEFAULT_MASK ((uint32_t)0xFFFFFF93)
110 #define OPAMP_CSR_TIMERMUX_MASK ((uint32_t)0xFFFFF8FF)
111 #define OPAMP_CSR_TRIMMING_MASK ((uint32_t)0x0000001F)
112 
113 /* Private macro -------------------------------------------------------------*/
114 /* Private variables ---------------------------------------------------------*/
115 /* Private function prototypes -----------------------------------------------*/
116 /* Private functions ---------------------------------------------------------*/
117 
144 void OPAMP_DeInit(uint32_t OPAMP_Selection)
145 {
147  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = ((uint32_t)0x00000000);
148 }
149 
164 void OPAMP_Init(uint32_t OPAMP_Selection, OPAMP_InitTypeDef* OPAMP_InitStruct)
165 {
166  uint32_t tmpreg = 0;
167 
168  /* Check the parameters */
169  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
172 
174  tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
175 
177  tmpreg &= (uint32_t) (OPAMP_CSR_DEFAULT_MASK);
178 
180  tmpreg |= (uint32_t)(OPAMP_InitStruct->OPAMP_InvertingInput | OPAMP_InitStruct->OPAMP_NonInvertingInput);
181 
183  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
184 }
185 
192 void OPAMP_StructInit(OPAMP_InitTypeDef* OPAMP_InitStruct)
193 {
196 }
197 
209 void OPAMP_PGAConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_PGAGain, uint32_t OPAMP_PGAConnect)
210 {
211  /* Check the parameters */
212  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
213  assert_param(IS_OPAMP_PGAGAIN(OPAMP_PGAGain));
214  assert_param(IS_OPAMP_PGACONNECT(OPAMP_PGAConnect));
215 
216  /* Reset the configuration bits */
217  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_PGGAIN);
218 
219  /* Set the new configuration */
220  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_PGAGain | OPAMP_PGAConnect);
221 }
222 
239 void OPAMP_VrefConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Vref)
240 {
241  uint32_t tmpreg = 0;
242 
243  /* Check the parameters */
244  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
245  assert_param(IS_OPAMP_VREF(OPAMP_Vref));
246 
248  tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
249 
251  tmpreg &= (uint32_t) (~OPAMP_CSR_CALSEL);
252 
254  tmpreg |= (uint32_t)(OPAMP_Vref);
255 
257  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
258 }
259 
271 void OPAMP_VrefConnectNonInvertingInput(uint32_t OPAMP_Selection, FunctionalState NewState)
272 {
273  /* Check the parameters */
274  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
276 
277  if (NewState != DISABLE)
278  {
279  /* Connnect the internal reference to the OPAMP's non inverting input */
280  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_FORCEVP);
281  }
282  else
283  {
284  /* Disconnnect the internal reference to the OPAMP's non inverting input */
285  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_FORCEVP);
286  }
287 }
288 
297 void OPAMP_VrefConnectADCCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
298 {
299  /* Check the parameters */
300  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
302 
303  if (NewState != DISABLE)
304  {
305  /* Enable output internal reference */
306  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_TSTREF);
307  }
308  else
309  {
310  /* Disable output internal reference */
311  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_TSTREF);
312  }
313 }
314 
331 void OPAMP_TimerControlledMuxConfig(uint32_t OPAMP_Selection, OPAMP_InitTypeDef* OPAMP_InitStruct)
332 {
333  uint32_t tmpreg = 0;
334 
335  /* Check the parameters */
336  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
339 
341  tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
342 
344  tmpreg &= (uint32_t) (OPAMP_CSR_TIMERMUX_MASK);
345 
347  tmpreg |= (uint32_t)((uint32_t)(OPAMP_InitStruct->OPAMP_InvertingInput<<3) | (uint32_t)(OPAMP_InitStruct->OPAMP_NonInvertingInput<<7));
348 
350  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
351 }
352 
364 void OPAMP_TimerControlledMuxCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
365 {
366  /* Check the parameters */
367  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
369 
370  if (NewState != DISABLE)
371  {
372  /* Enable the timer-controlled Mux mode */
373  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_TCMEN);
374  }
375  else
376  {
377  /* Disable the timer-controlled Mux mode */
378  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_TCMEN);
379  }
380 }
381 
393 void OPAMP_Cmd(uint32_t OPAMP_Selection, FunctionalState NewState)
394 {
395  /* Check the parameters */
396  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
398 
399  if (NewState != DISABLE)
400  {
401  /* Enable the selected OPAMPx peripheral */
402  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_OPAMPxEN);
403  }
404  else
405  {
406  /* Disable the selected OPAMPx peripheral */
407  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_OPAMPxEN);
408  }
409 }
410 
424 uint32_t OPAMP_GetOutputLevel(uint32_t OPAMP_Selection)
425 {
426  uint32_t opampout = 0x0;
427 
428  /* Check the parameters */
429  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
430 
431  /* Check if selected OPAMP output is high */
432  if ((*(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) & (OPAMP_CSR_OUTCAL)) != 0)
433  {
434  opampout = OPAMP_OutputLevel_High;
435  }
436  else
437  {
438  opampout = OPAMP_OutputLevel_Low;
439  }
440 
441  /* Return the OPAMP output level */
442  return (uint32_t)(opampout);
443 }
444 
458 void OPAMP_OffsetTrimModeSelect(uint32_t OPAMP_Selection, uint32_t OPAMP_Trimming)
459 {
460  /* Check the parameters */
461  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
462  assert_param(IS_OPAMP_TRIMMING(OPAMP_Trimming));
463 
464  /* Reset USERTRIM bit */
465  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (~(uint32_t) (OPAMP_CSR_USERTRIM));
466 
467  /* Select trimming mode */
468  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= OPAMP_Trimming;
469 }
470 
484 void OPAMP_OffsetTrimConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue)
485 {
486  uint32_t tmpreg = 0;
487 
488  /* Check the parameters */
489  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
490  assert_param(IS_OPAMP_INPUT(OPAMP_Input));
491  assert_param(IS_OPAMP_TRIMMINGVALUE(OPAMP_TrimValue));
492 
494  tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
495 
497  tmpreg &= ((uint32_t)~(OPAMP_CSR_TRIMMING_MASK<<OPAMP_Input));
498 
500  tmpreg |= (uint32_t)(OPAMP_TrimValue<<OPAMP_Input);
501 
503  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
504 }
505 
517 void OPAMP_StartCalibration(uint32_t OPAMP_Selection, FunctionalState NewState)
518 {
519  /* Check the parameters */
520  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
522 
523  if (NewState != DISABLE)
524  {
525  /* Start the OPAMPx calibration */
526  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_CALON);
527  }
528  else
529  {
530  /* Stop the OPAMPx calibration */
531  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_CALON);
532  }
533 }
534 
562 void OPAMP_LockConfig(uint32_t OPAMP_Selection)
563 {
564  /* Check the parameter */
565  assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
566 
567  /* Set the lock bit corresponding to selected OPAMP */
568  *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_LOCK);
569 }
570 
575 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define IS_OPAMP_PGACONNECT(CONNECT)
void OPAMP_TimerControlledMuxConfig(uint32_t OPAMP_Selection, OPAMP_InitTypeDef *OPAMP_InitStruct)
Configure the OPAMP peripheral (secondary inputs) for timer-controlled mux mode according to the spec...
#define IS_OPAMP_INVERTING_INPUT(INPUT)
FunctionalState
Definition: stm32f4xx.h:708
void OPAMP_VrefConnectNonInvertingInput(uint32_t OPAMP_Selection, FunctionalState NewState)
Connnect the internal reference to the OPAMP&#39;s non inverting input.
uint32_t OPAMP_NonInvertingInput
void OPAMP_StartCalibration(uint32_t OPAMP_Selection, FunctionalState NewState)
Start or stop the calibration of selected OPAMP peripheral.
void OPAMP_Cmd(uint32_t OPAMP_Selection, FunctionalState NewState)
Enable or disable the OPAMP peripheral.
void assert_param(int val)
#define IS_OPAMP_SECONDARY_INVINPUT(INVINPUT)
void OPAMP_Init(uint32_t OPAMP_Selection, OPAMP_InitTypeDef *OPAMP_InitStruct)
Initializes the OPAMP peripheral according to the specified parameters in OPAMP_InitStruct.
#define IS_FUNCTIONAL_STATE(STATE)
Definition: stm32f4xx.h:709
void OPAMP_StructInit(OPAMP_InitTypeDef *OPAMP_InitStruct)
Fills each OPAMP_InitStruct member with its default value.
#define OPAMP_OutputLevel_Low
void OPAMP_VrefConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Vref)
Configure the OPAMP&#39;s internal reference.
uint32_t OPAMP_InvertingInput
#define __IO
Definition: core_cm0.h:198
#define IS_OPAMP_VREF(VREF)
#define IS_OPAMP_NONINVERTING_INPUT(INPUT)
void OPAMP_OffsetTrimConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue)
Configure the trimming value of the OPAMP.
void OPAMP_DeInit(uint32_t OPAMP_Selection)
Deinitializes OPAMP peripheral registers to their default reset values.
#define IS_OPAMP_TRIMMING(TRIMMING)
#define OPAMP_InvertingInput_IO1
#define IS_OPAMP_ALL_PERIPH(PERIPH)
void OPAMP_TimerControlledMuxCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
Enable or disable the timer-controlled mux mode.
#define OPAMP_CSR_TRIMMING_MASK
#define IS_OPAMP_INPUT(INPUT)
#define OPAMP_CSR_TIMERMUX_MASK
void OPAMP_LockConfig(uint32_t OPAMP_Selection)
Lock the selected OPAMP configuration.
#define IS_OPAMP_PGAGAIN(GAIN)
#define IS_OPAMP_TRIMMINGVALUE(VALUE)
#define OPAMP_OutputLevel_High
uint32_t OPAMP_GetOutputLevel(uint32_t OPAMP_Selection)
Return the output level (high or low) during calibration of the selected OPAMP.
#define OPAMP_NonInvertingInput_IO1
#define OPAMP_CSR_DEFAULT_MASK
void OPAMP_PGAConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_PGAGain, uint32_t OPAMP_PGAConnect)
Configure the feedback resistor gain.
void OPAMP_OffsetTrimModeSelect(uint32_t OPAMP_Selection, uint32_t OPAMP_Trimming)
Select the trimming mode.
This file contains all the functions prototypes for the operational amplifiers (OPAMP) firmware libra...
void OPAMP_VrefConnectADCCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
Enables or disables connecting the OPAMP&#39;s internal reference to ADC.
OPAMP Init structure definition.


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:25