diff options
| author | Ralf Schmitt <ralf@bunkertor.net> | 2014-08-23 17:16:16 +0200 |
|---|---|---|
| committer | Ralf Schmitt <ralf@bunkertor.net> | 2014-08-24 16:31:12 +0200 |
| commit | af19f56ec98d27ab939b024effefcbebbab8f125 (patch) | |
| tree | a36580e1181affb90423987063d423a498479584 /keyboard/lightpad/backlight.c | |
| parent | 79840c678e13f9a737f80048bc3b9c9c55e3fc77 (diff) | |
| download | qmk_firmware-af19f56ec98d27ab939b024effefcbebbab8f125.tar.gz qmk_firmware-af19f56ec98d27ab939b024effefcbebbab8f125.zip | |
Support for Lightpad keypad
Diffstat (limited to 'keyboard/lightpad/backlight.c')
| -rw-r--r-- | keyboard/lightpad/backlight.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/keyboard/lightpad/backlight.c b/keyboard/lightpad/backlight.c new file mode 100644 index 000000000..693c566fc --- /dev/null +++ b/keyboard/lightpad/backlight.c | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | 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/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <avr/io.h> | ||
| 19 | #include "backlight.h" | ||
| 20 | |||
| 21 | /* Backlight pin configuration | ||
| 22 | * | ||
| 23 | * FN1 PB0 (low) | ||
| 24 | * FN2 PB5 (low) | ||
| 25 | * FN3 PB4 (low) | ||
| 26 | * FN4 PD7 (low) | ||
| 27 | * REAR PD6 (high) | ||
| 28 | * NUMPAD PB2 (high) | ||
| 29 | * NUMLOCK PB1 (low) | ||
| 30 | */ | ||
| 31 | void backlight_init_ports() { | ||
| 32 | DDRB |= (1<<0) | (1<<1) | (1<<2) | (1<<4) | (1<<5); | ||
| 33 | DDRD |= (1<<6) | (1<<7); | ||
| 34 | |||
| 35 | backlight_disable_numlock(); | ||
| 36 | } | ||
| 37 | |||
| 38 | void backlight_set(uint8_t level) { | ||
| 39 | (level & BACKLIGHT_FN1) ? backlight_enable_fn1() : backlight_disable_fn1(); | ||
| 40 | (level & BACKLIGHT_FN2) ? backlight_enable_fn2() : backlight_disable_fn2(); | ||
| 41 | (level & BACKLIGHT_FN3) ? backlight_enable_fn3() : backlight_disable_fn3(); | ||
| 42 | (level & BACKLIGHT_FN4) ? backlight_enable_fn4() : backlight_disable_fn4(); | ||
| 43 | (level & BACKLIGHT_NUMPAD) ? backlight_enable_numpad() : backlight_disable_numpad(); | ||
| 44 | (level & BACKLIGHT_REAR) ? backlight_enable_rear() : backlight_disable_rear(); | ||
| 45 | } | ||
| 46 | |||
| 47 | void backlight_enable_fn1() { | ||
| 48 | PORTB &= ~(1<<0); | ||
| 49 | } | ||
| 50 | |||
| 51 | void backlight_disable_fn1() { | ||
| 52 | PORTB |= (1<<0); | ||
| 53 | } | ||
| 54 | |||
| 55 | void backlight_invert_fn1() { | ||
| 56 | PORTB ^= (1<<0); | ||
| 57 | } | ||
| 58 | |||
| 59 | void backlight_enable_fn2() { | ||
| 60 | PORTB &= ~(1<<5); | ||
| 61 | } | ||
| 62 | |||
| 63 | void backlight_disable_fn2() { | ||
| 64 | PORTB |= (1<<5); | ||
| 65 | } | ||
| 66 | |||
| 67 | void backlight_invert_fn2() { | ||
| 68 | PORTB ^= (1<<5); | ||
| 69 | } | ||
| 70 | |||
| 71 | void backlight_enable_fn3() { | ||
| 72 | PORTB &= ~(1<<4); | ||
| 73 | } | ||
| 74 | |||
| 75 | void backlight_disable_fn3() { | ||
| 76 | PORTB |= (1<<4); | ||
| 77 | } | ||
| 78 | |||
| 79 | void backlight_invert_fn3() { | ||
| 80 | PORTB ^= (1<<4); | ||
| 81 | } | ||
| 82 | |||
| 83 | void backlight_enable_fn4() { | ||
| 84 | PORTD &= ~(1<<7); | ||
| 85 | } | ||
| 86 | |||
| 87 | void backlight_disable_fn4() { | ||
| 88 | PORTD |= (1<<7); | ||
| 89 | } | ||
| 90 | |||
| 91 | void backlight_invert_fn4() { | ||
| 92 | PORTD ^= (1<<7); | ||
| 93 | } | ||
| 94 | |||
| 95 | void backlight_enable_numpad() { | ||
| 96 | PORTB |= (1<<2); | ||
| 97 | } | ||
| 98 | |||
| 99 | void backlight_disable_numpad() { | ||
| 100 | PORTB &= ~(1<<2); | ||
| 101 | } | ||
| 102 | |||
| 103 | void backlight_invert_numpad() { | ||
| 104 | PORTB ^= (1<<2); | ||
| 105 | } | ||
| 106 | |||
| 107 | void backlight_enable_numlock() { | ||
| 108 | PORTB &= ~(1<<1); | ||
| 109 | } | ||
| 110 | |||
| 111 | void backlight_disable_numlock() { | ||
| 112 | PORTB |= (1<<1); | ||
| 113 | } | ||
| 114 | |||
| 115 | void backlight_invert_numlock() { | ||
| 116 | PORTB ^= (1<<1); | ||
| 117 | } | ||
| 118 | |||
| 119 | void backlight_enable_rear() { | ||
| 120 | PORTD |= (1<<6); | ||
| 121 | } | ||
| 122 | |||
| 123 | void backlight_disable_rear() { | ||
| 124 | PORTD &= ~(1<<6); | ||
| 125 | } | ||
| 126 | |||
| 127 | void backlight_invert_rear() { | ||
| 128 | PORTD ^= (1<<6); | ||
| 129 | } | ||
