aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c92
1 files changed, 67 insertions, 25 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 4a6d0355f..62d9ef923 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -1,3 +1,19 @@
1/* Copyright 2016-2017 Jack Humbert
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
1#include "quantum.h" 17#include "quantum.h"
2#ifdef PROTOCOL_LUFA 18#ifdef PROTOCOL_LUFA
3#include "outputselect.h" 19#include "outputselect.h"
@@ -7,6 +23,9 @@
7#define TAPPING_TERM 200 23#define TAPPING_TERM 200
8#endif 24#endif
9 25
26#include "backlight.h"
27extern backlight_config_t backlight_config;
28
10#ifdef FAUXCLICKY_ENABLE 29#ifdef FAUXCLICKY_ENABLE
11#include "fauxclicky.h" 30#include "fauxclicky.h"
12#endif 31#endif
@@ -95,8 +114,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
95 114
96void reset_keyboard(void) { 115void reset_keyboard(void) {
97 clear_keyboard(); 116 clear_keyboard();
98#ifdef AUDIO_ENABLE 117#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_ENABLE_BASIC))
99 stop_all_notes(); 118 music_all_notes_off();
100 shutdown_user(); 119 shutdown_user();
101#endif 120#endif
102 wait_ms(250); 121 wait_ms(250);
@@ -150,10 +169,13 @@ bool process_record_quantum(keyrecord_t *record) {
150 169
151 if (!( 170 if (!(
152 process_record_kb(keycode, record) && 171 process_record_kb(keycode, record) &&
153 #ifdef MIDI_ENABLE 172 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
154 process_midi(keycode, record) && 173 process_midi(keycode, record) &&
155 #endif 174 #endif
156 #ifdef AUDIO_ENABLE 175 #ifdef AUDIO_ENABLE
176 process_audio(keycode, record) &&
177 #endif
178 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
157 process_music(keycode, record) && 179 process_music(keycode, record) &&
158 #endif 180 #endif
159 #ifdef TAP_DANCE_ENABLE 181 #ifdef TAP_DANCE_ENABLE
@@ -291,14 +313,6 @@ bool process_record_quantum(keyrecord_t *record) {
291 return false; 313 return false;
292 break; 314 break;
293 #endif 315 #endif
294 #ifdef ADAFRUIT_BLE_ENABLE
295 case OUT_BLE:
296 if (record->event.pressed) {
297 set_output(OUTPUT_ADAFRUIT_BLE);
298 }
299 return false;
300 break;
301 #endif
302 #endif 316 #endif
303 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: 317 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO:
304 if (record->event.pressed) { 318 if (record->event.pressed) {
@@ -601,6 +615,10 @@ void matrix_scan_quantum() {
601 matrix_scan_combo(); 615 matrix_scan_combo();
602 #endif 616 #endif
603 617
618 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
619 backlight_task();
620 #endif
621
604 matrix_scan_kb(); 622 matrix_scan_kb();
605} 623}
606 624
@@ -668,13 +686,13 @@ __attribute__ ((weak))
668void backlight_set(uint8_t level) 686void backlight_set(uint8_t level)
669{ 687{
670 // Prevent backlight blink on lowest level 688 // Prevent backlight blink on lowest level
671 #if BACKLIGHT_ON_STATE == 0 689 // #if BACKLIGHT_ON_STATE == 0
672 // PORTx &= ~n 690 // // PORTx &= ~n
673 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); 691 // _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
674 #else 692 // #else
675 // PORTx |= n 693 // // PORTx |= n
676 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); 694 // _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
677 #endif 695 // #endif
678 696
679 if ( level == 0 ) { 697 if ( level == 0 ) {
680 #ifndef NO_BACKLIGHT_CLOCK 698 #ifndef NO_BACKLIGHT_CLOCK
@@ -682,13 +700,13 @@ void backlight_set(uint8_t level)
682 TCCR1A &= ~(_BV(COM1x1)); 700 TCCR1A &= ~(_BV(COM1x1));
683 OCR1x = 0x0; 701 OCR1x = 0x0;
684 #else 702 #else
685 #if BACKLIGHT_ON_STATE == 0 703 // #if BACKLIGHT_ON_STATE == 0
686 // PORTx |= n 704 // // PORTx |= n
687 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); 705 // _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
688 #else 706 // #else
689 // PORTx &= ~n 707 // // PORTx &= ~n
690 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); 708 // _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
691 #endif 709 // #endif
692 #endif 710 #endif
693 } 711 }
694 #ifndef NO_BACKLIGHT_CLOCK 712 #ifndef NO_BACKLIGHT_CLOCK
@@ -711,6 +729,30 @@ void backlight_set(uint8_t level)
711 #endif 729 #endif
712} 730}
713 731
732uint8_t backlight_tick = 0;
733
734void backlight_task(void) {
735 #ifdef NO_BACKLIGHT_CLOCK
736 if ((0xFFFF >> ((BACKLIGHT_LEVELS - backlight_config.level) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
737 #if BACKLIGHT_ON_STATE == 0
738 // PORTx &= ~n
739 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
740 #else
741 // PORTx |= n
742 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
743 #endif
744 } else {
745 #if BACKLIGHT_ON_STATE == 0
746 // PORTx |= n
747 _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
748 #else
749 // PORTx &= ~n
750 _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
751 #endif
752 }
753 backlight_tick = (backlight_tick + 1) % 16;
754 #endif
755}
714 756
715#ifdef BACKLIGHT_BREATHING 757#ifdef BACKLIGHT_BREATHING
716 758