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
@@ -74,8 +74,8 @@ void activity_work_handler(struct k_work *work) {
|
||||
} else
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_SLEEP) */
|
||||
if (inactive_time > MAX_IDLE_MS) {
|
||||
set_state(ZMK_ACTIVITY_IDLE);
|
||||
}
|
||||
set_state(ZMK_ACTIVITY_IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
K_WORK_DEFINE(activity_work, activity_work_handler);
|
||||
|
||||
@@ -28,8 +28,8 @@ static void behavior_queue_process_next(struct k_work *work) {
|
||||
struct q_item item = {.wait = 0};
|
||||
|
||||
while (k_msgq_get(&zmk_behavior_queue_msgq, &item, K_NO_WAIT) == 0) {
|
||||
LOG_DBG("Invoking %s: 0x%02x 0x%02x", item.binding.behavior_dev,
|
||||
item.binding.param1, item.binding.param2);
|
||||
LOG_DBG("Invoking %s: 0x%02x 0x%02x", item.binding.behavior_dev, item.binding.param1,
|
||||
item.binding.param2);
|
||||
|
||||
struct zmk_behavior_binding_event event = {.position = item.position,
|
||||
.timestamp = k_uptime_get()};
|
||||
|
||||
@@ -16,7 +16,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
#include <dt-bindings/zmk/bt.h>
|
||||
#include <zmk/behavior.h>
|
||||
|
||||
|
||||
#include <zmk/ble.h>
|
||||
|
||||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
|
||||
|
||||
@@ -166,9 +166,10 @@ static int behavior_caps_word_init(const struct device *dev) {
|
||||
#define CAPS_WORD_LABEL(i, _n) DT_INST_LABEL(i)
|
||||
|
||||
#define PARSE_BREAK(i) \
|
||||
{.page = ZMK_HID_USAGE_PAGE(i), \
|
||||
.id = ZMK_HID_USAGE_ID(i), \
|
||||
.implicit_modifiers = SELECT_MODS(i)}
|
||||
{ \
|
||||
.page = ZMK_HID_USAGE_PAGE(i), .id = ZMK_HID_USAGE_ID(i), \
|
||||
.implicit_modifiers = SELECT_MODS(i) \
|
||||
}
|
||||
|
||||
#define BREAK_ITEM(i, n) PARSE_BREAK(DT_INST_PROP_BY_IDX(n, continue_list, i))
|
||||
|
||||
@@ -177,7 +178,7 @@ static int behavior_caps_word_init(const struct device *dev) {
|
||||
static struct behavior_caps_word_config behavior_caps_word_config_##n = { \
|
||||
.index = n, \
|
||||
.mods = DT_INST_PROP_OR(n, mods, MOD_LSFT), \
|
||||
.continuations = {LISTIFY(DT_INST_PROP_LEN(n, continue_list), BREAK_ITEM, (,), n)}, \
|
||||
.continuations = {LISTIFY(DT_INST_PROP_LEN(n, continue_list), BREAK_ITEM, (, ), n)}, \
|
||||
.continuations_count = DT_INST_PROP_LEN(n, continue_list), \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(n, behavior_caps_word_init, NULL, &behavior_caps_word_data_##n, \
|
||||
|
||||
@@ -700,8 +700,8 @@ static int behavior_hold_tap_init(const struct device *dev) {
|
||||
#define KP_INST(n) \
|
||||
static struct behavior_hold_tap_config behavior_hold_tap_config_##n = { \
|
||||
.tapping_term_ms = DT_INST_PROP(n, tapping_term_ms), \
|
||||
.hold_behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(n, bindings, 0)), \
|
||||
.tap_behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(n, bindings, 1)), \
|
||||
.hold_behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 0), label), \
|
||||
.tap_behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 1), label), \
|
||||
.quick_tap_ms = DT_INST_PROP(n, quick_tap_ms), \
|
||||
.global_quick_tap = DT_INST_PROP(n, global_quick_tap), \
|
||||
.flavor = DT_ENUM_IDX(DT_DRV_INST(n), flavor), \
|
||||
|
||||
@@ -44,13 +44,13 @@ struct behavior_macro_config {
|
||||
struct zmk_behavior_binding bindings[];
|
||||
};
|
||||
|
||||
#define TAP_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_tap))
|
||||
#define PRESS_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_press))
|
||||
#define REL_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_release))
|
||||
#define TAP_MODE DT_PROP(DT_INST(0, zmk_macro_control_mode_tap), label)
|
||||
#define PRESS_MODE DT_PROP(DT_INST(0, zmk_macro_control_mode_press), label)
|
||||
#define REL_MODE DT_PROP(DT_INST(0, zmk_macro_control_mode_release), label)
|
||||
|
||||
#define TAP_TIME DT_LABEL(DT_INST(0, zmk_macro_control_tap_time))
|
||||
#define WAIT_TIME DT_LABEL(DT_INST(0, zmk_macro_control_wait_time))
|
||||
#define WAIT_REL DT_LABEL(DT_INST(0, zmk_macro_pause_for_release))
|
||||
#define TAP_TIME DT_PROP(DT_INST(0, zmk_macro_control_tap_time), label)
|
||||
#define WAIT_TIME DT_PROP(DT_INST(0, zmk_macro_control_wait_time), label)
|
||||
#define WAIT_REL DT_PROP(DT_INST(0, zmk_macro_pause_for_release), label)
|
||||
|
||||
#define ZM_IS_NODE_MATCH(a, b) (strcmp(a, b) == 0)
|
||||
#define IS_TAP_MODE(dev) ZM_IS_NODE_MATCH(dev, TAP_MODE)
|
||||
@@ -169,7 +169,7 @@ static const struct behavior_driver_api behavior_macro_driver_api = {
|
||||
#define BINDING_WITH_COMMA(idx, drv_inst) ZMK_KEYMAP_EXTRACT_BINDING(idx, DT_DRV_INST(drv_inst))
|
||||
|
||||
#define TRANSFORMED_BEHAVIORS(n) \
|
||||
{LISTIFY(DT_PROP_LEN(DT_DRV_INST(n), bindings), BINDING_WITH_COMMA, (,), n)},
|
||||
{LISTIFY(DT_PROP_LEN(DT_DRV_INST(n), bindings), BINDING_WITH_COMMA, (, ), n)},
|
||||
|
||||
#define MACRO_INST(n) \
|
||||
static struct behavior_macro_state behavior_macro_state_##n = {}; \
|
||||
|
||||
@@ -81,7 +81,7 @@ static int behavior_mod_morph_init(const struct device *dev) { return 0; }
|
||||
|
||||
#define _TRANSFORM_ENTRY(idx, node) \
|
||||
{ \
|
||||
.behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(node, bindings, idx)), \
|
||||
.behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(node, bindings, idx), label), \
|
||||
.param1 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param1), (0), \
|
||||
(DT_INST_PHA_BY_IDX(node, bindings, idx, param1))), \
|
||||
.param2 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param2), (0), \
|
||||
|
||||
@@ -240,7 +240,7 @@ static int behavior_tap_dance_init(const struct device *dev) {
|
||||
#define _TRANSFORM_ENTRY(idx, node) ZMK_KEYMAP_EXTRACT_BINDING(idx, node)
|
||||
|
||||
#define TRANSFORMED_BINDINGS(node) \
|
||||
{ LISTIFY(DT_INST_PROP_LEN(node, bindings), _TRANSFORM_ENTRY, (,), DT_DRV_INST(node)) }
|
||||
{ LISTIFY(DT_INST_PROP_LEN(node, bindings), _TRANSFORM_ENTRY, (, ), DT_DRV_INST(node)) }
|
||||
|
||||
#define KP_INST(n) \
|
||||
static struct zmk_behavior_binding \
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
#include <drivers/display.h>
|
||||
#include <zephyr/drivers/display.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "theme.h"
|
||||
@@ -21,9 +21,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
#include <zmk/events/activity_state_changed.h>
|
||||
#include <zmk/display/status_screen.h>
|
||||
|
||||
#define ZMK_DISPLAY_NAME CONFIG_LV_Z_DISPLAY_DEV_NAME
|
||||
|
||||
static const struct device *display;
|
||||
static const struct device *display = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
|
||||
static bool initialized = false;
|
||||
|
||||
static lv_obj_t *screen;
|
||||
@@ -103,8 +101,7 @@ static void initialize_theme() {
|
||||
void initialize_display(struct k_work *work) {
|
||||
LOG_DBG("");
|
||||
|
||||
display = device_get_binding(ZMK_DISPLAY_NAME);
|
||||
if (display == NULL) {
|
||||
if (!device_is_ready(display)) {
|
||||
LOG_ERR("Failed to find display device");
|
||||
return;
|
||||
}
|
||||
@@ -165,4 +162,4 @@ int display_event_handler(const zmk_event_t *eh) {
|
||||
ZMK_LISTENER(display, display_event_handler);
|
||||
ZMK_SUBSCRIPTION(display, zmk_activity_state_changed);
|
||||
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_DISPLAY_BLANK_ON_IDLE) */
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_DISPLAY_BLANK_ON_IDLE) */
|
||||
|
||||
@@ -22,14 +22,11 @@
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
struct ext_power_generic_config {
|
||||
const char *label;
|
||||
const uint8_t pin;
|
||||
const uint8_t flags;
|
||||
const struct gpio_dt_spec control;
|
||||
const uint16_t init_delay_ms;
|
||||
};
|
||||
|
||||
struct ext_power_generic_data {
|
||||
const struct device *gpio;
|
||||
bool status;
|
||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||
bool settings_init;
|
||||
@@ -39,10 +36,10 @@ struct ext_power_generic_data {
|
||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||
static void ext_power_save_state_work(struct k_work *work) {
|
||||
char setting_path[40];
|
||||
const struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
|
||||
const struct device *ext_power = DEVICE_DT_GET(DT_DRV_INST(0));
|
||||
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_PROP(0, label));
|
||||
settings_save_one(setting_path, &data->status, sizeof(data->status));
|
||||
}
|
||||
|
||||
@@ -62,7 +59,7 @@ static int ext_power_generic_enable(const struct device *dev) {
|
||||
struct ext_power_generic_data *data = dev->data;
|
||||
const struct ext_power_generic_config *config = dev->config;
|
||||
|
||||
if (gpio_pin_set(data->gpio, config->pin, 1)) {
|
||||
if (gpio_pin_set_dt(&config->control, 1)) {
|
||||
LOG_WRN("Failed to set ext-power control pin");
|
||||
return -EIO;
|
||||
}
|
||||
@@ -74,7 +71,8 @@ static int ext_power_generic_disable(const struct device *dev) {
|
||||
struct ext_power_generic_data *data = dev->data;
|
||||
const struct ext_power_generic_config *config = dev->config;
|
||||
|
||||
if (gpio_pin_set(data->gpio, config->pin, 0)) {
|
||||
if (gpio_pin_set_dt(&config->control, 0)) {
|
||||
LOG_WRN("Failed to set ext-power control pin");
|
||||
LOG_WRN("Failed to clear ext-power control pin");
|
||||
return -EIO;
|
||||
}
|
||||
@@ -93,7 +91,7 @@ static int ext_power_settings_set(const char *name, size_t len, settings_read_cb
|
||||
const char *next;
|
||||
int rc;
|
||||
|
||||
if (settings_name_steq(name, DT_INST_LABEL(0), &next) && !next) {
|
||||
if (settings_name_steq(name, DT_INST_PROP(0, label), &next) && !next) {
|
||||
const struct device *ext_power = DEVICE_DT_GET(DT_DRV_INST(0));
|
||||
struct ext_power_generic_data *data = ext_power->data;
|
||||
|
||||
@@ -106,7 +104,7 @@ static int ext_power_settings_set(const char *name, size_t len, settings_read_cb
|
||||
data->settings_init = true;
|
||||
|
||||
if (ext_power == NULL) {
|
||||
LOG_ERR("Unable to retrieve ext_power device: %s", DT_INST_LABEL(0));
|
||||
LOG_ERR("Unable to retrieve ext_power device: %s", DT_INST_PROP(0, label));
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
@@ -131,13 +129,7 @@ static int ext_power_generic_init(const struct device *dev) {
|
||||
struct ext_power_generic_data *data = dev->data;
|
||||
const struct ext_power_generic_config *config = dev->config;
|
||||
|
||||
data->gpio = device_get_binding(config->label);
|
||||
if (data->gpio == NULL) {
|
||||
LOG_ERR("Failed to get ext-power control device");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (gpio_pin_configure(data->gpio, config->pin, config->flags | GPIO_OUTPUT)) {
|
||||
if (gpio_pin_configure_dt(&config->control, GPIO_OUTPUT_INACTIVE)) {
|
||||
LOG_ERR("Failed to configure ext-power control pin");
|
||||
return -EIO;
|
||||
}
|
||||
@@ -190,9 +182,7 @@ static int ext_power_generic_pm_action(const struct device *dev, enum pm_device_
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
static const struct ext_power_generic_config config = {
|
||||
.label = DT_INST_GPIO_LABEL(0, control_gpios),
|
||||
.pin = DT_INST_GPIO_PIN(0, control_gpios),
|
||||
.flags = DT_INST_GPIO_FLAGS(0, control_gpios),
|
||||
.control = GPIO_DT_SPEC_INST_GET(0, control_gpios),
|
||||
.init_delay_ms = DT_INST_PROP_OR(0, init_delay_ms, 0)};
|
||||
|
||||
static struct ext_power_generic_data data = {
|
||||
|
||||
@@ -42,7 +42,7 @@ static uint8_t _zmk_keymap_layer_default = 0;
|
||||
#if ZMK_KEYMAP_HAS_SENSORS
|
||||
#define _TRANSFORM_SENSOR_ENTRY(idx, layer) \
|
||||
{ \
|
||||
.behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(layer, sensor_bindings, idx)), \
|
||||
.behavior_dev = DT_PROP(DT_PHANDLE_BY_IDX(layer, sensor_bindings, idx), label), \
|
||||
.param1 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(layer, sensor_bindings, idx, param1), (0), \
|
||||
(DT_PHA_BY_IDX(layer, sensor_bindings, idx, param1))), \
|
||||
.param2 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(layer, sensor_bindings, idx, param2), (0), \
|
||||
@@ -57,7 +57,8 @@ static uint8_t _zmk_keymap_layer_default = 0;
|
||||
|
||||
#endif /* ZMK_KEYMAP_HAS_SENSORS */
|
||||
|
||||
#define LAYER_LABEL(node) COND_CODE_0(DT_NODE_HAS_PROP(node, label), (NULL), (DT_LABEL(node))),
|
||||
#define LAYER_LABEL(node) \
|
||||
COND_CODE_0(DT_NODE_HAS_PROP(node, label), (NULL), (DT_PROP(node, label))),
|
||||
|
||||
// State
|
||||
|
||||
|
||||
@@ -58,8 +58,7 @@ void zmk_kscan_process_msgq(struct k_work *item) {
|
||||
}
|
||||
}
|
||||
|
||||
int zmk_kscan_init(char *name) {
|
||||
const struct device *dev = device_get_binding(name);
|
||||
int zmk_kscan_init(const struct device *dev) {
|
||||
if (dev == NULL) {
|
||||
LOG_ERR("Failed to get the KSCAN device");
|
||||
return -EINVAL;
|
||||
|
||||
@@ -17,12 +17,10 @@ LOG_MODULE_REGISTER(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
#include <zmk/display.h>
|
||||
#include <drivers/ext_power.h>
|
||||
|
||||
#define ZMK_KSCAN_DEV DT_LABEL(ZMK_MATRIX_NODE_ID)
|
||||
|
||||
void main(void) {
|
||||
LOG_INF("Welcome to ZMK!\n");
|
||||
|
||||
if (zmk_kscan_init(ZMK_KSCAN_DEV) != 0) {
|
||||
if (zmk_kscan_init(DEVICE_DT_GET(ZMK_MATRIX_NODE_ID)) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,14 @@
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
#define STRIP_LABEL DT_LABEL(DT_CHOSEN(zmk_underglow))
|
||||
#define STRIP_NUM_PIXELS DT_PROP(DT_CHOSEN(zmk_underglow), chain_length)
|
||||
#if !DT_CHOSEN(zmk_underglow)
|
||||
|
||||
#error "A zmk,underglow chosen node must be declared"
|
||||
|
||||
#endif
|
||||
|
||||
#define STRIP_CHOSEN DT_CHOSEN(zmk_underglow)
|
||||
#define STRIP_NUM_PIXELS DT_PROP(STRIP_CHOSEN, chain_length)
|
||||
|
||||
#define HUE_MAX 360
|
||||
#define SAT_MAX 100
|
||||
@@ -230,13 +236,7 @@ static struct k_work_delayable underglow_save_work;
|
||||
#endif
|
||||
|
||||
static int zmk_rgb_underglow_init(const struct device *_arg) {
|
||||
led_strip = device_get_binding(STRIP_LABEL);
|
||||
if (led_strip) {
|
||||
LOG_INF("Found LED strip device %s", STRIP_LABEL);
|
||||
} else {
|
||||
LOG_ERR("LED strip device %s not found", STRIP_LABEL);
|
||||
return -EINVAL;
|
||||
}
|
||||
led_strip = DEVICE_DT_GET(STRIP_CHOSEN);
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER)
|
||||
ext_power = device_get_binding("EXT_POWER");
|
||||
|
||||
@@ -65,7 +65,8 @@ static void zmk_sensors_init_item(const char *node, uint8_t i, uint8_t abs_i) {
|
||||
sensor_trigger_set(sensors[i].dev, &sensors[i].trigger, zmk_sensors_trigger_handler);
|
||||
}
|
||||
|
||||
#define _SENSOR_INIT(node) zmk_sensors_init_item(DT_LABEL(node), local_index++, absolute_index++);
|
||||
#define _SENSOR_INIT(node) \
|
||||
zmk_sensors_init_item(DT_PROP(node, label), local_index++, absolute_index++);
|
||||
#define SENSOR_INIT(idx, _i) \
|
||||
COND_CODE_1(DT_NODE_HAS_STATUS(ZMK_KEYMAP_SENSORS_BY_IDX(idx), okay), \
|
||||
(_SENSOR_INIT(ZMK_KEYMAP_SENSORS_BY_IDX(idx))), (absolute_index++;))
|
||||
|
||||
@@ -377,8 +377,7 @@ static bool split_central_eir_found(struct bt_data *data, void *user_data) {
|
||||
bt_uuid_to_str(&uuid.uuid, uuid_str, sizeof(uuid_str));
|
||||
bt_uuid_to_str(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_SERVICE_UUID), service_uuid_str,
|
||||
sizeof(service_uuid_str));
|
||||
LOG_DBG("UUID %s does not match split UUID: %s", uuid_str,
|
||||
service_uuid_str);
|
||||
LOG_DBG("UUID %s does not match split UUID: %s", uuid_str, service_uuid_str);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -433,8 +432,7 @@ static void split_central_device_found(const bt_addr_le_t *addr, int8_t rssi, ui
|
||||
char dev[BT_ADDR_LE_STR_LEN];
|
||||
|
||||
bt_addr_le_to_str(addr, dev, sizeof(dev));
|
||||
LOG_DBG("[DEVICE]: %s, AD evt type %u, AD data len %u, RSSI %i", dev, type, ad->len,
|
||||
rssi);
|
||||
LOG_DBG("[DEVICE]: %s, AD evt type %u, AD data len %u, RSSI %i", dev, type, ad->len, rssi);
|
||||
|
||||
/* We're only interested in connectable events */
|
||||
if (type == BT_GAP_ADV_TYPE_ADV_IND || type == BT_GAP_ADV_TYPE_ADV_DIRECT_IND) {
|
||||
|
||||
@@ -60,8 +60,8 @@ static ssize_t split_svc_run_behavior(struct bt_conn *conn, const struct bt_gatt
|
||||
.param2 = payload->data.param2,
|
||||
.behavior_dev = payload->behavior_dev,
|
||||
};
|
||||
LOG_DBG("%s with params %d %d: pressed? %d", binding.behavior_dev,
|
||||
binding.param1, binding.param2, payload->data.state);
|
||||
LOG_DBG("%s with params %d %d: pressed? %d", binding.behavior_dev, binding.param1,
|
||||
binding.param2, payload->data.state);
|
||||
struct zmk_behavior_binding_event event = {.position = payload->data.position,
|
||||
.timestamp = k_uptime_get()};
|
||||
int err;
|
||||
|
||||
Reference in New Issue
Block a user