Thu, 28 Sep 2023 11:29:23 +0200
Some ADC code simplified.
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * @file task_adc.c |
41
d327e0aff62f
Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents:
37
diff
changeset
|
3 | * @brief The FreeRTOS task to query the pressure sensors connected to ADC inputs. |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * The task will update the ADC_State structure. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | #include "config.h" |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | #define DEFAULT_VREF 1093 ///< Use adc2_vref_to_gpio() to obtain a better estimate |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
12 | #define NO_OF_SAMPLES 128 ///< Multisampling |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | |
44
e52d11b8f252
Removed dead code. Added more doxygen documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
41
diff
changeset
|
14 | #define PRESSURE_1 (CONFIG_PRESSURE_1) ///< ADC channel pressure sensor 1 |
e52d11b8f252
Removed dead code. Added more doxygen documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
41
diff
changeset
|
15 | #define PRESSURE_2 (CONFIG_PRESSURE_2) ///< ADC channel pressure sensor 2 |
e52d11b8f252
Removed dead code. Added more doxygen documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
41
diff
changeset
|
16 | #define PRESSURE_3 (CONFIG_PRESSURE_3) ///< ADC channel pressure sensor 3 |
e52d11b8f252
Removed dead code. Added more doxygen documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
41
diff
changeset
|
17 | #define BATT_CHANNEL (CONFIG_BATT_CHANNEL) ///< ADC channel half battery voltage |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | static const char *TAG = "task_adc"; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | SemaphoreHandle_t xSemaphoreADC = NULL; ///< Semaphire ADC task |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | EventGroupHandle_t xEventGroupADC; ///< Events ADC task |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | ADC_State *adc_state; ///< Public state for other tasks |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
25 | bool do_calibration = false; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
26 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | const int TASK_ADC_REQUEST_PRESSURE = BIT0; ///< Request temperature measurements |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | const int TASK_ADC_REQUEST_DONE = BIT1; ///< Request is completed |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
32 | static bool adc_calibration_init(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_t *out_handle); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
33 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | void request_adc(void) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | xEventGroupClearBits(xEventGroupADC, TASK_ADC_REQUEST_DONE); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | xEventGroupSetBits(xEventGroupADC, TASK_ADC_REQUEST_PRESSURE); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | bool ready_adc(void) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | if (xEventGroupGetBits(xEventGroupADC) & TASK_ADC_REQUEST_DONE) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | return true; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | return false; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | * Task to read pressure sensors and battery voltage on request. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | void task_adc(void *pvParameter) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | { |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
57 | adc_cali_handle_t adc1_cali_handle = NULL; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
58 | adc_unit_t channel; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
59 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
60 | adc_oneshot_chan_cfg_t config_adc = { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
61 | .bitwidth = ADC_BITWIDTH_DEFAULT, |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
62 | .atten = ADC_ATTEN_DB_0, |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
63 | }; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | ESP_LOGI(TAG, "Starting task ADC sensors"); |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
66 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | adc_state = malloc(sizeof(ADC_State)); |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
68 | for (int i = 0; i < 3; i++) { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
69 | adc_state->Pressure[i].valid = false; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
70 | adc_state->Pressure[i].atten = ADC_ATTEN_DB_0; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
71 | adc_state->Pressure[i].voltage = 0; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
72 | adc_state->Pressure[i].error = ADC_ERR_NONE; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | adc_state->Pressure[0].channel = PRESSURE_1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | adc_state->Pressure[1].channel = PRESSURE_2; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | adc_state->Pressure[2].channel = PRESSURE_3; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | adc_state->Batt_voltage = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | adc_state->Batt_error = ADC_ERR_NONE; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | /* event handler and event group for this task */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | xEventGroupADC = xEventGroupCreate(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | EventBits_t uxBits; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | * Task loop forever. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | while (1) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
88 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | uxBits = xEventGroupWaitBits(xEventGroupADC, TASK_ADC_REQUEST_PRESSURE, pdFALSE, pdFALSE, portMAX_DELAY ); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | if (uxBits & TASK_ADC_REQUEST_PRESSURE) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | |
37
358bbd5b608e
menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
93 | ESP_LOGD(TAG, "Requested ADC readings"); |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
94 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
95 | int adc_reading, raw, tmp, voltage; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
96 | adc_atten_t atten = ADC_ATTEN_DB_0; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
97 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
98 | adc_oneshot_unit_handle_t adc1_handle; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
99 | adc_oneshot_unit_init_cfg_t init_config1 = { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
100 | .unit_id = ADC_UNIT_1, |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
101 | }; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
103 | for (int i = 0; i < 3; i++) { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
104 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
105 | ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle)); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
106 | atten = config_adc.atten = ADC_ATTEN_DB_0, |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
107 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
108 | channel = adc_state->Pressure[i].channel; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
109 | ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, channel, &config_adc)); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | adc_reading = 0; |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
111 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
112 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | * Autoranging the ADC conversion |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | while (1) { |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
116 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
117 | config_adc.bitwidth = ADC_BITWIDTH_DEFAULT; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
118 | config_adc.atten = atten; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
119 | adc_oneshot_config_channel(adc1_handle, channel, &config_adc); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
120 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
121 | ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, channel, &raw)); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
122 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
123 | // ESP_LOGI(TAG, "bottle %d channel %d raw %d atten %d", i, channel, raw, atten); |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
124 | if (atten == ADC_ATTEN_DB_0 && raw > 3700) |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
125 | atten = ADC_ATTEN_DB_2_5; |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
126 | else if (atten == ADC_ATTEN_DB_2_5 && raw > 3700) |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
127 | atten = ADC_ATTEN_DB_6; |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
128 | else if (atten == ADC_ATTEN_DB_6 && raw > 3700) |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
129 | atten = ADC_ATTEN_DB_11; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
130 | else |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
131 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
132 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
133 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | * Now that he have the best attenuation, multisample the real value. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
136 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | for (int j = 0; j < NO_OF_SAMPLES; j++) { |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
138 | if (adc_oneshot_read(adc1_handle, channel, &tmp) == ESP_OK) { |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | adc_reading += tmp; |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
140 | } else { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
141 | adc_reading = -1; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
142 | break; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
143 | } |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
144 | } |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
145 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
146 | do_calibration = adc_calibration_init(ADC_UNIT_1, atten, &adc1_cali_handle); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
147 | |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
148 | if (xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE) { |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
149 | if (adc_reading < 0) { |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
150 | adc_state->Pressure[i].error = ADC_ERR_READ; |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
151 | adc_state->Pressure[i].voltage = 0; |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
152 | } else { |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
153 | adc_reading /= NO_OF_SAMPLES; |
76 | 154 | adc_cali_raw_to_voltage(adc1_cali_handle, adc_reading, &voltage); // voltage in mV |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
155 | adc_state->Pressure[i].voltage = voltage; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | adc_state->Pressure[i].error = ADC_ERR_NONE; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | } |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
158 | xSemaphoreGive(xSemaphoreADC); |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
159 | } else { |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
160 | ESP_LOGE(TAG, "Missed lock 1"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
161 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | ESP_LOGI(TAG, "Pressure %d raw: %4d, atten: %d, %.3f volt, error: %d", |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
163 | i, adc_reading, atten, (adc_state->Pressure[i].voltage / 1000.0), adc_state->Pressure[i].error); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
164 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
165 | //Tear Down |
76 | 166 | adc_oneshot_del_unit(adc1_handle); |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
167 | if (do_calibration) { |
76 | 168 | adc_cali_delete_scheme_line_fitting(adc1_cali_handle); |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
169 | } |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
170 | do_calibration = false; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
171 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
172 | |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
173 | /* |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
174 | * Read VDD by reading 1/2 VDD from a precision ladder. |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
175 | */ |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
176 | adc_reading = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
177 | atten = ADC_ATTEN_DB_6; // Don't use DB_11, it has a bad linearity. |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
178 | channel = (adc_unit_t)BATT_CHANNEL; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
179 | ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle)); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
180 | do_calibration = adc_calibration_init(ADC_UNIT_1, atten, &adc1_cali_handle); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
181 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
182 | config_adc.bitwidth = ADC_BITWIDTH_DEFAULT; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
183 | config_adc.atten = atten; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
184 | adc_oneshot_config_channel(adc1_handle, (adc_unit_t)BATT_CHANNEL, &config_adc); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
185 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
186 | ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, (adc_unit_t)BATT_CHANNEL, &raw)); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
187 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
188 | for (int j = 0; j < NO_OF_SAMPLES; j++) { |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
189 | if (adc_oneshot_read(adc1_handle, channel, &tmp) == ESP_OK) { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
190 | adc_reading += tmp; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
191 | } else { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
192 | adc_reading = -1; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
193 | break; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
194 | } |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
195 | } |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
196 | if (xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE) { |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
197 | if (adc_reading < 0) { |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
198 | adc_state->Batt_voltage = 3.3; |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
199 | adc_state->Batt_error = ADC_ERR_READ; |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
200 | } else { |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
201 | adc_reading /= NO_OF_SAMPLES; |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
202 | adc_cali_raw_to_voltage(adc1_cali_handle, adc_reading, &voltage); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
203 | /* Multiply by 2, measured on a ladder. */ |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
204 | adc_state->Batt_voltage = voltage * 2; // Chip supply voltage in mV |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
205 | adc_state->Batt_error = ADC_ERR_NONE; |
12
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
206 | } |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
207 | xSemaphoreGive(xSemaphoreADC); |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
208 | } else { |
7dc9003f86a8
ADC1 source code cleanup. Switched to 12 bit resolution again. Multisample set to 128. Improved adc-state structure locking. Improved ADC read error detection. DS18B20 extra error logging. MQTT better publish counter locking.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
209 | ESP_LOGE(TAG, "Missed lock 2"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
210 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
211 | |
76 | 212 | adc_oneshot_del_unit(adc1_handle); |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
213 | if (do_calibration) { |
76 | 214 | adc_cali_delete_scheme_line_fitting(adc1_cali_handle); |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
215 | } |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
216 | do_calibration = false; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
217 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
218 | xEventGroupClearBits(xEventGroupADC, TASK_ADC_REQUEST_PRESSURE); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
219 | xEventGroupSetBits(xEventGroupADC, TASK_ADC_REQUEST_DONE); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
220 | #if 1 |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
221 | ESP_LOGI(TAG, "Battery raw: %4d, atten: %d %.3f volt, error: %d", adc_reading, atten, adc_state->Batt_voltage / 1000.0, adc_state->Batt_error); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
222 | #endif |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
223 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
224 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
225 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
226 | |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
227 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
228 | /*--------------------------------------------------------------- |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
229 | ADC Calibration |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
230 | ---------------------------------------------------------------*/ |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
231 | static bool adc_calibration_init(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_t *out_handle) |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
232 | { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
233 | adc_cali_handle_t handle = NULL; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
234 | bool calibrated = false; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
235 | |
76 | 236 | adc_cali_line_fitting_config_t cali_config = { |
237 | .unit_id = unit, | |
238 | .atten = atten, | |
239 | .bitwidth = ADC_BITWIDTH_DEFAULT, | |
240 | }; | |
241 | esp_err_t ret = adc_cali_create_scheme_line_fitting(&cali_config, &handle); | |
242 | if (ret == ESP_OK) { | |
243 | calibrated = true; | |
68
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
244 | } |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
245 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
246 | *out_handle = handle; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
247 | if (ret == ESP_ERR_NOT_SUPPORTED || !calibrated) { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
248 | ESP_LOGW(TAG, "eFuse not burnt, skip software calibration"); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
249 | } else if (ret != ESP_OK) { |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
250 | ESP_LOGE(TAG, "Invalid arg or no memory"); |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
251 | } |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
252 | |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
253 | return calibrated; |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
254 | } |
121b3fa6b806
Migrated ADC converter to isp-idf v5.1
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
255 |