Lines Matching +full:adc +full:- +full:config

4  * SPDX-License-Identifier: Apache-2.0
9 #include <zephyr/drivers/adc.h>
34 * @brief RA ADC config
36 * This structure contains constant data for given instance of RA ADC.
50 * @brief RA ADC data
52 * This structure contains data structures used by a RA ADC.
57 /** Pointer to RA ADC own device structure */
59 /** Structure that handle fsp ADC */
60 adc_instance_ctrl_t adc; member
61 /** Structure that handle fsp ADC config */
63 /** Structure that handle fsp ADC channel config */
74 * @brief Setup channels before starting to scan ADC
76 * @param dev RA ADC device
80 * @return -ENOTSUP if channel id or differential is wrong value
81 * @return -EINVAL if channel configuration is invalid
86 struct adc_ra_data *data = dev->data; in adc_ra_channel_setup()
87 const struct adc_ra_config *config = dev->config; in adc_ra_channel_setup() local
89 if (!((config->channel_available_mask & (1 << channel_cfg->channel_id)) != 0)) { in adc_ra_channel_setup()
90 LOG_ERR("unsupported channel id '%d'", channel_cfg->channel_id); in adc_ra_channel_setup()
91 return -ENOTSUP; in adc_ra_channel_setup()
94 if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { in adc_ra_channel_setup()
96 return -EINVAL; in adc_ra_channel_setup()
99 if (channel_cfg->differential) { in adc_ra_channel_setup()
101 return -ENOTSUP; in adc_ra_channel_setup()
104 if (channel_cfg->gain != ADC_GAIN_1) { in adc_ra_channel_setup()
106 return -EINVAL; in adc_ra_channel_setup()
109 data->f_channel_cfg.scan_mask |= (1U << channel_cfg->channel_id); in adc_ra_channel_setup()
110 /* Configure ADC channel specific settings */ in adc_ra_channel_setup()
111 fsp_err = R_ADC_ScanCfg(&data->adc, &data->f_channel_cfg); in adc_ra_channel_setup()
113 return -ENOTSUP; in adc_ra_channel_setup()
124 struct adc_ra_data *data = dev->data; in adc_ra_isr()
128 int16_t *sample_buffer = (int16_t *)data->buf; in adc_ra_isr()
130 channels = data->channels; in adc_ra_isr()
134 fsp_err = R_ADC_Read(&data->adc, channel_id, &sample_buffer[data->buf_id]); in adc_ra_isr()
138 data->buf_id = data->buf_id + 1; in adc_ra_isr()
144 adc_context_on_sampling_done(&data->ctx, dev); in adc_ra_isr()
148 * @brief Check if buffer in @p sequence is big enough to hold all ADC samples
150 * @param dev RA ADC device
151 * @param sequence ADC sequence description
154 * @return -ENOMEM if buffer is not big enough
158 const struct adc_ra_config *config = dev->config; in adc_ra_check_buffer_size() local
163 for (mask = BIT(config->num_channels - 1); mask != 0; mask >>= 1) { in adc_ra_check_buffer_size()
164 if (mask & sequence->channels) { in adc_ra_check_buffer_size()
170 if (sequence->options) { in adc_ra_check_buffer_size()
171 needed *= (1 + sequence->options->extra_samplings); in adc_ra_check_buffer_size()
174 if (sequence->buffer_size < needed) { in adc_ra_check_buffer_size()
175 return -ENOMEM; in adc_ra_check_buffer_size()
184 * @param dev RA ADC device
185 * @param sequence ADC sequence description
188 * @return -ENOTSUP if requested resolution or channel is out side of supported
190 * @return -ENOMEM if buffer is not big enough
196 const struct adc_ra_config *config = dev->config; in adc_ra_start_read() local
197 struct adc_ra_data *data = dev->data; in adc_ra_start_read()
200 if (sequence->resolution > ADC_RA_MAX_RESOLUTION || sequence->resolution == 0) { in adc_ra_start_read()
201 LOG_ERR("unsupported resolution %d", sequence->resolution); in adc_ra_start_read()
202 return -ENOTSUP; in adc_ra_start_read()
205 if (find_msb_set(sequence->channels) > config->num_channels) { in adc_ra_start_read()
206 LOG_ERR("unsupported channels in mask: 0x%08x", sequence->channels); in adc_ra_start_read()
207 return -ENOTSUP; in adc_ra_start_read()
216 data->buf_id = 0; in adc_ra_start_read()
217 data->buf = sequence->buffer; in adc_ra_start_read()
218 adc_context_start_read(&data->ctx, sequence); in adc_ra_start_read()
220 adc_context_wait_for_completion(&data->ctx); in adc_ra_start_read()
228 * @param dev RA ADC device
229 * @param sequence ADC sequence description
233 * @return -ENOTSUP if requested resolution or channel is out side of supported
235 * @return -ENOMEM if buffer is not big enough
242 struct adc_ra_data *data = dev->data; in adc_ra_read_async()
245 adc_context_lock(&data->ctx, async ? true : false, async); in adc_ra_read_async()
247 adc_context_release(&data->ctx, err); in adc_ra_read_async()
255 * @param dev RA ADC device
256 * @param sequence ADC sequence description
259 * @return -ENOTSUP if requested resolution or channel is out side of supported
261 * @return -ENOMEM if buffer is not big enough
274 data->channels = ctx->sequence.channels; in adc_context_start_sampling()
276 R_ADC_ScanStart(&data->adc); in adc_context_start_sampling()
284 data->buf_id = 0; in adc_context_update_buffer_pointer()
289 * @brief Function called on init for each RA ADC device. It setups all
292 * @param dev RA ADC device
294 * @return -EIO if error
300 const struct adc_ra_config *config = dev->config; in adc_ra_init() local
301 struct adc_ra_data *data = dev->data; in adc_ra_init()
305 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in adc_ra_init()
310 /* Open ADC module */ in adc_ra_init()
311 fsp_err = R_ADC_Open(&data->adc, &data->f_config); in adc_ra_init()
313 return -EIO; in adc_ra_init()
316 config->irq_configure(); in adc_ra_init()
318 adc_context_unlock_unconditionally(&data->ctx); in adc_ra_init()
325 R_ICU->IELSR[DT_INST_IRQ_BY_NAME(idx, scanend, irq)] = \
351 static DEVICE_API(adc, adc_ra_api_##idx) = { \