Skip to content

Commit bed5b62

Browse files
committed
Fix: There is no need to manually power-up the ADC, as the ADC is powered-up within 'adc1_get_raw'
1 parent ae9c853 commit bed5b62

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

main/CommandHandler.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,20 +1199,16 @@ extern "C" {
11991199

12001200
int getAnalogRead(const uint8_t command[], uint8_t response[])
12011201
{
1202-
uint8_t pin = command[4];
1202+
uint8_t adc_channel = command[4];
12031203

1204-
/* Power up the ADC. */
1205-
adc_power_on();
12061204
/* Initialize the ADC. */
1207-
adc_gpio_init(ADC_UNIT_1, (adc_channel_t)pin);
1205+
adc_gpio_init(ADC_UNIT_1, (adc_channel_t)adc_channel);
12081206
/* Set maximum analog bit-width = 12 bit. */
12091207
adc1_config_width(ADC_WIDTH_BIT_12);
12101208
/* Configure channel attenuation. */
1211-
adc1_config_channel_atten((adc1_channel_t)pin, ADC_ATTEN_DB_0);
1209+
adc1_config_channel_atten((adc1_channel_t)adc_channel, ADC_ATTEN_DB_0);
12121210
/* Read the analog value from the pin. */
1213-
uint16_t const adc_raw = adc1_get_raw((adc1_channel_t)pin);
1214-
/* Power down the ADC. */
1215-
adc_power_off();
1211+
uint16_t const adc_raw = adc1_get_raw((adc1_channel_t)adc_channel);
12161212

12171213
response[2] = 1; // number of parameters
12181214
response[3] = sizeof(adc_raw); // parameter 1 length = 2 bytes

0 commit comments

Comments
 (0)