-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
Made AVR backlight pwm resolution configurable #7521
Conversation
Currently, I can't test these changes myself, so I need help with that. There's a good chance I messed up some of the math when changing from the hard-coded values. |
With BACKLIGHT_CUSTOM_RESOLUTION set to 65535, the maximum brightness is right, but breathing doesn't work as intended, it keeps the 6 second default time but the leds are off for one second then switch to like 5% of brightness for 5 seconds. With the resolution set to 4096, the pwm frequency measurably increases, but the maximum brightness is very low, maybe around 10%. |
@dotleon Hey, and thanks for testing it. Would you be up for testing the newest push? |
Maximum brightness is good, scaling is working properly, and pwm frequency increases as intended. |
that's epilepsy inducing. |
The breathing ISR still seems to be assuming a 244Hz frequency:
qmk_firmware/quantum/backlight/backlight_avr.c Lines 448 to 450 in e4dd9e1
|
Yeah that seems to be what it was :) @dotleon This should let breathing work too. Was the shimmering of the LEDs a camera artifact, or was that also observed by eye? Ignoring the way too fast breathing, the LEDs seemed to be shimmering a bit in the video you posted |
@Duckle29 the shimmering was not a camera artifact, I think something overflows, I've experimented a little yesterday and here are my findings:
|
Thank you for your contribution! |
Some merge conflicts here. |
While the conflict has been resolved, I don't feel comfortable merging this for a few reasons. Lack of hardware to test on and as such a lack of confidence in the change. |
Retargeted to |
550bb6a
to
9d827f9
Compare
1d4c0cd
to
65c27a3
Compare
a1b96ba
to
3430907
Compare
Constant is no longer needed since running the breathing ISR at a fixed 120Hz
edcb57e
to
e058c2b
Compare
Description
This PR aims to make hardware PWM resolution configurable, allowing higher PWM frequencies at lower resolutions.
Currently, 16bit timers use the full 16bit resolution, resulting in a ~244Hz frequency for the backlight PWM. This would be noticeable in the peripheral vision if moving quickly / turning your head quickly. Additionally, with most keyboards having very few brightness levels, this resolution is wasted.
For now, making the top of the counter optionally configurable using
#define BACKLIGHT_CUSTOM_RESOLUTION = <custom resolution>
should offer configurability for users that find 244Hz too slow.In order to achieve this, some things have been changed slightly.
The cie_lightness function was hard-coded to assume the max value was 65535.
In order to avoid floating point arithmetic, I replaced the hard-coded 8% and 16% values of that with division with the nearest integer to the reciprocal of the respective percentages. x/12 for ~8% (8.333...%) and x/6 for ~16% (16.666...%)
No change default behavior should be as it was, except for the minor differences in percentages.
Types of Changes
Checklist