Lines Matching +full:bus +full:- +full:range

5  * SPDX-License-Identifier: Apache-2.0
74 /* +/-6.144V range = Gain 1/3 */
76 /* +/-4.096V range = Gain 1/2 */
78 /* +/-2.048V range = Gain 1 (default) */
80 /* +/-1.024V range = Gain 2 */
82 /* +/-0.512V range = Gain 4 */
84 /* +/-0.256V range = Gain 8 */
108 /* Non-latching comparator (default) */
126 struct i2c_dt_spec bus; member
148 const struct ads1x1x_config *config = dev->config; in ads1x1x_read_reg()
152 ret = i2c_burst_read_dt(&config->bus, reg_addr, (uint8_t *)&reg_val, sizeof(reg_val)); in ads1x1x_read_reg()
154 LOG_ERR("ADS1X1X[0x%X]: error reading register 0x%X (%d)", config->bus.addr, in ads1x1x_read_reg()
166 const struct ads1x1x_config *config = dev->config; in ads1x1x_write_reg()
173 ret = i2c_write_dt(&config->bus, buf, sizeof(buf)); in ads1x1x_write_reg()
176 LOG_ERR("ADS1X1X[0x%X]: error writing register 0x%X (%d)", config->bus.addr, in ads1x1x_write_reg()
202 struct ads1x1x_data *data = dev->data; in ads1x1x_acq_time_to_dr()
203 const struct ads1x1x_config *ads_config = dev->config; in ads1x1x_acq_time_to_dr()
204 const uint32_t *odr_delay = ads_config->odr_delay; in ads1x1x_acq_time_to_dr()
206 int odr = -EINVAL; in ads1x1x_acq_time_to_dr()
215 return -EINVAL; in ads1x1x_acq_time_to_dr()
260 /* As per the datasheet, 25us is needed to wake-up from power down mode in ads1x1x_acq_time_to_dr()
263 data->ready_time = K_USEC(odr_delay_us); in ads1x1x_acq_time_to_dr()
271 struct ads1x1x_data *data = dev->data; in ads1x1x_wait_data_ready()
273 k_sleep(data->ready_time); in ads1x1x_wait_data_ready()
295 const struct ads1x1x_config *ads_config = dev->config; in ads1x1x_channel_setup()
296 struct ads1x1x_data *data = dev->data; in ads1x1x_channel_setup()
300 if (channel_cfg->channel_id != 0) { in ads1x1x_channel_setup()
301 LOG_ERR("unsupported channel id '%d'", channel_cfg->channel_id); in ads1x1x_channel_setup()
302 return -ENOTSUP; in ads1x1x_channel_setup()
305 if (channel_cfg->reference != ADC_REF_INTERNAL) { in ads1x1x_channel_setup()
306 LOG_ERR("unsupported channel reference type '%d'", channel_cfg->reference); in ads1x1x_channel_setup()
307 return -ENOTSUP; in ads1x1x_channel_setup()
310 if (ads_config->multiplexer) { in ads1x1x_channel_setup()
312 if (channel_cfg->differential) { in ads1x1x_channel_setup()
313 if (channel_cfg->input_positive == 0 && channel_cfg->input_negative == 1) { in ads1x1x_channel_setup()
315 } else if (channel_cfg->input_positive == 0 && in ads1x1x_channel_setup()
316 channel_cfg->input_negative == 3) { in ads1x1x_channel_setup()
318 } else if (channel_cfg->input_positive == 1 && in ads1x1x_channel_setup()
319 channel_cfg->input_negative == 3) { in ads1x1x_channel_setup()
321 } else if (channel_cfg->input_positive == 2 && in ads1x1x_channel_setup()
322 channel_cfg->input_negative == 3) { in ads1x1x_channel_setup()
326 channel_cfg->input_positive, channel_cfg->input_negative); in ads1x1x_channel_setup()
327 return -ENOTSUP; in ads1x1x_channel_setup()
330 if (channel_cfg->input_positive == 0) { in ads1x1x_channel_setup()
332 } else if (channel_cfg->input_positive == 1) { in ads1x1x_channel_setup()
334 } else if (channel_cfg->input_positive == 2) { in ads1x1x_channel_setup()
336 } else if (channel_cfg->input_positive == 3) { in ads1x1x_channel_setup()
340 channel_cfg->input_positive); in ads1x1x_channel_setup()
341 return -ENOTSUP; in ads1x1x_channel_setup()
346 if (!((channel_cfg->differential) && in ads1x1x_channel_setup()
347 (channel_cfg->input_positive == 0 && channel_cfg->input_negative == 1))) { in ads1x1x_channel_setup()
349 channel_cfg->input_positive, channel_cfg->input_negative); in ads1x1x_channel_setup()
350 return -ENOTSUP; in ads1x1x_channel_setup()
354 data->differential = channel_cfg->differential; in ads1x1x_channel_setup()
356 dr = ads1x1x_acq_time_to_dr(dev, channel_cfg->acquisition_time); in ads1x1x_channel_setup()
359 channel_cfg->acquisition_time); in ads1x1x_channel_setup()
360 return -ENOTSUP; in ads1x1x_channel_setup()
365 if (ads_config->pga) { in ads1x1x_channel_setup()
367 switch (channel_cfg->gain) { in ads1x1x_channel_setup()
387 LOG_ERR("unsupported channel gain '%d'", channel_cfg->gain); in ads1x1x_channel_setup()
388 return -ENOTSUP; in ads1x1x_channel_setup()
392 if (channel_cfg->gain != ADC_GAIN_1) { in ads1x1x_channel_setup()
393 LOG_ERR("unsupported channel gain '%d'", channel_cfg->gain); in ads1x1x_channel_setup()
394 return -ENOTSUP; in ads1x1x_channel_setup()
411 if (sequence->options) { in ads1x1x_validate_buffer_size()
412 needed *= (1 + sequence->options->extra_samplings); in ads1x1x_validate_buffer_size()
415 if (sequence->buffer_size < needed) { in ads1x1x_validate_buffer_size()
416 return -ENOMEM; in ads1x1x_validate_buffer_size()
424 const struct ads1x1x_config *config = dev->config; in ads1x1x_validate_sequence()
425 struct ads1x1x_data *data = dev->data; in ads1x1x_validate_sequence()
426 uint8_t resolution = data->differential ? config->resolution : config->resolution - 1; in ads1x1x_validate_sequence()
429 if (sequence->resolution != resolution) { in ads1x1x_validate_sequence()
430 LOG_ERR("unsupported resolution %d", sequence->resolution); in ads1x1x_validate_sequence()
431 return -ENOTSUP; in ads1x1x_validate_sequence()
434 if (sequence->channels != BIT(0)) { in ads1x1x_validate_sequence()
436 return -ENOTSUP; in ads1x1x_validate_sequence()
439 if (sequence->oversampling) { in ads1x1x_validate_sequence()
441 return -ENOTSUP; in ads1x1x_validate_sequence()
447 return -ENOTSUP; in ads1x1x_validate_sequence()
458 data->buffer = data->repeat_buffer; in adc_context_update_buffer_pointer()
467 data->repeat_buffer = data->buffer; in adc_context_start_sampling()
469 ret = ads1x1x_start_conversion(data->dev); in adc_context_start_sampling()
472 * sampling, return an immediate error (likely -EIO) rather in adc_context_start_sampling()
478 k_sem_give(&data->acq_sem); in adc_context_start_sampling()
484 struct ads1x1x_data *data = dev->data; in ads1x1x_adc_start_read()
491 data->buffer = sequence->buffer; in ads1x1x_adc_start_read()
493 adc_context_start_read(&data->ctx, sequence); in ads1x1x_adc_start_read()
495 return adc_context_wait_for_completion(&data->ctx); in ads1x1x_adc_start_read()
502 struct ads1x1x_data *data = dev->data; in ads1x1x_adc_read_async()
504 adc_context_lock(&data->ctx, async ? true : false, async); in ads1x1x_adc_read_async()
506 adc_context_release(&data->ctx, rc); in ads1x1x_adc_read_async()
514 struct ads1x1x_data *data = dev->data; in ads1x1x_adc_perform_read()
515 const struct ads1x1x_config *config = dev->config; in ads1x1x_adc_perform_read()
520 adc_context_complete(&data->ctx, rc); in ads1x1x_adc_perform_read()
528 *data->buffer++ = buf / (1 << (16 - config->resolution)); in ads1x1x_adc_perform_read()
530 adc_context_on_sampling_done(&data->ctx, dev); in ads1x1x_adc_perform_read()
542 struct ads1x1x_data *data = dev->data; in ads1x1x_acquisition_thread()
546 k_sem_take(&data->acq_sem, K_FOREVER); in ads1x1x_acquisition_thread()
551 adc_context_complete(&data->ctx, rc); in ads1x1x_acquisition_thread()
561 const struct ads1x1x_config *config = dev->config; in ads1x1x_init()
562 struct ads1x1x_data *data = dev->data; in ads1x1x_init()
564 data->dev = dev; in ads1x1x_init()
566 k_sem_init(&data->acq_sem, 0, 1); in ads1x1x_init()
568 if (!device_is_ready(config->bus.bus)) { in ads1x1x_init()
569 LOG_ERR("I2C bus %s not ready", config->bus.bus->name); in ads1x1x_init()
570 return -ENODEV; in ads1x1x_init()
574 k_thread_create(&data->thread, data->stack, K_THREAD_STACK_SIZEOF(data->stack), in ads1x1x_init()
579 adc_context_unlock_unconditionally(&data->ctx); in ads1x1x_init()
597 .bus = I2C_DT_SPEC_GET(DT_INST_ADS1X1X(n, t)), \
613 * A positive full-scale (+FS) input produces an output code of 7FFFh and a
614 * negative full-scale (–FS) input produces an output code of 8000h. Single
615 * ended signal measurements only only use the positive code range from
656 * A positive full-scale (+FS) input produces an output code of 7FFh and a
657 * negative full-scale (–FS) input produces an output code of 800h. Single
658 * ended signal measurements only only use the positive code range from