parent
63033f73f4
commit
0aa43c5f5b
|
|
@ -31,6 +31,38 @@ static TaskHandle_t adc_task_handle;
|
|||
|
||||
static const char *TAG = "EERG";
|
||||
|
||||
/* ADC continuous read task */
|
||||
static void adc_read_task(void *pvParameter)
|
||||
{
|
||||
ESP_LOGI(TAG, "Starting adc read task");
|
||||
esp_err_t adc_ret;
|
||||
uint32_t ret_num = 0;
|
||||
uint8_t result[ADC_READ_LEN] = {0};
|
||||
/* Fill result with 0xcc */
|
||||
memset(result, 0xcc, ADC_READ_LEN);
|
||||
|
||||
/* Wait here until notified that the conversion is done */
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ADC conversion finished callback */
|
||||
static bool IRAM_ATTR adc_conv_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data)
|
||||
|
|
@ -109,32 +141,12 @@ void app_main(void)
|
|||
/* Initialize continuous driver */
|
||||
adc_cont_init();
|
||||
/* Start the continuous driver */
|
||||
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};
|
||||
/* Fill result with 0xcc */
|
||||
memset(result, 0xcc, ADC_READ_LEN);
|
||||
xTaskCreate(adc_read_task, "adc read", 2048, NULL, 0, &adc_task_handle);
|
||||
|
||||
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 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue