Lines Matching +full:wakeup +full:- +full:controller

4  * SPDX-License-Identifier: Apache-2.0
55 struct k_sem wakeup; member
61 const struct analog_axis_config *cfg = dev->config; in analog_axis_num_axes()
63 return cfg->num_channels; in analog_axis_num_axes()
70 const struct analog_axis_config *cfg = dev->config; in analog_axis_calibration_get()
71 struct analog_axis_data *data = dev->data; in analog_axis_calibration_get()
72 struct analog_axis_calibration *cal = &cfg->calibration[channel]; in analog_axis_calibration_get()
74 if (channel >= cfg->num_channels) { in analog_axis_calibration_get()
75 return -EINVAL; in analog_axis_calibration_get()
78 k_sem_take(&data->cal_lock, K_FOREVER); in analog_axis_calibration_get()
80 k_sem_give(&data->cal_lock); in analog_axis_calibration_get()
87 struct analog_axis_data *data = dev->data; in analog_axis_set_raw_data_cb()
89 k_sem_take(&data->cal_lock, K_FOREVER); in analog_axis_set_raw_data_cb()
90 data->raw_data_cb = cb; in analog_axis_set_raw_data_cb()
91 k_sem_give(&data->cal_lock); in analog_axis_set_raw_data_cb()
98 const struct analog_axis_config *cfg = dev->config; in analog_axis_calibration_set()
99 struct analog_axis_data *data = dev->data; in analog_axis_calibration_set()
100 struct analog_axis_calibration *cal = &cfg->calibration[channel]; in analog_axis_calibration_set()
102 if (channel >= cfg->num_channels) { in analog_axis_calibration_set()
103 return -EINVAL; in analog_axis_calibration_set()
106 k_sem_take(&data->cal_lock, K_FOREVER); in analog_axis_calibration_set()
108 k_sem_give(&data->cal_lock); in analog_axis_calibration_set()
117 const struct analog_axis_config *cfg = dev->config; in analog_axis_out_deadzone()
118 const struct analog_axis_channel_config *axis_cfg = &cfg->channel_cfg[channel]; in analog_axis_out_deadzone()
119 struct analog_axis_calibration *cal = &cfg->calibration[channel]; in analog_axis_out_deadzone()
121 int16_t in_range = cal->in_max - cal->in_min; in analog_axis_out_deadzone()
122 int16_t out_range = axis_cfg->out_max - axis_cfg->out_min; in analog_axis_out_deadzone()
123 int16_t in_mid = DIV_ROUND_CLOSEST(cal->in_min + cal->in_max, 2); in analog_axis_out_deadzone()
124 int16_t in_min = cal->in_min; in analog_axis_out_deadzone()
126 if (abs(raw_val - in_mid) < cal->in_deadzone) { in analog_axis_out_deadzone()
127 return DIV_ROUND_CLOSEST(axis_cfg->out_max + axis_cfg->out_min, 2); in analog_axis_out_deadzone()
130 in_range -= cal->in_deadzone * 2; in analog_axis_out_deadzone()
131 in_min += cal->in_deadzone; in analog_axis_out_deadzone()
133 raw_val += cal->in_deadzone; in analog_axis_out_deadzone()
135 raw_val -= cal->in_deadzone; in analog_axis_out_deadzone()
138 return DIV_ROUND_CLOSEST((raw_val - in_min) * out_range, in_range) + axis_cfg->out_min; in analog_axis_out_deadzone()
145 const struct analog_axis_config *cfg = dev->config; in analog_axis_out_linear()
146 const struct analog_axis_channel_config *axis_cfg = &cfg->channel_cfg[channel]; in analog_axis_out_linear()
147 struct analog_axis_calibration *cal = &cfg->calibration[channel]; in analog_axis_out_linear()
149 int16_t in_range = cal->in_max - cal->in_min; in analog_axis_out_linear()
150 int16_t out_range = axis_cfg->out_max - axis_cfg->out_min; in analog_axis_out_linear()
152 return DIV_ROUND_CLOSEST((raw_val - cal->in_min) * out_range, in_range) + axis_cfg->out_min; in analog_axis_out_linear()
157 const struct analog_axis_config *cfg = dev->config; in analog_axis_loop()
158 struct analog_axis_data *data = dev->data; in analog_axis_loop()
159 int16_t bufs[cfg->num_channels]; in analog_axis_loop()
165 const struct analog_axis_channel_config *axis_cfg_0 = &cfg->channel_cfg[0]; in analog_axis_loop()
169 adc_sequence_init_dt(&axis_cfg_0->adc, &sequence); in analog_axis_loop()
171 for (i = 0; i < cfg->num_channels; i++) { in analog_axis_loop()
172 const struct analog_axis_channel_config *axis_cfg = &cfg->channel_cfg[i]; in analog_axis_loop()
174 sequence.channels |= BIT(axis_cfg->adc.channel_id); in analog_axis_loop()
177 err = adc_read(axis_cfg_0->adc.dev, &sequence); in analog_axis_loop()
183 k_sem_take(&data->cal_lock, K_FOREVER); in analog_axis_loop()
185 for (i = 0; i < cfg->num_channels; i++) { in analog_axis_loop()
186 const struct analog_axis_channel_config *axis_cfg = &cfg->channel_cfg[i]; in analog_axis_loop()
187 struct analog_axis_channel_data *axis_data = &cfg->channel_data[i]; in analog_axis_loop()
188 struct analog_axis_calibration *cal = &cfg->calibration[i]; in analog_axis_loop()
191 if (axis_cfg->invert_input) { in analog_axis_loop()
192 raw_val *= -1; in analog_axis_loop()
195 if (data->raw_data_cb != NULL) { in analog_axis_loop()
196 data->raw_data_cb(dev, i, raw_val); in analog_axis_loop()
199 LOG_DBG("%s: ch %d: raw_val: %d", dev->name, i, raw_val); in analog_axis_loop()
201 if (cal->in_deadzone > 0) { in analog_axis_loop()
207 out = CLAMP(out, axis_cfg->out_min, axis_cfg->out_max); in analog_axis_loop()
209 if (axis_cfg->invert_output) { in analog_axis_loop()
210 out = axis_cfg->out_max - out; in analog_axis_loop()
213 if (axis_data->last_out != out) { in analog_axis_loop()
214 input_report_abs(dev, axis_cfg->axis, out, true, K_FOREVER); in analog_axis_loop()
216 axis_data->last_out = out; in analog_axis_loop()
219 k_sem_give(&data->cal_lock); in analog_axis_loop()
225 const struct analog_axis_config *cfg = dev->config; in analog_axis_thread()
226 struct analog_axis_data *data = dev->data; in analog_axis_thread()
230 for (i = 0; i < cfg->num_channels; i++) { in analog_axis_thread()
231 const struct analog_axis_channel_config *axis_cfg = &cfg->channel_cfg[i]; in analog_axis_thread()
233 if (!adc_is_ready_dt(&axis_cfg->adc)) { in analog_axis_thread()
234 LOG_ERR("ADC controller device not ready"); in analog_axis_thread()
238 err = adc_channel_setup_dt(&axis_cfg->adc); in analog_axis_thread()
247 if (atomic_get(&data->suspended) == 1) { in analog_axis_thread()
248 k_sem_take(&data->wakeup, K_FOREVER); in analog_axis_thread()
253 k_timer_status_sync(&data->timer); in analog_axis_thread()
259 struct analog_axis_data *data = dev->data; in analog_axis_init()
262 k_sem_init(&data->cal_lock, 1, 1); in analog_axis_init()
263 k_timer_init(&data->timer, NULL, NULL); in analog_axis_init()
266 k_sem_init(&data->wakeup, 0, 1); in analog_axis_init()
269 tid = k_thread_create(&data->thread, data->thread_stack, in analog_axis_init()
270 K_KERNEL_STACK_SIZEOF(data->thread_stack), in analog_axis_init()
276 return -ENODEV; in analog_axis_init()
279 k_thread_name_set(&data->thread, dev->name); in analog_axis_init()
282 const struct analog_axis_config *cfg = dev->config; in analog_axis_init()
284 k_timer_start(&data->timer, in analog_axis_init()
285 K_MSEC(cfg->poll_period_ms), K_MSEC(cfg->poll_period_ms)); in analog_axis_init()
289 atomic_set(&data->suspended, 1); in analog_axis_init()
306 const struct analog_axis_config *cfg = dev->config; in analog_axis_pm_action()
307 struct analog_axis_data *data = dev->data; in analog_axis_pm_action()
311 atomic_set(&data->suspended, 1); in analog_axis_pm_action()
312 k_timer_stop(&data->timer); in analog_axis_pm_action()
315 k_timer_start(&data->timer, in analog_axis_pm_action()
316 K_MSEC(cfg->poll_period_ms), in analog_axis_pm_action()
317 K_MSEC(cfg->poll_period_ms)); in analog_axis_pm_action()
318 atomic_set(&data->suspended, 0); in analog_axis_pm_action()
319 k_sem_give(&data->wakeup); in analog_axis_pm_action()
322 return -ENOTSUP; in analog_axis_pm_action()