G32R430 Device Driver Layer v1.0.4
G32R4xx Device Driver Layer API Reference
g32r4xx_ddl_adc12.c
Go to the documentation of this file.
1
43#if defined(USE_FULL_DDL_DRIVER)
44
45/* Includes ------------------------------------------------------------------*/
46#include "g32r4xx_ddl_adc12.h"
47#include "g32r4xx_ddl_rcm.h"
48
49#ifdef USE_FULL_ASSERT
50 #include "g32_assert.h"
51#else
52 #define ASSERT_PARAM(_PARAM_) ((void)0U)
53#endif
54
58
59#if defined (ADC3)
60
64
65/* Private types -------------------------------------------------------------*/
66/* Private variables ---------------------------------------------------------*/
67/* Private constants ---------------------------------------------------------*/
68/* Private macros ------------------------------------------------------------*/
69
73
77
78/* Definitions of ADC hardware constraints delays */
79/* Note: Only ADC peripheral HW delays are defined in ADC LL driver driver, */
80/* not timeout values: */
81/* Timeout values for ADC operations are dependent to device clock */
82/* configuration (system clock versus ADC clock), */
83/* and therefore must be defined in user application. */
84/* Refer to @ref ADC_LL_EC_HW_DELAYS for description of ADC timeout */
85/* values definition. */
86/* Note: ADC timeout values are defined here in CPU cycles to be independent */
87/* of device clock setting. */
88/* In user application, ADC timeout values should be defined with */
89/* temporal values, in function of device clock settings. */
90/* Highest ratio CPU clock frequency vs ADC clock frequency: */
91/* - ADC clock from synchronous clock with AHB prescaler 512, */
92/* ADC prescaler 4. */
93/* Ratio max = 512 *4 = 2048 */
94/* - ADC clock from asynchronous clock (PLLP) with prescaler 256. */
95/* Highest CPU clock PLL (PLLR). */
96/* Ratio max = PLLRmax /PPLPmin * 256 = (VCO/2) / (VCO/31) * 256 */
97/* = 3968 */
98/* Unit: CPU cycles. */
99#define ADC12_CLOCK_RATIO_VS_CPU_HIGHEST (3968UL)
100#define ADC12_TIMEOUT_DISABLE_CPU_CYCLES (ADC12_CLOCK_RATIO_VS_CPU_HIGHEST * 1UL)
101#define ADC12_TIMEOUT_STOP_CONVERSION_CPU_CYCLES (ADC12_CLOCK_RATIO_VS_CPU_HIGHEST * 1UL)
102
103#define IS_DDL_ADC12_REG_TRIG_SOURCE(__ADC12_INSTANCE__, __REG_TRIG_SOURCE__) \
104 (((__REG_TRIG_SOURCE__) == DDL_ADC12_REG_TRIG_SOFTWARE) \
105 || ((__REG_TRIG_SOURCE__) == DDL_ADC12_REG_TRIG_EXT_TMR1_CC1) \
106 || ((__REG_TRIG_SOURCE__) == DDL_ADC12_REG_TRIG_EXT_TMR1_CC2) \
107 || ((__REG_TRIG_SOURCE__) == DDL_ADC12_REG_TRIG_EXT_TMR1_CC3) \
108 || ((__REG_TRIG_SOURCE__) == DDL_ADC12_REG_TRIG_EXT_TMR2_CC2) \
109 || ((__REG_TRIG_SOURCE__) == DDL_ADC12_REG_TRIG_EXT_TMR3_TRGO) \
110 || ((__REG_TRIG_SOURCE__) == DDL_ADC12_REG_TRIG_EXT_TMR4_CC4) \
111 || ((__REG_TRIG_SOURCE__) == DDL_ADC12_REG_TRIG_EXT_EINT_LINE11) \
112 )
113
114#define IS_DDL_ADC12_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__) \
115 (((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_DISABLE) \
116 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_2RANKS) \
117 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_3RANKS) \
118 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_4RANKS) \
119 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_5RANKS) \
120 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_6RANKS) \
121 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_7RANKS) \
122 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_8RANKS) \
123 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_9RANKS) \
124 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_10RANKS) \
125 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_11RANKS) \
126 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_12RANKS) \
127 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_13RANKS) \
128 || ((__REG_SEQ_SCAN_LENGTH__) == DDL_ADC12_REG_SEQ_SCAN_ENABLE_14RANKS) \
129 )
130
131#define IS_DDL_ADC12_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__) \
132 (((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_DISABLE) \
133 || ((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_1RANK) \
134 || ((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_2RANKS) \
135 || ((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_3RANKS) \
136 || ((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_4RANKS) \
137 || ((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_5RANKS) \
138 || ((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_6RANKS) \
139 || ((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_7RANKS) \
140 || ((__REG_SEQ_DISCONT_MODE__) == DDL_ADC12_REG_SEQ_DISCONT_8RANKS) \
141 )
142
143#define IS_DDL_ADC12_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__) \
144 (((__REG_CONTINUOUS_MODE__) == DDL_ADC12_REG_CONV_SINGLE) \
145 || ((__REG_CONTINUOUS_MODE__) == DDL_ADC12_REG_CONV_CONTINUOUS) \
146 )
147
148#define IS_DDL_ADC12_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__) \
149 (((__REG_DMA_TRANSFER__) == DDL_ADC12_REG_DMA_TRANSFER_DISABLE) \
150 || ((__REG_DMA_TRANSFER__) == DDL_ADC12_REG_DMA_TRANSFER_ENABLE) \
151 )
152
153#define IS_DDL_ADC12_INJ_TRIG_SOURCE(__ADC12_INSTANCE__, __INJ_TRIG_SOURCE__) \
154 (((__INJ_TRIG_SOURCE__) == DDL_ADC12_INJ_TRIG_SOFTWARE) \
155 || ((__INJ_TRIG_SOURCE__) == DDL_ADC12_INJ_TRIG_EXT_TMR1_TRGO) \
156 || ((__INJ_TRIG_SOURCE__) == DDL_ADC12_INJ_TRIG_EXT_TMR1_CC4) \
157 || ((__INJ_TRIG_SOURCE__) == DDL_ADC12_INJ_TRIG_EXT_TMR2_TRGO) \
158 || ((__INJ_TRIG_SOURCE__) == DDL_ADC12_INJ_TRIG_EXT_TMR2_CC1) \
159 || ((__INJ_TRIG_SOURCE__) == DDL_ADC12_INJ_TRIG_EXT_TMR3_CC4) \
160 || ((__INJ_TRIG_SOURCE__) == DDL_ADC12_INJ_TRIG_EXT_TMR4_TRGO) \
161 || ((__INJ_TRIG_SOURCE__) == DDL_ADC12_INJ_TRIG_EXT_EINT_LINE15) \
162 )
163
164#define IS_DDL_ADC12_INJ_TRIG_EXT_EDGE(__INJ_TRIG_EXT_EDGE__) \
165 (((__INJ_TRIG_EXT_EDGE__) == DDL_ADC12_INJ_TRIG_EXT_RISING) \
166 || ((__INJ_TRIG_EXT_EDGE__) == DDL_ADC12_INJ_TRIG_EXT_DISABLE) \
167 )
168
169#define IS_DDL_ADC12_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__) \
170 (((__INJ_TRIG_AUTO__) == DDL_ADC12_INJ_TRIG_INDEPENDENT) \
171 || ((__INJ_TRIG_AUTO__) == DDL_ADC12_INJ_TRIG_FROM_GRP_REGULAR) \
172 )
173
174#define IS_DDL_ADC12_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__) \
175 (((__INJ_SEQ_SCAN_LENGTH__) == DDL_ADC12_INJ_SEQ_SCAN_DISABLE) \
176 || ((__INJ_SEQ_SCAN_LENGTH__) == DDL_ADC12_INJ_SEQ_SCAN_ENABLE_2RANKS) \
177 || ((__INJ_SEQ_SCAN_LENGTH__) == DDL_ADC12_INJ_SEQ_SCAN_ENABLE_3RANKS) \
178 || ((__INJ_SEQ_SCAN_LENGTH__) == DDL_ADC12_INJ_SEQ_SCAN_ENABLE_4RANKS) \
179 )
180
181#define IS_DDL_ADC12_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__) \
182 (((__INJ_SEQ_DISCONT_MODE__) == DDL_ADC12_INJ_SEQ_DISCONT_DISABLE) \
183 || ((__INJ_SEQ_DISCONT_MODE__) == DDL_ADC12_INJ_SEQ_DISCONT_1RANK) \
184 )
185
186#define IS_DDL_ADC12_CHANNEL(__CHANNEL__) \
187 (((__CHANNEL__) == DDL_ADC12_CHANNEL_0) \
188 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_1) \
189 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_2) \
190 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_3) \
191 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_4) \
192 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_5) \
193 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_6) \
194 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_7) \
195 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_8) \
196 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_9) \
197 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_10) \
198 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_11) \
199 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_12) \
200 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_13) \
201 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_14) \
202 || ((__CHANNEL__) == DDL_ADC12_CHANNEL_15) \
203 )
204
208
209
213
214
215/* Private function prototypes -----------------------------------------------*/
216
217/* Exported functions --------------------------------------------------------*/
221
225
236ErrorStatus DDL_ADC12_DeInit(ADC12_TypeDef *ADCx)
237{
238 ErrorStatus status = SUCCESS;
239
240 __IO uint32_t timeout_cpu_cycles = 0UL;
241
242 /* Check the parameters */
243 ASSERT_PARAM(IS_ADC12_ALL_INSTANCE(ADCx));
244
245 /* Disable ADC instance if not already disabled. */
246 if (DDL_ADC12_IsEnabled(ADCx) == 1UL)
247 {
248 /* Set ADC group regular trigger source to SW start to ensure to not */
249 /* have an external trigger event occurring during the conversion stop */
250 /* ADC disable process. */
252
253 /* Stop potential ADC conversion on going on ADC group regular. */
254 if (DDL_ADC12_REG_IsConversionOngoing(ADCx) != 0UL)
255 {
257 {
259 }
260 }
261
262 /* Set ADC group injected trigger source to SW start to ensure to not */
263 /* have an external trigger event occurring during the conversion stop */
264 /* ADC disable process. */
266
267 /* Stop potential ADC conversion on going on ADC group injected. */
268 if (DDL_ADC12_INJ_IsConversionOngoing(ADCx) != 0UL)
269 {
271 {
273 }
274 }
275
276 /* Wait for ADC conversions are effectively stopped */
277 timeout_cpu_cycles = ADC12_TIMEOUT_STOP_CONVERSION_CPU_CYCLES;
280 {
281 timeout_cpu_cycles--;
282 if (timeout_cpu_cycles == 0UL)
283 {
284 /* Time-out error */
285 status = ERROR;
286 break;
287 }
288 }
289
290 /* Disable the ADC instance */
291 DDL_ADC12_Disable(ADCx);
292
293 }
294
295 /* Check whether ADC state is compliant with expected state */
296 if (READ_BIT(ADCx->CR,
297 (ADC_CR_JADSTP | ADC_CR_ADSTP | ADC_CR_JADSTART | ADC_CR_ADSTART
298 | ADC_CR_ADEN)
299 )
300 == 0UL)
301 {
302 /* ========== Reset ADC registers ========== */
303 /* Reset register IER */
304 CLEAR_BIT(ADCx->IER,
310 )
311 );
312
313 /* Reset register ISR */
314 SET_BIT(ADCx->ISR,
320 )
321 );
322
323 /* Reset register CR */
324 /* - Bits ADC_CR_JADSTP, ADC_CR_ADSTP, ADC_CR_JADSTART, ADC_CR_ADSTART, */
325 /* ADC_CR_ADCAL, ADC_CR_ADDIS, ADC_CR_ADEN are in */
326 /* access mode "read-set": no direct reset applicable. */
327 /* - Reset Calibration mode to default setting (single ended). */
328 /* - Disable ADC internal voltage regulator. */
329 /* - Enable ADC deep power down. */
330 /* Note: ADC internal voltage regulator disable and ADC deep power */
331 /* down enable are conditioned to ADC state disabled: */
332 /* already done above. */
333
334 /* Reset register CFGR */
335 MODIFY_REG(ADCx->CFGR,
336 ( ADC_CFGR_AWD1CH | ADC_CFGR_JAUTO | ADC_CFGR_JAWD1EN
337 | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL
338 | ADC_CFGR_JDISCEN | ADC_CFGR_DISCNUM | ADC_CFGR_DISCEN
339 | ADC_CFGR_CONT
340 | ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL | ADC_CFGR_ALIGN
341 | ADC_CFGR_DMAEN),
342 0x00000000UL
343 );
344
345 /* Reset register SMPR1 */
346 CLEAR_BIT(ADCx->SMPR1,
347 ( ADC_SMPR1_SMP7 | ADC_SMPR1_SMP6
348 | ADC_SMPR1_SMP5 | ADC_SMPR1_SMP4 | ADC_SMPR1_SMP3
349 | ADC_SMPR1_SMP2 | ADC_SMPR1_SMP1 | ADC_SMPR1_SMP0)
350 );
351
352 /* Reset register SMPR2 */
353 CLEAR_BIT(ADCx->SMPR2,
354 ( ADC_SMPR2_SMP15 | ADC_SMPR2_SMP14
355 | ADC_SMPR2_SMP13 | ADC_SMPR2_SMP12 | ADC_SMPR2_SMP11
356 | ADC_SMPR2_SMP10 | ADC_SMPR2_SMP9 | ADC_SMPR2_SMP8)
357 );
358
359 /* Reset register TR1 */
360 MODIFY_REG(ADCx->TR1, ADC_TR1_HT1 | ADC_TR1_LT1, ADC_TR1_HT1);
361
362 /* Reset register SQR1 */
363 CLEAR_BIT(ADCx->SQR1,
364 ( ADC_SQR1_SQ7 | ADC_SQR1_SQ6 | ADC_SQR1_SQ5
365 | ADC_SQR1_SQ4 | ADC_SQR1_SQ3 | ADC_SQR1_SQ2
366 | ADC_SQR1_SQ1 | ADC_SQR1_RL)
367 );
368
369 /* Reset register SQR2 */
370 CLEAR_BIT(ADCx->SQR2,
371 ( ADC_SQR2_SQ14 | ADC_SQR2_SQ13
372 | ADC_SQR2_SQ12 | ADC_SQR2_SQ11 | ADC_SQR2_SQ10
373 | ADC_SQR2_SQ9 | ADC_SQR2_SQ8)
374 );
375
376 CLEAR_BIT(ADCx->SQR3,
377 ( ADC_SQR3_SQ16 | ADC_SQR3_SQ15) );
378
379 /* Reset register JSQR */
380 CLEAR_BIT(ADCx->JSQR,
381 (ADC_JSQR_JL
382 | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN
383 | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
384 | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1)
385 );
386
387 /* Reset register DR */
388 /* Note: bits in access mode read only, no direct reset applicable */
389
390 /* Reset register OFR1 */
391 CLEAR_BIT(ADCx->JOFFSET1, ADC_JOFFSET1_JOFFSET1);
392 /* Reset register OFR2 */
393 CLEAR_BIT(ADCx->JOFFSET2, ADC_JOFFSET2_JOFFSET2);
394 /* Reset register OFR3 */
395 CLEAR_BIT(ADCx->JOFFSET3, ADC_JOFFSET3_JOFFSET3);
396 /* Reset register OFR4 */
397 CLEAR_BIT(ADCx->JOFFSET4, ADC_JOFFSET4_JOFFSET4);
398
399 /* Reset registers JDR1, JDR2, JDR3, JDR4 */
400 /* Note: bits in access mode read only, no direct reset applicable */
401 }
402 else
403 {
404 /* ADC instance is in an unknown state */
405 /* Need to performing a hard reset of ADC instance, using high level */
406 /* clock source RCM ADC reset. */
407 status = ERROR;
408 }
409
410 return status;
411}
412
446ErrorStatus DDL_ADC12_Init(ADC12_TypeDef *ADCx, DDL_ADC12_InitTypeDef *ADC_InitStruct)
447{
448 ErrorStatus status = SUCCESS;
449
450 /* Check the parameters */
451 ASSERT_PARAM(IS_ADC12_ALL_INSTANCE(ADCx));
452
453 /* Note: Hardware constraint (refer to description of this function): */
454 /* ADC instance must be disabled. */
455 if (DDL_ADC12_IsEnabled(ADCx) == 0UL)
456 {
457 /* Configuration of ADC hierarchical scope: */
458 /* - ADC instance */
459 /* - Set ADC low power mode */
460 MODIFY_REG(ADCx->CFGR, ADC_CFGR_ALIGN, ADC_InitStruct->DataAlignment);
461
462 }
463 else
464 {
465 /* Initialization error: ADC instance is not disabled. */
466 status = ERROR;
467 }
468
469 return status;
470}
471
479{
480 /* Set ADC_InitStruct fields to default values */
481 /* Set fields of ADC instance */
483}
484
517ErrorStatus DDL_ADC12_REG_Init(ADC12_TypeDef *ADCx, DDL_ADC12_REG_InitTypeDef *ADC_REG_InitStruct)
518{
519 ErrorStatus status = SUCCESS;
520
521 /* Check the parameters */
522 ASSERT_PARAM(IS_ADC12_ALL_INSTANCE(ADCx));
523 ASSERT_PARAM(IS_DDL_ADC12_REG_TRIG_SOURCE(ADCx, ADC_REG_InitStruct->TriggerSource));
525 if (ADC_REG_InitStruct->SequencerLength != DDL_ADC12_REG_SEQ_SCAN_DISABLE)
526 {
528
529 /* ADC group regular continuous mode and discontinuous mode */
530 /* can not be enabled simultenaeously */
532 || (ADC_REG_InitStruct->SequencerDiscont == DDL_ADC12_REG_SEQ_DISCONT_DISABLE));
533 }
536
537 /* Note: Hardware constraint (refer to description of this function): */
538 /* ADC instance must be disabled. */
539 if (DDL_ADC12_IsEnabled(ADCx) == 0UL)
540 {
541 /* Configuration of ADC hierarchical scope: */
542 /* - ADC group regular */
543 /* - Set ADC group regular trigger source */
544 /* - Set ADC group regular sequencer length */
545 /* - Set ADC group regular sequencer discontinuous mode */
546 /* - Set ADC group regular continuous mode */
547 /* - Set ADC group regular conversion data transfer: no transfer or */
548 /* transfer by DMA, and DMA requests mode */
549 /* - Set ADC group regular overrun behavior */
550 /* Note: On this G32R4 series, ADC trigger edge is set to value 0x0 by */
551 /* setting of trigger source to SW start. */
552 if (ADC_REG_InitStruct->SequencerLength != DDL_ADC12_REG_SEQ_SCAN_DISABLE)
553 {
554 MODIFY_REG(ADCx->CFGR,
555 ADC_CFGR_EXTSEL
556 | ADC_CFGR_EXTEN
557 | ADC_CFGR_DISCEN
558 | ADC_CFGR_DISCNUM
559 | ADC_CFGR_CONT
560 | ADC_CFGR_DMAEN
561 ,
562 ADC_REG_InitStruct->TriggerSource
563 | ADC_REG_InitStruct->SequencerDiscont
564 | ADC_REG_InitStruct->ContinuousMode
565 | ADC_REG_InitStruct->DMATransfer
566 );
567 }
568 else
569 {
570 MODIFY_REG(ADCx->CFGR,
571 ADC_CFGR_EXTSEL
572 | ADC_CFGR_EXTEN
573 | ADC_CFGR_DISCEN
574 | ADC_CFGR_DISCNUM
575 | ADC_CFGR_CONT
576 | ADC_CFGR_DMAEN
577 ,
578 ADC_REG_InitStruct->TriggerSource
580 | ADC_REG_InitStruct->ContinuousMode
581 | ADC_REG_InitStruct->DMATransfer
582 );
583 }
584
585 /* Set ADC group regular sequencer length and scan direction */
586 DDL_ADC12_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
587 }
588 else
589 {
590 /* Initialization error: ADC instance is not disabled. */
591 status = ERROR;
592 }
593 return status;
594}
595
603{
604 /* Set ADC_REG_InitStruct fields to default values */
605 /* Set fields of ADC group regular */
606 /* Note: On this G32R4 series, ADC trigger edge is set to value 0x0 by */
607 /* setting of trigger source to SW start. */
608 ADC_REG_InitStruct->TriggerSource = DDL_ADC12_REG_TRIG_SOFTWARE;
611 ADC_REG_InitStruct->ContinuousMode = DDL_ADC12_REG_CONV_SINGLE;
613}
614
647ErrorStatus DDL_ADC12_INJ_Init(ADC12_TypeDef *ADCx, DDL_ADC12_INJ_InitTypeDef *ADC_INJ_InitStruct)
648{
649 ErrorStatus status = SUCCESS;
650
651 /* Check the parameters */
652 ASSERT_PARAM(IS_ADC12_ALL_INSTANCE(ADCx));
653 ASSERT_PARAM(IS_DDL_ADC12_INJ_TRIG_SOURCE(ADCx, ADC_INJ_InitStruct->TriggerSource));
655 if (ADC_INJ_InitStruct->SequencerLength != DDL_ADC12_INJ_SEQ_SCAN_DISABLE)
656 {
658 }
660
661 /* Note: Hardware constraint (refer to description of this function): */
662 /* ADC instance must be disabled. */
663 if (DDL_ADC12_IsEnabled(ADCx) == 0UL)
664 {
665 /* Configuration of ADC hierarchical scope: */
666 /* - ADC group injected */
667 /* - Set ADC group injected trigger source */
668 /* - Set ADC group injected sequencer length */
669 /* - Set ADC group injected sequencer discontinuous mode */
670 /* - Set ADC group injected conversion trigger: independent or */
671 /* from ADC group regular */
672 /* Note: On this G32R4 series, ADC trigger edge is set to value 0x0 by */
673 /* setting of trigger source to SW start. */
674 if (ADC_INJ_InitStruct->SequencerLength != DDL_ADC12_REG_SEQ_SCAN_DISABLE)
675 {
676 MODIFY_REG(ADCx->CFGR,
677 ADC_CFGR_JDISCEN
678 | ADC_CFGR_JAUTO
679 ,
680 ADC_INJ_InitStruct->SequencerDiscont
681 | ADC_INJ_InitStruct->TrigAuto
682 );
683 }
684 else
685 {
686 MODIFY_REG(ADCx->CFGR,
687 ADC_CFGR_JDISCEN
688 | ADC_CFGR_JAUTO
689 ,
691 | ADC_INJ_InitStruct->TrigAuto
692 );
693 }
694
695 MODIFY_REG(ADCx->JSQR,
696 ADC_JSQR_JEXTSEL
697 | ADC_JSQR_JEXTEN
698 | ADC_JSQR_JL
699 ,
700 ADC_INJ_InitStruct->TriggerSource
701 | ADC_INJ_InitStruct->SequencerLength
702 );
703 }
704 else
705 {
706 /* Initialization error: ADC instance is not disabled. */
707 status = ERROR;
708 }
709 return status;
710}
711
719{
720 /* Set ADC_INJ_InitStruct fields to default values */
721 /* Set fields of ADC group injected */
722 ADC_INJ_InitStruct->TriggerSource = DDL_ADC12_INJ_TRIG_SOFTWARE;
725 ADC_INJ_InitStruct->TrigAuto = DDL_ADC12_INJ_TRIG_INDEPENDENT;
726}
727
731
735
739
740#endif /* ADC3 */
741
745
746#endif /* USE_FULL_DDL_DRIVER */
747
G32 assert template file. This file should be copied to the application folder and renamed to g32_ass...
#define ASSERT_PARAM(_PARAM_)
Definition g32_assert.h:58
Header file of ADC DDL module.
Header file of RCM DDL module.
#define DDL_ADC12_FLAG_EOS
#define DDL_ADC12_FLAG_JEOS
#define DDL_ADC12_FLAG_EOC
#define DDL_ADC12_FLAG_JEOC
#define DDL_ADC12_FLAG_AWD1
#define DDL_ADC12_INJ_SEQ_DISCONT_DISABLE
#define DDL_ADC12_INJ_SEQ_SCAN_DISABLE
#define DDL_ADC12_INJ_TRIG_SOFTWARE
#define DDL_ADC12_INJ_TRIG_INDEPENDENT
#define DDL_ADC12_IT_JEOS
#define DDL_ADC12_IT_EOC
#define DDL_ADC12_IT_AWD1
#define DDL_ADC12_IT_JEOC
#define DDL_ADC12_IT_EOS
#define DDL_ADC12_REG_CONV_SINGLE
#define DDL_ADC12_REG_DMA_TRANSFER_DISABLE
#define DDL_ADC12_REG_SEQ_DISCONT_DISABLE
#define DDL_ADC12_REG_SEQ_SCAN_DISABLE
#define DDL_ADC12_REG_TRIG_SOFTWARE
__STATIC_INLINE void DDL_ADC12_INJ_SetTriggerSource(ADC12_TypeDef *ADCx, uint32_t TriggerSource)
Set ADC group injected conversion trigger source: internal (SW start) or from external peripheral (ti...
__STATIC_INLINE void DDL_ADC12_REG_SetSequencerLength(ADC12_TypeDef *ADCx, uint32_t SequencerNbRanks)
Set ADC group regular sequencer length and scan direction.
__STATIC_INLINE void DDL_ADC12_REG_SetTriggerSource(ADC12_TypeDef *ADCx, uint32_t TriggerSource)
Set ADC group regular conversion trigger source: internal (SW start) or from external peripheral (tim...
ErrorStatus DDL_ADC12_DeInit(ADC12_TypeDef *ADCx)
De-initialize registers of the selected ADC instance to their default reset values.
void DDL_ADC12_INJ_StructInit(DDL_ADC12_INJ_InitTypeDef *ADC_INJ_InitStruct)
Set each DDL_ADC12_INJ_InitTypeDef field to default value.
ErrorStatus DDL_ADC12_INJ_Init(ADC12_TypeDef *ADCx, DDL_ADC12_INJ_InitTypeDef *ADC_INJ_InitStruct)
Initialize some features of ADC group injected.
void DDL_ADC12_StructInit(DDL_ADC12_InitTypeDef *ADC_InitStruct)
Set each DDL_ADC12_InitTypeDef field to default value.
ErrorStatus DDL_ADC12_Init(ADC12_TypeDef *ADCx, DDL_ADC12_InitTypeDef *ADC_InitStruct)
Initialize some features of ADC instance.
void DDL_ADC12_REG_StructInit(DDL_ADC12_REG_InitTypeDef *ADC_REG_InitStruct)
Set each DDL_ADC12_REG_InitTypeDef field to default value.
ErrorStatus DDL_ADC12_REG_Init(ADC12_TypeDef *ADCx, DDL_ADC12_REG_InitTypeDef *ADC_REG_InitStruct)
Initialize some features of ADC group regular.
__STATIC_INLINE void DDL_ADC12_INJ_StopConversion(ADC12_TypeDef *ADCx)
Stop ADC group injected conversion.
__STATIC_INLINE uint32_t DDL_ADC12_INJ_IsStopConversionOngoing(ADC12_TypeDef *ADCx)
Get ADC group injected command of conversion stop state.
__STATIC_INLINE uint32_t DDL_ADC12_INJ_IsConversionOngoing(ADC12_TypeDef *ADCx)
Get ADC group injected conversion state.
__STATIC_INLINE void DDL_ADC12_REG_StopConversion(ADC12_TypeDef *ADCx)
Stop ADC group regular conversion.
__STATIC_INLINE uint32_t DDL_ADC12_REG_IsConversionOngoing(ADC12_TypeDef *ADCx)
Get ADC group regular conversion state.
__STATIC_INLINE uint32_t DDL_ADC12_REG_IsStopConversionOngoing(ADC12_TypeDef *ADCx)
Get ADC group regular command of conversion stop state.
__STATIC_INLINE uint32_t DDL_ADC12_IsEnabled(ADC12_TypeDef *ADCx)
Get the selected ADC instance enable state.
__STATIC_INLINE void DDL_ADC12_Disable(ADC12_TypeDef *ADCx)
Disable the selected ADC instance.
#define IS_DDL_ADC12_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__)
#define IS_DDL_ADC12_REG_TRIG_SOURCE(__ADC12_INSTANCE__, __REG_TRIG_SOURCE__)
#define ADC12_TIMEOUT_STOP_CONVERSION_CPU_CYCLES
#define IS_DDL_ADC12_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__)
#define IS_DDL_ADC12_INJ_TRIG_SOURCE(__ADC12_INSTANCE__, __INJ_TRIG_SOURCE__)
#define IS_DDL_ADC12_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__)
#define IS_DDL_ADC12_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__)
#define IS_DDL_ADC12_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__)
#define IS_DDL_ADC12_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__)
#define IS_DDL_ADC12_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__)
#define DDL_ADC12_ALIGNMENT_RIGHT
Structure definition of some features of ADC group injected.
Structure definition of some features of ADC instance.
Structure definition of some features of ADC group regular.