MSPM0L11XX_L13XX Driver Library  2.05.01.00
dl_opa.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file dl_opa.h
34  * @brief Op-Amp (OPA) Driver Library
35  * @defgroup OPA Op-Amp (OPA)
36  *
37  * @anchor ti_dl_dl_opa_Overview
38  * # Overview
39  *
40  * The OP-Amp Driver Library allows full configuration of the MSPM0 OPA module.
41  * The OPA is a zero-drift chopper stabilized operational amplifier with a
42  * programmable gain stage.
43  *
44  * <hr>
45 
46  ******************************************************************************
47  */
51 #ifndef ti_dl_dl_opa__include
52 #define ti_dl_dl_opa__include
53 
54 #include <stdbool.h>
55 #include <stdint.h>
56 
57 #include <ti/devices/msp/msp.h>
58 #include <ti/driverlib/dl_common.h>
59 
60 #ifdef __MSPM0_HAS_OA__
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
67 typedef enum {
69  DL_OPA_CHOPPING_MODE_DISABLE = OA_CFG_CHOP_OFF,
76 
78 typedef enum {
79 
81  DL_OPA_OUTPUT_PIN_ENABLED = OA_CFG_OUTPIN_ENABLED,
83  DL_OPA_OUTPUT_PIN_DISABLED = OA_CFG_OUTPIN_DISABLED,
84 
86 
88 typedef enum {
90  DL_OPA_PSEL_OPEN = OA_CFG_PSEL_NC,
92  DL_OPA_PSEL_IN0_POS = OA_CFG_PSEL_EXTPIN0,
94  DL_OPA_PSEL_IN1_POS = OA_CFG_PSEL_EXTPIN1,
96  DL_OPA_PSEL_DAC_OUT = OA_CFG_PSEL_DAC12OUT,
98  DL_OPA_PSEL_DAC8_OUT = OA_CFG_PSEL_DAC8OUT,
100  DL_OPA_PSEL_VREF = OA_CFG_PSEL_VREF,
102  DL_OPA_PSEL_RTOP = OA_CFG_PSEL_OANM1RTOP,
103 
105  DL_OPA_PSEL_GPAMP_OUT = OA_CFG_PSEL_GPAMP_OUT_INT,
107  DL_OPA_PSEL_GND = OA_CFG_PSEL_VSS,
108 
109 } DL_OPA_PSEL;
110 
112 typedef enum {
114  DL_OPA_NSEL_OPEN = OA_CFG_NSEL_NC,
116  DL_OPA_NSEL_IN0_NEG = OA_CFG_NSEL_EXTPIN0,
118  DL_OPA_NSEL_IN1_NEG = OA_CFG_NSEL_EXTPIN1,
120  DL_OPA_NSEL_RBOT = OA_CFG_NSEL_OANP1RBOT,
122  DL_OPA_NSEL_RTAP = OA_CFG_NSEL_OANRTAP,
124  DL_OPA_NSEL_RTOP = OA_CFG_NSEL_OANRTOP,
126  DL_OPA_NSEL_SPARE = OA_CFG_NSEL_SPARE,
127 } DL_OPA_NSEL;
128 
130 typedef enum {
132  DL_OPA_MSEL_OPEN = OA_CFG_MSEL_NC,
134  DL_OPA_MSEL_IN1_NEG = OA_CFG_MSEL_EXTNPIN1,
136  DL_OPA_MSEL_GND = OA_CFG_MSEL_VSS,
138  DL_OPA_MSEL_DAC_OUT = OA_CFG_MSEL_DAC12OUT,
140  DL_OPA_MSEL_RTOP = OA_CFG_MSEL_OANM1RTOP,
141 } DL_OPA_MSEL;
142 
144 typedef enum {
146  DL_OPA_GBW_HIGH = OA_CFGBASE_GBW_HIGHGAIN,
148  DL_OPA_GBW_LOW = OA_CFGBASE_GBW_LOWGAIN,
149 } DL_OPA_GBW;
150 
152 typedef enum {
154  DL_OPA_GAIN_N0_P1 = (((uint32_t) 0x0) << OA_CFG_GAIN_OFS),
157  DL_OPA_GAIN_N1_P2 = (((uint32_t) 0x1) << OA_CFG_GAIN_OFS),
160  DL_OPA_GAIN_N3_P4 = (((uint32_t) 0x2) << OA_CFG_GAIN_OFS),
163  DL_OPA_GAIN_N7_P8 = (((uint32_t) 0x3) << OA_CFG_GAIN_OFS),
166  DL_OPA_GAIN_N15_P16 = (((uint32_t) 0x4) << OA_CFG_GAIN_OFS),
169  DL_OPA_GAIN_N31_P32 = (((uint32_t) 0x5) << OA_CFG_GAIN_OFS),
170 } DL_OPA_GAIN;
171 
175 typedef struct {
177  DL_OPA_CHOPPING_MODE choppingMode;
179  DL_OPA_OUTPUT_PIN_STATE outputPinState;
181  DL_OPA_PSEL pselChannel;
183  DL_OPA_NSEL nselChannel;
185  DL_OPA_MSEL mselChannel;
188 } DL_OPA_Config;
189 
201 __STATIC_INLINE void DL_OPA_enablePower(OA_Regs *opa)
202 {
203  opa->GPRCM.PWREN = (OA_PWREN_KEY_UNLOCK_W | OA_PWREN_ENABLE_ENABLE);
204 }
205 
217 __STATIC_INLINE void DL_OPA_disablePower(OA_Regs *opa)
218 {
219  opa->GPRCM.PWREN = (OA_PWREN_KEY_UNLOCK_W | OA_PWREN_ENABLE_DISABLE);
220 }
221 
238 __STATIC_INLINE bool DL_OPA_isPowerEnabled(const OA_Regs *opa)
239 {
240  return (
241  (opa->GPRCM.PWREN & OA_PWREN_ENABLE_MASK) == OA_PWREN_ENABLE_ENABLE);
242 }
243 
249 __STATIC_INLINE void DL_OPA_reset(OA_Regs *opa)
250 {
251  opa->GPRCM.RSTCTL = (OA_RSTCTL_KEY_UNLOCK_W | OA_RSTCTL_RESETSTKYCLR_CLR |
252  OA_RSTCTL_RESETASSERT_ASSERT);
253 }
254 
264 __STATIC_INLINE bool DL_OPA_isReset(const OA_Regs *opa)
265 {
266  return ((opa->GPRCM.STAT & OA_GPRCM_STAT_RESETSTKY_MASK) ==
267  OA_GPRCM_STAT_RESETSTKY_RESET);
268 }
269 
275 __STATIC_INLINE void DL_OPA_enable(OA_Regs *opa)
276 {
277  opa->CTL |= OA_CTL_ENABLE_ON;
278 }
279 
291 __STATIC_INLINE bool DL_OPA_isEnabled(const OA_Regs *opa)
292 {
293  return ((opa->CTL & OA_CTL_ENABLE_MASK) == OA_CTL_ENABLE_ON);
294 }
295 
301 __STATIC_INLINE void DL_OPA_disable(OA_Regs *opa)
302 {
303  opa->CTL &= ~(OA_CTL_ENABLE_MASK);
304 }
305 
316 __STATIC_INLINE void DL_OPA_init(OA_Regs *opa, const DL_OPA_Config *config)
317 {
318  DL_Common_updateReg(&opa->CFG,
319  (uint32_t) config->choppingMode | (uint32_t) config->outputPinState |
320  (uint32_t) config->pselChannel | (uint32_t) config->nselChannel |
321  (uint32_t) config->mselChannel | (uint32_t) config->gain,
322  OA_CFG_CHOP_MASK | OA_CFG_OUTPIN_MASK | OA_CFG_PSEL_MASK |
323  OA_CFG_NSEL_MASK | OA_CFG_MSEL_MASK | OA_CFG_GAIN_MASK);
324 }
325 
337 __STATIC_INLINE void DL_OPA_setGainBandwidth(
338  OA_Regs *opa, DL_OPA_GBW bandwidth)
339 {
341  &opa->CFGBASE, (uint32_t) bandwidth, OA_CFGBASE_GBW_MASK);
342 }
343 
353 __STATIC_INLINE DL_OPA_GBW DL_OPA_getGainBandwidth(const OA_Regs *opa)
354 {
355  uint32_t bandwidth = (opa->CFGBASE & OA_CFGBASE_GBW_MASK);
356 
357  return (DL_OPA_GBW)(bandwidth);
358 }
359 
370 __STATIC_INLINE void DL_OPA_enableRailToRailInput(OA_Regs *opa)
371 {
372  opa->CFGBASE |= OA_CFGBASE_RRI_ON;
373 }
374 
386 __STATIC_INLINE bool DL_OPA_isRailToRailInputEnabled(OA_Regs *opa)
387 {
388  return ((opa->CFGBASE &= OA_CFGBASE_RRI_MASK) == OA_CFGBASE_RRI_ON);
389 }
390 
396 __STATIC_INLINE void DL_OPA_disableRailToRailInput(OA_Regs *opa)
397 {
398  opa->CFGBASE &= ~(OA_CFGBASE_RRI_MASK);
399 }
400 
408 __STATIC_INLINE void DL_OPA_setChoppingMode(
409  OA_Regs *opa, DL_OPA_CHOPPING_MODE mode)
410 {
411  DL_Common_updateReg(&opa->CFG, (uint32_t) mode, OA_CFG_CHOP_MASK);
412 }
413 
423 __STATIC_INLINE DL_OPA_CHOPPING_MODE DL_OPA_getChoppingMode(const OA_Regs *opa)
424 {
425  uint32_t mode = (opa->CFG & OA_CFG_CHOP_MASK);
426 
427  return (DL_OPA_CHOPPING_MODE)(mode);
428 }
429 
444 __STATIC_INLINE void DL_OPA_setOutputPinState(
445  OA_Regs *opa, DL_OPA_OUTPUT_PIN_STATE state)
446 {
447  DL_Common_updateReg(&opa->CFG, (uint32_t) state, OA_CFG_OUTPIN_MASK);
448 }
449 
466 __STATIC_INLINE DL_OPA_OUTPUT_PIN_STATE DL_OPA_getOutputPinState(
467  const OA_Regs *opa)
468 {
469  uint32_t state = (opa->CFG & OA_CFG_OUTPIN_MASK);
470 
471  return (DL_OPA_OUTPUT_PIN_STATE)(state);
472 }
473 
483 __STATIC_INLINE void DL_OPA_disableOutputPin(OA_Regs *opa)
484 {
485  opa->CFG &= ~(OA_CFG_OUTPIN_MASK);
486 }
487 
499  OA_Regs *opa, DL_OPA_PSEL inputChannel)
500 {
501  DL_Common_updateReg(&opa->CFG, (uint32_t) inputChannel, OA_CFG_PSEL_MASK);
502 }
503 
513 __STATIC_INLINE DL_OPA_PSEL DL_OPA_getNonInvertingInputChannel(
514  const OA_Regs *opa)
515 {
516  uint32_t inputChannel = (opa->CFG & OA_CFG_PSEL_MASK);
517 
518  return (DL_OPA_PSEL)(inputChannel);
519 }
520 
531 __STATIC_INLINE void DL_OPA_setInvertingInputChannel(
532  OA_Regs *opa, DL_OPA_NSEL inputChannel)
533 {
534  DL_Common_updateReg(&opa->CFG, (uint32_t) inputChannel, OA_CFG_NSEL_MASK);
535 }
536 
546 __STATIC_INLINE DL_OPA_NSEL DL_OPA_getInvertingInputChannel(const OA_Regs *opa)
547 {
548  uint32_t inputChannel = (opa->CFG & OA_CFG_NSEL_MASK);
549 
550  return (DL_OPA_NSEL)(inputChannel);
551 }
552 
563 __STATIC_INLINE void DL_OPA_setMMUXInputChannel(
564  OA_Regs *opa, DL_OPA_MSEL inputChannel)
565 {
566  DL_Common_updateReg(&opa->CFG, (uint32_t) inputChannel, OA_CFG_MSEL_MASK);
567 }
568 
578 __STATIC_INLINE DL_OPA_MSEL DL_OPA_getMMUXInputChannel(const OA_Regs *opa)
579 {
580  uint32_t inputChannel = (opa->CFG & OA_CFG_MSEL_MASK);
581 
582  return (DL_OPA_MSEL)(inputChannel);
583 }
584 
597 __STATIC_INLINE void DL_OPA_setGain(OA_Regs *opa, DL_OPA_GAIN gain)
598 {
599  DL_Common_updateReg(&opa->CFG, (uint32_t) gain, OA_CFG_GAIN_MASK);
600 }
601 
613 __STATIC_INLINE DL_OPA_GAIN DL_OPA_getGain(const OA_Regs *opa)
614 {
615  uint32_t gain = (opa->CFG & OA_CFG_GAIN_MASK);
616 
617  return (DL_OPA_GAIN)(gain);
618 }
619 
634 DL_OPA_GAIN DL_OPA_increaseGain(OA_Regs *opa);
635 
650 DL_OPA_GAIN DL_OPA_decreaseGain(OA_Regs *opa);
651 
663 __STATIC_INLINE bool DL_OPA_isReady(const OA_Regs *opa)
664 {
665  return ((opa->STAT & OA_STAT_RDY_MASK) == OA_STAT_RDY_TRUE);
666 }
667 
668 #ifdef __cplusplus
669 }
670 #endif
671 #endif /* __MSPM0_HAS_OA__ */
672 
673 #endif /* ti_dl_dl_opa__include */
674 
Definition: dl_opa.h:160
DL_OPA_GAIN DL_OPA_increaseGain(OA_Regs *opa)
Increment gain to the next DL_OPA_GAIN enum value.
__STATIC_INLINE void DL_Common_updateReg(volatile uint32_t *reg, uint32_t val, uint32_t mask)
Writes value to specified register - retaining bits unaffected by mask.
Definition: dl_common.h:63
Definition: dl_opa.h:102
__STATIC_INLINE void DL_OPA_setInvertingInputChannel(OA_Regs *opa, DL_OPA_NSEL inputChannel)
Set the inverting input channel.
Definition: dl_opa.h:531
__STATIC_INLINE void DL_OPA_enablePower(OA_Regs *opa)
Enables the Peripheral Write Enable (PWREN) register for the OPA.
Definition: dl_opa.h:201
Definition: dl_opa.h:100
Definition: dl_opa.h:124
Definition: dl_opa.h:148
DL_OPA_GAIN DL_OPA_decreaseGain(OA_Regs *opa)
Decrement gain to the next DL_OPA_GAIN enum value.
DL_OPA_NSEL nselChannel
Definition: dl_opa.h:183
__STATIC_INLINE bool DL_OPA_isRailToRailInputEnabled(OA_Regs *opa)
Checks if the the rail-to-rail input (RRI) is enabled.
Definition: dl_opa.h:386
__STATIC_INLINE void DL_OPA_setGain(OA_Regs *opa, DL_OPA_GAIN gain)
Set the gain for the programmable gain stage.
Definition: dl_opa.h:597
Definition: dl_opa.h:83
Definition: dl_opa.h:140
__STATIC_INLINE void DL_OPA_setGainBandwidth(OA_Regs *opa, DL_OPA_GBW bandwidth)
Set the gain bandwidth (GBW)
Definition: dl_opa.h:337
Definition: dl_opa.h:114
Definition: dl_opa.h:122
__STATIC_INLINE bool DL_OPA_isReady(const OA_Regs *opa)
Checks if the OPA is ready.
Definition: dl_opa.h:663
Definition: dl_opa.h:92
Definition: dl_opa.h:116
Definition: dl_opa.h:157
__STATIC_INLINE void DL_OPA_setMMUXInputChannel(OA_Regs *opa, DL_OPA_MSEL inputChannel)
Set the M-MUX input channel.
Definition: dl_opa.h:563
__STATIC_INLINE void DL_OPA_disablePower(OA_Regs *opa)
Disables the Peripheral Write Enable (PWREN) register for the OPA.
Definition: dl_opa.h:217
__STATIC_INLINE void DL_OPA_disableOutputPin(OA_Regs *opa)
Disable the OPA output signal to be accessed by a device pin.
Definition: dl_opa.h:483
DriverLib Common APIs.
Definition: dl_opa.h:134
__STATIC_INLINE DL_OPA_MSEL DL_OPA_getMMUXInputChannel(const OA_Regs *opa)
Get the M-MUX input channel.
Definition: dl_opa.h:578
Definition: dl_opa.h:120
__STATIC_INLINE DL_OPA_NSEL DL_OPA_getInvertingInputChannel(const OA_Regs *opa)
Get the inverting input channel.
Definition: dl_opa.h:546
Definition: dl_opa.h:163
Definition: dl_opa.h:69
Definition: dl_opa.h:71
__STATIC_INLINE DL_OPA_OUTPUT_PIN_STATE DL_OPA_getOutputPinState(const OA_Regs *opa)
Get the state of the output pin.
Definition: dl_opa.h:466
__STATIC_INLINE DL_OPA_GBW DL_OPA_getGainBandwidth(const OA_Regs *opa)
Get the gain bandwidth (GBW)
Definition: dl_opa.h:353
__STATIC_INLINE void DL_OPA_disable(OA_Regs *opa)
Disable the OPA peripheral.
Definition: dl_opa.h:301
__STATIC_INLINE bool DL_OPA_isReset(const OA_Regs *opa)
Returns if OPA peripheral was reset.
Definition: dl_opa.h:264
Definition: dl_opa.h:98
Definition: dl_opa.h:126
Definition: dl_opa.h:118
__STATIC_INLINE void DL_OPA_reset(OA_Regs *opa)
Resets OPA peripheral.
Definition: dl_opa.h:249
__STATIC_INLINE void DL_OPA_enable(OA_Regs *opa)
Enable the OPA peripheral.
Definition: dl_opa.h:275
__STATIC_INLINE bool DL_OPA_isEnabled(const OA_Regs *opa)
Checks if the OPA peripheral is enabled.
Definition: dl_opa.h:291
__STATIC_INLINE DL_OPA_GAIN DL_OPA_getGain(const OA_Regs *opa)
Get the gain from the programmable gain stage.
Definition: dl_opa.h:613
__STATIC_INLINE DL_OPA_PSEL DL_OPA_getNonInvertingInputChannel(const OA_Regs *opa)
Get the non-inverting input channel.
Definition: dl_opa.h:513
__STATIC_INLINE DL_OPA_CHOPPING_MODE DL_OPA_getChoppingMode(const OA_Regs *opa)
Get the chopping mode.
Definition: dl_opa.h:423
DL_OPA_GBW
Definition: dl_opa.h:144
Definition: dl_opa.h:90
Definition: dl_opa.h:94
__STATIC_INLINE void DL_OPA_init(OA_Regs *opa, const DL_OPA_Config *config)
Initialize the OPA peripheral.
Definition: dl_opa.h:316
Definition: dl_opa.h:138
DL_OPA_CHOPPING_MODE
Definition: dl_opa.h:67
DL_OPA_MSEL
Definition: dl_opa.h:130
Definition: dl_opa.h:74
__STATIC_INLINE void DL_OPA_setChoppingMode(OA_Regs *opa, DL_OPA_CHOPPING_MODE mode)
Set and enable the chopping mode.
Definition: dl_opa.h:408
Definition: dl_opa.h:169
DL_OPA_MSEL mselChannel
Definition: dl_opa.h:185
Definition: dl_opa.h:136
__STATIC_INLINE void DL_OPA_setNonInvertingInputChannel(OA_Regs *opa, DL_OPA_PSEL inputChannel)
Set the non-inverting input channel.
Definition: dl_opa.h:498
DL_OPA_GAIN
Definition: dl_opa.h:152
Definition: dl_opa.h:96
__STATIC_INLINE bool DL_OPA_isPowerEnabled(const OA_Regs *opa)
Returns if the Peripheral Write Enable (PWREN) register for the OPA is enabled.
Definition: dl_opa.h:238
__STATIC_INLINE void DL_OPA_setOutputPinState(OA_Regs *opa, DL_OPA_OUTPUT_PIN_STATE state)
Set the state of the output pin.
Definition: dl_opa.h:444
__STATIC_INLINE void DL_OPA_enableRailToRailInput(OA_Regs *opa)
Enable the rail-to-rail input (RRI)
Definition: dl_opa.h:370
Configuration struct for DL_OPA_init.
Definition: dl_opa.h:175
DL_OPA_GAIN gain
Definition: dl_opa.h:187
DL_OPA_OUTPUT_PIN_STATE
Definition: dl_opa.h:78
Definition: dl_opa.h:107
Definition: dl_opa.h:132
__STATIC_INLINE void DL_OPA_disableRailToRailInput(OA_Regs *opa)
Disable the rail-to-rail input (RRI)
Definition: dl_opa.h:396
DL_OPA_NSEL
Definition: dl_opa.h:112
Definition: dl_opa.h:146
DL_OPA_PSEL
Definition: dl_opa.h:88
Definition: dl_opa.h:166
DL_OPA_OUTPUT_PIN_STATE outputPinState
Definition: dl_opa.h:179
Definition: dl_opa.h:154
DL_OPA_CHOPPING_MODE choppingMode
Definition: dl_opa.h:177
Definition: dl_opa.h:105
DL_OPA_PSEL pselChannel
Definition: dl_opa.h:181
Definition: dl_opa.h:81
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale