forked from kofal.net/zmk
refactor: Move away from deprecated label usages.
* Move away from DT_LABEL. * Move to DEVICE_DT_GET for non-behavior device access. * Move various drivers to `gpio_spec_dt` and `DT` related macros. * Remove mcp23017 while at it, since better upstream driver is available.
This commit is contained in:
committed by
Pete Johanson
parent
062f94d014
commit
09ed79a867
@@ -19,11 +19,9 @@
|
||||
LOG_MODULE_REGISTER(EC11, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
static int ec11_get_ab_state(const struct device *dev) {
|
||||
struct ec11_data *drv_data = dev->data;
|
||||
const struct ec11_config *drv_cfg = dev->config;
|
||||
|
||||
return (gpio_pin_get(drv_data->a, drv_cfg->a_pin) << 1) |
|
||||
gpio_pin_get(drv_data->b, drv_cfg->b_pin);
|
||||
return (gpio_pin_get_dt(&drv_cfg->a) << 1) | gpio_pin_get_dt(&drv_cfg->b);
|
||||
}
|
||||
|
||||
static int ec11_sample_fetch(const struct device *dev, enum sensor_channel chan) {
|
||||
@@ -94,27 +92,25 @@ int ec11_init(const struct device *dev) {
|
||||
struct ec11_data *drv_data = dev->data;
|
||||
const struct ec11_config *drv_cfg = dev->config;
|
||||
|
||||
LOG_DBG("A: %s %d B: %s %d resolution %d", drv_cfg->a_label, drv_cfg->a_pin, drv_cfg->b_label,
|
||||
drv_cfg->b_pin, drv_cfg->resolution);
|
||||
LOG_DBG("A: %s %d B: %s %d resolution %d", drv_cfg->a.port->name, drv_cfg->a.pin,
|
||||
drv_cfg->b.port->name, drv_cfg->b.pin, drv_cfg->resolution);
|
||||
|
||||
drv_data->a = device_get_binding(drv_cfg->a_label);
|
||||
if (drv_data->a == NULL) {
|
||||
LOG_ERR("Failed to get pointer to A GPIO device");
|
||||
if (!device_is_ready(drv_cfg->a.port)) {
|
||||
LOG_ERR("A GPIO device is not ready");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
drv_data->b = device_get_binding(drv_cfg->b_label);
|
||||
if (drv_data->b == NULL) {
|
||||
LOG_ERR("Failed to get pointer to B GPIO device");
|
||||
if (!device_is_ready(drv_cfg->b.port)) {
|
||||
LOG_ERR("B GPIO device is not ready");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (gpio_pin_configure(drv_data->a, drv_cfg->a_pin, drv_cfg->a_flags | GPIO_INPUT)) {
|
||||
if (gpio_pin_configure_dt(&drv_cfg->a, GPIO_INPUT)) {
|
||||
LOG_DBG("Failed to configure A pin");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (gpio_pin_configure(drv_data->b, drv_cfg->b_pin, drv_cfg->b_flags | GPIO_INPUT)) {
|
||||
if (gpio_pin_configure_dt(&drv_cfg->b, GPIO_INPUT)) {
|
||||
LOG_DBG("Failed to configure B pin");
|
||||
return -EIO;
|
||||
}
|
||||
@@ -134,12 +130,8 @@ int ec11_init(const struct device *dev) {
|
||||
#define EC11_INST(n) \
|
||||
struct ec11_data ec11_data_##n; \
|
||||
const struct ec11_config ec11_cfg_##n = { \
|
||||
.a_label = DT_INST_GPIO_LABEL(n, a_gpios), \
|
||||
.a_pin = DT_INST_GPIO_PIN(n, a_gpios), \
|
||||
.a_flags = DT_INST_GPIO_FLAGS(n, a_gpios), \
|
||||
.b_label = DT_INST_GPIO_LABEL(n, b_gpios), \
|
||||
.b_pin = DT_INST_GPIO_PIN(n, b_gpios), \
|
||||
.b_flags = DT_INST_GPIO_FLAGS(n, b_gpios), \
|
||||
.a = GPIO_DT_SPEC_INST_GET(n, a_gpios), \
|
||||
.b = GPIO_DT_SPEC_INST_GET(n, b_gpios), \
|
||||
COND_CODE_0(DT_INST_NODE_HAS_PROP(n, resolution), (1), (DT_INST_PROP(n, resolution))), \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(n, ec11_init, NULL, &ec11_data_##n, &ec11_cfg_##n, POST_KERNEL, \
|
||||
|
||||
@@ -11,20 +11,13 @@
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
struct ec11_config {
|
||||
const char *a_label;
|
||||
const uint8_t a_pin;
|
||||
const uint8_t a_flags;
|
||||
|
||||
const char *b_label;
|
||||
const uint8_t b_pin;
|
||||
const uint8_t b_flags;
|
||||
const struct gpio_dt_spec a;
|
||||
const struct gpio_dt_spec b;
|
||||
|
||||
const uint8_t resolution;
|
||||
};
|
||||
|
||||
struct ec11_data {
|
||||
const struct device *a;
|
||||
const struct device *b;
|
||||
uint8_t ab_state;
|
||||
int8_t pulses;
|
||||
int8_t ticks;
|
||||
|
||||
@@ -20,18 +20,15 @@ extern struct ec11_data ec11_driver;
|
||||
LOG_MODULE_DECLARE(EC11, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
static inline void setup_int(const struct device *dev, bool enable) {
|
||||
struct ec11_data *data = dev->data;
|
||||
const struct ec11_config *cfg = dev->config;
|
||||
|
||||
LOG_DBG("enabled %s", (enable ? "true" : "false"));
|
||||
|
||||
if (gpio_pin_interrupt_configure(data->a, cfg->a_pin,
|
||||
enable ? GPIO_INT_EDGE_BOTH : GPIO_INT_DISABLE)) {
|
||||
if (gpio_pin_interrupt_configure_dt(&cfg->a, enable ? GPIO_INT_EDGE_BOTH : GPIO_INT_DISABLE)) {
|
||||
LOG_WRN("Unable to set A pin GPIO interrupt");
|
||||
}
|
||||
|
||||
if (gpio_pin_interrupt_configure(data->b, cfg->b_pin,
|
||||
enable ? GPIO_INT_EDGE_BOTH : GPIO_INT_DISABLE)) {
|
||||
if (gpio_pin_interrupt_configure_dt(&cfg->b, enable ? GPIO_INT_EDGE_BOTH : GPIO_INT_DISABLE)) {
|
||||
LOG_WRN("Unable to set A pin GPIO interrupt");
|
||||
}
|
||||
}
|
||||
@@ -121,16 +118,16 @@ int ec11_init_interrupt(const struct device *dev) {
|
||||
drv_data->dev = dev;
|
||||
/* setup gpio interrupt */
|
||||
|
||||
gpio_init_callback(&drv_data->a_gpio_cb, ec11_a_gpio_callback, BIT(drv_cfg->a_pin));
|
||||
gpio_init_callback(&drv_data->a_gpio_cb, ec11_a_gpio_callback, BIT(drv_cfg->a.pin));
|
||||
|
||||
if (gpio_add_callback(drv_data->a, &drv_data->a_gpio_cb) < 0) {
|
||||
if (gpio_add_callback(drv_cfg->a.port, &drv_data->a_gpio_cb) < 0) {
|
||||
LOG_DBG("Failed to set A callback!");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
gpio_init_callback(&drv_data->b_gpio_cb, ec11_b_gpio_callback, BIT(drv_cfg->b_pin));
|
||||
gpio_init_callback(&drv_data->b_gpio_cb, ec11_b_gpio_callback, BIT(drv_cfg->b.pin));
|
||||
|
||||
if (gpio_add_callback(drv_data->b, &drv_data->b_gpio_cb) < 0) {
|
||||
if (gpio_add_callback(drv_cfg->b.port, &drv_data->b_gpio_cb) < 0) {
|
||||
LOG_DBG("Failed to set B callback!");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user