EFR32 Mighty Gecko 13 Software Documentation  efr32mg13-doc-5.1.2
em_csen.c
Go to the documentation of this file.
1 /***************************************************************************/
33 #include "em_csen.h"
34 #if defined( CSEN_COUNT ) && ( CSEN_COUNT > 0 )
35 
36 #include "em_assert.h"
37 #include "em_cmu.h"
38 #include <stddef.h>
39 
40 /***************************************************************************/
45 /***************************************************************************/
50 /*******************************************************************************
51  ******************************* DEFINES ***********************************
52  ******************************************************************************/
53 
57 #define CSEN_REF_VALID(ref) ((ref) == CSEN)
58 
61 /*******************************************************************************
62  ************************** GLOBAL FUNCTIONS *******************************
63  ******************************************************************************/
64 
65 /***************************************************************************/
88 void CSEN_DMBaselineSet(CSEN_TypeDef *csen, uint32_t up, uint32_t down)
89 {
90  EFM_ASSERT(up < 0x10000);
91  EFM_ASSERT(down < 0x10000);
92 
95 }
96 
97 
98 /***************************************************************************/
115 void CSEN_Init(CSEN_TypeDef *csen, const CSEN_Init_TypeDef *init)
116 {
117  uint32_t tmp;
118 
119  EFM_ASSERT(CSEN_REF_VALID(csen));
120  EFM_ASSERT(init->warmUpCount < 4);
121 
122  /* Initialize CTRL. This will stop any conversion in progress. */
123  tmp = CSEN_CTRL_STM_DEFAULT;
124 
125  if (init->cpAccuracyHi)
126  {
128  }
129 
130  if (init->localSense)
131  {
133  }
134 
135  if (init->keepWarm)
136  {
138  }
139 
140  csen->CTRL = tmp;
141 
142  /* Initialize TIMCTRL. */
146 
147  /* PRSSEL only has one field */
148  csen->PRSSEL = init->prsSel << _CSEN_PRSSEL_PRSSEL_SHIFT;
149 
150  /* Set input selections for inputs 0 to 31 */
152  | (init->input8To15 << _CSEN_SCANINPUTSEL0_INPUT8TO15SEL_SHIFT)
153  | (init->input16To23 << _CSEN_SCANINPUTSEL0_INPUT16TO23SEL_SHIFT)
154  | (init->input24To31 << _CSEN_SCANINPUTSEL0_INPUT24TO31SEL_SHIFT);
155 
156  /* Set input selections for inputs 32 to 63 */
157  csen->SCANINPUTSEL1 = (init->input32To39 << _CSEN_SCANINPUTSEL1_INPUT32TO39SEL_SHIFT)
158  | (init->input40To47 << _CSEN_SCANINPUTSEL1_INPUT40TO47SEL_SHIFT)
159  | (init->input48To55 << _CSEN_SCANINPUTSEL1_INPUT48TO55SEL_SHIFT)
160  | (init->input56To63 << _CSEN_SCANINPUTSEL1_INPUT56TO63SEL_SHIFT);
161 }
162 
163 
164 /***************************************************************************/
187 {
188  uint32_t tmp;
189 
190  EFM_ASSERT(CSEN_REF_VALID(csen));
191  EFM_ASSERT(init->dmIterPerCycle < 0x10);
192  EFM_ASSERT(init->dmCycles < 0x10);
193 
194  /* Initialize CTRL. This will stop any conversion in progress.
195  * These composite inputs set multiple fields. They do not need
196  * to be shifted. */
197  tmp = ((uint32_t)init->sampleMode
198  | (uint32_t)init->convSel
199  | (uint32_t)init->cmpMode);
200 
201  tmp |= (init->trigSel << _CSEN_CTRL_STM_SHIFT)
202  | (init->accMode << _CSEN_CTRL_ACU_SHIFT)
203  | (init->sarRes << _CSEN_CTRL_SARCR_SHIFT);
204 
205  if (init->enableDma)
206  {
207  tmp |= CSEN_CTRL_DMAEN_ENABLE;
208  }
209 
210  if (init->sumOnly)
211  {
212  tmp |= CSEN_CTRL_DRSF_ENABLE;
213  }
214 
215  if (init->autoGnd)
216  {
218  }
219 
220  /* Preserve the fields that were initialized by CSEN_Init(). */
221  tmp |= csen->CTRL & (_CSEN_CTRL_CPACCURACY_MASK
224 
225  csen->CTRL = tmp;
226 
227  /* EMACTRL only has one field */
229 
230  /* CMPTHR only has one field */
231  csen->CMPTHR = init->cmpThr << _CSEN_CMPTHR_CMPTHR_SHIFT;
232 
233  /* SINGLECTRL only has one field */
235 
236  /* Set all input enables */
237  csen->SCANMASK0 = init->inputMask0;
238  csen->SCANMASK1 = init->inputMask1;
239 
240  /* Initialize DMCFG. */
241  tmp = (init->dmRes << _CSEN_DMCFG_CRMODE_SHIFT)
242  | (init->dmCycles << _CSEN_DMCFG_DMCR_SHIFT)
244  | (init->dmDelta << _CSEN_DMCFG_DMG_SHIFT);
245 
246  if (init->dmFixedDelta)
247  {
248  tmp |= CSEN_DMCFG_DMGRDIS;
249  }
250 
251  csen->DMCFG = tmp;
252 
253  /* Initialize ANACTRL. */
257 }
258 
259 
260 /***************************************************************************/
268 {
269  EFM_ASSERT(CSEN_REF_VALID(csen));
270 
271  /* Resetting CTRL stops any conversion in progress. */
272  csen->CTRL = _CSEN_CTRL_RESETVALUE;
275  csen->DATA = _CSEN_DATA_RESETVALUE;
281  csen->EMA = _CSEN_EMA_RESETVALUE;
287  csen->IEN = _CSEN_IEN_RESETVALUE;
288  csen->IFC = _CSEN_IF_MASK;
289 }
290 
291 
294 #endif /* defined(CSEN_COUNT) && (CSEN_COUNT > 0) */
Clock management unit (CMU) API.
#define _CSEN_SCANINPUTSEL1_INPUT32TO39SEL_SHIFT
#define _CSEN_SCANINPUTSEL1_RESETVALUE
CSEN_InputSel_TypeDef input0To7
Definition: em_csen.h:387
#define _CSEN_DMBASELINE_RESETVALUE
#define _CSEN_SCANINPUTSEL1_INPUT56TO63SEL_SHIFT
__IOM uint32_t PRSSEL
#define _CSEN_SCANINPUTSEL0_INPUT16TO23SEL_SHIFT
#define _CSEN_CTRL_RESETVALUE
Emlib peripheral API "assert" implementation.
__IOM uint32_t DATA
CSEN_GainSel_TypeDef gainSel
Definition: em_csen.h:496
#define _CSEN_ANACTRL_IREFPROG_SHIFT
#define _CSEN_TIMCTRL_PCPRESC_SHIFT
#define _CSEN_DMCFG_CRMODE_SHIFT
#define _CSEN_EMACTRL_RESETVALUE
#define CSEN_CTRL_WARMUPMODE_KEEPCSENWARM
__IOM uint32_t DMBASELINE
#define _CSEN_PRSSEL_RESETVALUE
#define CSEN_CTRL_DMAEN_ENABLE
CSEN_ConvSel_TypeDef convSel
Definition: em_csen.h:463
CSEN_SingleSel_TypeDef singleSel
Definition: em_csen.h:445
CSEN_ResetPhaseSel_TypeDef resetPhase
Definition: em_csen.h:489
#define _CSEN_DATA_RESETVALUE
#define _CSEN_SINGLECTRL_RESETVALUE
__IOM uint32_t ANACTRL
#define _CSEN_EMACTRL_EMASAMPLE_SHIFT
#define _CSEN_SINGLECTRL_SINGLESEL_SHIFT
#define _CSEN_IEN_RESETVALUE
uint8_t dmIterPerCycle
Definition: em_csen.h:473
#define _CSEN_CTRL_LOCALSENS_MASK
#define _CSEN_DMCFG_DMG_SHIFT
__IOM uint32_t EMA
#define _CSEN_TIMCTRL_WARMUPCNT_SHIFT
#define CSEN_CTRL_DRSF_ENABLE
CSEN_CmpMode_TypeDef cmpMode
Definition: em_csen.h:439
__IOM uint32_t TIMCTRL
__IOM uint32_t DMCFG
#define _CSEN_TIMCTRL_PCTOP_SHIFT
#define _CSEN_SCANINPUTSEL1_INPUT40TO47SEL_SHIFT
#define CSEN_DMCFG_DMGRDIS
#define CSEN_CTRL_AUTOGND_ENABLE
#define _CSEN_CTRL_ACU_SHIFT
#define _CSEN_CMPTHR_CMPTHR_SHIFT
CSEN_SARRes_TypeDef sarRes
Definition: em_csen.h:466
CSEN_TrigSel_TypeDef trigSel
Definition: em_csen.h:424
void CSEN_Init(CSEN_TypeDef *csen, const CSEN_Init_TypeDef *init)
Initialize CSEN.
Definition: em_csen.c:115
__IOM uint32_t IFC
#define _CSEN_ANACTRL_RESETVALUE
#define _CSEN_DMBASELINE_BASELINEUP_SHIFT
__IOM uint32_t SINGLECTRL
CSEN_EMASample_TypeDef emaSample
Definition: em_csen.h:436
#define _CSEN_EMA_RESETVALUE
uint8_t warmUpCount
Definition: em_csen.h:375
#define CSEN_CTRL_CPACCURACY_HI
CSEN_PCPrescale_TypeDef pcPrescale
Definition: em_csen.h:381
__IOM uint32_t SCANINPUTSEL1
#define _CSEN_CTRL_WARMUPMODE_MASK
#define _CSEN_SCANINPUTSEL1_INPUT48TO55SEL_SHIFT
CSEN_DMRes_TypeDef dmRes
Definition: em_csen.h:469
#define _CSEN_SCANINPUTSEL0_INPUT24TO31SEL_SHIFT
uint32_t inputMask1
Definition: em_csen.h:457
__IOM uint32_t CMPTHR
void CSEN_DMBaselineSet(CSEN_TypeDef *csen, uint32_t up, uint32_t down)
Set the DM integrator initial value.
Definition: em_csen.c:88
#define CSEN_CTRL_STM_DEFAULT
#define _CSEN_CTRL_CPACCURACY_MASK
#define _CSEN_SCANMASK1_RESETVALUE
#define _CSEN_SCANINPUTSEL0_RESETVALUE
__IOM uint32_t SCANMASK1
#define _CSEN_SCANINPUTSEL0_INPUT8TO15SEL_SHIFT
#define _CSEN_DMCFG_RESETVALUE
CSEN_PRSSel_TypeDef prsSel
Definition: em_csen.h:384
#define _CSEN_ANACTRL_IDACIREFS_SHIFT
void CSEN_Reset(CSEN_TypeDef *csen)
Reset CSEN to same state as after a HW reset.
Definition: em_csen.c:267
#define _CSEN_CMPTHR_RESETVALUE
CSEN_AccMode_TypeDef accMode
Definition: em_csen.h:433
__IOM uint32_t EMACTRL
#define _CSEN_ANACTRL_TRSTPROG_SHIFT
__IOM uint32_t SCANMASK0
#define _CSEN_DMCFG_DMCR_SHIFT
uint32_t inputMask0
Definition: em_csen.h:454
__IOM uint32_t IEN
#define _CSEN_CTRL_SARCR_SHIFT
#define _CSEN_SCANMASK0_RESETVALUE
CSEN_SampleMode_TypeDef sampleMode
Definition: em_csen.h:421
#define _CSEN_PRSSEL_PRSSEL_SHIFT
uint8_t pcReload
Definition: em_csen.h:378
__IOM uint32_t SCANINPUTSEL0
void CSEN_InitMode(CSEN_TypeDef *csen, const CSEN_InitMode_TypeDef *init)
Initialize a CSEN measurement mode.
Definition: em_csen.c:186
#define _CSEN_CTRL_STM_SHIFT
#define _CSEN_TIMCTRL_RESETVALUE
#define _CSEN_DMBASELINE_BASELINEDN_SHIFT
#define _CSEN_SCANINPUTSEL0_INPUT0TO7SEL_SHIFT
#define _CSEN_DMCFG_DMR_SHIFT
CSEN_DriveSel_TypeDef driveSel
Definition: em_csen.h:493
Capacitive Sense Module (CSEN) peripheral API.
__IOM uint32_t CTRL
#define _CSEN_IF_MASK