#change CPI by keypress

1 messages · Page 1 of 1 (latest)

rain vine
#

I want to add a feature to change the CPI when a key is pressed in the repository https://github.com/inorichi/zmk-pmw3610-driver. However, I’m a complete beginner and unsure of where to start. I understand that there is a function like set_cpi in the driver, and that I need to call it in response to a keypress, but I’m not sure which file to modify or how to define the keycodes. I would appreciate any hints on how to proceed.

feral mural
#

It's not really trivial, check the new behavior guide under development docs

#

But read through the guide

rain vine
#

thank you
I will read docs and examples

rain vine
# feral mural Here is a relatively barebones example of adding a behavior to a module <https:/...

I tried writing it based on examples like this,
https://github.com/kumamuk-git/zmk-pmw3610-driver/commit/50d510b987d13c88c91b1f9223693121d36831c9
but I'm not sure how to handle the YAML part. I already have a YAML file, but should I create a separate YAML for the behavior? Also, could you check if there are any unnatural points in what I've written?

feral mural
#
  • Your compatible values in the dtsi need to match what's on the first line in the source. i.e. change it to zmk,behavior-pmw3610
  • You need a new yaml file zmk,behavior-pmw3610.yml in a special location for the behavior, yes. It's separate from the driver
  • Add the necessary Kconfig to set the symbol like in my commit
  • Compile the .c conditionally in the CMakeLists.txt using above symbol
solid shell
#

Here is another example to call an implemented sensor_driver_api in a zephyr driver.

rain vine
rain vine
#

The fact that no logs are appearing—could it mean that the line

const struct device *dev = binding->behavior_dev;
is not working properly?

rain vine
#

@feral mural @solid shell
after some modification, it no longer freezes.
but cpi won't be changed by keypress.
According to the log, this line may be the cause.
If you come up with any ideas for modifications, I'd be glad to hear them?
https://github.com/kumamuk-git/zmk-pmw3610-driver/blob/8e667f4a620b4b03ce0da402d1d79979c7215f7d/src/behaviors/begavior_pmw3610.c#L35

GitHub

Contribute to kumamuk-git/zmk-pmw3610-driver development by creating an account on GitHub.

solid shell
#

the dev you got in pressed callback is the behavior you just created, it is not referencing to the 3610 sensor device. you might find a property namedtb6612fng_dev in my above example, it is the pattern you could follow.

rain vine
# solid shell the `dev` you got in *pressed callback* is the behavior you just created, it is ...

https://github.com/kumamuk-git/zmk-config-test/blob/w/o_dongle/config/Test.keymap
ERROR: /behaviors/cpi_d200 POST_KERNEL 1 < /soc/spi@40003000/trackball@0 POST_KERNEL 33
ERROR: /behaviors/cpi_i200 POST_KERNEL 2 < /soc/spi@40003000/trackball@0 POST_KERNEL 33

I wrote in the keymap file to tie pixart_dev to trackball like this, but it fails due to build priority(?)

BEHAVIOR_DT_INST_DEFINE(n, behavior_cpi_init, NULL, NULL, &behavior_cpi_config_##n,            \
                        POST_KERNEL, 34,                      \
                        &behavior_cpi_driver_api);

Specifying 34 did not change the result.

GitHub

Contribute to kumamuk-git/zmk-config-test development by creating an account on GitHub.

solid shell
#

on zephyr prespective, there is 2 devices. you gonna need to sort out the initial sequence by yourself. see example.

rain vine
solid shell
#

just put something else as the device. in case, you dont trigger the behavior on peripheral side.

rain vine
solid shell
#

no. put any device can do. you can makeup another dummy behavior of yours. it wil compile but definitly will crash if its triggerered (but it will never happening)

rain vine
solid shell
#

the keymap is the common config while compiling both shield roles. in youe case, there is no trackball on the peripheral , so it need a dummy device to pass the dts check. dummy device can be any node which zephyr thinks that is a device. you might get the idea from the readme of input-replay-module,

rain vine
solid shell
#

you forget to swap in the sensor device pointer in your press callback