Lines Matching +full:reg +full:- +full:rc
6 * SPDX-License-Identifier: Apache-2.0
81 const struct ads1112_config *config = dev->config; in ads1112_read_reg()
83 int rc = i2c_read_dt(&config->bus, buf, sizeof(buf)); in ads1112_read_reg() local
92 return rc; in ads1112_read_reg()
95 static int ads1112_write_reg(const struct device *dev, uint8_t reg) in ads1112_write_reg() argument
97 uint8_t msg[1] = {reg}; in ads1112_write_reg()
98 const struct ads1112_config *config = dev->config; in ads1112_write_reg()
104 return i2c_write_dt(&config->bus, msg, sizeof(msg)); in ads1112_write_reg()
109 struct ads1112_data *data = dev->data; in ads1112_acq_time_to_dr()
110 int odr = -EINVAL; in ads1112_acq_time_to_dr()
117 return -EINVAL; in ads1112_acq_time_to_dr()
145 data->ready_time = K_USEC(ready_time_us + 10); in ads1112_acq_time_to_dr()
152 int rc; in ads1112_wait_data_ready() local
153 struct ads1112_data *data = dev->data; in ads1112_wait_data_ready()
155 k_sleep(data->ready_time); in ads1112_wait_data_ready()
158 rc = ads1112_read_reg(dev, ADS1112_REG_CONFIG, &status); in ads1112_wait_data_ready()
159 if (rc != 0) { in ads1112_wait_data_ready()
160 return rc; in ads1112_wait_data_ready()
166 rc = ads1112_read_reg(dev, ADS1112_REG_CONFIG, &status); in ads1112_wait_data_ready()
167 if (rc != 0) { in ads1112_wait_data_ready()
168 return rc; in ads1112_wait_data_ready()
188 struct ads1112_data *data = dev->data; in ads1112_channel_setup()
192 if (channel_cfg->channel_id != 0) { in ads1112_channel_setup()
193 return -EINVAL; in ads1112_channel_setup()
196 if (channel_cfg->differential) { in ads1112_channel_setup()
197 if (channel_cfg->input_positive == 0 && channel_cfg->input_negative == 1) { in ads1112_channel_setup()
199 } else if (channel_cfg->input_positive == 2 && channel_cfg->input_negative == 3) { in ads1112_channel_setup()
202 return -EINVAL; in ads1112_channel_setup()
205 if (channel_cfg->input_positive == 0) { in ads1112_channel_setup()
207 } else if (channel_cfg->input_positive == 1) { in ads1112_channel_setup()
209 } else if (channel_cfg->input_positive == 2) { in ads1112_channel_setup()
212 return -EINVAL; in ads1112_channel_setup()
216 data->differential = channel_cfg->differential; in ads1112_channel_setup()
218 dr = ads1112_acq_time_to_dr(dev, channel_cfg->acquisition_time); in ads1112_channel_setup()
225 switch (channel_cfg->gain) { in ads1112_channel_setup()
239 return -EINVAL; in ads1112_channel_setup()
251 if (sequence->options) { in ads1112_validate_buffer_size()
252 needed *= (1 + sequence->options->extra_samplings); in ads1112_validate_buffer_size()
255 if (sequence->buffer_size < needed) { in ads1112_validate_buffer_size()
256 LOG_ERR("Insufficient buffer %i < %i", sequence->buffer_size, needed); in ads1112_validate_buffer_size()
257 return -ENOMEM; in ads1112_validate_buffer_size()
265 if (sequence->channels != BIT(0)) { in ads1112_validate_sequence()
266 LOG_ERR("Invalid Channel 0x%x", sequence->channels); in ads1112_validate_sequence()
267 return -EINVAL; in ads1112_validate_sequence()
270 if (sequence->oversampling) { in ads1112_validate_sequence()
272 return -EINVAL; in ads1112_validate_sequence()
283 data->buffer = data->buffer_ptr; in adc_context_update_buffer_pointer()
291 data->buffer_ptr = data->buffer; in adc_context_start_sampling()
292 k_sem_give(&data->acq_sem); in adc_context_start_sampling()
298 int rc = 0; in ads1112_adc_start_read() local
299 struct ads1112_data *data = dev->data; in ads1112_adc_start_read()
301 rc = ads1112_validate_sequence(dev, sequence); in ads1112_adc_start_read()
302 if (rc != 0) { in ads1112_adc_start_read()
303 return rc; in ads1112_adc_start_read()
306 data->buffer = sequence->buffer; in ads1112_adc_start_read()
308 adc_context_start_read(&data->ctx, sequence); in ads1112_adc_start_read()
311 rc = adc_context_wait_for_completion(&data->ctx); in ads1112_adc_start_read()
313 return rc; in ads1112_adc_start_read()
318 int rc; in ads1112_adc_perform_read() local
319 struct ads1112_data *data = dev->data; in ads1112_adc_perform_read()
321 k_sem_take(&data->acq_sem, K_FOREVER); in ads1112_adc_perform_read()
323 rc = ads1112_wait_data_ready(dev); in ads1112_adc_perform_read()
324 if (rc != 0) { in ads1112_adc_perform_read()
325 adc_context_complete(&data->ctx, rc); in ads1112_adc_perform_read()
326 return rc; in ads1112_adc_perform_read()
329 rc = ads1112_read_sample(dev, data->buffer); in ads1112_adc_perform_read()
330 if (rc != 0) { in ads1112_adc_perform_read()
331 adc_context_complete(&data->ctx, rc); in ads1112_adc_perform_read()
332 return rc; in ads1112_adc_perform_read()
334 data->buffer++; in ads1112_adc_perform_read()
336 adc_context_on_sampling_done(&data->ctx, dev); in ads1112_adc_perform_read()
338 return rc; in ads1112_adc_perform_read()
343 int rc; in ads1112_read() local
344 struct ads1112_data *data = dev->data; in ads1112_read()
346 adc_context_lock(&data->ctx, false, NULL); in ads1112_read()
347 rc = ads1112_adc_start_read(dev, sequence, false); in ads1112_read()
349 while (rc == 0 && k_sem_take(&data->ctx.sync, K_NO_WAIT) != 0) { in ads1112_read()
350 rc = ads1112_adc_perform_read(dev); in ads1112_read()
353 adc_context_release(&data->ctx, rc); in ads1112_read()
354 return rc; in ads1112_read()
359 int rc = 0; in ads1112_init() local
360 const struct ads1112_config *config = dev->config; in ads1112_init()
361 struct ads1112_data *data = dev->data; in ads1112_init()
363 adc_context_init(&data->ctx); in ads1112_init()
365 k_sem_init(&data->acq_sem, 0, 1); in ads1112_init()
367 if (!device_is_ready(config->bus.bus)) { in ads1112_init()
368 return -ENODEV; in ads1112_init()
371 rc = ads1112_write_reg(dev, ADS1112_DEFAULT_CONFIG); in ads1112_init()
372 if (rc) { in ads1112_init()
374 return rc; in ads1112_init()
377 adc_context_unlock_unconditionally(&data->ctx); in ads1112_init()
379 return rc; in ads1112_init()