aboutsummaryrefslogtreecommitdiff
path: root/src/mcu/peripheral/rtl876x_adc.c
blob: 04c8f0c9788cf65d7497e999933073996c330398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
/**
*********************************************************************************************************
*               Copyright(c) 2021, Realtek Semiconductor Corporation. All rights reserved.
**********************************************************************************************************
* @file     rtl876x_adc.c
* @brief    This file provides all the ADC firmware functions.
* @details
* @author   yuan
* @date     2021-05-10
* @version  v1.0.2
*********************************************************************************************************
*/
#include "rtl876x_rcc.h"
#include "rtl876x_adc.h"


/**
  * @brief  Deinitializes the ADC peripheral registers to their default reset values(turn off ADC clock).
  *
  * @param  ADCx: selected ADC peripheral.
  * @return None.
  */
void ADC_DeInit(ADC_TypeDef *ADCx)
{
    assert_param(IS_ADC_PERIPH(ADCx));

    RCC_PeriphClockCmd(APBPeriph_ADC, APBPeriph_ADC_CLOCK, DISABLE);

    return;
}

/**
  * @brief  Initializes the ADC peripheral according to the specified
  *         parameters in the ADC_InitStruct
  * @param  ADCx: selected ADC peripheral.
  * @param  ADC_InitStruct: pointer to a ADCInitTypeDef structure that
  *         contains the configuration information for the specified ADC peripheral
  * @return None.
  */
void ADC_Init(ADC_TypeDef *ADCx, ADC_InitTypeDef *ADC_InitStruct)
{
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_ADC_DATA_WRITE_TO_FIFO_CMD(ADC_InitStruct->ADC_DataWriteToFifo));
    assert_param(IS_ADC_FIFO_THRESHOLD(ADC_InitStruct->ADC_FifoThdLevel));
    assert_param(IS_ADC_WATER_LEVEL_CONFIG(ADC_InitStruct->ADC_WaterLevel));
    assert_param(IS_ADC_OVERWRITE_MODE(ADC_InitStruct->ADC_FifoOverWriteEn));
    assert_param(IS_ADC_LATCH_DATA_EDGE(ADC_InitStruct->ADC_DataLatchEdge));
    assert_param(IS_ADC_DATA_AVG_NUM(ADC_InitStruct->ADC_DataAvgSel));
    assert_param(IS_ADC_DATA_AVG_EN(ADC_InitStruct->ADC_DataAvgEn));
    assert_param(IS_ADC_POWER_ON_MODE(ADC_InitStruct->ADC_PowerOnMode));
    assert_param(IS_ADC_RG2X_0_DELAY_TIME(ADC_InitStruct->ADC_RG2X0Dly));
    assert_param(IS_ADC_RG0X_1_DELAY_TIME(ADC_InitStruct->ADC_RG0X1Dly));
    assert_param(IS_ADC_RG0X_0_DELAY_TIME(ADC_InitStruct->ADC_RG0X0Dly));
    assert_param(IS_ADC_DATA_MINUS_CMD(ADC_InitStruct->ADC_DataMinusEn));
    assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
    assert_param(IS_ADC_TIMER_TRIGGER_CMD(ADC_InitStruct->ADC_TimerTriggerEn));
    assert_param(IS_ADC_POWER_ALWAYS_ON(ADC_InitStruct->ADC_PowerAlwaysOnEn));
    assert_param(IS_ADC_CONVERT_TIME(ADC_InitStruct->ADC_ConvertTime));


    /* Added to stabilize the power supply! */
    uint16_t reg_value = 0;

    /* enable cmp low noise for 3 bit */
    reg_value = btaon_fast_read_safe(0x116);
    btaon_fast_write(0x116, reg_value | BIT(10));

    /* vref_sel = 0.85V */
    reg_value = btaon_fast_read_safe(0x116);
    btaon_fast_write(0x116, reg_value | BIT(5) | BIT(4));

    /*Disable all interrupt.*/
    ADCx->INTCR &= (~0x1f);

    /* Set power mode first */
    ADCx->PWRDLY = (((ADC_InitStruct->ADC_DataLatchDly & 0x7) << 6) |
                    ADC_InitStruct->ADC_PowerAlwaysOnEn |
                    ADC_InitStruct->ADC_PowerOnMode);

    if (ADC_InitStruct->ADC_PowerOnMode == ADC_POWER_ON_AUTO)
    {
        ADCx->PWRDLY |= (ADC_InitStruct->ADC_RG2X0Dly \
                         | ADC_InitStruct->ADC_RG0X1Dly \
                         | ADC_InitStruct->ADC_RG0X0Dly);
    }

    if (ADC_InitStruct->ADC_DataAvgEn == ADC_DATA_AVERAGE_ENABLE)
    {
        ADCx->PWRDLY |= (ADC_InitStruct->ADC_DataAvgEn | ADC_InitStruct->ADC_DataAvgSel);
        /* Disable schedule table */
        ADCx->SCHCR &= (~0xffff);
        /* Set schedule table */
        ADCx->SCHTAB0 = ADC_InitStruct->ADC_SchIndex[0];
        ADCx->SCHCR |= (uint16_t)0x0001;
    }
    else
    {
        /* Disable schedule table */
        ADCx->SCHCR &= (~0xffff);

        /* Set schedule table */
        for (uint8_t index = 0; index < MAX_ADC_SCH_NUM; index++)
        {
            *(__IO uint32_t *)((uint32_t *)(&ADCx->SCHTAB0) + index) = ((ADC_InitStruct->ADC_SchIndex[index * 2]
                                                                         & 0x1F)
                                                                        | ((ADC_InitStruct->ADC_SchIndex[index * 2 + 1] & 0x1F) << 16));
        }
        ADCx->SCHCR = ADC_InitStruct->ADC_Bitmap;
    }

    /* Set ADC mode */
    ADCx->CR = ((ADC_InitStruct->ADC_DataWriteToFifo)
                | ((ADC_InitStruct->ADC_FifoThdLevel & 0x3F) << 20)
                | ((ADC_InitStruct->ADC_WaterLevel & 0x3F) << 14)
                | (ADC_InitStruct->ADC_FifoOverWriteEn)
                | (ADC_InitStruct->ADC_DataLatchEdge));

    ADCx->DATCLK = ((ADC_InitStruct->ADC_DataMinusEn)
                    | (ADC_InitStruct->ADC_DataAlign)
                    | ((ADC_InitStruct->ADC_DataMinusOffset & 0xFFF) << 16));

    ADCx->ANACTL |= (0x03 << 10);
    if ((ADC_InitStruct->ADC_SampleTime & 0x3FFF) < 19)
    {
        /* adc sample period max 400kHz */
        ADC_InitStruct->ADC_SampleTime = 19;
    }
    ADCx->SAMTIM = ((ADC_InitStruct->ADC_ConvertTime)
                    | (ADC_InitStruct->ADC_SampleTime & 0x3FFF));

    /*clear adc fifo*/
    ADCx->CR |= BIT26;

    /*clear all interrupt*/
    ADCx->INTCR |= (0x1f << 8);

    return;
}

