aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/config_common.h99
-rw-r--r--quantum/keymap.h4
-rwxr-xr-xquantum/light_ws2812.c151
-rwxr-xr-xquantum/light_ws2812.h21
-rw-r--r--quantum/process_keycode/process_printer.c254
-rw-r--r--quantum/process_keycode/process_printer.h8
-rw-r--r--quantum/process_keycode/process_printer_bb.c260
-rw-r--r--quantum/quantum.c43
-rw-r--r--quantum/quantum.h9
-rw-r--r--quantum/rgblight.c126
-rw-r--r--quantum/rgblight.h12
11 files changed, 873 insertions, 114 deletions
diff --git a/quantum/config_common.h b/quantum/config_common.h
index 8ed5f4a10..f3897dc2c 100644
--- a/quantum/config_common.h
+++ b/quantum/config_common.h
@@ -5,55 +5,56 @@
5#define COL2ROW 0 5#define COL2ROW 0
6#define ROW2COL 1 6#define ROW2COL 1
7/* I/O pins */ 7/* I/O pins */
8#define B0 0x30 8#ifndef F0
9#define B1 0x31 9 #define B0 0x30
10#define B2 0x32 10 #define B1 0x31
11#define B3 0x33 11 #define B2 0x32
12#define B4 0x34 12 #define B3 0x33
13#define B5 0x35 13 #define B4 0x34
14#define B6 0x36 14 #define B5 0x35
15#define B7 0x37 15 #define B6 0x36
16#define C0 0x60 16 #define B7 0x37
17#define C1 0x61 17 #define C0 0x60
18#define C2 0x62 18 #define C1 0x61
19#define C3 0x63 19 #define C2 0x62
20#define C4 0x64 20 #define C3 0x63
21#define C5 0x65 21 #define C4 0x64
22#define C6 0x66 22 #define C5 0x65
23#define C7 0x67 23 #define C6 0x66
24#define D0 0x90 24 #define C7 0x67
25#define D1 0x91 25 #define D0 0x90
26#define D2 0x92 26 #define D1 0x91
27#define D3 0x93 27 #define D2 0x92
28#define D4 0x94 28 #define D3 0x93
29#define D5 0x95 29 #define D4 0x94
30#define D6 0x96 30 #define D5 0x95
31#define D7 0x97 31 #define D6 0x96
32#define E0 0xC0 32 #define D7 0x97
33#define E1 0xC1 33 #define E0 0xC0
34#define E2 0xC2 34 #define E1 0xC1
35#define E3 0xC3 35 #define E2 0xC2
36#define E4 0xC4 36 #define E3 0xC3
37#define E5 0xC5 37 #define E4 0xC4
38#define E6 0xC6 38 #define E5 0xC5
39#define E7 0xC7 39 #define E6 0xC6
40#define F0 0xF0 40 #define E7 0xC7
41#define F1 0xF1 41 #define F0 0xF0
42#define F2 0xF2 42 #define F1 0xF1
43#define F3 0xF3 43 #define F2 0xF2
44#define F4 0xF4 44 #define F3 0xF3
45#define F5 0xF5 45 #define F4 0xF4
46#define F6 0xF6 46 #define F5 0xF5
47#define F7 0xF7 47 #define F6 0xF6
48#define A0 0x00 48 #define F7 0xF7
49#define A1 0x01 49 #define A0 0x00
50#define A2 0x02 50 #define A1 0x01
51#define A3 0x03 51 #define A2 0x02
52#define A4 0x04 52 #define A3 0x03
53#define A5 0x05 53 #define A4 0x04
54#define A6 0x06 54 #define A5 0x05
55#define A7 0x07 55 #define A6 0x06
56 56 #define A7 0x07
57#endif
57 58
58/* USART configuration */ 59/* USART configuration */
59#ifdef BLUETOOTH_ENABLE 60#ifdef BLUETOOTH_ENABLE
diff --git a/quantum/keymap.h b/quantum/keymap.h
index a01bbfbd1..ae56d16c7 100644
--- a/quantum/keymap.h
+++ b/quantum/keymap.h
@@ -178,6 +178,10 @@ enum quantum_keycodes {
178 // Right shift, close paren 178 // Right shift, close paren
179 KC_RSPC, 179 KC_RSPC,
180 180
181 // Printing
182 PRINT_ON,
183 PRINT_OFF,
184
181 // always leave at the end 185 // always leave at the end
182 SAFE_RANGE 186 SAFE_RANGE
183}; 187};
diff --git a/quantum/light_ws2812.c b/quantum/light_ws2812.c
index 401845e85..a883b1388 100755
--- a/quantum/light_ws2812.c
+++ b/quantum/light_ws2812.c
@@ -16,14 +16,128 @@
16#include <util/delay.h> 16#include <util/delay.h>
17#include "debug.h" 17#include "debug.h"
18 18
19#ifdef RGBW_BB_TWI
20
21// Port for the I2C
22#define I2C_DDR DDRD
23#define I2C_PIN PIND
24#define I2C_PORT PORTD
25
26// Pins to be used in the bit banging
27#define I2C_CLK 0
28#define I2C_DAT 1
29
30#define I2C_DATA_HI()\
31I2C_DDR &= ~ (1 << I2C_DAT);\
32I2C_PORT |= (1 << I2C_DAT);
33#define I2C_DATA_LO()\
34I2C_DDR |= (1 << I2C_DAT);\
35I2C_PORT &= ~ (1 << I2C_DAT);
36
37#define I2C_CLOCK_HI()\
38I2C_DDR &= ~ (1 << I2C_CLK);\
39I2C_PORT |= (1 << I2C_CLK);
40#define I2C_CLOCK_LO()\
41I2C_DDR |= (1 << I2C_CLK);\
42I2C_PORT &= ~ (1 << I2C_CLK);
43
44#define I2C_DELAY 1
45
46void I2C_WriteBit(unsigned char c)
47{
48 if (c > 0)
49 {
50 I2C_DATA_HI();
51 }
52 else
53 {
54 I2C_DATA_LO();
55 }
56
57 I2C_CLOCK_HI();
58 _delay_us(I2C_DELAY);
59
60 I2C_CLOCK_LO();
61 _delay_us(I2C_DELAY);
62
63 if (c > 0)
64 {
65 I2C_DATA_LO();
66 }
67
68 _delay_us(I2C_DELAY);
69}
70
71// Inits bitbanging port, must be called before using the functions below
72//
73void I2C_Init()
74{
75 I2C_PORT &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK));
76
77 I2C_CLOCK_HI();
78 I2C_DATA_HI();
79
80 _delay_us(I2C_DELAY);
81}
82
83// Send a START Condition
84//
85void I2C_Start()
86{
87 // set both to high at the same time
88 I2C_DDR &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK));
89 _delay_us(I2C_DELAY);
90
91 I2C_DATA_LO();
92 _delay_us(I2C_DELAY);
93
94 I2C_CLOCK_LO();
95 _delay_us(I2C_DELAY);
96}
97
98// Send a STOP Condition
99//
100void I2C_Stop()
101{
102 I2C_CLOCK_HI();
103 _delay_us(I2C_DELAY);
104
105 I2C_DATA_HI();
106 _delay_us(I2C_DELAY);
107}
108
109// write a byte to the I2C slave device
110//
111unsigned char I2C_Write(unsigned char c)
112{
113 for (char i = 0; i < 8; i++)
114 {
115 I2C_WriteBit(c & 128);
116
117 c <<= 1;
118 }
119
120
121 I2C_WriteBit(0);
122 _delay_us(I2C_DELAY);
123 _delay_us(I2C_DELAY);
124
125 // _delay_us(I2C_DELAY);
126 //return I2C_ReadBit();
127 return 0;
128}
129
130
131#endif
132
19// Setleds for standard RGB 133// Setleds for standard RGB
20void inline ws2812_setleds(struct cRGB *ledarray, uint16_t leds) 134void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds)
21{ 135{
22 // ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin)); 136 // ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
23 ws2812_setleds_pin(ledarray,leds, _BV(RGB_DI_PIN & 0xF)); 137 ws2812_setleds_pin(ledarray,leds, _BV(RGB_DI_PIN & 0xF));
24} 138}
25 139
26void inline ws2812_setleds_pin(struct cRGB *ledarray, uint16_t leds, uint8_t pinmask) 140void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask)
27{ 141{
28 // ws2812_DDRREG |= pinmask; // Enable DDR 142 // ws2812_DDRREG |= pinmask; // Enable DDR
29 // new universal format (DDR) 143 // new universal format (DDR)
@@ -34,14 +148,41 @@ void inline ws2812_setleds_pin(struct cRGB *ledarray, uint16_t leds, uint8_t pin
34} 148}
35 149
36// Setleds for SK6812RGBW 150// Setleds for SK6812RGBW
37void inline ws2812_setleds_rgbw(struct cRGBW *ledarray, uint16_t leds) 151void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds)
38{ 152{
153
154 #ifdef RGBW_BB_TWI
155 uint8_t sreg_prev, twcr_prev;
156 sreg_prev=SREG;
157 twcr_prev=TWCR;
158 cli();
159 TWCR &= ~(1<<TWEN);
160 I2C_Init();
161 I2C_Start();
162 I2C_Write(0x84);
163 uint16_t datlen = leds<<2;
164 uint8_t curbyte;
165 uint8_t * data = (uint8_t*)ledarray;
166 while (datlen--) {
167 curbyte=*data++;
168 I2C_Write(curbyte);
169 }
170 I2C_Stop();
171 SREG=sreg_prev;
172 TWCR=twcr_prev;
173 #endif
174
175
39 // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR 176 // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR
40 // new universal format (DDR) 177 // new universal format (DDR)
41 _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF); 178 _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF);
42 179
43 ws2812_sendarray_mask((uint8_t*)ledarray,leds<<2,_BV(RGB_DI_PIN & 0xF)); 180 ws2812_sendarray_mask((uint8_t*)ledarray,leds<<2,_BV(RGB_DI_PIN & 0xF));
44 _delay_us(80); 181
182
183 #ifndef RGBW_BB_TWI
184 _delay_us(80);
185 #endif
45} 186}
46 187
47void ws2812_sendarray(uint8_t *data,uint16_t datlen) 188void ws2812_sendarray(uint8_t *data,uint16_t datlen)
@@ -123,7 +264,7 @@ void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)
123 cli(); 264 cli();
124 265
125 while (datlen--) { 266 while (datlen--) {
126 curbyte=*data++; 267 curbyte=(*data++);
127 268
128 asm volatile( 269 asm volatile(
129 " ldi %0,8 \n\t" 270 " ldi %0,8 \n\t"
diff --git a/quantum/light_ws2812.h b/quantum/light_ws2812.h
index 54eef22d9..9498e550e 100755
--- a/quantum/light_ws2812.h
+++ b/quantum/light_ws2812.h
@@ -16,6 +16,21 @@
16#include <avr/io.h> 16#include <avr/io.h>
17#include <avr/interrupt.h> 17#include <avr/interrupt.h>
18//#include "ws2812_config.h" 18//#include "ws2812_config.h"
19//#include "i2cmaster.h"
20
21#define LIGHT_I2C 1
22#define LIGHT_I2C_ADDR 0x84
23#define LIGHT_I2C_ADDR_WRITE ( (LIGHT_I2C_ADDR<<1) | I2C_WRITE )
24#define LIGHT_I2C_ADDR_READ ( (LIGHT_I2C_ADDR<<1) | I2C_READ )
25
26#define RGBW 1
27
28#ifdef RGBW
29 #define LED_TYPE struct cRGBW
30#else
31 #define LED_TYPE struct cRGB
32#endif
33
19 34
20/* 35/*
21 * Structure of the LED array 36 * Structure of the LED array
@@ -42,9 +57,9 @@ struct cRGBW { uint8_t g; uint8_t r; uint8_t b; uint8_t w;};
42 * - Wait 50�s to reset the LEDs 57 * - Wait 50�s to reset the LEDs
43 */ 58 */
44 59
45void ws2812_setleds (struct cRGB *ledarray, uint16_t number_of_leds); 60void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds);
46void ws2812_setleds_pin (struct cRGB *ledarray, uint16_t number_of_leds,uint8_t pinmask); 61void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);
47void ws2812_setleds_rgbw(struct cRGBW *ledarray, uint16_t number_of_leds); 62void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
48 63
49/* 64/*
50 * Old interface / Internal functions 65 * Old interface / Internal functions
diff --git a/quantum/process_keycode/process_printer.c b/quantum/process_keycode/process_printer.c
new file mode 100644
index 000000000..2e11dd366
--- /dev/null
+++ b/quantum/process_keycode/process_printer.c
@@ -0,0 +1,254 @@
1#include "process_printer.h"
2#include "action_util.h"
3
4bool printing_enabled = false;
5uint8_t character_shift = 0;
6
7void enabled_printing() {
8 printing_enabled = true;
9 serial_init();
10}
11
12void disable_printing() {
13 printing_enabled = false;
14}
15
16uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
17
18// uint8_t keycode_to_ascii[0xFF][2];
19
20// keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
21
22void print_char(char c) {
23 USB_Disable();
24 serial_send(c);
25 USB_Init();
26}
27
28void print_box_string(uint8_t text[]) {
29 uint8_t len = strlen(text);
30 uint8_t out[len * 3 + 8];
31 out[0] = 0xDA;
32 for (uint8_t i = 0; i < len; i++) {
33 out[i+1] = 0xC4;
34 }
35 out[len + 1] = 0xBF;
36 out[len + 2] = '\n';
37
38 out[len + 3] = 0xB3;
39 for (uint8_t i = 0; i < len; i++) {
40 out[len + 4 + i] = text[i];
41 }
42 out[len * 2 + 4] = 0xB3;
43 out[len * 2 + 5] = '\n';
44
45
46 out[len * 2 + 6] = 0xC0;
47 for (uint8_t i = 0; i < len; i++) {
48 out[len * 2 + 7 + i] = 0xC4;
49 }
50 out[len * 3 + 7] = 0xD9;
51 out[len * 3 + 8] = '\n';
52
53 print_string(out);
54}
55
56void print_string(char c[]) {
57 for(uint8_t i = 0; i < strlen(c); i++)
58 print_char(c[i]);
59}
60
61bool process_printer(uint16_t keycode, keyrecord_t *record) {
62 if (keycode == PRINT_ON) {
63 enabled_printing();
64 return false;
65 }
66 if (keycode == PRINT_OFF) {
67 disable_printing();
68 return false;
69 }
70
71 if (printing_enabled) {
72 switch(keycode) {
73 case KC_EXLM ... KC_RPRN:
74 case KC_UNDS:
75 case KC_PLUS:
76 case KC_LCBR:
77 case KC_RCBR:
78 case KC_PIPE:
79 case KC_TILD:
80 keycode &= 0xFF;
81 case KC_LSFT:
82 case KC_RSFT:
83 if (record->event.pressed) {
84 character_shift++;
85 } else {
86 character_shift--;
87 }
88 return false;
89 break;
90 }
91
92 switch(keycode) {
93 case KC_F1:
94 if (record->event.pressed) {
95 print_box_string("This is a line of text!");
96 }
97 return false;
98 case KC_ESC:
99 if (record->event.pressed) {
100 print_char(0x1B);
101 }
102 return false;
103 break;
104 case KC_SPC:
105 if (record->event.pressed) {
106 print_char(0x20);
107 }
108 return false;
109 break;
110 case KC_A ... KC_Z:
111 if (record->event.pressed) {
112 if (character_shift) {
113 print_char(0x41 + (keycode - KC_A));
114 } else {
115 print_char(0x61 + (keycode - KC_A));
116 }
117 }
118 return false;
119 break;
120 case KC_1 ... KC_0:
121 if (record->event.pressed) {
122 if (character_shift) {
123 print_char(shifted_numbers[keycode - KC_1]);
124 } else {
125 print_char(0x30 + ((keycode - KC_1 + 1) % 10));
126 }
127 }
128 return false;
129 break;
130 case KC_ENT:
131 if (record->event.pressed) {
132 if (character_shift) {
133 print_char(0x0C);
134 } else {
135 print_char(0x0A);
136 }
137 }
138 return false;
139 break;
140 case KC_BSPC:
141 if (record->event.pressed) {
142 if (character_shift) {
143 print_char(0x18);
144 } else {
145 print_char(0x1A);
146 }
147 }
148 return false;
149 break;
150 case KC_DOT:
151 if (record->event.pressed) {
152 if (character_shift) {
153 print_char(0x3E);
154 } else {
155 print_char(0x2E);
156 }
157 }
158 return false;
159 break;
160 case KC_COMM:
161 if (record->event.pressed) {
162 if (character_shift) {
163 print_char(0x3C);
164 } else {
165 print_char(0x2C);
166 }
167 }
168 return false;
169 break;
170 case KC_SLSH:
171 if (record->event.pressed) {
172 if (character_shift) {
173 print_char(0x3F);
174 } else {
175 print_char(0x2F);
176 }
177 }
178 return false;
179 break;
180 case KC_QUOT:
181 if (record->event.pressed) {
182 if (character_shift) {
183 print_char(0x22);
184 } else {
185 print_char(0x27);
186 }
187 }
188 return false;
189 break;
190 case KC_GRV:
191 if (record->event.pressed) {
192 if (character_shift) {
193 print_char(0x7E);
194 } else {
195 print_char(0x60);
196 }
197 }
198 return false;
199 break;
200 case KC_MINS:
201 if (record->event.pressed) {
202 if (character_shift) {
203 print_char(0x5F);
204 } else {
205 print_char(0x2D);
206 }
207 }
208 return false;
209 break;
210 case KC_EQL:
211 if (record->event.pressed) {
212 if (character_shift) {
213 print_char(0x2B);
214 } else {
215 print_char(0x3D);
216 }
217 }
218 return false;
219 break;
220 case KC_LBRC:
221 if (record->event.pressed) {
222 if (character_shift) {
223 print_char(0x7B);
224 } else {
225 print_char(0x5B);
226 }
227 }
228 return false;
229 break;
230 case KC_RBRC:
231 if (record->event.pressed) {
232 if (character_shift) {
233 print_char(0x7D);
234 } else {
235 print_char(0x5D);
236 }
237 }
238 return false;
239 break;
240 case KC_BSLS:
241 if (record->event.pressed) {
242 if (character_shift) {
243 print_char(0x7C);
244 } else {
245 print_char(0x5C);
246 }
247 }
248 return false;
249 break;
250 }
251 }
252 return true;
253
254} \ No newline at end of file
diff --git a/quantum/process_keycode/process_printer.h b/quantum/process_keycode/process_printer.h
new file mode 100644
index 000000000..fdd36d75a
--- /dev/null
+++ b/quantum/process_keycode/process_printer.h
@@ -0,0 +1,8 @@
1#ifndef PROCESS_PRINTER_H
2#define PROCESS_PRINTER_H
3
4#include "quantum.h"
5
6#include "protocol/serial.h"
7
8#endif \ No newline at end of file
diff --git a/quantum/process_keycode/process_printer_bb.c b/quantum/process_keycode/process_printer_bb.c
new file mode 100644
index 000000000..1924d0377
--- /dev/null
+++ b/quantum/process_keycode/process_printer_bb.c
@@ -0,0 +1,260 @@
1#include "process_printer.h"
2#include "action_util.h"
3
4bool printing_enabled = false;
5uint8_t character_shift = 0;
6
7#define SERIAL_PIN_DDR DDRD
8#define SERIAL_PIN_PORT PORTD
9#define SERIAL_PIN_MASK _BV(PD3)
10#define SERIAL_DELAY 52
11
12inline static
13void serial_delay(void) {
14 _delay_us(SERIAL_DELAY);
15}
16
17inline static
18void serial_high(void) {
19 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
20}
21
22inline static
23void serial_low(void) {
24 SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
25}
26
27inline static
28void serial_output(void) {
29 SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
30}
31
32
33void enabled_printing() {
34 printing_enabled = true;
35 serial_output();
36 serial_high();
37}
38
39void disable_printing() {
40 printing_enabled = false;
41}
42
43uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
44
45// uint8_t keycode_to_ascii[0xFF][2];
46
47// keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
48
49void print_char(char c) {
50 uint8_t b = 8;
51 serial_output();
52 while( b-- ) {
53 if(c & (1 << b)) {
54 serial_high();
55 } else {
56 serial_low();
57 }
58 serial_delay();
59 }
60}
61
62void print_string(char c[]) {
63 for(uint8_t i = 0; i < strlen(c); i++)
64 print_char(c[i]);
65}
66
67bool process_printer(uint16_t keycode, keyrecord_t *record) {
68 if (keycode == PRINT_ON) {
69 enabled_printing();
70 return false;
71 }
72 if (keycode == PRINT_OFF) {
73 disable_printing();
74 return false;
75 }
76
77 if (printing_enabled) {
78 switch(keycode) {
79 case KC_EXLM ... KC_RPRN:
80 case KC_UNDS:
81 case KC_PLUS:
82 case KC_LCBR:
83 case KC_RCBR:
84 case KC_PIPE:
85 case KC_TILD:
86 keycode &= 0xFF;
87 case KC_LSFT:
88 case KC_RSFT:
89 if (record->event.pressed) {
90 character_shift++;
91 } else {
92 character_shift--;
93 }
94 return false;
95 break;
96 }
97
98 switch(keycode) {
99 case KC_F1:
100 if (record->event.pressed) {
101 print_string("This is a line of text!\n\n\n");
102 }
103 return false;
104 case KC_ESC:
105 if (record->event.pressed) {
106 print_char(0x1B);
107 }
108 return false;
109 break;
110 case KC_SPC:
111 if (record->event.pressed) {
112 print_char(0x20);
113 }
114 return false;
115 break;
116 case KC_A ... KC_Z:
117 if (record->event.pressed) {
118 if (character_shift) {
119 print_char(0x41 + (keycode - KC_A));
120 } else {
121 print_char(0x61 + (keycode - KC_A));
122 }
123 }
124 return false;
125 break;
126 case KC_1 ... KC_0:
127 if (record->event.pressed) {
128 if (character_shift) {
129 print_char(shifted_numbers[keycode - KC_1]);
130 } else {
131 print_char(0x30 + ((keycode - KC_1 + 1) % 10));
132 }
133 }
134 return false;
135 break;
136 case KC_ENT:
137 if (record->event.pressed) {
138 if (character_shift) {
139 print_char(0x0C);
140 } else {
141 print_char(0x0A);
142 }
143 }
144 return false;
145 break;
146 case KC_BSPC:
147 if (record->event.pressed) {
148 if (character_shift) {
149 print_char(0x18);
150 } else {
151 print_char(0x1A);
152 }
153 }
154 return false;
155 break;
156 case KC_DOT:
157 if (record->event.pressed) {
158 if (character_shift) {
159 print_char(0x3E);
160 } else {
161 print_char(0x2E);
162 }
163 }
164 return false;
165 break;
166 case KC_COMM:
167 if (record->event.pressed) {
168 if (character_shift) {
169 print_char(0x3C);
170 } else {
171 print_char(0x2C);
172 }
173 }
174 return false;
175 break;
176 case KC_SLSH:
177 if (record->event.pressed) {
178 if (character_shift) {
179 print_char(0x3F);
180 } else {
181 print_char(0x2F);
182 }
183 }
184 return false;
185 break;
186 case KC_QUOT:
187 if (record->event.pressed) {
188 if (character_shift) {
189 print_char(0x22);
190 } else {
191 print_char(0x27);
192 }
193 }
194 return false;
195 break;
196 case KC_GRV:
197 if (record->event.pressed) {
198 if (character_shift) {
199 print_char(0x7E);
200 } else {
201 print_char(0x60);
202 }
203 }
204 return false;
205 break;
206 case KC_MINS:
207 if (record->event.pressed) {
208 if (character_shift) {
209 print_char(0x5F);
210 } else {
211 print_char(0x2D);
212 }
213 }
214 return false;
215 break;
216 case KC_EQL:
217 if (record->event.pressed) {
218 if (character_shift) {
219 print_char(0x2B);
220 } else {
221 print_char(0x3D);
222 }
223 }
224 return false;
225 break;
226 case KC_LBRC:
227 if (record->event.pressed) {
228 if (character_shift) {
229 print_char(0x7B);
230 } else {
231 print_char(0x5B);
232 }
233 }
234 return false;
235 break;
236 case KC_RBRC:
237 if (record->event.pressed) {
238 if (character_shift) {
239 print_char(0x7D);
240 } else {
241 print_char(0x5D);
242 }
243 }
244 return false;
245 break;
246 case KC_BSLS:
247 if (record->event.pressed) {
248 if (character_shift) {
249 print_char(0x7C);
250 } else {
251 print_char(0x5C);
252 }
253 }
254 return false;
255 break;
256 }
257 }
258 return true;
259
260} \ No newline at end of file
diff --git a/quantum/quantum.c b/quantum/quantum.c
index b5e2d60b9..f9f1ef22d 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -134,6 +134,9 @@ bool process_record_quantum(keyrecord_t *record) {
134 #ifdef UCIS_ENABLE 134 #ifdef UCIS_ENABLE
135 process_ucis(keycode, record) && 135 process_ucis(keycode, record) &&
136 #endif 136 #endif
137 #ifdef PRINTING_ENABLE
138 process_printer(keycode, record) &&
139 #endif
137 #ifdef UNICODEMAP_ENABLE 140 #ifdef UNICODEMAP_ENABLE
138 process_unicode_map(keycode, record) && 141 process_unicode_map(keycode, record) &&
139 #endif 142 #endif
@@ -806,6 +809,46 @@ void backlight_set(uint8_t level)
806#endif // backlight 809#endif // backlight
807 810
808 811
812// Functions for spitting out values
813//
814
815void send_dword(uint32_t number) { // this might not actually work
816 uint16_t word = (number >> 16);
817 send_word(word);
818 send_word(number & 0xFFFFUL);
819}
820
821void send_word(uint16_t number) {
822 uint8_t byte = number >> 8;
823 send_byte(byte);
824 send_byte(number & 0xFF);
825}
826
827void send_byte(uint8_t number) {
828 uint8_t nibble = number >> 4;
829 send_nibble(nibble);
830 send_nibble(number & 0xF);
831}
832
833void send_nibble(uint8_t number) {
834 switch (number) {
835 case 0:
836 register_code(KC_0);
837 unregister_code(KC_0);
838 break;
839 case 1 ... 9:
840 register_code(KC_1 + (number - 1));
841 unregister_code(KC_1 + (number - 1));
842 break;
843 case 0xA ... 0xF:
844 register_code(KC_A + (number - 0xA));
845 unregister_code(KC_A + (number - 0xA));
846 break;
847 }
848}
849
850
851
809 852
810__attribute__ ((weak)) 853__attribute__ ((weak))
811void led_set_user(uint8_t usb_led) { 854void led_set_user(uint8_t usb_led) {
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 0c6046649..3d35f11fa 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -59,6 +59,10 @@ extern uint32_t default_layer_state;
59 59
60#include "process_tap_dance.h" 60#include "process_tap_dance.h"
61 61
62#ifdef PRINTING_ENABLE
63 #include "process_printer.h"
64#endif
65
62#define SEND_STRING(str) send_string(PSTR(str)) 66#define SEND_STRING(str) send_string(PSTR(str))
63void send_string(const char *str); 67void send_string(const char *str);
64 68
@@ -106,6 +110,11 @@ void breathing_speed_dec(uint8_t value);
106#endif 110#endif
107 111
108#endif 112#endif
113void send_dword(uint32_t number);
114void send_word(uint16_t number);
115void send_byte(uint8_t number);
116void send_nibble(uint8_t number);
117
109 118
110void led_set_user(uint8_t usb_led); 119void led_set_user(uint8_t usb_led);
111void led_set_kb(uint8_t usb_led); 120void led_set_kb(uint8_t usb_led);
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index d550c5866..00620da58 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -69,11 +69,12 @@ const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {100, 50, 20};
69 69
70rgblight_config_t rgblight_config; 70rgblight_config_t rgblight_config;
71rgblight_config_t inmem_config; 71rgblight_config_t inmem_config;
72struct cRGB led[RGBLED_NUM];
73uint8_t rgblight_inited = 0;
74 72
73LED_TYPE led[RGBLED_NUM];
74uint8_t rgblight_inited = 0;
75bool rgblight_timer_enabled = false;
75 76
76void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) { 77void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
77 uint8_t r = 0, g = 0, b = 0, base, color; 78 uint8_t r = 0, g = 0, b = 0, base, color;
78 79
79 if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. 80 if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
@@ -124,7 +125,7 @@ void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) {
124 setrgb(r, g, b, led1); 125 setrgb(r, g, b, led1);
125} 126}
126 127
127void setrgb(uint8_t r, uint8_t g, uint8_t b, struct cRGB *led1) { 128void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) {
128 (*led1).r = r; 129 (*led1).r = r;
129 (*led1).g = g; 130 (*led1).g = g;
130 (*led1).b = b; 131 (*led1).b = b;
@@ -141,9 +142,9 @@ void eeconfig_update_rgblight_default(void) {
141 dprintf("eeconfig_update_rgblight_default\n"); 142 dprintf("eeconfig_update_rgblight_default\n");
142 rgblight_config.enable = 1; 143 rgblight_config.enable = 1;
143 rgblight_config.mode = 1; 144 rgblight_config.mode = 1;
144 rgblight_config.hue = 200; 145 rgblight_config.hue = 0;
145 rgblight_config.sat = 204; 146 rgblight_config.sat = 255;
146 rgblight_config.val = 204; 147 rgblight_config.val = 255;
147 eeconfig_update_rgblight(rgblight_config.raw); 148 eeconfig_update_rgblight(rgblight_config.raw);
148} 149}
149void eeconfig_debug_rgblight(void) { 150void eeconfig_debug_rgblight(void) {
@@ -173,7 +174,7 @@ void rgblight_init(void) {
173 } 174 }
174 eeconfig_debug_rgblight(); // display current eeprom values 175 eeconfig_debug_rgblight(); // display current eeprom values
175 176
176 #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) 177 #ifdef RGBLIGHT_ANIMATIONS
177 rgblight_timer_init(); // setup the timer 178 rgblight_timer_init(); // setup the timer
178 #endif 179 #endif
179 180
@@ -220,7 +221,7 @@ void rgblight_mode(uint8_t mode) {
220 eeconfig_update_rgblight(rgblight_config.raw); 221 eeconfig_update_rgblight(rgblight_config.raw);
221 xprintf("rgblight mode: %u\n", rgblight_config.mode); 222 xprintf("rgblight mode: %u\n", rgblight_config.mode);
222 if (rgblight_config.mode == 1) { 223 if (rgblight_config.mode == 1) {
223 #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) 224 #ifdef RGBLIGHT_ANIMATIONS
224 rgblight_timer_disable(); 225 rgblight_timer_disable();
225 #endif 226 #endif
226 } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 23) { 227 } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 23) {
@@ -230,7 +231,7 @@ void rgblight_mode(uint8_t mode) {
230 // MODE 15-20, snake 231 // MODE 15-20, snake
231 // MODE 21-23, knight 232 // MODE 21-23, knight
232 233
233 #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) 234 #ifdef RGBLIGHT_ANIMATIONS
234 rgblight_timer_enable(); 235 rgblight_timer_enable();
235 #endif 236 #endif
236 } 237 }
@@ -244,7 +245,7 @@ void rgblight_toggle(void) {
244 if (rgblight_config.enable) { 245 if (rgblight_config.enable) {
245 rgblight_mode(rgblight_config.mode); 246 rgblight_mode(rgblight_config.mode);
246 } else { 247 } else {
247 #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) 248 #ifdef RGBLIGHT_ANIMATIONS
248 rgblight_timer_disable(); 249 rgblight_timer_disable();
249 #endif 250 #endif
250 _delay_ms(50); 251 _delay_ms(50);
@@ -252,6 +253,13 @@ void rgblight_toggle(void) {
252 } 253 }
253} 254}
254 255
256void rgblight_enable(void) {
257 rgblight_config.enable = 1;
258 eeconfig_update_rgblight(rgblight_config.raw);
259 xprintf("rgblight enable: rgblight_config.enable = %u\n", rgblight_config.enable);
260 rgblight_mode(rgblight_config.mode);
261}
262
255 263
256void rgblight_increase_hue(void) { 264void rgblight_increase_hue(void) {
257 uint16_t hue; 265 uint16_t hue;
@@ -307,7 +315,7 @@ void rgblight_decrease_val(void) {
307void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { 315void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
308 inmem_config.raw = rgblight_config.raw; 316 inmem_config.raw = rgblight_config.raw;
309 if (rgblight_config.enable) { 317 if (rgblight_config.enable) {
310 struct cRGB tmp_led; 318 LED_TYPE tmp_led;
311 sethsv(hue, sat, val, &tmp_led); 319 sethsv(hue, sat, val, &tmp_led);
312 inmem_config.hue = hue; 320 inmem_config.hue = hue;
313 inmem_config.sat = sat; 321 inmem_config.sat = sat;
@@ -351,66 +359,78 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) {
351 359
352void rgblight_set(void) { 360void rgblight_set(void) {
353 if (rgblight_config.enable) { 361 if (rgblight_config.enable) {
354 ws2812_setleds(led, RGBLED_NUM); 362 #ifdef RGBW
363 ws2812_setleds_rgbw(led, RGBLED_NUM);
364 #else
365 ws2812_setleds(led, RGBLED_NUM);
366 #endif
355 } else { 367 } else {
356 for (uint8_t i = 0; i < RGBLED_NUM; i++) { 368 for (uint8_t i = 0; i < RGBLED_NUM; i++) {
357 led[i].r = 0; 369 led[i].r = 0;
358 led[i].g = 0; 370 led[i].g = 0;
359 led[i].b = 0; 371 led[i].b = 0;
360 } 372 }
361 ws2812_setleds(led, RGBLED_NUM); 373 #ifdef RGBW
374 ws2812_setleds_rgbw(led, RGBLED_NUM);
375 #else
376 ws2812_setleds(led, RGBLED_NUM);
377 #endif
362 } 378 }
363} 379}
364 380
365#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) 381#ifdef RGBLIGHT_ANIMATIONS
366 382
367// Animation timer -- AVR Timer3 383// Animation timer -- AVR Timer3
368void rgblight_timer_init(void) { 384void rgblight_timer_init(void) {
369 static uint8_t rgblight_timer_is_init = 0; 385 // static uint8_t rgblight_timer_is_init = 0;
370 if (rgblight_timer_is_init) { 386 // if (rgblight_timer_is_init) {
371 return; 387 // return;
372 } 388 // }
373 rgblight_timer_is_init = 1; 389 // rgblight_timer_is_init = 1;
374 /* Timer 3 setup */ 390 // /* Timer 3 setup */
375 TCCR3B = _BV(WGM32) //CTC mode OCR3A as TOP 391 // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP
376 | _BV(CS30); //Clock selelct: clk/1 392 // | _BV(CS30); // Clock selelct: clk/1
377 /* Set TOP value */ 393 // /* Set TOP value */
378 uint8_t sreg = SREG; 394 // uint8_t sreg = SREG;
379 cli(); 395 // cli();
380 OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff; 396 // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff;
381 OCR3AL = RGBLED_TIMER_TOP & 0xff; 397 // OCR3AL = RGBLED_TIMER_TOP & 0xff;
382 SREG = sreg; 398 // SREG = sreg;
399
400 rgblight_timer_enabled = true;
383} 401}
384void rgblight_timer_enable(void) { 402void rgblight_timer_enable(void) {
385 TIMSK3 |= _BV(OCIE3A); 403 rgblight_timer_enabled = true;
386 dprintf("TIMER3 enabled.\n"); 404 dprintf("TIMER3 enabled.\n");
387} 405}
388void rgblight_timer_disable(void) { 406void rgblight_timer_disable(void) {
389 TIMSK3 &= ~_BV(OCIE3A); 407 rgblight_timer_enabled = false;
390 dprintf("TIMER3 disabled.\n"); 408 dprintf("TIMER3 disabled.\n");
391} 409}
392void rgblight_timer_toggle(void) { 410void rgblight_timer_toggle(void) {
393 TIMSK3 ^= _BV(OCIE3A); 411 rgblight_timer_enabled ^= rgblight_timer_enabled;
394 dprintf("TIMER3 toggled.\n"); 412 dprintf("TIMER3 toggled.\n");
395} 413}
396 414
397ISR(TIMER3_COMPA_vect) { 415void rgblight_task(void) {
398 // mode = 1, static light, do nothing here 416 if (rgblight_timer_enabled) {
399 if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { 417 // mode = 1, static light, do nothing here
400 // mode = 2 to 5, breathing mode 418 if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) {
401 rgblight_effect_breathing(rgblight_config.mode - 2); 419 // mode = 2 to 5, breathing mode
402 } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 8) { 420 rgblight_effect_breathing(rgblight_config.mode - 2);
403 // mode = 6 to 8, rainbow mood mod 421 } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 8) {
404 rgblight_effect_rainbow_mood(rgblight_config.mode - 6); 422 // mode = 6 to 8, rainbow mood mod
405 } else if (rgblight_config.mode >= 9 && rgblight_config.mode <= 14) { 423 rgblight_effect_rainbow_mood(rgblight_config.mode - 6);
406 // mode = 9 to 14, rainbow swirl mode 424 } else if (rgblight_config.mode >= 9 && rgblight_config.mode <= 14) {
407 rgblight_effect_rainbow_swirl(rgblight_config.mode - 9); 425 // mode = 9 to 14, rainbow swirl mode
408 } else if (rgblight_config.mode >= 15 && rgblight_config.mode <= 20) { 426 rgblight_effect_rainbow_swirl(rgblight_config.mode - 9);
409 // mode = 15 to 20, snake mode 427 } else if (rgblight_config.mode >= 15 && rgblight_config.mode <= 20) {
410 rgblight_effect_snake(rgblight_config.mode - 15); 428 // mode = 15 to 20, snake mode
411 } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) { 429 rgblight_effect_snake(rgblight_config.mode - 15);
412 // mode = 21 to 23, knight mode 430 } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) {
413 rgblight_effect_knight(rgblight_config.mode - 21); 431 // mode = 21 to 23, knight mode
432 rgblight_effect_knight(rgblight_config.mode - 21);
433 }
414 } 434 }
415} 435}
416 436
@@ -449,7 +469,7 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) {
449 last_timer = timer_read(); 469 last_timer = timer_read();
450 for (i = 0; i < RGBLED_NUM; i++) { 470 for (i = 0; i < RGBLED_NUM; i++) {
451 hue = (360 / RGBLED_NUM * i + current_hue) % 360; 471 hue = (360 / RGBLED_NUM * i + current_hue) % 360;
452 sethsv(hue, rgblight_config.sat, rgblight_config.val, &led[i]); 472 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
453 } 473 }
454 rgblight_set(); 474 rgblight_set();
455 475
@@ -486,7 +506,7 @@ void rgblight_effect_snake(uint8_t interval) {
486 k = k + RGBLED_NUM; 506 k = k + RGBLED_NUM;
487 } 507 }
488 if (i == k) { 508 if (i == k) {
489 sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), &led[i]); 509 sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), (LED_TYPE *)&led[i]);
490 } 510 }
491 } 511 }
492 } 512 }
@@ -506,7 +526,7 @@ void rgblight_effect_knight(uint8_t interval) {
506 static uint16_t last_timer = 0; 526 static uint16_t last_timer = 0;
507 uint8_t i, j, cur; 527 uint8_t i, j, cur;
508 int8_t k; 528 int8_t k;
509 struct cRGB preled[RGBLED_NUM]; 529 LED_TYPE preled[RGBLED_NUM];
510 static int8_t increment = -1; 530 static int8_t increment = -1;
511 if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { 531 if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) {
512 return; 532 return;
@@ -525,7 +545,7 @@ void rgblight_effect_knight(uint8_t interval) {
525 k = RGBLED_NUM - 1; 545 k = RGBLED_NUM - 1;
526 } 546 }
527 if (i == k) { 547 if (i == k) {
528 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, &preled[i]); 548 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&preled[i]);
529 } 549 }
530 } 550 }
531 } 551 }
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index 17f04ffcf..a3673348e 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -1,8 +1,7 @@
1#ifndef RGBLIGHT_H 1#ifndef RGBLIGHT_H
2#define RGBLIGHT_H 2#define RGBLIGHT_H
3 3
4 4#ifdef RGBLIGHT_ANIMATIONS
5#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
6 #define RGBLIGHT_MODES 23 5 #define RGBLIGHT_MODES 23
7#else 6#else
8 #define RGBLIGHT_MODES 1 7 #define RGBLIGHT_MODES 1
@@ -34,6 +33,7 @@
34#endif 33#endif
35 34
36#define RGBLED_TIMER_TOP F_CPU/(256*64) 35#define RGBLED_TIMER_TOP F_CPU/(256*64)
36// #define RGBLED_TIMER_TOP 0xFF10
37 37
38#include <stdint.h> 38#include <stdint.h>
39#include <stdbool.h> 39#include <stdbool.h>
@@ -61,6 +61,7 @@ void rgblight_init(void);
61void rgblight_increase(void); 61void rgblight_increase(void);
62void rgblight_decrease(void); 62void rgblight_decrease(void);
63void rgblight_toggle(void); 63void rgblight_toggle(void);
64void rgblight_enable(void);
64void rgblight_step(void); 65void rgblight_step(void);
65void rgblight_mode(uint8_t mode); 66void rgblight_mode(uint8_t mode);
66void rgblight_set(void); 67void rgblight_set(void);
@@ -78,10 +79,13 @@ void eeconfig_update_rgblight(uint32_t val);
78void eeconfig_update_rgblight_default(void); 79void eeconfig_update_rgblight_default(void);
79void eeconfig_debug_rgblight(void); 80void eeconfig_debug_rgblight(void);
80 81
81void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1); 82void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1);
82void setrgb(uint8_t r, uint8_t g, uint8_t b, struct cRGB *led1); 83void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1);
83void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); 84void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
84 85
86
87void rgblight_task(void);
88
85void rgblight_timer_init(void); 89void rgblight_timer_init(void);
86void rgblight_timer_enable(void); 90void rgblight_timer_enable(void);
87void rgblight_timer_disable(void); 91void rgblight_timer_disable(void);