Qmk_firmware: kb / user hooks - TMK vs QMK

Created on 3 Apr 2017  路  6Comments  路  Source: qmk/qmk_firmware

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:

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

Most helpful comment

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!

All 6 comments

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.

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.

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@53bd4a01be5c4327462e6c6620ea7670eddca6f2 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.

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

And #3113

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?

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Frefreak picture Frefreak  路  4Comments

fredizzimo picture fredizzimo  路  4Comments

fredizzimo picture fredizzimo  路  4Comments

kb3dow picture kb3dow  路  3Comments

MarkuBu picture MarkuBu  路  3Comments