Lines Matching +full:conversion +full:- +full:rate

4  * SPDX-License-Identifier: Apache-2.0
13 #include <zephyr/dt-bindings/adc/smartbond-adc.h>
50 * settings for each channel that must be applied before conversion.
61 uint8_t channel_id = channel_cfg->channel_id; in adc_smartbond_channel_setup()
65 return -EINVAL; in adc_smartbond_channel_setup()
68 if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { in adc_smartbond_channel_setup()
70 return -EINVAL; in adc_smartbond_channel_setup()
73 if (channel_cfg->differential) { in adc_smartbond_channel_setup()
74 if (channel_cfg->input_positive != SMARTBOND_GPADC_P1_09 && in adc_smartbond_channel_setup()
75 channel_cfg->input_positive != SMARTBOND_GPADC_P0_08) { in adc_smartbond_channel_setup()
77 return -EINVAL; in adc_smartbond_channel_setup()
81 switch (channel_cfg->gain) { in adc_smartbond_channel_setup()
84 config->gp_adc_ctrl2_reg = 0x101; in adc_smartbond_channel_setup()
87 config->gp_adc_ctrl2_reg = 0; in adc_smartbond_channel_setup()
91 return -EINVAL; in adc_smartbond_channel_setup()
94 switch (channel_cfg->reference) { in adc_smartbond_channel_setup()
99 return -EINVAL; in adc_smartbond_channel_setup()
102 config->gp_adc_ctrl_reg = in adc_smartbond_channel_setup()
103 channel_cfg->input_positive << GPADC_GP_ADC_CTRL_REG_GP_ADC_SEL_Pos; in adc_smartbond_channel_setup()
104 if (!channel_cfg->differential) { in adc_smartbond_channel_setup()
105 config->gp_adc_ctrl_reg |= GPADC_GP_ADC_CTRL_REG_GP_ADC_SE_Msk; in adc_smartbond_channel_setup()
149 int current_channel = u32_count_trailing_zeros(data->channel_read_mask); in adc_context_start_sampling()
151 if (ctx->sequence.calibrate) { in adc_context_start_sampling()
154 val = GPADC->GP_ADC_CTRL_REG & ~PER_CHANNEL_ADC_CONFIG_MASK; in adc_context_start_sampling()
159 GPADC->GP_ADC_CTRL2_REG = m_channels[current_channel].gp_adc_ctrl2_reg; in adc_context_start_sampling()
160 GPADC->GP_ADC_CTRL_REG = val; in adc_context_start_sampling()
171 data->buffer += data->sequence_channel_count; in adc_context_update_buffer_pointer()
181 if (sequence->options) { in check_buffer_size()
182 needed_buffer_size *= (1 + sequence->options->extra_samplings); in check_buffer_size()
185 if (sequence->buffer_size < needed_buffer_size) { in check_buffer_size()
187 sequence->buffer_size, needed_buffer_size); in check_buffer_size()
188 return -ENOMEM; in check_buffer_size()
198 struct adc_smartbond_data *data = dev->data; in start_read()
200 if (sequence->oversampling > 7U) { in start_read()
202 return -EINVAL; in start_read()
205 if ((sequence->channels == 0) || in start_read()
206 ((sequence->channels & ~BIT_MASK(SMARTBOND_ADC_CHANNEL_COUNT)) != 0)) { in start_read()
208 return -EINVAL; in start_read()
211 if (sequence->resolution < 8 || sequence->resolution > 15) { in start_read()
213 sequence->resolution); in start_read()
214 return -EINVAL; in start_read()
222 data->buffer = sequence->buffer; in start_read()
223 data->channel_read_mask = sequence->channels; in start_read()
224 data->sequence_channel_count = pop_count(sequence->channels); in start_read()
225 data->result_index = 0; in start_read()
227 adc_context_start_read(&data->ctx, sequence); in start_read()
229 error = adc_context_wait_for_completion(&data->ctx); in start_read()
235 struct adc_smartbond_data *data = dev->data; in adc_smartbond_isr()
236 int current_channel = u32_count_trailing_zeros(data->channel_read_mask); in adc_smartbond_isr()
238 GPADC->GP_ADC_CLEAR_INT_REG = 0; in adc_smartbond_isr()
240 data->buffer[data->result_index++] = ((uint16_t)GPADC->GP_ADC_RESULT_REG) >> in adc_smartbond_isr()
241 (16 - data->ctx.sequence.resolution); in adc_smartbond_isr()
243 data->channel_read_mask ^= 1 << current_channel; in adc_smartbond_isr()
245 if (data->channel_read_mask == 0) { in adc_smartbond_isr()
247 adc_context_on_sampling_done(&data->ctx, dev); in adc_smartbond_isr()
249 adc_context_start_sampling(&data->ctx); in adc_smartbond_isr()
252 LOG_DBG("%s ISR triggered.", dev->name); in adc_smartbond_isr()
260 struct adc_smartbond_data *data = dev->data; in adc_smartbond_read()
262 adc_context_lock(&data->ctx, false, NULL); in adc_smartbond_read()
265 adc_context_release(&data->ctx, error); in adc_smartbond_read()
276 struct adc_smartbond_data *data = dev->data; in adc_smartbond_read_async()
279 adc_context_lock(&data->ctx, true, async); in adc_smartbond_read_async()
282 adc_context_release(&data->ctx, error); in adc_smartbond_read_async()
290 int ret, rate; in gpadc_smartbond_resume() local
291 const struct adc_smartbond_cfg *config = dev->config; in gpadc_smartbond_resume()
297 clock_control_get_rate(clock_dev, (clock_control_subsys_t)SMARTBOND_CLK_SYS_CLK, &rate); in gpadc_smartbond_resume()
298 GPADC->GP_ADC_CTRL3_REG = (rate/1600000)&0xff; in gpadc_smartbond_resume()
300 GPADC->GP_ADC_CTRL_REG = GPADC_GP_ADC_CTRL_REG_GP_ADC_EN_Msk; in gpadc_smartbond_resume()
306 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in gpadc_smartbond_resume()
307 if (ret < 0 && ret != -ENOENT) { in gpadc_smartbond_resume()
309 GPADC->GP_ADC_CTRL_REG = 0; in gpadc_smartbond_resume()
325 const struct adc_smartbond_cfg *config = dev->config; in gpadc_smartbond_suspend()
328 GPADC->GP_ADC_CTRL_REG = 0; in gpadc_smartbond_suspend()
337 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_SLEEP); in gpadc_smartbond_suspend()
338 if (ret < 0 && ret != -ENOENT) { in gpadc_smartbond_suspend()
359 return -ENOTSUP; in gpadc_smartbond_pm_action()
368 struct adc_smartbond_data *data = dev->data; in adc_smartbond_init()
387 adc_context_unlock_unconditionally(&data->ctx); in adc_smartbond_init()