Lines Matching +full:0 +full:x00 +full:- +full:positive

5  * SPDX-License-Identifier: Apache-2.0
45 ADS1X1X_REG_CONV = 0x00,
46 ADS1X1X_REG_CONFIG = 0x01,
47 ADS1X1X_REG_LO_THRESH = 0x02,
48 ADS1X1X_REG_HI_THRESH = 0x03,
52 ADS1X15_CONFIG_MUX_DIFF_0_1 = 0,
65 ADS1X1X_CONFIG_DR_8_128 = 0,
85 /* +/-6.144V range = Gain 1/3 */
86 ADS1X1X_CONFIG_PGA_6144 = 0,
87 /* +/-4.096V range = Gain 1/2 */
89 /* +/-2.048V range = Gain 1 (default) */
91 /* +/-1.024V range = Gain 2 */
93 /* +/-0.512V range = Gain 4 */
95 /* +/-0.256V range = Gain 8 */
100 ADS1X1X_CONFIG_MODE_CONTINUOUS = 0,
106 ADS1X1X_CONFIG_COMP_MODE_TRADITIONAL = 0,
113 ADS1X1X_CONFIG_COMP_POLARITY_ACTIVE_LO = 0,
119 /* Non-latching comparator (default) */
120 ADS1X1X_CONFIG_COMP_NON_LATCHING = 0,
127 ADS1X1X_CONFIG_COMP_QUEUE_1 = 0,
169 const struct ads1x1x_config *config = dev->config; in ads1x1x_setup_rdy_pin()
171 ? GPIO_INPUT | config->alert_rdy.dt_flags in ads1x1x_setup_rdy_pin()
174 ret = gpio_pin_configure_dt(&config->alert_rdy, flags); in ads1x1x_setup_rdy_pin()
175 if (ret < 0) { in ads1x1x_setup_rdy_pin()
183 const struct ads1x1x_config *config = dev->config; in ads1x1x_setup_rdy_interrupt()
189 ret = gpio_pin_interrupt_configure_dt(&config->alert_rdy, flags); in ads1x1x_setup_rdy_interrupt()
190 if (ret < 0) { in ads1x1x_setup_rdy_interrupt()
199 const struct ads1x1x_config *config = dev->config; in ads1x1x_read_reg()
203 ret = i2c_burst_read_dt(&config->bus, reg_addr, (uint8_t *)&reg_val, sizeof(reg_val)); in ads1x1x_read_reg()
204 if (ret != 0) { in ads1x1x_read_reg()
205 LOG_ERR("ADS1X1X[0x%X]: error reading register 0x%X (%d)", config->bus.addr, in ads1x1x_read_reg()
212 return 0; in ads1x1x_read_reg()
217 const struct ads1x1x_config *config = dev->config; in ads1x1x_write_reg()
221 buf[0] = reg_addr; in ads1x1x_write_reg()
224 ret = i2c_write_dt(&config->bus, buf, sizeof(buf)); in ads1x1x_write_reg()
226 if (ret != 0) { in ads1x1x_write_reg()
227 LOG_ERR("ADS1X1X[0x%X]: error writing register 0x%X (%d)", config->bus.addr, in ads1x1x_write_reg()
232 return 0; in ads1x1x_write_reg()
242 if (ret != 0) { in ads1x1x_start_conversion()
253 * pin. Set the most-significant bit of the Hi_thresh register to 1
254 * and the most-significant bit of Lo_thresh register to 0 to enable
273 /* set to 0 to enable conversion ALERT/RDY */ in ads1x1x_enable_conv_ready_signal()
287 struct ads1x1x_data *data = dev->data; in ads1x1x_acq_time_to_dr()
288 const struct ads1x1x_config *ads_config = dev->config; in ads1x1x_acq_time_to_dr()
289 const uint32_t *odr_delay = ads_config->odr_delay; in ads1x1x_acq_time_to_dr()
290 uint32_t odr_delay_us = 0; in ads1x1x_acq_time_to_dr()
291 int odr = -EINVAL; in ads1x1x_acq_time_to_dr()
300 return -EINVAL; in ads1x1x_acq_time_to_dr()
345 /* As per the datasheet, 25us is needed to wake-up from power down mode in ads1x1x_acq_time_to_dr()
348 data->ready_time = K_USEC(odr_delay_us); in ads1x1x_acq_time_to_dr()
356 struct ads1x1x_data *data = dev->data; in ads1x1x_wait_data_ready()
358 k_sleep(data->ready_time); in ads1x1x_wait_data_ready()
359 uint16_t status = 0; in ads1x1x_wait_data_ready()
362 if (rc != 0) { in ads1x1x_wait_data_ready()
369 if (rc != 0) { in ads1x1x_wait_data_ready()
380 const struct ads1x1x_config *ads_config = dev->config; in ads1x1x_channel_setup()
381 struct ads1x1x_data *data = dev->data; in ads1x1x_channel_setup()
382 uint16_t config = 0; in ads1x1x_channel_setup()
383 int dr = 0; in ads1x1x_channel_setup()
385 if (channel_cfg->channel_id != 0) { in ads1x1x_channel_setup()
386 LOG_ERR("unsupported channel id '%d'", channel_cfg->channel_id); in ads1x1x_channel_setup()
387 return -ENOTSUP; in ads1x1x_channel_setup()
390 if (channel_cfg->reference != ADC_REF_INTERNAL) { in ads1x1x_channel_setup()
391 LOG_ERR("unsupported channel reference type '%d'", channel_cfg->reference); in ads1x1x_channel_setup()
392 return -ENOTSUP; in ads1x1x_channel_setup()
395 if (ads_config->multiplexer) { in ads1x1x_channel_setup()
397 if (channel_cfg->differential) { in ads1x1x_channel_setup()
398 if (channel_cfg->input_positive == 0 && channel_cfg->input_negative == 1) { in ads1x1x_channel_setup()
400 } else if (channel_cfg->input_positive == 0 && in ads1x1x_channel_setup()
401 channel_cfg->input_negative == 3) { in ads1x1x_channel_setup()
403 } else if (channel_cfg->input_positive == 1 && in ads1x1x_channel_setup()
404 channel_cfg->input_negative == 3) { in ads1x1x_channel_setup()
406 } else if (channel_cfg->input_positive == 2 && in ads1x1x_channel_setup()
407 channel_cfg->input_negative == 3) { in ads1x1x_channel_setup()
410 LOG_ERR("unsupported input positive '%d' and input negative '%d'", in ads1x1x_channel_setup()
411 channel_cfg->input_positive, channel_cfg->input_negative); in ads1x1x_channel_setup()
412 return -ENOTSUP; in ads1x1x_channel_setup()
415 if (channel_cfg->input_positive == 0) { in ads1x1x_channel_setup()
417 } else if (channel_cfg->input_positive == 1) { in ads1x1x_channel_setup()
419 } else if (channel_cfg->input_positive == 2) { in ads1x1x_channel_setup()
421 } else if (channel_cfg->input_positive == 3) { in ads1x1x_channel_setup()
424 LOG_ERR("unsupported input positive '%d'", in ads1x1x_channel_setup()
425 channel_cfg->input_positive); in ads1x1x_channel_setup()
426 return -ENOTSUP; in ads1x1x_channel_setup()
431 if (!((channel_cfg->differential) && in ads1x1x_channel_setup()
432 (channel_cfg->input_positive == 0 && channel_cfg->input_negative == 1))) { in ads1x1x_channel_setup()
433 LOG_ERR("unsupported input positive '%d' and input negative '%d'", in ads1x1x_channel_setup()
434 channel_cfg->input_positive, channel_cfg->input_negative); in ads1x1x_channel_setup()
435 return -ENOTSUP; in ads1x1x_channel_setup()
439 data->differential = channel_cfg->differential; in ads1x1x_channel_setup()
441 dr = ads1x1x_acq_time_to_dr(dev, channel_cfg->acquisition_time); in ads1x1x_channel_setup()
442 if (dr < 0) { in ads1x1x_channel_setup()
443 LOG_ERR("unsupported channel acquisition time 0x%02x", in ads1x1x_channel_setup()
444 channel_cfg->acquisition_time); in ads1x1x_channel_setup()
445 return -ENOTSUP; in ads1x1x_channel_setup()
450 if (ads_config->pga) { in ads1x1x_channel_setup()
452 switch (channel_cfg->gain) { in ads1x1x_channel_setup()
472 LOG_ERR("unsupported channel gain '%d'", channel_cfg->gain); in ads1x1x_channel_setup()
473 return -ENOTSUP; in ads1x1x_channel_setup()
477 if (channel_cfg->gain != ADC_GAIN_1) { in ads1x1x_channel_setup()
478 LOG_ERR("unsupported channel gain '%d'", channel_cfg->gain); in ads1x1x_channel_setup()
479 return -ENOTSUP; in ads1x1x_channel_setup()
496 if (sequence->options) { in ads1x1x_validate_buffer_size()
497 needed *= (1 + sequence->options->extra_samplings); in ads1x1x_validate_buffer_size()
500 if (sequence->buffer_size < needed) { in ads1x1x_validate_buffer_size()
501 return -ENOMEM; in ads1x1x_validate_buffer_size()
504 return 0; in ads1x1x_validate_buffer_size()
509 const struct ads1x1x_config *config = dev->config; in ads1x1x_validate_sequence()
510 struct ads1x1x_data *data = dev->data; in ads1x1x_validate_sequence()
511 uint8_t resolution = data->differential ? config->resolution : config->resolution - 1; in ads1x1x_validate_sequence()
514 if (sequence->resolution != resolution) { in ads1x1x_validate_sequence()
515 LOG_ERR("unsupported resolution %d", sequence->resolution); in ads1x1x_validate_sequence()
516 return -ENOTSUP; in ads1x1x_validate_sequence()
519 if (sequence->channels != BIT(0)) { in ads1x1x_validate_sequence()
520 LOG_ERR("only channel 0 supported"); in ads1x1x_validate_sequence()
521 return -ENOTSUP; in ads1x1x_validate_sequence()
524 if (sequence->oversampling) { in ads1x1x_validate_sequence()
526 return -ENOTSUP; in ads1x1x_validate_sequence()
532 return -ENOTSUP; in ads1x1x_validate_sequence()
535 return 0; in ads1x1x_validate_sequence()
543 data->buffer = data->repeat_buffer; in adc_context_update_buffer_pointer()
552 data->repeat_buffer = data->buffer; in adc_context_start_sampling()
554 ret = ads1x1x_start_conversion(data->dev); in adc_context_start_sampling()
555 if (ret != 0) { in adc_context_start_sampling()
557 * sampling, return an immediate error (likely -EIO) rather in adc_context_start_sampling()
565 if (data->tid) { in adc_context_start_sampling()
566 k_sem_give(&data->acq_sem); in adc_context_start_sampling()
573 struct ads1x1x_data *data = dev->data; in ads1x1x_adc_start_read()
576 if (rc != 0) { in ads1x1x_adc_start_read()
580 data->buffer = sequence->buffer; in ads1x1x_adc_start_read()
583 const struct ads1x1x_config *config = dev->config; in ads1x1x_adc_start_read()
585 if (config->alert_rdy.port) { in ads1x1x_adc_start_read()
587 if (rc < 0) { in ads1x1x_adc_start_read()
592 if (rc < 0) { in ads1x1x_adc_start_read()
599 adc_context_start_read(&data->ctx, sequence); in ads1x1x_adc_start_read()
601 return adc_context_wait_for_completion(&data->ctx); in ads1x1x_adc_start_read()
608 struct ads1x1x_data *data = dev->data; in ads1x1x_adc_read_async()
610 adc_context_lock(&data->ctx, async ? true : false, async); in ads1x1x_adc_read_async()
612 adc_context_release(&data->ctx, rc); in ads1x1x_adc_read_async()
620 struct ads1x1x_data *data = dev->data; in ads1x1x_adc_perform_read()
621 const struct ads1x1x_config *config = dev->config; in ads1x1x_adc_perform_read()
625 if (rc != 0) { in ads1x1x_adc_perform_read()
626 adc_context_complete(&data->ctx, rc); in ads1x1x_adc_perform_read()
634 *data->buffer++ = buf / (1 << (16 - config->resolution)); in ads1x1x_adc_perform_read()
636 adc_context_on_sampling_done(&data->ctx, dev); in ads1x1x_adc_perform_read()
652 struct ads1x1x_data *data = dev->data; in ads1x1x_acquisition_thread()
656 k_sem_take(&data->acq_sem, K_FOREVER); in ads1x1x_acquisition_thread()
659 if (rc != 0) { in ads1x1x_acquisition_thread()
661 adc_context_complete(&data->ctx, rc); in ads1x1x_acquisition_thread()
676 dev = data->dev; in ads1x1x_work_fn()
693 dev = data->dev; in ads1x1x_conv_ready_cb()
694 config = dev->config; in ads1x1x_conv_ready_cb()
696 if (config->alert_rdy.port) { in ads1x1x_conv_ready_cb()
698 if (rc < 0) { in ads1x1x_conv_ready_cb()
702 if (rc < 0) { in ads1x1x_conv_ready_cb()
708 k_work_submit(&data->work); in ads1x1x_conv_ready_cb()
713 const struct ads1x1x_config *config = dev->config; in ads1x1x_init_interrupt()
714 struct ads1x1x_data *data = dev->data; in ads1x1x_init_interrupt()
719 if (rc < 0) { in ads1x1x_init_interrupt()
724 if (rc < 0) { in ads1x1x_init_interrupt()
728 gpio_init_callback(&data->gpio_cb, ads1x1x_conv_ready_cb, in ads1x1x_init_interrupt()
729 BIT(config->alert_rdy.pin)); in ads1x1x_init_interrupt()
730 rc = gpio_add_callback(config->alert_rdy.port, &data->gpio_cb); in ads1x1x_init_interrupt()
733 return -rc; in ads1x1x_init_interrupt()
737 k_work_init(&data->work, ads1x1x_work_fn); in ads1x1x_init_interrupt()
745 return 0; in ads1x1x_init_interrupt()
751 const struct ads1x1x_config *config = dev->config; in ads1x1x_init()
752 struct ads1x1x_data *data = dev->data; in ads1x1x_init()
754 data->dev = dev; in ads1x1x_init()
756 k_sem_init(&data->acq_sem, 0, 1); in ads1x1x_init()
758 if (!device_is_ready(config->bus.bus)) { in ads1x1x_init()
759 LOG_ERR("I2C bus %s not ready", config->bus.bus->name); in ads1x1x_init()
760 return -ENODEV; in ads1x1x_init()
764 if (config->alert_rdy.port) { in ads1x1x_init()
765 if (ads1x1x_init_interrupt(dev) < 0) { in ads1x1x_init()
767 return -EIO; in ads1x1x_init()
774 data->tid = in ads1x1x_init()
775 k_thread_create(&data->thread, data->stack, in ads1x1x_init()
776 K_THREAD_STACK_SIZEOF(data->stack), in ads1x1x_init()
780 0, K_NO_WAIT); in ads1x1x_init()
781 k_thread_name_set(data->tid, "adc_ads1x1x"); in ads1x1x_init()
784 adc_context_unlock_unconditionally(&data->ctx); in ads1x1x_init()
786 return 0; in ads1x1x_init()
801 .alert_rdy = GPIO_DT_SPEC_INST_GET_OR(n, alert_rdy_gpios, {0}), \
826 * A positive full-scale (+FS) input produces an output code of 7FFFh and a
827 * negative full-scale (–FS) input produces an output code of 8000h. Single
828 * ended signal measurements only use the positive code range from
869 * A positive full-scale (+FS) input produces an output code of 7FFh and a
870 * negative full-scale (–FS) input produces an output code of 800h. Single
871 * ended signal measurements only use the positive code range from