Lines Matching +full:alert +full:- +full:config

5  * SPDX-License-Identifier: Apache-2.0
85 /* +/-6.144V range = Gain 1/3 */
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 */
112 /* ALERT/RDY pin is low when active (default) */
114 /* ALERT/RDY pin is high when active */
119 /* Non-latching comparator (default) */
126 /* Assert ALERT/RDY after one conversions */
128 /* Assert ALERT/RDY after two conversions */
130 /* Assert ALERT/RDY after four conversions */
132 /* Disable the comparator and put ALERT/RDY in high state (default) */
169 const struct ads1x1x_config *config = dev->config; in ads1x1x_setup_rdy_pin() local
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()
183 const struct ads1x1x_config *config = dev->config; in ads1x1x_setup_rdy_interrupt() local
189 ret = gpio_pin_interrupt_configure_dt(&config->alert_rdy, flags); in ads1x1x_setup_rdy_interrupt()
199 const struct ads1x1x_config *config = dev->config; in ads1x1x_read_reg() local
203 ret = i2c_burst_read_dt(&config->bus, reg_addr, (uint8_t *)&reg_val, sizeof(reg_val)); in ads1x1x_read_reg()
205 LOG_ERR("ADS1X1X[0x%X]: error reading register 0x%X (%d)", config->bus.addr, in ads1x1x_read_reg()
217 const struct ads1x1x_config *config = dev->config; in ads1x1x_write_reg() local
224 ret = i2c_write_dt(&config->bus, buf, sizeof(buf)); in ads1x1x_write_reg()
227 LOG_ERR("ADS1X1X[0x%X]: error writing register 0x%X (%d)", config->bus.addr, in ads1x1x_write_reg()
238 uint16_t config; in ads1x1x_start_conversion() local
241 ret = ads1x1x_read_reg(dev, ADS1X1X_REG_CONFIG, &config); in ads1x1x_start_conversion()
245 config |= ADS1X1X_CONFIG_OS; in ads1x1x_start_conversion()
246 ret = ads1x1x_write_reg(dev, ADS1X1X_REG_CONFIG, config); in ads1x1x_start_conversion()
252 /* The ALERT/RDY pin can also be configured as a conversion ready
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
262 /* set to 1 to enable conversion ALERT/RDY */ in ads1x1x_enable_conv_ready_signal()
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()
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()
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() local
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()
399 config |= ADS1X1X_CONFIG_MUX(ADS1X15_CONFIG_MUX_DIFF_0_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()
402 config |= ADS1X1X_CONFIG_MUX(ADS1X15_CONFIG_MUX_DIFF_0_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()
405 config |= ADS1X1X_CONFIG_MUX(ADS1X15_CONFIG_MUX_DIFF_1_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()
408 config |= ADS1X1X_CONFIG_MUX(ADS1X15_CONFIG_MUX_DIFF_2_3); 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()
416 config |= ADS1X1X_CONFIG_MUX(ADS1X15_CONFIG_MUX_SINGLE_0); in ads1x1x_channel_setup()
417 } else if (channel_cfg->input_positive == 1) { in ads1x1x_channel_setup()
418 config |= ADS1X1X_CONFIG_MUX(ADS1X15_CONFIG_MUX_SINGLE_1); in ads1x1x_channel_setup()
419 } else if (channel_cfg->input_positive == 2) { in ads1x1x_channel_setup()
420 config |= ADS1X1X_CONFIG_MUX(ADS1X15_CONFIG_MUX_SINGLE_2); in ads1x1x_channel_setup()
421 } else if (channel_cfg->input_positive == 3) { in ads1x1x_channel_setup()
422 config |= ADS1X1X_CONFIG_MUX(ADS1X15_CONFIG_MUX_SINGLE_3); 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()
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()
444 channel_cfg->acquisition_time); in ads1x1x_channel_setup()
445 return -ENOTSUP; in ads1x1x_channel_setup()
448 config |= ADS1X1X_CONFIG_DR(dr); in ads1x1x_channel_setup()
450 if (ads_config->pga) { in ads1x1x_channel_setup()
452 switch (channel_cfg->gain) { in ads1x1x_channel_setup()
454 config |= ADS1X1X_CONFIG_PGA(ADS1X1X_CONFIG_PGA_6144); in ads1x1x_channel_setup()
457 config |= ADS1X1X_CONFIG_PGA(ADS1X1X_CONFIG_PGA_4096); in ads1x1x_channel_setup()
460 config |= ADS1X1X_CONFIG_PGA(ADS1X1X_CONFIG_PGA_2048); in ads1x1x_channel_setup()
463 config |= ADS1X1X_CONFIG_PGA(ADS1X1X_CONFIG_PGA_1024); in ads1x1x_channel_setup()
466 config |= ADS1X1X_CONFIG_PGA(ADS1X1X_CONFIG_PGA_512); in ads1x1x_channel_setup()
469 config |= ADS1X1X_CONFIG_PGA(ADS1X1X_CONFIG_PGA_256); 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()
484 config |= ADS1X1X_CONFIG_MODE; in ads1x1x_channel_setup()
487 config |= ADS1X1X_CONFIG_COMP_MODE; in ads1x1x_channel_setup()
489 return ads1x1x_write_reg(dev, ADS1X1X_REG_CONFIG, config); 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()
509 const struct ads1x1x_config *config = dev->config; in ads1x1x_validate_sequence() local
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()
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()
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()
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()
580 data->buffer = sequence->buffer; in ads1x1x_adc_start_read()
583 const struct ads1x1x_config *config = dev->config; in ads1x1x_adc_start_read() local
585 if (config->alert_rdy.port) { in ads1x1x_adc_start_read()
588 LOG_ERR("Could not configure GPIO Alert/RDY"); in ads1x1x_adc_start_read()
593 LOG_ERR("Could not configure Alert/RDY interrupt"); 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() local
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()
661 adc_context_complete(&data->ctx, rc); in ads1x1x_acquisition_thread()
676 dev = data->dev; in ads1x1x_work_fn()
687 const struct ads1x1x_config *config; in ads1x1x_conv_ready_cb() local
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()
708 k_work_submit(&data->work); in ads1x1x_conv_ready_cb()
713 const struct ads1x1x_config *config = dev->config; in ads1x1x_init_interrupt() local
714 struct ads1x1x_data *data = dev->data; in ads1x1x_init_interrupt()
720 LOG_ERR("Could disable the alert/rdy gpio pin."); in ads1x1x_init_interrupt()
725 LOG_ERR("Could disable the alert/rdy interrupts."); 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()
741 LOG_ERR("failed to configure ALERT/RDY pin (err=%d)", rc); in ads1x1x_init_interrupt()
751 const struct ads1x1x_config *config = dev->config; in ads1x1x_init() local
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()
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()
781 k_thread_name_set(data->tid, "adc_ads1x1x"); in ads1x1x_init()
784 adc_context_unlock_unconditionally(&data->ctx); in ads1x1x_init()
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
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