diff options
101 files changed, 474 insertions, 2802 deletions
diff --git a/keyboards/ares/ares.c b/keyboards/ares/ares.c index 07276491c..e6379cb18 100644 --- a/keyboards/ares/ares.c +++ b/keyboards/ares/ares.c | |||
@@ -17,27 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "ares.h" | 18 | #include "ares.h" |
19 | 19 | ||
20 | #ifdef BACKLIGHT_ENABLE | 20 | void keyboard_pre_init_kb(void) { |
21 | void backlight_init_ports(void) { | 21 | led_init_ports(); |
22 | setPinOutput(D0); | 22 | keyboard_pre_init_user(); |
23 | setPinOutput(D1); | ||
24 | setPinOutput(D4); | ||
25 | setPinOutput(D6); | ||
26 | } | 23 | } |
27 | 24 | ||
28 | void backlight_set(uint8_t level) { | 25 | void led_init_ports(void) { |
29 | if (level == 0) { | 26 | setPinOutput(D1); |
30 | // Turn out the lights | 27 | writePinHigh(D1); |
31 | writePinLow(D0); | 28 | } |
32 | writePinLow(D1); | 29 | |
33 | writePinLow(D4); | 30 | bool led_update_kb(led_t led_state) { |
34 | writePinLow(D6); | 31 | if (led_update_user(led_state)) { |
35 | } else { | 32 | writePin(D1, !led_state.caps_lock); |
36 | // Turn on the lights | 33 | } |
37 | writePinHigh(D0); | 34 | return true; |
38 | writePinHigh(D1); | ||
39 | writePinHigh(D4); | ||
40 | writePinHigh(D6); | ||
41 | } | ||
42 | } | 35 | } |
43 | #endif | ||
diff --git a/keyboards/ares/config.h b/keyboards/ares/config.h index f0aa926ea..c50587db9 100644 --- a/keyboards/ares/config.h +++ b/keyboards/ares/config.h | |||
@@ -37,7 +37,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | #define DIODE_DIRECTION COL2ROW | 37 | #define DIODE_DIRECTION COL2ROW |
38 | #define DEBOUNCE 5 | 38 | #define DEBOUNCE 5 |
39 | 39 | ||
40 | #define BACKLIGHT_LEVELS 1 | 40 | #define BACKLIGHT_PIN D4 |
41 | #define BACKLIGHT_LEVELS 3 | ||
41 | #define RGBLIGHT_ANIMATIONS | 42 | #define RGBLIGHT_ANIMATIONS |
42 | 43 | ||
43 | #define NO_UART 1 | 44 | #define NO_UART 1 |
diff --git a/keyboards/ares/rules.mk b/keyboards/ares/rules.mk index 58d36bc67..f54074172 100644 --- a/keyboards/ares/rules.mk +++ b/keyboards/ares/rules.mk | |||
@@ -17,7 +17,7 @@ MOUSEKEY_ENABLE = no | |||
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = yes |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = no | 21 | RGBLIGHT_ENABLE = no |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
diff --git a/keyboards/bfake/bfake.c b/keyboards/bfake/bfake.c index 9039fe546..eb328ba83 100644 --- a/keyboards/bfake/bfake.c +++ b/keyboards/bfake/bfake.c | |||
@@ -17,30 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "bfake.h" | 18 | #include "bfake.h" |
19 | 19 | ||
20 | void backlight_init_ports(void) { | 20 | void keyboard_pre_init_kb(void) { |
21 | setPinOutput(D0); | 21 | led_init_ports(); |
22 | setPinOutput(D1); | 22 | keyboard_pre_init_user(); |
23 | setPinOutput(D4); | 23 | } |
24 | setPinOutput(D6); | ||
25 | 24 | ||
26 | writePinLow(D0); | 25 | void led_init_ports(void) { |
27 | writePinLow(D1); | 26 | setPinOutput(D1); |
28 | writePinLow(D4); | 27 | writePinHigh(D1); |
29 | writePinLow(D6); | ||
30 | } | 28 | } |
31 | 29 | ||
32 | void backlight_set(uint8_t level) { | 30 | bool led_update_kb(led_t led_state) { |
33 | if (level == 0) { | 31 | if (led_update_user(led_state)) { |
34 | // Turn out the lights | 32 | writePin(D1, !led_state.caps_lock); |
35 | writePinLow(D0); | 33 | } |
36 | writePinLow(D1); | 34 | return true; |
37 | writePinLow(D4); | ||
38 | writePinLow(D6); | ||
39 | } else { | ||
40 | // Turn on the lights | ||
41 | writePinHigh(D0); | ||
42 | writePinHigh(D1); | ||
43 | writePinHigh(D4); | ||
44 | writePinHigh(D6); | ||
45 | } | ||
46 | } | 35 | } |
diff --git a/keyboards/bfake/config.h b/keyboards/bfake/config.h index 65f1f3a75..7c814ccc9 100644 --- a/keyboards/bfake/config.h +++ b/keyboards/bfake/config.h | |||
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #ifndef BFAKE_CONFIG_H | 18 | #pragma once |
19 | #define BFAKE_CONFIG_H | ||
20 | 19 | ||
21 | #include "config_common.h" | 20 | #include "config_common.h" |
22 | 21 | ||
@@ -38,9 +37,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
38 | #define DIODE_DIRECTION COL2ROW | 37 | #define DIODE_DIRECTION COL2ROW |
39 | #define DEBOUNCE 5 | 38 | #define DEBOUNCE 5 |
40 | 39 | ||
41 | #define BACKLIGHT_LEVELS 1 | 40 | #define BACKLIGHT_PIN D4 |
41 | #define BACKLIGHT_LEVELS 3 | ||
42 | #define RGBLIGHT_ANIMATIONS | 42 | #define RGBLIGHT_ANIMATIONS |
43 | 43 | ||
44 | #define NO_UART 1 | 44 | #define NO_UART 1 |
45 | |||
46 | #endif | ||
diff --git a/keyboards/bfake/rules.mk b/keyboards/bfake/rules.mk index 107bb4fa9..ab6af983c 100644 --- a/keyboards/bfake/rules.mk +++ b/keyboards/bfake/rules.mk | |||
@@ -17,7 +17,7 @@ MOUSEKEY_ENABLE = yes | |||
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = yes |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = no | 21 | RGBLIGHT_ENABLE = no |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
diff --git a/keyboards/donutcables/budget96/budget96.c b/keyboards/donutcables/budget96/budget96.c index e9125a3e6..7317e24e2 100644 --- a/keyboards/donutcables/budget96/budget96.c +++ b/keyboards/donutcables/budget96/budget96.c | |||
@@ -16,32 +16,22 @@ | |||
16 | 16 | ||
17 | #include "budget96.h" | 17 | #include "budget96.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | keyboard_pre_init_user(); | ||
22 | } | ||
23 | |||
24 | void led_init_ports(void) { | ||
21 | setPinOutput(D0); | 25 | setPinOutput(D0); |
22 | setPinOutput(D1); | 26 | setPinOutput(D1); |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | ||
25 | |||
26 | // turn backlight LEDs on | ||
27 | writePinHigh(D0); | 27 | writePinHigh(D0); |
28 | writePinHigh(D1); | 28 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | ||
31 | } | 29 | } |
32 | 30 | ||
33 | void backlight_set(uint8_t level) { | 31 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 32 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 33 | writePin(D0, !led_state.num_lock); |
36 | writePinLow(D0); | 34 | writePin(D1, !led_state.caps_lock); |
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 35 | } |
36 | return true; | ||
47 | } | 37 | } |
diff --git a/keyboards/donutcables/budget96/config.h b/keyboards/donutcables/budget96/config.h index 127e542f1..dddc8075b 100644 --- a/keyboards/donutcables/budget96/config.h +++ b/keyboards/donutcables/budget96/config.h | |||
@@ -37,5 +37,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | #define DIODE_DIRECTION COL2ROW | 37 | #define DIODE_DIRECTION COL2ROW |
38 | #define DEBOUNCE 5 | 38 | #define DEBOUNCE 5 |
39 | 39 | ||
40 | #define BACKLIGHT_LEVELS 1 | 40 | #define BACKLIGHT_PIN D4 |
41 | #define BACKLIGHT_LEVELS 3 | ||
41 | #define RGBLIGHT_ANIMATIONS | 42 | #define RGBLIGHT_ANIMATIONS |
diff --git a/keyboards/donutcables/budget96/rules.mk b/keyboards/donutcables/budget96/rules.mk index 54328d248..84eace5ed 100644 --- a/keyboards/donutcables/budget96/rules.mk +++ b/keyboards/donutcables/budget96/rules.mk | |||
@@ -15,7 +15,7 @@ BOOTLOADER = bootloadHID | |||
15 | BOOTMAGIC_ENABLE = no | 15 | BOOTMAGIC_ENABLE = no |
16 | MOUSEKEY_ENABLE = yes | 16 | MOUSEKEY_ENABLE = yes |
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = no |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
diff --git a/keyboards/eve/meteor/config.h b/keyboards/eve/meteor/config.h index b23bc877f..2100c3a45 100644 --- a/keyboards/eve/meteor/config.h +++ b/keyboards/eve/meteor/config.h | |||
@@ -36,4 +36,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
36 | #define DIODE_DIRECTION COL2ROW | 36 | #define DIODE_DIRECTION COL2ROW |
37 | #define DEBOUNCE 5 | 37 | #define DEBOUNCE 5 |
38 | 38 | ||
39 | #define BACKLIGHT_LEVELS 1 | 39 | #define BACKLIGHT_PIN D4 |
40 | #define BACKLIGHT_LEVELS 3 | ||
diff --git a/keyboards/eve/meteor/meteor.c b/keyboards/eve/meteor/meteor.c index f5ecbad02..ac1ca5d64 100644 --- a/keyboards/eve/meteor/meteor.c +++ b/keyboards/eve/meteor/meteor.c | |||
@@ -16,32 +16,19 @@ | |||
16 | 16 | ||
17 | #include "meteor.h" | 17 | #include "meteor.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | setPinOutput(D0); | 21 | keyboard_pre_init_user(); |
22 | setPinOutput(D1); | 22 | } |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | ||
25 | 23 | ||
26 | // turn backlight LEDs on | 24 | void led_init_ports(void) { |
27 | writePinHigh(D0); | 25 | setPinOutput(D1); |
28 | writePinHigh(D1); | 26 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | ||
31 | } | 27 | } |
32 | 28 | ||
33 | void backlight_set(uint8_t level) { | 29 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 30 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 31 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | ||
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 32 | } |
33 | return true; | ||
47 | } | 34 | } |
diff --git a/keyboards/exclusive/e6v2/le_bmc/config.h b/keyboards/exclusive/e6v2/le_bmc/config.h index d0b976c1e..ca680f502 100644 --- a/keyboards/exclusive/e6v2/le_bmc/config.h +++ b/keyboards/exclusive/e6v2/le_bmc/config.h | |||
@@ -45,5 +45,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
45 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, C2, C3, C4, C5, D7 } | 45 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, C2, C3, C4, C5, D7 } |
46 | #define DIODE_DIRECTION COL2ROW | 46 | #define DIODE_DIRECTION COL2ROW |
47 | 47 | ||
48 | #define BACKLIGHT_PIN D4 | ||
49 | #define BACKLIGHT_LEVELS 3 | ||
50 | |||
48 | #define RGBLED_NUM 6 | 51 | #define RGBLED_NUM 6 |
49 | #define RGBLIGHT_ANIMATIONS | 52 | #define RGBLIGHT_ANIMATIONS |
diff --git a/keyboards/exclusive/e6v2/le_bmc/le_bmc.c b/keyboards/exclusive/e6v2/le_bmc/le_bmc.c index e3b81c81b..b09e58879 100644 --- a/keyboards/exclusive/e6v2/le_bmc/le_bmc.c +++ b/keyboards/exclusive/e6v2/le_bmc/le_bmc.c | |||
@@ -16,32 +16,19 @@ | |||
16 | 16 | ||
17 | #include "le_bmc.h" | 17 | #include "le_bmc.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | setPinOutput(D0); | 21 | keyboard_pre_init_user(); |
22 | setPinOutput(D1); | 22 | } |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | ||
25 | 23 | ||
26 | // turn backlight LEDs on | 24 | void led_init_ports(void) { |
27 | writePinHigh(D0); | 25 | setPinOutput(D1); |
28 | writePinHigh(D1); | 26 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | ||
31 | } | 27 | } |
32 | 28 | ||
33 | void backlight_set(uint8_t level) { | 29 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 30 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 31 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | ||
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 32 | } |
33 | return true; | ||
47 | } | 34 | } |
diff --git a/keyboards/exclusive/e6v2/le_bmc/rules.mk b/keyboards/exclusive/e6v2/le_bmc/rules.mk index 106044ba7..ded651d3d 100644 --- a/keyboards/exclusive/e6v2/le_bmc/rules.mk +++ b/keyboards/exclusive/e6v2/le_bmc/rules.mk | |||
@@ -17,13 +17,13 @@ BOOTLOADER = bootloadHID | |||
17 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | 17 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) |
18 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) | 18 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) |
19 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | 19 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) |
20 | CONSOLE_ENABLE = yes # Console for debug(+400) | 20 | CONSOLE_ENABLE = no # Console for debug(+400) |
21 | COMMAND_ENABLE = yes # Commands for debug and configuration | 21 | COMMAND_ENABLE = yes # Commands for debug and configuration |
22 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 22 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
23 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 23 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
24 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 24 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
25 | NKRO_ENABLE = no # USB Nkey Rollover | 25 | NKRO_ENABLE = no # USB Nkey Rollover |
26 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default | 26 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality on B7 by default |
27 | WS2812_DRIVER = i2c | 27 | WS2812_DRIVER = i2c |
28 | RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow | 28 | RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow |
29 | MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) | 29 | MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) |
diff --git a/keyboards/exclusive/e6v2/oe_bmc/config.h b/keyboards/exclusive/e6v2/oe_bmc/config.h index fc7c91ca6..a6b56ba00 100644 --- a/keyboards/exclusive/e6v2/oe_bmc/config.h +++ b/keyboards/exclusive/e6v2/oe_bmc/config.h | |||
@@ -45,5 +45,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
45 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, C2, C3, C4, C5, D7 } | 45 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, C2, C3, C4, C5, D7 } |
46 | #define DIODE_DIRECTION COL2ROW | 46 | #define DIODE_DIRECTION COL2ROW |
47 | 47 | ||
48 | #define BACKLIGHT_PIN D4 | ||
49 | #define BACKLIGHT_LEVELS 3 | ||
50 | |||
48 | #define RGBLED_NUM 6 | 51 | #define RGBLED_NUM 6 |
49 | #define RGBLIGHT_ANIMATIONS | 52 | #define RGBLIGHT_ANIMATIONS |
diff --git a/keyboards/exclusive/e6v2/oe_bmc/oe_bmc.c b/keyboards/exclusive/e6v2/oe_bmc/oe_bmc.c index 97d354653..a0a6c579b 100644 --- a/keyboards/exclusive/e6v2/oe_bmc/oe_bmc.c +++ b/keyboards/exclusive/e6v2/oe_bmc/oe_bmc.c | |||
@@ -16,32 +16,19 @@ | |||
16 | 16 | ||
17 | #include "oe_bmc.h" | 17 | #include "oe_bmc.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | setPinOutput(D0); | 21 | keyboard_pre_init_user(); |
22 | setPinOutput(D1); | 22 | } |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | ||
25 | 23 | ||
26 | // turn backlight LEDs on | 24 | void led_init_ports(void) { |
27 | writePinHigh(D0); | 25 | setPinOutput(D1); |
28 | writePinHigh(D1); | 26 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | ||
31 | } | 27 | } |
32 | 28 | ||
33 | void backlight_set(uint8_t level) { | 29 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 30 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 31 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | ||
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 32 | } |
33 | return true; | ||
47 | } | 34 | } |
diff --git a/keyboards/exclusive/e6v2/oe_bmc/rules.mk b/keyboards/exclusive/e6v2/oe_bmc/rules.mk index 106044ba7..ded651d3d 100644 --- a/keyboards/exclusive/e6v2/oe_bmc/rules.mk +++ b/keyboards/exclusive/e6v2/oe_bmc/rules.mk | |||
@@ -17,13 +17,13 @@ BOOTLOADER = bootloadHID | |||
17 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | 17 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) |
18 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) | 18 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) |
19 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | 19 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) |
20 | CONSOLE_ENABLE = yes # Console for debug(+400) | 20 | CONSOLE_ENABLE = no # Console for debug(+400) |
21 | COMMAND_ENABLE = yes # Commands for debug and configuration | 21 | COMMAND_ENABLE = yes # Commands for debug and configuration |
22 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 22 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
23 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 23 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
24 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 24 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
25 | NKRO_ENABLE = no # USB Nkey Rollover | 25 | NKRO_ENABLE = no # USB Nkey Rollover |
26 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default | 26 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality on B7 by default |
27 | WS2812_DRIVER = i2c | 27 | WS2812_DRIVER = i2c |
28 | RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow | 28 | RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow |
29 | MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) | 29 | MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) |
diff --git a/keyboards/exent/config.h b/keyboards/exent/config.h index 08d241f65..4921746c1 100644 --- a/keyboards/exent/config.h +++ b/keyboards/exent/config.h | |||
@@ -39,7 +39,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
39 | #define DIODE_DIRECTION COL2ROW | 39 | #define DIODE_DIRECTION COL2ROW |
40 | #define DEBOUNCE 5 | 40 | #define DEBOUNCE 5 |
41 | 41 | ||
42 | #define BACKLIGHT_LEVELS 1 | 42 | #define BACKLIGHT_PIN D4 |
43 | #define BACKLIGHT_LEVELS 3 | ||
43 | #define RGBLIGHT_ANIMATIONS | 44 | #define RGBLIGHT_ANIMATIONS |
44 | 45 | ||
45 | #define NO_UART 1 | 46 | #define NO_UART 1 |
diff --git a/keyboards/exent/exent.c b/keyboards/exent/exent.c index 82066f7e8..c6870f2c7 100644 --- a/keyboards/exent/exent.c +++ b/keyboards/exent/exent.c | |||
@@ -15,3 +15,26 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "exent.h" | 17 | #include "exent.h" |
18 | |||
19 | void keyboard_pre_init_kb(void) { | ||
20 | led_init_ports(); | ||
21 | keyboard_pre_init_user(); | ||
22 | } | ||
23 | |||
24 | void led_init_ports(void) { | ||
25 | setPinOutput(D0); | ||
26 | setPinOutput(D1); | ||
27 | setPinOutput(D6); | ||
28 | writePinHigh(D0); | ||
29 | writePinHigh(D1); | ||
30 | writePinHigh(D6); | ||
31 | } | ||
32 | |||
33 | bool led_update_kb(led_t led_state) { | ||
34 | if (led_update_user(led_state)) { | ||
35 | writePin(D0, !led_state.num_lock); | ||
36 | writePin(D1, !led_state.caps_lock); | ||
37 | writePin(D6, !led_state.scroll_lock); | ||
38 | } | ||
39 | return true; | ||
40 | } | ||
diff --git a/keyboards/exent/rules.mk b/keyboards/exent/rules.mk index 10442b31b..0ea425ac7 100644 --- a/keyboards/exent/rules.mk +++ b/keyboards/exent/rules.mk | |||
@@ -17,7 +17,7 @@ MOUSEKEY_ENABLE = no | |||
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = yes |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
diff --git a/keyboards/facew/config.h b/keyboards/facew/config.h index 9a31f9278..0dc35e625 100644 --- a/keyboards/facew/config.h +++ b/keyboards/facew/config.h | |||
@@ -37,5 +37,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | #define DIODE_DIRECTION COL2ROW | 37 | #define DIODE_DIRECTION COL2ROW |
38 | #define DEBOUNCE 5 | 38 | #define DEBOUNCE 5 |
39 | 39 | ||
40 | #define BACKLIGHT_LEVELS 1 | 40 | #define BACKLIGHT_PIN D4 |
41 | #define BACKLIGHT_LEVELS 3 | ||
41 | #define RGBLIGHT_ANIMATIONS | 42 | #define RGBLIGHT_ANIMATIONS |
diff --git a/keyboards/facew/facew.c b/keyboards/facew/facew.c index fa58f0cf7..fc176466f 100644 --- a/keyboards/facew/facew.c +++ b/keyboards/facew/facew.c | |||
@@ -17,30 +17,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "facew.h" | 18 | #include "facew.h" |
19 | 19 | ||
20 | void backlight_init_ports(void) { | 20 | void keyboard_pre_init_kb(void) { |
21 | setPinOutput(D0); | 21 | led_init_ports(); |
22 | setPinOutput(D1); | 22 | keyboard_pre_init_user(); |
23 | setPinOutput(D4); | 23 | } |
24 | setPinOutput(D6); | ||
25 | 24 | ||
26 | writePinLow(D0); | 25 | void led_init_ports(void) { |
27 | writePinLow(D1); | 26 | setPinOutput(D0); |
28 | writePinLow(D4); | 27 | setPinOutput(D1); |
29 | writePinLow(D6); | 28 | writePinHigh(D0); |
29 | writePinHigh(D1); | ||
30 | } | 30 | } |
31 | 31 | ||
32 | void backlight_set(uint8_t level) { | 32 | bool led_update_kb(led_t led_state) { |
33 | if (level == 0) { | 33 | if (led_update_user(led_state)) { |
34 | // Turn out the lights | 34 | writePin(D1, !led_state.caps_lock); |
35 | writePinLow(D0); | 35 | } |
36 | writePinLow(D1); | 36 | return true; |
37 | writePinLow(D4); | ||
38 | writePinLow(D6); | ||
39 | } else { | ||
40 | // Turn on the lights | ||
41 | writePinHigh(D0); | ||
42 | writePinHigh(D1); | ||
43 | writePinHigh(D4); | ||
44 | writePinHigh(D6); | ||
45 | } | ||
46 | } | 37 | } |
diff --git a/keyboards/facew/rules.mk b/keyboards/facew/rules.mk index c4117d15d..81cfb758c 100644 --- a/keyboards/facew/rules.mk +++ b/keyboards/facew/rules.mk | |||
@@ -15,7 +15,7 @@ BOOTLOADER = bootloadHID | |||
15 | BOOTMAGIC_ENABLE = no | 15 | BOOTMAGIC_ENABLE = no |
16 | MOUSEKEY_ENABLE = yes | 16 | MOUSEKEY_ENABLE = yes |
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = no |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
diff --git a/keyboards/ft/mars80/config.h b/keyboards/ft/mars80/config.h index 1bf939287..38c3e851a 100644 --- a/keyboards/ft/mars80/config.h +++ b/keyboards/ft/mars80/config.h | |||
@@ -38,7 +38,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
38 | #define DIODE_DIRECTION COL2ROW | 38 | #define DIODE_DIRECTION COL2ROW |
39 | #define DEBOUNCE 5 | 39 | #define DEBOUNCE 5 |
40 | 40 | ||
41 | #define BACKLIGHT_LEVELS 1 | 41 | #define BACKLIGHT_PIN D4 |
42 | #define BACKLIGHT_LEVELS 3 | ||
42 | #define RGBLIGHT_ANIMATIONS | 43 | #define RGBLIGHT_ANIMATIONS |
43 | 44 | ||
44 | #define NO_UART 1 | 45 | #define NO_UART 1 |
diff --git a/keyboards/ft/mars80/mars80.c b/keyboards/ft/mars80/mars80.c index 8e5127408..ca1950353 100644 --- a/keyboards/ft/mars80/mars80.c +++ b/keyboards/ft/mars80/mars80.c | |||
@@ -16,32 +16,22 @@ | |||
16 | 16 | ||
17 | #include "mars80.h" | 17 | #include "mars80.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | setPinOutput(D0); | 21 | keyboard_pre_init_user(); |
22 | } | ||
23 | |||
24 | void led_init_ports(void) { | ||
22 | setPinOutput(D1); | 25 | setPinOutput(D1); |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | 26 | setPinOutput(D6); |
25 | |||
26 | // turn backlight LEDs on | ||
27 | writePinHigh(D0); | ||
28 | writePinHigh(D1); | 27 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | 28 | writePinHigh(D6); |
31 | } | 29 | } |
32 | 30 | ||
33 | void backlight_set(uint8_t level) { | 31 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 32 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 33 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | 34 | writePin(D6, !led_state.scroll_lock); |
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 35 | } |
36 | return true; | ||
47 | } | 37 | } |
diff --git a/keyboards/gray_studio/hb85/hb85.c b/keyboards/gray_studio/hb85/hb85.c index 21562b9e0..57f5e6031 100644 --- a/keyboards/gray_studio/hb85/hb85.c +++ b/keyboards/gray_studio/hb85/hb85.c | |||
@@ -18,32 +18,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | 18 | ||
19 | #include "hb85.h" | 19 | #include "hb85.h" |
20 | 20 | ||
21 | void backlight_init_ports(void) { | 21 | void keyboard_pre_init_kb(void) { |
22 | // initialize pins D0, D1, D4 and D6 as output | 22 | led_init_ports(); |
23 | keyboard_pre_init_user(); | ||
24 | } | ||
25 | |||
26 | void led_init_ports(void) { | ||
23 | setPinOutput(D0); | 27 | setPinOutput(D0); |
24 | setPinOutput(D1); | 28 | setPinOutput(D1); |
25 | setPinOutput(D4); | ||
26 | setPinOutput(D6); | 29 | setPinOutput(D6); |
27 | |||
28 | // turn backlight LEDs on | ||
29 | writePinHigh(D0); | 30 | writePinHigh(D0); |
30 | writePinHigh(D1); | 31 | writePinHigh(D1); |
31 | writePinHigh(D4); | ||
32 | writePinHigh(D6); | 32 | writePinHigh(D6); |
33 | } | 33 | } |
34 | 34 | ||
35 | void backlight_set(uint8_t level) { | 35 | bool led_update_kb(led_t led_state) { |
36 | if (level == 0) { | 36 | if (led_update_user(led_state)) { |
37 | // turn backlight LEDs off | 37 | writePin(D0, !led_state.num_lock); |
38 | writePinLow(D0); | 38 | writePin(D1, !led_state.caps_lock); |
39 | writePinLow(D1); | 39 | writePin(D6, !led_state.scroll_lock); |
40 | writePinLow(D4); | ||
41 | writePinLow(D6); | ||
42 | } else { | ||
43 | // turn backlight LEDs on | ||
44 | writePinHigh(D0); | ||
45 | writePinHigh(D1); | ||
46 | writePinHigh(D4); | ||
47 | writePinHigh(D6); | ||
48 | } | 40 | } |
41 | return true; | ||
49 | } | 42 | } |
diff --git a/keyboards/gray_studio/hb85/rules.mk b/keyboards/gray_studio/hb85/rules.mk index ec57b03dc..79b783e42 100644 --- a/keyboards/gray_studio/hb85/rules.mk +++ b/keyboards/gray_studio/hb85/rules.mk | |||
@@ -17,7 +17,7 @@ MOUSEKEY_ENABLE = no | |||
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = yes |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
diff --git a/keyboards/jc65/v32a/config.h b/keyboards/jc65/v32a/config.h index 5439dbe39..392aebc2a 100644 --- a/keyboards/jc65/v32a/config.h +++ b/keyboards/jc65/v32a/config.h | |||
@@ -32,7 +32,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
32 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 } | 32 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 } |
33 | #define DIODE_DIRECTION COL2ROW | 33 | #define DIODE_DIRECTION COL2ROW |
34 | 34 | ||
35 | #define BACKLIGHT_LEVELS 1 | 35 | #define BACKLIGHT_PIN D4 |
36 | #define BACKLIGHT_LEVELS 3 | ||
37 | |||
36 | #define RGBLED_NUM 16 | 38 | #define RGBLED_NUM 16 |
37 | #define RGBLIGHT_ANIMATIONS | 39 | #define RGBLIGHT_ANIMATIONS |
38 | #define RGBLIGHT_HUE_STEP 8 | 40 | #define RGBLIGHT_HUE_STEP 8 |
diff --git a/keyboards/jc65/v32a/v32a.c b/keyboards/jc65/v32a/v32a.c index 2a289872f..627661a57 100644 --- a/keyboards/jc65/v32a/v32a.c +++ b/keyboards/jc65/v32a/v32a.c | |||
@@ -17,32 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "v32a.h" | 18 | #include "v32a.h" |
19 | 19 | ||
20 | #ifdef BACKLIGHT_ENABLE | 20 | void keyboard_pre_init_kb(void) { |
21 | void backlight_init_ports(void) { | 21 | led_init_ports(); |
22 | setPinOutput(D0); | 22 | keyboard_pre_init_user(); |
23 | setPinOutput(D1); | 23 | } |
24 | setPinOutput(D4); | ||
25 | setPinOutput(D6); | ||
26 | 24 | ||
27 | writePinLow(D0); | 25 | void led_init_ports(void) { |
28 | writePinLow(D1); | 26 | setPinOutput(D1); |
29 | writePinLow(D4); | 27 | writePinHigh(D1); |
30 | writePinLow(D6); | ||
31 | } | 28 | } |
32 | 29 | ||
33 | void backlight_set(uint8_t level) { | 30 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 31 | if (led_update_user(led_state)) { |
35 | // Turn out the lights | 32 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | 33 | } |
37 | writePinLow(D1); | 34 | return true; |
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // Turn on the lights | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | ||
47 | } | 35 | } |
48 | #endif | ||
diff --git a/keyboards/jj40/config.h b/keyboards/jj40/config.h index 2310ce87e..90bcacfd1 100644 --- a/keyboards/jj40/config.h +++ b/keyboards/jj40/config.h | |||
@@ -35,7 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
35 | 35 | ||
36 | #define BACKLIGHT_PIN D4 | 36 | #define BACKLIGHT_PIN D4 |
37 | #define BACKLIGHT_LEVELS 12 | 37 | #define BACKLIGHT_LEVELS 12 |
38 | // #define BACKLIGHT_BREATHING // Requires #4324 to enable hardware pwm for atmega32a | 38 | #define BACKLIGHT_BREATHING |
39 | 39 | ||
40 | /* RGB underglow */ | 40 | /* RGB underglow */ |
41 | // NOTE: for PS2AVRGB boards, underglow commands are sent via I2C to 0xB0. | 41 | // NOTE: for PS2AVRGB boards, underglow commands are sent via I2C to 0xB0. |
diff --git a/keyboards/jj4x4/config.h b/keyboards/jj4x4/config.h index 8918e60da..b3f33d6e7 100644 --- a/keyboards/jj4x4/config.h +++ b/keyboards/jj4x4/config.h | |||
@@ -38,7 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
38 | 38 | ||
39 | #define BACKLIGHT_PIN D4 | 39 | #define BACKLIGHT_PIN D4 |
40 | #define BACKLIGHT_LEVELS 12 | 40 | #define BACKLIGHT_LEVELS 12 |
41 | // #define BACKLIGHT_BREATHING // Requires #4324 to enable hardware pwm for atmega32a | 41 | #define BACKLIGHT_BREATHING |
42 | 42 | ||
43 | /* RGB underglow */ | 43 | /* RGB underglow */ |
44 | // NOTE: for PS2AVRGB boards, underglow commands are sent via I2C to 0xB0. | 44 | // NOTE: for PS2AVRGB boards, underglow commands are sent via I2C to 0xB0. |
diff --git a/keyboards/jj50/backlight.c b/keyboards/jj50/backlight.c deleted file mode 100644 index fbd241fa9..000000000 --- a/keyboards/jj50/backlight.c +++ /dev/null | |||
@@ -1,213 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #include "backlight.h" | ||
7 | #include "quantum.h" | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | #include <avr/interrupt.h> | ||
11 | |||
12 | #include "backlight_custom.h" | ||
13 | #include "breathing_custom.h" | ||
14 | |||
15 | // DEBUG | ||
16 | #include <stdlib.h> | ||
17 | #include <stdio.h> | ||
18 | |||
19 | // Port D: digital pins of the AVR chipset | ||
20 | #define NUMLOCK_PORT (1 << 0) // D0 | ||
21 | #define CAPSLOCK_PORT (1 << 1) // D1 | ||
22 | #define BACKLIGHT_PORT (1 << 4) // D4 | ||
23 | #define SCROLLLOCK_PORT (1 << 6) // D6 | ||
24 | |||
25 | #define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 | ||
26 | #define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default | ||
27 | |||
28 | #define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask | ||
29 | |||
30 | #define PWM_MAX 0xFF | ||
31 | #define TIMER_TOP 255 // 8 bit PWM | ||
32 | |||
33 | extern backlight_config_t backlight_config; | ||
34 | |||
35 | /** | ||
36 | * References | ||
37 | * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation | ||
38 | * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b | ||
39 | * Timers: http://www.avrbeginners.net/architecture/timers/timers.html | ||
40 | * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/ | ||
41 | * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware | ||
42 | */ | ||
43 | |||
44 | // @Override | ||
45 | // turn LEDs on and off depending on USB caps/num/scroll lock states. | ||
46 | __attribute__ ((weak)) | ||
47 | void led_set_user(uint8_t usb_led) { | ||
48 | if (usb_led & (1 << USB_LED_NUM_LOCK)) { | ||
49 | // turn on | ||
50 | DDRD |= NUMLOCK_PORT; | ||
51 | PORTD |= NUMLOCK_PORT; | ||
52 | } else { | ||
53 | // turn off | ||
54 | DDRD &= ~NUMLOCK_PORT; | ||
55 | PORTD &= ~NUMLOCK_PORT; | ||
56 | } | ||
57 | |||
58 | if (usb_led & (1 << USB_LED_CAPS_LOCK)) { | ||
59 | DDRD |= CAPSLOCK_PORT; | ||
60 | PORTD |= CAPSLOCK_PORT; | ||
61 | } else { | ||
62 | DDRD &= ~CAPSLOCK_PORT; | ||
63 | PORTD &= ~CAPSLOCK_PORT; | ||
64 | } | ||
65 | |||
66 | if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { | ||
67 | DDRD |= SCROLLLOCK_PORT; | ||
68 | PORTD |= SCROLLLOCK_PORT; | ||
69 | } else { | ||
70 | DDRD &= ~SCROLLLOCK_PORT; | ||
71 | PORTD &= ~SCROLLLOCK_PORT; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | #ifdef BACKLIGHT_ENABLE | ||
76 | |||
77 | // sets up Timer 1 for 8-bit PWM | ||
78 | void timer1PWMSetup(void) { // NOTE ONLY CALL THIS ONCE | ||
79 | // default 8 bit mode | ||
80 | TCCR1A &= ~(1 << 1); // cbi(TCCR1A,PWM11); <- set PWM11 bit to HIGH | ||
81 | TCCR1A |= (1 << 0); // sbi(TCCR1A,PWM10); <- set PWM10 bit to LOW | ||
82 | |||
83 | // clear output compare value A | ||
84 | // outb(OCR1AH, 0); | ||
85 | // outb(OCR1AL, 0); | ||
86 | |||
87 | // clear output comparator registers for B | ||
88 | OCR1BH = 0; // outb(OCR1BH, 0); | ||
89 | OCR1BL = 0; // outb(OCR1BL, 0); | ||
90 | } | ||
91 | |||
92 | bool is_init = false; | ||
93 | void timer1Init(void) { | ||
94 | // timer1SetPrescaler(TIMER1PRESCALE) | ||
95 | // set to DIV/64 | ||
96 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER1PRESCALE; | ||
97 | |||
98 | // reset TCNT1 | ||
99 | TCNT1H = 0; // outb(TCNT1H, 0); | ||
100 | TCNT1L = 0; // outb(TCNT1L, 0); | ||
101 | |||
102 | // TOIE1: Timer Overflow Interrupt Enable (Timer 1); | ||
103 | TIMSK |= _BV(TOIE1); // sbi(TIMSK, TOIE1); | ||
104 | |||
105 | is_init = true; | ||
106 | } | ||
107 | |||
108 | void timer1UnInit(void) { | ||
109 | // set prescaler back to NONE | ||
110 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | 0x00; // TIMERRTC_CLK_STOP | ||
111 | |||
112 | // disable timer overflow interrupt | ||
113 | TIMSK &= ~_BV(TOIE1); // overflow bit? | ||
114 | |||
115 | setPWM(0); | ||
116 | |||
117 | is_init = false; | ||
118 | } | ||
119 | |||
120 | |||
121 | // handle TCNT1 overflow | ||
122 | //! Interrupt handler for tcnt1 overflow interrupt | ||
123 | ISR(TIMER1_OVF_vect, ISR_NOBLOCK) | ||
124 | { | ||
125 | // sei(); | ||
126 | // handle breathing here | ||
127 | #ifdef BACKLIGHT_BREATHING | ||
128 | if (is_breathing()) { | ||
129 | custom_breathing_handler(); | ||
130 | } | ||
131 | #endif | ||
132 | |||
133 | // TODO call user defined function | ||
134 | } | ||
135 | |||
136 | // enable timer 1 PWM | ||
137 | // timer1PWMBOn() | ||
138 | void timer1PWMBEnable(void) { | ||
139 | // turn on channel B (OC1B) PWM output | ||
140 | // set OC1B as non-inverted PWM | ||
141 | TCCR1A |= _BV(COM1B1); | ||
142 | TCCR1A &= ~_BV(COM1B0); | ||
143 | } | ||
144 | |||
145 | // disable timer 1 PWM | ||
146 | // timer1PWMBOff() | ||
147 | void timer1PWMBDisable(void) { | ||
148 | TCCR1A &= ~_BV(COM1B1); | ||
149 | TCCR1A &= ~_BV(COM1B0); | ||
150 | } | ||
151 | |||
152 | void enableBacklight(void) { | ||
153 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
154 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
155 | } | ||
156 | |||
157 | void disableBacklight(void) { | ||
158 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
159 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
160 | } | ||
161 | |||
162 | void startPWM(void) { | ||
163 | timer1Init(); | ||
164 | timer1PWMBEnable(); | ||
165 | enableBacklight(); | ||
166 | } | ||
167 | |||
168 | void stopPWM(void) { | ||
169 | timer1UnInit(); | ||
170 | disableBacklight(); | ||
171 | timer1PWMBDisable(); | ||
172 | } | ||
173 | |||
174 | void b_led_init_ports(void) { | ||
175 | /* turn backlight on/off depending on user preference */ | ||
176 | #if BACKLIGHT_ON_STATE == 0 | ||
177 | // DDRx register: sets the direction of Port D | ||
178 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
179 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
180 | #else | ||
181 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
182 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
183 | #endif | ||
184 | |||
185 | timer1PWMSetup(); | ||
186 | startPWM(); | ||
187 | |||
188 | #ifdef BACKLIGHT_BREATHING | ||
189 | breathing_enable(); | ||
190 | #endif | ||
191 | } | ||
192 | |||
193 | void b_led_set(uint8_t level) { | ||
194 | if (level > BACKLIGHT_LEVELS) { | ||
195 | level = BACKLIGHT_LEVELS; | ||
196 | } | ||
197 | |||
198 | setPWM((int)(TIMER_TOP * (float) level / BACKLIGHT_LEVELS)); | ||
199 | } | ||
200 | |||
201 | // called every matrix scan | ||
202 | void b_led_task(void) { | ||
203 | // do nothing for now | ||
204 | } | ||
205 | |||
206 | void setPWM(uint16_t xValue) { | ||
207 | if (xValue > TIMER_TOP) { | ||
208 | xValue = TIMER_TOP; | ||
209 | } | ||
210 | OCR1B = xValue; // timer1PWMBSet(xValue); | ||
211 | } | ||
212 | |||
213 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/jj50/backlight_custom.h b/keyboards/jj50/backlight_custom.h deleted file mode 100644 index 7210be840..000000000 --- a/keyboards/jj50/backlight_custom.h +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #ifndef BACKLIGHT_CUSTOM_H | ||
7 | #define BACKLIGHT_CUSTOM_H | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | void b_led_init_ports(void); | ||
11 | void b_led_set(uint8_t level); | ||
12 | void b_led_task(void); | ||
13 | void setPWM(uint16_t xValue); | ||
14 | |||
15 | #endif // BACKLIGHT_CUSTOM_H | ||
diff --git a/keyboards/jj50/breathing_custom.h b/keyboards/jj50/breathing_custom.h deleted file mode 100644 index 71416b1b4..000000000 --- a/keyboards/jj50/breathing_custom.h +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /** | ||
2 | * Breathing effect code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Works in conjunction with `backlight.c`. | ||
4 | * | ||
5 | * Code adapted from `quantum.c` to register with the existing TIMER1 overflow | ||
6 | * handler in `backlight.c` instead of setting up its own timer. | ||
7 | * Kenneth A. (github.com/krusli | krusli.me) | ||
8 | */ | ||
9 | |||
10 | #ifdef BACKLIGHT_ENABLE | ||
11 | #ifdef BACKLIGHT_BREATHING | ||
12 | |||
13 | #include "backlight_custom.h" | ||
14 | |||
15 | #ifndef BREATHING_PERIOD | ||
16 | #define BREATHING_PERIOD 6 | ||
17 | #endif | ||
18 | |||
19 | #define breathing_min() do {breathing_counter = 0;} while (0) | ||
20 | #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) | ||
21 | |||
22 | // TODO make this share code with quantum.c | ||
23 | |||
24 | #define BREATHING_NO_HALT 0 | ||
25 | #define BREATHING_HALT_OFF 1 | ||
26 | #define BREATHING_HALT_ON 2 | ||
27 | #define BREATHING_STEPS 128 | ||
28 | |||
29 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
30 | static uint8_t breathing_halt = BREATHING_NO_HALT; | ||
31 | static uint16_t breathing_counter = 0; | ||
32 | |||
33 | static bool breathing = false; | ||
34 | |||
35 | bool is_breathing(void) { | ||
36 | return breathing; | ||
37 | } | ||
38 | |||
39 | // See http://jared.geek.nz/2013/feb/linear-led-pwm | ||
40 | static uint16_t cie_lightness(uint16_t v) { | ||
41 | if (v <= 5243) // if below 8% of max | ||
42 | return v / 9; // same as dividing by 900% | ||
43 | else { | ||
44 | uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare | ||
45 | // to get a useful result with integer division, we shift left in the expression above | ||
46 | // and revert what we've done again after squaring. | ||
47 | y = y * y * y >> 8; | ||
48 | if (y > 0xFFFFUL) // prevent overflow | ||
49 | return 0xFFFFU; | ||
50 | else | ||
51 | return (uint16_t) y; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void breathing_enable(void) { | ||
56 | breathing = true; | ||
57 | breathing_counter = 0; | ||
58 | breathing_halt = BREATHING_NO_HALT; | ||
59 | // interrupt already registered | ||
60 | } | ||
61 | |||
62 | void breathing_pulse(void) { | ||
63 | if (get_backlight_level() == 0) | ||
64 | breathing_min(); | ||
65 | else | ||
66 | breathing_max(); | ||
67 | breathing_halt = BREATHING_HALT_ON; | ||
68 | // breathing_interrupt_enable(); | ||
69 | breathing = true; | ||
70 | } | ||
71 | |||
72 | void breathing_disable(void) { | ||
73 | breathing = false; | ||
74 | // backlight_set(get_backlight_level()); | ||
75 | b_led_set(get_backlight_level()); // custom implementation of backlight_set() | ||
76 | } | ||
77 | |||
78 | void breathing_self_disable(void) | ||
79 | { | ||
80 | if (get_backlight_level() == 0) | ||
81 | breathing_halt = BREATHING_HALT_OFF; | ||
82 | else | ||
83 | breathing_halt = BREATHING_HALT_ON; | ||
84 | } | ||
85 | |||
86 | void breathing_toggle(void) { | ||
87 | if (is_breathing()) | ||
88 | breathing_disable(); | ||
89 | else | ||
90 | breathing_enable(); | ||
91 | } | ||
92 | |||
93 | void breathing_period_set(uint8_t value) | ||
94 | { | ||
95 | if (!value) | ||
96 | value = 1; | ||
97 | breathing_period = value; | ||
98 | } | ||
99 | |||
100 | void breathing_period_default(void) { | ||
101 | breathing_period_set(BREATHING_PERIOD); | ||
102 | } | ||
103 | |||
104 | void breathing_period_inc(void) | ||
105 | { | ||
106 | breathing_period_set(breathing_period+1); | ||
107 | } | ||
108 | |||
109 | void breathing_period_dec(void) | ||
110 | { | ||
111 | breathing_period_set(breathing_period-1); | ||
112 | } | ||
113 | |||
114 | /* To generate breathing curve in python: | ||
115 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | ||
116 | */ | ||
117 | static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
118 | |||
119 | // Use this before the cie_lightness function. | ||
120 | static inline uint16_t scale_backlight(uint16_t v) { | ||
121 | return v / BACKLIGHT_LEVELS * get_backlight_level(); | ||
122 | } | ||
123 | |||
124 | void custom_breathing_handler(void) { | ||
125 | uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; | ||
126 | // resetting after one period to prevent ugly reset at overflow. | ||
127 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); | ||
128 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; | ||
129 | |||
130 | if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || | ||
131 | ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) | ||
132 | { | ||
133 | // breathing_interrupt_disable(); | ||
134 | } | ||
135 | |||
136 | setPWM(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U))); | ||
137 | } | ||
138 | |||
139 | #endif // BACKLIGHT_BREATHING | ||
140 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/jj50/config.h b/keyboards/jj50/config.h index 884a28d50..9b9feb067 100644 --- a/keyboards/jj50/config.h +++ b/keyboards/jj50/config.h | |||
@@ -38,7 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
38 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4 } | 38 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4 } |
39 | #define DIODE_DIRECTION COL2ROW | 39 | #define DIODE_DIRECTION COL2ROW |
40 | 40 | ||
41 | //#define BACKLIGHT_PIN D4 | 41 | #define BACKLIGHT_PIN D4 |
42 | #define BACKLIGHT_LEVELS 12 | 42 | #define BACKLIGHT_LEVELS 12 |
43 | 43 | ||
44 | #define RGB_DI_PIN E2 | 44 | #define RGB_DI_PIN E2 |
diff --git a/keyboards/jj50/jj50.c b/keyboards/jj50/jj50.c index a302adf40..91b10aebe 100644 --- a/keyboards/jj50/jj50.c +++ b/keyboards/jj50/jj50.c | |||
@@ -16,20 +16,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "jj50.h" | 18 | #include "jj50.h" |
19 | |||
20 | #include "backlight.h" | ||
21 | #include "backlight_custom.h" | ||
22 | |||
23 | #ifdef BACKLIGHT_ENABLE | ||
24 | void backlight_init_ports(void) { | ||
25 | b_led_init_ports(); | ||
26 | } | ||
27 | |||
28 | void backlight_task(void) { | ||
29 | b_led_task(); | ||
30 | } | ||
31 | |||
32 | void backlight_set(uint8_t level) { | ||
33 | b_led_set(level); | ||
34 | } | ||
35 | #endif | ||
diff --git a/keyboards/jj50/rules.mk b/keyboards/jj50/rules.mk index 62b21e4df..38faf3716 100644 --- a/keyboards/jj50/rules.mk +++ b/keyboards/jj50/rules.mk | |||
@@ -29,6 +29,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | |||
29 | 29 | ||
30 | #OPT_DEFS = -DDEBUG_LEVEL=0 | 30 | #OPT_DEFS = -DDEBUG_LEVEL=0 |
31 | 31 | ||
32 | SRC = backlight.c | ||
33 | |||
34 | LAYOUTS = ortho_5x12 | 32 | LAYOUTS = ortho_5x12 |
diff --git a/keyboards/kbdfans/kbdpad/mk1/mk1.c b/keyboards/kbdfans/kbdpad/mk1/mk1.c index aa781875c..f5fe47741 100644 --- a/keyboards/kbdfans/kbdpad/mk1/mk1.c +++ b/keyboards/kbdfans/kbdpad/mk1/mk1.c | |||
@@ -16,14 +16,19 @@ | |||
16 | 16 | ||
17 | #include "mk1.h" | 17 | #include "mk1.h" |
18 | 18 | ||
19 | #define NUMLOCK_PIN D0 | 19 | void keyboard_pre_init_kb(void) { |
20 | led_init_ports(); | ||
21 | keyboard_pre_init_user(); | ||
22 | } | ||
20 | 23 | ||
21 | void matrix_init_kb(void) { | 24 | void led_init_ports(void) { |
22 | setPinOutput(NUMLOCK_PIN); | 25 | setPinOutput(D0); |
23 | matrix_init_user(); | 26 | writePinHigh(D0); |
24 | } | 27 | } |
25 | 28 | ||
26 | void led_set_kb(uint8_t usb_led) { | 29 | bool led_update_kb(led_t led_state) { |
27 | writePin(NUMLOCK_PIN, IS_LED_ON(usb_led, USB_LED_NUM_LOCK)); | 30 | if (led_update_user(led_state)) { |
28 | led_set_user(usb_led); | 31 | writePin(D0, !led_state.num_lock); |
32 | } | ||
33 | return true; | ||
29 | } | 34 | } |
diff --git a/keyboards/mechmini/v1/config.h b/keyboards/mechmini/v1/config.h index eb15a368a..07422f9ff 100644 --- a/keyboards/mechmini/v1/config.h +++ b/keyboards/mechmini/v1/config.h | |||
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #ifndef V1_CONFIG_H | 18 | #pragma once |
19 | #define V1_CONFIG_H | ||
20 | 19 | ||
21 | #include "config_common.h" | 20 | #include "config_common.h" |
22 | 21 | ||
@@ -38,11 +37,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
38 | 37 | ||
39 | #define NO_UART 1 | 38 | #define NO_UART 1 |
40 | 39 | ||
40 | #define BACKLIGHT_PIN D4 | ||
41 | #define BACKLIGHT_LEVELS 3 | ||
42 | |||
41 | /* RGB underglow */ | 43 | /* RGB underglow */ |
42 | // The RGB_DI_PIN value seems to be shared between all PS2AVRGB boards. | 44 | // The RGB_DI_PIN value seems to be shared between all PS2AVRGB boards. |
43 | // The same pin is used on the JJ40, at least. | 45 | // The same pin is used on the JJ40, at least. |
44 | #define RGBLED_NUM 16 | 46 | #define RGBLED_NUM 16 |
45 | #define RGBLIGHT_ANIMATIONS | 47 | #define RGBLIGHT_ANIMATIONS |
46 | #define RGB_DI_PIN E2 | 48 | #define RGB_DI_PIN E2 |
47 | |||
48 | #endif | ||
diff --git a/keyboards/mechmini/v1/rules.mk b/keyboards/mechmini/v1/rules.mk index 1c6252c59..6f2adc2f8 100644 --- a/keyboards/mechmini/v1/rules.mk +++ b/keyboards/mechmini/v1/rules.mk | |||
@@ -17,7 +17,7 @@ MOUSEKEY_ENABLE = yes | |||
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = yes |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
diff --git a/keyboards/mehkee96/config.h b/keyboards/mehkee96/config.h index d506626d1..afc9d0a7b 100644 --- a/keyboards/mehkee96/config.h +++ b/keyboards/mehkee96/config.h | |||
@@ -16,6 +16,9 @@ | |||
16 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 } | 16 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 } |
17 | #define DIODE_DIRECTION COL2ROW | 17 | #define DIODE_DIRECTION COL2ROW |
18 | 18 | ||
19 | #define BACKLIGHT_PIN D4 | ||
20 | #define BACKLIGHT_LEVELS 3 | ||
21 | |||
19 | #define RGBLED_NUM 16 | 22 | #define RGBLED_NUM 16 |
20 | #define RGBLIGHT_ANIMATIONS | 23 | #define RGBLIGHT_ANIMATIONS |
21 | /* key combination for command */ | 24 | /* key combination for command */ |
diff --git a/keyboards/mehkee96/mehkee96.c b/keyboards/mehkee96/mehkee96.c index d9e2bac7a..2da25b6b8 100644 --- a/keyboards/mehkee96/mehkee96.c +++ b/keyboards/mehkee96/mehkee96.c | |||
@@ -16,3 +16,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "mehkee96.h" | 18 | #include "mehkee96.h" |
19 | |||
20 | void keyboard_pre_init_kb(void) { | ||
21 | led_init_ports(); | ||
22 | keyboard_pre_init_user(); | ||
23 | } | ||
24 | |||
25 | void led_init_ports(void) { | ||
26 | setPinOutput(D0); | ||
27 | setPinOutput(D1); | ||
28 | writePinHigh(D0); | ||
29 | writePinHigh(D1); | ||
30 | } | ||
31 | |||
32 | bool led_update_kb(led_t led_state) { | ||
33 | if (led_update_user(led_state)) { | ||
34 | writePin(D0, !led_state.num_lock); | ||
35 | writePin(D1, !led_state.caps_lock); | ||
36 | } | ||
37 | return true; | ||
38 | } | ||
diff --git a/keyboards/mehkee96/rules.mk b/keyboards/mehkee96/rules.mk index a7d36548f..772706e6c 100644 --- a/keyboards/mehkee96/rules.mk +++ b/keyboards/mehkee96/rules.mk | |||
@@ -17,9 +17,9 @@ BOOTLOADER = bootloadHID | |||
17 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) | 17 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) |
18 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) | 18 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) |
19 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | 19 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) |
20 | CONSOLE_ENABLE = yes # Console for debug(+400) | 20 | CONSOLE_ENABLE = no # Console for debug(+400) |
21 | COMMAND_ENABLE = yes # Commands for debug and configuration | 21 | COMMAND_ENABLE = yes # Commands for debug and configuration |
22 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | 22 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality |
23 | RGBLIGHT_ENABLE = yes | 23 | RGBLIGHT_ENABLE = yes |
24 | WS2812_DRIVER = i2c | 24 | WS2812_DRIVER = i2c |
25 | 25 | ||
diff --git a/keyboards/panc60/config.h b/keyboards/panc60/config.h index c565f39bc..b3bcdc973 100644 --- a/keyboards/panc60/config.h +++ b/keyboards/panc60/config.h | |||
@@ -37,5 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | #define DIODE_DIRECTION COL2ROW | 37 | #define DIODE_DIRECTION COL2ROW |
38 | #define DEBOUNCE 5 | 38 | #define DEBOUNCE 5 |
39 | 39 | ||
40 | #define BACKLIGHT_LEVELS 1 | 40 | #define BACKLIGHT_PIN D4 |
41 | #define BACKLIGHT_LEVELS 3 | ||
42 | |||
41 | #define RGBLIGHT_ANIMATIONS | 43 | #define RGBLIGHT_ANIMATIONS |
diff --git a/keyboards/panc60/panc60.c b/keyboards/panc60/panc60.c index 6bd16a4bd..a200b2587 100644 --- a/keyboards/panc60/panc60.c +++ b/keyboards/panc60/panc60.c | |||
@@ -16,30 +16,19 @@ | |||
16 | 16 | ||
17 | #include "panc60.h" | 17 | #include "panc60.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | setPinOutput(D0); | 20 | led_init_ports(); |
21 | setPinOutput(D1); | 21 | keyboard_pre_init_user(); |
22 | setPinOutput(D4); | 22 | } |
23 | setPinOutput(D6); | ||
24 | 23 | ||
25 | writePinLow(D0); | 24 | void led_init_ports(void) { |
26 | writePinLow(D1); | 25 | setPinOutput(D1); |
27 | writePinLow(D4); | 26 | writePinHigh(D1); |
28 | writePinLow(D6); | ||
29 | } | 27 | } |
30 | 28 | ||
31 | void backlight_set(uint8_t level) { | 29 | bool led_update_kb(led_t led_state) { |
32 | if (level == 0) { | 30 | if (led_update_user(led_state)) { |
33 | // Turn out the lights | 31 | writePin(D1, !led_state.caps_lock); |
34 | writePinLow(D0); | 32 | } |
35 | writePinLow(D1); | 33 | return true; |
36 | writePinLow(D4); | ||
37 | writePinLow(D6); | ||
38 | } else { | ||
39 | // Turn on the lights | ||
40 | writePinHigh(D0); | ||
41 | writePinHigh(D1); | ||
42 | writePinHigh(D4); | ||
43 | writePinHigh(D6); | ||
44 | } | ||
45 | } | 34 | } |
diff --git a/keyboards/pearl/config.h b/keyboards/pearl/config.h index 0ae69e8e2..5dbba3ec0 100644 --- a/keyboards/pearl/config.h +++ b/keyboards/pearl/config.h | |||
@@ -31,7 +31,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
31 | #define RGBLIGHT_ANIMATIONS | 31 | #define RGBLIGHT_ANIMATIONS |
32 | #define RGBLED_NUM 12 | 32 | #define RGBLED_NUM 12 |
33 | 33 | ||
34 | #define BACKLIGHT_LEVELS 1 | 34 | #define BACKLIGHT_PIN D4 |
35 | #define BACKLIGHT_LEVELS 3 | ||
35 | 36 | ||
36 | #define MATRIX_ROWS 4 | 37 | #define MATRIX_ROWS 4 |
37 | #define MATRIX_COLS 13 | 38 | #define MATRIX_COLS 13 |
diff --git a/keyboards/pearl/pearl.c b/keyboards/pearl/pearl.c index 093b5fdd9..cebbc9fcb 100644 --- a/keyboards/pearl/pearl.c +++ b/keyboards/pearl/pearl.c | |||
@@ -17,32 +17,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "pearl.h" | 18 | #include "pearl.h" |
19 | 19 | ||
20 | void backlight_init_ports(void) { | 20 | void keyboard_pre_init_kb(void) { |
21 | // initialize pins D0, D1, D4 and D6 as output | 21 | led_init_ports(); |
22 | keyboard_pre_init_user(); | ||
23 | } | ||
24 | |||
25 | void led_init_ports(void) { | ||
22 | setPinOutput(D0); | 26 | setPinOutput(D0); |
23 | setPinOutput(D1); | 27 | setPinOutput(D1); |
24 | setPinOutput(D4); | ||
25 | setPinOutput(D6); | 28 | setPinOutput(D6); |
26 | |||
27 | // turn backlight LEDs on | ||
28 | writePinHigh(D0); | 29 | writePinHigh(D0); |
29 | writePinHigh(D1); | 30 | writePinHigh(D1); |
30 | writePinHigh(D4); | ||
31 | writePinHigh(D6); | 31 | writePinHigh(D6); |
32 | } | 32 | } |
33 | 33 | ||
34 | void backlight_set(uint8_t level) { | 34 | bool led_update_kb(led_t led_state) { |
35 | if (level == 0) { | 35 | if (led_update_user(led_state)) { |
36 | // turn backlight LEDs off | 36 | writePin(D0, !led_state.num_lock); |
37 | writePinLow(D0); | 37 | writePin(D1, !led_state.caps_lock); |
38 | writePinLow(D1); | 38 | writePin(D6, !led_state.scroll_lock); |
39 | writePinLow(D4); | ||
40 | writePinLow(D6); | ||
41 | } else { | ||
42 | // turn backlight LEDs on | ||
43 | writePinHigh(D0); | ||
44 | writePinHigh(D1); | ||
45 | writePinHigh(D4); | ||
46 | writePinHigh(D6); | ||
47 | } | 39 | } |
40 | return true; | ||
48 | } | 41 | } |
diff --git a/keyboards/percent/canoe/canoe.c b/keyboards/percent/canoe/canoe.c index 79c6330fe..d3c66dbf1 100644 --- a/keyboards/percent/canoe/canoe.c +++ b/keyboards/percent/canoe/canoe.c | |||
@@ -17,32 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "canoe.h" | 18 | #include "canoe.h" |
19 | 19 | ||
20 | #ifdef BACKLIGHT_ENABLE | 20 | void keyboard_pre_init_kb(void) { |
21 | void backlight_set(uint8_t level) { | 21 | led_init_ports(); |
22 | if (level == 0) { | 22 | keyboard_pre_init_user(); |
23 | // Turn out the lights | ||
24 | writePinLow(D0); | ||
25 | writePinLow(D1); | ||
26 | writePinLow(D4); | ||
27 | writePinLow(D6); | ||
28 | } else { | ||
29 | // Turn on the lights | ||
30 | writePinHigh(D0); | ||
31 | writePinHigh(D1); | ||
32 | writePinHigh(D4); | ||
33 | writePinHigh(D6); | ||
34 | } | ||
35 | } | 23 | } |
36 | 24 | ||
37 | void backlight_init_ports(void) { | 25 | void led_init_ports(void) { |
38 | setPinOutput(D0); | 26 | setPinOutput(D1); |
39 | setPinOutput(D1); | 27 | writePinHigh(D1); |
40 | setPinOutput(D4); | 28 | } |
41 | setPinOutput(D6); | ||
42 | 29 | ||
43 | writePinLow(D0); | 30 | bool led_update_kb(led_t led_state) { |
44 | writePinLow(D1); | 31 | if (led_update_user(led_state)) { |
45 | writePinLow(D4); | 32 | writePin(D1, !led_state.caps_lock); |
46 | writePinLow(D6); | 33 | } |
34 | return true; | ||
47 | } | 35 | } |
48 | #endif | ||
diff --git a/keyboards/percent/canoe/config.h b/keyboards/percent/canoe/config.h index 950e0806e..21b3dcea6 100644 --- a/keyboards/percent/canoe/config.h +++ b/keyboards/percent/canoe/config.h | |||
@@ -38,7 +38,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
38 | #define DIODE_DIRECTION COL2ROW | 38 | #define DIODE_DIRECTION COL2ROW |
39 | #define DEBOUNCE 5 | 39 | #define DEBOUNCE 5 |
40 | 40 | ||
41 | #define BACKLIGHT_LEVELS 1 | 41 | #define BACKLIGHT_PIN D4 |
42 | #define BACKLIGHT_LEVELS 3 | ||
43 | |||
42 | #define RGBLIGHT_ANIMATIONS | 44 | #define RGBLIGHT_ANIMATIONS |
43 | 45 | ||
44 | #define NO_UART 1 | 46 | #define NO_UART 1 |
diff --git a/keyboards/percent/canoe/rules.mk b/keyboards/percent/canoe/rules.mk index 6340c8122..9661eaefe 100644 --- a/keyboards/percent/canoe/rules.mk +++ b/keyboards/percent/canoe/rules.mk | |||
@@ -17,7 +17,7 @@ MOUSEKEY_ENABLE = no | |||
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = yes |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
diff --git a/keyboards/percent/skog/backlight.c b/keyboards/percent/skog/backlight.c deleted file mode 100644 index 94e8126d8..000000000 --- a/keyboards/percent/skog/backlight.c +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #include "backlight.h" | ||
7 | #include "quantum.h" | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | #include <avr/interrupt.h> | ||
11 | |||
12 | #include "backlight_custom.h" | ||
13 | #include "breathing_custom.h" | ||
14 | |||
15 | // DEBUG | ||
16 | #include <stdlib.h> | ||
17 | #include <stdio.h> | ||
18 | |||
19 | // Port D: digital pins of the AVR chipset | ||
20 | #define NUMLOCK_PORT (1 << 0) // D0 | ||
21 | #define CAPSLOCK_PORT (1 << 1) // D1 | ||
22 | #define BACKLIGHT_PORT (1 << 4) // D4 | ||
23 | #define SCROLLLOCK_PORT (1 << 6) // D6 | ||
24 | |||
25 | #define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 | ||
26 | #define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default | ||
27 | |||
28 | #define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask | ||
29 | |||
30 | #define PWM_MAX 0xFF | ||
31 | #define TIMER_TOP 255 // 8 bit PWM | ||
32 | |||
33 | extern backlight_config_t backlight_config; | ||
34 | |||
35 | /** | ||
36 | * References | ||
37 | * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation | ||
38 | * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b | ||
39 | * Timers: http://www.avrbeginners.net/architecture/timers/timers.html | ||
40 | * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/ | ||
41 | * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware | ||
42 | */ | ||
43 | |||
44 | // @Override | ||
45 | // turn LEDs on and off depending on USB caps/num/scroll lock states. | ||
46 | __attribute__ ((weak)) | ||
47 | void led_set_user(uint8_t usb_led) { | ||
48 | if (usb_led & (1 << USB_LED_NUM_LOCK)) { | ||
49 | // turn on | ||
50 | DDRD |= NUMLOCK_PORT; | ||
51 | PORTD |= NUMLOCK_PORT; | ||
52 | } else { | ||
53 | // turn off | ||
54 | DDRD &= ~NUMLOCK_PORT; | ||
55 | PORTD &= ~NUMLOCK_PORT; | ||
56 | } | ||
57 | |||
58 | if (usb_led & (1 << USB_LED_CAPS_LOCK)) { | ||
59 | DDRD |= CAPSLOCK_PORT; | ||
60 | PORTD |= CAPSLOCK_PORT; | ||
61 | } else { | ||
62 | DDRD &= ~CAPSLOCK_PORT; | ||
63 | PORTD &= ~CAPSLOCK_PORT; | ||
64 | } | ||
65 | |||
66 | if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { | ||
67 | DDRD |= SCROLLLOCK_PORT; | ||
68 | PORTD |= SCROLLLOCK_PORT; | ||
69 | } else { | ||
70 | DDRD &= ~SCROLLLOCK_PORT; | ||
71 | PORTD &= ~SCROLLLOCK_PORT; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | #ifdef BACKLIGHT_ENABLE | ||
76 | |||
77 | // sets up Timer 1 for 8-bit PWM | ||
78 | void timer1PWMSetup(void) { // NOTE ONLY CALL THIS ONCE | ||
79 | // default 8 bit mode | ||
80 | TCCR1A &= ~(1 << 1); // cbi(TCCR1A,PWM11); <- set PWM11 bit to HIGH | ||
81 | TCCR1A |= (1 << 0); // sbi(TCCR1A,PWM10); <- set PWM10 bit to LOW | ||
82 | |||
83 | // clear output compare value A | ||
84 | // outb(OCR1AH, 0); | ||
85 | // outb(OCR1AL, 0); | ||
86 | |||
87 | // clear output comparator registers for B | ||
88 | OCR1BH = 0; // outb(OCR1BH, 0); | ||
89 | OCR1BL = 0; // outb(OCR1BL, 0); | ||
90 | } | ||
91 | |||
92 | bool is_init = false; | ||
93 | void timer1Init(void) { | ||
94 | // timer1SetPrescaler(TIMER1PRESCALE) | ||
95 | // set to DIV/64 | ||
96 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER1PRESCALE; | ||
97 | |||
98 | // reset TCNT1 | ||
99 | TCNT1H = 0; // outb(TCNT1H, 0); | ||
100 | TCNT1L = 0; // outb(TCNT1L, 0); | ||
101 | |||
102 | // TOIE1: Timer Overflow Interrupt Enable (Timer 1); | ||
103 | TIMSK |= _BV(TOIE1); // sbi(TIMSK, TOIE1); | ||
104 | |||
105 | is_init = true; | ||
106 | } | ||
107 | |||
108 | void timer1UnInit(void) { | ||
109 | // set prescaler back to NONE | ||
110 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | 0x00; // TIMERRTC_CLK_STOP | ||
111 | |||
112 | // disable timer overflow interrupt | ||
113 | TIMSK &= ~_BV(TOIE1); // overflow bit? | ||
114 | |||
115 | setPWM(0); | ||
116 | |||
117 | is_init = false; | ||
118 | } | ||
119 | |||
120 | |||
121 | // handle TCNT1 overflow | ||
122 | //! Interrupt handler for tcnt1 overflow interrupt | ||
123 | ISR(TIMER1_OVF_vect, ISR_NOBLOCK) | ||
124 | { | ||
125 | // sei(); | ||
126 | // handle breathing here | ||
127 | #ifdef BACKLIGHT_BREATHING | ||
128 | if (is_breathing()) { | ||
129 | custom_breathing_handler(); | ||
130 | } | ||
131 | #endif | ||
132 | } | ||
133 | |||
134 | // enable timer 1 PWM | ||
135 | // timer1PWMBOn() | ||
136 | void timer1PWMBEnable(void) { | ||
137 | // turn on channel B (OC1B) PWM output | ||
138 | // set OC1B as non-inverted PWM | ||
139 | TCCR1A |= _BV(COM1B1); | ||
140 | TCCR1A &= ~_BV(COM1B0); | ||
141 | } | ||
142 | |||
143 | // disable timer 1 PWM | ||
144 | // timer1PWMBOff() | ||
145 | void timer1PWMBDisable(void) { | ||
146 | TCCR1A &= ~_BV(COM1B1); | ||
147 | TCCR1A &= ~_BV(COM1B0); | ||
148 | } | ||
149 | |||
150 | void enableBacklight(void) { | ||
151 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
152 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
153 | } | ||
154 | |||
155 | void disableBacklight(void) { | ||
156 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
157 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
158 | } | ||
159 | |||
160 | void startPWM(void) { | ||
161 | timer1Init(); | ||
162 | timer1PWMBEnable(); | ||
163 | enableBacklight(); | ||
164 | } | ||
165 | |||
166 | void stopPWM(void) { | ||
167 | timer1UnInit(); | ||
168 | disableBacklight(); | ||
169 | timer1PWMBDisable(); | ||
170 | } | ||
171 | |||
172 | void b_led_init_ports(void) { | ||
173 | /* turn backlight on/off depending on user preference */ | ||
174 | #if BACKLIGHT_ON_STATE == 0 | ||
175 | // DDRx register: sets the direction of Port D | ||
176 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
177 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
178 | #else | ||
179 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
180 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
181 | #endif | ||
182 | |||
183 | timer1PWMSetup(); | ||
184 | startPWM(); | ||
185 | |||
186 | #ifdef BACKLIGHT_BREATHING | ||
187 | breathing_enable(); | ||
188 | #endif | ||
189 | } | ||
190 | |||
191 | void b_led_set(uint8_t level) { | ||
192 | if (level > BACKLIGHT_LEVELS) { | ||
193 | level = BACKLIGHT_LEVELS; | ||
194 | } | ||
195 | |||
196 | setPWM((int)(TIMER_TOP * (float) level / BACKLIGHT_LEVELS)); | ||
197 | } | ||
198 | |||
199 | // called every matrix scan | ||
200 | void b_led_task(void) { | ||
201 | // do nothing for now | ||
202 | } | ||
203 | |||
204 | void setPWM(uint16_t xValue) { | ||
205 | if (xValue > TIMER_TOP) { | ||
206 | xValue = TIMER_TOP; | ||
207 | } | ||
208 | OCR1B = xValue; // timer1PWMBSet(xValue); | ||
209 | } | ||
210 | |||
211 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/percent/skog/backlight_custom.h b/keyboards/percent/skog/backlight_custom.h deleted file mode 100644 index 51365fe3b..000000000 --- a/keyboards/percent/skog/backlight_custom.h +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #pragma once | ||
7 | |||
8 | #include <avr/pgmspace.h> | ||
9 | void b_led_init_ports(void); | ||
10 | void b_led_set(uint8_t level); | ||
11 | void b_led_task(void); | ||
12 | void setPWM(uint16_t xValue); | ||
13 | |||
diff --git a/keyboards/percent/skog/breathing_custom.h b/keyboards/percent/skog/breathing_custom.h deleted file mode 100644 index 71416b1b4..000000000 --- a/keyboards/percent/skog/breathing_custom.h +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /** | ||
2 | * Breathing effect code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Works in conjunction with `backlight.c`. | ||
4 | * | ||
5 | * Code adapted from `quantum.c` to register with the existing TIMER1 overflow | ||
6 | * handler in `backlight.c` instead of setting up its own timer. | ||
7 | * Kenneth A. (github.com/krusli | krusli.me) | ||
8 | */ | ||
9 | |||
10 | #ifdef BACKLIGHT_ENABLE | ||
11 | #ifdef BACKLIGHT_BREATHING | ||
12 | |||
13 | #include "backlight_custom.h" | ||
14 | |||
15 | #ifndef BREATHING_PERIOD | ||
16 | #define BREATHING_PERIOD 6 | ||
17 | #endif | ||
18 | |||
19 | #define breathing_min() do {breathing_counter = 0;} while (0) | ||
20 | #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) | ||
21 | |||
22 | // TODO make this share code with quantum.c | ||
23 | |||
24 | #define BREATHING_NO_HALT 0 | ||
25 | #define BREATHING_HALT_OFF 1 | ||
26 | #define BREATHING_HALT_ON 2 | ||
27 | #define BREATHING_STEPS 128 | ||
28 | |||
29 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
30 | static uint8_t breathing_halt = BREATHING_NO_HALT; | ||
31 | static uint16_t breathing_counter = 0; | ||
32 | |||
33 | static bool breathing = false; | ||
34 | |||
35 | bool is_breathing(void) { | ||
36 | return breathing; | ||
37 | } | ||
38 | |||
39 | // See http://jared.geek.nz/2013/feb/linear-led-pwm | ||
40 | static uint16_t cie_lightness(uint16_t v) { | ||
41 | if (v <= 5243) // if below 8% of max | ||
42 | return v / 9; // same as dividing by 900% | ||
43 | else { | ||
44 | uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare | ||
45 | // to get a useful result with integer division, we shift left in the expression above | ||
46 | // and revert what we've done again after squaring. | ||
47 | y = y * y * y >> 8; | ||
48 | if (y > 0xFFFFUL) // prevent overflow | ||
49 | return 0xFFFFU; | ||
50 | else | ||
51 | return (uint16_t) y; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void breathing_enable(void) { | ||
56 | breathing = true; | ||
57 | breathing_counter = 0; | ||
58 | breathing_halt = BREATHING_NO_HALT; | ||
59 | // interrupt already registered | ||
60 | } | ||
61 | |||
62 | void breathing_pulse(void) { | ||
63 | if (get_backlight_level() == 0) | ||
64 | breathing_min(); | ||
65 | else | ||
66 | breathing_max(); | ||
67 | breathing_halt = BREATHING_HALT_ON; | ||
68 | // breathing_interrupt_enable(); | ||
69 | breathing = true; | ||
70 | } | ||
71 | |||
72 | void breathing_disable(void) { | ||
73 | breathing = false; | ||
74 | // backlight_set(get_backlight_level()); | ||
75 | b_led_set(get_backlight_level()); // custom implementation of backlight_set() | ||
76 | } | ||
77 | |||
78 | void breathing_self_disable(void) | ||
79 | { | ||
80 | if (get_backlight_level() == 0) | ||
81 | breathing_halt = BREATHING_HALT_OFF; | ||
82 | else | ||
83 | breathing_halt = BREATHING_HALT_ON; | ||
84 | } | ||
85 | |||
86 | void breathing_toggle(void) { | ||
87 | if (is_breathing()) | ||
88 | breathing_disable(); | ||
89 | else | ||
90 | breathing_enable(); | ||
91 | } | ||
92 | |||
93 | void breathing_period_set(uint8_t value) | ||
94 | { | ||
95 | if (!value) | ||
96 | value = 1; | ||
97 | breathing_period = value; | ||
98 | } | ||
99 | |||
100 | void breathing_period_default(void) { | ||
101 | breathing_period_set(BREATHING_PERIOD); | ||
102 | } | ||
103 | |||
104 | void breathing_period_inc(void) | ||
105 | { | ||
106 | breathing_period_set(breathing_period+1); | ||
107 | } | ||
108 | |||
109 | void breathing_period_dec(void) | ||
110 | { | ||
111 | breathing_period_set(breathing_period-1); | ||
112 | } | ||
113 | |||
114 | /* To generate breathing curve in python: | ||
115 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | ||
116 | */ | ||
117 | static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
118 | |||
119 | // Use this before the cie_lightness function. | ||
120 | static inline uint16_t scale_backlight(uint16_t v) { | ||
121 | return v / BACKLIGHT_LEVELS * get_backlight_level(); | ||
122 | } | ||
123 | |||
124 | void custom_breathing_handler(void) { | ||
125 | uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; | ||
126 | // resetting after one period to prevent ugly reset at overflow. | ||
127 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); | ||
128 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; | ||
129 | |||
130 | if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || | ||
131 | ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) | ||
132 | { | ||
133 | // breathing_interrupt_disable(); | ||
134 | } | ||
135 | |||
136 | setPWM(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U))); | ||
137 | } | ||
138 | |||
139 | #endif // BACKLIGHT_BREATHING | ||
140 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/percent/skog/config.h b/keyboards/percent/skog/config.h index 7a0c703ec..15844711f 100644 --- a/keyboards/percent/skog/config.h +++ b/keyboards/percent/skog/config.h | |||
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #ifndef CONFIG_H | 18 | #pragma once |
19 | #define CONFIG_H | ||
20 | 19 | ||
21 | #define VENDOR_ID 0x20A0 | 20 | #define VENDOR_ID 0x20A0 |
22 | #define PRODUCT_ID 0x422D | 21 | #define PRODUCT_ID 0x422D |
@@ -36,8 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
36 | #define RGBLED_NUM 2 | 35 | #define RGBLED_NUM 2 |
37 | #define RGBLIGHT_ANIMATIONS | 36 | #define RGBLIGHT_ANIMATIONS |
38 | 37 | ||
38 | #define BACKLIGHT_PIN D4 | ||
39 | #define BACKLIGHT_LEVELS 5 | 39 | #define BACKLIGHT_LEVELS 5 |
40 | 40 | ||
41 | #define NO_UART 1 | 41 | #define NO_UART 1 |
42 | |||
43 | #endif | ||
diff --git a/keyboards/percent/skog/rules.mk b/keyboards/percent/skog/rules.mk index da03a2e0c..0d243b858 100644 --- a/keyboards/percent/skog/rules.mk +++ b/keyboards/percent/skog/rules.mk | |||
@@ -21,11 +21,7 @@ BACKLIGHT_ENABLE = yes | |||
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
24 | BACKLIGHT_CUSTOM_DRIVER = yes | ||
25 | |||
26 | OPT_DEFS = -DDEBUG_LEVEL=0 | 24 | OPT_DEFS = -DDEBUG_LEVEL=0 |
27 | 25 | ||
28 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 26 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
29 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 27 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
30 | |||
31 | SRC = backlight.c | ||
diff --git a/keyboards/percent/skog/skog.c b/keyboards/percent/skog/skog.c index 1c26c550e..241833937 100644 --- a/keyboards/percent/skog/skog.c +++ b/keyboards/percent/skog/skog.c | |||
@@ -19,20 +19,22 @@ ps2avrGB support code by Kenneth A. (bminiex/.[ch]) | |||
19 | 19 | ||
20 | #include "skog.h" | 20 | #include "skog.h" |
21 | 21 | ||
22 | #include "backlight.h" | 22 | void keyboard_pre_init_kb(void) { |
23 | #include "backlight_custom.h" | 23 | led_init_ports(); |
24 | 24 | keyboard_pre_init_user(); | |
25 | #ifdef BACKLIGHT_ENABLE | ||
26 | /// Overrides functions in `quantum.c` | ||
27 | void backlight_init_ports(void) { | ||
28 | b_led_init_ports(); | ||
29 | } | 25 | } |
30 | 26 | ||
31 | void backlight_task(void) { | 27 | void led_init_ports(void) { |
32 | b_led_task(); | 28 | setPinOutput(D1); |
29 | setPinOutput(D6); | ||
30 | writePinHigh(D1); | ||
31 | writePinHigh(D6); | ||
33 | } | 32 | } |
34 | 33 | ||
35 | void backlight_set(uint8_t level) { | 34 | bool led_update_kb(led_t led_state) { |
36 | b_led_set(level); | 35 | if (led_update_user(led_state)) { |
36 | writePin(D1, !led_state.caps_lock); | ||
37 | writePin(D6, !led_state.scroll_lock); | ||
38 | } | ||
39 | return true; | ||
37 | } | 40 | } |
38 | #endif | ||
diff --git a/keyboards/percent/skog_lite/config.h b/keyboards/percent/skog_lite/config.h index 97d11238e..ec3928b72 100644 --- a/keyboards/percent/skog_lite/config.h +++ b/keyboards/percent/skog_lite/config.h | |||
@@ -38,5 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
38 | #define DIODE_DIRECTION COL2ROW | 38 | #define DIODE_DIRECTION COL2ROW |
39 | #define DEBOUNCE 5 | 39 | #define DEBOUNCE 5 |
40 | 40 | ||
41 | #define BACKLIGHT_LEVELS 1 | 41 | #define BACKLIGHT_PIN D4 |
42 | #define BACKLIGHT_LEVELS 3 | ||
43 | |||
42 | #define RGBLIGHT_ANIMATIONS | 44 | #define RGBLIGHT_ANIMATIONS |
diff --git a/keyboards/percent/skog_lite/skog_lite.c b/keyboards/percent/skog_lite/skog_lite.c index a6c00f529..e611885a6 100644 --- a/keyboards/percent/skog_lite/skog_lite.c +++ b/keyboards/percent/skog_lite/skog_lite.c | |||
@@ -16,32 +16,22 @@ | |||
16 | 16 | ||
17 | #include "skog_lite.h" | 17 | #include "skog_lite.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | setPinOutput(D0); | 21 | keyboard_pre_init_user(); |
22 | } | ||
23 | |||
24 | void led_init_ports(void) { | ||
22 | setPinOutput(D1); | 25 | setPinOutput(D1); |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | 26 | setPinOutput(D6); |
25 | |||
26 | // turn backlight LEDs on | ||
27 | writePinHigh(D0); | ||
28 | writePinHigh(D1); | 27 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | 28 | writePinHigh(D6); |
31 | } | 29 | } |
32 | 30 | ||
33 | void backlight_set(uint8_t level) { | 31 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 32 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 33 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | 34 | writePin(D6, !led_state.scroll_lock); |
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 35 | } |
36 | return true; | ||
47 | } | 37 | } |
diff --git a/keyboards/singa/config.h b/keyboards/singa/config.h index badaef513..e998e6ea9 100644 --- a/keyboards/singa/config.h +++ b/keyboards/singa/config.h | |||
@@ -37,5 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | #define DIODE_DIRECTION COL2ROW | 37 | #define DIODE_DIRECTION COL2ROW |
38 | #define DEBOUNCE 5 | 38 | #define DEBOUNCE 5 |
39 | 39 | ||
40 | #define BACKLIGHT_LEVELS 1 | 40 | #define BACKLIGHT_PIN D4 |
41 | #define BACKLIGHT_LEVELS 3 | ||
42 | |||
41 | #define RGBLIGHT_ANIMATIONS | 43 | #define RGBLIGHT_ANIMATIONS |
diff --git a/keyboards/singa/rules.mk b/keyboards/singa/rules.mk index 54328d248..84eace5ed 100644 --- a/keyboards/singa/rules.mk +++ b/keyboards/singa/rules.mk | |||
@@ -15,7 +15,7 @@ BOOTLOADER = bootloadHID | |||
15 | BOOTMAGIC_ENABLE = no | 15 | BOOTMAGIC_ENABLE = no |
16 | MOUSEKEY_ENABLE = yes | 16 | MOUSEKEY_ENABLE = yes |
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = no |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
diff --git a/keyboards/singa/singa.c b/keyboards/singa/singa.c index 144065d02..7b60e3c29 100644 --- a/keyboards/singa/singa.c +++ b/keyboards/singa/singa.c | |||
@@ -16,32 +16,19 @@ | |||
16 | 16 | ||
17 | #include "singa.h" | 17 | #include "singa.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | setPinOutput(D0); | 21 | keyboard_pre_init_user(); |
22 | setPinOutput(D1); | 22 | } |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | ||
25 | 23 | ||
26 | // turn backlight LEDs on | 24 | void led_init_ports(void) { |
27 | writePinHigh(D0); | 25 | setPinOutput(D1); |
28 | writePinHigh(D1); | 26 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | ||
31 | } | 27 | } |
32 | 28 | ||
33 | void backlight_set(uint8_t level) { | 29 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 30 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 31 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | ||
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 32 | } |
33 | return true; | ||
47 | } | 34 | } |
diff --git a/keyboards/tgr/alice/alice.c b/keyboards/tgr/alice/alice.c index 39aed2cf5..9fb4957ac 100644 --- a/keyboards/tgr/alice/alice.c +++ b/keyboards/tgr/alice/alice.c | |||
@@ -16,3 +16,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "alice.h" | 18 | #include "alice.h" |
19 | |||
20 | void keyboard_pre_init_kb(void) { | ||
21 | led_init_ports(); | ||
22 | keyboard_pre_init_user(); | ||
23 | } | ||
24 | |||
25 | void led_init_ports(void) { | ||
26 | setPinOutput(D0); | ||
27 | setPinOutput(D1); | ||
28 | setPinOutput(D6); | ||
29 | writePinHigh(D0); | ||
30 | writePinHigh(D1); | ||
31 | writePinHigh(D6); | ||
32 | } | ||
33 | |||
34 | bool led_update_kb(led_t led_state) { | ||
35 | if (led_update_user(led_state)) { | ||
36 | writePin(D0, !led_state.num_lock); | ||
37 | writePin(D1, !led_state.caps_lock); | ||
38 | writePin(D6, !led_state.scroll_lock); | ||
39 | } | ||
40 | return true; | ||
41 | } | ||
diff --git a/keyboards/tgr/alice/config.h b/keyboards/tgr/alice/config.h index 4c36896b7..1f1b32d4e 100644 --- a/keyboards/tgr/alice/config.h +++ b/keyboards/tgr/alice/config.h | |||
@@ -33,6 +33,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
33 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 } | 33 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 } |
34 | #define DIODE_DIRECTION COL2ROW | 34 | #define DIODE_DIRECTION COL2ROW |
35 | 35 | ||
36 | #define BACKLIGHT_PIN D4 | ||
37 | #define BACKLIGHT_LEVELS 3 | ||
38 | |||
36 | #define RGBLED_NUM 18 | 39 | #define RGBLED_NUM 18 |
37 | #define RGBLIGHT_ANIMATIONS | 40 | #define RGBLIGHT_ANIMATIONS |
38 | 41 | ||
diff --git a/keyboards/tgr/alice/rules.mk b/keyboards/tgr/alice/rules.mk index 530e8ea32..a8fea7efa 100644 --- a/keyboards/tgr/alice/rules.mk +++ b/keyboards/tgr/alice/rules.mk | |||
@@ -17,7 +17,7 @@ MOUSEKEY_ENABLE = no | |||
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = yes |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
diff --git a/keyboards/tgr/jane/config.h b/keyboards/tgr/jane/config.h index dd119d3b0..5fb9a9056 100644 --- a/keyboards/tgr/jane/config.h +++ b/keyboards/tgr/jane/config.h | |||
@@ -36,4 +36,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
36 | #define DIODE_DIRECTION COL2ROW | 36 | #define DIODE_DIRECTION COL2ROW |
37 | #define DEBOUNCE 5 | 37 | #define DEBOUNCE 5 |
38 | 38 | ||
39 | #define BACKLIGHT_LEVELS 1 | 39 | #define BACKLIGHT_PIN D4 |
40 | #define BACKLIGHT_LEVELS 3 | ||
diff --git a/keyboards/tgr/jane/jane.c b/keyboards/tgr/jane/jane.c index 4ab0b3007..24183a0f7 100644 --- a/keyboards/tgr/jane/jane.c +++ b/keyboards/tgr/jane/jane.c | |||
@@ -16,32 +16,22 @@ | |||
16 | 16 | ||
17 | #include "jane.h" | 17 | #include "jane.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | setPinOutput(D0); | 21 | keyboard_pre_init_user(); |
22 | } | ||
23 | |||
24 | void led_init_ports(void) { | ||
22 | setPinOutput(D1); | 25 | setPinOutput(D1); |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | 26 | setPinOutput(D6); |
25 | |||
26 | // turn backlight LEDs on | ||
27 | writePinHigh(D0); | ||
28 | writePinHigh(D1); | 27 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | 28 | writePinHigh(D6); |
31 | } | 29 | } |
32 | 30 | ||
33 | void backlight_set(uint8_t level) { | 31 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 32 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 33 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | 34 | writePin(D6, !led_state.scroll_lock); |
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 35 | } |
36 | return true; | ||
47 | } | 37 | } |
diff --git a/keyboards/unikorn/config.h b/keyboards/unikorn/config.h index 1c4f3431a..e6bdbe7f2 100644 --- a/keyboards/unikorn/config.h +++ b/keyboards/unikorn/config.h | |||
@@ -36,7 +36,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
36 | #define DIODE_DIRECTION COL2ROW | 36 | #define DIODE_DIRECTION COL2ROW |
37 | #define DEBOUNCE 5 | 37 | #define DEBOUNCE 5 |
38 | 38 | ||
39 | #define BACKLIGHT_LEVELS 1 | 39 | #define BACKLIGHT_PIN D4 |
40 | #define BACKLIGHT_LEVELS 3 | ||
41 | |||
40 | #ifdef RGBLIGHT_ENABLE | 42 | #ifdef RGBLIGHT_ENABLE |
41 | #define RGBLED_NUM 17 | 43 | #define RGBLED_NUM 17 |
42 | #define RGBLIGHT_ANIMATIONS | 44 | #define RGBLIGHT_ANIMATIONS |
diff --git a/keyboards/unikorn/unikorn.c b/keyboards/unikorn/unikorn.c index 70bc5a988..26a5092a5 100644 --- a/keyboards/unikorn/unikorn.c +++ b/keyboards/unikorn/unikorn.c | |||
@@ -16,32 +16,19 @@ | |||
16 | 16 | ||
17 | #include "unikorn.h" | 17 | #include "unikorn.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | setPinOutput(D0); | 21 | keyboard_pre_init_user(); |
22 | setPinOutput(D1); | 22 | } |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | ||
25 | 23 | ||
26 | // turn backlight LEDs on | 24 | void led_init_ports(void) { |
27 | writePinHigh(D0); | 25 | setPinOutput(D1); |
28 | writePinHigh(D1); | 26 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | ||
31 | } | 27 | } |
32 | 28 | ||
33 | void backlight_set(uint8_t level) { | 29 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 30 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 31 | writePin(D1, !led_state.caps_lock); |
36 | writePinLow(D0); | ||
37 | writePinLow(D1); | ||
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 32 | } |
33 | return true; | ||
47 | } | 34 | } |
diff --git a/keyboards/winkeyless/bface/bface.c b/keyboards/winkeyless/bface/bface.c index 8cb5b600c..49e8bbcd2 100644 --- a/keyboards/winkeyless/bface/bface.c +++ b/keyboards/winkeyless/bface/bface.c | |||
@@ -16,32 +16,25 @@ | |||
16 | 16 | ||
17 | #include "bface.h" | 17 | #include "bface.h" |
18 | 18 | ||
19 | void backlight_init_ports(void) { | 19 | void keyboard_pre_init_kb(void) { |
20 | // initialize pins D0, D1, D4 and D6 as output | 20 | led_init_ports(); |
21 | keyboard_pre_init_user(); | ||
22 | } | ||
23 | |||
24 | void led_init_ports(void) { | ||
21 | setPinOutput(D0); | 25 | setPinOutput(D0); |
22 | setPinOutput(D1); | 26 | setPinOutput(D1); |
23 | setPinOutput(D4); | ||
24 | setPinOutput(D6); | 27 | setPinOutput(D6); |
25 | |||
26 | // turn backlight LEDs on | ||
27 | writePinHigh(D0); | 28 | writePinHigh(D0); |
28 | writePinHigh(D1); | 29 | writePinHigh(D1); |
29 | writePinHigh(D4); | ||
30 | writePinHigh(D6); | 30 | writePinHigh(D6); |
31 | } | 31 | } |
32 | 32 | ||
33 | void backlight_set(uint8_t level) { | 33 | bool led_update_kb(led_t led_state) { |
34 | if (level == 0) { | 34 | if (led_update_user(led_state)) { |
35 | // turn backlight LEDs off | 35 | writePin(D0, !led_state.num_lock); |
36 | writePinLow(D0); | 36 | writePin(D1, !led_state.caps_lock); |
37 | writePinLow(D1); | 37 | writePin(D6, !led_state.scroll_lock); |
38 | writePinLow(D4); | ||
39 | writePinLow(D6); | ||
40 | } else { | ||
41 | // turn backlight LEDs on | ||
42 | writePinHigh(D0); | ||
43 | writePinHigh(D1); | ||
44 | writePinHigh(D4); | ||
45 | writePinHigh(D6); | ||
46 | } | 38 | } |
39 | return true; | ||
47 | } | 40 | } |
diff --git a/keyboards/winkeyless/bface/config.h b/keyboards/winkeyless/bface/config.h index 95d44557a..7ada9a49a 100644 --- a/keyboards/winkeyless/bface/config.h +++ b/keyboards/winkeyless/bface/config.h | |||
@@ -42,10 +42,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
42 | 42 | ||
43 | #define NO_UART 1 | 43 | #define NO_UART 1 |
44 | 44 | ||
45 | #ifdef BACKLIGHT_ENABLE | 45 | #define BACKLIGHT_PIN D4 |
46 | // the backlight PWM does not work (yet). Therefore, we only have two backlight levels (on/off) | 46 | #define BACKLIGHT_LEVELS 3 |
47 | #define BACKLIGHT_LEVELS 1 | ||
48 | #define LED_PIN PORTD | ||
49 | #define BACKLIGHT_PORT_NUM (1 << 4) | ||
50 | #endif | ||
51 | |||
diff --git a/keyboards/winkeyless/bface/rules.mk b/keyboards/winkeyless/bface/rules.mk index 506e37ac9..84eace5ed 100644 --- a/keyboards/winkeyless/bface/rules.mk +++ b/keyboards/winkeyless/bface/rules.mk | |||
@@ -18,8 +18,6 @@ EXTRAKEY_ENABLE = yes | |||
18 | CONSOLE_ENABLE = no | 18 | CONSOLE_ENABLE = no |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
21 | BACKLIGHT_CUSTOM_DRIVER = yes | ||
22 | BACKLIGHT_BREATHING = no | ||
23 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
24 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
25 | 23 | ||
diff --git a/keyboards/winkeyless/bmini/bmini.c b/keyboards/winkeyless/bmini/bmini.c index f44fd36a8..fe3b74be1 100644 --- a/keyboards/winkeyless/bmini/bmini.c +++ b/keyboards/winkeyless/bmini/bmini.c | |||
@@ -16,3 +16,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "bmini.h" | 18 | #include "bmini.h" |
19 | |||
20 | void keyboard_pre_init_kb(void) { | ||
21 | led_init_ports(); | ||
22 | keyboard_pre_init_user(); | ||
23 | } | ||
24 | |||
25 | void led_init_ports(void) { | ||
26 | setPinOutput(D0); | ||
27 | setPinOutput(D1); | ||
28 | setPinOutput(D6); | ||
29 | writePinHigh(D0); | ||
30 | writePinHigh(D1); | ||
31 | writePinHigh(D6); | ||
32 | } | ||
33 | |||
34 | bool led_update_kb(led_t led_state) { | ||
35 | if (led_update_user(led_state)) { | ||
36 | writePin(D0, !led_state.num_lock); | ||
37 | writePin(D1, !led_state.caps_lock); | ||
38 | writePin(D6, !led_state.scroll_lock); | ||
39 | } | ||
40 | return true; | ||
41 | } | ||
diff --git a/keyboards/winkeyless/bmini/config.h b/keyboards/winkeyless/bmini/config.h index f8a26e4f0..95c44be9a 100644 --- a/keyboards/winkeyless/bmini/config.h +++ b/keyboards/winkeyless/bmini/config.h | |||
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #ifndef BMINI_CONFIG_H | 18 | #pragma once |
19 | #define BMINI_CONFIG_H | ||
20 | 19 | ||
21 | #include "config_common.h" | 20 | #include "config_common.h" |
22 | 21 | ||
@@ -37,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | 36 | ||
38 | #define RGBLIGHT_ANIMATIONS | 37 | #define RGBLIGHT_ANIMATIONS |
39 | 38 | ||
40 | #define NO_UART 1 | 39 | #define BACKLIGHT_PIN D4 |
40 | #define BACKLIGHT_LEVELS 3 | ||
41 | 41 | ||
42 | #endif | 42 | #define NO_UART 1 |
diff --git a/keyboards/winkeyless/bmini/rules.mk b/keyboards/winkeyless/bmini/rules.mk index 530e8ea32..a8fea7efa 100644 --- a/keyboards/winkeyless/bmini/rules.mk +++ b/keyboards/winkeyless/bmini/rules.mk | |||
@@ -17,7 +17,7 @@ MOUSEKEY_ENABLE = no | |||
17 | EXTRAKEY_ENABLE = yes | 17 | EXTRAKEY_ENABLE = yes |
18 | CONSOLE_ENABLE = yes | 18 | CONSOLE_ENABLE = yes |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = yes |
21 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
diff --git a/keyboards/winkeyless/bminiex/backlight.c b/keyboards/winkeyless/bminiex/backlight.c deleted file mode 100644 index 94e8126d8..000000000 --- a/keyboards/winkeyless/bminiex/backlight.c +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #include "backlight.h" | ||
7 | #include "quantum.h" | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | #include <avr/interrupt.h> | ||
11 | |||
12 | #include "backlight_custom.h" | ||
13 | #include "breathing_custom.h" | ||
14 | |||
15 | // DEBUG | ||
16 | #include <stdlib.h> | ||
17 | #include <stdio.h> | ||
18 | |||
19 | // Port D: digital pins of the AVR chipset | ||
20 | #define NUMLOCK_PORT (1 << 0) // D0 | ||
21 | #define CAPSLOCK_PORT (1 << 1) // D1 | ||
22 | #define BACKLIGHT_PORT (1 << 4) // D4 | ||
23 | #define SCROLLLOCK_PORT (1 << 6) // D6 | ||
24 | |||
25 | #define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 | ||
26 | #define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default | ||
27 | |||
28 | #define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask | ||
29 | |||
30 | #define PWM_MAX 0xFF | ||
31 | #define TIMER_TOP 255 // 8 bit PWM | ||
32 | |||
33 | extern backlight_config_t backlight_config; | ||
34 | |||
35 | /** | ||
36 | * References | ||
37 | * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation | ||
38 | * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b | ||
39 | * Timers: http://www.avrbeginners.net/architecture/timers/timers.html | ||
40 | * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/ | ||
41 | * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware | ||
42 | */ | ||
43 | |||
44 | // @Override | ||
45 | // turn LEDs on and off depending on USB caps/num/scroll lock states. | ||
46 | __attribute__ ((weak)) | ||
47 | void led_set_user(uint8_t usb_led) { | ||
48 | if (usb_led & (1 << USB_LED_NUM_LOCK)) { | ||
49 | // turn on | ||
50 | DDRD |= NUMLOCK_PORT; | ||
51 | PORTD |= NUMLOCK_PORT; | ||
52 | } else { | ||
53 | // turn off | ||
54 | DDRD &= ~NUMLOCK_PORT; | ||
55 | PORTD &= ~NUMLOCK_PORT; | ||
56 | } | ||
57 | |||
58 | if (usb_led & (1 << USB_LED_CAPS_LOCK)) { | ||
59 | DDRD |= CAPSLOCK_PORT; | ||
60 | PORTD |= CAPSLOCK_PORT; | ||
61 | } else { | ||
62 | DDRD &= ~CAPSLOCK_PORT; | ||
63 | PORTD &= ~CAPSLOCK_PORT; | ||
64 | } | ||
65 | |||
66 | if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { | ||
67 | DDRD |= SCROLLLOCK_PORT; | ||
68 | PORTD |= SCROLLLOCK_PORT; | ||
69 | } else { | ||
70 | DDRD &= ~SCROLLLOCK_PORT; | ||
71 | PORTD &= ~SCROLLLOCK_PORT; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | #ifdef BACKLIGHT_ENABLE | ||
76 | |||
77 | // sets up Timer 1 for 8-bit PWM | ||
78 | void timer1PWMSetup(void) { // NOTE ONLY CALL THIS ONCE | ||
79 | // default 8 bit mode | ||
80 | TCCR1A &= ~(1 << 1); // cbi(TCCR1A,PWM11); <- set PWM11 bit to HIGH | ||
81 | TCCR1A |= (1 << 0); // sbi(TCCR1A,PWM10); <- set PWM10 bit to LOW | ||
82 | |||
83 | // clear output compare value A | ||
84 | // outb(OCR1AH, 0); | ||
85 | // outb(OCR1AL, 0); | ||
86 | |||
87 | // clear output comparator registers for B | ||
88 | OCR1BH = 0; // outb(OCR1BH, 0); | ||
89 | OCR1BL = 0; // outb(OCR1BL, 0); | ||
90 | } | ||
91 | |||
92 | bool is_init = false; | ||
93 | void timer1Init(void) { | ||
94 | // timer1SetPrescaler(TIMER1PRESCALE) | ||
95 | // set to DIV/64 | ||
96 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER1PRESCALE; | ||
97 | |||
98 | // reset TCNT1 | ||
99 | TCNT1H = 0; // outb(TCNT1H, 0); | ||
100 | TCNT1L = 0; // outb(TCNT1L, 0); | ||
101 | |||
102 | // TOIE1: Timer Overflow Interrupt Enable (Timer 1); | ||
103 | TIMSK |= _BV(TOIE1); // sbi(TIMSK, TOIE1); | ||
104 | |||
105 | is_init = true; | ||
106 | } | ||
107 | |||
108 | void timer1UnInit(void) { | ||
109 | // set prescaler back to NONE | ||
110 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | 0x00; // TIMERRTC_CLK_STOP | ||
111 | |||
112 | // disable timer overflow interrupt | ||
113 | TIMSK &= ~_BV(TOIE1); // overflow bit? | ||
114 | |||
115 | setPWM(0); | ||
116 | |||
117 | is_init = false; | ||
118 | } | ||
119 | |||
120 | |||
121 | // handle TCNT1 overflow | ||
122 | //! Interrupt handler for tcnt1 overflow interrupt | ||
123 | ISR(TIMER1_OVF_vect, ISR_NOBLOCK) | ||
124 | { | ||
125 | // sei(); | ||
126 | // handle breathing here | ||
127 | #ifdef BACKLIGHT_BREATHING | ||
128 | if (is_breathing()) { | ||
129 | custom_breathing_handler(); | ||
130 | } | ||
131 | #endif | ||
132 | } | ||
133 | |||
134 | // enable timer 1 PWM | ||
135 | // timer1PWMBOn() | ||
136 | void timer1PWMBEnable(void) { | ||
137 | // turn on channel B (OC1B) PWM output | ||
138 | // set OC1B as non-inverted PWM | ||
139 | TCCR1A |= _BV(COM1B1); | ||
140 | TCCR1A &= ~_BV(COM1B0); | ||
141 | } | ||
142 | |||
143 | // disable timer 1 PWM | ||
144 | // timer1PWMBOff() | ||
145 | void timer1PWMBDisable(void) { | ||
146 | TCCR1A &= ~_BV(COM1B1); | ||
147 | TCCR1A &= ~_BV(COM1B0); | ||
148 | } | ||
149 | |||
150 | void enableBacklight(void) { | ||
151 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
152 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
153 | } | ||
154 | |||
155 | void disableBacklight(void) { | ||
156 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
157 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
158 | } | ||
159 | |||
160 | void startPWM(void) { | ||
161 | timer1Init(); | ||
162 | timer1PWMBEnable(); | ||
163 | enableBacklight(); | ||
164 | } | ||
165 | |||
166 | void stopPWM(void) { | ||
167 | timer1UnInit(); | ||
168 | disableBacklight(); | ||
169 | timer1PWMBDisable(); | ||
170 | } | ||
171 | |||
172 | void b_led_init_ports(void) { | ||
173 | /* turn backlight on/off depending on user preference */ | ||
174 | #if BACKLIGHT_ON_STATE == 0 | ||
175 | // DDRx register: sets the direction of Port D | ||
176 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
177 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
178 | #else | ||
179 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
180 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
181 | #endif | ||
182 | |||
183 | timer1PWMSetup(); | ||
184 | startPWM(); | ||
185 | |||
186 | #ifdef BACKLIGHT_BREATHING | ||
187 | breathing_enable(); | ||
188 | #endif | ||
189 | } | ||
190 | |||
191 | void b_led_set(uint8_t level) { | ||
192 | if (level > BACKLIGHT_LEVELS) { | ||
193 | level = BACKLIGHT_LEVELS; | ||
194 | } | ||
195 | |||
196 | setPWM((int)(TIMER_TOP * (float) level / BACKLIGHT_LEVELS)); | ||
197 | } | ||
198 | |||
199 | // called every matrix scan | ||
200 | void b_led_task(void) { | ||
201 | // do nothing for now | ||
202 | } | ||
203 | |||
204 | void setPWM(uint16_t xValue) { | ||
205 | if (xValue > TIMER_TOP) { | ||
206 | xValue = TIMER_TOP; | ||
207 | } | ||
208 | OCR1B = xValue; // timer1PWMBSet(xValue); | ||
209 | } | ||
210 | |||
211 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/winkeyless/bminiex/backlight_custom.h b/keyboards/winkeyless/bminiex/backlight_custom.h deleted file mode 100644 index 51365fe3b..000000000 --- a/keyboards/winkeyless/bminiex/backlight_custom.h +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #pragma once | ||
7 | |||
8 | #include <avr/pgmspace.h> | ||
9 | void b_led_init_ports(void); | ||
10 | void b_led_set(uint8_t level); | ||
11 | void b_led_task(void); | ||
12 | void setPWM(uint16_t xValue); | ||
13 | |||
diff --git a/keyboards/winkeyless/bminiex/bminiex.c b/keyboards/winkeyless/bminiex/bminiex.c index 11315b921..365aeee2b 100644 --- a/keyboards/winkeyless/bminiex/bminiex.c +++ b/keyboards/winkeyless/bminiex/bminiex.c | |||
@@ -17,20 +17,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "bminiex.h" | 18 | #include "bminiex.h" |
19 | 19 | ||
20 | #include "backlight.h" | 20 | void keyboard_pre_init_kb(void) { |
21 | #include "backlight_custom.h" | 21 | led_init_ports(); |
22 | 22 | keyboard_pre_init_user(); | |
23 | #ifdef BACKLIGHT_ENABLE | ||
24 | /// Overrides functions in `quantum.c` | ||
25 | void backlight_init_ports(void) { | ||
26 | b_led_init_ports(); | ||
27 | } | 23 | } |
28 | 24 | ||
29 | void backlight_task(void) { | 25 | void led_init_ports(void) { |
30 | b_led_task(); | 26 | setPinOutput(D0); |
27 | setPinOutput(D1); | ||
28 | setPinOutput(D6); | ||
29 | writePinHigh(D0); | ||
30 | writePinHigh(D1); | ||
31 | writePinHigh(D6); | ||
31 | } | 32 | } |
32 | 33 | ||
33 | void backlight_set(uint8_t level) { | 34 | bool led_update_kb(led_t led_state) { |
34 | b_led_set(level); | 35 | if (led_update_user(led_state)) { |
36 | writePin(D0, !led_state.num_lock); | ||
37 | writePin(D1, !led_state.caps_lock); | ||
38 | writePin(D6, !led_state.scroll_lock); | ||
39 | } | ||
40 | return true; | ||
35 | } | 41 | } |
36 | #endif | ||
diff --git a/keyboards/winkeyless/bminiex/breathing_custom.h b/keyboards/winkeyless/bminiex/breathing_custom.h deleted file mode 100644 index 71416b1b4..000000000 --- a/keyboards/winkeyless/bminiex/breathing_custom.h +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /** | ||
2 | * Breathing effect code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Works in conjunction with `backlight.c`. | ||
4 | * | ||
5 | * Code adapted from `quantum.c` to register with the existing TIMER1 overflow | ||
6 | * handler in `backlight.c` instead of setting up its own timer. | ||
7 | * Kenneth A. (github.com/krusli | krusli.me) | ||
8 | */ | ||
9 | |||
10 | #ifdef BACKLIGHT_ENABLE | ||
11 | #ifdef BACKLIGHT_BREATHING | ||
12 | |||
13 | #include "backlight_custom.h" | ||
14 | |||
15 | #ifndef BREATHING_PERIOD | ||
16 | #define BREATHING_PERIOD 6 | ||
17 | #endif | ||
18 | |||
19 | #define breathing_min() do {breathing_counter = 0;} while (0) | ||
20 | #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) | ||
21 | |||
22 | // TODO make this share code with quantum.c | ||
23 | |||
24 | #define BREATHING_NO_HALT 0 | ||
25 | #define BREATHING_HALT_OFF 1 | ||
26 | #define BREATHING_HALT_ON 2 | ||
27 | #define BREATHING_STEPS 128 | ||
28 | |||
29 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
30 | static uint8_t breathing_halt = BREATHING_NO_HALT; | ||
31 | static uint16_t breathing_counter = 0; | ||
32 | |||
33 | static bool breathing = false; | ||
34 | |||
35 | bool is_breathing(void) { | ||
36 | return breathing; | ||
37 | } | ||
38 | |||
39 | // See http://jared.geek.nz/2013/feb/linear-led-pwm | ||
40 | static uint16_t cie_lightness(uint16_t v) { | ||
41 | if (v <= 5243) // if below 8% of max | ||
42 | return v / 9; // same as dividing by 900% | ||
43 | else { | ||
44 | uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare | ||
45 | // to get a useful result with integer division, we shift left in the expression above | ||
46 | // and revert what we've done again after squaring. | ||
47 | y = y * y * y >> 8; | ||
48 | if (y > 0xFFFFUL) // prevent overflow | ||
49 | return 0xFFFFU; | ||
50 | else | ||
51 | return (uint16_t) y; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void breathing_enable(void) { | ||
56 | breathing = true; | ||
57 | breathing_counter = 0; | ||
58 | breathing_halt = BREATHING_NO_HALT; | ||
59 | // interrupt already registered | ||
60 | } | ||
61 | |||
62 | void breathing_pulse(void) { | ||
63 | if (get_backlight_level() == 0) | ||
64 | breathing_min(); | ||
65 | else | ||
66 | breathing_max(); | ||
67 | breathing_halt = BREATHING_HALT_ON; | ||
68 | // breathing_interrupt_enable(); | ||
69 | breathing = true; | ||
70 | } | ||
71 | |||
72 | void breathing_disable(void) { | ||
73 | breathing = false; | ||
74 | // backlight_set(get_backlight_level()); | ||
75 | b_led_set(get_backlight_level()); // custom implementation of backlight_set() | ||
76 | } | ||
77 | |||
78 | void breathing_self_disable(void) | ||
79 | { | ||
80 | if (get_backlight_level() == 0) | ||
81 | breathing_halt = BREATHING_HALT_OFF; | ||
82 | else | ||
83 | breathing_halt = BREATHING_HALT_ON; | ||
84 | } | ||
85 | |||
86 | void breathing_toggle(void) { | ||
87 | if (is_breathing()) | ||
88 | breathing_disable(); | ||
89 | else | ||
90 | breathing_enable(); | ||
91 | } | ||
92 | |||
93 | void breathing_period_set(uint8_t value) | ||
94 | { | ||
95 | if (!value) | ||
96 | value = 1; | ||
97 | breathing_period = value; | ||
98 | } | ||
99 | |||
100 | void breathing_period_default(void) { | ||
101 | breathing_period_set(BREATHING_PERIOD); | ||
102 | } | ||
103 | |||
104 | void breathing_period_inc(void) | ||
105 | { | ||
106 | breathing_period_set(breathing_period+1); | ||
107 | } | ||
108 | |||
109 | void breathing_period_dec(void) | ||
110 | { | ||
111 | breathing_period_set(breathing_period-1); | ||
112 | } | ||
113 | |||
114 | /* To generate breathing curve in python: | ||
115 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | ||
116 | */ | ||
117 | static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
118 | |||
119 | // Use this before the cie_lightness function. | ||
120 | static inline uint16_t scale_backlight(uint16_t v) { | ||
121 | return v / BACKLIGHT_LEVELS * get_backlight_level(); | ||
122 | } | ||
123 | |||
124 | void custom_breathing_handler(void) { | ||
125 | uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; | ||
126 | // resetting after one period to prevent ugly reset at overflow. | ||
127 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); | ||
128 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; | ||
129 | |||
130 | if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || | ||
131 | ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) | ||
132 | { | ||
133 | // breathing_interrupt_disable(); | ||
134 | } | ||
135 | |||
136 | setPWM(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U))); | ||
137 | } | ||
138 | |||
139 | #endif // BACKLIGHT_BREATHING | ||
140 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/winkeyless/bminiex/config.h b/keyboards/winkeyless/bminiex/config.h index 037ca0028..8952796a8 100644 --- a/keyboards/winkeyless/bminiex/config.h +++ b/keyboards/winkeyless/bminiex/config.h | |||
@@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
36 | 36 | ||
37 | #define RGBLIGHT_ANIMATIONS | 37 | #define RGBLIGHT_ANIMATIONS |
38 | 38 | ||
39 | #define BACKLIGHT_PIN D4 | ||
39 | #define BACKLIGHT_LEVELS 5 | 40 | #define BACKLIGHT_LEVELS 5 |
40 | 41 | ||
41 | #define NO_UART 1 | 42 | #define NO_UART 1 |
diff --git a/keyboards/winkeyless/bminiex/rules.mk b/keyboards/winkeyless/bminiex/rules.mk index 2c999dcbf..df7124400 100644 --- a/keyboards/winkeyless/bminiex/rules.mk +++ b/keyboards/winkeyless/bminiex/rules.mk | |||
@@ -19,7 +19,6 @@ CONSOLE_ENABLE = no | |||
19 | DEBUG_ENABLE = no | 19 | DEBUG_ENABLE = no |
20 | COMMAND_ENABLE = no | 20 | COMMAND_ENABLE = no |
21 | BACKLIGHT_ENABLE = yes | 21 | BACKLIGHT_ENABLE = yes |
22 | BACKLIGHT_CUSTOM_DRIVER = yes | ||
23 | RGBLIGHT_ENABLE = yes | 22 | RGBLIGHT_ENABLE = yes |
24 | WS2812_DRIVER = i2c | 23 | WS2812_DRIVER = i2c |
25 | TAP_DANCE_ENABLE = no | 24 | TAP_DANCE_ENABLE = no |
@@ -28,5 +27,3 @@ TAP_DANCE_ENABLE = no | |||
28 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 27 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
29 | 28 | ||
30 | OPT_DEFS = -DDEBUG_LEVEL=0 | 29 | OPT_DEFS = -DDEBUG_LEVEL=0 |
31 | |||
32 | SRC += backlight.c | ||
diff --git a/keyboards/ymd75/backlight.c b/keyboards/ymd75/backlight.c deleted file mode 100644 index cb0a97923..000000000 --- a/keyboards/ymd75/backlight.c +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | Modified by Wayne K Jones (github.com/WarmCatUK) 2018 | ||
5 | */ | ||
6 | |||
7 | #include "backlight.h" | ||
8 | #include "quantum.h" | ||
9 | |||
10 | #include <avr/pgmspace.h> | ||
11 | #include <avr/interrupt.h> | ||
12 | |||
13 | #include "backlight_custom.h" | ||
14 | #include "breathing_custom.h" | ||
15 | |||
16 | // DEBUG | ||
17 | #include <stdlib.h> | ||
18 | #include <stdio.h> | ||
19 | |||
20 | // Port D: digital pins of the AVR chipset | ||
21 | //#define NUMLOCK_PORT (1 << 2) // 2nd pin of Port D (digital) | ||
22 | #define CAPSLOCK_PORT (1 << 1) // 1st pin | ||
23 | #define BACKLIGHT_PORT (1 << 4) // D4 | ||
24 | //#define SCROLLLOCK_PORT (1 << 6) // D6 | ||
25 | |||
26 | #define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 | ||
27 | #define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default | ||
28 | |||
29 | #define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask | ||
30 | |||
31 | #define PWM_MAX 0xFF | ||
32 | #define TIMER_TOP 255 // 8 bit PWM | ||
33 | |||
34 | extern backlight_config_t backlight_config; | ||
35 | |||
36 | /** | ||
37 | * References | ||
38 | * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation | ||
39 | * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b | ||
40 | * Timers: http://www.avrbeginners.net/architecture/timers/timers.html | ||
41 | * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/ | ||
42 | * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware | ||
43 | */ | ||
44 | |||
45 | // @Override | ||
46 | // turn LEDs on and off depending on USB caps/num/scroll lock states. | ||
47 | __attribute__ ((weak)) | ||
48 | void led_set_user(uint8_t usb_led) { | ||
49 | /* | ||
50 | if (usb_led & (1 << USB_LED_NUM_LOCK)) { | ||
51 | // turn on | ||
52 | DDRD |= NUMLOCK_PORT; | ||
53 | PORTD |= NUMLOCK_PORT; | ||
54 | } else { | ||
55 | // turn off | ||
56 | DDRD &= ~NUMLOCK_PORT; | ||
57 | PORTD &= ~NUMLOCK_PORT; | ||
58 | } | ||
59 | */ | ||
60 | if (usb_led & (1 << USB_LED_CAPS_LOCK)) { | ||
61 | DDRD |= CAPSLOCK_PORT; | ||
62 | PORTD |= CAPSLOCK_PORT; | ||
63 | } else { | ||
64 | DDRD &= ~CAPSLOCK_PORT; | ||
65 | PORTD &= ~CAPSLOCK_PORT; | ||
66 | } | ||
67 | /* | ||
68 | if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { | ||
69 | DDRD |= SCROLLLOCK_PORT; | ||
70 | PORTD |= SCROLLLOCK_PORT; | ||
71 | } else { | ||
72 | DDRD &= ~SCROLLLOCK_PORT; | ||
73 | PORTD &= ~SCROLLLOCK_PORT; | ||
74 | } | ||
75 | */ | ||
76 | } | ||
77 | |||
78 | #ifdef BACKLIGHT_ENABLE | ||
79 | |||
80 | // sets up Timer 1 for 8-bit PWM | ||
81 | void timer1PWMSetup(void) { // NOTE ONLY CALL THIS ONCE | ||
82 | // default 8 bit mode | ||
83 | TCCR1A &= ~(1 << 1); // cbi(TCCR1A,PWM11); <- set PWM11 bit to HIGH | ||
84 | TCCR1A |= (1 << 0); // sbi(TCCR1A,PWM10); <- set PWM10 bit to LOW | ||
85 | |||
86 | // clear output compare value A | ||
87 | // outb(OCR1AH, 0); | ||
88 | // outb(OCR1AL, 0); | ||
89 | |||
90 | // clear output comparator registers for B | ||
91 | OCR1BH = 0; // outb(OCR1BH, 0); | ||
92 | OCR1BL = 0; // outb(OCR1BL, 0); | ||
93 | } | ||
94 | |||
95 | bool is_init = false; | ||
96 | void timer1Init(void) { | ||
97 | // timer1SetPrescaler(TIMER1PRESCALE) | ||
98 | // set to DIV/64 | ||
99 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER1PRESCALE; | ||
100 | |||
101 | // reset TCNT1 | ||
102 | TCNT1H = 0; // outb(TCNT1H, 0); | ||
103 | TCNT1L = 0; // outb(TCNT1L, 0); | ||
104 | |||
105 | // TOIE1: Timer Overflow Interrupt Enable (Timer 1); | ||
106 | TIMSK |= _BV(TOIE1); // sbi(TIMSK, TOIE1); | ||
107 | |||
108 | is_init = true; | ||
109 | } | ||
110 | |||
111 | void timer1UnInit(void) { | ||
112 | // set prescaler back to NONE | ||
113 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | 0x00; // TIMERRTC_CLK_STOP | ||
114 | |||
115 | // disable timer overflow interrupt | ||
116 | TIMSK &= ~_BV(TOIE1); // overflow bit? | ||
117 | |||
118 | setPWM(0); | ||
119 | |||
120 | is_init = false; | ||
121 | } | ||
122 | |||
123 | |||
124 | // handle TCNT1 overflow | ||
125 | //! Interrupt handler for tcnt1 overflow interrupt | ||
126 | ISR(TIMER1_OVF_vect, ISR_NOBLOCK) | ||
127 | { | ||
128 | // sei(); | ||
129 | // handle breathing here | ||
130 | #ifdef BACKLIGHT_BREATHING | ||
131 | if (is_breathing()) { | ||
132 | custom_breathing_handler(); | ||
133 | } | ||
134 | #endif | ||
135 | |||
136 | // TODO call user defined function | ||
137 | } | ||
138 | |||
139 | // enable timer 1 PWM | ||
140 | // timer1PWMBOn() | ||
141 | void timer1PWMBEnable(void) { | ||
142 | // turn on channel B (OC1B) PWM output | ||
143 | // set OC1B as non-inverted PWM | ||
144 | TCCR1A |= _BV(COM1B1); | ||
145 | TCCR1A &= ~_BV(COM1B0); | ||
146 | } | ||
147 | |||
148 | // disable timer 1 PWM | ||
149 | // timer1PWMBOff() | ||
150 | void timer1PWMBDisable(void) { | ||
151 | TCCR1A &= ~_BV(COM1B1); | ||
152 | TCCR1A &= ~_BV(COM1B0); | ||
153 | } | ||
154 | |||
155 | void enableBacklight(void) { | ||
156 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
157 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
158 | } | ||
159 | |||
160 | void disableBacklight(void) { | ||
161 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
162 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
163 | } | ||
164 | |||
165 | void startPWM(void) { | ||
166 | timer1Init(); | ||
167 | timer1PWMBEnable(); | ||
168 | enableBacklight(); | ||
169 | } | ||
170 | |||
171 | void stopPWM(void) { | ||
172 | timer1UnInit(); | ||
173 | disableBacklight(); | ||
174 | timer1PWMBDisable(); | ||
175 | } | ||
176 | |||
177 | void b_led_init_ports(void) { | ||
178 | /* turn backlight on/off depending on user preference */ | ||
179 | #if BACKLIGHT_ON_STATE == 0 | ||
180 | // DDRx register: sets the direction of Port D | ||
181 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
182 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
183 | #else | ||
184 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
185 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
186 | #endif | ||
187 | |||
188 | timer1PWMSetup(); | ||
189 | startPWM(); | ||
190 | |||
191 | #ifdef BACKLIGHT_BREATHING | ||
192 | breathing_enable(); | ||
193 | #endif | ||
194 | } | ||
195 | |||
196 | void b_led_set(uint8_t level) { | ||
197 | if (level > BACKLIGHT_LEVELS) { | ||
198 | level = BACKLIGHT_LEVELS; | ||
199 | } | ||
200 | |||
201 | setPWM((int)(TIMER_TOP * (float) level / BACKLIGHT_LEVELS)); | ||
202 | } | ||
203 | |||
204 | // called every matrix scan | ||
205 | void b_led_task(void) { | ||
206 | // do nothing for now | ||
207 | } | ||
208 | |||
209 | void setPWM(uint16_t xValue) { | ||
210 | if (xValue > TIMER_TOP) { | ||
211 | xValue = TIMER_TOP; | ||
212 | } | ||
213 | OCR1B = xValue; // timer1PWMBSet(xValue); | ||
214 | } | ||
215 | |||
216 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/ymd75/backlight_custom.h b/keyboards/ymd75/backlight_custom.h deleted file mode 100644 index 7210be840..000000000 --- a/keyboards/ymd75/backlight_custom.h +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #ifndef BACKLIGHT_CUSTOM_H | ||
7 | #define BACKLIGHT_CUSTOM_H | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | void b_led_init_ports(void); | ||
11 | void b_led_set(uint8_t level); | ||
12 | void b_led_task(void); | ||
13 | void setPWM(uint16_t xValue); | ||
14 | |||
15 | #endif // BACKLIGHT_CUSTOM_H | ||
diff --git a/keyboards/ymd75/breathing_custom.h b/keyboards/ymd75/breathing_custom.h deleted file mode 100644 index 71416b1b4..000000000 --- a/keyboards/ymd75/breathing_custom.h +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /** | ||
2 | * Breathing effect code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Works in conjunction with `backlight.c`. | ||
4 | * | ||
5 | * Code adapted from `quantum.c` to register with the existing TIMER1 overflow | ||
6 | * handler in `backlight.c` instead of setting up its own timer. | ||
7 | * Kenneth A. (github.com/krusli | krusli.me) | ||
8 | */ | ||
9 | |||
10 | #ifdef BACKLIGHT_ENABLE | ||
11 | #ifdef BACKLIGHT_BREATHING | ||
12 | |||
13 | #include "backlight_custom.h" | ||
14 | |||
15 | #ifndef BREATHING_PERIOD | ||
16 | #define BREATHING_PERIOD 6 | ||
17 | #endif | ||
18 | |||
19 | #define breathing_min() do {breathing_counter = 0;} while (0) | ||
20 | #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) | ||
21 | |||
22 | // TODO make this share code with quantum.c | ||
23 | |||
24 | #define BREATHING_NO_HALT 0 | ||
25 | #define BREATHING_HALT_OFF 1 | ||
26 | #define BREATHING_HALT_ON 2 | ||
27 | #define BREATHING_STEPS 128 | ||
28 | |||
29 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
30 | static uint8_t breathing_halt = BREATHING_NO_HALT; | ||
31 | static uint16_t breathing_counter = 0; | ||
32 | |||
33 | static bool breathing = false; | ||
34 | |||
35 | bool is_breathing(void) { | ||
36 | return breathing; | ||
37 | } | ||
38 | |||
39 | // See http://jared.geek.nz/2013/feb/linear-led-pwm | ||
40 | static uint16_t cie_lightness(uint16_t v) { | ||
41 | if (v <= 5243) // if below 8% of max | ||
42 | return v / 9; // same as dividing by 900% | ||
43 | else { | ||
44 | uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare | ||
45 | // to get a useful result with integer division, we shift left in the expression above | ||
46 | // and revert what we've done again after squaring. | ||
47 | y = y * y * y >> 8; | ||
48 | if (y > 0xFFFFUL) // prevent overflow | ||
49 | return 0xFFFFU; | ||
50 | else | ||
51 | return (uint16_t) y; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void breathing_enable(void) { | ||
56 | breathing = true; | ||
57 | breathing_counter = 0; | ||
58 | breathing_halt = BREATHING_NO_HALT; | ||
59 | // interrupt already registered | ||
60 | } | ||
61 | |||
62 | void breathing_pulse(void) { | ||
63 | if (get_backlight_level() == 0) | ||
64 | breathing_min(); | ||
65 | else | ||
66 | breathing_max(); | ||
67 | breathing_halt = BREATHING_HALT_ON; | ||
68 | // breathing_interrupt_enable(); | ||
69 | breathing = true; | ||
70 | } | ||
71 | |||
72 | void breathing_disable(void) { | ||
73 | breathing = false; | ||
74 | // backlight_set(get_backlight_level()); | ||
75 | b_led_set(get_backlight_level()); // custom implementation of backlight_set() | ||
76 | } | ||
77 | |||
78 | void breathing_self_disable(void) | ||
79 | { | ||
80 | if (get_backlight_level() == 0) | ||
81 | breathing_halt = BREATHING_HALT_OFF; | ||
82 | else | ||
83 | breathing_halt = BREATHING_HALT_ON; | ||
84 | } | ||
85 | |||
86 | void breathing_toggle(void) { | ||
87 | if (is_breathing()) | ||
88 | breathing_disable(); | ||
89 | else | ||
90 | breathing_enable(); | ||
91 | } | ||
92 | |||
93 | void breathing_period_set(uint8_t value) | ||
94 | { | ||
95 | if (!value) | ||
96 | value = 1; | ||
97 | breathing_period = value; | ||
98 | } | ||
99 | |||
100 | void breathing_period_default(void) { | ||
101 | breathing_period_set(BREATHING_PERIOD); | ||
102 | } | ||
103 | |||
104 | void breathing_period_inc(void) | ||
105 | { | ||
106 | breathing_period_set(breathing_period+1); | ||
107 | } | ||
108 | |||
109 | void breathing_period_dec(void) | ||
110 | { | ||
111 | breathing_period_set(breathing_period-1); | ||
112 | } | ||
113 | |||
114 | /* To generate breathing curve in python: | ||
115 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | ||
116 | */ | ||
117 | static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
118 | |||
119 | // Use this before the cie_lightness function. | ||
120 | static inline uint16_t scale_backlight(uint16_t v) { | ||
121 | return v / BACKLIGHT_LEVELS * get_backlight_level(); | ||
122 | } | ||
123 | |||
124 | void custom_breathing_handler(void) { | ||
125 | uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; | ||
126 | // resetting after one period to prevent ugly reset at overflow. | ||
127 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); | ||
128 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; | ||
129 | |||
130 | if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || | ||
131 | ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) | ||
132 | { | ||
133 | // breathing_interrupt_disable(); | ||
134 | } | ||
135 | |||
136 | setPWM(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U))); | ||
137 | } | ||
138 | |||
139 | #endif // BACKLIGHT_BREATHING | ||
140 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/ymd75/config.h b/keyboards/ymd75/config.h index 00f6bd292..88916be62 100644 --- a/keyboards/ymd75/config.h +++ b/keyboards/ymd75/config.h | |||
@@ -17,8 +17,7 @@ You should have received a copy of the GNU General Public License | |||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #ifndef CONFIG_H | 20 | #pragma once |
21 | #define CONFIG_H | ||
22 | 21 | ||
23 | #include "config_common.h" | 22 | #include "config_common.h" |
24 | 23 | ||
@@ -39,6 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
39 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 } | 38 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 } |
40 | #define DIODE_DIRECTION COL2ROW | 39 | #define DIODE_DIRECTION COL2ROW |
41 | 40 | ||
41 | #define BACKLIGHT_PIN D4 | ||
42 | #define BACKLIGHT_LEVELS 12 | 42 | #define BACKLIGHT_LEVELS 12 |
43 | 43 | ||
44 | #define RGB_DI_PIN E2 | 44 | #define RGB_DI_PIN E2 |
@@ -49,5 +49,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
49 | #define RGBLIGHT_VAL_STEP 18 | 49 | #define RGBLIGHT_VAL_STEP 18 |
50 | 50 | ||
51 | #define NO_UART 1 | 51 | #define NO_UART 1 |
52 | |||
53 | #endif | ||
diff --git a/keyboards/ymd75/rules.mk b/keyboards/ymd75/rules.mk index eb41e19cf..9d584b2b4 100644 --- a/keyboards/ymd75/rules.mk +++ b/keyboards/ymd75/rules.mk | |||
@@ -23,14 +23,8 @@ WS2812_DRIVER = i2c | |||
23 | NKRO_ENABLE = no | 23 | NKRO_ENABLE = no |
24 | # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 24 | # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
25 | 25 | ||
26 | |||
27 | DISABLE_WS2812 = no | 26 | DISABLE_WS2812 = no |
28 | 27 | ||
29 | KEY_LOCK_ENABLE = yes | 28 | KEY_LOCK_ENABLE = yes |
30 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 29 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
31 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 30 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
32 | |||
33 | |||
34 | #OPT_DEFS = -DDEBUG_LEVEL=0 | ||
35 | |||
36 | SRC = backlight.c | ||
diff --git a/keyboards/ymd75/ymd75.c b/keyboards/ymd75/ymd75.c index e32a745bf..1c5c38039 100644 --- a/keyboards/ymd75/ymd75.c +++ b/keyboards/ymd75/ymd75.c | |||
@@ -17,20 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "ymd75.h" | 18 | #include "ymd75.h" |
19 | 19 | ||
20 | #include "backlight.h" | 20 | void keyboard_pre_init_kb(void) { |
21 | #include "backlight_custom.h" | 21 | led_init_ports(); |
22 | 22 | keyboard_pre_init_user(); | |
23 | #ifdef BACKLIGHT_ENABLE | ||
24 | /// Overrides functions in `quantum.c` | ||
25 | void backlight_init_ports(void) { | ||
26 | b_led_init_ports(); | ||
27 | } | 23 | } |
28 | 24 | ||
29 | void backlight_task(void) { | 25 | void led_init_ports(void) { |
30 | b_led_task(); | 26 | setPinOutput(D1); |
27 | writePinHigh(D1); | ||
31 | } | 28 | } |
32 | 29 | ||
33 | void backlight_set(uint8_t level) { | 30 | bool led_update_kb(led_t led_state) { |
34 | b_led_set(level); | 31 | if (led_update_user(led_state)) { |
32 | writePin(D1, !led_state.caps_lock); | ||
33 | } | ||
34 | return true; | ||
35 | } | 35 | } |
36 | #endif | ||
diff --git a/keyboards/ymd96/backlight.c b/keyboards/ymd96/backlight.c deleted file mode 100644 index f3f2b7a05..000000000 --- a/keyboards/ymd96/backlight.c +++ /dev/null | |||
@@ -1,214 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #include "backlight.h" | ||
7 | #include "quantum.h" | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | #include <avr/interrupt.h> | ||
11 | |||
12 | #include "backlight_custom.h" | ||
13 | #include "breathing_custom.h" | ||
14 | |||
15 | // DEBUG | ||
16 | #include <stdlib.h> | ||
17 | #include <stdio.h> | ||
18 | |||
19 | // Port D: digital pins of the AVR chipset | ||
20 | #define NUMLOCK_PORT (1 << 0) // 0th pin of Port D (digital) | ||
21 | #define CAPSLOCK_PORT (1 << 1) // 1st pin | ||
22 | #define BACKLIGHT_PORT (1 << 4) // D4 | ||
23 | //#define SCROLLLOCK_PORT (1 << 6) // D6 | ||
24 | |||
25 | #define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 | ||
26 | #define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default | ||
27 | |||
28 | #define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask | ||
29 | |||
30 | #define PWM_MAX 0xFF | ||
31 | #define TIMER_TOP 255 // 8 bit PWM | ||
32 | |||
33 | extern backlight_config_t backlight_config; | ||
34 | |||
35 | /** | ||
36 | * References | ||
37 | * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation | ||
38 | * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b | ||
39 | * Timers: http://www.avrbeginners.net/architecture/timers/timers.html | ||
40 | * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/ | ||
41 | * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware | ||
42 | */ | ||
43 | |||
44 | // @Override | ||
45 | // turn LEDs on and off depending on USB caps/num/scroll lock states. | ||
46 | __attribute__ ((weak)) | ||
47 | void led_set_user(uint8_t usb_led) { | ||
48 | if (usb_led & (1 << USB_LED_NUM_LOCK)) { | ||
49 | // turn on | ||
50 | DDRD |= NUMLOCK_PORT; | ||
51 | PORTD |= NUMLOCK_PORT; | ||
52 | } else { | ||
53 | // turn off | ||
54 | DDRD &= ~NUMLOCK_PORT; | ||
55 | PORTD &= ~NUMLOCK_PORT; | ||
56 | } | ||
57 | |||
58 | if (usb_led & (1 << USB_LED_CAPS_LOCK)) { | ||
59 | DDRD |= CAPSLOCK_PORT; | ||
60 | PORTD |= CAPSLOCK_PORT; | ||
61 | } else { | ||
62 | DDRD &= ~CAPSLOCK_PORT; | ||
63 | PORTD &= ~CAPSLOCK_PORT; | ||
64 | } | ||
65 | |||
66 | /* YMD96 does not have scroll lock led | ||
67 | if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { | ||
68 | DDRD |= SCROLLLOCK_PORT; | ||
69 | PORTD |= SCROLLLOCK_PORT; | ||
70 | } else { | ||
71 | DDRD &= ~SCROLLLOCK_PORT; | ||
72 | PORTD &= ~SCROLLLOCK_PORT; | ||
73 | }*/ | ||
74 | } | ||
75 | |||
76 | #ifdef BACKLIGHT_ENABLE | ||
77 | |||
78 | // sets up Timer 1 for 8-bit PWM | ||
79 | void timer1PWMSetup(void) { // NOTE ONLY CALL THIS ONCE | ||
80 | // default 8 bit mode | ||
81 | TCCR1A &= ~(1 << 1); // cbi(TCCR1A,PWM11); <- set PWM11 bit to HIGH | ||
82 | TCCR1A |= (1 << 0); // sbi(TCCR1A,PWM10); <- set PWM10 bit to LOW | ||
83 | |||
84 | // clear output compare value A | ||
85 | // outb(OCR1AH, 0); | ||
86 | // outb(OCR1AL, 0); | ||
87 | |||
88 | // clear output comparator registers for B | ||
89 | OCR1BH = 0; // outb(OCR1BH, 0); | ||
90 | OCR1BL = 0; // outb(OCR1BL, 0); | ||
91 | } | ||
92 | |||
93 | bool is_init = false; | ||
94 | void timer1Init(void) { | ||
95 | // timer1SetPrescaler(TIMER1PRESCALE) | ||
96 | // set to DIV/64 | ||
97 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER1PRESCALE; | ||
98 | |||
99 | // reset TCNT1 | ||
100 | TCNT1H = 0; // outb(TCNT1H, 0); | ||
101 | TCNT1L = 0; // outb(TCNT1L, 0); | ||
102 | |||
103 | // TOIE1: Timer Overflow Interrupt Enable (Timer 1); | ||
104 | TIMSK |= _BV(TOIE1); // sbi(TIMSK, TOIE1); | ||
105 | |||
106 | is_init = true; | ||
107 | } | ||
108 | |||
109 | void timer1UnInit(void) { | ||
110 | // set prescaler back to NONE | ||
111 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | 0x00; // TIMERRTC_CLK_STOP | ||
112 | |||
113 | // disable timer overflow interrupt | ||
114 | TIMSK &= ~_BV(TOIE1); // overflow bit? | ||
115 | |||
116 | setPWM(0); | ||
117 | |||
118 | is_init = false; | ||
119 | } | ||
120 | |||
121 | |||
122 | // handle TCNT1 overflow | ||
123 | //! Interrupt handler for tcnt1 overflow interrupt | ||
124 | ISR(TIMER1_OVF_vect, ISR_NOBLOCK) | ||
125 | { | ||
126 | // sei(); | ||
127 | // handle breathing here | ||
128 | #ifdef BACKLIGHT_BREATHING | ||
129 | if (is_breathing()) { | ||
130 | custom_breathing_handler(); | ||
131 | } | ||
132 | #endif | ||
133 | |||
134 | // TODO call user defined function | ||
135 | } | ||
136 | |||
137 | // enable timer 1 PWM | ||
138 | // timer1PWMBOn() | ||
139 | void timer1PWMBEnable(void) { | ||
140 | // turn on channel B (OC1B) PWM output | ||
141 | // set OC1B as non-inverted PWM | ||
142 | TCCR1A |= _BV(COM1B1); | ||
143 | TCCR1A &= ~_BV(COM1B0); | ||
144 | } | ||
145 | |||
146 | // disable timer 1 PWM | ||
147 | // timer1PWMBOff() | ||
148 | void timer1PWMBDisable(void) { | ||
149 | TCCR1A &= ~_BV(COM1B1); | ||
150 | TCCR1A &= ~_BV(COM1B0); | ||
151 | } | ||
152 | |||
153 | void enableBacklight(void) { | ||
154 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
155 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
156 | } | ||
157 | |||
158 | void disableBacklight(void) { | ||
159 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
160 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
161 | } | ||
162 | |||
163 | void startPWM(void) { | ||
164 | timer1Init(); | ||
165 | timer1PWMBEnable(); | ||
166 | enableBacklight(); | ||
167 | } | ||
168 | |||
169 | void stopPWM(void) { | ||
170 | timer1UnInit(); | ||
171 | disableBacklight(); | ||
172 | timer1PWMBDisable(); | ||
173 | } | ||
174 | |||
175 | void b_led_init_ports(void) { | ||
176 | /* turn backlight on/off depending on user preference */ | ||
177 | #if BACKLIGHT_ON_STATE == 0 | ||
178 | // DDRx register: sets the direction of Port D | ||
179 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
180 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
181 | #else | ||
182 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
183 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
184 | #endif | ||
185 | |||
186 | timer1PWMSetup(); | ||
187 | startPWM(); | ||
188 | |||
189 | #ifdef BACKLIGHT_BREATHING | ||
190 | breathing_enable(); | ||
191 | #endif | ||
192 | } | ||
193 | |||
194 | void b_led_set(uint8_t level) { | ||
195 | if (level > BACKLIGHT_LEVELS) { | ||
196 | level = BACKLIGHT_LEVELS; | ||
197 | } | ||
198 | |||
199 | setPWM((int)(TIMER_TOP * (float) level / BACKLIGHT_LEVELS)); | ||
200 | } | ||
201 | |||
202 | // called every matrix scan | ||
203 | void b_led_task(void) { | ||
204 | // do nothing for now | ||
205 | } | ||
206 | |||
207 | void setPWM(uint16_t xValue) { | ||
208 | if (xValue > TIMER_TOP) { | ||
209 | xValue = TIMER_TOP; | ||
210 | } | ||
211 | OCR1B = xValue; // timer1PWMBSet(xValue); | ||
212 | } | ||
213 | |||
214 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/ymd96/backlight_custom.h b/keyboards/ymd96/backlight_custom.h deleted file mode 100644 index 7210be840..000000000 --- a/keyboards/ymd96/backlight_custom.h +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #ifndef BACKLIGHT_CUSTOM_H | ||
7 | #define BACKLIGHT_CUSTOM_H | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | void b_led_init_ports(void); | ||
11 | void b_led_set(uint8_t level); | ||
12 | void b_led_task(void); | ||
13 | void setPWM(uint16_t xValue); | ||
14 | |||
15 | #endif // BACKLIGHT_CUSTOM_H | ||
diff --git a/keyboards/ymd96/breathing_custom.h b/keyboards/ymd96/breathing_custom.h deleted file mode 100644 index 71416b1b4..000000000 --- a/keyboards/ymd96/breathing_custom.h +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /** | ||
2 | * Breathing effect code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Works in conjunction with `backlight.c`. | ||
4 | * | ||
5 | * Code adapted from `quantum.c` to register with the existing TIMER1 overflow | ||
6 | * handler in `backlight.c` instead of setting up its own timer. | ||
7 | * Kenneth A. (github.com/krusli | krusli.me) | ||
8 | */ | ||
9 | |||
10 | #ifdef BACKLIGHT_ENABLE | ||
11 | #ifdef BACKLIGHT_BREATHING | ||
12 | |||
13 | #include "backlight_custom.h" | ||
14 | |||
15 | #ifndef BREATHING_PERIOD | ||
16 | #define BREATHING_PERIOD 6 | ||
17 | #endif | ||
18 | |||
19 | #define breathing_min() do {breathing_counter = 0;} while (0) | ||
20 | #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) | ||
21 | |||
22 | // TODO make this share code with quantum.c | ||
23 | |||
24 | #define BREATHING_NO_HALT 0 | ||
25 | #define BREATHING_HALT_OFF 1 | ||
26 | #define BREATHING_HALT_ON 2 | ||
27 | #define BREATHING_STEPS 128 | ||
28 | |||
29 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
30 | static uint8_t breathing_halt = BREATHING_NO_HALT; | ||
31 | static uint16_t breathing_counter = 0; | ||
32 | |||
33 | static bool breathing = false; | ||
34 | |||
35 | bool is_breathing(void) { | ||
36 | return breathing; | ||
37 | } | ||
38 | |||
39 | // See http://jared.geek.nz/2013/feb/linear-led-pwm | ||
40 | static uint16_t cie_lightness(uint16_t v) { | ||
41 | if (v <= 5243) // if below 8% of max | ||
42 | return v / 9; // same as dividing by 900% | ||
43 | else { | ||
44 | uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare | ||
45 | // to get a useful result with integer division, we shift left in the expression above | ||
46 | // and revert what we've done again after squaring. | ||
47 | y = y * y * y >> 8; | ||
48 | if (y > 0xFFFFUL) // prevent overflow | ||
49 | return 0xFFFFU; | ||
50 | else | ||
51 | return (uint16_t) y; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void breathing_enable(void) { | ||
56 | breathing = true; | ||
57 | breathing_counter = 0; | ||
58 | breathing_halt = BREATHING_NO_HALT; | ||
59 | // interrupt already registered | ||
60 | } | ||
61 | |||
62 | void breathing_pulse(void) { | ||
63 | if (get_backlight_level() == 0) | ||
64 | breathing_min(); | ||
65 | else | ||
66 | breathing_max(); | ||
67 | breathing_halt = BREATHING_HALT_ON; | ||
68 | // breathing_interrupt_enable(); | ||
69 | breathing = true; | ||
70 | } | ||
71 | |||
72 | void breathing_disable(void) { | ||
73 | breathing = false; | ||
74 | // backlight_set(get_backlight_level()); | ||
75 | b_led_set(get_backlight_level()); // custom implementation of backlight_set() | ||
76 | } | ||
77 | |||
78 | void breathing_self_disable(void) | ||
79 | { | ||
80 | if (get_backlight_level() == 0) | ||
81 | breathing_halt = BREATHING_HALT_OFF; | ||
82 | else | ||
83 | breathing_halt = BREATHING_HALT_ON; | ||
84 | } | ||
85 | |||
86 | void breathing_toggle(void) { | ||
87 | if (is_breathing()) | ||
88 | breathing_disable(); | ||
89 | else | ||
90 | breathing_enable(); | ||
91 | } | ||
92 | |||
93 | void breathing_period_set(uint8_t value) | ||
94 | { | ||
95 | if (!value) | ||
96 | value = 1; | ||
97 | breathing_period = value; | ||
98 | } | ||
99 | |||
100 | void breathing_period_default(void) { | ||
101 | breathing_period_set(BREATHING_PERIOD); | ||
102 | } | ||
103 | |||
104 | void breathing_period_inc(void) | ||
105 | { | ||
106 | breathing_period_set(breathing_period+1); | ||
107 | } | ||
108 | |||
109 | void breathing_period_dec(void) | ||
110 | { | ||
111 | breathing_period_set(breathing_period-1); | ||
112 | } | ||
113 | |||
114 | /* To generate breathing curve in python: | ||
115 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | ||
116 | */ | ||
117 | static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
118 | |||
119 | // Use this before the cie_lightness function. | ||
120 | static inline uint16_t scale_backlight(uint16_t v) { | ||
121 | return v / BACKLIGHT_LEVELS * get_backlight_level(); | ||
122 | } | ||
123 | |||
124 | void custom_breathing_handler(void) { | ||
125 | uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; | ||
126 | // resetting after one period to prevent ugly reset at overflow. | ||
127 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); | ||
128 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; | ||
129 | |||
130 | if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || | ||
131 | ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) | ||
132 | { | ||
133 | // breathing_interrupt_disable(); | ||
134 | } | ||
135 | |||
136 | setPWM(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U))); | ||
137 | } | ||
138 | |||
139 | #endif // BACKLIGHT_BREATHING | ||
140 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/ymd96/config.h b/keyboards/ymd96/config.h index 1232f90c2..d761e6037 100644 --- a/keyboards/ymd96/config.h +++ b/keyboards/ymd96/config.h | |||
@@ -18,8 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | 18 | ||
19 | #include "config_common.h" | 19 | #include "config_common.h" |
20 | 20 | ||
21 | #ifndef CONFIG_H | 21 | #pragma once |
22 | #define CONFIG_H | ||
23 | 22 | ||
24 | #define VENDOR_ID 0x20A0 | 23 | #define VENDOR_ID 0x20A0 |
25 | #define PRODUCT_ID 0x422D | 24 | #define PRODUCT_ID 0x422D |
@@ -38,8 +37,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
38 | /* COL2ROW or ROW2COL */ | 37 | /* COL2ROW or ROW2COL */ |
39 | #define DIODE_DIRECTION COL2ROW | 38 | #define DIODE_DIRECTION COL2ROW |
40 | 39 | ||
40 | #define BACKLIGHT_PIN D4 | ||
41 | #define BACKLIGHT_LEVELS 12 | 41 | #define BACKLIGHT_LEVELS 12 |
42 | // #define BACKLIGHT_BREATHING // works, but BL_TOGG might not work | 42 | #define BACKLIGHT_BREATHING |
43 | 43 | ||
44 | #define TAPPING_TOGGLE 3 | 44 | #define TAPPING_TOGGLE 3 |
45 | 45 | ||
@@ -55,5 +55,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
55 | /*#define RGBLIGHT_VAL_STEP 20 | 55 | /*#define RGBLIGHT_VAL_STEP 20 |
56 | 56 | ||
57 | #define NO_UART 1*/ | 57 | #define NO_UART 1*/ |
58 | |||
59 | #endif | ||
diff --git a/keyboards/ymd96/rules.mk b/keyboards/ymd96/rules.mk index 3c892daab..b7571649b 100644 --- a/keyboards/ymd96/rules.mk +++ b/keyboards/ymd96/rules.mk | |||
@@ -19,7 +19,6 @@ CONSOLE_ENABLE = no | |||
19 | COMMAND_ENABLE = no | 19 | COMMAND_ENABLE = no |
20 | 20 | ||
21 | BACKLIGHT_ENABLE = yes | 21 | BACKLIGHT_ENABLE = yes |
22 | BACKLIGHT_CUSTOM_DRIVER = yes | ||
23 | 22 | ||
24 | RGBLIGHT_ENABLE = yes | 23 | RGBLIGHT_ENABLE = yes |
25 | WS2812_DRIVER = i2c | 24 | WS2812_DRIVER = i2c |
@@ -30,5 +29,3 @@ KEY_LOCK_ENABLE = yes | |||
30 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 29 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
31 | 30 | ||
32 | OPT_DEFS = -DDEBUG_LEVEL=0 | 31 | OPT_DEFS = -DDEBUG_LEVEL=0 |
33 | |||
34 | SRC = backlight.c | ||
diff --git a/keyboards/ymd96/ymd96.c b/keyboards/ymd96/ymd96.c index eae84ade1..c81435e45 100644 --- a/keyboards/ymd96/ymd96.c +++ b/keyboards/ymd96/ymd96.c | |||
@@ -18,20 +18,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | 18 | ||
19 | #include "ymd96.h" | 19 | #include "ymd96.h" |
20 | 20 | ||
21 | #include "backlight.h" | 21 | void keyboard_pre_init_kb(void) { |
22 | #include "backlight_custom.h" | 22 | led_init_ports(); |
23 | 23 | keyboard_pre_init_user(); | |
24 | #ifdef BACKLIGHT_ENABLE | ||
25 | /// Overrides functions in `quantum.c` | ||
26 | void backlight_init_ports(void) { | ||
27 | b_led_init_ports(); | ||
28 | } | 24 | } |
29 | 25 | ||
30 | void backlight_task(void) { | 26 | void led_init_ports(void) { |
31 | b_led_task(); | 27 | setPinOutput(D0); |
28 | setPinOutput(D1); | ||
29 | writePinHigh(D0); | ||
30 | writePinHigh(D1); | ||
32 | } | 31 | } |
33 | 32 | ||
34 | void backlight_set(uint8_t level) { | 33 | bool led_update_kb(led_t led_state) { |
35 | b_led_set(level); | 34 | if (led_update_user(led_state)) { |
35 | writePin(D0, !led_state.num_lock); | ||
36 | writePin(D1, !led_state.caps_lock); | ||
37 | } | ||
38 | return true; | ||
36 | } | 39 | } |
37 | #endif | ||
diff --git a/keyboards/ymdk/bface/bface.c b/keyboards/ymdk/bface/bface.c index 8622fd523..e2810409a 100644 --- a/keyboards/ymdk/bface/bface.c +++ b/keyboards/ymdk/bface/bface.c | |||
@@ -16,26 +16,19 @@ | |||
16 | */ | 16 | */ |
17 | #include "quantum.h" | 17 | #include "quantum.h" |
18 | 18 | ||
19 | void keyboard_pre_init_kb(void) { | ||
20 | led_init_ports(); | ||
21 | keyboard_pre_init_user(); | ||
22 | } | ||
19 | 23 | ||
20 | void keyboard_pre_init_kb(void){ | 24 | void led_init_ports(void) { |
21 | //init the CAPS LOCK LED pin as an output | ||
22 | setPinOutput(D1); | 25 | setPinOutput(D1); |
23 | //init the Backlight Pin as an output | 26 | writePinHigh(D1); |
24 | setPinOutput(D4); | ||
25 | //call any user initialization code | ||
26 | keyboard_pre_init_user(); | ||
27 | } | 27 | } |
28 | 28 | ||
29 | void led_set_kb(uint8_t usb_led){ | 29 | bool led_update_kb(led_t led_state) { |
30 | //control the caps lock LED | 30 | if (led_update_user(led_state)) { |
31 | if(IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)){ | 31 | writePin(D1, !led_state.caps_lock); |
32 | //set led pin to high | ||
33 | writePinHigh(D1); | ||
34 | } else { | ||
35 | //set to low | ||
36 | writePinLow(D1); | ||
37 | } | 32 | } |
38 | //call any user LED functions | 33 | return true; |
39 | led_set_user(usb_led); | ||
40 | } | 34 | } |
41 | |||
diff --git a/keyboards/ymdk/bface/config.h b/keyboards/ymdk/bface/config.h index 2273b7e84..a8c8a2149 100644 --- a/keyboards/ymdk/bface/config.h +++ b/keyboards/ymdk/bface/config.h | |||
@@ -40,5 +40,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
40 | 40 | ||
41 | #define BACKLIGHT_PIN D4 | 41 | #define BACKLIGHT_PIN D4 |
42 | #define BACKLIGHT_LEVELS 6 | 42 | #define BACKLIGHT_LEVELS 6 |
43 | |||
44 | |||
diff --git a/keyboards/ymdk/bface/rules.mk b/keyboards/ymdk/bface/rules.mk index f6f026cf3..6320071ab 100644 --- a/keyboards/ymdk/bface/rules.mk +++ b/keyboards/ymdk/bface/rules.mk | |||
@@ -18,9 +18,6 @@ EXTRAKEY_ENABLE = yes | |||
18 | CONSOLE_ENABLE = no | 18 | CONSOLE_ENABLE = no |
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
21 | BACKLIGHT_CUSTOM_DRIVER = no | ||
22 | BACKLIGHT_BREATHING = no | ||
23 | RGBLIGHT_ENABLE = no | 21 | RGBLIGHT_ENABLE = no |
24 | RGBLIGHT_CUSTOM_DRIVER = no | ||
25 | 22 | ||
26 | OPT_DEFS = -DDEBUG_LEVEL=0 | 23 | OPT_DEFS = -DDEBUG_LEVEL=0 |
diff --git a/keyboards/ymdk_np21/backlight.c b/keyboards/ymdk_np21/backlight.c deleted file mode 100644 index fbd241fa9..000000000 --- a/keyboards/ymdk_np21/backlight.c +++ /dev/null | |||
@@ -1,213 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #include "backlight.h" | ||
7 | #include "quantum.h" | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | #include <avr/interrupt.h> | ||
11 | |||
12 | #include "backlight_custom.h" | ||
13 | #include "breathing_custom.h" | ||
14 | |||
15 | // DEBUG | ||
16 | #include <stdlib.h> | ||
17 | #include <stdio.h> | ||
18 | |||
19 | // Port D: digital pins of the AVR chipset | ||
20 | #define NUMLOCK_PORT (1 << 0) // D0 | ||
21 | #define CAPSLOCK_PORT (1 << 1) // D1 | ||
22 | #define BACKLIGHT_PORT (1 << 4) // D4 | ||
23 | #define SCROLLLOCK_PORT (1 << 6) // D6 | ||
24 | |||
25 | #define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 | ||
26 | #define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default | ||
27 | |||
28 | #define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask | ||
29 | |||
30 | #define PWM_MAX 0xFF | ||
31 | #define TIMER_TOP 255 // 8 bit PWM | ||
32 | |||
33 | extern backlight_config_t backlight_config; | ||
34 | |||
35 | /** | ||
36 | * References | ||
37 | * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation | ||
38 | * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b | ||
39 | * Timers: http://www.avrbeginners.net/architecture/timers/timers.html | ||
40 | * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/ | ||
41 | * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware | ||
42 | */ | ||
43 | |||
44 | // @Override | ||
45 | // turn LEDs on and off depending on USB caps/num/scroll lock states. | ||
46 | __attribute__ ((weak)) | ||
47 | void led_set_user(uint8_t usb_led) { | ||
48 | if (usb_led & (1 << USB_LED_NUM_LOCK)) { | ||
49 | // turn on | ||
50 | DDRD |= NUMLOCK_PORT; | ||
51 | PORTD |= NUMLOCK_PORT; | ||
52 | } else { | ||
53 | // turn off | ||
54 | DDRD &= ~NUMLOCK_PORT; | ||
55 | PORTD &= ~NUMLOCK_PORT; | ||
56 | } | ||
57 | |||
58 | if (usb_led & (1 << USB_LED_CAPS_LOCK)) { | ||
59 | DDRD |= CAPSLOCK_PORT; | ||
60 | PORTD |= CAPSLOCK_PORT; | ||
61 | } else { | ||
62 | DDRD &= ~CAPSLOCK_PORT; | ||
63 | PORTD &= ~CAPSLOCK_PORT; | ||
64 | } | ||
65 | |||
66 | if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { | ||
67 | DDRD |= SCROLLLOCK_PORT; | ||
68 | PORTD |= SCROLLLOCK_PORT; | ||
69 | } else { | ||
70 | DDRD &= ~SCROLLLOCK_PORT; | ||
71 | PORTD &= ~SCROLLLOCK_PORT; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | #ifdef BACKLIGHT_ENABLE | ||
76 | |||
77 | // sets up Timer 1 for 8-bit PWM | ||
78 | void timer1PWMSetup(void) { // NOTE ONLY CALL THIS ONCE | ||
79 | // default 8 bit mode | ||
80 | TCCR1A &= ~(1 << 1); // cbi(TCCR1A,PWM11); <- set PWM11 bit to HIGH | ||
81 | TCCR1A |= (1 << 0); // sbi(TCCR1A,PWM10); <- set PWM10 bit to LOW | ||
82 | |||
83 | // clear output compare value A | ||
84 | // outb(OCR1AH, 0); | ||
85 | // outb(OCR1AL, 0); | ||
86 | |||
87 | // clear output comparator registers for B | ||
88 | OCR1BH = 0; // outb(OCR1BH, 0); | ||
89 | OCR1BL = 0; // outb(OCR1BL, 0); | ||
90 | } | ||
91 | |||
92 | bool is_init = false; | ||
93 | void timer1Init(void) { | ||
94 | // timer1SetPrescaler(TIMER1PRESCALE) | ||
95 | // set to DIV/64 | ||
96 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER1PRESCALE; | ||
97 | |||
98 | // reset TCNT1 | ||
99 | TCNT1H = 0; // outb(TCNT1H, 0); | ||
100 | TCNT1L = 0; // outb(TCNT1L, 0); | ||
101 | |||
102 | // TOIE1: Timer Overflow Interrupt Enable (Timer 1); | ||
103 | TIMSK |= _BV(TOIE1); // sbi(TIMSK, TOIE1); | ||
104 | |||
105 | is_init = true; | ||
106 | } | ||
107 | |||
108 | void timer1UnInit(void) { | ||
109 | // set prescaler back to NONE | ||
110 | (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | 0x00; // TIMERRTC_CLK_STOP | ||
111 | |||
112 | // disable timer overflow interrupt | ||
113 | TIMSK &= ~_BV(TOIE1); // overflow bit? | ||
114 | |||
115 | setPWM(0); | ||
116 | |||
117 | is_init = false; | ||
118 | } | ||
119 | |||
120 | |||
121 | // handle TCNT1 overflow | ||
122 | //! Interrupt handler for tcnt1 overflow interrupt | ||
123 | ISR(TIMER1_OVF_vect, ISR_NOBLOCK) | ||
124 | { | ||
125 | // sei(); | ||
126 | // handle breathing here | ||
127 | #ifdef BACKLIGHT_BREATHING | ||
128 | if (is_breathing()) { | ||
129 | custom_breathing_handler(); | ||
130 | } | ||
131 | #endif | ||
132 | |||
133 | // TODO call user defined function | ||
134 | } | ||
135 | |||
136 | // enable timer 1 PWM | ||
137 | // timer1PWMBOn() | ||
138 | void timer1PWMBEnable(void) { | ||
139 | // turn on channel B (OC1B) PWM output | ||
140 | // set OC1B as non-inverted PWM | ||
141 | TCCR1A |= _BV(COM1B1); | ||
142 | TCCR1A &= ~_BV(COM1B0); | ||
143 | } | ||
144 | |||
145 | // disable timer 1 PWM | ||
146 | // timer1PWMBOff() | ||
147 | void timer1PWMBDisable(void) { | ||
148 | TCCR1A &= ~_BV(COM1B1); | ||
149 | TCCR1A &= ~_BV(COM1B0); | ||
150 | } | ||
151 | |||
152 | void enableBacklight(void) { | ||
153 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
154 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
155 | } | ||
156 | |||
157 | void disableBacklight(void) { | ||
158 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
159 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
160 | } | ||
161 | |||
162 | void startPWM(void) { | ||
163 | timer1Init(); | ||
164 | timer1PWMBEnable(); | ||
165 | enableBacklight(); | ||
166 | } | ||
167 | |||
168 | void stopPWM(void) { | ||
169 | timer1UnInit(); | ||
170 | disableBacklight(); | ||
171 | timer1PWMBDisable(); | ||
172 | } | ||
173 | |||
174 | void b_led_init_ports(void) { | ||
175 | /* turn backlight on/off depending on user preference */ | ||
176 | #if BACKLIGHT_ON_STATE == 0 | ||
177 | // DDRx register: sets the direction of Port D | ||
178 | // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input | ||
179 | PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low | ||
180 | #else | ||
181 | DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output | ||
182 | PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high | ||
183 | #endif | ||
184 | |||
185 | timer1PWMSetup(); | ||
186 | startPWM(); | ||
187 | |||
188 | #ifdef BACKLIGHT_BREATHING | ||
189 | breathing_enable(); | ||
190 | #endif | ||
191 | } | ||
192 | |||
193 | void b_led_set(uint8_t level) { | ||
194 | if (level > BACKLIGHT_LEVELS) { | ||
195 | level = BACKLIGHT_LEVELS; | ||
196 | } | ||
197 | |||
198 | setPWM((int)(TIMER_TOP * (float) level / BACKLIGHT_LEVELS)); | ||
199 | } | ||
200 | |||
201 | // called every matrix scan | ||
202 | void b_led_task(void) { | ||
203 | // do nothing for now | ||
204 | } | ||
205 | |||
206 | void setPWM(uint16_t xValue) { | ||
207 | if (xValue > TIMER_TOP) { | ||
208 | xValue = TIMER_TOP; | ||
209 | } | ||
210 | OCR1B = xValue; // timer1PWMBSet(xValue); | ||
211 | } | ||
212 | |||
213 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/ymdk_np21/backlight_custom.h b/keyboards/ymdk_np21/backlight_custom.h deleted file mode 100644 index 7210be840..000000000 --- a/keyboards/ymdk_np21/backlight_custom.h +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | /** | ||
2 | * Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Kenneth A. (github.com/krusli | krusli.me) | ||
4 | */ | ||
5 | |||
6 | #ifndef BACKLIGHT_CUSTOM_H | ||
7 | #define BACKLIGHT_CUSTOM_H | ||
8 | |||
9 | #include <avr/pgmspace.h> | ||
10 | void b_led_init_ports(void); | ||
11 | void b_led_set(uint8_t level); | ||
12 | void b_led_task(void); | ||
13 | void setPWM(uint16_t xValue); | ||
14 | |||
15 | #endif // BACKLIGHT_CUSTOM_H | ||
diff --git a/keyboards/ymdk_np21/breathing_custom.h b/keyboards/ymdk_np21/breathing_custom.h deleted file mode 100644 index 71416b1b4..000000000 --- a/keyboards/ymdk_np21/breathing_custom.h +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /** | ||
2 | * Breathing effect code for PS2AVRGB boards (ATMEGA32A) | ||
3 | * Works in conjunction with `backlight.c`. | ||
4 | * | ||
5 | * Code adapted from `quantum.c` to register with the existing TIMER1 overflow | ||
6 | * handler in `backlight.c` instead of setting up its own timer. | ||
7 | * Kenneth A. (github.com/krusli | krusli.me) | ||
8 | */ | ||
9 | |||
10 | #ifdef BACKLIGHT_ENABLE | ||
11 | #ifdef BACKLIGHT_BREATHING | ||
12 | |||
13 | #include "backlight_custom.h" | ||
14 | |||
15 | #ifndef BREATHING_PERIOD | ||
16 | #define BREATHING_PERIOD 6 | ||
17 | #endif | ||
18 | |||
19 | #define breathing_min() do {breathing_counter = 0;} while (0) | ||
20 | #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) | ||
21 | |||
22 | // TODO make this share code with quantum.c | ||
23 | |||
24 | #define BREATHING_NO_HALT 0 | ||
25 | #define BREATHING_HALT_OFF 1 | ||
26 | #define BREATHING_HALT_ON 2 | ||
27 | #define BREATHING_STEPS 128 | ||
28 | |||
29 | static uint8_t breathing_period = BREATHING_PERIOD; | ||
30 | static uint8_t breathing_halt = BREATHING_NO_HALT; | ||
31 | static uint16_t breathing_counter = 0; | ||
32 | |||
33 | static bool breathing = false; | ||
34 | |||
35 | bool is_breathing(void) { | ||
36 | return breathing; | ||
37 | } | ||
38 | |||
39 | // See http://jared.geek.nz/2013/feb/linear-led-pwm | ||
40 | static uint16_t cie_lightness(uint16_t v) { | ||
41 | if (v <= 5243) // if below 8% of max | ||
42 | return v / 9; // same as dividing by 900% | ||
43 | else { | ||
44 | uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare | ||
45 | // to get a useful result with integer division, we shift left in the expression above | ||
46 | // and revert what we've done again after squaring. | ||
47 | y = y * y * y >> 8; | ||
48 | if (y > 0xFFFFUL) // prevent overflow | ||
49 | return 0xFFFFU; | ||
50 | else | ||
51 | return (uint16_t) y; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void breathing_enable(void) { | ||
56 | breathing = true; | ||
57 | breathing_counter = 0; | ||
58 | breathing_halt = BREATHING_NO_HALT; | ||
59 | // interrupt already registered | ||
60 | } | ||
61 | |||
62 | void breathing_pulse(void) { | ||
63 | if (get_backlight_level() == 0) | ||
64 | breathing_min(); | ||
65 | else | ||
66 | breathing_max(); | ||
67 | breathing_halt = BREATHING_HALT_ON; | ||
68 | // breathing_interrupt_enable(); | ||
69 | breathing = true; | ||
70 | } | ||
71 | |||
72 | void breathing_disable(void) { | ||
73 | breathing = false; | ||
74 | // backlight_set(get_backlight_level()); | ||
75 | b_led_set(get_backlight_level()); // custom implementation of backlight_set() | ||
76 | } | ||
77 | |||
78 | void breathing_self_disable(void) | ||
79 | { | ||
80 | if (get_backlight_level() == 0) | ||
81 | breathing_halt = BREATHING_HALT_OFF; | ||
82 | else | ||
83 | breathing_halt = BREATHING_HALT_ON; | ||
84 | } | ||
85 | |||
86 | void breathing_toggle(void) { | ||
87 | if (is_breathing()) | ||
88 | breathing_disable(); | ||
89 | else | ||
90 | breathing_enable(); | ||
91 | } | ||
92 | |||
93 | void breathing_period_set(uint8_t value) | ||
94 | { | ||
95 | if (!value) | ||
96 | value = 1; | ||
97 | breathing_period = value; | ||
98 | } | ||
99 | |||
100 | void breathing_period_default(void) { | ||
101 | breathing_period_set(BREATHING_PERIOD); | ||
102 | } | ||
103 | |||
104 | void breathing_period_inc(void) | ||
105 | { | ||
106 | breathing_period_set(breathing_period+1); | ||
107 | } | ||
108 | |||
109 | void breathing_period_dec(void) | ||
110 | { | ||
111 | breathing_period_set(breathing_period-1); | ||
112 | } | ||
113 | |||
114 | /* To generate breathing curve in python: | ||
115 | * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] | ||
116 | */ | ||
117 | static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
118 | |||
119 | // Use this before the cie_lightness function. | ||
120 | static inline uint16_t scale_backlight(uint16_t v) { | ||
121 | return v / BACKLIGHT_LEVELS * get_backlight_level(); | ||
122 | } | ||
123 | |||
124 | void custom_breathing_handler(void) { | ||
125 | uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; | ||
126 | // resetting after one period to prevent ugly reset at overflow. | ||
127 | breathing_counter = (breathing_counter + 1) % (breathing_period * 244); | ||
128 | uint8_t index = breathing_counter / interval % BREATHING_STEPS; | ||
129 | |||
130 | if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || | ||
131 | ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) | ||
132 | { | ||
133 | // breathing_interrupt_disable(); | ||
134 | } | ||
135 | |||
136 | setPWM(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U))); | ||
137 | } | ||
138 | |||
139 | #endif // BACKLIGHT_BREATHING | ||
140 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/ymdk_np21/config.h b/keyboards/ymdk_np21/config.h index 60c527776..91478d903 100644 --- a/keyboards/ymdk_np21/config.h +++ b/keyboards/ymdk_np21/config.h | |||
@@ -15,10 +15,9 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "config_common.h" | 18 | #pragma once |
19 | 19 | ||
20 | #ifndef CONFIG_H | 20 | #include "config_common.h" |
21 | #define CONFIG_H | ||
22 | 21 | ||
23 | #define VENDOR_ID 0x20A0 | 22 | #define VENDOR_ID 0x20A0 |
24 | #define PRODUCT_ID 0x422D | 23 | #define PRODUCT_ID 0x422D |
@@ -37,8 +36,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | /* COL2ROW or ROW2COL */ | 36 | /* COL2ROW or ROW2COL */ |
38 | #define DIODE_DIRECTION COL2ROW | 37 | #define DIODE_DIRECTION COL2ROW |
39 | 38 | ||
39 | #define BACKLIGHT_PIN D4 | ||
40 | #define BACKLIGHT_LEVELS 12 | 40 | #define BACKLIGHT_LEVELS 12 |
41 | // #define BACKLIGHT_BREATHING // works, but BL_TOGG might not work | 41 | #define BACKLIGHT_BREATHING |
42 | 42 | ||
43 | #define TAPPING_TOGGLE 3 | 43 | #define TAPPING_TOGGLE 3 |
44 | 44 | ||
@@ -52,5 +52,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
52 | #define RGBLED_NUM 5 | 52 | #define RGBLED_NUM 5 |
53 | #define RGB_DI_PIN E2 // NOTE: for PS2AVRGB boards, underglow commands are sent via I2C to 0xB0. | 53 | #define RGB_DI_PIN E2 // NOTE: for PS2AVRGB boards, underglow commands are sent via I2C to 0xB0. |
54 | #define RGBLIGHT_ANIMATIONS | 54 | #define RGBLIGHT_ANIMATIONS |
55 | |||
56 | #endif | ||
diff --git a/keyboards/ymdk_np21/rules.mk b/keyboards/ymdk_np21/rules.mk index 772bee928..237386bce 100644 --- a/keyboards/ymdk_np21/rules.mk +++ b/keyboards/ymdk_np21/rules.mk | |||
@@ -19,7 +19,6 @@ CONSOLE_ENABLE = no | |||
19 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
20 | 20 | ||
21 | BACKLIGHT_ENABLE = yes | 21 | BACKLIGHT_ENABLE = yes |
22 | BACKLIGHT_CUSTOM_DRIVER = yes | ||
23 | 22 | ||
24 | RGBLIGHT_ENABLE = yes | 23 | RGBLIGHT_ENABLE = yes |
25 | WS2812_DRIVER = i2c | 24 | WS2812_DRIVER = i2c |
@@ -30,5 +29,3 @@ KEY_LOCK_ENABLE = yes | |||
30 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 29 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
31 | 30 | ||
32 | OPT_DEFS = -DDEBUG_LEVEL=0 | 31 | OPT_DEFS = -DDEBUG_LEVEL=0 |
33 | |||
34 | SRC = backlight.c | ||
diff --git a/keyboards/ymdk_np21/ymdk_np21.c b/keyboards/ymdk_np21/ymdk_np21.c index f2b3d46da..5bf159758 100644 --- a/keyboards/ymdk_np21/ymdk_np21.c +++ b/keyboards/ymdk_np21/ymdk_np21.c | |||
@@ -18,20 +18,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | 18 | ||
19 | #include "ymdk_np21.h" | 19 | #include "ymdk_np21.h" |
20 | 20 | ||
21 | #include "backlight.h" | 21 | void keyboard_pre_init_kb(void) { |
22 | #include "backlight_custom.h" | 22 | led_init_ports(); |
23 | 23 | keyboard_pre_init_user(); | |
24 | #ifdef BACKLIGHT_ENABLE | ||
25 | /// Overrides functions in `quantum.c` | ||
26 | void backlight_init_ports(void) { | ||
27 | b_led_init_ports(); | ||
28 | } | 24 | } |
29 | 25 | ||
30 | void backlight_task(void) { | 26 | void led_init_ports(void) { |
31 | b_led_task(); | 27 | setPinOutput(D0); |
28 | writePinHigh(D0); | ||
32 | } | 29 | } |
33 | 30 | ||
34 | void backlight_set(uint8_t level) { | 31 | bool led_update_kb(led_t led_state) { |
35 | b_led_set(level); | 32 | if (led_update_user(led_state)) { |
33 | writePin(D0, !led_state.num_lock); | ||
34 | } | ||
35 | return true; | ||
36 | } | 36 | } |
37 | #endif | ||