| MINI58_BSP V3.01.003 The Board Support Package for Mini58 Series MCU

adc.c
Go to the documentation of this file.
1/**************************************************************************/
12#include "Mini58Series.h"
13
38 void ADC_Open(ADC_T *adc,
39 uint32_t u32InputMode,
40 uint32_t u32OpMode,
41 uint32_t u32ChMask)
42{
43 ADC->CHEN = (ADC->CHEN & ~(ADC_CHEN_CHEN0_Msk |
44 ADC_CHEN_CHEN1_Msk |
45 ADC_CHEN_CHEN2_Msk |
46 ADC_CHEN_CHEN3_Msk |
47 ADC_CHEN_CHEN4_Msk |
48 ADC_CHEN_CHEN5_Msk |
49 ADC_CHEN_CHEN6_Msk |
50 ADC_CHEN_CHEN7_Msk)) | u32ChMask;
51 return;
52}
53
59 void ADC_Close(ADC_T *adc)
60{
61 SYS->IPRST1 |= SYS_IPRST1_ADCRST_Msk;
62 SYS->IPRST1 &= ~SYS_IPRST1_ADCRST_Msk;
63 return;
64
65}
66
81 void ADC_EnableHWTrigger(ADC_T *adc,
82 uint32_t u32Source,
83 uint32_t u32Param)
84{
85 ADC->CTL &= ~(ADC_TRIGGER_BY_PWM | ADC_RISING_EDGE_TRIGGER | ADC_CTL_HWTRGEN_Msk);
86 if(u32Source == ADC_TRIGGER_BY_EXT_PIN)
87 {
88 ADC->CTL |= u32Source | u32Param | ADC_CTL_HWTRGEN_Msk;
89 }
90 else
91 {
92 ADC->TRGDLY = (ADC->TRGDLY & ~ADC_TRGDLY_DELAY_Msk) | u32Param;
93 ADC->CTL |= u32Source | ADC_CTL_HWTRGEN_Msk;
94 }
95 return;
96}
97
103 void ADC_DisableHWTrigger(ADC_T *adc)
104{
105 ADC->CTL &= ~(ADC_TRIGGER_BY_PWM | ADC_RISING_EDGE_TRIGGER | ADC_CTL_HWTRGEN_Msk);
106 return;
107}
108
128 void ADC_SetExtraSampleTime(ADC_T *adc,
129 uint32_t u32ChNum,
130 uint32_t u32SampleTime)
131{
132 ADC->EXTSMPT = (ADC->EXTSMPT & ~ADC_EXTSMPT_EXTSMPT_Msk) | u32SampleTime;
133}
134
146 void ADC_EnableInt(ADC_T *adc, uint32_t u32Mask)
147{
148 if(u32Mask & ADC_ADIF_INT)
149 ADC->CTL |= ADC_CTL_ADCIEN_Msk;
150 if(u32Mask & ADC_CMP0_INT)
151 ADC->CMP0 |= ADC_CMP0_ADCMPIE_Msk;
152 if(u32Mask & ADC_CMP1_INT)
153 ADC->CMP1 |= ADC_CMP1_ADCMPIE_Msk;
154
155 return;
156}
157
169 void ADC_DisableInt(ADC_T *adc, uint32_t u32Mask)
170{
171 if(u32Mask & ADC_ADIF_INT)
172 ADC->CTL &= ~ADC_CTL_ADCIEN_Msk;
173 if(u32Mask & ADC_CMP0_INT)
174 ADC->CMP0 &= ~ADC_CMP0_ADCMPIE_Msk;
175 if(u32Mask & ADC_CMP1_INT)
176 ADC->CMP1 &= ~ADC_CMP1_ADCMPIE_Msk;
177
178 return;
179}
180
193 void ADC_SeqModeEnable(ADC_T *adc, uint32_t u32SeqTYPE, uint32_t u32ModeSel)
194{
195 // Enable ADC Sequential Mode
196 ADC->SEQCTL = ADC->SEQCTL | ADC_SEQCTL_SEQEN_Msk;
197
198 // Select ADC Sequential Mode Type
199 ADC->SEQCTL = (ADC->SEQCTL & ~(ADC_SEQCTL_SEQTYPE_Msk)) | (u32SeqTYPE << ADC_SEQCTL_SEQTYPE_Pos);
200
201 // Select ADC Sequential Mode Type
202 ADC->SEQCTL = (ADC->SEQCTL & ~(ADC_SEQCTL_MODESEL_Msk)) | (u32ModeSel << ADC_SEQCTL_MODESEL_Pos);
203
204 return;
205}
206
216 void ADC_SeqModeTriggerSrc(ADC_T *adc, uint32_t u32SeqModeTriSrc1, uint32_t u32SeqModeTriSrc2)
217{
218 // Select PWM Trigger Source Selection for TRG1CTL or TRG2CTL
219 ADC->SEQCTL = (ADC->SEQCTL & ~(ADC_SEQCTL_TRG1CTL_Msk)) | (u32SeqModeTriSrc1 << ADC_SEQCTL_TRG1CTL_Pos);
220 ADC->SEQCTL = (ADC->SEQCTL & ~(ADC_SEQCTL_TRG2CTL_Msk)) | (u32SeqModeTriSrc2 << ADC_SEQCTL_TRG2CTL_Pos);
221 return;
222}
223 /* end of group Mini58_ADC_EXPORTED_FUNCTIONS */
225 /* end of group Mini58_ADC_Driver */
227 /* end of group Mini58_Device_Driver */
229
230/*** (C) COPYRIGHT 2022 Nuvoton Technology Corp. ***/
Mini58Series.h
Mini58 series peripheral access layer header file. This file contains all the peripheral register's d...
SYS_IPRST1_ADCRST_Msk
#define SYS_IPRST1_ADCRST_Msk
Definition: Mini58Series.h:10125
ADC_CMP0_INT
#define ADC_CMP0_INT
Definition: adc.h:44
ADC_TRIGGER_BY_PWM
#define ADC_TRIGGER_BY_PWM
Definition: adc.h:40
ADC_ADIF_INT
#define ADC_ADIF_INT
Definition: adc.h:43
ADC_TRIGGER_BY_EXT_PIN
#define ADC_TRIGGER_BY_EXT_PIN
Definition: adc.h:39
ADC_CMP1_INT
#define ADC_CMP1_INT
Definition: adc.h:45
ADC_RISING_EDGE_TRIGGER
#define ADC_RISING_EDGE_TRIGGER
Definition: adc.h:42
ADC_SeqModeTriggerSrc
void ADC_SeqModeTriggerSrc(ADC_T *adc, uint32_t u32SeqModeTriSrc1, uint32_t u32SeqModeTriSrc2)
ADC PWM Sequential Mode PWM Trigger Source and type.
Definition: adc.c:216
ADC_EnableHWTrigger
void ADC_EnableHWTrigger(ADC_T *adc, uint32_t u32Source, uint32_t u32Param)
Configure the hardware trigger condition and enable hardware trigger.
Definition: adc.c:81
ADC_Close
void ADC_Close(ADC_T *adc)
Disable ADC module.
Definition: adc.c:59
ADC_SeqModeEnable
void ADC_SeqModeEnable(ADC_T *adc, uint32_t u32SeqTYPE, uint32_t u32ModeSel)
ADC PWM Sequential Mode Control.
Definition: adc.c:193
ADC_SetExtraSampleTime
void ADC_SetExtraSampleTime(ADC_T *adc, uint32_t u32ChNum, uint32_t u32SampleTime)
Set ADC sample time for designated channel.
Definition: adc.c:128
ADC_Open
void ADC_Open(ADC_T *adc, uint32_t u32InputMode, uint32_t u32OpMode, uint32_t u32ChMask)
This API configures ADC module to be ready for convert the input from selected channel.
Definition: adc.c:38
ADC_DisableInt
void ADC_DisableInt(ADC_T *adc, uint32_t u32Mask)
Disable the interrupt(s) selected by u32Mask parameter.
Definition: adc.c:169
ADC_DisableHWTrigger
void ADC_DisableHWTrigger(ADC_T *adc)
Disable hardware trigger ADC function.
Definition: adc.c:103
ADC_EnableInt
void ADC_EnableInt(ADC_T *adc, uint32_t u32Mask)
Enable the interrupt(s) selected by u32Mask parameter.
Definition: adc.c:146
ADC_SEQCTL_SEQEN_Msk
#define ADC_SEQCTL_SEQEN_Msk
Definition: Mini58Series.h:782
ADC_CHEN_CHEN2_Msk
#define ADC_CHEN_CHEN2_Msk
Definition: Mini58Series.h:698
ADC_CHEN_CHEN5_Msk
#define ADC_CHEN_CHEN5_Msk
Definition: Mini58Series.h:707
ADC_CHEN_CHEN3_Msk
#define ADC_CHEN_CHEN3_Msk
Definition: Mini58Series.h:701
ADC_CHEN_CHEN4_Msk
#define ADC_CHEN_CHEN4_Msk
Definition: Mini58Series.h:704
ADC_CHEN_CHEN0_Msk
#define ADC_CHEN_CHEN0_Msk
Definition: Mini58Series.h:692
ADC_CMP1_ADCMPIE_Msk
#define ADC_CMP1_ADCMPIE_Msk
Definition: Mini58Series.h:740
ADC_SEQCTL_SEQTYPE_Msk
#define ADC_SEQCTL_SEQTYPE_Msk
Definition: Mini58Series.h:785
ADC_CHEN_CHEN1_Msk
#define ADC_CHEN_CHEN1_Msk
Definition: Mini58Series.h:695
ADC_CMP0_ADCMPIE_Msk
#define ADC_CMP0_ADCMPIE_Msk
Definition: Mini58Series.h:722
ADC_SEQCTL_MODESEL_Msk
#define ADC_SEQCTL_MODESEL_Msk
Definition: Mini58Series.h:788
ADC_SEQCTL_TRG1CTL_Pos
#define ADC_SEQCTL_TRG1CTL_Pos
Definition: Mini58Series.h:790
ADC_CTL_HWTRGEN_Msk
#define ADC_CTL_HWTRGEN_Msk
Definition: Mini58Series.h:686
ADC_CTL_ADCIEN_Msk
#define ADC_CTL_ADCIEN_Msk
Definition: Mini58Series.h:677
ADC_CHEN_CHEN6_Msk
#define ADC_CHEN_CHEN6_Msk
Definition: Mini58Series.h:710
ADC_SEQCTL_TRG1CTL_Msk
#define ADC_SEQCTL_TRG1CTL_Msk
Definition: Mini58Series.h:791
ADC_SEQCTL_SEQTYPE_Pos
#define ADC_SEQCTL_SEQTYPE_Pos
Definition: Mini58Series.h:784
ADC_CHEN_CHEN7_Msk
#define ADC_CHEN_CHEN7_Msk
Definition: Mini58Series.h:713
ADC_SEQCTL_TRG2CTL_Pos
#define ADC_SEQCTL_TRG2CTL_Pos
Definition: Mini58Series.h:793
ADC_SEQCTL_TRG2CTL_Msk
#define ADC_SEQCTL_TRG2CTL_Msk
Definition: Mini58Series.h:794
ADC_SEQCTL_MODESEL_Pos
#define ADC_SEQCTL_MODESEL_Pos
Definition: Mini58Series.h:787
ADC
#define ADC
Pointer to ADC register structure.
Definition: Mini58Series.h:11726
SYS
#define SYS
Pointer to SYS register structure.
Definition: Mini58Series.h:11729
ADC_T
Definition: Mini58Series.h:322