reform

MNT Reform: Open Source Portable Computer
Log (Feed) | Files | Refs (Tags) | README

commit 1189670232e2a1e06d1f479f52ad31fec55e6c06
parent 28f1c2c834c2043b31ae9359f61593ff22c283b4
Author: Valtteri Koskivuori <vkoskiv@gmail.com>
Date:   Sat,  7 Oct 2023 22:07:30 +0300

Fix bug that causes jumpy keyboard backlight adjustment

Here, I actually adjust the hardware parameters, these settings work the
best based on my understanding of Atmel docs, and experimentation.

The key change is to set the clock select parameters to choose a
prescale that divides the IO clock by 8.
In the original implementation, a comment implied that the intent was to
set the prescale to /256, but the actual code just sets the first CS00
bit of TCCR0B, which selects no prescaling.
Now, we explicitly choose a prescale of clock_io/8, which seems to
result in the desired behaviour. The brightness increases and decreases
in equal increments, with no jumps with dead keypresses in between.
There are now 1+8 brightness levels, that is, 'off' + 8 levels of
brightness.
Going any higher than a pwmval of 8 with these settings causes the
backlight to blink, I believe due to overcurrent protection.

Diffstat:
Mreform2-keyboard-fw/backlight.c | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/reform2-keyboard-fw/backlight.c b/reform2-keyboard-fw/backlight.c @@ -9,8 +9,8 @@ #include "backlight.h" #define KBD_MIN_PWMVAL 0 -#define KBD_MAX_PWMVAL 10 -#define KBD_PWM_STEP 2 +#define KBD_MAX_PWMVAL 8 +#define KBD_PWM_STEP 1 int16_t pwmval = KBD_MAX_PWMVAL; void kbd_brightness_init(void) { @@ -33,9 +33,9 @@ void kbd_brightness_init(void) { TCCR0A |= (1 << COM0A1); // Set 'Clock Select' to: - // - No prescale - TCCR0B |= (1 << CS00); - TCCR0B &= ~(1 << CS01); + // - prescale clk_io / 8 + TCCR0B &= ~(1 << CS00); + TCCR0B |= (1 << CS01); TCCR0B &= ~(1 << CS02); }