aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Aloysius <krusli@users.noreply.github.com>2018-01-19 08:02:32 +1100
committerJack Humbert <jack.humb@gmail.com>2018-01-18 16:02:32 -0500
commit365b86357825ebed7012377a5684269760326fd2 (patch)
treee54f479c245e1509fa6511114dea037b3999b3a5
parent5b22ddf5262af8860373ce7a3847f912d5947071 (diff)
downloadqmk_firmware-365b86357825ebed7012377a5684269760326fd2.tar.gz
qmk_firmware-365b86357825ebed7012377a5684269760326fd2.zip
Backlighting for JJ40 and underglow initialisation code (#2260)
* Cleanup Mechmini keymap. Once the custom RGB function is defined, there is no need to manually handle RGB code. * Change default to KEYMAP_MIT, not KEYMAP_OFFSET * Add custom RGB code for JJ40 * Reset Mechmini advertised power draw to 500. Will have to test actual maximum power draw later. * RGB working on JJ40. * Fix: saturation increase/decrease flipped * Add new directory for my custom keymap with RGB keycodes * Swap LAlt and LGUI * Update JJ40 max power draw with measured value * Update: fun40 rules.mk to enable underglow; earlier failed Travis CI * Fix: init RGB LEDs on boot. Also added HHKB-like keymap for XD60. * Super rudimentary backlight test, init RGB LEDs on boot * Backlighting works - stays on for now * Toggling working * Now can override backlight.c functions. Problem was functions in backlight.c weren't called before due to a lack of matrix_scan_quantum() in matrix.c * Timers not working * Delete global.h * Cleanup * Compiles * Good sign: LEDs stop working again * Handle timer1 overflow * Progress: fix: forgot to init * Backlighting fully working now except breathing. * Revert keymap to original keycodes * Update XD60 keymap README * Update JJ40 keymap with backlight toggles * Breathing working just fine. * Update references * Add backlight_set() call * Cleanup code to disable backlight * Fix: does not compile * Fix: missing call to rgblight_task. * Testing with BACKLIGHT_BREATHING * Cleanup * Cleanup comments * More commenting cleanup. * Do not enable BACKLIGHT_BREATHING by default
-rw-r--r--common_features.mk3
-rw-r--r--keyboards/jj40/backlight.c212
-rw-r--r--keyboards/jj40/backlight_custom.h15
-rw-r--r--keyboards/jj40/breathing_custom.h140
-rw-r--r--keyboards/jj40/config.h6
-rw-r--r--keyboards/jj40/jj40.c42
-rw-r--r--keyboards/jj40/jj40.h2
-rw-r--r--keyboards/jj40/keymaps/default/keymap.c17
-rw-r--r--keyboards/jj40/keymaps/krusli/config.h8
-rw-r--r--keyboards/jj40/keymaps/krusli/keymap.c23
-rw-r--r--keyboards/jj40/matrix.c36
-rw-r--r--keyboards/jj40/rules.mk8
-rw-r--r--keyboards/jj40/usbconfig.h2
-rw-r--r--keyboards/xd60/keymaps/krusli/HHKB-like.txt0
-rw-r--r--keyboards/xd60/keymaps/krusli/keymap.c62
-rw-r--r--keyboards/xd60/keymaps/krusli/readme.md2
-rw-r--r--quantum/quantum.c12
-rw-r--r--tmk_core/common/backlight.c2
18 files changed, 528 insertions, 64 deletions
diff --git a/common_features.mk b/common_features.mk
index a67cf230f..1c0b3546a 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -156,6 +156,9 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
156 ifeq ($(strip $(VISUALIZER_ENABLE)), yes) 156 ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
157 CIE1931_CURVE = yes 157 CIE1931_CURVE = yes
158 endif 158 endif
159 ifeq ($(strip $(BACKLIGHT_CUSTOM_DRIVER)), yes)
160 OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER
161 endif
159endif 162endif
160 163
161ifeq ($(strip $(CIE1931_CURVE)), yes) 164ifeq ($(strip $(CIE1931_CURVE)), yes)
diff --git a/keyboards/jj40/backlight.c b/keyboards/jj40/backlight.c
new file mode 100644
index 000000000..079c410ff
--- /dev/null
+++ b/keyboards/jj40/backlight.c
@@ -0,0 +1,212 @@
1/**
2 * Backlighting code for PS2AVRGB boards (ATMEGA32A)
3 * Kenneth A. (github.com/krusli | krusli.me)
4 */
5
6#include "backlight.h"
7#include "quantum.h"
8
9#include <avr/pgmspace.h>
10#include <avr/interrupt.h>
11
12#include "backlight_custom.h"
13#include "breathing_custom.h"
14
15// DEBUG
16#include <stdlib.h>
17#include <stdio.h>
18
19// Port D: digital pins of the AVR chipset
20#define NUMLOCK_PORT (1 << 1) // 1st pin of Port D (digital)
21#define CAPSLOCK_PORT (1 << 2) // 2nd pin
22#define BACKLIGHT_PORT (1 << 4) // 4th pin
23#define SCROLLLOCK_PORT (1 << 6) // 6th pin
24
25#define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64
26#define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default
27
28#define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask
29
30#define PWM_MAX 0xFF
31#define TIMER_TOP 255 // 8 bit PWM
32
33extern backlight_config_t backlight_config;
34
35/**
36 * References
37 * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation
38 * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b
39 * Timers: http://www.avrbeginners.net/architecture/timers/timers.html
40 * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/
41 * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware
42 */
43
44// @Override
45// turn LEDs on and off depending on USB caps/num/scroll lock states.
46void led_set_user(uint8_t usb_led) {
47 if (usb_led & (1 << USB_LED_NUM_LOCK)) {
48 // turn on
49 DDRD |= NUMLOCK_PORT;
50 PORTD |= NUMLOCK_PORT;
51 } else {
52 // turn off
53 DDRD &= ~NUMLOCK_PORT;
54 PORTD &= ~NUMLOCK_PORT;
55 }
56
57 if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
58 DDRD |= CAPSLOCK_PORT;
59 PORTD |= CAPSLOCK_PORT;
60 } else {
61 DDRD &= ~CAPSLOCK_PORT;
62 PORTD &= ~CAPSLOCK_PORT;
63 }
64
65 if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
66 DDRD |= SCROLLLOCK_PORT;
67 PORTD |= SCROLLLOCK_PORT;
68 } else {
69 DDRD &= ~SCROLLLOCK_PORT;
70 PORTD &= ~SCROLLLOCK_PORT;
71 }
72}
73
74#ifdef BACKLIGHT_ENABLE
75
76// sets up Timer 1 for 8-bit PWM
77void timer1PWMSetup(void) { // NOTE ONLY CALL THIS ONCE
78 // default 8 bit mode
79 TCCR1A &= ~(1 << 1); // cbi(TCCR1A,PWM11); <- set PWM11 bit to HIGH
80 TCCR1A |= (1 << 0); // sbi(TCCR1A,PWM10); <- set PWM10 bit to LOW
81
82 // clear output compare value A
83 // outb(OCR1AH, 0);
84 // outb(OCR1AL, 0);
85
86 // clear output comparator registers for B
87 OCR1BH = 0; // outb(OCR1BH, 0);
88 OCR1BL = 0; // outb(OCR1BL, 0);
89}
90
91bool is_init = false;
92void timer1Init(void) {
93 // timer1SetPrescaler(TIMER1PRESCALE)
94 // set to DIV/64
95 (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER1PRESCALE;
96
97 // reset TCNT1
98 TCNT1H = 0; // outb(TCNT1H, 0);
99 TCNT1L = 0; // outb(TCNT1L, 0);
100
101 // TOIE1: Timer Overflow Interrupt Enable (Timer 1);
102 TIMSK |= _BV(TOIE1); // sbi(TIMSK, TOIE1);
103
104 is_init = true;
105}
106
107void timer1UnInit(void) {
108 // set prescaler back to NONE
109 (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | 0x00; // TIMERRTC_CLK_STOP
110
111 // disable timer overflow interrupt
112 TIMSK &= ~_BV(TOIE1); // overflow bit?
113
114 setPWM(0);
115
116 is_init = false;
117}
118
119
120// handle TCNT1 overflow
121//! Interrupt handler for tcnt1 overflow interrupt
122ISR(TIMER1_OVF_vect, ISR_NOBLOCK)
123{
124 // sei();
125 // handle breathing here
126 #ifdef BACKLIGHT_BREATHING
127 if (is_breathing()) {
128 custom_breathing_handler();
129 }
130 #endif
131
132 // TODO call user defined function
133}
134
135// enable timer 1 PWM
136// timer1PWMBOn()
137void timer1PWMBEnable(void) {
138 // turn on channel B (OC1B) PWM output
139 // set OC1B as non-inverted PWM
140 TCCR1A |= _BV(COM1B1);
141 TCCR1A &= ~_BV(COM1B0);
142}
143
144// disable timer 1 PWM
145// timer1PWMBOff()
146void timer1PWMBDisable(void) {
147 TCCR1A &= ~_BV(COM1B1);
148 TCCR1A &= ~_BV(COM1B0);
149}
150
151void enableBacklight(void) {
152 DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output
153 PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high
154}
155
156void disableBacklight(void) {
157 // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input
158 PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low
159}
160
161void startPWM(void) {
162 timer1Init();
163 timer1PWMBEnable();
164 enableBacklight();
165}
166
167void stopPWM(void) {
168 timer1UnInit();
169 disableBacklight();
170 timer1PWMBDisable();
171}
172
173void b_led_init_ports(void) {
174 /* turn backlight on/off depending on user preference */
175 #if BACKLIGHT_ON_STATE == 0
176 // DDRx register: sets the direction of Port D
177 // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input
178 PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low
179 #else
180 DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output
181 PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high
182 #endif
183
184 timer1PWMSetup();
185 startPWM();
186
187 #ifdef BACKLIGHT_BREATHING
188 breathing_enable();
189 #endif
190}
191
192void b_led_set(uint8_t level) {
193 if (level > BACKLIGHT_LEVELS) {
194 level = BACKLIGHT_LEVELS;
195 }
196
197 setPWM((int)(TIMER_TOP * (float) level / BACKLIGHT_LEVELS));
198}
199
200// called every matrix scan
201void b_led_task(void) {
202 // do nothing for now
203}
204
205void setPWM(uint16_t xValue) {
206 if (xValue > TIMER_TOP) {
207 xValue = TIMER_TOP;
208 }
209 OCR1B = xValue; // timer1PWMBSet(xValue);
210}
211
212#endif // BACKLIGHT_ENABLE
diff --git a/keyboards/jj40/backlight_custom.h b/keyboards/jj40/backlight_custom.h
new file mode 100644
index 000000000..7210be840
--- /dev/null
+++ b/keyboards/jj40/backlight_custom.h
@@ -0,0 +1,15 @@
1/**
2 * Backlighting code for PS2AVRGB boards (ATMEGA32A)
3 * Kenneth A. (github.com/krusli | krusli.me)
4 */
5
6#ifndef BACKLIGHT_CUSTOM_H
7#define BACKLIGHT_CUSTOM_H
8
9#include <avr/pgmspace.h>
10void b_led_init_ports(void);
11void b_led_set(uint8_t level);
12void b_led_task(void);
13void setPWM(uint16_t xValue);
14
15#endif // BACKLIGHT_CUSTOM_H
diff --git a/keyboards/jj40/breathing_custom.h b/keyboards/jj40/breathing_custom.h
new file mode 100644
index 000000000..71416b1b4
--- /dev/null
+++ b/keyboards/jj40/breathing_custom.h
@@ -0,0 +1,140 @@
1/**
2 * Breathing effect code for PS2AVRGB boards (ATMEGA32A)
3 * Works in conjunction with `backlight.c`.
4 *
5 * Code adapted from `quantum.c` to register with the existing TIMER1 overflow
6 * handler in `backlight.c` instead of setting up its own timer.
7 * Kenneth A. (github.com/krusli | krusli.me)
8 */
9
10#ifdef BACKLIGHT_ENABLE
11#ifdef BACKLIGHT_BREATHING
12
13#include "backlight_custom.h"
14
15#ifndef BREATHING_PERIOD
16#define BREATHING_PERIOD 6
17#endif
18
19#define breathing_min() do {breathing_counter = 0;} while (0)
20#define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0)
21
22// TODO make this share code with quantum.c
23
24#define BREATHING_NO_HALT 0
25#define BREATHING_HALT_OFF 1
26#define BREATHING_HALT_ON 2
27#define BREATHING_STEPS 128
28
29static uint8_t breathing_period = BREATHING_PERIOD;
30static uint8_t breathing_halt = BREATHING_NO_HALT;
31static uint16_t breathing_counter = 0;
32
33static bool breathing = false;
34
35bool is_breathing(void) {
36 return breathing;
37}
38
39// See http://jared.geek.nz/2013/feb/linear-led-pwm
40static uint16_t cie_lightness(uint16_t v) {
41 if (v <= 5243) // if below 8% of max
42 return v / 9; // same as dividing by 900%
43 else {
44 uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare
45 // to get a useful result with integer division, we shift left in the expression above
46 // and revert what we've done again after squaring.
47 y = y * y * y >> 8;
48 if (y > 0xFFFFUL) // prevent overflow
49 return 0xFFFFU;
50 else
51 return (uint16_t) y;
52 }
53}
54
55void breathing_enable(void) {
56 breathing = true;
57 breathing_counter = 0;
58 breathing_halt = BREATHING_NO_HALT;
59 // interrupt already registered
60}
61
62void breathing_pulse(void) {
63 if (get_backlight_level() == 0)
64 breathing_min();
65 else
66 breathing_max();
67 breathing_halt = BREATHING_HALT_ON;
68 // breathing_interrupt_enable();
69 breathing = true;
70}
71
72void breathing_disable(void) {
73 breathing = false;
74 // backlight_set(get_backlight_level());
75 b_led_set(get_backlight_level()); // custom implementation of backlight_set()
76}
77
78void breathing_self_disable(void)
79{
80 if (get_backlight_level() == 0)
81 breathing_halt = BREATHING_HALT_OFF;
82 else
83 breathing_halt = BREATHING_HALT_ON;
84}
85
86void breathing_toggle(void) {
87 if (is_breathing())
88 breathing_disable();
89 else
90 breathing_enable();
91}
92
93void breathing_period_set(uint8_t value)
94{
95 if (!value)
96 value = 1;
97 breathing_period = value;
98}
99
100void breathing_period_default(void) {
101 breathing_period_set(BREATHING_PERIOD);
102}
103
104void breathing_period_inc(void)
105{
106 breathing_period_set(breathing_period+1);
107}
108
109void breathing_period_dec(void)
110{
111 breathing_period_set(breathing_period-1);
112}
113
114/* To generate breathing curve in python:
115 * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
116 */
117static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
118
119// Use this before the cie_lightness function.
120static inline uint16_t scale_backlight(uint16_t v) {
121 return v / BACKLIGHT_LEVELS * get_backlight_level();
122}
123
124void custom_breathing_handler(void) {
125 uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS;
126 // resetting after one period to prevent ugly reset at overflow.
127 breathing_counter = (breathing_counter + 1) % (breathing_period * 244);
128 uint8_t index = breathing_counter / interval % BREATHING_STEPS;
129
130 if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) ||
131 ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1)))
132 {
133 // breathing_interrupt_disable();
134 }
135
136 setPWM(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U)));
137}
138
139#endif // BACKLIGHT_BREATHING
140#endif // BACKLIGHT_ENABLE
diff --git a/keyboards/jj40/config.h b/keyboards/jj40/config.h
index 3152f22be..7fac1ed5b 100644
--- a/keyboards/jj40/config.h
+++ b/keyboards/jj40/config.h
@@ -34,8 +34,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
34/* COL2ROW or ROW2COL */ 34/* COL2ROW or ROW2COL */
35#define DIODE_DIRECTION COL2ROW 35#define DIODE_DIRECTION COL2ROW
36 36
37#define BACKLIGHT_PIN B6 37#define BACKLIGHT_LEVELS 12
38#define BACKLIGHT_LEVELS 3 38// #define BACKLIGHT_BREATHING // works, but BL_TOGG might not work
39 39
40#define TAPPING_TOGGLE 3 40#define TAPPING_TOGGLE 3
41 41
@@ -45,7 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
45// The RGB_DI_PIN value seems to be shared between all PS2AVRGB boards. 45// The RGB_DI_PIN value seems to be shared between all PS2AVRGB boards.
46// The same pin is used on the JJ40, at least. 46// The same pin is used on the JJ40, at least.
47#define RGBLED_NUM 5 47#define RGBLED_NUM 5
48#define RGB_DI_PIN E2 48#define RGB_DI_PIN E2 // NOTE: for PS2AVRGB boards, underglow commands are sent via I2C to 0xB0.
49#define RGBLIGHT_ANIMATIONS 49#define RGBLIGHT_ANIMATIONS
50 50
51/* key combination for command */ 51/* key combination for command */
diff --git a/keyboards/jj40/jj40.c b/keyboards/jj40/jj40.c
index 6044e83fd..9c1775d6a 100644
--- a/keyboards/jj40/jj40.c
+++ b/keyboards/jj40/jj40.c
@@ -1,5 +1,6 @@
1/* 1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> 2Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
3Modified 2018 Kenneth A. <github.com/krusli>
3 4
4This program is free software: you can redistribute it and/or modify 5This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by 6it under the terms of the GNU General Public License as published by
@@ -24,8 +25,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24 25
25#include "i2c.h" 26#include "i2c.h"
26 27
27// custom RGB driver 28#include "backlight.h"
29#include "backlight_custom.h"
30
28extern rgblight_config_t rgblight_config; 31extern rgblight_config_t rgblight_config;
32
33// for keyboard subdirectory level init functions
34// @Override
35void matrix_init_kb(void) {
36 // call user level keymaps, if any
37 // matrix_init_user();
38}
39
40#ifdef BACKLIGHT_ENABLE
41/// Overrides functions in `quantum.c`
42void backlight_init_ports(void) {
43 b_led_init_ports();
44}
45
46void backlight_task(void) {
47 b_led_task();
48}
49
50void backlight_set(uint8_t level) {
51 b_led_set(level);
52}
53#endif
54
55// custom RGB driver
29void rgblight_set(void) { 56void rgblight_set(void) {
30 if (!rgblight_config.enable) { 57 if (!rgblight_config.enable) {
31 for (uint8_t i=0; i<RGBLED_NUM; i++) { 58 for (uint8_t i=0; i<RGBLED_NUM; i++) {
@@ -39,8 +66,15 @@ void rgblight_set(void) {
39 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); 66 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
40} 67}
41 68
42__attribute__ ((weak)) 69bool rgb_init = false;
43void matrix_scan_user(void) { 70void matrix_scan_user(void) {
44 rgblight_task(); 71 // if LEDs were previously on before poweroff, turn them back on
45 /* Nothing else for now. */ 72 if (rgb_init == false && rgblight_config.enable) {
73 i2c_init();
74 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
75 rgb_init = true;
76 }
77
78 rgblight_task();
79 /* Nothing else for now. */
46} 80}
diff --git a/keyboards/jj40/jj40.h b/keyboards/jj40/jj40.h
index 6837423f8..44d8b0f37 100644
--- a/keyboards/jj40/jj40.h
+++ b/keyboards/jj40/jj40.h
@@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
23#include "keycode.h" 23#include "keycode.h"
24#include "action.h" 24#include "action.h"
25 25
26void matrix_init_user(void); // TODO port this to other PS2AVRGB boards
27
26#define KEYMAP_GRID( \ 28#define KEYMAP_GRID( \
27 K01, K02, K03, K04, K05, K06, K07, K08, K09, K010, K011, K012, \ 29 K01, K02, K03, K04, K05, K06, K07, K08, K09, K010, K011, K012, \
28 K11, K12, K13, K14, K15, K16, K17, K18, K19, K110, K111, K112, \ 30 K11, K12, K13, K14, K15, K16, K17, K18, K19, K110, K111, K112, \
diff --git a/keyboards/jj40/keymaps/default/keymap.c b/keyboards/jj40/keymaps/default/keymap.c
index 480486a18..e02dd902a 100644
--- a/keyboards/jj40/keymaps/default/keymap.c
+++ b/keyboards/jj40/keymaps/default/keymap.c
@@ -1,20 +1,3 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "jj40.h" 1#include "jj40.h"
19#include "action_layer.h" 2#include "action_layer.h"
20 3
diff --git a/keyboards/jj40/keymaps/krusli/config.h b/keyboards/jj40/keymaps/krusli/config.h
new file mode 100644
index 000000000..11cafbefc
--- /dev/null
+++ b/keyboards/jj40/keymaps/krusli/config.h
@@ -0,0 +1,8 @@
1#ifndef CONFIG_USER_H
2#define CONFIG_USER_H
3
4#include "../../config.h"
5
6#define PREVENT_STUCK_MODIFIERS
7
8#endif
diff --git a/keyboards/jj40/keymaps/krusli/keymap.c b/keyboards/jj40/keymaps/krusli/keymap.c
index 59e3988e1..5a985199e 100644
--- a/keyboards/jj40/keymaps/krusli/keymap.c
+++ b/keyboards/jj40/keymaps/krusli/keymap.c
@@ -1,20 +1,3 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "jj40.h" 1#include "jj40.h"
19#include "action_layer.h" 2#include "action_layer.h"
20 3
@@ -62,7 +45,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
62 KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, \ 45 KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, \
63 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \ 46 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
64 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,_______, _______, _______, \ 47 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,_______, _______, _______, \
65 _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \ 48 BL_TOGG, BL_STEP, BL_BRTG, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
66), 49),
67 50
68/* Raise 51/* Raise
@@ -73,13 +56,13 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
73 * |------+------+------+------+------+------|------+------+------+------+------+------| 56 * |------+------+------+------+------+------|------+------+------+------+------+------|
74 * | | F7 | F8 | F9 | F10 | F11 | F12 | RGB | RGB | RGB | RGB |Enter | 57 * | | F7 | F8 | F9 | F10 | F11 | F12 | RGB | RGB | RGB | RGB |Enter |
75 * |------+------+------+------+------+------+------+------+------+------+------+------| 58 * |------+------+------+------+------+------+------+------+------+------+------+------|
76 * | | RGB | RGB | RGB | RGB | | | Next | Vol- | Vol+ | Play | 59 * | RGB | RGB | RGB | RGB | | | | Next | Vol- | Vol+ | Play |
77 * `-----------------------------------------------------------------------------------' 60 * `-----------------------------------------------------------------------------------'
78 */ 61 */
79[_RAISE] = KEYMAP( \ 62[_RAISE] = KEYMAP( \
80 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \ 63 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
81 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \ 64 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
82 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, RGB_TOG, RGB_MOD, RGB_VAD, RGB_VAI, _______, \ 65 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, RGB_TOG, RGB_MOD, RGB_VAD, RGB_VAI, _______, \
83 _______, RGB_HUD, RGB_HUI, RGB_SAD, RGB_SAI, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \ 66 RGB_HUD, RGB_HUI, RGB_SAD, RGB_SAI, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
84) 67)
85}; 68};
diff --git a/keyboards/jj40/matrix.c b/keyboards/jj40/matrix.c
index 140026013..a9e9cb539 100644
--- a/keyboards/jj40/matrix.c
+++ b/keyboards/jj40/matrix.c
@@ -29,6 +29,9 @@ static uint8_t debouncing = DEBOUNCE;
29static matrix_row_t matrix[MATRIX_ROWS]; 29static matrix_row_t matrix[MATRIX_ROWS];
30static matrix_row_t matrix_debouncing[MATRIX_ROWS]; 30static matrix_row_t matrix_debouncing[MATRIX_ROWS];
31 31
32void matrix_set_row_status(uint8_t row);
33uint8_t bit_reverse(uint8_t x);
34
32void matrix_init(void) { 35void matrix_init(void) {
33 // all outputs for rows high 36 // all outputs for rows high
34 DDRB = 0xFF; 37 DDRB = 0xFF;
@@ -47,18 +50,8 @@ void matrix_init(void) {
47 matrix[row] = 0x00; 50 matrix[row] = 0x00;
48 matrix_debouncing[row] = 0x00; 51 matrix_debouncing[row] = 0x00;
49 } 52 }
50}
51 53
52void matrix_set_row_status(uint8_t row) { 54 matrix_init_quantum(); // missing from original port by Luiz
53 DDRB = (1 << row);
54 PORTB = ~(1 << row);
55}
56
57uint8_t bit_reverse(uint8_t x) {
58 x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
59 x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
60 x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
61 return x;
62} 55}
63 56
64uint8_t matrix_scan(void) { 57uint8_t matrix_scan(void) {
@@ -93,11 +86,30 @@ uint8_t matrix_scan(void) {
93 } 86 }
94 } 87 }
95 88
96 matrix_scan_user(); 89 matrix_scan_quantum(); // also missing in original PS2AVRGB implementation
97 90
98 return 1; 91 return 1;
99} 92}
100 93
94void matrix_scan_kb(void) {
95 // Looping keyboard code goes here
96 // This runs every cycle (a lot)
97 matrix_scan_user();
98};
99
100// declarations
101void matrix_set_row_status(uint8_t row) {
102 DDRB = (1 << row);
103 PORTB = ~(1 << row);
104}
105
106uint8_t bit_reverse(uint8_t x) {
107 x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
108 x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
109 x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
110 return x;
111}
112
101inline matrix_row_t matrix_get_row(uint8_t row) { 113inline matrix_row_t matrix_get_row(uint8_t row) {
102 return matrix[row]; 114 return matrix[row];
103} 115}
diff --git a/keyboards/jj40/rules.mk b/keyboards/jj40/rules.mk
index cdc898c0f..670967fbd 100644
--- a/keyboards/jj40/rules.mk
+++ b/keyboards/jj40/rules.mk
@@ -36,11 +36,13 @@ MOUSEKEY_ENABLE = no
36EXTRAKEY_ENABLE = yes 36EXTRAKEY_ENABLE = yes
37CONSOLE_ENABLE = no 37CONSOLE_ENABLE = no
38COMMAND_ENABLE = yes 38COMMAND_ENABLE = yes
39BACKLIGHT_ENABLE = no 39
40BACKLIGHT_ENABLE = yes
41BACKLIGHT_CUSTOM_DRIVER = yes
40 42
41RGBLIGHT_ENABLE = yes 43RGBLIGHT_ENABLE = yes
42RGBLIGHT_CUSTOM_DRIVER = yes 44RGBLIGHT_CUSTOM_DRIVER = yes
43DISABLE_WS2812 = yes # TODO check if this is necessary 45# DISABLE_WS2812 = no
44 46
45KEY_LOCK_ENABLE = yes 47KEY_LOCK_ENABLE = yes
46 48
@@ -51,7 +53,7 @@ OPT_DEFS = -DDEBUG_LEVEL=0
51 53
52# custom matrix setup 54# custom matrix setup
53CUSTOM_MATRIX = yes 55CUSTOM_MATRIX = yes
54SRC = matrix.c i2c.c 56SRC = matrix.c i2c.c backlight.c
55 57
56# programming options 58# programming options
57PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex 59PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex
diff --git a/keyboards/jj40/usbconfig.h b/keyboards/jj40/usbconfig.h
index 520d08f61..ad97e7f0a 100644
--- a/keyboards/jj40/usbconfig.h
+++ b/keyboards/jj40/usbconfig.h
@@ -119,7 +119,7 @@ section at the end of this file).
119 * device is powered from the USB bus. 119 * device is powered from the USB bus.
120 */ 120 */
121// max power draw with maxed white underglow measured at 120 mA (peaks) 121// max power draw with maxed white underglow measured at 120 mA (peaks)
122#define USB_CFG_MAX_BUS_POWER 150 122#define USB_CFG_MAX_BUS_POWER 100
123/* Set this variable to the maximum USB bus power consumption of your device. 123/* Set this variable to the maximum USB bus power consumption of your device.
124 * The value is in milliamperes. [It will be divided by two since USB 124 * The value is in milliamperes. [It will be divided by two since USB
125 * communicates power requirements in units of 2 mA.] 125 * communicates power requirements in units of 2 mA.]
diff --git a/keyboards/xd60/keymaps/krusli/HHKB-like.txt b/keyboards/xd60/keymaps/krusli/HHKB-like.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/keyboards/xd60/keymaps/krusli/HHKB-like.txt
diff --git a/keyboards/xd60/keymaps/krusli/keymap.c b/keyboards/xd60/keymaps/krusli/keymap.c
new file mode 100644
index 000000000..71f6e3c2e
--- /dev/null
+++ b/keyboards/xd60/keymaps/krusli/keymap.c
@@ -0,0 +1,62 @@
1#include "xd60.h"
2#include "action_layer.h"
3
4/* HHKB-like layout for standard 60% layout with split RShift and split backspace */
5
6const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
7
8 // 0: Base Layer
9 KEYMAP(
10 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_GRV, \
11 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, \
12 KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NO, KC_ENT, \
13 KC_LSFT, KC_NO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_RSFT, F(0), \
14 KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_RGUI, KC_RALT, F(0), KC_RCTL, KC_RCTL),
15
16 // 1: Function Layer
17 /* Layer HHKB: HHKB mode (HHKB Fn)
18 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
19 | Pwr | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | Ins | Del |
20 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
21 | Caps | | | | | | | | Psc | Slk | Pus | Up | | Backs | |
22 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
23 | | VoD | VoU | Mut | | | * | / | Hom | PgU | Lef | Rig | Enter | | |
24 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
25 | | | | | | | + | - | End | PgD | Dow | | | | |
26 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
27
28 |------+------+----------------------+------+------+
29 | **** | **** | ******************** | **** | **** |
30 |------+------+----------------------+------+------+
31 */
32 KEYMAP(
33 RESET, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_F13, KC_F14, \
34 KC_CAPS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, KC_TRNS, KC_BSPC, \
35 KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_PAST, KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_NO, KC_ENT, \
36 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PPLS, KC_PMNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS, KC_TRNS, \
37 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, F(0), KC_TRNS, KC_TRNS),
38};
39
40// Custom Actions
41const uint16_t PROGMEM fn_actions[] = {
42 [0] = ACTION_LAYER_MOMENTARY(1), // to Fn overlay
43};
44
45// Macros
46const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
47
48 // MACRODOWN only works in this function
49 switch(id) {
50 case 0:
51 if (record->event.pressed) { register_code(KC_RSFT); }
52 else { unregister_code(KC_RSFT); }
53 break;
54 }
55
56 return MACRO_NONE;
57};
58
59// Loop
60void matrix_scan_user(void) {
61 // Empty
62};
diff --git a/keyboards/xd60/keymaps/krusli/readme.md b/keyboards/xd60/keymaps/krusli/readme.md
new file mode 100644
index 000000000..7b6bce9c4
--- /dev/null
+++ b/keyboards/xd60/keymaps/krusli/readme.md
@@ -0,0 +1,2 @@
1# krusli's HHKB-style keymap for the XD60
2HHKB-style keymap for the XD60. The board was not built with split backspace but still has Backspace and |\\ swapped.
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 88617412c..65fa25961 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -138,13 +138,13 @@ void reset_keyboard(void) {
138 clear_keyboard(); 138 clear_keyboard();
139#if defined(MIDI_ENABLE) && defined(MIDI_BASIC) 139#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
140 process_midi_all_notes_off(); 140 process_midi_all_notes_off();
141#endif 141#endif
142#if defined(AUDIO_ENABLE) 142#if defined(AUDIO_ENABLE)
143 music_all_notes_off(); 143 music_all_notes_off();
144 uint16_t timer_start = timer_read(); 144 uint16_t timer_start = timer_read();
145 PLAY_SONG(goodbye_song); 145 PLAY_SONG(goodbye_song);
146 shutdown_user(); 146 shutdown_user();
147 while(timer_elapsed(timer_start) < 250) 147 while(timer_elapsed(timer_start) < 250)
148 wait_ms(1); 148 wait_ms(1);
149 stop_all_notes(); 149 stop_all_notes();
150#else 150#else
@@ -885,6 +885,7 @@ void backlight_set(uint8_t level) {}
885 885
886uint8_t backlight_tick = 0; 886uint8_t backlight_tick = 0;
887 887
888#ifndef BACKLIGHT_CUSTOM_DRIVER
888void backlight_task(void) { 889void backlight_task(void) {
889 if ((0xFFFF >> ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) { 890 if ((0xFFFF >> ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
890 #if BACKLIGHT_ON_STATE == 0 891 #if BACKLIGHT_ON_STATE == 0
@@ -905,9 +906,12 @@ void backlight_task(void) {
905 } 906 }
906 backlight_tick = backlight_tick + 1 % 16; 907 backlight_tick = backlight_tick + 1 % 16;
907} 908}
909#endif
908 910
909#ifdef BACKLIGHT_BREATHING 911#ifdef BACKLIGHT_BREATHING
910#error "Backlight breathing only available with hardware PWM. Please disable." 912 #ifndef BACKLIGHT_CUSTOM_DRIVER
913 #error "Backlight breathing only available with hardware PWM. Please disable."
914 #endif
911#endif 915#endif
912 916
913#else // pwm through timer 917#else // pwm through timer
@@ -935,6 +939,7 @@ static inline void set_pwm(uint16_t val) {
935 OCR1x = val; 939 OCR1x = val;
936} 940}
937 941
942#ifndef BACKLIGHT_CUSTOM_DRIVER
938__attribute__ ((weak)) 943__attribute__ ((weak))
939void backlight_set(uint8_t level) { 944void backlight_set(uint8_t level) {
940 if (level > BACKLIGHT_LEVELS) 945 if (level > BACKLIGHT_LEVELS)
@@ -952,6 +957,7 @@ void backlight_set(uint8_t level) {
952} 957}
953 958
954void backlight_task(void) {} 959void backlight_task(void) {}
960#endif // BACKLIGHT_CUSTOM_DRIVER
955 961
956#ifdef BACKLIGHT_BREATHING 962#ifdef BACKLIGHT_BREATHING
957 963
diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c
index 4d2491b98..12f75b38a 100644
--- a/tmk_core/common/backlight.c
+++ b/tmk_core/common/backlight.c
@@ -94,4 +94,4 @@ void backlight_level(uint8_t level)
94uint8_t get_backlight_level(void) 94uint8_t get_backlight_level(void)
95{ 95{
96 return backlight_config.level; 96 return backlight_config.level;
97} \ No newline at end of file 97}