42 #include "sys/clock.h" 53 #define PRINTF(...) printf(__VA_ARGS__) 58 static uint8_t decimation_rate;
59 static uint8_t enabled_channels;
62 set_decimation_rate(uint8_t rate)
69 decimation_rate = rate;
72 return ZOUL_SENSORS_ERROR;
75 return decimation_rate;
79 get_channel_pin(
int type)
81 if((ZOUL_SENSORS_ADC1) && (type == ZOUL_SENSORS_ADC1)) {
84 if((ZOUL_SENSORS_ADC2) && (type == ZOUL_SENSORS_ADC2)) {
87 if((ZOUL_SENSORS_ADC3) && (type == ZOUL_SENSORS_ADC3)) {
90 if((ZOUL_SENSORS_ADC4) && (type == ZOUL_SENSORS_ADC4)) {
93 if((ZOUL_SENSORS_ADC5) && (type == ZOUL_SENSORS_ADC5)) {
96 if((ZOUL_SENSORS_ADC6) && (type == ZOUL_SENSORS_ADC6)) {
99 return ZOUL_SENSORS_ERROR;
108 if(!(type & enabled_channels)) {
109 PRINTF(
"ADC: channel not enabled\n");
110 return ZOUL_SENSORS_ERROR;
113 channel = get_channel_pin(type);
115 if(channel == ZOUL_SENSORS_ERROR) {
116 PRINTF(
"ADC: pin not active\n");
117 return ZOUL_SENSORS_ERROR;
120 res =
adc_get(channel, ADC_SENSORS_REFERENCE, decimation_rate);
131 configure(
int type,
int value)
134 case SENSORS_HW_INIT:
138 PRINTF(
"ADC: invalid adc pin mask (0x%02X)\n", value);
139 return ZOUL_SENSORS_ERROR;
145 if(value & ZOUL_SENSORS_ADC1) {
148 if(value & ZOUL_SENSORS_ADC2) {
151 if(value & ZOUL_SENSORS_ADC3) {
154 if(value & ZOUL_SENSORS_ADC4) {
157 if(value & ZOUL_SENSORS_ADC5) {
160 if(value & ZOUL_SENSORS_ADC6) {
165 enabled_channels |= value;
166 PRINTF(
"ADC: enabled channels 0x%02X\n", enabled_channels);
169 case ZOUL_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE:
170 return set_decimation_rate((uint8_t)value);
173 return ZOUL_SENSORS_ERROR;
184 SENSORS_SENSOR(adc_zoul, ADC_ZOUL, value, configure, status);
#define SOC_ADC_ADCCON_REF_EXT_DIFF
External reference on AIN6-AIN7 differential input.
#define ADC_SENSORS_ADC1_PIN
ADC1 to PA5.
#define SOC_ADC_ADCCON_DIV_512
512 decimation rate (12 bits ENOB)
#define ADC_SENSORS_ADC6_PIN
ADC6 not declared.
#define SOC_ADC_ADCCON_DIV_128
128 decimation rate (9 bits ENOB)
Header file with register and macro declarations for the cc2538 GPIO module.
#define ADC_SENSORS_ADC4_PIN
ADC4 to PA6.
Header file with declarations for the I/O Control module.
#define ADC_SENSORS_ADC3_PIN
ADC3 to PA2.
#define IOC_OVERRIDE_ANA
Analog Enable.
void adc_init(void)
Initializes the ADC controller.
Header file for the cc2538 ADC driver.
Implementation of a generic module controlling Zoul sensors.
#define ZOUL_SENSORS_ADC_MIN
PA1 pin mask.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE. ...
#define SOC_ADC_ADCCON_DIV_64
64 decimation rate (7 bits ENOB)
#define SOC_ADC_ADCCON_DIV_256
256 decimation rate (10 bits ENOB)
#define GPIO_A_NUM
GPIO_A: 0.
void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over)
Set Port:Pin override function.
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to input.
#define SOC_ADC_ADCCON_CH_AIN0
AIN0.
#define GPIO_A_BASE
GPIO_A.
#define ADC_SENSORS_ADC2_PIN
ADC2 to PA4.
#define ADC_SENSORS_ADC5_PIN
ADC5 to PA7.
int16_t adc_get(uint8_t channel, uint8_t ref, uint8_t div)
Performs a single conversion on a given ADC channel.
Header file for the Zoul ADC interface.