1 /* Copyright 2017 REPLACE_WITH_YOUR_NAME
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/>.
16 #include "v60_type_r.h"
20 #include <avr/pgmspace.h>
22 #include "action_layer.h"
25 // if we've got an RGB underglow!
27 #define SOFTPWM_LED_TIMER_TOP F_CPU/(256*64)
29 extern rgblight_config_t rgblight_config;
30 static uint8_t softpwm_buff[3] = {0};
32 void matrix_init_user(void) {
36 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
37 uint8_t r = led[0].r, g = led[0].g, b = led[0].b;
40 if (record->event.pressed) {
45 rgblight_setrgb(r, g, b);
50 if (record->event.pressed) {
55 rgblight_setrgb(r, g, b);
60 if (record->event.pressed) {
65 rgblight_setrgb(r, g, b);
70 if (record->event.pressed) {
75 rgblight_setrgb(r, g, b);
80 if (record->event.pressed) {
85 rgblight_setrgb(r, g, b);
90 if (record->event.pressed) {
95 rgblight_setrgb(r, g, b);
105 void rgb_timer_init(void) {
108 TCCR1B |= (1<<WGM12);
109 /* Clock selelct: clk/8 */
114 OCR1AH = (SOFTPWM_LED_TIMER_TOP >> 8) & 0xff;
115 OCR1AL = SOFTPWM_LED_TIMER_TOP & 0xff;
118 // Enable the compare match interrupt on timer 1
119 TIMSK1 |= (1<<OCIE1A);
122 void rgb_init(void) {
123 DDRF |= (1<<PF6 | 1<<PF5 | 1<<PF4);
124 PORTF |= (1<<PF6 | 1<<PF5 | 1<<PF4);
129 void set_rgb_pin_on(uint8_t pin) {
133 void set_rgb_pin_off(uint8_t pin) {
137 void rgblight_set(void) {
138 // xprintf("Setting RGB underglow\n");
139 if (!rgblight_config.enable) {
143 set_rgb_pin_off(RGB_RED_PIN);
144 set_rgb_pin_off(RGB_GREEN_PIN);
145 set_rgb_pin_off(RGB_BLUE_PIN);
148 // //xprintf("Red: %u, Green: %u, Blue: %u\n", led[0].r, led[0].g, led[0].b);
151 ISR(TIMER1_COMPA_vect)
153 static uint8_t pwm = 0;
158 if (softpwm_buff[0]) {
159 set_rgb_pin_on(RGB_RED_PIN);
160 softpwm_buff[0] = led[0].r;
163 if (softpwm_buff[1]) {
164 set_rgb_pin_on(RGB_GREEN_PIN);
165 softpwm_buff[1] = led[0].g;
168 if (softpwm_buff[2]) {
169 set_rgb_pin_on(RGB_BLUE_PIN);
170 softpwm_buff[2] = led[0].b;
175 if (pwm == softpwm_buff[0]) {
176 set_rgb_pin_off(RGB_RED_PIN);
177 softpwm_buff[0] = led[0].r;
181 if (pwm == softpwm_buff[1]) {
182 set_rgb_pin_off(RGB_GREEN_PIN);
183 softpwm_buff[1] = led[0].g;
186 if (pwm == softpwm_buff[2]) {
187 set_rgb_pin_off(RGB_BLUE_PIN);
188 softpwm_buff[2] = led[0].b;
193 void matrix_init_user(void) {
196 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
200 #endif // V60_POLESTAR
202 // we need these functions for both versions
203 void led_set_kb(uint8_t usb_led) {
204 // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
206 led_set_user(usb_led);
209 void matrix_scan_user(void) {
212 void matrix_init_kb(void) {
213 // put your keyboard start-up code here
214 // runs once when the firmware starts up
219 void matrix_scan_kb(void) {
220 // put your looping keyboard code here
221 // runs every cycle (a lot)
226 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
227 // put your per-action keyboard code here
228 // runs for every action, just before processing by the firmware
230 return process_record_user(keycode, record);