Lines Matching +full:polling +full:- +full:mode

4  * SPDX-License-Identifier: Apache-2.0
46 atomic_t polling; member
66 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_irq_setup()
71 const struct gpio_dt_spec *gpio = &cfg->ab_gpio[i]; in gpio_qdec_irq_setup()
83 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_idle_polling_mode()
85 if (cfg->idle_poll_time_us > 0) { in gpio_qdec_idle_polling_mode()
94 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_poll_mode()
95 struct gpio_qdec_data *data = dev->data; in gpio_qdec_poll_mode()
101 k_timer_start(&data->sample_timer, K_NO_WAIT, in gpio_qdec_poll_mode()
102 K_USEC(cfg->sample_time_us)); in gpio_qdec_poll_mode()
104 atomic_set(&data->polling, 1); in gpio_qdec_poll_mode()
106 LOG_DBG("polling start"); in gpio_qdec_poll_mode()
111 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_idle_mode()
112 struct gpio_qdec_data *data = dev->data; in gpio_qdec_idle_mode()
115 k_timer_start(&data->sample_timer, K_NO_WAIT, in gpio_qdec_idle_mode()
116 K_USEC(cfg->idle_poll_time_us)); in gpio_qdec_idle_mode()
118 k_timer_stop(&data->sample_timer); in gpio_qdec_idle_mode()
122 atomic_set(&data->polling, 0); in gpio_qdec_idle_mode()
124 LOG_DBG("polling stop"); in gpio_qdec_idle_mode()
129 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_get_step()
133 for (int i = 0; i < cfg->led_gpio_count; i++) { in gpio_qdec_get_step()
134 gpio_pin_set_dt(&cfg->led_gpio[i], 1); in gpio_qdec_get_step()
137 k_busy_wait(cfg->led_pre_us); in gpio_qdec_get_step()
140 if (gpio_pin_get_dt(&cfg->ab_gpio[0])) { in gpio_qdec_get_step()
143 if (gpio_pin_get_dt(&cfg->ab_gpio[1])) { in gpio_qdec_get_step()
148 for (int i = 0; i < cfg->led_gpio_count; i++) { in gpio_qdec_get_step()
149 gpio_pin_set_dt(&cfg->led_gpio[i], 0); in gpio_qdec_get_step()
159 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_sample_timer_timeout()
160 struct gpio_qdec_data *data = dev->data; in gpio_qdec_sample_timer_timeout()
166 if (atomic_get(&data->suspended) == 1) { in gpio_qdec_sample_timer_timeout()
173 if (data->prev_step == step) { in gpio_qdec_sample_timer_timeout()
178 atomic_get(&data->polling) == 0) { in gpio_qdec_sample_timer_timeout()
182 switch ((data->prev_step << 4U) | step) { in gpio_qdec_sample_timer_timeout()
193 delta = -1; in gpio_qdec_sample_timer_timeout()
196 LOG_WRN("%s: lost steps", dev->name); in gpio_qdec_sample_timer_timeout()
199 data->prev_step = step; in gpio_qdec_sample_timer_timeout()
202 data->acc += delta; in gpio_qdec_sample_timer_timeout()
205 if (abs(data->acc) >= cfg->steps_per_period) { in gpio_qdec_sample_timer_timeout()
206 k_work_submit(&data->event_work); in gpio_qdec_sample_timer_timeout()
209 k_work_reschedule(&data->idle_work, K_MSEC(cfg->idle_timeout_ms)); in gpio_qdec_sample_timer_timeout()
216 const struct device *dev = data->dev; in gpio_qdec_event_worker()
217 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_event_worker()
222 acc = data->acc / cfg->steps_per_period; in gpio_qdec_event_worker()
223 data->acc -= acc * cfg->steps_per_period; in gpio_qdec_event_worker()
227 input_report_rel(data->dev, cfg->axis, acc, true, K_FOREVER); in gpio_qdec_event_worker()
236 const struct device *dev = data->dev; in gpio_qdec_idle_worker()
246 const struct device *dev = data->dev; in gpio_qdec_cb()
253 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_init()
254 struct gpio_qdec_data *data = dev->data; in gpio_qdec_init()
257 data->dev = dev; in gpio_qdec_init()
259 k_work_init(&data->event_work, gpio_qdec_event_worker); in gpio_qdec_init()
260 k_work_init_delayable(&data->idle_work, gpio_qdec_idle_worker); in gpio_qdec_init()
262 k_timer_init(&data->sample_timer, gpio_qdec_sample_timer_timeout, NULL); in gpio_qdec_init()
263 k_timer_user_data_set(&data->sample_timer, (void *)dev); in gpio_qdec_init()
265 gpio_init_callback(&data->gpio_cb, gpio_qdec_cb, in gpio_qdec_init()
266 BIT(cfg->ab_gpio[0].pin) | BIT(cfg->ab_gpio[1].pin)); in gpio_qdec_init()
268 const struct gpio_dt_spec *gpio = &cfg->ab_gpio[i]; in gpio_qdec_init()
271 LOG_ERR("%s is not ready", gpio->port->name); in gpio_qdec_init()
272 return -ENODEV; in gpio_qdec_init()
285 ret = gpio_add_callback_dt(gpio, &data->gpio_cb); in gpio_qdec_init()
292 for (int i = 0; i < cfg->led_gpio_count; i++) { in gpio_qdec_init()
293 const struct gpio_dt_spec *gpio = &cfg->led_gpio[i]; in gpio_qdec_init()
294 gpio_flags_t mode; in gpio_qdec_init() local
297 LOG_ERR("%s is not ready", gpio->port->name); in gpio_qdec_init()
298 return -ENODEV; in gpio_qdec_init()
301 mode = gpio_qdec_idle_polling_mode(dev) ? in gpio_qdec_init()
304 ret = gpio_pin_configure_dt(gpio, mode); in gpio_qdec_init()
311 data->prev_step = gpio_qdec_get_step(dev); in gpio_qdec_init()
321 LOG_DBG("Device %s initialized", dev->name); in gpio_qdec_init()
329 const struct gpio_qdec_config *cfg = dev->config; in gpio_qdec_pin_suspend()
330 gpio_flags_t mode = suspend ? GPIO_DISCONNECTED : GPIO_INPUT; in gpio_qdec_pin_suspend() local
334 const struct gpio_dt_spec *gpio = &cfg->ab_gpio[i]; in gpio_qdec_pin_suspend()
336 ret = gpio_pin_configure_dt(gpio, mode); in gpio_qdec_pin_suspend()
343 for (int i = 0; i < cfg->led_gpio_count; i++) { in gpio_qdec_pin_suspend()
345 gpio_pin_set_dt(&cfg->led_gpio[i], 0); in gpio_qdec_pin_suspend()
347 gpio_pin_set_dt(&cfg->led_gpio[i], 1); in gpio_qdec_pin_suspend()
355 struct gpio_qdec_data *data = dev->data; in gpio_qdec_pm_action()
361 atomic_set(&data->suspended, 1); in gpio_qdec_pm_action()
363 k_work_cancel_delayable_sync(&data->idle_work, &sync); in gpio_qdec_pm_action()
369 k_timer_stop(&data->sample_timer); in gpio_qdec_pm_action()
375 atomic_set(&data->suspended, 0); in gpio_qdec_pm_action()
379 data->prev_step = gpio_qdec_get_step(dev); in gpio_qdec_pm_action()
380 data->acc = 0; in gpio_qdec_pm_action()
386 return -ENOTSUP; in gpio_qdec_pm_action()
400 "led-pre-us must be specified when setting led-gpios and " \
401 "idle-poll-time-us"); \