Lines Matching +full:threshold +full:- +full:mv
5 * SPDX-License-Identifier: Apache-2.0
27 #define ADC_RPI_CHANNEL_NUM (ADC_CS_RROBIN_MSB - ADC_CS_RROBIN_LSB + 1)
69 hw_set_bits(&adc_hw->cs, ADC_CS_START_ONCE_BITS); in adc_start_once()
74 return (uint16_t)adc_hw->result; in adc_get_result()
79 return (adc_hw->cs & ADC_CS_ERR_BITS) ? true : false; in adc_get_err()
85 hw_set_bits(&adc_hw->fcs, ADC_FCS_OVER_BITS); in adc_clear_errors()
86 hw_set_bits(&adc_hw->fcs, ADC_FCS_UNDER_BITS); in adc_clear_errors()
87 hw_set_bits(&adc_hw->fcs, ADC_FCS_ERR_BITS); in adc_clear_errors()
88 hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS); in adc_clear_errors()
93 adc_hw->cs = ADC_CS_EN_BITS; in adc_enable()
94 while (!(adc_hw->cs & ADC_CS_READY_BITS)) { in adc_enable()
102 const struct adc_rpi_config *config = dev->config; in adc_rpi_channel_setup()
104 if (channel_cfg->channel_id >= config->num_channels) { in adc_rpi_channel_setup()
105 LOG_ERR("unsupported channel id '%d'", channel_cfg->channel_id); in adc_rpi_channel_setup()
106 return -ENOTSUP; in adc_rpi_channel_setup()
109 if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { in adc_rpi_channel_setup()
111 return -EINVAL; in adc_rpi_channel_setup()
114 if (channel_cfg->differential) { in adc_rpi_channel_setup()
116 return -ENOTSUP; in adc_rpi_channel_setup()
119 if (channel_cfg->gain != ADC_GAIN_1) { in adc_rpi_channel_setup()
121 return -EINVAL; in adc_rpi_channel_setup()
134 * @return -ENOMEM if buffer is not big enough
139 const struct adc_rpi_config *config = dev->config; in adc_rpi_check_buffer_size()
144 for (mask = BIT(config->num_channels - 1); mask != 0; mask >>= 1) { in adc_rpi_check_buffer_size()
145 if (mask & sequence->channels) { in adc_rpi_check_buffer_size()
151 if (sequence->options) { in adc_rpi_check_buffer_size()
152 needed *= (1 + sequence->options->extra_samplings); in adc_rpi_check_buffer_size()
155 if (sequence->buffer_size < needed) { in adc_rpi_check_buffer_size()
156 return -ENOMEM; in adc_rpi_check_buffer_size()
169 * @return -ENOTSUP if requested resolution or channel is out side of supported
171 * @return -ENOMEM if buffer is not big enough
178 const struct adc_rpi_config *config = dev->config; in adc_rpi_start_read()
179 struct adc_rpi_data *data = dev->data; in adc_rpi_start_read()
182 if (sequence->resolution > ADC_RPI_MAX_RESOLUTION || in adc_rpi_start_read()
183 sequence->resolution == 0) { in adc_rpi_start_read()
184 LOG_ERR("unsupported resolution %d", sequence->resolution); in adc_rpi_start_read()
185 return -ENOTSUP; in adc_rpi_start_read()
188 if (find_msb_set(sequence->channels) > config->num_channels) { in adc_rpi_start_read()
190 sequence->channels); in adc_rpi_start_read()
191 return -ENOTSUP; in adc_rpi_start_read()
200 data->buf = sequence->buffer; in adc_rpi_start_read()
201 adc_context_start_read(&data->ctx, sequence); in adc_rpi_start_read()
203 return adc_context_wait_for_completion(&data->ctx); in adc_rpi_start_read()
211 struct adc_rpi_data *data = dev->data; in adc_rpi_isr()
226 adc_context_complete(&data->ctx, -EIO); in adc_rpi_isr()
231 *data->buf++ = result; in adc_rpi_isr()
232 data->channels &= ~(BIT(ainsel)); in adc_rpi_isr()
235 if (data->channels == 0) { in adc_rpi_isr()
236 adc_context_on_sampling_done(&data->ctx, dev); in adc_rpi_isr()
241 ainsel = (uint8_t)(find_lsb_set(data->channels) - 1); in adc_rpi_isr()
250 struct adc_rpi_data *data = dev->data; in adc_rpi_read_async()
253 adc_context_lock(&data->ctx, async ? true : false, async); in adc_rpi_read_async()
255 adc_context_release(&data->ctx, err); in adc_rpi_read_async()
271 data->channels = ctx->sequence.channels; in adc_context_start_sampling()
272 data->repeat_buf = data->buf; in adc_context_start_sampling()
277 adc_select_input(find_lsb_set(data->channels) - 1); in adc_context_start_sampling()
288 data->buf = data->repeat_buf; in adc_context_update_buffer_pointer()
294 * channels to return constant 0 mV and create acquisition thread.
302 const struct adc_rpi_config *config = dev->config; in adc_rpi_init()
303 struct adc_rpi_data *data = dev->data; in adc_rpi_init()
306 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in adc_rpi_init()
311 ret = clock_control_on(config->clk_dev, config->clk_id); in adc_rpi_init()
316 ret = reset_line_toggle_dt(&config->reset); in adc_rpi_init()
321 config->irq_configure(); in adc_rpi_init()
325 * Set the threshold as 1 for getting notification immediately in adc_rpi_init()
339 adc_context_unlock_unconditionally(&data->ctx); in adc_rpi_init()