]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Add support for 328P hardware backlight on B1/B2 (#6776)
authorfauxpark <fauxpark@gmail.com>
Sat, 21 Sep 2019 05:11:15 +0000 (15:11 +1000)
committerDrashna Jaelre <drashna@live.com>
Sat, 21 Sep 2019 05:11:15 +0000 (22:11 -0700)
docs/feature_backlight.md
quantum/quantum.c

index 690eb821576fd899fb8e4fb4dc676d6d1bcd6b3d..556da73859b376566a256c340036bca28af9c6e6 100644 (file)
@@ -32,16 +32,18 @@ This feature is distinct from both the [RGB underglow](feature_rgblight.md) and
 
 Hardware PWM is supported according to the following table:
 
-|Backlight Pin|AT90USB64/128|ATmega16/32U4|ATmega16/32U2|ATmega32A|
-|-------------|-------------|-------------|-------------|---------|
-|`B5`         |Timer 1      |Timer 1      |             |         |
-|`B6`         |Timer 1      |Timer 1      |             |         |
-|`B7`         |Timer 1      |Timer 1      |Timer 1      |         |
-|`C4`         |Timer 3      |             |             |         |
-|`C5`         |Timer 3      |             |Timer 1      |         |
-|`C6`         |Timer 3      |Timer 3      |Timer 1      |         |
-|`D4`         |             |             |             |Timer 1  |
-|`D5`         |             |             |             |Timer 1  |
+|Backlight Pin|AT90USB64/128|ATmega16/32U4|ATmega16/32U2|ATmega32A|ATmega328P|
+|-------------|-------------|-------------|-------------|---------|----------|
+|`B1`         |             |             |             |         |Timer 1   |
+|`B2`         |             |             |             |         |Timer 1   |
+|`B5`         |Timer 1      |Timer 1      |             |         |          |
+|`B6`         |Timer 1      |Timer 1      |             |         |          |
+|`B7`         |Timer 1      |Timer 1      |Timer 1      |         |          |
+|`C4`         |Timer 3      |             |             |         |          |
+|`C5`         |Timer 3      |             |Timer 1      |         |          |
+|`C6`         |Timer 3      |Timer 3      |Timer 1      |         |          |
+|`D4`         |             |             |             |Timer 1  |          |
+|`D5`         |             |             |             |Timer 1  |          |
 
 All other pins will use software PWM. If the [Audio](feature_audio.md) feature is disabled or only using one timer, the backlight PWM can be triggered by a hardware timer:
 
index 85a03377f3cce5e3a5a7cfff9f9197ee809ecd94..ec80fa557f987e734eadd370c0e0df8967295c87 100644 (file)
@@ -1104,6 +1104,22 @@ void matrix_scan_quantum() {
 #            define COMxx1 COM1A1
 #            define OCRxx OCR1A
 #        endif
+#    elif defined(__AVR_ATmega328P__) && (BACKLIGHT_PIN == B1 || BACKLIGHT_PIN == B2)
+#        define HARDWARE_PWM
+#        define ICRx ICR1
+#        define TCCRxA TCCR1A
+#        define TCCRxB TCCR1B
+#        define TIMERx_OVF_vect TIMER1_OVF_vect
+#        define TIMSKx TIMSK1
+#        define TOIEx TOIE1
+
+#        if BACKLIGHT_PIN == B1
+#            define COMxx1 COM1A1
+#            define OCRxx OCR1A
+#        elif BACKLIGHT_PIN == B2
+#            define COMxx1 COM1B1
+#            define OCRxx OCR1B
+#        endif
 #    else
 #        if !defined(BACKLIGHT_CUSTOM_DRIVER)
 #            if !defined(B5_AUDIO) && !defined(B6_AUDIO) && !defined(B7_AUDIO)