]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
adds soft pwm for non-timed ports
authorJack Humbert <jack.humb@gmail.com>
Sun, 12 Feb 2017 16:29:42 +0000 (11:29 -0500)
committerJack Humbert <jack.humb@gmail.com>
Sun, 12 Feb 2017 16:29:42 +0000 (11:29 -0500)
keyboards/planck/rules.mk
keyboards/preonic/rules.mk
quantum/quantum.c
quantum/quantum.h

index 4423d422f6f5a6f92b531e840495ecd55672a86b..6776062f6db0f97b8cafec8d628b013757437611 100644 (file)
@@ -56,13 +56,13 @@ EXTRAKEY_ENABLE ?= yes       # Audio control and System control(+450)
 CONSOLE_ENABLE ?= no         # Console for debug(+400)
 COMMAND_ENABLE ?= no        # Commands for debug and configuration
 NKRO_ENABLE ?= no            # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
-BACKLIGHT_ENABLE ?= no      # Enable keyboard backlight functionality
+BACKLIGHT_ENABLE ?= yes      # Enable keyboard backlight functionality
 MIDI_ENABLE ?= yes            # MIDI controls
 AUDIO_ENABLE ?= yes           # Audio output on port C6
 UNICODE_ENABLE ?= no         # Unicode
 BLUETOOTH_ENABLE ?= no       # Enable Bluetooth with the Adafruit EZ-Key HID
 RGBLIGHT_ENABLE ?= no        # Enable WS2812 RGB underlight.
-API_SYSEX_ENABLE = yes
+API_SYSEX_ENABLE = no
 
 # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
 SLEEP_LED_ENABLE ?= no    # Breathing sleep LED during USB suspend
index 62473e3564a994a95f876c79196df2b202e52078..6be5b55bcd2917b3e27a2638b2948c58b1a792a0 100644 (file)
@@ -58,13 +58,13 @@ EXTRAKEY_ENABLE ?= yes       # Audio control and System control(+450)
 CONSOLE_ENABLE ?= no         # Console for debug(+400)
 COMMAND_ENABLE ?= no        # Commands for debug and configuration
 NKRO_ENABLE ?= no            # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
-BACKLIGHT_ENABLE ?= no      # Enable keyboard backlight functionality
+BACKLIGHT_ENABLE ?= yes      # Enable keyboard backlight functionality
 MIDI_ENABLE ?= yes            # MIDI controls
 AUDIO_ENABLE ?= yes           # Audio output on port C6
 UNICODE_ENABLE ?= no         # Unicode
 BLUETOOTH_ENABLE ?= no       # Enable Bluetooth with the Adafruit EZ-Key HID
 RGBLIGHT_ENABLE ?= no        # Enable WS2812 RGB underlight.
-API_SYSEX_ENABLE ?= yes
+API_SYSEX_ENABLE ?= no
 
 # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
 SLEEP_LED_ENABLE ?= no    # Breathing sleep LED during USB suspend
\ No newline at end of file
index 45ea8cb73c0553452aa9e1fc4a29e082a85ad4a2..95f06d95d44a313f5fd81f72c2fe5d1cf5b71d22 100644 (file)
@@ -7,6 +7,9 @@
 #define TAPPING_TERM 200
 #endif
 
+#include "backlight.h"
+extern backlight_config_t backlight_config;
+
 static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
   switch (code) {
   case QK_MODS ... QK_MODS_MAX:
@@ -577,6 +580,10 @@ void matrix_scan_quantum() {
     matrix_scan_combo();
   #endif
 
+  #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
+    backlight_task();
+  #endif
+
   matrix_scan_kb();
 }
 
@@ -644,13 +651,13 @@ __attribute__ ((weak))
 void backlight_set(uint8_t level)
 {
   // Prevent backlight blink on lowest level
-  #if BACKLIGHT_ON_STATE == 0
-    // PORTx &= ~n
-    _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
-  #else
-    // PORTx |= n
-    _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
-  #endif
+  // #if BACKLIGHT_ON_STATE == 0
+  //   // PORTx &= ~n
+  //   _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
+  // #else
+  //   // PORTx |= n
+  //   _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
+  // #endif
 
   if ( level == 0 ) {
     #ifndef NO_BACKLIGHT_CLOCK
@@ -658,13 +665,13 @@ void backlight_set(uint8_t level)
       TCCR1A &= ~(_BV(COM1x1));
       OCR1x = 0x0;
     #else
-      #if BACKLIGHT_ON_STATE == 0
-        // PORTx |= n
-        _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
-      #else
-        // PORTx &= ~n
-        _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
-      #endif
+      // #if BACKLIGHT_ON_STATE == 0
+      //   // PORTx |= n
+      //   _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
+      // #else
+      //   // PORTx &= ~n
+      //   _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
+      // #endif
     #endif
   } 
   #ifndef NO_BACKLIGHT_CLOCK
@@ -687,6 +694,30 @@ void backlight_set(uint8_t level)
   #endif
 }
 
+uint8_t backlight_tick = 0;
+
+void backlight_task(void) {
+  #ifdef NO_BACKLIGHT_CLOCK
+  if ((0xFFFF >> ((BACKLIGHT_LEVELS - backlight_config.level) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) { 
+    #if BACKLIGHT_ON_STATE == 0
+      // PORTx &= ~n
+      _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
+    #else
+      // PORTx |= n
+      _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
+    #endif
+  } else {
+    #if BACKLIGHT_ON_STATE == 0
+      // PORTx |= n
+      _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
+    #else
+      // PORTx &= ~n
+      _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
+    #endif
+  }
+  backlight_tick = (backlight_tick + 1) % 16;
+  #endif
+}
 
 #ifdef BACKLIGHT_BREATHING
 
index 18f072189d7b5f5a3ff3bdd9be325e6e8d322ebb..2470d8c7da57bea7f5041530dc7a450af85ca27c 100644 (file)
@@ -95,6 +95,7 @@ void unregister_code16 (uint16_t code);
 
 #ifdef BACKLIGHT_ENABLE
 void backlight_init_ports(void);
+void backlight_task(void);
 
 #ifdef BACKLIGHT_BREATHING
 void breathing_enable(void);