Lines Matching +full:sample +full:- +full:time +full:- +full:us
4 * SPDX-License-Identifier: Apache-2.0
32 /* ADC sample time delay (Unit:us) */
38 #define ADC_CHANNEL_OFFSET(ch) ((ch)-CHIP_ADC_CH13-ADC_CHANNEL_SHIFT)
77 * The sample buffer pointer should be prepared
85 * this config will be used at initial time
98 uint8_t channel_id = channel_cfg->channel_id; in adc_it8xxx2_channel_setup()
100 if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { in adc_it8xxx2_channel_setup()
101 LOG_ERR("Selected ADC acquisition time is not valid"); in adc_it8xxx2_channel_setup()
102 return -EINVAL; in adc_it8xxx2_channel_setup()
109 return -EINVAL; in adc_it8xxx2_channel_setup()
114 channel_id -= ADC_CHANNEL_SHIFT; in adc_it8xxx2_channel_setup()
117 if (channel_cfg->gain != ADC_GAIN_1) { in adc_it8xxx2_channel_setup()
119 return -EINVAL; in adc_it8xxx2_channel_setup()
122 if (channel_cfg->reference != ADC_REF_INTERNAL) { in adc_it8xxx2_channel_setup()
124 return -EINVAL; in adc_it8xxx2_channel_setup()
140 adc_regs->VCH0CTL = IT8XXX2_ADC_DATVAL | in adc_disable_measurement()
148 adc_regs->adc_vchs_ctrl[ADC_CHANNEL_OFFSET(ch)].VCHCTL = in adc_disable_measurement()
153 adc_regs->ADCCFG &= ~IT8XXX2_ADC_ADCEN; in adc_disable_measurement()
162 struct adc_it8xxx2_data *data = dev->data; in adc_data_valid()
164 return (data->ch <= CHIP_ADC_CH7) ? in adc_data_valid()
165 (adc_regs->VCH0CTL & IT8XXX2_ADC_DATVAL) : in adc_data_valid()
166 (adc_regs->ADCDVSTS2 & BIT(ADC_CHANNEL_OFFSET(data->ch))); in adc_data_valid()
172 struct adc_it8xxx2_data *data = dev->data; in adc_it8xxx2_get_sample()
176 if (data->ch <= CHIP_ADC_CH7) { in adc_it8xxx2_get_sample()
178 *data->buffer++ = adc_regs->VCH0DATM << 8 | in adc_it8xxx2_get_sample()
179 adc_regs->VCH0DATL; in adc_it8xxx2_get_sample()
182 *data->buffer++ = in adc_it8xxx2_get_sample()
183 adc_regs->adc_vchs_ctrl[ADC_CHANNEL_OFFSET(data->ch)].VCHDATM << 8 | in adc_it8xxx2_get_sample()
184 adc_regs->adc_vchs_ctrl[ADC_CHANNEL_OFFSET(data->ch)].VCHDATL; in adc_it8xxx2_get_sample()
188 adc_regs->ADCDVSTS, data->ch); in adc_it8xxx2_get_sample()
191 adc_disable_measurement(data->ch); in adc_it8xxx2_get_sample()
201 * the sampling time limit, the program will return. in adc_poll_valid_data()
205 /* Wait next clock time (1/32.768K~=30.5us) */ in adc_poll_valid_data()
226 struct adc_it8xxx2_data *data = dev->data; in adc_enable_measurement()
230 adc_regs->VCH0CTL = (IT8XXX2_ADC_DATVAL | IT8XXX2_ADC_INTDVEN) + ch; in adc_enable_measurement()
233 adc_regs->adc_vchs_ctrl[ADC_CHANNEL_OFFSET(ch)].VCHCTL = in adc_enable_measurement()
238 adc_regs->ADCCFG |= IT8XXX2_ADC_ADCEN; in adc_enable_measurement()
242 * at a time. The ADC sampling of it8xxx2 needs to read each channel in adc_enable_measurement()
258 k_sem_take(&data->sem, K_FOREVER); in adc_enable_measurement()
268 if (sequence->options) { in check_buffer_size()
269 needed_buffer_size *= (1 + sequence->options->extra_samplings); in check_buffer_size()
272 if (sequence->buffer_size < needed_buffer_size) { in check_buffer_size()
274 sequence->buffer_size, needed_buffer_size); in check_buffer_size()
275 return -ENOMEM; in check_buffer_size()
284 struct adc_it8xxx2_data *data = dev->data; in adc_it8xxx2_start_read()
285 uint32_t channel_mask = sequence->channels; in adc_it8xxx2_start_read()
294 return -EINVAL; in adc_it8xxx2_start_read()
297 if (!sequence->resolution) { in adc_it8xxx2_start_read()
299 return -EINVAL; in adc_it8xxx2_start_read()
301 LOG_DBG("Configure resolution=%d", sequence->resolution); in adc_it8xxx2_start_read()
303 data->buffer = sequence->buffer; in adc_it8xxx2_start_read()
305 adc_context_start_read(&data->ctx, sequence); in adc_it8xxx2_start_read()
307 return adc_context_wait_for_completion(&data->ctx); in adc_it8xxx2_start_read()
314 uint32_t channels = ctx->sequence.channels; in adc_context_start_sampling()
317 data->repeat_buffer = data->buffer; in adc_context_start_sampling()
324 data->ch = find_lsb_set(channels) - 1; in adc_context_start_sampling()
325 channels &= ~BIT(data->ch); in adc_context_start_sampling()
327 adc_enable_measurement(data->ch); in adc_context_start_sampling()
332 if (check_buffer_size(&ctx->sequence, channel_count)) { in adc_context_start_sampling()
336 adc_context_on_sampling_done(&data->ctx, DEVICE_DT_INST_GET(0)); in adc_context_start_sampling()
342 struct adc_it8xxx2_data *data = dev->data; in adc_it8xxx2_read()
345 adc_context_lock(&data->ctx, false, NULL); in adc_it8xxx2_read()
347 adc_context_release(&data->ctx, err); in adc_it8xxx2_read()
357 struct adc_it8xxx2_data *data = dev->data; in adc_it8xxx2_read_async()
360 adc_context_lock(&data->ctx, true, async); in adc_it8xxx2_read_async()
362 adc_context_release(&data->ctx, err); in adc_it8xxx2_read_async()
375 data->buffer = data->repeat_buffer; in adc_context_update_buffer_pointer()
381 struct adc_it8xxx2_data *data = dev->data; in adc_it8xxx2_isr()
387 k_sem_give(&data->sem); in adc_it8xxx2_isr()
412 adc_regs->ADCSTS |= IT8XXX2_ADC_AINITB; in adc_accuracy_initialization()
414 adc_regs->KDCTL |= IT8XXX2_ADC_AHCE; in adc_accuracy_initialization()
416 adc_regs->ADCSTS &= ~IT8XXX2_ADC_AINITB; in adc_accuracy_initialization()
421 const struct adc_it8xxx2_cfg *config = dev->config; in adc_it8xxx2_init()
422 struct adc_it8xxx2_data *data = dev->data; in adc_it8xxx2_init()
427 /* ADC input voltage 0V ~ AVCC (3.3V) is mapped into 0h-3FFh */ in adc_it8xxx2_init()
428 adc_regs->ADCIVMFSCS1 = ADC_0_7_FULL_SCALE_MASK; in adc_it8xxx2_init()
429 adc_regs->ADCIVMFSCS2 = ADC_8_10_FULL_SCALE_MASK; in adc_it8xxx2_init()
430 adc_regs->ADCIVMFSCS3 = ADC_13_16_FULL_SCALE_MASK; in adc_it8xxx2_init()
436 status = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in adc_it8xxx2_init()
443 * The ADC channel conversion time is 30.8*(SCLKDIV+1) us. in adc_it8xxx2_init()
444 * (Current setting is 61.6us) in adc_it8xxx2_init()
446 * NOTE: A sample time delay (60us) also need to be included in in adc_it8xxx2_init()
447 * conversion time. in adc_it8xxx2_init()
448 * In addition, the ADC has a waiting time of 202.8us for in adc_it8xxx2_init()
451 * So the final ADC sample time result is ~= 324.4us. in adc_it8xxx2_init()
453 adc_regs->ADCSTS &= ~IT8XXX2_ADC_ADCCTS1; in adc_it8xxx2_init()
454 adc_regs->ADCCFG &= ~IT8XXX2_ADC_ADCCTS0; in adc_it8xxx2_init()
456 * bit[5-0]@ADCCTL : SCLKDIV in adc_it8xxx2_init()
459 adc_regs->ADCCTL = 1; in adc_it8xxx2_init()
462 adc_regs->ADCCTL1 = in adc_it8xxx2_init()
463 (adc_regs->ADCCTL1 & ~ADC_SACLKDIV_MASK) | ADC_SACLKDIV(2); in adc_it8xxx2_init()
469 adc_regs->ADCGCR |= IT8XXX2_ADC_DBKEN; in adc_it8xxx2_init()
474 k_sem_init(&data->sem, 0, 1); in adc_it8xxx2_init()
475 adc_context_unlock_unconditionally(&data->ctx); in adc_it8xxx2_init()