Lines Matching +full:reg +full:- +full:rc
5 * SPDX-License-Identifier: Apache-2.0
107 const struct ads1119_config *config = dev->config; in ads1119_read_reg()
109 return i2c_reg_read_byte_dt(&config->bus, ADS1119_CMD_READ_REG | reg_addr, reg_val); in ads1119_read_reg()
112 static int ads1119_write_reg(const struct device *dev, uint8_t reg) in ads1119_write_reg() argument
114 const struct ads1119_config *config = dev->config; in ads1119_write_reg()
116 return i2c_reg_write_byte_dt(&config->bus, ADS1119_CMD_WRITE_REG, reg); in ads1119_write_reg()
122 struct ads1119_data *data = dev->data; in ads1119_acq_time_to_dr()
123 int odr = -EINVAL; in ads1119_acq_time_to_dr()
130 return -EINVAL; in ads1119_acq_time_to_dr()
157 data->ready_time = K_USEC(ready_time_us + 10); in ads1119_acq_time_to_dr()
164 const struct ads1119_config *config = dev->config; in ads1119_send_start_read()
167 return i2c_write_dt(&config->bus, &cmd, sizeof(cmd)); in ads1119_send_start_read()
172 int rc; in ads1119_wait_data_ready() local
173 struct ads1119_data *data = dev->data; in ads1119_wait_data_ready()
175 k_sleep(data->ready_time); in ads1119_wait_data_ready()
178 rc = ads1119_read_reg(dev, ADS1119_REG_STATUS, &status); in ads1119_wait_data_ready()
179 if (rc != 0) { in ads1119_wait_data_ready()
180 return rc; in ads1119_wait_data_ready()
186 rc = ads1119_read_reg(dev, ADS1119_REG_STATUS, &status); in ads1119_wait_data_ready()
187 if (rc != 0) { in ads1119_wait_data_ready()
188 return rc; in ads1119_wait_data_ready()
199 const struct ads1119_config *config = dev->config; in ads1119_read_sample()
202 res = i2c_write_read_dt(&config->bus, in ads1119_read_sample()
213 struct ads1119_data *data = dev->data; in ads1119_channel_setup()
217 if (channel_cfg->channel_id != 0) { in ads1119_channel_setup()
218 return -EINVAL; in ads1119_channel_setup()
221 switch (channel_cfg->reference) { in ads1119_channel_setup()
229 return -EINVAL; in ads1119_channel_setup()
232 if (channel_cfg->differential) { in ads1119_channel_setup()
233 if (channel_cfg->input_positive == 0 && channel_cfg->input_negative == 1) { in ads1119_channel_setup()
235 } else if (channel_cfg->input_positive == 1 && channel_cfg->input_negative == 2) { in ads1119_channel_setup()
237 } else if (channel_cfg->input_positive == 2 && channel_cfg->input_negative == 3) { in ads1119_channel_setup()
240 return -EINVAL; in ads1119_channel_setup()
243 if (channel_cfg->input_positive == 0) { in ads1119_channel_setup()
245 } else if (channel_cfg->input_positive == 1) { in ads1119_channel_setup()
247 } else if (channel_cfg->input_positive == 2) { in ads1119_channel_setup()
249 } else if (channel_cfg->input_positive == 3) { in ads1119_channel_setup()
252 return -EINVAL; in ads1119_channel_setup()
255 data->differential = channel_cfg->differential; in ads1119_channel_setup()
257 dr = ads1119_acq_time_to_dr(dev, channel_cfg->acquisition_time); in ads1119_channel_setup()
264 switch (channel_cfg->gain) { in ads1119_channel_setup()
272 return -EINVAL; in ads1119_channel_setup()
285 if (sequence->options) { in ads1119_validate_buffer_size()
286 needed *= (1 + sequence->options->extra_samplings); in ads1119_validate_buffer_size()
289 if (sequence->buffer_size < needed) { in ads1119_validate_buffer_size()
290 return -ENOMEM; in ads1119_validate_buffer_size()
298 const struct ads1119_data *data = dev->data; in ads1119_validate_sequence()
299 const uint8_t resolution = data->differential ? ADS1119_RESOLUTION : ADS1119_RESOLUTION - 1; in ads1119_validate_sequence()
301 if (sequence->resolution != resolution) { in ads1119_validate_sequence()
302 return -EINVAL; in ads1119_validate_sequence()
305 if (sequence->channels != BIT(0)) { in ads1119_validate_sequence()
306 return -EINVAL; in ads1119_validate_sequence()
309 if (sequence->oversampling) { in ads1119_validate_sequence()
310 return -EINVAL; in ads1119_validate_sequence()
324 data->buffer = data->buffer_ptr; in adc_context_update_buffer_pointer()
333 data->buffer_ptr = data->buffer; in adc_context_start_sampling()
334 k_sem_give(&data->acq_sem); in adc_context_start_sampling()
341 int rc; in ads1119_adc_start_read() local
342 struct ads1119_data *data = dev->data; in ads1119_adc_start_read()
344 rc = ads1119_validate_sequence(dev, sequence); in ads1119_adc_start_read()
345 if (rc != 0) { in ads1119_adc_start_read()
346 return rc; in ads1119_adc_start_read()
349 data->buffer = sequence->buffer; in ads1119_adc_start_read()
351 adc_context_start_read(&data->ctx, sequence); in ads1119_adc_start_read()
354 rc = adc_context_wait_for_completion(&data->ctx); in ads1119_adc_start_read()
356 return rc; in ads1119_adc_start_read()
361 int rc; in ads1119_adc_perform_read() local
362 struct ads1119_data *data = dev->data; in ads1119_adc_perform_read()
364 k_sem_take(&data->acq_sem, K_FOREVER); in ads1119_adc_perform_read()
366 rc = ads1119_send_start_read(dev); in ads1119_adc_perform_read()
367 if (rc) { in ads1119_adc_perform_read()
368 adc_context_complete(&data->ctx, rc); in ads1119_adc_perform_read()
369 return rc; in ads1119_adc_perform_read()
372 rc = ads1119_wait_data_ready(dev); in ads1119_adc_perform_read()
373 if (rc != 0) { in ads1119_adc_perform_read()
374 adc_context_complete(&data->ctx, rc); in ads1119_adc_perform_read()
375 return rc; in ads1119_adc_perform_read()
378 rc = ads1119_read_sample(dev, data->buffer); in ads1119_adc_perform_read()
379 if (rc != 0) { in ads1119_adc_perform_read()
380 adc_context_complete(&data->ctx, rc); in ads1119_adc_perform_read()
381 return rc; in ads1119_adc_perform_read()
383 data->buffer++; in ads1119_adc_perform_read()
385 adc_context_on_sampling_done(&data->ctx, dev); in ads1119_adc_perform_read()
387 return rc; in ads1119_adc_perform_read()
395 int rc; in ads1119_adc_read_async() local
396 struct ads1119_data *data = dev->data; in ads1119_adc_read_async()
398 adc_context_lock(&data->ctx, true, async); in ads1119_adc_read_async()
399 rc = ads1119_adc_start_read(dev, sequence, true); in ads1119_adc_read_async()
400 adc_context_release(&data->ctx, rc); in ads1119_adc_read_async()
402 return rc; in ads1119_adc_read_async()
407 int rc; in ads1119_read() local
408 struct ads1119_data *data = dev->data; in ads1119_read()
410 adc_context_lock(&data->ctx, false, NULL); in ads1119_read()
411 rc = ads1119_adc_start_read(dev, sequence, true); in ads1119_read()
412 adc_context_release(&data->ctx, rc); in ads1119_read()
414 return rc; in ads1119_read()
420 int rc; in ads1119_read() local
421 struct ads1119_data *data = dev->data; in ads1119_read()
423 adc_context_lock(&data->ctx, false, NULL); in ads1119_read()
424 rc = ads1119_adc_start_read(dev, sequence, false); in ads1119_read()
426 while (rc == 0 && k_sem_take(&data->ctx.sync, K_NO_WAIT) != 0) { in ads1119_read()
427 rc = ads1119_adc_perform_read(dev); in ads1119_read()
430 adc_context_release(&data->ctx, rc); in ads1119_read()
431 return rc; in ads1119_read()
450 int rc; in ads1119_init() local
452 const struct ads1119_config *config = dev->config; in ads1119_init()
453 struct ads1119_data *data = dev->data; in ads1119_init()
455 adc_context_init(&data->ctx); in ads1119_init()
457 k_sem_init(&data->acq_sem, 0, 1); in ads1119_init()
459 if (!device_is_ready(config->bus.bus)) { in ads1119_init()
460 return -ENODEV; in ads1119_init()
463 rc = ads1119_read_reg(dev, ADS1119_REG_STATUS, &status); in ads1119_init()
464 if (rc) { in ads1119_init()
465 LOG_ERR("Could not get %s status", dev->name); in ads1119_init()
466 return rc; in ads1119_init()
471 k_thread_create(&data->thread, config->stack, in ads1119_init()
479 adc_context_unlock_unconditionally(&data->ctx); in ads1119_init()
481 return rc; in ads1119_init()