1 /* Copyright 2018 Jason Williams (Wilba)
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 #include "wt_mono_backlight.h"
18 #include "drivers/avr/i2c_master.h"
19 #include "drivers/issi/is31fl3736.h"
21 #include <avr/interrupt.h>
23 #define ISSI_ADDR_DEFAULT 0x50
25 bool g_suspend_state = false;
27 // Global tick at 20 Hz
29 uint8_t g_config_effect_speed = 0;
30 uint8_t g_config_brightness = 255;
32 void backlight_init_drivers(void)
36 IS31FL3736_init( ISSI_ADDR_DEFAULT );
38 for ( uint8_t index = 0; index < 96; index++ ) {
39 IS31FL3736_mono_set_led_control_register( index, true );
41 IS31FL3736_update_led_control_registers( ISSI_ADDR_DEFAULT, 0x00 );
45 // This is (F_CPU/1024) / 20 Hz
48 #define TIMER3_TOP 781
50 void backlight_timer_init(void)
52 static uint8_t backlight_timer_is_init = 0;
53 if ( backlight_timer_is_init ) {
56 backlight_timer_is_init = 1;
59 TCCR3B = _BV(WGM32) | // CTC mode OCR3A as TOP
60 _BV(CS32) | _BV(CS30); // prescale by /1024
65 OCR3AH = (TIMER3_TOP >> 8) & 0xff;
66 OCR3AL = TIMER3_TOP & 0xff;
70 void backlight_timer_enable(void)
72 TIMSK3 |= _BV(OCIE3A);
75 void backlight_timer_disable(void)
77 TIMSK3 &= ~_BV(OCIE3A);
80 void backlight_set_suspend_state(bool state)
82 g_suspend_state = state;
85 void backlight_effect_cycle_all(void)
87 uint8_t offset = ( g_tick << g_config_effect_speed ) & 0xFF;
89 backlight_set_brightness_all( offset );
92 ISR(TIMER3_COMPA_vect)
94 // delay 1 second before driving LEDs or doing anything else
95 static uint8_t startup_tick = 0;
96 if ( startup_tick < 20 ) {
103 //backlight_effect_cycle_all();
104 backlight_set_brightness_all( 255 );
107 void backlight_update_pwm_buffers(void)
109 IS31FL3736_update_pwm_buffers(ISSI_ADDR_DEFAULT,0x00);
112 void backlight_set_brightness_all( uint8_t value )
114 IS31FL3736_mono_set_brightness_all( value );