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

Feature : Backlight - New option : BACKLIGHT_CAPS_LOCK #4769

Merged
merged 4 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/feature_backlight.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ To change the behaviour of the backlighting, `#define` these in your `config.h`:
|---------------------|-------------|-------------------------------------------------------------------------------------------------------------|
|`BACKLIGHT_PIN` |`B7` |The pin that controls the LEDs. Unless you are designing your own keyboard, you shouldn't need to change this|
|`BACKLIGHT_LEVELS` |`3` |The number of brightness levels (maximum 15 excluding off) |
|`BACKLIGHT_CAPS_LOCK`|*Not defined*|Enable Caps Lock indicator using backlight (for keyboards without dedicated LED) |
|`BACKLIGHT_BREATHING`|*Not defined*|Enable backlight breathing, if hardware PWM is used |
|`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds |

Expand Down
18 changes: 18 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,24 @@ void led_set(uint8_t usb_led)
// PORTE &= ~(1<<6);
// }

#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
// Use backlight as Caps Lock indicator
uint8_t bl_toggle_lvl = 0;

if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK) && !backlight_config.enable) {
// Turning Caps Lock ON and backlight is disabled in config
// Toggling backlight to the brightest level
bl_toggle_lvl = BACKLIGHT_LEVELS;
} else if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK) && backlight_config.enable) {
// Turning Caps Lock OFF and backlight is enabled in config
// Toggling backlight and restoring config level
bl_toggle_lvl = backlight_config.level;
}

// Set level without modify backlight_config to keep ability to restore state
backlight_set(bl_toggle_lvl);
#endif

led_set_kb(usb_led);
}

Expand Down
57 changes: 32 additions & 25 deletions tmk_core/common/avr/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,31 @@ static uint8_t wdt_timeout = 0;
static void power_down(uint8_t wdto)
{
#ifdef PROTOCOL_LUFA
if (USB_DeviceState == DEVICE_STATE_Configured) return;
if (USB_DeviceState == DEVICE_STATE_Configured) return;
#endif
wdt_timeout = wdto;
wdt_timeout = wdto;

// Watchdog Interrupt Mode
wdt_intr_enable(wdto);
// Watchdog Interrupt Mode
wdt_intr_enable(wdto);

#ifdef BACKLIGHT_ENABLE
backlight_set(0);
backlight_set(0);
#endif

// Turn off LED indicators
led_set(0);
// Turn off LED indicators
uint8_t leds_off = 0;
#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
if (is_backlight_enabled()) {
// Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
leds_off |= (1<<USB_LED_CAPS_LOCK);
}
#endif
led_set(leds_off);

#ifdef AUDIO_ENABLE
// This sometimes disables the start-up noise, so it's been disabled
// stop_all_notes();
#endif /* AUDIO_ENABLE */
#ifdef AUDIO_ENABLE
// This sometimes disables the start-up noise, so it's been disabled
// stop_all_notes();
#endif /* AUDIO_ENABLE */
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_disable();
Expand All @@ -124,20 +131,20 @@ static void power_down(uint8_t wdto)
#endif
suspend_power_down_kb();

// TODO: more power saving
// See PicoPower application note
// - I/O port input with pullup
// - prescale clock
// - BOD disable
// - Power Reduction Register PRR
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei();
sleep_cpu();
sleep_disable();

// Disable watchdog after sleep
wdt_disable();
// TODO: more power saving
// See PicoPower application note
// - I/O port input with pullup
// - prescale clock
// - BOD disable
// - Power Reduction Register PRR
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei();
sleep_cpu();
sleep_disable();

// Disable watchdog after sleep
wdt_disable();
}
#endif

Expand Down