Lines Matching +full:vbias +full:- +full:pins

4  * SPDX-License-Identifier: Apache-2.0
12 #include <zephyr/dt-bindings/adc/ads1x4s0x_adc.h>
95 FIELD_GET(GENMASK(pos + length - 1, pos), value)
97 target &= ~GENMASK(pos + length - 1, pos); \
98 target |= FIELD_PREP(GENMASK(pos + length - 1, pos), value)
366 * - AIN0 as positive input
367 * - AIN1 as negative input
373 * - disable reference monitor
374 * - enable positive reference buffer
375 * - disable negative reference buffer
376 * - use internal reference
377 * - enable internal voltage reference
386 * - disable global chop
387 * - use internal oscillator
388 * - single shot conversion mode
389 * - low latency filter
390 * - 20 samples per second
399 * - delay of 14*t_mod
400 * - disable gain
401 * - gain 1
408 * - disable PGA output rail flag
409 * - low-side power switch
410 * - IDAC off
417 * - disconnect IDAC1
418 * - disconnect IDAC2
457 uint32_t pins) in ads1x4s0x_data_ready_handler() argument
460 ARG_UNUSED(pins); in ads1x4s0x_data_ready_handler()
465 k_sem_give(&data->data_ready_signal); in ads1x4s0x_data_ready_handler()
471 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_read_register()
495 int result = spi_transceive_dt(&config->bus, &tx, &rx); in ads1x4s0x_read_register()
498 LOG_ERR("%s: spi_transceive failed with error %i", dev->name, result); in ads1x4s0x_read_register()
503 LOG_DBG("%s: read from register 0x%02X value 0x%02X", dev->name, register_address, *value); in ads1x4s0x_read_register()
511 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_write_register()
527 LOG_DBG("%s: writing to register 0x%02X value 0x%02X", dev->name, register_address, value); in ads1x4s0x_write_register()
528 int result = spi_write_dt(&config->bus, &tx); in ads1x4s0x_write_register()
531 LOG_ERR("%s: spi_write failed with error %i", dev->name, result); in ads1x4s0x_write_register()
542 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_write_multiple_registers()
560 LOG_WRN("%s: ignoring the command to write 0 registers", dev->name); in ads1x4s0x_write_multiple_registers()
561 return -EINVAL; in ads1x4s0x_write_multiple_registers()
565 buffer_tx[1] = count - 1; in ads1x4s0x_write_multiple_registers()
572 __ASSERT(register_addresses[i - 1] + 1 == register_addresses[i], in ads1x4s0x_write_multiple_registers()
576 int result = spi_write_dt(&config->bus, &tx); in ads1x4s0x_write_multiple_registers()
579 LOG_ERR("%s: spi_write failed with error %i", dev->name, result); in ads1x4s0x_write_multiple_registers()
588 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_send_command()
601 LOG_DBG("%s: sending command 0x%02X", dev->name, command); in ads1x4s0x_send_command()
602 int result = spi_write_dt(&config->bus, &tx); in ads1x4s0x_send_command()
605 LOG_ERR("%s: spi_write failed with error %i", dev->name, result); in ads1x4s0x_send_command()
615 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_channel_setup()
623 uint8_t vbias = 0; in ads1x4s0x_channel_setup() local
628 uint16_t acquisition_time_value = ADC_ACQ_TIME_VALUE(channel_cfg->acquisition_time); in ads1x4s0x_channel_setup()
629 uint16_t acquisition_time_unit = ADC_ACQ_TIME_UNIT(channel_cfg->acquisition_time); in ads1x4s0x_channel_setup()
638 if (channel_cfg->channel_id != 0) { in ads1x4s0x_channel_setup()
639 LOG_ERR("%s: only one channel is supported", dev->name); in ads1x4s0x_channel_setup()
640 return -EINVAL; in ads1x4s0x_channel_setup()
648 if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT && in ads1x4s0x_channel_setup()
650 LOG_ERR("%s: invalid acquisition time %i", dev->name, in ads1x4s0x_channel_setup()
651 channel_cfg->acquisition_time); in ads1x4s0x_channel_setup()
652 return -EINVAL; in ads1x4s0x_channel_setup()
655 if (channel_cfg->acquisition_time == ADC_ACQ_TIME_DEFAULT) { in ads1x4s0x_channel_setup()
661 switch (channel_cfg->reference) { in ads1x4s0x_channel_setup()
687 LOG_ERR("%s: reference %i is not supported", dev->name, channel_cfg->reference); in ads1x4s0x_channel_setup()
688 return -EINVAL; in ads1x4s0x_channel_setup()
691 if (channel_cfg->differential) { in ads1x4s0x_channel_setup()
692 LOG_DBG("%s: configuring channel for a differential measurement from the pins (p, " in ads1x4s0x_channel_setup()
694 dev->name, channel_cfg->input_positive, channel_cfg->input_negative); in ads1x4s0x_channel_setup()
695 if (channel_cfg->input_positive >= config->channels && in ads1x4s0x_channel_setup()
696 channel_cfg->input_positive != ADS1X4S0X_INPUT_SELECTION_AINCOM) { in ads1x4s0x_channel_setup()
697 LOG_ERR("%s: positive channel input %i is invalid", dev->name, in ads1x4s0x_channel_setup()
698 channel_cfg->input_positive); in ads1x4s0x_channel_setup()
699 return -EINVAL; in ads1x4s0x_channel_setup()
702 if (channel_cfg->input_negative >= config->channels && in ads1x4s0x_channel_setup()
703 channel_cfg->input_negative != ADS1X4S0X_INPUT_SELECTION_AINCOM) { in ads1x4s0x_channel_setup()
704 LOG_ERR("%s: negative channel input %i is invalid", dev->name, in ads1x4s0x_channel_setup()
705 channel_cfg->input_negative); in ads1x4s0x_channel_setup()
706 return -EINVAL; in ads1x4s0x_channel_setup()
709 if (channel_cfg->input_positive == channel_cfg->input_negative) { in ads1x4s0x_channel_setup()
711 dev->name); in ads1x4s0x_channel_setup()
712 return -EINVAL; in ads1x4s0x_channel_setup()
715 ADS1X4S0X_REGISTER_INPMUX_MUXP_SET(input_mux, channel_cfg->input_positive); in ads1x4s0x_channel_setup()
716 ADS1X4S0X_REGISTER_INPMUX_MUXN_SET(input_mux, channel_cfg->input_negative); in ads1x4s0x_channel_setup()
717 pin_selections[0] = channel_cfg->input_positive; in ads1x4s0x_channel_setup()
718 pin_selections[1] = channel_cfg->input_negative; in ads1x4s0x_channel_setup()
721 dev->name, channel_cfg->input_positive); in ads1x4s0x_channel_setup()
722 if (channel_cfg->input_positive >= config->channels && in ads1x4s0x_channel_setup()
723 channel_cfg->input_positive != ADS1X4S0X_INPUT_SELECTION_AINCOM) { in ads1x4s0x_channel_setup()
724 LOG_ERR("%s: channel input %i is invalid", dev->name, in ads1x4s0x_channel_setup()
725 channel_cfg->input_positive); in ads1x4s0x_channel_setup()
726 return -EINVAL; in ads1x4s0x_channel_setup()
729 ADS1X4S0X_REGISTER_INPMUX_MUXP_SET(input_mux, channel_cfg->input_positive); in ads1x4s0x_channel_setup()
731 pin_selections[0] = channel_cfg->input_positive; in ads1x4s0x_channel_setup()
735 switch (channel_cfg->gain) { in ads1x4s0x_channel_setup()
762 LOG_ERR("%s: gain value %i not supported", dev->name, channel_cfg->gain); in ads1x4s0x_channel_setup()
763 return -EINVAL; in ads1x4s0x_channel_setup()
766 if (channel_cfg->gain != ADC_GAIN_1) { in ads1x4s0x_channel_setup()
771 switch (config->idac_current) { in ads1x4s0x_channel_setup()
803 LOG_ERR("%s: IDAC magnitude %i not supported", dev->name, config->idac_current); in ads1x4s0x_channel_setup()
804 return -EINVAL; in ads1x4s0x_channel_setup()
807 if (channel_cfg->current_source_pin_set) { in ads1x4s0x_channel_setup()
808 LOG_DBG("%s: current source pin set to %i and %i", dev->name, in ads1x4s0x_channel_setup()
809 channel_cfg->current_source_pin[0], channel_cfg->current_source_pin[1]); in ads1x4s0x_channel_setup()
810 if (channel_cfg->current_source_pin[0] > 0b1111) { in ads1x4s0x_channel_setup()
811 LOG_ERR("%s: invalid selection %i for I1MUX", dev->name, in ads1x4s0x_channel_setup()
812 channel_cfg->current_source_pin[0]); in ads1x4s0x_channel_setup()
813 return -EINVAL; in ads1x4s0x_channel_setup()
816 if (channel_cfg->current_source_pin[1] > 0b1111) { in ads1x4s0x_channel_setup()
817 LOG_ERR("%s: invalid selection %i for I2MUX", dev->name, in ads1x4s0x_channel_setup()
818 channel_cfg->current_source_pin[1]); in ads1x4s0x_channel_setup()
819 return -EINVAL; in ads1x4s0x_channel_setup()
822 ADS1X4S0X_REGISTER_IDACMUX_I1MUX_SET(idac_mux, channel_cfg->current_source_pin[0]); in ads1x4s0x_channel_setup()
823 ADS1X4S0X_REGISTER_IDACMUX_I2MUX_SET(idac_mux, channel_cfg->current_source_pin[1]); in ads1x4s0x_channel_setup()
824 pin_selections[2] = channel_cfg->current_source_pin[0]; in ads1x4s0x_channel_setup()
825 pin_selections[3] = channel_cfg->current_source_pin[1]; in ads1x4s0x_channel_setup()
828 LOG_DBG("%s: current source pins not set", dev->name); in ads1x4s0x_channel_setup()
843 LOG_ERR("%s: pins for inputs and current sources must be different", in ads1x4s0x_channel_setup()
844 dev->name); in ads1x4s0x_channel_setup()
845 return -EINVAL; in ads1x4s0x_channel_setup()
850 ADS1X4S0X_REGISTER_VBIAS_VB_LEVEL_SET(vbias, config->vbias_level); in ads1x4s0x_channel_setup()
852 if ((channel_cfg->vbias_pins & in ads1x4s0x_channel_setup()
854 LOG_ERR("%s: invalid VBIAS pin selection 0x%08X", dev->name, in ads1x4s0x_channel_setup()
855 channel_cfg->vbias_pins); in ads1x4s0x_channel_setup()
856 return -EINVAL; in ads1x4s0x_channel_setup()
859 vbias |= channel_cfg->vbias_pins; in ads1x4s0x_channel_setup()
875 values[6] = vbias; in ads1x4s0x_channel_setup()
882 LOG_ERR("%s: unable to configure registers", dev->name); in ads1x4s0x_channel_setup()
892 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_validate_buffer_size()
895 needed = (config->resolution > 16) ? sizeof(int32_t) : sizeof(int16_t); in ads1x4s0x_validate_buffer_size()
897 if (sequence->options) { in ads1x4s0x_validate_buffer_size()
898 needed *= (1 + sequence->options->extra_samplings); in ads1x4s0x_validate_buffer_size()
901 if (sequence->buffer_size < needed) { in ads1x4s0x_validate_buffer_size()
902 return -ENOMEM; in ads1x4s0x_validate_buffer_size()
911 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_validate_sequence()
913 if (sequence->resolution != config->resolution) { in ads1x4s0x_validate_sequence()
914 LOG_ERR("%s: invalid resolution", dev->name); in ads1x4s0x_validate_sequence()
915 return -EINVAL; in ads1x4s0x_validate_sequence()
918 if (sequence->channels != BIT(0)) { in ads1x4s0x_validate_sequence()
919 LOG_ERR("%s: invalid channel", dev->name); in ads1x4s0x_validate_sequence()
920 return -EINVAL; in ads1x4s0x_validate_sequence()
923 if (sequence->oversampling) { in ads1x4s0x_validate_sequence()
924 LOG_ERR("%s: oversampling is not supported", dev->name); in ads1x4s0x_validate_sequence()
925 return -EINVAL; in ads1x4s0x_validate_sequence()
936 data->buffer = data->buffer_ptr; in adc_context_update_buffer_pointer()
944 data->buffer_ptr = data->buffer; in adc_context_start_sampling()
945 k_sem_give(&data->acquire_signal); in adc_context_start_sampling()
952 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_adc_start_read()
957 LOG_ERR("%s: sequence validation failed", dev->name); in ads1x4s0x_adc_start_read()
961 data->buffer = sequence->buffer; in ads1x4s0x_adc_start_read()
963 adc_context_start_read(&data->ctx, sequence); in ads1x4s0x_adc_start_read()
966 result = adc_context_wait_for_completion(&data->ctx); in ads1x4s0x_adc_start_read()
974 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_send_start_read()
977 if (config->gpio_start_sync.port == 0) { in ads1x4s0x_send_start_read()
980 LOG_ERR("%s: unable to send START/SYNC command", dev->name); in ads1x4s0x_send_start_read()
984 result = gpio_pin_set_dt(&config->gpio_start_sync, 1); in ads1x4s0x_send_start_read()
987 LOG_ERR("%s: unable to start ADC operation", dev->name); in ads1x4s0x_send_start_read()
994 result = gpio_pin_set_dt(&config->gpio_start_sync, 0); in ads1x4s0x_send_start_read()
997 LOG_ERR("%s: unable to start ADC operation", dev->name); in ads1x4s0x_send_start_read()
1007 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_wait_data_ready()
1009 return k_sem_take(&data->data_ready_signal, ADC_CONTEXT_WAIT_FOR_COMPLETION_TIMEOUT); in ads1x4s0x_wait_data_ready()
1015 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_read_sample_16()
1037 int result = spi_transceive_dt(&config->bus, &tx, &rx); in ads1x4s0x_read_sample_16()
1040 LOG_ERR("%s: spi_transceive failed with error %i", dev->name, result); in ads1x4s0x_read_sample_16()
1045 LOG_DBG("%s: read ADC sample %i", dev->name, *buffer); in ads1x4s0x_read_sample_16()
1054 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_read_sample_24()
1076 int result = spi_transceive_dt(&config->bus, &tx, &rx); in ads1x4s0x_read_sample_24()
1079 LOG_ERR("%s: spi_transceive failed with error %i", dev->name, result); in ads1x4s0x_read_sample_24()
1085 LOG_DBG("%s: read ADC sample 0x%02X%02X%02X", dev->name, *(buffer_rx + 1), *(buffer_rx + 2), in ads1x4s0x_read_sample_24()
1095 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_adc_perform_read()
1096 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_adc_perform_read()
1097 void *buffer = data->buffer; in ads1x4s0x_adc_perform_read()
1099 k_sem_take(&data->acquire_signal, K_FOREVER); in ads1x4s0x_adc_perform_read()
1100 k_sem_reset(&data->data_ready_signal); in ads1x4s0x_adc_perform_read()
1104 LOG_ERR("%s: unable to start ADC conversion", dev->name); in ads1x4s0x_adc_perform_read()
1105 adc_context_complete(&data->ctx, result); in ads1x4s0x_adc_perform_read()
1111 LOG_ERR("%s: waiting for data to be ready failed", dev->name); in ads1x4s0x_adc_perform_read()
1112 adc_context_complete(&data->ctx, result); in ads1x4s0x_adc_perform_read()
1117 if (config->resolution == 24) { in ads1x4s0x_adc_perform_read()
1118 result = ads1x4s0x_read_sample_24(dev, (int32_t *)data->buffer); in ads1x4s0x_adc_perform_read()
1122 adc_context_on_sampling_done(&data->ctx, dev); in ads1x4s0x_adc_perform_read()
1130 if (config->resolution == 16) { in ads1x4s0x_adc_perform_read()
1131 result = ads1x4s0x_read_sample_16(dev, (int16_t *)data->buffer); in ads1x4s0x_adc_perform_read()
1135 adc_context_on_sampling_done(&data->ctx, dev); in ads1x4s0x_adc_perform_read()
1142 LOG_ERR("%s: reading sample failed", dev->name); in ads1x4s0x_adc_perform_read()
1143 adc_context_complete(&data->ctx, result); in ads1x4s0x_adc_perform_read()
1152 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_adc_read_async()
1154 adc_context_lock(&data->ctx, true, async); in ads1x4s0x_adc_read_async()
1156 adc_context_release(&data->ctx, result); in ads1x4s0x_adc_read_async()
1164 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_read()
1166 adc_context_lock(&data->ctx, false, NULL); in ads1x4s0x_read()
1168 adc_context_release(&data->ctx, result); in ads1x4s0x_read()
1177 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_read()
1179 adc_context_lock(&data->ctx, false, NULL); in ads1x4s0x_read()
1182 while (result == 0 && k_sem_take(&data->ctx.sync, K_NO_WAIT) != 0) { in ads1x4s0x_read()
1186 adc_context_release(&data->ctx, result); in ads1x4s0x_read()
1208 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_write_config()
1214 ADS1X4S0X_REGISTER_GPIOCON_CON_SET(gpio_con, data->gpio_enabled); in ads1x4s0x_gpio_write_config()
1215 ADS1X4S0X_REGISTER_GPIODAT_DAT_SET(gpio_dat, data->gpio_value); in ads1x4s0x_gpio_write_config()
1216 ADS1X4S0X_REGISTER_GPIODAT_DIR_SET(gpio_dat, data->gpio_direction); in ads1x4s0x_gpio_write_config()
1228 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_write_value()
1231 ADS1X4S0X_REGISTER_GPIODAT_DAT_SET(gpio_dat, data->gpio_value); in ads1x4s0x_gpio_write_value()
1232 ADS1X4S0X_REGISTER_GPIODAT_DIR_SET(gpio_dat, data->gpio_direction); in ads1x4s0x_gpio_write_value()
1239 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_set_output()
1243 LOG_ERR("%s: invalid pin %i", dev->name, pin); in ads1x4s0x_gpio_set_output()
1244 return -EINVAL; in ads1x4s0x_gpio_set_output()
1247 k_mutex_lock(&data->gpio_lock, K_FOREVER); in ads1x4s0x_gpio_set_output()
1249 data->gpio_enabled |= BIT(pin); in ads1x4s0x_gpio_set_output()
1250 data->gpio_direction &= ~BIT(pin); in ads1x4s0x_gpio_set_output()
1253 data->gpio_value |= BIT(pin); in ads1x4s0x_gpio_set_output()
1255 data->gpio_value &= ~BIT(pin); in ads1x4s0x_gpio_set_output()
1260 k_mutex_unlock(&data->gpio_lock); in ads1x4s0x_gpio_set_output()
1267 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_set_input()
1271 LOG_ERR("%s: invalid pin %i", dev->name, pin); in ads1x4s0x_gpio_set_input()
1272 return -EINVAL; in ads1x4s0x_gpio_set_input()
1275 k_mutex_lock(&data->gpio_lock, K_FOREVER); in ads1x4s0x_gpio_set_input()
1277 data->gpio_enabled |= BIT(pin); in ads1x4s0x_gpio_set_input()
1278 data->gpio_direction |= BIT(pin); in ads1x4s0x_gpio_set_input()
1279 data->gpio_value &= ~BIT(pin); in ads1x4s0x_gpio_set_input()
1283 k_mutex_unlock(&data->gpio_lock); in ads1x4s0x_gpio_set_input()
1290 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_deconfigure()
1294 LOG_ERR("%s: invalid pin %i", dev->name, pin); in ads1x4s0x_gpio_deconfigure()
1295 return -EINVAL; in ads1x4s0x_gpio_deconfigure()
1298 k_mutex_lock(&data->gpio_lock, K_FOREVER); in ads1x4s0x_gpio_deconfigure()
1300 data->gpio_enabled &= ~BIT(pin); in ads1x4s0x_gpio_deconfigure()
1301 data->gpio_direction |= BIT(pin); in ads1x4s0x_gpio_deconfigure()
1302 data->gpio_value &= ~BIT(pin); in ads1x4s0x_gpio_deconfigure()
1306 k_mutex_unlock(&data->gpio_lock); in ads1x4s0x_gpio_deconfigure()
1313 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_set_pin_value()
1317 LOG_ERR("%s: invalid pin %i", dev->name, pin); in ads1x4s0x_gpio_set_pin_value()
1318 return -EINVAL; in ads1x4s0x_gpio_set_pin_value()
1321 k_mutex_lock(&data->gpio_lock, K_FOREVER); in ads1x4s0x_gpio_set_pin_value()
1323 if ((BIT(pin) & data->gpio_enabled) == 0) { in ads1x4s0x_gpio_set_pin_value()
1324 LOG_ERR("%s: gpio pin %i not configured", dev->name, pin); in ads1x4s0x_gpio_set_pin_value()
1325 result = -EINVAL; in ads1x4s0x_gpio_set_pin_value()
1326 } else if ((BIT(pin) & data->gpio_direction) != 0) { in ads1x4s0x_gpio_set_pin_value()
1327 LOG_ERR("%s: gpio pin %i not configured as output", dev->name, pin); in ads1x4s0x_gpio_set_pin_value()
1328 result = -EINVAL; in ads1x4s0x_gpio_set_pin_value()
1330 data->gpio_value |= BIT(pin); in ads1x4s0x_gpio_set_pin_value()
1335 k_mutex_unlock(&data->gpio_lock); in ads1x4s0x_gpio_set_pin_value()
1342 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_get_pin_value()
1347 LOG_ERR("%s: invalid pin %i", dev->name, pin); in ads1x4s0x_gpio_get_pin_value()
1348 return -EINVAL; in ads1x4s0x_gpio_get_pin_value()
1351 k_mutex_lock(&data->gpio_lock, K_FOREVER); in ads1x4s0x_gpio_get_pin_value()
1353 if ((BIT(pin) & data->gpio_enabled) == 0) { in ads1x4s0x_gpio_get_pin_value()
1354 LOG_ERR("%s: gpio pin %i not configured", dev->name, pin); in ads1x4s0x_gpio_get_pin_value()
1355 result = -EINVAL; in ads1x4s0x_gpio_get_pin_value()
1356 } else if ((BIT(pin) & data->gpio_direction) == 0) { in ads1x4s0x_gpio_get_pin_value()
1357 LOG_ERR("%s: gpio pin %i not configured as input", dev->name, pin); in ads1x4s0x_gpio_get_pin_value()
1358 result = -EINVAL; in ads1x4s0x_gpio_get_pin_value()
1361 data->gpio_value = ADS1X4S0X_REGISTER_GPIODAT_DAT_GET(gpio_dat); in ads1x4s0x_gpio_get_pin_value()
1362 *value = (BIT(pin) & data->gpio_value) != 0; in ads1x4s0x_gpio_get_pin_value()
1365 k_mutex_unlock(&data->gpio_lock); in ads1x4s0x_gpio_get_pin_value()
1372 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_port_get_raw()
1376 k_mutex_lock(&data->gpio_lock, K_FOREVER); in ads1x4s0x_gpio_port_get_raw()
1379 data->gpio_value = ADS1X4S0X_REGISTER_GPIODAT_DAT_GET(gpio_dat); in ads1x4s0x_gpio_port_get_raw()
1380 *value = data->gpio_value; in ads1x4s0x_gpio_port_get_raw()
1382 k_mutex_unlock(&data->gpio_lock); in ads1x4s0x_gpio_port_get_raw()
1390 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_port_set_masked_raw()
1393 k_mutex_lock(&data->gpio_lock, K_FOREVER); in ads1x4s0x_gpio_port_set_masked_raw()
1395 data->gpio_value = ((data->gpio_value & ~mask) | (mask & value)) & data->gpio_enabled & in ads1x4s0x_gpio_port_set_masked_raw()
1396 ~data->gpio_direction; in ads1x4s0x_gpio_port_set_masked_raw()
1399 k_mutex_unlock(&data->gpio_lock); in ads1x4s0x_gpio_port_set_masked_raw()
1404 int ads1x4s0x_gpio_port_toggle_bits(const struct device *dev, gpio_port_pins_t pins) in ads1x4s0x_gpio_port_toggle_bits() argument
1406 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_gpio_port_toggle_bits()
1409 k_mutex_lock(&data->gpio_lock, K_FOREVER); in ads1x4s0x_gpio_port_toggle_bits()
1411 data->gpio_value = (data->gpio_value ^ pins) & data->gpio_enabled & ~data->gpio_direction; in ads1x4s0x_gpio_port_toggle_bits()
1414 k_mutex_unlock(&data->gpio_lock); in ads1x4s0x_gpio_port_toggle_bits()
1427 const struct ads1x4s0x_config *config = dev->config; in ads1x4s0x_init()
1428 struct ads1x4s0x_data *data = dev->data; in ads1x4s0x_init()
1430 adc_context_init(&data->ctx); in ads1x4s0x_init()
1432 k_sem_init(&data->data_ready_signal, 0, 1); in ads1x4s0x_init()
1433 k_sem_init(&data->acquire_signal, 0, 1); in ads1x4s0x_init()
1436 k_mutex_init(&data->gpio_lock); in ads1x4s0x_init()
1439 if (!spi_is_ready_dt(&config->bus)) { in ads1x4s0x_init()
1440 LOG_ERR("%s: SPI device is not ready", dev->name); in ads1x4s0x_init()
1441 return -ENODEV; in ads1x4s0x_init()
1444 if (config->gpio_reset.port != NULL) { in ads1x4s0x_init()
1445 result = gpio_pin_configure_dt(&config->gpio_reset, GPIO_OUTPUT_ACTIVE); in ads1x4s0x_init()
1447 LOG_ERR("%s: failed to initialize GPIO for reset", dev->name); in ads1x4s0x_init()
1452 if (config->gpio_start_sync.port != NULL) { in ads1x4s0x_init()
1453 result = gpio_pin_configure_dt(&config->gpio_start_sync, GPIO_OUTPUT_INACTIVE); in ads1x4s0x_init()
1455 LOG_ERR("%s: failed to initialize GPIO for start/sync", dev->name); in ads1x4s0x_init()
1460 result = gpio_pin_configure_dt(&config->gpio_data_ready, GPIO_INPUT); in ads1x4s0x_init()
1462 LOG_ERR("%s: failed to initialize GPIO for data ready", dev->name); in ads1x4s0x_init()
1466 result = gpio_pin_interrupt_configure_dt(&config->gpio_data_ready, GPIO_INT_EDGE_TO_ACTIVE); in ads1x4s0x_init()
1468 LOG_ERR("%s: failed to configure data ready interrupt", dev->name); in ads1x4s0x_init()
1469 return -EIO; in ads1x4s0x_init()
1472 gpio_init_callback(&data->callback_data_ready, ads1x4s0x_data_ready_handler, in ads1x4s0x_init()
1473 BIT(config->gpio_data_ready.pin)); in ads1x4s0x_init()
1474 result = gpio_add_callback(config->gpio_data_ready.port, &data->callback_data_ready); in ads1x4s0x_init()
1476 LOG_ERR("%s: failed to add data ready callback", dev->name); in ads1x4s0x_init()
1477 return -EIO; in ads1x4s0x_init()
1481 k_tid_t tid = k_thread_create(&data->thread, config->stack, in ads1x4s0x_init()
1490 if (config->gpio_reset.port == NULL) { in ads1x4s0x_init()
1493 LOG_ERR("%s: unable to send RESET command", dev->name); in ads1x4s0x_init()
1498 gpio_pin_set_dt(&config->gpio_reset, 0); in ads1x4s0x_init()
1505 LOG_ERR("%s: unable to read status register", dev->name); in ads1x4s0x_init()
1510 LOG_ERR("%s: ADS114 is not yet ready", dev->name); in ads1x4s0x_init()
1511 return -EBUSY; in ads1x4s0x_init()
1522 LOG_ERR("%s: unable to set default reference control values", dev->name); in ads1x4s0x_init()
1531 LOG_ERR("%s: unable to read reference control values", dev->name); in ads1x4s0x_init()
1536 LOG_ERR("%s: reference control register is incorrect: 0x%02X", dev->name, in ads1x4s0x_init()
1538 return -EIO; in ads1x4s0x_init()
1542 data->gpio_enabled = 0x00; in ads1x4s0x_init()
1543 data->gpio_direction = 0x0F; in ads1x4s0x_init()
1544 data->gpio_value = 0x00; in ads1x4s0x_init()
1549 LOG_ERR("%s: unable to configure defaults for GPIOs", dev->name); in ads1x4s0x_init()
1554 adc_context_unlock_unconditionally(&data->ctx); in ads1x4s0x_init()