Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update new behavior example code #2511

Open
joelspadin opened this issue Sep 27, 2024 · 0 comments
Open

Update new behavior example code #2511

joelspadin opened this issue Sep 27, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@joelspadin
Copy link
Collaborator

Some of the example code at https://zmk.dev/docs/development/new-behavior#creating-the-driver-c is either outdated or incomplete. The following issues should be fixed:

  1. #if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) in the C file should be replaced with
    config ZMK_BEHAVIOR_<NAME>
        bool
        default y
        depends on DT_HAS_ZMK_BEHAVIOR_<NAME>_ENABLED
    
    in Kconfig.behaviors and
    target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_<NAME> app PRIVATE src/behaviors/<file>.c)
    in CMakeLists.txt
  2. The code example with BEHAVIOR_DT_INST_DEFINE(0, ... shows how to create a behavior that only supports one instance. It includes a comment that implies that simply switching 0 to n will add support for multiple instances, but this is incorrect. The correct structure for such a behavior is
    #define MY_BEHAVIOR_INST(n) \
        static const struct my_behavior_config my_behavior_config_##n = { ... }; \
        static struct my_behavior_data my_behavior_data_##n = { ... }; \
        BEHAVIOR_DT_INST_DEFINE(n, my_behavior_init, NULL, &my_behavior_data_##n, &my_behavior_config_##n, \
                                POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &my_behavior_driver_api);
    
    DT_INST_FOREACH_STATUS_OKAY(MY_BEHAVIOR_INST)
    We could either make this the only example, then describe how to simplify it if your behavior only supports one instance, or we could have examples of both formats (though having two examples could be more confusing and harder to maintain).
@joelspadin joelspadin added the documentation Improvements or additions to documentation label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant