Lines Matching +full:esp32 +full:- +full:s2
4 * SPDX-License-Identifier: Apache-2.0
30 * for ESP32-S2 is doing it, so we copy that approach in Zephyr driver
51 /* Convert resolution in bits to esp32 enum values */
52 #define WIDTH_MASK(r) ((((r) - 9) < ADC_WIDTH_MAX) ? ((r) - 9) : (ADC_WIDTH_MAX - 1))
76 /* Convert zephyr,gain property to the ESP32 attenuation */
93 return -ENOTSUP; in gain_to_atten()
122 struct adc_esp32_data *data = dev->data; in adc_calibration_init()
126 LOG_WRN("Skip software calibration - Not supported!"); in adc_calibration_init()
129 LOG_WRN("Skip software calibration - Invalid version!"); in adc_calibration_init()
143 const struct adc_esp32_conf *conf = dev->config; in adc_esp32_read()
144 struct adc_esp32_data *data = dev->data; in adc_esp32_read()
148 uint8_t channel_id = find_lsb_set(seq->channels) - 1; in adc_esp32_read()
150 if (seq->buffer_size < 2) { in adc_esp32_read()
151 LOG_ERR("Sequence buffer space too low '%d'", seq->buffer_size); in adc_esp32_read()
152 return -ENOMEM; in adc_esp32_read()
155 if (seq->channels > BIT(channel_id)) { in adc_esp32_read()
156 LOG_ERR("Multi-channel readings not supported"); in adc_esp32_read()
157 return -ENOTSUP; in adc_esp32_read()
160 if (seq->options) { in adc_esp32_read()
161 if (seq->options->extra_samplings) { in adc_esp32_read()
163 return -ENOTSUP; in adc_esp32_read()
166 if (seq->options->interval_us) { in adc_esp32_read()
168 return -ENOTSUP; in adc_esp32_read()
172 if (INVALID_RESOLUTION(seq->resolution)) { in adc_esp32_read()
173 LOG_ERR("unsupported resolution (%d)", seq->resolution); in adc_esp32_read()
174 return -ENOTSUP; in adc_esp32_read()
177 if (seq->calibrate) { in adc_esp32_read()
180 return -ENOTSUP; in adc_esp32_read()
183 data->resolution[channel_id] = seq->resolution; in adc_esp32_read()
187 if (conf->unit == ADC_UNIT_1) { in adc_esp32_read()
191 adc_set_data_width(conf->unit, WIDTH_MASK(data->resolution[channel_id])); in adc_esp32_read()
195 if (conf->unit == ADC_UNIT_1) { in adc_esp32_read()
198 if (conf->unit == ADC_UNIT_2) { in adc_esp32_read()
200 LOG_ERR("Conversion timeout on '%s' channel %d", dev->name, channel_id); in adc_esp32_read()
201 return -ETIMEDOUT; in adc_esp32_read()
206 if (data->calibrate) { in adc_esp32_read()
207 data->chars[channel_id].bit_width = WIDTH_MASK(data->resolution[channel_id]); in adc_esp32_read()
209 cal = cal_mv = esp_adc_cal_raw_to_voltage(reading, &data->chars[channel_id]); in adc_esp32_read()
212 if (data->attenuation[channel_id] == ADC_ATTEN_DB_11) { in adc_esp32_read()
220 atten_to_gain(data->attenuation[channel_id], &cal); in adc_esp32_read()
221 if (data->meas_ref_internal > 0) { in adc_esp32_read()
222 cal = (cal << data->resolution[channel_id]) / data->meas_ref_internal; in adc_esp32_read()
231 data->buffer = (uint16_t *) seq->buffer; in adc_esp32_read()
232 data->buffer[0] = cal; in adc_esp32_read()
246 return -ENOTSUP; in adc_esp32_read_async()
252 const struct adc_esp32_conf *conf = (const struct adc_esp32_conf *)dev->config; in adc_esp32_channel_setup()
253 struct adc_esp32_data *data = (struct adc_esp32_data *) dev->data; in adc_esp32_channel_setup()
256 if (cfg->channel_id >= conf->channel_count) { in adc_esp32_channel_setup()
257 LOG_ERR("Unsupported channel id '%d'", cfg->channel_id); in adc_esp32_channel_setup()
258 return -ENOTSUP; in adc_esp32_channel_setup()
261 if (cfg->reference != ADC_REF_INTERNAL) { in adc_esp32_channel_setup()
262 LOG_ERR("Unsupported channel reference '%d'", cfg->reference); in adc_esp32_channel_setup()
263 return -ENOTSUP; in adc_esp32_channel_setup()
266 if (cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { in adc_esp32_channel_setup()
267 LOG_ERR("Unsupported acquisition_time '%d'", cfg->acquisition_time); in adc_esp32_channel_setup()
268 return -ENOTSUP; in adc_esp32_channel_setup()
271 if (cfg->differential) { in adc_esp32_channel_setup()
273 return -ENOTSUP; in adc_esp32_channel_setup()
276 if (gain_to_atten(cfg->gain, &data->attenuation[cfg->channel_id])) { in adc_esp32_channel_setup()
277 LOG_ERR("Unsupported gain value '%d'", cfg->gain); in adc_esp32_channel_setup()
278 return -ENOTSUP; in adc_esp32_channel_setup()
282 if (conf->unit == ADC_UNIT_1) { in adc_esp32_channel_setup()
283 adc1_config_channel_atten(cfg->channel_id, data->attenuation[cfg->channel_id]); in adc_esp32_channel_setup()
285 if (conf->unit == ADC_UNIT_2) { in adc_esp32_channel_setup()
286 adc2_config_channel_atten(cfg->channel_id, data->attenuation[cfg->channel_id]); in adc_esp32_channel_setup()
289 if (data->calibrate) { in adc_esp32_channel_setup()
290 esp_adc_cal_value_t cal = esp_adc_cal_characterize(conf->unit, in adc_esp32_channel_setup()
291 data->attenuation[cfg->channel_id], in adc_esp32_channel_setup()
292 WIDTH_MASK(data->resolution[cfg->channel_id]), in adc_esp32_channel_setup()
293 data->meas_ref_internal, in adc_esp32_channel_setup()
294 &data->chars[cfg->channel_id]); in adc_esp32_channel_setup()
297 return -EIO; in adc_esp32_channel_setup()
307 struct adc_esp32_data *data = (struct adc_esp32_data *) dev->data; in adc_esp32_init()
309 for (uint8_t i = 0; i < ARRAY_SIZE(data->resolution); i++) { in adc_esp32_init()
310 data->resolution[i] = ADC_RESOLUTION_MAX; in adc_esp32_init()
312 for (uint8_t i = 0; i < ARRAY_SIZE(data->attenuation); i++) { in adc_esp32_init()
313 data->attenuation[i] = ADC_ATTEN_DB_0; in adc_esp32_init()
317 data->meas_ref_internal = ADC_ESP32_DEFAULT_VREF_INTERNAL; in adc_esp32_init()
320 data->calibrate = adc_calibration_init(dev); in adc_esp32_init()