/**
  * @brief  Fills each ADC_InitStruct member with its default value.
  * @param  ADC_InitStruct: pointer to an ADC_InitTypeDef structure which will be initialized.
  * @retval None
  */
void ADC_StructInit(ADC_InitTypeDef *ADC_InitStruct)
{
    ADC_InitStruct->ADC_SampleTime      = 255;  /* (n + 1) cycle of 10MHz,n = 0 to 16383 */
    ADC_InitStruct->ADC_ConvertTime     = ADC_CONVERT_TIME_500NS;

    ADC_InitStruct->ADC_DataWriteToFifo = ADC_DATA_WRITE_TO_FIFO_DISABLE;
    ADC_InitStruct->ADC_FifoThdLevel    = 0x0A;
    ADC_InitStruct->ADC_WaterLevel      = 0x1;
    ADC_InitStruct->ADC_FifoOverWriteEn = ADC_FIFO_OVER_WRITE_ENABLE;
    ADC_InitStruct->ADC_DataLatchEdge   = ADC_LATCH_DATA_Positive;

    ADC_InitStruct->ADC_SchIndex[0]     = 0;
    ADC_InitStruct->ADC_SchIndex[1]     = 0;
    ADC_InitStruct->ADC_SchIndex[2]     = 0;
    ADC_InitStruct->ADC_SchIndex[3]     = 0;
    ADC_InitStruct->ADC_SchIndex[4]     = 0;
    ADC_InitStruct->ADC_SchIndex[5]     = 0;
    ADC_InitStruct->ADC_SchIndex[6]     = 0;
    ADC_InitStruct->ADC_SchIndex[7]     = 0;
    ADC_InitStruct->ADC_SchIndex[8]     = 0;
    ADC_InitStruct->ADC_SchIndex[9]     = 0;
    ADC_InitStruct->ADC_SchIndex[10]    = 0;
    ADC_InitStruct->ADC_SchIndex[11]    = 0;
    ADC_InitStruct->ADC_SchIndex[12]    = 0;
    ADC_InitStruct->ADC_SchIndex[13]    = 0;
    ADC_InitStruct->ADC_SchIndex[14]    = 0;
    ADC_InitStruct->ADC_SchIndex[15]    = 0;
    ADC_InitStruct->ADC_Bitmap          = 0x0;

    ADC_InitStruct->ADC_DataAlign       = ADC_DATA_ALIGN_LSB;
    ADC_InitStruct->ADC_DataMinusEn     = ADC_DATA_MINUS_DISABLE;
    ADC_InitStruct->ADC_DataMinusOffset = 0;

    ADC_InitStruct->ADC_DataAvgEn       = ADC_DATA_AVERAGE_DISABLE;
    ADC_InitStruct->ADC_DataAvgSel      = ADC_DATA_AVERAGE_OF_2;
    /* Reserved parameter, please do not change values*/
    ADC_InitStruct->ADC_PowerOnMode     = ADC_POWER_ON_AUTO;
    ADC_InitStruct->ADC_PowerAlwaysOnEn = ADC_POWER_ALWAYS_ON_DISABLE;
    ADC_InitStruct->ADC_DataLatchDly    = 0x1;
    ADC_InitStruct->ADC_RG2X0Dly        = ADC_RG2X_0_DELAY_10_US;
    ADC_InitStruct->ADC_RG0X1Dly        = ADC_RG0X_1_DELAY_20_US;
    ADC_InitStruct->ADC_RG0X0Dly        = ADC_RG0X_0_DELAY_30_US;

    return;
}

/**
  * @brief  Enables or disables the ADC peripheral.
  * @param  ADCx: selected ADC peripheral.
  * @param  adcMode: adc mode select.
        This parameter can be one of the following values:
  *     @arg ADC_ONE_SHOT_MODE: one shot mode.
  *     @arg ADC_CONTINUOUS_MODE: continuous mode.
  * @param  NewState: new state of the ADC peripheral.
  *     This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_Cmd(ADC_TypeDef *ADCx, uint8_t adcMode, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_ADC_SAMPLE_MODE(adcMode));
    assert_param(IS_FUNCTIONAL_STATE(NewState));
    uint8_t reg_value = 0;

    if (NewState == ENABLE)
    {
        reg_value = btaon_fast_read_safe(0x113);
        btaon_fast_write(0x113, reg_value & ~BIT2);
        /* In case manual mode */
        if (ADCx->PWRDLY  & ADC_POWER_ON_MANUAL)
        {
            ADCx->PWRDLY  |= 0x3C00;
//            ADC_DelayUs(80);
            platform_delay_us(80);
            ADCx->PWRDLY  |= (BIT14 | BIT15);
//            ADC_DelayUs(320);
            platform_delay_us(320);
            ADCx->PWRDLY  |= (BIT16 | BIT17);
//            ADC_DelayUs(240);
            platform_delay_us(240);
            ADCx->PWRDLY  |= BIT18;
        }
        /* Reset ADC mode first */
        ADCx->CR &= ~0x03;
        /* Enable ADC */
        ADCx->CR |= adcMode;
    }
    else
    {
        ADCx->CR &= ~0x03;
        reg_value = btaon_fast_read_safe(0x113);
        btaon_fast_write(0x113, reg_value | BIT2);
    }

    return;
}

/**
  * @brief  Enables or disables the specified ADC interrupts.
  * @param  ADCx: selected ADC peripheral.
  * @param  ADC_INT: specifies the ADC interrupts sources to be enabled or disabled.
  *         This parameter can be any combination of the following values:
  *         @arg ADC_INT_FIFO_RD_REQ :FIFO read request
  *         @arg ADC_INT_FIFO_RD_ERR :FIFO read error
  *         @arg ADC_INT_FIFO_THD :ADC FIFO size > thd
  *         @arg ADC_INT_FIFO_FULL :ADC FIFO overflow
  *         @arg ADC_INT_ONE_SHOT_DONE :ADC one shot mode done
  * @param  NewState: new state of the specified ADC interrupts.
  *         This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_INTConfig(ADC_TypeDef *ADCx, uint32_t ADC_INT, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_ADC_INT(ADC_INT));
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    if (NewState != DISABLE)
    {
        /* Enable the selected ADC interrupts */
        ADCx->INTCR |= ADC_INT;
    }
    else
    {
        /* Disable the selected ADC interrupts */
        ADCx->INTCR &= (uint32_t)~ADC_INT;
    }
}

