2020-07-17 19:43:19 -07:00
|
|
|
/*
|
2020-09-09 20:57:44 -07:00
|
|
|
* Copyright (c) 2020 The ZMK Contributors
|
2020-07-17 19:43:19 -07:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-10-07 21:46:08 -07:00
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/drivers/gpio.h>
|
|
|
|
#include <zephyr/sys/util.h>
|
2020-07-17 19:43:19 -07:00
|
|
|
|
2020-07-20 17:54:58 -07:00
|
|
|
struct ec11_config {
|
2023-01-17 17:40:44 -08:00
|
|
|
const struct gpio_dt_spec a;
|
|
|
|
const struct gpio_dt_spec b;
|
2020-07-20 17:54:58 -07:00
|
|
|
|
2021-12-02 07:07:29 -08:00
|
|
|
const uint16_t steps;
|
2020-12-02 08:41:57 -08:00
|
|
|
const uint8_t resolution;
|
2020-07-17 19:43:19 -07:00
|
|
|
};
|
|
|
|
|
2020-07-20 17:54:58 -07:00
|
|
|
struct ec11_data {
|
2020-12-02 08:41:57 -08:00
|
|
|
uint8_t ab_state;
|
|
|
|
int8_t pulses;
|
|
|
|
int8_t ticks;
|
|
|
|
int8_t delta;
|
2020-07-17 19:43:19 -07:00
|
|
|
|
2020-07-20 17:54:58 -07:00
|
|
|
#ifdef CONFIG_EC11_TRIGGER
|
2020-09-13 19:53:24 -07:00
|
|
|
struct gpio_callback a_gpio_cb;
|
|
|
|
struct gpio_callback b_gpio_cb;
|
2020-12-10 11:31:51 -08:00
|
|
|
const struct device *dev;
|
2020-07-17 19:43:19 -07:00
|
|
|
|
2020-09-13 19:53:24 -07:00
|
|
|
sensor_trigger_handler_t handler;
|
|
|
|
const struct sensor_trigger *trigger;
|
2020-07-17 19:43:19 -07:00
|
|
|
|
2020-07-20 17:54:58 -07:00
|
|
|
#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD)
|
2020-09-13 19:53:24 -07:00
|
|
|
K_THREAD_STACK_MEMBER(thread_stack, CONFIG_EC11_THREAD_STACK_SIZE);
|
|
|
|
struct k_sem gpio_sem;
|
|
|
|
struct k_thread thread;
|
2020-07-20 17:54:58 -07:00
|
|
|
#elif defined(CONFIG_EC11_TRIGGER_GLOBAL_THREAD)
|
2020-09-13 19:53:24 -07:00
|
|
|
struct k_work work;
|
2020-07-17 19:43:19 -07:00
|
|
|
#endif
|
|
|
|
|
2020-07-20 17:54:58 -07:00
|
|
|
#endif /* CONFIG_EC11_TRIGGER */
|
2020-07-17 19:43:19 -07:00
|
|
|
};
|
|
|
|
|
2020-07-20 17:54:58 -07:00
|
|
|
#ifdef CONFIG_EC11_TRIGGER
|
2020-07-17 19:43:19 -07:00
|
|
|
|
2020-12-10 11:31:51 -08:00
|
|
|
int ec11_trigger_set(const struct device *dev, const struct sensor_trigger *trig,
|
2020-09-13 19:53:24 -07:00
|
|
|
sensor_trigger_handler_t handler);
|
2020-07-17 19:43:19 -07:00
|
|
|
|
2020-12-10 11:31:51 -08:00
|
|
|
int ec11_init_interrupt(const struct device *dev);
|
2020-07-17 19:43:19 -07:00
|
|
|
#endif
|