CC35xxDriverLibrary
adc.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Filename: adc.h
3  *
4  * Description: Prototypes and defines for the ADC API.
5  *
6  * Copyright (c) 2024-2025 Texas Instruments Incorporated
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1) Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * 2) Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3) Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ******************************************************************************/
35 
36 #ifndef __ADC_H__
37 #define __ADC_H__
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #include <stdint.h>
49 #include "../inc/hw_adc.h"
50 #include "../inc/hw_memmap.h"
51 #include "../inc/hw_types.h"
52 
53 //*****************************************************************************
54 //
55 // If building with a C++ compiler, make all of the definitions in this header
56 // have a C binding.
57 //
58 //*****************************************************************************
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 //*****************************************************************************
64 //
65 // Values
66 //
67 //*****************************************************************************
68 
70 #define ADC_CLOCK_DIVIDER_1 ADC_CTL0_SCLKDIV_DIV_BY_1
71 
73 #define ADC_CLOCK_DIVIDER_2 ADC_CTL0_SCLKDIV_DIV_BY_2
74 
76 #define ADC_CLOCK_DIVIDER_4 ADC_CTL0_SCLKDIV_DIV_BY_4
77 
79 #define ADC_CLOCK_DIVIDER_8 ADC_CTL0_SCLKDIV_DIV_BY_8
80 
82 #define ADC_CLOCK_DIVIDER_16 ADC_CTL0_SCLKDIV_DIV_BY_16
83 
85 #define ADC_CLOCK_DIVIDER_24 ADC_CTL0_SCLKDIV_DIV_BY_24
86 
88 #define ADC_CLOCK_DIVIDER_32 ADC_CTL0_SCLKDIV_DIV_BY_32
89 
91 #define ADC_CLOCK_DIVIDER_48 ADC_CTL0_SCLKDIV_DIV_BY_48
92 
94 #define ADC_MODE_SINGLE (0 << ADC_MEMCTL_0_MOD_S)
95 
97 #define ADC_MODE_DIFFERENTIAL (1 << ADC_MEMCTL_0_MOD_S)
98 
100 #define ADC_INTERNAL_REFERENCE 0
101 
104 #define ADC_EXTERNAL_REFERENCE 1
105 
107 #define ADC_VDDA_REFERENCE 2
108 
110 #define ADC_FULL_SCALE_RANGE_0V0_3V3 0
111 
113 #define ADC_FULL_SCALE_RANGE_0V1_3V3 1
114 
116 #define ADC_FULL_SCALE_RANGE_0V0_3V2 2
117 
119 #define ADC_FULL_SCALE_RANGE_0V0_1V8 3
120 
123 #define ADC_POWER_DOWN_POLICY_AUTO ADC_CTL0_PWRDN_AUTO
124 
127 #define ADC_POWER_DOWN_POLICY_MANUAL ADC_CTL0_PWRDN_MANUAL
128 
131 #define ADC_SEQUENCE_REPEATSEQUENCE ADC_CTL1_CONSEQ_REPEATSEQUENCE
132 
135 #define ADC_SEQUENCE_REPEATSINGLE ADC_CTL1_CONSEQ_REPEATSINGLE
136 
139 #define ADC_SEQUENCE_SEQUENCE ADC_CTL1_CONSEQ_SEQUENCE
140 
143 #define ADC_SEQUENCE_SINGLE ADC_CTL1_CONSEQ_SINGLE
144 
147 #define ADC_SAMPLE_MODE_AUTO ADC_CTL1_SAMPMODE_AUTO
148 
154 #define ADC_SAMPLE_MODE_MANUAL ADC_CTL1_SAMPMODE_MANUAL
155 
160 #define ADC_TRIGGER_SOURCE_EVENT ADC_CTL1_TRIGSRC_EVENT
161 
168 #define ADC_TRIGGER_SOURCE_SOFTWARE ADC_CTL1_TRIGSRC_SOFTWARE
169 
174 #define ADC_TRIGGER_POLICY_AUTO_NEXT ADC_MEMCTL_0_TRIG_AUTO_NEXT
175 
177 #define ADC_TRIGGER_POLICY_TRIGGER_NEXT ADC_MEMCTL_0_TRIG_TRIGGER_NEXT
178 
180 #define ADC_INT_MEMRES_15 ADC_INTEVT0BM_MEMRESIFG15
181 
183 #define ADC_INT_MEMRES_14 ADC_INTEVT0BM_MEMRESIFG14
184 
186 #define ADC_INT_MEMRES_13 ADC_INTEVT0BM_MEMRESIFG13
187 
189 #define ADC_INT_MEMRES_12 ADC_INTEVT0BM_MEMRESIFG12
190 
192 #define ADC_INT_MEMRES_11 ADC_INTEVT0BM_MEMRESIFG11
193 
195 #define ADC_INT_MEMRES_10 ADC_INTEVT0BM_MEMRESIFG10
196 
198 #define ADC_INT_MEMRES_09 ADC_INTEVT0BM_MEMRESIFG9
199 
201 #define ADC_INT_MEMRES_08 ADC_INTEVT0BM_MEMRESIFG8
202 
204 #define ADC_INT_MEMRES_07 ADC_INTEVT0BM_MEMRESIFG7
205 
207 #define ADC_INT_MEMRES_06 ADC_INTEVT0BM_MEMRESIFG6
208 
210 #define ADC_INT_MEMRES_05 ADC_INTEVT0BM_MEMRESIFG5
211 
213 #define ADC_INT_MEMRES_04 ADC_INTEVT0BM_MEMRESIFG4
214 
216 #define ADC_INT_MEMRES_03 ADC_INTEVT0BM_MEMRESIFG3
217 
219 #define ADC_INT_MEMRES_02 ADC_INTEVT0BM_MEMRESIFG2
220 
222 #define ADC_INT_MEMRES_01 ADC_INTEVT0BM_MEMRESIFG1
223 
225 #define ADC_INT_MEMRES_00 ADC_INTEVT0BM_MEMRESIFG0
226 
228 #define ADC_INT_UVIFG ADC_INTEVT0BM_UVIFG
229 
231 #define ADC_INT_DMADONE ADC_INTEVT0BM_DMADONE
232 
234 #define ADC_INT_INIFG ADC_INTEVT0BM_INIFG
235 
237 #define ADC_INT_LOWIFG ADC_INTEVT0BM_LOFG
238 
240 #define ADC_INT_HIGHIFG ADC_INTEVT0BM_HIFG
241 
243 #define ADC_INT_TOVIFG ADC_INTEVT0BM_TOVIFG
244 
246 #define ADC_INT_OVIFG ADC_INTEVT0BM_OVIFG
247 
249 #define ADC_INT_ALL \
250  (ADC_INT_OVIFG | ADC_INT_TOVIFG | ADC_INT_HIGHIFG | ADC_INT_LOWIFG | ADC_INT_INIFG | ADC_INT_DMADONE | \
251  ADC_INT_UVIFG | ADC_INT_MEMRES_00 | ADC_INT_MEMRES_01 | ADC_INT_MEMRES_02 | ADC_INT_MEMRES_03 | \
252  ADC_INT_MEMRES_04 | ADC_INT_MEMRES_05 | ADC_INT_MEMRES_06 | ADC_INT_MEMRES_07 | ADC_INT_MEMRES_08 | \
253  ADC_INT_MEMRES_09 | ADC_INT_MEMRES_10 | ADC_INT_MEMRES_11 | ADC_INT_MEMRES_12 | ADC_INT_MEMRES_13 | \
254  ADC_INT_MEMRES_14 | ADC_INT_MEMRES_15)
255 
256 //*****************************************************************************
257 //
260 //
261 //*****************************************************************************
263 #define ADC_SAMPLE_CLK_NONE 0
264 #define ADC_SAMPLE_CLK_SOC_CLK 1
266 #define ADC_SAMPLE_CLK_HFXT 2
268 #define ADC_SAMPLE_CLK_SOC_PLL_CLK_DIV 3
270 
272 //*****************************************************************************
273 //
274 // API Functions and prototypes
275 //
276 //*****************************************************************************
277 
278 //*****************************************************************************
279 //
310 //
311 //*****************************************************************************
312 extern void ADCSetSampleDuration(uint32_t clkDiv, uint16_t clkCycles);
313 
314 //*****************************************************************************
315 //
340 //
341 //*****************************************************************************
342 extern void ADCSetInput(uint32_t reference, uint8_t channel, uint8_t fullScaleRange, uint32_t index);
343 
344 //*****************************************************************************
345 //
356 //
357 //*****************************************************************************
358 extern void ADCSetMemctlRange(uint32_t start, uint32_t stop);
359 
360 //*****************************************************************************
361 //
371 //
372 //*****************************************************************************
373 extern void ADCSetPowerDownPolicy(uint32_t powerDownPolicy);
374 
375 //*****************************************************************************
376 //
390 //
391 //*****************************************************************************
392 extern void ADCSetSequence(uint32_t sequence);
393 
394 //*****************************************************************************
395 //
407 //
408 //*****************************************************************************
409 extern void ADCSetSamplingClk(uint32_t clkSrc);
410 
411 //*****************************************************************************
412 //
420 //
421 //*****************************************************************************
422 extern void ADCSetSamplingMode(uint32_t samplingMode);
423 
424 //*****************************************************************************
425 //
433 //
434 //*****************************************************************************
435 extern void ADCSetTriggerSource(uint32_t triggerSource);
436 
437 //*****************************************************************************
438 //
452 //
453 //*****************************************************************************
454 extern void ADCSetTriggerPolicy(uint32_t triggerPolicy, uint32_t index);
455 
456 //*****************************************************************************
457 //
467 //
468 //*****************************************************************************
470 {
472 }
473 
474 //*****************************************************************************
475 //
484 //
485 //*****************************************************************************
487 {
489 }
490 
491 //*****************************************************************************
492 //
509 //
510 //*****************************************************************************
512 {
514 }
515 
516 //*****************************************************************************
517 //
526 //
527 //*****************************************************************************
529 {
531 }
532 
533 //*****************************************************************************
534 //
542 //
543 //*****************************************************************************
545 {
547 }
548 
549 //*****************************************************************************
550 //
554 //
555 //*****************************************************************************
557 {
559 }
560 
561 //*****************************************************************************
562 //
572 //
573 //*****************************************************************************
574 __STATIC_INLINE uint32_t ADCReadResult(uint32_t index)
575 {
576 
578 
579  // Return data from result register
580  return HWREG(ADC_BASE + ADC_O_MEMRES_0 + (4 * index));
581 }
582 
583 //*****************************************************************************
584 //
595 //
596 //*****************************************************************************
598 {
599 
601  {
602  return true;
603  }
604  else
605  {
606  return false;
607  }
608 }
609 
610 //*****************************************************************************
611 //
621 //
622 //*****************************************************************************
624 {
625  // Return data from result register
626  return HWREG(ADC_BASE + ADC_O_MEMRES_0 + (4 * index));
627 }
628 
629 //*****************************************************************************
630 //
646 //
647 //*****************************************************************************
648 extern uint32_t ADCValueToMicrovolts(uint32_t adcCode, uint32_t fullScaleRange);
649 
650 //*****************************************************************************
651 //
668 //
669 //*****************************************************************************
670 __STATIC_INLINE void ADCEnableInterrupt(uint32_t intFlags)
671 {
672  // Enable the specified interrupts.
673  HWREG(ADC_BASE + ADC_O_INTEVT0BM) |= intFlags;
674 }
675 
676 //*****************************************************************************
677 //
694 //
695 //*****************************************************************************
696 __STATIC_INLINE void ADCDisableInterrupt(uint32_t intFlags)
697 {
698  // Disable the specified interrupts.
699  HWREG(ADC_BASE + ADC_O_INTEVT0BM) &= ~(intFlags);
700 }
701 
702 //*****************************************************************************
703 //
717 //
718 //*****************************************************************************
720 {
721  return (HWREG(ADC_BASE + ADC_O_INTEVT0RIS));
722 }
723 
724 //*****************************************************************************
725 //
739 //
740 //*****************************************************************************
742 {
743  return (HWREG(ADC_BASE + ADC_O_INTEVT0MIS));
744 }
745 
746 //*****************************************************************************
747 //
784 //
785 //*****************************************************************************
786 __STATIC_INLINE void ADCClearInterrupt(uint32_t intFlags)
787 {
788  // Clear the requested interrupt sources
789  HWREG(ADC_BASE + ADC_O_INTEVT0CLR) = intFlags;
790 }
791 
792 //*****************************************************************************
793 //
806 //
807 //*****************************************************************************
808 extern void ADCStoreTrims(void);
809 
810 //*****************************************************************************
811 //
823 //
824 //*****************************************************************************
825 extern void ADCRestoreTrims(void);
826 
827 //*****************************************************************************
828 //
829 // Mark the end of the C bindings section for C++ compilers.
830 //
831 //*****************************************************************************
832 #ifdef __cplusplus
833 }
834 #endif
835 
836 //*****************************************************************************
837 //
841 //
842 //*****************************************************************************
843 
844 #endif // __ADC_H__
#define ADC_O_INTEVT0RIS
Definition: hw_adc.h:69
void ADCSetTriggerSource(uint32_t triggerSource)
Set ADC trigger source.
Definition: adc.c:183
__STATIC_INLINE uint32_t ADCReadResultNonBlocking(uint32_t index)
Read conversion result from ADC.
Definition: adc.h:623
void ADCSetSequence(uint32_t sequence)
Set conversion sequence.
Definition: adc.c:301
__STATIC_INLINE void ADCStartConversion(void)
Start conversion.
Definition: adc.h:469
uint32_t ADCValueToMicrovolts(uint32_t adcCode, uint32_t fullScaleRange)
Convert ADC code to microvolts.
Definition: adc.c:325
__STATIC_INLINE uint32_t ADCReadResult(uint32_t index)
Read conversion result from ADC.
Definition: adc.h:574
#define HWREG(x)
Definition: hw_types.h:78
#define ADC_CTL1_SC_M
Definition: hw_adc.h:5311
#define ADC_O_INTEVT0MIS
Definition: hw_adc.h:72
#define __STATIC_INLINE
Definition: hw_types.h:57
__STATIC_INLINE uint32_t ADCRawInterruptStatus(void)
Gets the current raw interrupt status.
Definition: adc.h:719
#define ADC_O_STA
Definition: hw_adc.h:225
void ADCSetSamplingMode(uint32_t samplingMode)
Set ADC sampling mode.
Definition: adc.c:159
void ADCSetSamplingClk(uint32_t clkSrc)
Set sampling clock source.
Definition: adc.c:278
#define ADC_O_INTEVT0BM
Definition: hw_adc.h:66
__STATIC_INLINE void ADCStopConversion(void)
Stop sample phase of a conversion.
Definition: adc.h:486
__STATIC_INLINE void ADCDisableDmaTrigger(void)
Disable DMA trigger for data transfer.
Definition: adc.h:556
#define ADC_CTL2_DMAEN_ENABLE
Definition: hw_adc.h:5468
__STATIC_INLINE void ADCEnableDmaTrigger(void)
Enable DMA trigger for data transfer.
Definition: adc.h:544
__STATIC_INLINE void ADCDisableConversion(void)
Disable conversion.
Definition: adc.h:528
void ADCSetPowerDownPolicy(uint32_t powerDownPolicy)
Set power down policy.
Definition: adc.c:254
__STATIC_INLINE void ADCClearInterrupt(uint32_t intFlags)
Clears ADC interrupt sources.
Definition: adc.h:786
__STATIC_INLINE bool ADCIsBusy(void)
Check if ADC is busy.
Definition: adc.h:597
__STATIC_INLINE void ADCDisableInterrupt(uint32_t intFlags)
Disables individual ADC interrupt sources.
Definition: adc.h:696
void ADCSetSampleDuration(uint32_t clkDiv, uint16_t clkCycles)
Sets the clock-divider value, and sample duration.
Definition: adc.c:53
#define ADC_O_MEMRES_0
Definition: hw_adc.h:177
__STATIC_INLINE void ADCEnableInterrupt(uint32_t intFlags)
Enables individual ADC interrupt sources.
Definition: adc.h:670
#define ADC_O_CTL0
Definition: hw_adc.h:123
#define ADC_O_INTEVT0CLR
Definition: hw_adc.h:78
#define ADC_STA_BUSY_ACTIVE
Definition: hw_adc.h:7777
void ADCSetInput(uint32_t reference, uint8_t channel, uint8_t fullScaleRange, uint32_t index)
Sets the ADC reference source and input channel.
Definition: adc.c:81
__STATIC_INLINE uint32_t ADCMaskedInterruptStatus(void)
Gets the current masked interrupt status.
Definition: adc.h:741
#define ADC_O_CTL2
Definition: hw_adc.h:129
void ADCRestoreTrims(void)
Restore trim values.
Definition: adc.c:385
#define ADC_CTL0_ENC_M
Definition: hw_adc.h:5215
#define ADC_CTL2_DMAEN_M
Definition: hw_adc.h:5465
#define ADC_CTL0_ENC_ON
Definition: hw_adc.h:5218
__STATIC_INLINE void ADCEnableConversion(void)
Enable conversion.
Definition: adc.h:511
void ADCSetMemctlRange(uint32_t start, uint32_t stop)
Set start and stop control registers.
Definition: adc.c:231
void ADCSetTriggerPolicy(uint32_t triggerPolicy, uint32_t index)
Set ADC trigger policy.
Definition: adc.c:207
void ADCStoreTrims(void)
Store trim values.
Definition: adc.c:375
#define ADC_O_CTL1
Definition: hw_adc.h:126
#define ADC_BASE
Definition: hw_memmap.h:100
#define ADC_CTL1_SC_START
Definition: hw_adc.h:5313