1515
1616LOG_MODULE_DECLARE (zmk , CONFIG_ZMK_LOG_LEVEL );
1717
18+ #if DT_HAS_COMPAT_STATUS_OKAY (DT_DRV_COMPAT )
19+
1820#if IS_ENABLED (CONFIG_ZMK_BEHAVIOR_METADATA )
1921
2022static const struct behavior_parameter_value_metadata param_values [] = {
@@ -36,16 +38,22 @@ static const struct behavior_parameter_metadata metadata = {
3638
3739#endif
3840
41+ struct behavior_mo_config {
42+ bool locking ;
43+ };
44+
3945static int mo_keymap_binding_pressed (struct zmk_behavior_binding * binding ,
4046 struct zmk_behavior_binding_event event ) {
4147 LOG_DBG ("position %d layer %d" , event .position , binding -> param1 );
42- return zmk_keymap_layer_activate (binding -> param1 );
48+ const struct behavior_mo_config * cfg = zmk_behavior_get_binding (binding -> behavior_dev )-> config ;
49+ return zmk_keymap_layer_activate (binding -> param1 , cfg -> locking );
4350}
4451
4552static int mo_keymap_binding_released (struct zmk_behavior_binding * binding ,
4653 struct zmk_behavior_binding_event event ) {
4754 LOG_DBG ("position %d layer %d" , event .position , binding -> param1 );
48- return zmk_keymap_layer_deactivate (binding -> param1 );
55+ const struct behavior_mo_config * cfg = zmk_behavior_get_binding (binding -> behavior_dev )-> config ;
56+ return zmk_keymap_layer_deactivate (binding -> param1 , cfg -> locking );
4957}
5058
5159static const struct behavior_driver_api behavior_mo_driver_api = {
@@ -56,5 +64,13 @@ static const struct behavior_driver_api behavior_mo_driver_api = {
5664#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA)
5765};
5866
59- BEHAVIOR_DT_INST_DEFINE (0 , NULL , NULL , NULL , NULL , POST_KERNEL , CONFIG_KERNEL_INIT_PRIORITY_DEFAULT ,
60- & behavior_mo_driver_api );
67+ #define MO_INST (n ) \
68+ static const struct behavior_mo_config behavior_mo_config_##n = { \
69+ .locking = DT_INST_PROP_OR(n, locking, false), \
70+ }; \
71+ BEHAVIOR_DT_INST_DEFINE(n, NULL, NULL, NULL, &behavior_mo_config_##n, POST_KERNEL, \
72+ CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_mo_driver_api);
73+
74+ DT_INST_FOREACH_STATUS_OKAY (MO_INST )
75+
76+ #endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */
0 commit comments