refactor(app): replace driver_data
with data
See: https://docs.zephyrproject.org/latest/releases/release-notes-2.4.html PR: #467
This commit is contained in:
parent
33c959d031
commit
1411092a7b
9 changed files with 45 additions and 45 deletions
|
@ -59,7 +59,7 @@ static void kscan_composite_child_callback(struct device *child_dev, uint32_t ro
|
||||||
bool pressed) {
|
bool pressed) {
|
||||||
// TODO: Ideally we can get this passed into our callback!
|
// TODO: Ideally we can get this passed into our callback!
|
||||||
struct device *dev = device_get_binding(DT_INST_LABEL(0));
|
struct device *dev = device_get_binding(DT_INST_LABEL(0));
|
||||||
struct kscan_composite_data *data = dev->driver_data;
|
struct kscan_composite_data *data = dev->data;
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(kscan_composite_children); i++) {
|
for (int i = 0; i < ARRAY_SIZE(kscan_composite_children); i++) {
|
||||||
const struct kscan_composite_child_config *cfg = &kscan_composite_children[i];
|
const struct kscan_composite_child_config *cfg = &kscan_composite_children[i];
|
||||||
|
@ -73,7 +73,7 @@ static void kscan_composite_child_callback(struct device *child_dev, uint32_t ro
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kscan_composite_configure(struct device *dev, kscan_callback_t callback) {
|
static int kscan_composite_configure(struct device *dev, kscan_callback_t callback) {
|
||||||
struct kscan_composite_data *data = dev->driver_data;
|
struct kscan_composite_data *data = dev->data;
|
||||||
|
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -91,7 +91,7 @@ static int kscan_composite_configure(struct device *dev, kscan_callback_t callba
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kscan_composite_init(struct device *dev) {
|
static int kscan_composite_init(struct device *dev) {
|
||||||
struct kscan_composite_data *data = dev->driver_data;
|
struct kscan_composite_data *data = dev->data;
|
||||||
|
|
||||||
data->dev = dev;
|
data->dev = dev;
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ struct kscan_gpio_item_config {
|
||||||
/* IO/GPIO SETUP */ \
|
/* IO/GPIO SETUP */ \
|
||||||
/* gpio_input_devices are PHYSICAL IO devices */ \
|
/* gpio_input_devices are PHYSICAL IO devices */ \
|
||||||
static struct device **kscan_gpio_input_devices_##n(struct device *dev) { \
|
static struct device **kscan_gpio_input_devices_##n(struct device *dev) { \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
return data->rows; \
|
return data->rows; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -80,7 +80,7 @@ struct kscan_gpio_item_config {
|
||||||
\
|
\
|
||||||
/* gpio_output_devices are PHYSICAL IO devices */ \
|
/* gpio_output_devices are PHYSICAL IO devices */ \
|
||||||
static struct device **kscan_gpio_output_devices_##n(struct device *dev) { \
|
static struct device **kscan_gpio_output_devices_##n(struct device *dev) { \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
return data->cols; \
|
return data->cols; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -101,7 +101,7 @@ struct kscan_gpio_item_config {
|
||||||
/* This is the core matrix_scan func */ \
|
/* This is the core matrix_scan func */ \
|
||||||
static int kscan_gpio_read_##n(struct device *dev) { \
|
static int kscan_gpio_read_##n(struct device *dev) { \
|
||||||
bool submit_follow_up_read = false; \
|
bool submit_follow_up_read = false; \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
static bool read_state[INST_MATRIX_INPUTS(n)][INST_MATRIX_OUTPUTS(n)]; \
|
static bool read_state[INST_MATRIX_INPUTS(n)][INST_MATRIX_OUTPUTS(n)]; \
|
||||||
for (int o = 0; o < INST_MATRIX_OUTPUTS(n); o++) { \
|
for (int o = 0; o < INST_MATRIX_OUTPUTS(n); o++) { \
|
||||||
/* Iterate over bits and set GPIOs accordingly */ \
|
/* Iterate over bits and set GPIOs accordingly */ \
|
||||||
|
@ -153,7 +153,7 @@ struct kscan_gpio_item_config {
|
||||||
/* KSCAN API configure function */ \
|
/* KSCAN API configure function */ \
|
||||||
static int kscan_gpio_configure_##n(struct device *dev, kscan_callback_t callback) { \
|
static int kscan_gpio_configure_##n(struct device *dev, kscan_callback_t callback) { \
|
||||||
LOG_DBG("KSCAN API configure"); \
|
LOG_DBG("KSCAN API configure"); \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
if (!callback) { \
|
if (!callback) { \
|
||||||
return -EINVAL; \
|
return -EINVAL; \
|
||||||
} \
|
} \
|
||||||
|
@ -165,7 +165,7 @@ struct kscan_gpio_item_config {
|
||||||
/* KSCAN API enable function */ \
|
/* KSCAN API enable function */ \
|
||||||
static int kscan_gpio_enable_##n(struct device *dev) { \
|
static int kscan_gpio_enable_##n(struct device *dev) { \
|
||||||
LOG_DBG("KSCAN API enable"); \
|
LOG_DBG("KSCAN API enable"); \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
/* TODO: we might want a follow up to hook into the sleep state hooks in Zephyr, */ \
|
/* TODO: we might want a follow up to hook into the sleep state hooks in Zephyr, */ \
|
||||||
/* and disable this timer when we enter a sleep state */ \
|
/* and disable this timer when we enter a sleep state */ \
|
||||||
k_timer_start(&data->poll_timer, K_MSEC(POLL_INTERVAL(n)), K_MSEC(POLL_INTERVAL(n))); \
|
k_timer_start(&data->poll_timer, K_MSEC(POLL_INTERVAL(n)), K_MSEC(POLL_INTERVAL(n))); \
|
||||||
|
@ -175,7 +175,7 @@ struct kscan_gpio_item_config {
|
||||||
/* KSCAN API disable function */ \
|
/* KSCAN API disable function */ \
|
||||||
static int kscan_gpio_disable_##n(struct device *dev) { \
|
static int kscan_gpio_disable_##n(struct device *dev) { \
|
||||||
LOG_DBG("KSCAN API disable"); \
|
LOG_DBG("KSCAN API disable"); \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
k_timer_stop(&data->poll_timer); \
|
k_timer_stop(&data->poll_timer); \
|
||||||
return 0; \
|
return 0; \
|
||||||
}; \
|
}; \
|
||||||
|
@ -183,7 +183,7 @@ struct kscan_gpio_item_config {
|
||||||
/* GPIO init function*/ \
|
/* GPIO init function*/ \
|
||||||
static int kscan_gpio_init_##n(struct device *dev) { \
|
static int kscan_gpio_init_##n(struct device *dev) { \
|
||||||
LOG_DBG("KSCAN GPIO init"); \
|
LOG_DBG("KSCAN GPIO init"); \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
int err; \
|
int err; \
|
||||||
/* configure input devices*/ \
|
/* configure input devices*/ \
|
||||||
struct device **input_devices = kscan_gpio_input_devices_##n(dev); \
|
struct device **input_devices = kscan_gpio_input_devices_##n(dev); \
|
||||||
|
|
|
@ -44,7 +44,7 @@ struct kscan_gpio_data {
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct device **kscan_gpio_input_devices(struct device *dev) {
|
static struct device **kscan_gpio_input_devices(struct device *dev) {
|
||||||
struct kscan_gpio_data *data = dev->driver_data;
|
struct kscan_gpio_data *data = dev->data;
|
||||||
return data->inputs;
|
return data->inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,12 +116,12 @@ static void kscan_gpio_timer_handler(struct k_timer *timer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kscan_gpio_direct_enable(struct device *dev) {
|
static int kscan_gpio_direct_enable(struct device *dev) {
|
||||||
struct kscan_gpio_data *data = dev->driver_data;
|
struct kscan_gpio_data *data = dev->data;
|
||||||
k_timer_start(&data->poll_timer, K_MSEC(10), K_MSEC(10));
|
k_timer_start(&data->poll_timer, K_MSEC(10), K_MSEC(10));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int kscan_gpio_direct_disable(struct device *dev) {
|
static int kscan_gpio_direct_disable(struct device *dev) {
|
||||||
struct kscan_gpio_data *data = dev->driver_data;
|
struct kscan_gpio_data *data = dev->data;
|
||||||
k_timer_stop(&data->poll_timer);
|
k_timer_stop(&data->poll_timer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ static int kscan_gpio_direct_disable(struct device *dev) {
|
||||||
#endif /* defined(CONFIG_ZMK_KSCAN_DIRECT_POLLING) */
|
#endif /* defined(CONFIG_ZMK_KSCAN_DIRECT_POLLING) */
|
||||||
|
|
||||||
static int kscan_gpio_direct_configure(struct device *dev, kscan_callback_t callback) {
|
static int kscan_gpio_direct_configure(struct device *dev, kscan_callback_t callback) {
|
||||||
struct kscan_gpio_data *data = dev->driver_data;
|
struct kscan_gpio_data *data = dev->data;
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ static int kscan_gpio_direct_configure(struct device *dev, kscan_callback_t call
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kscan_gpio_read(struct device *dev) {
|
static int kscan_gpio_read(struct device *dev) {
|
||||||
struct kscan_gpio_data *data = dev->driver_data;
|
struct kscan_gpio_data *data = dev->data;
|
||||||
const struct kscan_gpio_config *cfg = dev->config;
|
const struct kscan_gpio_config *cfg = dev->config;
|
||||||
uint32_t read_state = data->pin_state;
|
uint32_t read_state = data->pin_state;
|
||||||
bool submit_follow_up_read = false;
|
bool submit_follow_up_read = false;
|
||||||
|
@ -195,7 +195,7 @@ static const struct kscan_driver_api gpio_driver_api = {
|
||||||
static struct kscan_gpio_data kscan_gpio_data_##n = { \
|
static struct kscan_gpio_data kscan_gpio_data_##n = { \
|
||||||
.inputs = {[INST_INPUT_LEN(n) - 1] = NULL}}; \
|
.inputs = {[INST_INPUT_LEN(n) - 1] = NULL}}; \
|
||||||
static int kscan_gpio_init_##n(struct device *dev) { \
|
static int kscan_gpio_init_##n(struct device *dev) { \
|
||||||
struct kscan_gpio_data *data = dev->driver_data; \
|
struct kscan_gpio_data *data = dev->data; \
|
||||||
const struct kscan_gpio_config *cfg = dev->config; \
|
const struct kscan_gpio_config *cfg = dev->config; \
|
||||||
int err; \
|
int err; \
|
||||||
struct device **input_devices = kscan_gpio_input_devices(dev); \
|
struct device **input_devices = kscan_gpio_input_devices(dev); \
|
||||||
|
|
|
@ -81,7 +81,7 @@ static int kscan_gpio_config_interrupts(struct device **devices,
|
||||||
struct device *dev; \
|
struct device *dev; \
|
||||||
}; \
|
}; \
|
||||||
static struct device **kscan_gpio_input_devices_##n(struct device *dev) { \
|
static struct device **kscan_gpio_input_devices_##n(struct device *dev) { \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
return (COND_CODE_0(DT_ENUM_IDX(DT_DRV_INST(n), diode_direction), (data->cols), \
|
return (COND_CODE_0(DT_ENUM_IDX(DT_DRV_INST(n), diode_direction), (data->cols), \
|
||||||
(data->rows))); \
|
(data->rows))); \
|
||||||
} \
|
} \
|
||||||
|
@ -91,7 +91,7 @@ static int kscan_gpio_config_interrupts(struct device **devices,
|
||||||
COND_CODE_0(DT_ENUM_IDX(DT_DRV_INST(n), diode_direction), (cfg->cols), (cfg->rows)))); \
|
COND_CODE_0(DT_ENUM_IDX(DT_DRV_INST(n), diode_direction), (cfg->cols), (cfg->rows)))); \
|
||||||
} \
|
} \
|
||||||
static struct device **kscan_gpio_output_devices_##n(struct device *dev) { \
|
static struct device **kscan_gpio_output_devices_##n(struct device *dev) { \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
return (COND_CODE_0(DT_ENUM_IDX(DT_DRV_INST(n), diode_direction), (data->rows), \
|
return (COND_CODE_0(DT_ENUM_IDX(DT_DRV_INST(n), diode_direction), (data->rows), \
|
||||||
(data->cols))); \
|
(data->cols))); \
|
||||||
} \
|
} \
|
||||||
|
@ -132,7 +132,7 @@ static int kscan_gpio_config_interrupts(struct device **devices,
|
||||||
} \
|
} \
|
||||||
static int kscan_gpio_read_##n(struct device *dev) { \
|
static int kscan_gpio_read_##n(struct device *dev) { \
|
||||||
bool submit_follow_up_read = false; \
|
bool submit_follow_up_read = false; \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
static bool read_state[INST_MATRIX_ROWS(n)][INST_MATRIX_COLS(n)]; \
|
static bool read_state[INST_MATRIX_ROWS(n)][INST_MATRIX_COLS(n)]; \
|
||||||
/* Disable our interrupts temporarily while we scan, to avoid */ \
|
/* Disable our interrupts temporarily while we scan, to avoid */ \
|
||||||
/* re-entry while we iterate columns and set them active one by one */ \
|
/* re-entry while we iterate columns and set them active one by one */ \
|
||||||
|
@ -197,7 +197,7 @@ static int kscan_gpio_config_interrupts(struct device **devices,
|
||||||
static struct kscan_gpio_data_##n kscan_gpio_data_##n = { \
|
static struct kscan_gpio_data_##n kscan_gpio_data_##n = { \
|
||||||
.rows = {[INST_MATRIX_ROWS(n) - 1] = NULL}, .cols = {[INST_MATRIX_COLS(n) - 1] = NULL}}; \
|
.rows = {[INST_MATRIX_ROWS(n) - 1] = NULL}, .cols = {[INST_MATRIX_COLS(n) - 1] = NULL}}; \
|
||||||
static int kscan_gpio_configure_##n(struct device *dev, kscan_callback_t callback) { \
|
static int kscan_gpio_configure_##n(struct device *dev, kscan_callback_t callback) { \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
if (!callback) { \
|
if (!callback) { \
|
||||||
return -EINVAL; \
|
return -EINVAL; \
|
||||||
} \
|
} \
|
||||||
|
@ -207,14 +207,14 @@ static int kscan_gpio_config_interrupts(struct device **devices,
|
||||||
}; \
|
}; \
|
||||||
static int kscan_gpio_enable_##n(struct device *dev) { \
|
static int kscan_gpio_enable_##n(struct device *dev) { \
|
||||||
COND_CODE_1(CONFIG_ZMK_KSCAN_MATRIX_POLLING, \
|
COND_CODE_1(CONFIG_ZMK_KSCAN_MATRIX_POLLING, \
|
||||||
(struct kscan_gpio_data_##n *data = dev->driver_data; \
|
(struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
k_timer_start(&data->poll_timer, K_MSEC(10), K_MSEC(10)); return 0;), \
|
k_timer_start(&data->poll_timer, K_MSEC(10), K_MSEC(10)); return 0;), \
|
||||||
(int err = kscan_gpio_enable_interrupts_##n(dev); \
|
(int err = kscan_gpio_enable_interrupts_##n(dev); \
|
||||||
if (err) { return err; } return kscan_gpio_read_##n(dev);)) \
|
if (err) { return err; } return kscan_gpio_read_##n(dev);)) \
|
||||||
}; \
|
}; \
|
||||||
static int kscan_gpio_disable_##n(struct device *dev) { \
|
static int kscan_gpio_disable_##n(struct device *dev) { \
|
||||||
COND_CODE_1(CONFIG_ZMK_KSCAN_MATRIX_POLLING, \
|
COND_CODE_1(CONFIG_ZMK_KSCAN_MATRIX_POLLING, \
|
||||||
(struct kscan_gpio_data_##n *data = dev->driver_data; \
|
(struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
k_timer_stop(&data->poll_timer); return 0;), \
|
k_timer_stop(&data->poll_timer); return 0;), \
|
||||||
(return kscan_gpio_disable_interrupts_##n(dev);)) \
|
(return kscan_gpio_disable_interrupts_##n(dev);)) \
|
||||||
}; \
|
}; \
|
||||||
|
@ -226,7 +226,7 @@ static int kscan_gpio_config_interrupts(struct device **devices,
|
||||||
}), \
|
}), \
|
||||||
()) \
|
()) \
|
||||||
static int kscan_gpio_init_##n(struct device *dev) { \
|
static int kscan_gpio_init_##n(struct device *dev) { \
|
||||||
struct kscan_gpio_data_##n *data = dev->driver_data; \
|
struct kscan_gpio_data_##n *data = dev->data; \
|
||||||
int err; \
|
int err; \
|
||||||
struct device **input_devices = kscan_gpio_input_devices_##n(dev); \
|
struct device **input_devices = kscan_gpio_input_devices_##n(dev); \
|
||||||
for (int i = 0; i < INST_INPUT_LEN(n); i++) { \
|
for (int i = 0; i < INST_INPUT_LEN(n); i++) { \
|
||||||
|
|
|
@ -24,14 +24,14 @@ struct kscan_mock_data {
|
||||||
};
|
};
|
||||||
|
|
||||||
static int kscan_mock_disable_callback(struct device *dev) {
|
static int kscan_mock_disable_callback(struct device *dev) {
|
||||||
struct kscan_mock_data *data = dev->driver_data;
|
struct kscan_mock_data *data = dev->data;
|
||||||
|
|
||||||
k_delayed_work_cancel(&data->work);
|
k_delayed_work_cancel(&data->work);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kscan_mock_configure(struct device *dev, kscan_callback_t callback) {
|
static int kscan_mock_configure(struct device *dev, kscan_callback_t callback) {
|
||||||
struct kscan_mock_data *data = dev->driver_data;
|
struct kscan_mock_data *data = dev->data;
|
||||||
|
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -49,7 +49,7 @@ static int kscan_mock_configure(struct device *dev, kscan_callback_t callback) {
|
||||||
bool exit_after; \
|
bool exit_after; \
|
||||||
}; \
|
}; \
|
||||||
static void kscan_mock_schedule_next_event_##n(struct device *dev) { \
|
static void kscan_mock_schedule_next_event_##n(struct device *dev) { \
|
||||||
struct kscan_mock_data *data = dev->driver_data; \
|
struct kscan_mock_data *data = dev->data; \
|
||||||
const struct kscan_mock_config_##n *cfg = dev->config; \
|
const struct kscan_mock_config_##n *cfg = dev->config; \
|
||||||
if (data->event_index < DT_INST_PROP_LEN(n, events)) { \
|
if (data->event_index < DT_INST_PROP_LEN(n, events)) { \
|
||||||
uint32_t ev = cfg->events[data->event_index]; \
|
uint32_t ev = cfg->events[data->event_index]; \
|
||||||
|
@ -71,7 +71,7 @@ static int kscan_mock_configure(struct device *dev, kscan_callback_t callback) {
|
||||||
data->event_index++; \
|
data->event_index++; \
|
||||||
} \
|
} \
|
||||||
static int kscan_mock_init_##n(struct device *dev) { \
|
static int kscan_mock_init_##n(struct device *dev) { \
|
||||||
struct kscan_mock_data *data = dev->driver_data; \
|
struct kscan_mock_data *data = dev->data; \
|
||||||
data->dev = dev; \
|
data->dev = dev; \
|
||||||
k_delayed_work_init(&data->work, kscan_mock_work_handler_##n); \
|
k_delayed_work_init(&data->work, kscan_mock_work_handler_##n); \
|
||||||
return 0; \
|
return 0; \
|
||||||
|
|
|
@ -56,7 +56,7 @@ static uint8_t lithium_ion_mv_to_pct(int16_t bat_mv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) {
|
static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) {
|
||||||
struct bvd_data *drv_data = dev->driver_data;
|
struct bvd_data *drv_data = dev->data;
|
||||||
const struct bvd_config *drv_cfg = dev->config;
|
const struct bvd_config *drv_cfg = dev->config;
|
||||||
struct adc_sequence *as = &drv_data->as;
|
struct adc_sequence *as = &drv_data->as;
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bvd_channel_get(struct device *dev, enum sensor_channel chan, struct sensor_value *val) {
|
static int bvd_channel_get(struct device *dev, enum sensor_channel chan, struct sensor_value *val) {
|
||||||
struct bvd_data *drv_data = dev->driver_data;
|
struct bvd_data *drv_data = dev->data;
|
||||||
|
|
||||||
switch (chan) {
|
switch (chan) {
|
||||||
case SENSOR_CHAN_GAUGE_VOLTAGE:
|
case SENSOR_CHAN_GAUGE_VOLTAGE:
|
||||||
|
@ -140,7 +140,7 @@ static const struct sensor_driver_api bvd_api = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static int bvd_init(struct device *dev) {
|
static int bvd_init(struct device *dev) {
|
||||||
struct bvd_data *drv_data = dev->driver_data;
|
struct bvd_data *drv_data = dev->data;
|
||||||
const struct bvd_config *drv_cfg = dev->config;
|
const struct bvd_config *drv_cfg = dev->config;
|
||||||
|
|
||||||
drv_data->adc = device_get_binding(drv_cfg->io_channel.label);
|
drv_data->adc = device_get_binding(drv_cfg->io_channel.label);
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
LOG_MODULE_REGISTER(EC11, CONFIG_SENSOR_LOG_LEVEL);
|
LOG_MODULE_REGISTER(EC11, CONFIG_SENSOR_LOG_LEVEL);
|
||||||
|
|
||||||
static int ec11_get_ab_state(struct device *dev) {
|
static int ec11_get_ab_state(struct device *dev) {
|
||||||
struct ec11_data *drv_data = dev->driver_data;
|
struct ec11_data *drv_data = dev->data;
|
||||||
const struct ec11_config *drv_cfg = dev->config;
|
const struct ec11_config *drv_cfg = dev->config;
|
||||||
|
|
||||||
return (gpio_pin_get(drv_data->a, drv_cfg->a_pin) << 1) |
|
return (gpio_pin_get(drv_data->a, drv_cfg->a_pin) << 1) |
|
||||||
|
@ -27,7 +27,7 @@ static int ec11_get_ab_state(struct device *dev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan) {
|
static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan) {
|
||||||
struct ec11_data *drv_data = dev->driver_data;
|
struct ec11_data *drv_data = dev->data;
|
||||||
const struct ec11_config *drv_cfg = dev->config;
|
const struct ec11_config *drv_cfg = dev->config;
|
||||||
uint8_t val;
|
uint8_t val;
|
||||||
int8_t delta;
|
int8_t delta;
|
||||||
|
@ -70,7 +70,7 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan) {
|
||||||
|
|
||||||
static int ec11_channel_get(struct device *dev, enum sensor_channel chan,
|
static int ec11_channel_get(struct device *dev, enum sensor_channel chan,
|
||||||
struct sensor_value *val) {
|
struct sensor_value *val) {
|
||||||
struct ec11_data *drv_data = dev->driver_data;
|
struct ec11_data *drv_data = dev->data;
|
||||||
|
|
||||||
if (chan != SENSOR_CHAN_ROTATION) {
|
if (chan != SENSOR_CHAN_ROTATION) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
@ -91,7 +91,7 @@ static const struct sensor_driver_api ec11_driver_api = {
|
||||||
};
|
};
|
||||||
|
|
||||||
int ec11_init(struct device *dev) {
|
int ec11_init(struct device *dev) {
|
||||||
struct ec11_data *drv_data = dev->driver_data;
|
struct ec11_data *drv_data = dev->data;
|
||||||
const struct ec11_config *drv_cfg = dev->config;
|
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,
|
LOG_DBG("A: %s %d B: %s %d resolution %d", drv_cfg->a_label, drv_cfg->a_pin, drv_cfg->b_label,
|
||||||
|
|
|
@ -20,7 +20,7 @@ extern struct ec11_data ec11_driver;
|
||||||
LOG_MODULE_DECLARE(EC11, CONFIG_SENSOR_LOG_LEVEL);
|
LOG_MODULE_DECLARE(EC11, CONFIG_SENSOR_LOG_LEVEL);
|
||||||
|
|
||||||
static inline void setup_int(struct device *dev, bool enable) {
|
static inline void setup_int(struct device *dev, bool enable) {
|
||||||
struct ec11_data *data = dev->driver_data;
|
struct ec11_data *data = dev->data;
|
||||||
const struct ec11_config *cfg = dev->config;
|
const struct ec11_config *cfg = dev->config;
|
||||||
|
|
||||||
LOG_DBG("enabled %s", (enable ? "true" : "false"));
|
LOG_DBG("enabled %s", (enable ? "true" : "false"));
|
||||||
|
@ -66,7 +66,7 @@ static void ec11_b_gpio_callback(struct device *dev, struct gpio_callback *cb, u
|
||||||
|
|
||||||
static void ec11_thread_cb(void *arg) {
|
static void ec11_thread_cb(void *arg) {
|
||||||
struct device *dev = arg;
|
struct device *dev = arg;
|
||||||
struct ec11_data *drv_data = dev->driver_data;
|
struct ec11_data *drv_data = dev->data;
|
||||||
|
|
||||||
drv_data->handler(dev, drv_data->trigger);
|
drv_data->handler(dev, drv_data->trigger);
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ static void ec11_thread_cb(void *arg) {
|
||||||
#ifdef CONFIG_EC11_TRIGGER_OWN_THREAD
|
#ifdef CONFIG_EC11_TRIGGER_OWN_THREAD
|
||||||
static void ec11_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 ec11_data *drv_data = dev->driver_data;
|
struct ec11_data *drv_data = dev->data;
|
||||||
|
|
||||||
ARG_UNUSED(unused);
|
ARG_UNUSED(unused);
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ static void ec11_work_cb(struct k_work *work) {
|
||||||
|
|
||||||
int ec11_trigger_set(struct device *dev, const struct sensor_trigger *trig,
|
int ec11_trigger_set(struct device *dev, const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler) {
|
sensor_trigger_handler_t handler) {
|
||||||
struct ec11_data *drv_data = dev->driver_data;
|
struct ec11_data *drv_data = dev->data;
|
||||||
|
|
||||||
setup_int(dev, false);
|
setup_int(dev, false);
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ int ec11_trigger_set(struct device *dev, const struct sensor_trigger *trig,
|
||||||
}
|
}
|
||||||
|
|
||||||
int ec11_init_interrupt(struct device *dev) {
|
int ec11_init_interrupt(struct device *dev) {
|
||||||
struct ec11_data *drv_data = dev->driver_data;
|
struct ec11_data *drv_data = dev->data;
|
||||||
const struct ec11_config *drv_cfg = dev->config;
|
const struct ec11_config *drv_cfg = dev->config;
|
||||||
|
|
||||||
drv_data->dev = dev;
|
drv_data->dev = dev;
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct ext_power_generic_data {
|
||||||
static void ext_power_save_state_work(struct k_work *work) {
|
static void ext_power_save_state_work(struct k_work *work) {
|
||||||
char setting_path[40];
|
char setting_path[40];
|
||||||
struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
|
struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
|
||||||
struct ext_power_generic_data *data = ext_power->driver_data;
|
struct ext_power_generic_data *data = ext_power->data;
|
||||||
|
|
||||||
snprintf(setting_path, 40, "ext_power/state/%s", DT_INST_LABEL(0));
|
snprintf(setting_path, 40, "ext_power/state/%s", DT_INST_LABEL(0));
|
||||||
settings_save_one(setting_path, &data->status, sizeof(data->status));
|
settings_save_one(setting_path, &data->status, sizeof(data->status));
|
||||||
|
@ -56,7 +56,7 @@ int ext_power_save_state() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ext_power_generic_enable(struct device *dev) {
|
static int ext_power_generic_enable(struct device *dev) {
|
||||||
struct ext_power_generic_data *data = dev->driver_data;
|
struct ext_power_generic_data *data = dev->data;
|
||||||
const struct ext_power_generic_config *config = dev->config;
|
const struct ext_power_generic_config *config = dev->config;
|
||||||
|
|
||||||
if (gpio_pin_set(data->gpio, config->pin, 1)) {
|
if (gpio_pin_set(data->gpio, config->pin, 1)) {
|
||||||
|
@ -68,7 +68,7 @@ static int ext_power_generic_enable(struct device *dev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ext_power_generic_disable(struct device *dev) {
|
static int ext_power_generic_disable(struct device *dev) {
|
||||||
struct ext_power_generic_data *data = dev->driver_data;
|
struct ext_power_generic_data *data = dev->data;
|
||||||
const struct ext_power_generic_config *config = dev->config;
|
const struct ext_power_generic_config *config = dev->config;
|
||||||
|
|
||||||
if (gpio_pin_set(data->gpio, config->pin, 0)) {
|
if (gpio_pin_set(data->gpio, config->pin, 0)) {
|
||||||
|
@ -80,7 +80,7 @@ static int ext_power_generic_disable(struct device *dev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ext_power_generic_get(struct device *dev) {
|
static int ext_power_generic_get(struct device *dev) {
|
||||||
struct ext_power_generic_data *data = dev->driver_data;
|
struct ext_power_generic_data *data = dev->data;
|
||||||
return data->status;
|
return data->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ static int ext_power_settings_set(const char *name, size_t len, settings_read_cb
|
||||||
|
|
||||||
if (settings_name_steq(name, DT_INST_LABEL(0), &next) && !next) {
|
if (settings_name_steq(name, DT_INST_LABEL(0), &next) && !next) {
|
||||||
struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
|
struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
|
||||||
struct ext_power_generic_data *data = ext_power->driver_data;
|
struct ext_power_generic_data *data = ext_power->data;
|
||||||
|
|
||||||
if (len != sizeof(data->status)) {
|
if (len != sizeof(data->status)) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -125,7 +125,7 @@ struct settings_handler ext_power_conf = {.name = "ext_power/state",
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int ext_power_generic_init(struct device *dev) {
|
static int ext_power_generic_init(struct device *dev) {
|
||||||
struct ext_power_generic_data *data = dev->driver_data;
|
struct ext_power_generic_data *data = dev->data;
|
||||||
const struct ext_power_generic_config *config = dev->config;
|
const struct ext_power_generic_config *config = dev->config;
|
||||||
|
|
||||||
data->gpio = device_get_binding(config->label);
|
data->gpio = device_get_binding(config->label);
|
||||||
|
|
Loading…
Reference in a new issue