Lines Matching +full:valid +full:- +full:channels

4  * SPDX-License-Identifier: Apache-2.0
44 if (chan_mask & sequence->channels) { in adc_kb1200_validate_buffer_size()
51 if (sequence->options) { in adc_kb1200_validate_buffer_size()
52 buff_need *= 1 + sequence->options->extra_samplings; in adc_kb1200_validate_buffer_size()
55 if (buff_need > sequence->buffer_size) { in adc_kb1200_validate_buffer_size()
62 * 1. Start ADC sampling (set up flag ctx->sync)
63 * adc_context_start_read() -> adc_context_start_sampling()
64 * 2. Wait ADC sample finish (by monitor flag ctx->sync)
66 * 3. Finish ADC sample (isr clear flag ctx->sync)
67 * adc_context_on_sampling_done -> adc_context_complete
71 const struct adc_kb1200_config *config = dev->config; in adc_kb1200_start_read()
72 struct adc_kb1200_data *data = dev->data; in adc_kb1200_start_read()
75 if (!sequence->channels || (sequence->channels & ~BIT_MASK(ADC_MAX_CHAN))) { in adc_kb1200_start_read()
76 LOG_ERR("Invalid ADC channels."); in adc_kb1200_start_read()
77 return -EINVAL; in adc_kb1200_start_read()
80 if (sequence->resolution != ADC_RESOLUTION) { in adc_kb1200_start_read()
82 return -ENOTSUP; in adc_kb1200_start_read()
84 /* Check sequence->buffer_size is enough */ in adc_kb1200_start_read()
87 return -ENOMEM; in adc_kb1200_start_read()
91 data->buffer = sequence->buffer; in adc_kb1200_start_read()
92 data->buf_end = data->buffer + sequence->buffer_size / sizeof(uint16_t); in adc_kb1200_start_read()
94 data->adc_dev = dev; in adc_kb1200_start_read()
96 adc_context_start_read(&data->ctx, sequence); in adc_kb1200_start_read()
98 * flag to be valid, then record adc value. in adc_kb1200_start_read()
100 uint32_t channels = (config->adc->ADCCFG & ADC_CHANNEL_BIT_MASK) >> ADC_CHANNEL_BIT_POS; in adc_kb1200_start_read() local
102 while (channels) { in adc_kb1200_start_read()
107 ch_num = find_lsb_set(channels) - 1; in adc_kb1200_start_read()
108 /* wait valid flag */ in adc_kb1200_start_read()
109 while (config->adc->ADCDAT[ch_num] & ADC_INVALID_VALUE) { in adc_kb1200_start_read()
114 error = -EBUSY; in adc_kb1200_start_read()
119 if (data->buffer < data->buf_end) { in adc_kb1200_start_read()
120 *data->buffer = (uint16_t)(config->adc->ADCDAT[ch_num]); in adc_kb1200_start_read()
121 data->buffer++; in adc_kb1200_start_read()
123 error = -EINVAL; in adc_kb1200_start_read()
128 channels &= ~BIT(ch_num); in adc_kb1200_start_read()
133 adc_context_on_sampling_done(&data->ctx, dev); in adc_kb1200_start_read()
141 if (channel_cfg->channel_id >= ADC_MAX_CHAN) { in adc_kb1200_channel_setup()
142 LOG_ERR("Invalid channel %d.", channel_cfg->channel_id); in adc_kb1200_channel_setup()
143 return -EINVAL; in adc_kb1200_channel_setup()
146 if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { in adc_kb1200_channel_setup()
148 return -ENOTSUP; in adc_kb1200_channel_setup()
151 if (channel_cfg->differential) { in adc_kb1200_channel_setup()
152 LOG_ERR("Differential channels are not supported."); in adc_kb1200_channel_setup()
153 return -ENOTSUP; in adc_kb1200_channel_setup()
156 if (channel_cfg->gain != ADC_GAIN_1) { in adc_kb1200_channel_setup()
157 LOG_ERR("Unsupported channel gain %d.", channel_cfg->gain); in adc_kb1200_channel_setup()
158 return -ENOTSUP; in adc_kb1200_channel_setup()
161 if (channel_cfg->reference != ADC_REF_INTERNAL) { in adc_kb1200_channel_setup()
163 return -ENOTSUP; in adc_kb1200_channel_setup()
165 LOG_DBG("ADC channel %d configured.", channel_cfg->channel_id); in adc_kb1200_channel_setup()
171 struct adc_kb1200_data *data = dev->data; in adc_kb1200_read()
174 adc_context_lock(&data->ctx, false, NULL); in adc_kb1200_read()
176 adc_context_release(&data->ctx, error); in adc_kb1200_read()
185 struct adc_kb1200_data *data = dev->data; in adc_kb1200_read_async()
188 adc_context_lock(&data->ctx, true, async); in adc_kb1200_read_async()
190 adc_context_release(&data->ctx, error); in adc_kb1200_read_async()
200 const struct device *dev = data->adc_dev; in adc_context_start_sampling()
201 const struct adc_kb1200_config *config = dev->config; in adc_context_start_sampling()
203 data->repeat_buffer = data->buffer; in adc_context_start_sampling()
204 config->adc->ADCCFG = (config->adc->ADCCFG & ~ADC_CHANNEL_BIT_MASK) | in adc_context_start_sampling()
205 (ctx->sequence.channels << ADC_CHANNEL_BIT_POS); in adc_context_start_sampling()
206 config->adc->ADCCFG |= ADC_FUNCTION_ENABLE; in adc_context_start_sampling()
214 data->buffer = data->repeat_buffer; in adc_context_update_buffer_pointer()
229 const struct adc_kb1200_config *config = dev->config; in adc_kb1200_init()
230 struct adc_kb1200_data *data = dev->data; in adc_kb1200_init()
233 adc_context_unlock_unconditionally(&data->ctx); in adc_kb1200_init()
234 /* Configure pin-mux for ADC device */ in adc_kb1200_init()
235 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in adc_kb1200_init()