diff options
author | Rockman18 <rockman18.spam@gmail.com> | 2019-01-29 01:57:56 +0100 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-01-28 16:57:56 -0800 |
commit | df251d7a1387390383f12b3ff31d71d7e3de5a42 (patch) | |
tree | 8b0a5ca2fae4e8567ec857090d42925e3f347010 | |
parent | 0f507f01696eae0e8fe808d17a19db3f6d9e2ce4 (diff) | |
download | qmk_firmware-df251d7a1387390383f12b3ff31d71d7e3de5a42.tar.gz qmk_firmware-df251d7a1387390383f12b3ff31d71d7e3de5a42.zip |
Backlight - New option : BACKLIGHT_CAPS_LOCK (#4769)
* [BACKLIGHT_CAPS_LOCK_INDICATOR] Use backlight toggling as Caps Lock LED
I've implemented this feature because S65-X doesn't have LED indicators
and the existing led_set_kb(usb_led) function try to use backlight as
indicator but that creates an inconsistency with backlight_config state.
- define `BACKLIGHT_CAPS_LOCK_INDICATOR` to enable Caps Lock indicator
using backlight (for keyboards without dedicated LED)
- Don't turn off LED indicators when suspend because backlight is
already turned off. Else led_set(0) will turn back on backlight.
- Documentation has been updated
* [BACKLIGHT_CAPS_LOCK_INDICATOR] Turn off all LED indicators except Caps Lock if BACKLIGHT_CAPS_LOCK_INDICATOR
* [BACKLIGHT_CAPS_LOCK] Rename BACKLIGHT_CAPS_LOCK_INDICATOR
* [BACKLIGHT_CAPS_LOCK] Use new IS_LED_ON method
-rw-r--r-- | docs/feature_backlight.md | 1 | ||||
-rw-r--r-- | quantum/quantum.c | 18 | ||||
-rw-r--r-- | tmk_core/common/avr/suspend.c | 57 |
3 files changed, 51 insertions, 25 deletions
diff --git a/docs/feature_backlight.md b/docs/feature_backlight.md index f7a35406c..c7a1f131e 100644 --- a/docs/feature_backlight.md +++ b/docs/feature_backlight.md | |||
@@ -40,6 +40,7 @@ To change the behaviour of the backlighting, `#define` these in your `config.h`: | |||
40 | |---------------------|-------------|-------------------------------------------------------------------------------------------------------------| | 40 | |---------------------|-------------|-------------------------------------------------------------------------------------------------------------| |
41 | |`BACKLIGHT_PIN` |`B7` |The pin that controls the LEDs. Unless you are designing your own keyboard, you shouldn't need to change this| | 41 | |`BACKLIGHT_PIN` |`B7` |The pin that controls the LEDs. Unless you are designing your own keyboard, you shouldn't need to change this| |
42 | |`BACKLIGHT_LEVELS` |`3` |The number of brightness levels (maximum 15 excluding off) | | 42 | |`BACKLIGHT_LEVELS` |`3` |The number of brightness levels (maximum 15 excluding off) | |
43 | |`BACKLIGHT_CAPS_LOCK`|*Not defined*|Enable Caps Lock indicator using backlight (for keyboards without dedicated LED) | | ||
43 | |`BACKLIGHT_BREATHING`|*Not defined*|Enable backlight breathing, if hardware PWM is used | | 44 | |`BACKLIGHT_BREATHING`|*Not defined*|Enable backlight breathing, if hardware PWM is used | |
44 | |`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds | | 45 | |`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds | |
45 | 46 | ||
diff --git a/quantum/quantum.c b/quantum/quantum.c index 5d8ffe34e..c1829c768 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
@@ -1448,6 +1448,24 @@ void led_set(uint8_t usb_led) | |||
1448 | // PORTE &= ~(1<<6); | 1448 | // PORTE &= ~(1<<6); |
1449 | // } | 1449 | // } |
1450 | 1450 | ||
1451 | #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | ||
1452 | // Use backlight as Caps Lock indicator | ||
1453 | uint8_t bl_toggle_lvl = 0; | ||
1454 | |||
1455 | if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK) && !backlight_config.enable) { | ||
1456 | // Turning Caps Lock ON and backlight is disabled in config | ||
1457 | // Toggling backlight to the brightest level | ||
1458 | bl_toggle_lvl = BACKLIGHT_LEVELS; | ||
1459 | } else if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK) && backlight_config.enable) { | ||
1460 | // Turning Caps Lock OFF and backlight is enabled in config | ||
1461 | // Toggling backlight and restoring config level | ||
1462 | bl_toggle_lvl = backlight_config.level; | ||
1463 | } | ||
1464 | |||
1465 | // Set level without modify backlight_config to keep ability to restore state | ||
1466 | backlight_set(bl_toggle_lvl); | ||
1467 | #endif | ||
1468 | |||
1451 | led_set_kb(usb_led); | 1469 | led_set_kb(usb_led); |
1452 | } | 1470 | } |
1453 | 1471 | ||
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 28219f4dd..1194a040e 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
@@ -102,24 +102,31 @@ static uint8_t wdt_timeout = 0; | |||
102 | */ | 102 | */ |
103 | static void power_down(uint8_t wdto) { | 103 | static void power_down(uint8_t wdto) { |
104 | #ifdef PROTOCOL_LUFA | 104 | #ifdef PROTOCOL_LUFA |
105 | if (USB_DeviceState == DEVICE_STATE_Configured) return; | 105 | if (USB_DeviceState == DEVICE_STATE_Configured) return; |
106 | #endif | 106 | #endif |
107 | wdt_timeout = wdto; | 107 | wdt_timeout = wdto; |
108 | 108 | ||
109 | // Watchdog Interrupt Mode | 109 | // Watchdog Interrupt Mode |
110 | wdt_intr_enable(wdto); | 110 | wdt_intr_enable(wdto); |
111 | 111 | ||
112 | #ifdef BACKLIGHT_ENABLE | 112 | #ifdef BACKLIGHT_ENABLE |
113 | backlight_set(0); | 113 | backlight_set(0); |
114 | #endif | 114 | #endif |
115 | 115 | ||
116 | // Turn off LED indicators | 116 | // Turn off LED indicators |
117 | led_set(0); | 117 | uint8_t leds_off = 0; |
118 | #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | ||
119 | if (is_backlight_enabled()) { | ||
120 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off | ||
121 | leds_off |= (1<<USB_LED_CAPS_LOCK); | ||
122 | } | ||
123 | #endif | ||
124 | led_set(leds_off); | ||
118 | 125 | ||
119 | #ifdef AUDIO_ENABLE | 126 | #ifdef AUDIO_ENABLE |
120 | // This sometimes disables the start-up noise, so it's been disabled | 127 | // This sometimes disables the start-up noise, so it's been disabled |
121 | // stop_all_notes(); | 128 | // stop_all_notes(); |
122 | #endif /* AUDIO_ENABLE */ | 129 | #endif /* AUDIO_ENABLE */ |
123 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 130 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
124 | #ifdef RGBLIGHT_ANIMATIONS | 131 | #ifdef RGBLIGHT_ANIMATIONS |
125 | rgblight_timer_disable(); | 132 | rgblight_timer_disable(); |
@@ -135,20 +142,20 @@ static void power_down(uint8_t wdto) { | |||
135 | #endif | 142 | #endif |
136 | suspend_power_down_kb(); | 143 | suspend_power_down_kb(); |
137 | 144 | ||
138 | // TODO: more power saving | 145 | // TODO: more power saving |
139 | // See PicoPower application note | 146 | // See PicoPower application note |
140 | // - I/O port input with pullup | 147 | // - I/O port input with pullup |
141 | // - prescale clock | 148 | // - prescale clock |
142 | // - BOD disable | 149 | // - BOD disable |
143 | // - Power Reduction Register PRR | 150 | // - Power Reduction Register PRR |
144 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); | 151 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); |
145 | sleep_enable(); | 152 | sleep_enable(); |
146 | sei(); | 153 | sei(); |
147 | sleep_cpu(); | 154 | sleep_cpu(); |
148 | sleep_disable(); | 155 | sleep_disable(); |
149 | 156 | ||
150 | // Disable watchdog after sleep | 157 | // Disable watchdog after sleep |
151 | wdt_disable(); | 158 | wdt_disable(); |
152 | } | 159 | } |
153 | #endif | 160 | #endif |
154 | 161 | ||