/**
  * @brief  Read ADC data according to specific channel.
  * @param  ADCx: selected ADC peripheral.
  * @param  index: can be 0 to 15
  * @retval The 10-bit converted ADC data.
  */
uint16_t ADC_ReadRawData(ADC_TypeDef *ADCx, uint8_t index)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(index < 16);

    if (index & BIT(0))
    {
        return ((*(uint32_t *)((uint32_t *)(&ADCx->SCHD0) + (index >> 1))) >> 16);
    }
    else
    {
        return (*(uint32_t *)((uint32_t *)(&ADCx->SCHD0) + (index >> 1)));
    }
}

/**
  * @brief  Read ADC average data from ADC schedule table0.
  * @param  ADCx: selected ADC peripheral.
  * @param[out]  OutBuf: buffer to save data read from ADC FIFO.
  * @retval The 10-bit converted ADC data.
  */
uint16_t ADC_ReadAvgRawData(ADC_TypeDef *ADCx)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));

    uint16_t data = 0;
    data = (uint16_t)ADCx->SCHD0;

    return data;
}

/**
  * @brief  Get one data from ADC FIFO.
  * @param  ADCx: selected ADC peripheral.
  * @retval adc FIFO data.
  */
uint16_t ADC_ReadFIFO(ADC_TypeDef *ADCx)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));

    return (uint16_t)((ADCx->FIFO) & 0xFFF);
}

/**
  * @brief  Read data from ADC FIFO.
  * @param  ADCx: selected ADC peripheral.
  * @param[out]  outBuf: buffer to save data read from ADC FIFO.
  * @param  num: number of data to be read.
  * @retval None
  */
void ADC_ReadFIFOData(ADC_TypeDef *ADCx, uint16_t *outBuf, uint16_t num)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));

    while (num--)
    {
        *outBuf++ = (uint16_t)ADCx->FIFO;
    }

    return;
}

/**
  * @brief  Get ADC fifo data number.
  * @param  ADCx: selected ADC peripheral.
  * @retval current data number in adc fifo.
  */
uint8_t ADC_GetFIFODataLen(ADC_TypeDef *ADCx)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));

    return ((uint8_t)(((ADCx->SCHCR) >> 16) & 0x3F));
}

/**
  * @brief  Config ADC schedule table.
  * @param  ADCx: selected ADC peripheral.
  * @param  adcMode: ADC mode.
  *     This parameter can be one of the following values:
  *     @arg EXT_SINGLE_ENDED(index)
  *     @arg EXT_DIFFERENTIAL(index)
  *     @arg INTERNAL_VBAT_MODE
  * @param  Index: Schedule table index.
  * @return none.
  */
void ADC_SchIndexConfig(ADC_TypeDef *ADCx, uint8_t adcMode, uint16_t index)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_ADC_SCHEDULE_INDEX_CONFIG(adcMode));

    if (index & BIT0)
    {
        *(uint32_t *)((uint32_t *)(&ADCx->SCHTAB0) + (index >> 1)) |= (adcMode << 16);
    }
    else
    {
        *(uint32_t *)((uint32_t *)(&ADCx->SCHTAB0) + (index >> 1)) |= adcMode;
    }

    return;
}

/**
  * @brief  Same as function ADC_SchIndexConfig,this function is version bee2.
  * @param  ADCx: selected ADC peripheral.
  * @param  adcMode: ADC mode.
  *     This parameter can be one of the following values:
  *     @arg EXT_SINGLE_ENDED(index)
  *     @arg EXT_DIFFERENTIAL(index)
  *     @arg INTERNAL_VBAT_MODE
  * @param  Index: Schedule table index.
  * @return none.
  */
void ADC_SchTableConfig(ADC_TypeDef *ADCx, uint16_t Index, uint8_t adcMode)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_ADC_SCHEDULE_INDEX_CONFIG(adcMode));

    if (Index & BIT0)
    {
        *(uint32_t *)((uint32_t *)(&ADCx->SCHTAB0) + (Index >> 1)) |= (adcMode << 16);
    }
    else
    {
        *(uint32_t *)((uint32_t *)(&ADCx->SCHTAB0) + (Index >> 1)) |= adcMode;
    }

    return;
}

/**
  * @brief  Set adc schedule table.
  * @param  ADCx: selected ADC peripheral.
  * @param  channelMap: ADC channel map.
  * @param  NewState: new state of the ADC peripheral.
  *   This parameter can be: ENABLE or DISABLE.
  * @return none.
  */
void ADC_BitMapConfig(ADC_TypeDef *ADCx, uint16_t bitMap, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    if (NewState == ENABLE)
    {
        ADCx->SCHCR |= bitMap;
    }
    else
    {
        ADCx->SCHCR &= (~bitMap);
    }

    return;
}

/**
  * @brief  Power on ADC manually.
  * @param  ADCx: selected ADC peripheral.
  * @param  NewState: new state of the ADC power on.
  *     This parameter can be: ENABLE or DISABLE.
  *     @note If enable, ADC power will always on.
  * @retval None
  */
void ADC_ManualPowerOnCmd(ADC_TypeDef *ADCx, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    if (NewState != DISABLE)
    {
        ADCx->PWRDLY |= BIT19;
    }
    else
    {
        ADCx->PWRDLY &= ~(BIT19);
    }
}

/**
  * @brief  Enable or disable stop fifo from writing data.
  * @param  ADCx: selected ADC peripheral.
  * @param  NewState: new state of the ADC fifo write.
  *     This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_WriteFIFOCmd(ADC_TypeDef *ADCx, FunctionalState NewState)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    if (NewState == DISABLE)
    {
        ADCx->PWRDLY |= BIT21;
    }
    else
    {
        ADCx->PWRDLY &= ~(BIT21);
    }
}

/**
  * @brief  Config ADC bypass resistor.Attention!!!Channels using bypass mode cannot over 0.9V!!!!
  * @param  channelNum: external channel number, can be 0~3.
  * @param  NewState: ENABLE or DISABLE.
  * @retval None
  */
void ADC_BypassCmd(uint8_t ChannelNum, FunctionalState NewState)
{
    assert_param(ChannelNum <= 3);
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    if (ChannelNum > 3)
    {
        return;
    }

    uint16_t reg_value = 0;

    if (NewState != DISABLE)
    {
        reg_value = btaon_fast_read_safe(0x118);
        reg_value |= BIT(ChannelNum);
        btaon_fast_write(0x118, reg_value);
    }
    else
    {
        reg_value = btaon_fast_read_safe(0x118);
        reg_value &= ~BIT(ChannelNum);
        btaon_fast_write(0x118, reg_value);
    }
}

/**
  * @brief  Checks whether the specified ADC interrupt status flag is set or not.
  * @param  ADCx: selected ADC peripheral.
  * @param  ADC_INT_FLAG: specifies the interrupt status flag to check.
  *     This parameter can be one of the following values:
  *     @arg ADC_INT_ONE_SHOT_DONE: ADC once convert end interrupt
  *     @arg ADC_INT_FIFO_OVERFLOW: ADC FIFO overflow interrupt
  *     @arg ADC_INT_FIFO_THD: fifo larger than threshold
  *     @arg ADC_INT_FIFO_RD_ERR: ADC read FIFO error interrupt
  *     @arg ADC_INT_FIFO_RD_REQ: ADC read FIFO request interrupt
  * @retval The new state of ADC_INT (SET or RESET).
  */
ITStatus ADC_GetINTStatus(ADC_TypeDef *ADCx, uint32_t ADC_INT)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_ADC_INT(ADC_INT));

    FlagStatus bitstatus = RESET;

    if ((ADCx->INTCR & (ADC_INT << 16)) != 0)
    {
        bitstatus = SET;
    }

    return bitstatus;
}

/**
  * @brief  Clear the ADC interrupt pending bit.
  * @param  ADCx: selected ADC peripheral.
  * @param  ADC_INT: specifies the interrupt pending bit to clear.
  *     This parameter can be any combination of the following values:
  *     @arg ADC_INT_ONE_SHOT_DONE: ADC once convert end interrupt
  *     @arg ADC_INT_FIFO_OVERFLOW: ADC FIFO overflow interrupt
  *     @arg ADC_INT_FIFO_THD: fifo larger than threshold
  *     @arg ADC_INT_FIFO_RD_ERR: ADC read FIFO error interrupt
  *     @arg ADC_INT_FIFO_RD_REQ: ADC read FIFO request interrupt
  * @retval None
  */
void ADC_ClearINTPendingBit(ADC_TypeDef *ADCx, uint32_t ADC_INT)
{
    /* Check the parameters */
    assert_param(IS_ADC_PERIPH(ADCx));
    assert_param(IS_ADC_INT(ADC_INT));

    ADCx->INTCR |= (ADC_INT << 8);

    return;
}

/******************* (C) COPYRIGHT 2020 Realtek Semiconductor Corporation *****END OF FILE****/