reform

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

commit 539b32cca137f7dec0071d8ef7c6103f3dddf15f
parent abd26239c5bd4a61c5c87e661b60b8ddb6262340
Author: Valtteri Koskivuori <vkoskiv@gmail.com>
Date:   Mon, 16 Oct 2023 23:52:09 +0300

Implement fade-in & fade-out animations for keyboard backlight

It now smoothly fades in the backlight on startup. If running in
standalone mode, it does it right when it receives power, and on the
Reform, when USB power gets enabled about ~20s into boot.

Diffstat:
Mreform2-keyboard-fw/backlight.c | 5++++-
Mreform2-keyboard-fw/backlight.h | 3+++
Mreform2-keyboard-fw/keyboard.c | 7+++++++
Mreform2-keyboard-fw/menu.c | 28+++++++++++++++++++++++++++-
Mreform2-keyboard-fw/menu.h | 4++++
5 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/reform2-keyboard-fw/backlight.c b/reform2-keyboard-fw/backlight.c @@ -5,7 +5,6 @@ */ #include <avr/io.h> -#include <stdint.h> #include "backlight.h" #define KBD_MIN_PWMVAL 0 @@ -57,3 +56,7 @@ void kbd_brightness_set(int brite) { if (pwmval >= KBD_MAX_PWMVAL) pwmval = KBD_MAX_PWMVAL; OCR0A = pwmval; } + +int16_t kbd_brightness_get(void) { + return pwmval; +} diff --git a/reform2-keyboard-fw/backlight.h b/reform2-keyboard-fw/backlight.h @@ -7,9 +7,12 @@ #ifndef _BACKLIGHT_H_ #define _BACKLIGHT_H_ +#include <stdint.h> + void kbd_brightness_init(void); void kbd_brightness_inc(void); void kbd_brightness_dec(void); void kbd_brightness_set(int brite); +int16_t kbd_brightness_get(void); #endif diff --git a/reform2-keyboard-fw/keyboard.c b/reform2-keyboard-fw/keyboard.c @@ -87,6 +87,8 @@ bool media_toggle = 0; bool fn_key = 0; // Am I holding FN? bool circle = 0; // Am I holding circle? +bool should_run_fade_anim = 0; + // enter the menu void enter_meta_mode(void) { active_meta_mode = 1; @@ -301,6 +303,10 @@ int main(void) if (counter%750 == 0) { remote_process_alerts(); } + if (should_run_fade_anim) { + anim_kbd_hello(); + should_run_fade_anim = false; + } #endif } } @@ -347,6 +353,7 @@ ISR(WDT_vect) /** Event handler for the library USB Connection event. */ void EVENT_USB_Device_Connect(void) { + should_run_fade_anim = true; } /** Event handler for the library USB Disconnection event. */ diff --git a/reform2-keyboard-fw/menu.c b/reform2-keyboard-fw/menu.c @@ -101,10 +101,10 @@ int execute_meta_function(int keycode) { return 2; } else if (keycode == KEY_1) { + kbd_brightness_init(); if (remote_turn_on_som()) { anim_hello(); } - kbd_brightness_init(); return 0; } else if (keycode == KEY_R) { @@ -170,8 +170,23 @@ int execute_meta_function(int keycode) { return 0; } +#ifndef KBD_MODE_STANDALONE +void anim_kbd_hello(void) { + kbd_brightness_set(0); + for (int b = 0; b < 8; ++b) { + kbd_brightness_inc(); + Delay_MS(90); + } + for (int b = 0; b < 4; ++b) { + kbd_brightness_dec(); + Delay_MS(110); + } +} +#endif + void anim_hello(void) { gfx_clear(); + kbd_brightness_set(0); gfx_on(); for (int y=0; y<3; y++) { for (int x=0; x<12; x++) { @@ -180,10 +195,16 @@ void anim_hello(void) { } } for (int y=0; y<0xff; y++) { + if ((y % 32) == 0) { + kbd_brightness_inc(); + } gfx_contrast(y); Delay_MS(2); } for (int y=0; y<0xff; y++) { + if ((y % 64) == 0) { + kbd_brightness_dec(); + } gfx_contrast(0xff-y); Delay_MS(2); } @@ -203,5 +224,10 @@ void anim_goodbye(void) { gfx_flush(); } } + int16_t brt = kbd_brightness_get(); + while (brt--) { + kbd_brightness_dec(); + Delay_MS(64); + } gfx_off(); } diff --git a/reform2-keyboard-fw/menu.h b/reform2-keyboard-fw/menu.h @@ -25,4 +25,8 @@ int execute_meta_function(int keycode); void anim_hello(void); void anim_goodbye(void); +#ifndef KBD_MODE_STANDALONE +void anim_kbd_hello(void); +#endif + #endif