parent
2abdd7be0c
commit
284f9e4d71
|
|
@ -10,6 +10,7 @@
|
|||
#include "freertos/task.h"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "hal/adc_types.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
/* ADC input pins */
|
||||
#define ADC_INPUT_1_PIN 4
|
||||
|
|
@ -17,6 +18,8 @@
|
|||
#define ADC_INPUT_3_PIN 9 /* TODO Reroute from pin 46 to 9 on schematic, cant do ADC */
|
||||
#define ADC_INPUT_4_PIN 10
|
||||
|
||||
#define ADC_READ_LEN 256
|
||||
|
||||
/* ADC channels */
|
||||
static adc_channel_t channel[4] = {ADC_CHANNEL_3, ADC_CHANNEL_5, ADC_CHANNEL_8, ADC_CHANNEL_9};
|
||||
|
||||
|
|
@ -67,7 +70,7 @@ static void adc_cont_init(void)
|
|||
/* Create continuous mode driver handle */
|
||||
adc_continuous_handle_cfg_t adc_handle_config = {
|
||||
.max_store_buf_size = 1024,
|
||||
.conv_frame_size = 100
|
||||
.conv_frame_size = ADC_READ_LEN
|
||||
};
|
||||
ESP_ERROR_CHECK(adc_continuous_new_handle(&adc_handle_config, &adc_handle));
|
||||
|
||||
|
|
@ -108,6 +111,29 @@ void app_main(void)
|
|||
adc_task_handle = xTaskGetCurrentTaskHandle();
|
||||
ESP_ERROR_CHECK(adc_continuous_start(adc_handle));
|
||||
|
||||
esp_err_t adc_ret;
|
||||
uint32_t ret_num = 0;
|
||||
uint8_t result[ADC_READ_LEN] = {0};
|
||||
|
||||
while (1) {
|
||||
/* Perform a read */
|
||||
adc_ret = adc_continuous_read(adc_handle, result, ADC_READ_LEN, &ret_num, 0);
|
||||
if (adc_ret == ESP_OK) {
|
||||
for (int i = 0; i < ret_num; i+= SOC_ADC_DIGI_RESULT_BYTES) {
|
||||
/* Grab the data and channel number */
|
||||
adc_digi_output_data_t *p_data = (void*)&result[i];
|
||||
uint32_t chan = ((p_data)->type2.channel);
|
||||
uint32_t data = ((p_data)->type2.data);
|
||||
/* Check channel number to see if data is bogus */
|
||||
if (chan < SOC_ADC_CHANNEL_NUM(ADC_UNIT_1)) {
|
||||
ESP_LOGI("adc", "ADC_1_%"PRIu32" value: %"PRIx32, chan, data);
|
||||
} else {
|
||||
ESP_LOGW("adc", "Invalid data from ADC_1_%"PRIu32, chan);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Cleanup ADC */
|
||||
adc_cleanup();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue