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

Relocate RGB keycode processing #7508

Merged
merged 8 commits into from
Dec 16, 2019
Merged

Conversation

zvecr
Copy link
Member

@zvecr zvecr commented Nov 28, 2019

Description

This PR relocates a block of keycode handling to its own file for readability and also attempts to save some firmware bytes. Mimicking travis by running ./util/docker_build.sh helix/pico/back:default:

before
* The firmware size is approaching the maximum - 28482/28672 (99%, 190 bytes free)

after
* The firmware size is approaching the maximum - 28158/28672 (98%, 514 bytes free)

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@drashna
Copy link
Member

drashna commented Nov 30, 2019

I like this, a lot.

Though, I don't like the remapping of the rgb matrix functions to rgb light functions, even if it's behind a preprocessor.

In fact, this makes #5404 almost trival to implement, rather than the messy mess that it is right now.

@drashna drashna requested a review from a team November 30, 2019 00:41
@zvecr zvecr marked this pull request as ready for review November 30, 2019 13:28
Copy link
Contributor

@yanfali yanfali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

*
* noinline to optimise for firmware size not speed (not in hot path)
*/
void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change these to return boolean and return false. This will make the caller slightly cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So i gave the above suggestion a go, and it consumes about an extra 50 bytes with the return false and return handleKeycodeRGB(. While its about 0.17% of the available flash, we recent had the issue with trying to claw back 4 bytes. Do we want to focus on readability here? (its still a net saving)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'm all for regaining as much program space as possible... I think that readability (and maintainability) should be the priority.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the handleKeycodeRGB had more logic, i would agree, but if it just returns false i would say personally not any more readable. That being said, i don't mind either way.

In the case of the animations, you end up with

#ifdef RGBLIGHT_EFFECT_KNIGHT
                return handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end);
#else
                return false;
#endif

or

#ifdef RGBLIGHT_EFFECT_KNIGHT
                return handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end);
#endif
                return false;

with the dead double return that gets optimised out, which in both cases is less readable to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deliberately didn't ask you to modify RGBMode because I didn't think it helped readability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So i gave the above suggestion a go, and it consumes about an extra 50 bytes with the return false and return handleKeycodeRGB(. While its about 0.17% of the available flash, we recent had the issue with trying to claw back 4 bytes. Do we want to focus on readability here? (its still a net saving)

I actually think that making this signature return something maybe useful in the long run, much like we had with led settings. Right now it only returns false, but there may be cases in the future where it's useful to return true.

Copy link
Member Author

@zvecr zvecr Dec 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I read "these" as both the new function signatures.

As this is non user facing, would we not just defer to the point we implement the additional functionality?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a fair point. I still think it's slightly more readable than having an explicit false, but it's also anticipating use cases we don't have, so just leave it as is for now.

@drashna drashna mentioned this pull request Dec 6, 2019
13 tasks
@zvecr zvecr force-pushed the feature/rgb_keycodes branch from 1f21ae8 to 2237db2 Compare December 16, 2019 00:42
@zvecr
Copy link
Member Author

zvecr commented Dec 16, 2019

Finally ironed out all the rebase issues, should be good to go again!

@zvecr zvecr requested a review from a team December 16, 2019 18:14
@drashna drashna merged commit ae40fc4 into qmk:master Dec 16, 2019
benjaminmikiten added a commit to benjaminmikiten/qmk_firmware that referenced this pull request Dec 18, 2019
* master: (99 commits)
  [Keymap] Added userspace for d4mation. Included their keymap for the Atreus62 (qmk#7483)
  [Keymap] Custom user keymap for Think6.5 with LED range control (qmk#7603)
  [Keymap] CRKBD Custom Keymap - KidBrazil (qmk#7630)
  [Keymap] Add pico 70 keys keymap (qmk#7654)
  Tidy up dztech default keymaps and info.json (qmk#7608)
  Heisenberg handwired keyboard added (qmk#7643)
  [Keyboard] Added Filco Majestouch TKL Pegasus Hoof ISO Layout (qmk#7647)
  Ported J80 to QMK (qmk#7488)
  [Keyboard] Magnavox Videowriter conversion with Pro Micro (qmk#7634)
  [Docs] add japanese translation (basic part) (qmk#7461)
  Tidy up dztech rules.mk
  Relocate RGB keycode processing (qmk#7508)
  Move kwerdenker's personal keymap from RGB (qmk#7645)
  Remove QMK_KEYBOARD_CONFIG_H from boards (qmk#7635)
  Disable usb on slave half to resolve random 'lockup' (qmk#7649)
  [Core] Optimize matrix processing (qmk#7621)
  [Keymap] boy_314's satisfaction75 layout (qmk#7638)
  [Keyboard] XD68 65% ATMega32U4 based (qmk#7395)
  [keyboard] Plain60 cleanups (qmk#7644)
  update default h88 keymap (qmk#7646)
  ...
patrl pushed a commit to patrl/qmk_firmware that referenced this pull request Dec 29, 2019
* Move rgb keycode logic to process_keycode

* Fixes for rgb matrix

* Fixes for mxss

* Fix inc/dec logic, add comments

* Fix return RAINBOW_SWIRL logic

* stop external use of rgb helper functions

* merge fix

* Fix 'defined but not used' when all animations are disabled
drashna pushed a commit to zsa/qmk_firmware that referenced this pull request Jan 2, 2020
* Move rgb keycode logic to process_keycode

* Fixes for rgb matrix

* Fixes for mxss

* Fix inc/dec logic, add comments

* Fix return RAINBOW_SWIRL logic

* stop external use of rgb helper functions

* merge fix

* Fix 'defined but not used' when all animations are disabled
fdidron added a commit to zsa/qmk_firmware that referenced this pull request Jan 6, 2020
* clean up quantum.c (qmk#7485)

* idea

* progress

* more stuff

* wip

* wip

* last couple of keycodes you can move safely

* Update quantum/quantum.c

Co-Authored-By: fauxpark <[email protected]>

* Put back RGB_MODE_BREATHE

* Compile out some keycode processing when features are disabled (qmk#7506)

* Add shift-to-invert to remaining directional RGB_* keycode pairs (qmk#7484)

* Add shift-to-invert to remaining directional RGB_* keycode pairs

RGB_MODE_FORWARD / RGB_MODE_REVERSE invert their functions when shift is held.
This change adds the same capabilities to the remaining directional RGB_*
keycode pairs.  This improves consistency and provides full RGB control in a
keymap containing only one keycode from each pair.

* remove redundant variable

* fix typo

* Fix more typos

Flyspell is on now I swear!

* Relocate magic keycode processing (qmk#7512)

* Move magic keycode processing to own file

* Save some bytes

* Update comments

* Update define to one thats not already used...

* Fix audio

* Fix breathing toggle when rgb is disabled (qmk#7550)

* Ifdef MAGIC_EE_HANDS until #178 drops

revert this commit once it does

* Add short aliases for Magic keycodes (qmk#7541)

* Add short alias for `MAGIC_TOGGLE_NKRO`

* Add aliases for the other Bootmagic keycodes

* Replace long form in default keymaps

* Fix FORCE_NKRO handling (qmk#7601)

* Add until #173 drops

* Relocate RGB keycode processing (qmk#7508)

* Move rgb keycode logic to process_keycode

* Fixes for rgb matrix

* Fixes for mxss

* Fix inc/dec logic, add comments

* Fix return RAINBOW_SWIRL logic

* stop external use of rgb helper functions

* merge fix

* Fix 'defined but not used' when all animations are disabled

Co-authored-by: Yan-Fa Li <[email protected]>
Co-authored-by: Joel Challis <[email protected]>
Co-authored-by: Manna Harbour <[email protected]>
Co-authored-by: fauxpark <[email protected]>
Co-authored-by: Florian Didron <[email protected]>
fdidron added a commit to zsa/qmk_firmware that referenced this pull request Jan 8, 2020
* clean up quantum.c (qmk#7485)

* idea

* progress

* more stuff

* wip

* wip

* last couple of keycodes you can move safely

* Update quantum/quantum.c

Co-Authored-By: fauxpark <[email protected]>

* Put back RGB_MODE_BREATHE

* Compile out some keycode processing when features are disabled (qmk#7506)

* Add shift-to-invert to remaining directional RGB_* keycode pairs (qmk#7484)

* Add shift-to-invert to remaining directional RGB_* keycode pairs

RGB_MODE_FORWARD / RGB_MODE_REVERSE invert their functions when shift is held.
This change adds the same capabilities to the remaining directional RGB_*
keycode pairs.  This improves consistency and provides full RGB control in a
keymap containing only one keycode from each pair.

* remove redundant variable

* fix typo

* Fix more typos

Flyspell is on now I swear!

* Relocate magic keycode processing (qmk#7512)

* Move magic keycode processing to own file

* Save some bytes

* Update comments

* Update define to one thats not already used...

* Fix audio

* Fix breathing toggle when rgb is disabled (qmk#7550)

* Ifdef MAGIC_EE_HANDS until #178 drops

revert this commit once it does

* Add short aliases for Magic keycodes (qmk#7541)

* Add short alias for `MAGIC_TOGGLE_NKRO`

* Add aliases for the other Bootmagic keycodes

* Replace long form in default keymaps

* Fix FORCE_NKRO handling (qmk#7601)

* Add until #173 drops

* Relocate RGB keycode processing (qmk#7508)

* Move rgb keycode logic to process_keycode

* Fixes for rgb matrix

* Fixes for mxss

* Fix inc/dec logic, add comments

* Fix return RAINBOW_SWIRL logic

* stop external use of rgb helper functions

* merge fix

* Fix 'defined but not used' when all animations are disabled

Co-authored-by: Yan-Fa Li <[email protected]>
Co-authored-by: Joel Challis <[email protected]>
Co-authored-by: Manna Harbour <[email protected]>
Co-authored-by: fauxpark <[email protected]>
Co-authored-by: Florian Didron <[email protected]>
HokieGeek pushed a commit to HokieGeek/qmk_firmware that referenced this pull request Feb 21, 2020
* Move rgb keycode logic to process_keycode

* Fixes for rgb matrix

* Fixes for mxss

* Fix inc/dec logic, add comments

* Fix return RAINBOW_SWIRL logic

* stop external use of rgb helper functions

* merge fix

* Fix 'defined but not used' when all animations are disabled
kylekuj pushed a commit to kylekuj/qmk_firmware that referenced this pull request Apr 21, 2020
* Move rgb keycode logic to process_keycode

* Fixes for rgb matrix

* Fixes for mxss

* Fix inc/dec logic, add comments

* Fix return RAINBOW_SWIRL logic

* stop external use of rgb helper functions

* merge fix

* Fix 'defined but not used' when all animations are disabled
@zvecr zvecr deleted the feature/rgb_keycodes branch April 28, 2020 01:03
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
* Move rgb keycode logic to process_keycode

* Fixes for rgb matrix

* Fixes for mxss

* Fix inc/dec logic, add comments

* Fix return RAINBOW_SWIRL logic

* stop external use of rgb helper functions

* merge fix

* Fix 'defined but not used' when all animations are disabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants