-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadc_driver.cpp
More file actions
55 lines (43 loc) · 1.24 KB
/
Copy pathadc_driver.cpp
File metadata and controls
55 lines (43 loc) · 1.24 KB
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
#include "adc_driver.h"
CADC_Driver ADC0_Driver(MCU_ADC0_BASE_ADDRESS);
CADC_Driver ADC1_Driver(MCU_ADC1_BASE_ADDRESS);
CADC_Driver ADCDriver[2] = {ADC0_Driver, ADC1_Driver};
int32_t CADC_Driver::initialize(const uint32_t chNum, const CADC_ChannelConfig& params)
{
stopAcq(chNum);
if (params._inputType == e_conversionMode_Continous)
{
ADC_CONFIG_REGISTERS->ADC_STEPCONFIG[chNum] |= (1 << MODE);
}
ADC_CONFIG_REGISTERS->ADC_STEPCONFIG[chNum] |= ((params._sampleAvgNum) << AVERAGING);
ADC_CONFIG_REGISTERS->ADC_STEPCONFIG[chNum] |= ((chNum & 0xF) << SEL_INP_SWC);
if (params._inputNegPin == INVALID_PIN)
{
ADC_CONFIG_REGISTERS->ADC_STEPCONFIG[chNum] &= ~(1 << DIFF_CNTRL_BIT);
}
else
{
ADC_CONFIG_REGISTERS->ADC_STEPCONFIG[chNum] |= ((chNum & 0xF) << SEL_INM_SWM);
}
}
int32_t CADC_Driver::startAcq(const uint32_t chNum)
{
ADC_CONFIG_REGISTERS->ADC_STEPENABLE |= (1 << chNum);
enableADC();
return 0;
}
int32_t CADC_Driver::enableAdc()
{
ADC_CONFIG_REGISTERS->ADC_ENABLE_CLR |= (0x01);
return 0;
}
int32_t CADC_Driver::disable()
{
ADC_CONFIG_REGISTERS->ADC_ENABLE_CLR &= ~(0x01);
return 0;
}
int32_t CADC_Driver::stopAcq(const uint32_t chNum)
{
ADC_CONFIG_REGISTERS->ADC_STEPENABLE &= ~(1 << chNum); // disable it for now
return 0;
}