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

kb / user hooks - TMK vs QMK #1205

Closed
10 of 11 tasks
jpetermans opened this issue Apr 3, 2017 · 6 comments
Closed
10 of 11 tasks

kb / user hooks - TMK vs QMK #1205

jpetermans opened this issue Apr 3, 2017 · 6 comments

Comments

@jpetermans
Copy link
Contributor

jpetermans commented Apr 3, 2017

I'm in the process of trying to port over matt3o's whitefox backlight code from TMK and converting for infinity60. In another issue I opened, #1179, fredizzimo commented that he is working on a software solution for the ergodox that could be ported over. In the meantime, I thought I'd take a stab at porting over the hardward approach from the whitefox tmk code.

matt3o's led_controller code uses functions from tmk_core/common/hook.c which qmk does not have. I'm trying to translate to equivalent the kb / user level functions from qmk and want to make sure the timing of the calls is similar. My attempt is below. Bolded calls are used in led_controller.c from tmk. Do these look correct? My primary concern is matching the hook_early_init timing.

  • Hook_early_init - just after processor startup (qmk = matrix_init)
    • initialize I2C, is31_init, write led pages, clean up capslock register
  • Hook_usb_suspend_entry - called once after suspend rec'd (qmk = shutdown_user)
    • enable sleep led
  • Hook_usb_suspend_loop - called while in suspended state (qmk = ??)
    • check for usb activity and send wakeup
  • Hook_usb_wakeup - called once after wakup rec'd (qmk = startup_user)
    • disable sleep led

(unused in whitefox led_controller code)

  • Hook_late_init - last stage of init, just before keyboard loop (qmk = ??)
  • Hook_keyboard_loop - called from keyboard loop (often) (qmk = matrix_scan)
  • Hook_matrix_change - called matrix change event (keypress, often) (qmk = matrix_scan)
  • Hook_default_layer_change - default layer change event (qmk = process_action_kb)
  • Hook_layer_change - layer state change event (qmk = process_action_kb)
  • Hook_keyboard_leds_change - indicator LED change event (qmk = led_set)
  • Hook_bootmagic - called when checking bootmagic combo (qmk = ??)

(edit)
Full list of hooks to convert:

  • Hook_early_init - just after processor startup (qmk = matrix_init)
  • Hook_late_init - last stage of init, just before keyboard loop (qmk = keyboard_post_init in Add kb and user level keyboard initialization functions  #3113 )
  • Hook_usb_suspend_entry - called once after suspend rec'd (qmk = suspend_power_down)
  • Hook_keyboard_loop - called from keyboard loop (often) (qmk = matrix_scan)
  • Hook_matrix_change - called matrix change event (keypress, often) (qmk = matrix_scan)
  • Hook_usb_suspend_loop - called while in suspended state (qmk = I believe that suspend_power_down_* handles this, as of Add Suspend functions #3112)
  • Hook_usb_wakeup - called once after wakup rec'd (qmk = suspend_wakeup_init)
  • Hook_default_layer_change - default layer change event (qmk = default_layer_state_set, missing user function, has kb function)
  • Hook_layer_change - layer state change event (qmk = layer_state_set)
  • Hook_keyboard_leds_change - indicator LED change event (qmk = led_set)
  • Hook_bootmagic - called when checking bootmagic combo (qmk = TBD)
@jackhumbert
Copy link
Member

I wouldn't mind setting up a framework for more hooks like this, or even renaming some of the existing ones. I wasn't aware of the hooks TMK added - this might have happened after we forked.

@jpetermans
Copy link
Contributor Author

The matrix_init_ and matrix_scan_ functions seem to cover most scenarios. matrix_init worked fine for the tmk backlight code I'm working on from whitefox. It was using hook_init_early. Although, additional hooks may be less processor intensive in some cases where you don't need to run something every keyboard loop, just on a few discrete events.

@luizribeiro
Copy link
Contributor

This would be nice to have. I've been using matrix_scan_user for changing backlight color when the current layer changes, but TMK-style hooks would be a bit cleaner.

In case you're curious, tmk/tmk_keyboard@53bd4a0 was the commit that introduced hooks to TMK. There's more to that commit than just setting up hooks I believe, but the code for hooks looks pretty clean and fairly simple to move to QMK.

@drashna
Copy link
Member

drashna commented Jul 25, 2018

This is partially done, now, actually.
https://docs.qmk.fm/#/custom_quantum_functions?id=keyboard-idlingwake-code

And #3113

@drashna
Copy link
Member

drashna commented Mar 29, 2019

I think the only thing that is left is bootmagic, actually. And we have bootmagic lite which is user configurable, though not as fully featured.

And I'm not sure we really need the bootmagic hook. That can be done as part of the init functions. Right now, bootmagic lite does this during matrix_init.

@jpetermans would you say that this could be closed?

@jpetermans
Copy link
Contributor Author

I haven't looked over everything in any detail, but there is no need for me to that. A quick review looks like it's all covered as you noted. Closing this issue. Thanks for the building in these additional options!

mattpcaswell pushed a commit to mattpcaswell/qmk_firmware that referenced this issue Jun 7, 2023
* add default keymap: 1upkeyboards/pi60_rgb

* update default keymaps: 40percentclub/polyandry

promicro and teensy2 versions

* add default keymap: ai03/lunar_ii

* add default keymap: ano

* update default keymap: bbrfkr/dynamis

* add default keymap: binepad/bnr1/v1

* add default keymap: bolsa/bolsalice

* update default keymap: bpiphany/ghost_squid

* add default keymap: doio/kb16/rev1

* add default keymap: doio/kb16/rev2

* update default keymap: han60

* update default keymap: handwired/kbod

* add default keymap: hotdox76v2

* add default keymap: hubble

* add default keymap: huytbt/h50

* add default keymap: keebio/sinc/rev3

* add default keymap: kepler_33/proto

* update default keymap: kopibeng/mnk65

* update default keymap: latincompass/latinpadble

* update default keymap: macro3

* update default keymap: maxr1998/phoebe

* update default keymap: mechlovin/kay65

* update default keymap: melgeek/mj6xy/rev3

* update default keymap: mode/m65hi_alpha

* update default keymap: mwstudio/mw65_black

* add default keymap: nightly_boards/octopadplus

* update default keymap: splitkb/aurora/sweep/rev1

* add default keymap: star75

* update default keymap: wavtype/p01_ultra

* add default keymap: wilba_tech/wt65_d

* add default keymap: work_louder/numpad

* add default keymap: yandrstudio/nz67v2

* add default keymap: binepad/bn006

* add default keymap: cannonkeys/brutalv2_1800

* update default keymap: horrortroll/chinese_pcb/black_e65

* update default keymap: horrortroll/chinese_pcb/devil68_pro

* add default keymap: keychron/q1/iso_encoder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants