|
|
@ -4,7 +4,7 @@ |
|
|
|
* SPDX-License-Identifier: Apache-2.0 |
|
|
|
* SPDX-License-Identifier: Apache-2.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#define DT_DRV_COMPAT alps_en11 |
|
|
|
#define DT_DRV_COMPAT alps_ec11 |
|
|
|
|
|
|
|
|
|
|
|
#include <device.h> |
|
|
|
#include <device.h> |
|
|
|
#include <drivers/gpio.h> |
|
|
|
#include <drivers/gpio.h> |
|
|
@ -12,18 +12,18 @@ |
|
|
|
#include <kernel.h> |
|
|
|
#include <kernel.h> |
|
|
|
#include <drivers/sensor.h> |
|
|
|
#include <drivers/sensor.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "en11.h" |
|
|
|
#include "ec11.h" |
|
|
|
|
|
|
|
|
|
|
|
extern struct en11_data en11_driver; |
|
|
|
extern struct ec11_data ec11_driver; |
|
|
|
|
|
|
|
|
|
|
|
#include <logging/log.h> |
|
|
|
#include <logging/log.h> |
|
|
|
LOG_MODULE_DECLARE(EN11, CONFIG_SENSOR_LOG_LEVEL); |
|
|
|
LOG_MODULE_DECLARE(EC11, CONFIG_SENSOR_LOG_LEVEL); |
|
|
|
|
|
|
|
|
|
|
|
static inline void setup_int(struct device *dev, |
|
|
|
static inline void setup_int(struct device *dev, |
|
|
|
bool enable) |
|
|
|
bool enable) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct en11_data *data = dev->driver_data; |
|
|
|
struct ec11_data *data = dev->driver_data; |
|
|
|
const struct en11_config *cfg = dev->config_info; |
|
|
|
const struct ec11_config *cfg = dev->config_info; |
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("enabled %s", (enable ? "true" : "false")); |
|
|
|
LOG_DBG("enabled %s", (enable ? "true" : "false")); |
|
|
|
|
|
|
|
|
|
|
@ -44,59 +44,60 @@ static inline void setup_int(struct device *dev, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void en11_a_gpio_callback(struct device *dev, |
|
|
|
static void ec11_a_gpio_callback(struct device *dev, |
|
|
|
struct gpio_callback *cb, u32_t pins) |
|
|
|
struct gpio_callback *cb, u32_t pins) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct en11_data *drv_data = |
|
|
|
struct ec11_data *drv_data = |
|
|
|
CONTAINER_OF(cb, struct en11_data, a_gpio_cb); |
|
|
|
CONTAINER_OF(cb, struct ec11_data, a_gpio_cb); |
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG(""); |
|
|
|
LOG_DBG(""); |
|
|
|
|
|
|
|
|
|
|
|
setup_int(drv_data->dev, false); |
|
|
|
setup_int(drv_data->dev, false); |
|
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) |
|
|
|
#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD) |
|
|
|
k_sem_give(&drv_data->gpio_sem); |
|
|
|
k_sem_give(&drv_data->gpio_sem); |
|
|
|
#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) |
|
|
|
#elif defined(CONFIG_EC11_TRIGGER_GLOBAL_THREAD) |
|
|
|
k_work_submit(&drv_data->work); |
|
|
|
k_work_submit(&drv_data->work); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void en11_b_gpio_callback(struct device *dev, |
|
|
|
static void ec11_b_gpio_callback(struct device *dev, |
|
|
|
struct gpio_callback *cb, u32_t pins) |
|
|
|
struct gpio_callback *cb, u32_t pins) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct en11_data *drv_data = |
|
|
|
struct ec11_data *drv_data = |
|
|
|
CONTAINER_OF(cb, struct en11_data, b_gpio_cb); |
|
|
|
CONTAINER_OF(cb, struct ec11_data, b_gpio_cb); |
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG(""); |
|
|
|
LOG_DBG(""); |
|
|
|
|
|
|
|
|
|
|
|
setup_int(drv_data->dev, false); |
|
|
|
setup_int(drv_data->dev, false); |
|
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) |
|
|
|
#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD) |
|
|
|
k_sem_give(&drv_data->gpio_sem); |
|
|
|
k_sem_give(&drv_data->gpio_sem); |
|
|
|
#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) |
|
|
|
#elif defined(CONFIG_EC11_TRIGGER_GLOBAL_THREAD) |
|
|
|
k_work_submit(&drv_data->work); |
|
|
|
k_work_submit(&drv_data->work); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void en11_thread_cb(void *arg) |
|
|
|
static void ec11_thread_cb(void *arg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct device *dev = arg; |
|
|
|
struct device *dev = arg; |
|
|
|
struct en11_data *drv_data = dev->driver_data; |
|
|
|
struct ec11_data *drv_data = dev->driver_data; |
|
|
|
const struct en11_config *cfg = dev->config_info; |
|
|
|
const struct ec11_config *cfg = dev->config_info; |
|
|
|
u16_t status; |
|
|
|
u16_t status; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drv_data->handler(dev, &drv_data->trigger); |
|
|
|
// gpio_pin_get(drv_data->a, cfg->a_pin)
|
|
|
|
// gpio_pin_get(drv_data->a, cfg->a_pin)
|
|
|
|
|
|
|
|
|
|
|
|
// if (en11_reg_read(drv_data, EN11_REG_STATUS, &status) < 0) {
|
|
|
|
// if (ec11_reg_read(drv_data, EC11_REG_STATUS, &status) < 0) {
|
|
|
|
// return;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// if (status & EN11_DATA_READY_INT_BIT &&
|
|
|
|
// if (status & EC11_DATA_READY_INT_BIT &&
|
|
|
|
// drv_data->drdy_handler != NULL) {
|
|
|
|
// drv_data->drdy_handler != NULL) {
|
|
|
|
// drv_data->drdy_handler(dev, &drv_data->drdy_trigger);
|
|
|
|
// drv_data->drdy_handler(dev, &drv_data->drdy_trigger);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// if (status & EN11_TOBJ_TH_INT_BITS &&
|
|
|
|
// if (status & EC11_TOBJ_TH_INT_BITS &&
|
|
|
|
// drv_data->th_handler != NULL) {
|
|
|
|
// drv_data->th_handler != NULL) {
|
|
|
|
// drv_data->th_handler(dev, &drv_data->th_trigger);
|
|
|
|
// drv_data->th_handler(dev, &drv_data->th_trigger);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
@ -104,41 +105,43 @@ static void en11_thread_cb(void *arg) |
|
|
|
setup_int(dev, true); |
|
|
|
setup_int(dev, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_EN11_TRIGGER_OWN_THREAD |
|
|
|
#ifdef CONFIG_EC11_TRIGGER_OWN_THREAD |
|
|
|
static void en11_thread(int dev_ptr, int unused) |
|
|
|
static void ec11_thread(int dev_ptr, int unused) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct device *dev = INT_TO_POINTER(dev_ptr); |
|
|
|
struct device *dev = INT_TO_POINTER(dev_ptr); |
|
|
|
struct en11_data *drv_data = dev->driver_data; |
|
|
|
struct ec11_data *drv_data = dev->driver_data; |
|
|
|
|
|
|
|
|
|
|
|
ARG_UNUSED(unused); |
|
|
|
ARG_UNUSED(unused); |
|
|
|
|
|
|
|
|
|
|
|
while (1) { |
|
|
|
while (1) { |
|
|
|
k_sem_take(&drv_data->gpio_sem, K_FOREVER); |
|
|
|
k_sem_take(&drv_data->gpio_sem, K_FOREVER); |
|
|
|
en11_thread_cb(dev); |
|
|
|
ec11_thread_cb(dev); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_EN11_TRIGGER_GLOBAL_THREAD |
|
|
|
#ifdef CONFIG_EC11_TRIGGER_GLOBAL_THREAD |
|
|
|
static void en11_work_cb(struct k_work *work) |
|
|
|
static void ec11_work_cb(struct k_work *work) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct en11_data *drv_data = |
|
|
|
struct ec11_data *drv_data = |
|
|
|
CONTAINER_OF(work, struct en11_data, work); |
|
|
|
CONTAINER_OF(work, struct ec11_data, work); |
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG(""); |
|
|
|
LOG_DBG(""); |
|
|
|
|
|
|
|
|
|
|
|
en11_thread_cb(drv_data->dev); |
|
|
|
ec11_thread_cb(drv_data->dev); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
int en11_trigger_set(struct device *dev, |
|
|
|
int ec11_trigger_set(struct device *dev, |
|
|
|
const struct sensor_trigger *trig, |
|
|
|
const struct sensor_trigger *trig, |
|
|
|
sensor_trigger_handler_t handler) |
|
|
|
sensor_trigger_handler_t handler) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct en11_data *drv_data = dev->driver_data; |
|
|
|
struct ec11_data *drv_data = dev->driver_data; |
|
|
|
|
|
|
|
|
|
|
|
setup_int(dev, false); |
|
|
|
setup_int(dev, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k_msleep(5); |
|
|
|
|
|
|
|
|
|
|
|
drv_data->trigger = *trig; |
|
|
|
drv_data->trigger = *trig; |
|
|
|
drv_data->handler = handler; |
|
|
|
drv_data->handler = handler; |
|
|
|
|
|
|
|
|
|
|
@ -147,10 +150,10 @@ int en11_trigger_set(struct device *dev, |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int en11_init_interrupt(struct device *dev) |
|
|
|
int ec11_init_interrupt(struct device *dev) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct en11_data *drv_data = dev->driver_data; |
|
|
|
struct ec11_data *drv_data = dev->driver_data; |
|
|
|
const struct en11_config *drv_cfg = dev->config_info; |
|
|
|
const struct ec11_config *drv_cfg = dev->config_info; |
|
|
|
|
|
|
|
|
|
|
|
drv_data->dev = dev; |
|
|
|
drv_data->dev = dev; |
|
|
|
/* setup gpio interrupt */ |
|
|
|
/* setup gpio interrupt */ |
|
|
@ -165,7 +168,7 @@ int en11_init_interrupt(struct device *dev) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gpio_init_callback(&drv_data->a_gpio_cb, |
|
|
|
gpio_init_callback(&drv_data->a_gpio_cb, |
|
|
|
en11_a_gpio_callback, |
|
|
|
ec11_a_gpio_callback, |
|
|
|
BIT(drv_cfg->a_pin)); |
|
|
|
BIT(drv_cfg->a_pin)); |
|
|
|
|
|
|
|
|
|
|
|
if (gpio_add_callback(drv_data->a, &drv_data->a_gpio_cb) < 0) { |
|
|
|
if (gpio_add_callback(drv_data->a, &drv_data->a_gpio_cb) < 0) { |
|
|
@ -181,7 +184,7 @@ int en11_init_interrupt(struct device *dev) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gpio_init_callback(&drv_data->b_gpio_cb, |
|
|
|
gpio_init_callback(&drv_data->b_gpio_cb, |
|
|
|
en11_b_gpio_callback, |
|
|
|
ec11_b_gpio_callback, |
|
|
|
BIT(drv_cfg->b_pin)); |
|
|
|
BIT(drv_cfg->b_pin)); |
|
|
|
|
|
|
|
|
|
|
|
if (gpio_add_callback(drv_data->b, &drv_data->b_gpio_cb) < 0) { |
|
|
|
if (gpio_add_callback(drv_data->b, &drv_data->b_gpio_cb) < 0) { |
|
|
@ -191,16 +194,16 @@ int en11_init_interrupt(struct device *dev) |
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("A Pin? %d, B Pin? %d", gpio_pin_get(drv_data->a, drv_cfg->a_pin), gpio_pin_get(drv_data->b, drv_cfg->b_pin)); |
|
|
|
LOG_DBG("A Pin? %d, B Pin? %d", gpio_pin_get(drv_data->a, drv_cfg->a_pin), gpio_pin_get(drv_data->b, drv_cfg->b_pin)); |
|
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) |
|
|
|
#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD) |
|
|
|
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX); |
|
|
|
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX); |
|
|
|
|
|
|
|
|
|
|
|
k_thread_create(&drv_data->thread, drv_data->thread_stack, |
|
|
|
k_thread_create(&drv_data->thread, drv_data->thread_stack, |
|
|
|
CONFIG_EN11_THREAD_STACK_SIZE, |
|
|
|
CONFIG_EC11_THREAD_STACK_SIZE, |
|
|
|
(k_thread_entry_t)en11_thread, dev, |
|
|
|
(k_thread_entry_t)ec11_thread, dev, |
|
|
|
0, NULL, K_PRIO_COOP(CONFIG_EN11_THREAD_PRIORITY), |
|
|
|
0, NULL, K_PRIO_COOP(CONFIG_EC11_THREAD_PRIORITY), |
|
|
|
0, K_NO_WAIT); |
|
|
|
0, K_NO_WAIT); |
|
|
|
#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) |
|
|
|
#elif defined(CONFIG_EC11_TRIGGER_GLOBAL_THREAD) |
|
|
|
drv_data->work.handler = en11_work_cb; |
|
|
|
k_work_init(&drv_data->work, ec11_work_cb); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |