fix: clang format

This commit is contained in:
Cody McGinnis 2020-09-14 10:26:30 -04:00
parent 3c260301eb
commit 888896c3ef

View file

@ -20,124 +20,123 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#define _TRANSFORM_ENTRY(idx, node) \ #define _TRANSFORM_ENTRY(idx, node) \
{ .behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(node, bindings, idx)), \ { \
.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))), \ .behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(node, bindings, idx)), \
.param2 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param2), (0), (DT_INST_PHA_BY_IDX(node, bindings, idx, param2))), \ .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), \
(DT_INST_PHA_BY_IDX(node, bindings, idx, param2))), \
},
#define TRANSFORMED_BINDINGS(node) \ #define TRANSFORMED_BINDINGS(node) \
{ UTIL_LISTIFY(DT_INST_PROP_LEN(node, bindings), _TRANSFORM_ENTRY, node) } { UTIL_LISTIFY(DT_INST_PROP_LEN(node, bindings), _TRANSFORM_ENTRY, node) }
#if 1 || DT_NODE_EXISTS(DT_DRV_INST(0)) #if 1 || DT_NODE_EXISTS(DT_DRV_INST(0))
enum mode { enum mode {
ZMK_BHV_SIMPLE_MACRO_MODE_KEY_UP = 0, ZMK_BHV_SIMPLE_MACRO_MODE_KEY_UP = 0,
ZMK_BHV_SIMPLE_MACRO_MODE_KEY_DOWN = 1, ZMK_BHV_SIMPLE_MACRO_MODE_KEY_DOWN = 1,
ZMK_BHV_SIMPLE_MACRO_MODE_HOLD = 2, ZMK_BHV_SIMPLE_MACRO_MODE_HOLD = 2,
}; };
struct behavior_simple_macro_config { struct behavior_simple_macro_config {
int mode; int mode;
int sleep; int sleep;
int behavior_count; int behavior_count;
struct zmk_behavior_binding* behaviors; struct zmk_behavior_binding *behaviors;
}; };
struct behavior_simple_macro_data { }; struct behavior_simple_macro_data {};
static int behavior_simple_macro_init(struct device *dev) static int behavior_simple_macro_init(struct device *dev) { return 0; }
{
return 0; static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t _, u32_t __) {
const struct behavior_simple_macro_config *cfg = dev->config_info;
if (cfg->mode == ZMK_BHV_SIMPLE_MACRO_MODE_KEY_DOWN) {
LOG_DBG("tapping on key up");
for (int index = 0; index < cfg->behavior_count; index++) {
struct device *behavior = device_get_binding(cfg->behaviors[index].behavior_dev);
if (behavior) {
LOG_DBG("tapping: binding name: %s",
log_strdup(cfg->behaviors[index].behavior_dev));
k_msleep(cfg->sleep);
behavior_keymap_binding_pressed(behavior, position, cfg->behaviors[index].param1,
cfg->behaviors[index].param2);
k_msleep(cfg->sleep);
behavior_keymap_binding_released(behavior, position, cfg->behaviors[index].param1,
cfg->behaviors[index].param2);
}
}
} else if (cfg->mode == ZMK_BHV_SIMPLE_MACRO_MODE_HOLD) {
for (int index = 0; index < cfg->behavior_count; index++) {
struct device *behavior = device_get_binding(cfg->behaviors[index].behavior_dev);
if (behavior) {
LOG_DBG("pressing: binding name: %s",
log_strdup(cfg->behaviors[index].behavior_dev));
behavior_keymap_binding_pressed(behavior, position, cfg->behaviors[index].param1,
cfg->behaviors[index].param2);
}
}
}
return 0;
} }
static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t _, u32_t __) static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t _, u32_t __) {
{ const struct behavior_simple_macro_config *cfg = dev->config_info;
const struct behavior_simple_macro_config *cfg = dev->config_info;
if (cfg->mode == ZMK_BHV_SIMPLE_MACRO_MODE_KEY_DOWN) if (cfg->mode == ZMK_BHV_SIMPLE_MACRO_MODE_KEY_UP) {
{ LOG_DBG("tapping on key down");
LOG_DBG("tapping on key up"); for (int index = 0; index < cfg->behavior_count; index++) {
for (int index = 0; index < cfg->behavior_count; index++) struct device *behavior = device_get_binding(cfg->behaviors[index].behavior_dev);
{ if (behavior) {
struct device *behavior = device_get_binding(cfg->behaviors[index].behavior_dev); LOG_DBG("tapping: binding name: %s",
if (behavior) { log_strdup(cfg->behaviors[index].behavior_dev));
LOG_DBG("tapping: binding name: %s", log_strdup(cfg->behaviors[index].behavior_dev)); k_msleep(cfg->sleep);
k_msleep(cfg->sleep); behavior_keymap_binding_pressed(behavior, position, cfg->behaviors[index].param1,
behavior_keymap_binding_pressed(behavior, position, cfg->behaviors[index].param1, cfg->behaviors[index].param2); cfg->behaviors[index].param2);
k_msleep(cfg->sleep); k_msleep(cfg->sleep);
behavior_keymap_binding_released(behavior, position, cfg->behaviors[index].param1, cfg->behaviors[index].param2); behavior_keymap_binding_released(behavior, position, cfg->behaviors[index].param1,
} cfg->behaviors[index].param2);
}
}
} else if (cfg->mode == ZMK_BHV_SIMPLE_MACRO_MODE_HOLD) {
for (int index = cfg->behavior_count - 1; index >= 0; index--) {
struct device *behavior = device_get_binding(cfg->behaviors[index].behavior_dev);
if (behavior) {
LOG_DBG("releasing: binding name: %s",
log_strdup(cfg->behaviors[index].behavior_dev));
behavior_keymap_binding_released(behavior, position, cfg->behaviors[index].param1,
cfg->behaviors[index].param2);
}
}
} }
}
else if (cfg->mode == ZMK_BHV_SIMPLE_MACRO_MODE_HOLD)
{
for (int index = 0; index < cfg->behavior_count; index++)
{
struct device *behavior = device_get_binding(cfg->behaviors[index].behavior_dev);
if (behavior) {
LOG_DBG("pressing: binding name: %s", log_strdup(cfg->behaviors[index].behavior_dev));
behavior_keymap_binding_pressed(behavior, position, cfg->behaviors[index].param1, cfg->behaviors[index].param2);
}
}
}
return 0; return 0;
}
static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t _, u32_t __)
{
const struct behavior_simple_macro_config *cfg = dev->config_info;
if (cfg->mode == ZMK_BHV_SIMPLE_MACRO_MODE_KEY_UP)
{
LOG_DBG("tapping on key down");
for (int index = 0; index < cfg->behavior_count; index++)
{
struct device *behavior = device_get_binding(cfg->behaviors[index].behavior_dev);
if (behavior) {
LOG_DBG("tapping: binding name: %s", log_strdup(cfg->behaviors[index].behavior_dev));
k_msleep(cfg->sleep);
behavior_keymap_binding_pressed(behavior, position, cfg->behaviors[index].param1, cfg->behaviors[index].param2);
k_msleep(cfg->sleep);
behavior_keymap_binding_released(behavior, position, cfg->behaviors[index].param1, cfg->behaviors[index].param2);
}
}
}
else if (cfg->mode == ZMK_BHV_SIMPLE_MACRO_MODE_HOLD)
{
for (int index = cfg->behavior_count - 1; index >= 0; index--)
{
struct device *behavior = device_get_binding(cfg->behaviors[index].behavior_dev);
if (behavior) {
LOG_DBG("releasing: binding name: %s", log_strdup(cfg->behaviors[index].behavior_dev));
behavior_keymap_binding_released(behavior, position, cfg->behaviors[index].param1, cfg->behaviors[index].param2);
}
}
}
return 0;
} }
static const struct behavior_driver_api behavior_simple_macro_driver_api = { static const struct behavior_driver_api behavior_simple_macro_driver_api = {
.binding_pressed = on_keymap_binding_pressed, .binding_pressed = on_keymap_binding_pressed,
.binding_released = on_keymap_binding_released, .binding_released = on_keymap_binding_released,
}; };
#define KP_INST(n) \ #define KP_INST(n) \
static struct zmk_behavior_binding behavior_simple_macro_config_##n##_bindings[DT_INST_PROP_LEN(n, bindings)] = TRANSFORMED_BINDINGS(n); \ static struct zmk_behavior_binding \
static struct behavior_simple_macro_config behavior_simple_macro_config_##n = { \ behavior_simple_macro_config_##n##_bindings[DT_INST_PROP_LEN(n, bindings)] = \
.behaviors = behavior_simple_macro_config_##n##_bindings, \ TRANSFORMED_BINDINGS(n); \
.behavior_count = DT_INST_PROP_LEN(n, bindings), \ static struct behavior_simple_macro_config behavior_simple_macro_config_##n = { \
.sleep = DT_INST_PROP(n, sleep), \ .behaviors = behavior_simple_macro_config_##n##_bindings, \
.mode = DT_ENUM_IDX(DT_DRV_INST(n), mode), \ .behavior_count = DT_INST_PROP_LEN(n, bindings), \
}; \ .sleep = DT_INST_PROP(n, sleep), \
static struct behavior_simple_macro_data behavior_simple_macro_data_##n; \ .mode = DT_ENUM_IDX(DT_DRV_INST(n), mode), \
DEVICE_AND_API_INIT(behavior_simple_macro_##n, DT_INST_LABEL(n), behavior_simple_macro_init, \ }; \
&behavior_simple_macro_data_##n, \ static struct behavior_simple_macro_data behavior_simple_macro_data_##n; \
&behavior_simple_macro_config_##n, \ DEVICE_AND_API_INIT(behavior_simple_macro_##n, DT_INST_LABEL(n), behavior_simple_macro_init, \
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ &behavior_simple_macro_data_##n, &behavior_simple_macro_config_##n, \
&behavior_simple_macro_driver_api); APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&behavior_simple_macro_driver_api);
DT_INST_FOREACH_STATUS_OKAY(KP_INST) DT_INST_FOREACH_STATUS_OKAY(KP_INST)
#endif #endif