v1.c (1970B)
1 /* Copyright 2017 MechMerlin <mechmerlin@gmail.com> 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 #include "quantum.h" 17 18 enum BACKLIGHT_AREAS { 19 BACKLIGHT_ALPHA = 0b0000001, 20 BACKLIGHT_EXTRA = 0b0000010, 21 BACKLIGHT_MODNUM = 0b0000100, 22 BACKLIGHT_FROW = 0b0001000, 23 BACKLIGHT_RGB = 0b0010000, 24 BACKLIGHT_RGBRED = 0b0010000, 25 BACKLIGHT_RGBGREEN = 0b0100000, 26 BACKLIGHT_RGBBLUE = 0b1000000, 27 BACKLIGHT_SWITCH = 0b0001111 28 }; 29 30 uint8_t backlight_os_state = 0; 31 uint32_t backlight_layer_state = 0; 32 33 void backlight_set(uint8_t level) { 34 level & BACKLIGHT_ALPHA ? (PORTB |= 0b00000010) : (PORTB &= ~0b00000010); 35 level & BACKLIGHT_EXTRA ? (PORTB |= 0b00000100) : (PORTB &= ~0b00000100); 36 level & BACKLIGHT_MODNUM ? (PORTB |= 0b00001000) : (PORTB &= ~0b00001000); 37 level & BACKLIGHT_FROW ? (PORTE |= 0b01000000) : (PORTE &= ~0b01000000); 38 level & BACKLIGHT_RGBRED ? (PORTD |= 0b01000000) : (PORTD &= ~0b01000000); 39 level & BACKLIGHT_RGBGREEN ? (PORTD |= 0b10000000) : (PORTD &= ~0b10000000); 40 level & BACKLIGHT_RGBBLUE ? (PORTD |= 0b00010000) : (PORTD &= ~0b00010000); 41 } 42 43 bool led_update_kb(led_t led_state) { 44 bool res = led_update_user(led_state); 45 if(res) { 46 backlight_os_state & 2 ? (PORTB &= ~0b00000001) : (PORTB |= 0b00000001); 47 backlight_os_state & 4 ? (PORTB &= ~0b00010000) : (PORTB |= 0b00010000); 48 } 49 return res; 50 }