1 /* Copyright 2017 Sebastian Kaim
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.
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.
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/>.
17 #ifdef BACKLIGHT_ENABLE
19 #include "backlight_ps2avrGB.h"
20 #define sbi(reg,bit) reg |= (_BV(bit))
21 #define cbi(reg,bit) reg &= (~_BV(bit))
27 void backlight_init_ports(void)
29 #if BACKLIGHT_ON_STATE == 0
36 // this bitmagic is sourced from the original firmware
37 /*TCCR1B = ((TCCR1B & ~0x07) | 0x03);
49 TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
50 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
55 void backlight_set(uint8_t level)
62 /*uint8_t pwm = get_pwm_for_brightness(level);
63 set_backlight_pwm(pwm);
64 TCCR1A |= _BV(COM1x1);
65 OCR1x = (level >= 2) ? 0xFFFF : 0x00FF;*/
70 uint8_t get_pwm_for_brightness(uint8_t level)
72 // we need to cast up here to allow multiplication with 0xFF. We could also use floats, but this is probably a lot faster.
73 uint16_t brightness = (uint16_t)level * (uint16_t)PWM_MAX / (uint16_t)BACKLIGHT_LEVELS;
74 return (uint8_t)brightness;
77 void backlight_on(void)
79 //_SFR_IO8(0x12) |= _BV(0x4);
80 LED_PIN |= BACKLIGHT_PORT_NUM;
83 void backlight_off(void)
85 //_SFR_IO8(0x12) &= ~_BV(0x4);
86 LED_PIN &= ~BACKLIGHT_PORT_NUM;
89 void set_backlight_pwm(uint8_t level) {
90 // this does not work (yet)
94 #endif // BACKLIGHT_ENABLE