aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_printer_bb.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode/process_printer_bb.c')
-rw-r--r--quantum/process_keycode/process_printer_bb.c435
1 files changed, 209 insertions, 226 deletions
diff --git a/quantum/process_keycode/process_printer_bb.c b/quantum/process_keycode/process_printer_bb.c
index 3a00f169d..e482d8259 100644
--- a/quantum/process_keycode/process_printer_bb.c
+++ b/quantum/process_keycode/process_printer_bb.c
@@ -17,44 +17,29 @@
17#include "process_printer.h" 17#include "process_printer.h"
18#include "action_util.h" 18#include "action_util.h"
19 19
20bool printing_enabled = false; 20bool printing_enabled = false;
21uint8_t character_shift = 0; 21uint8_t character_shift = 0;
22 22
23#define SERIAL_PIN_DDR DDRD 23#define SERIAL_PIN_DDR DDRD
24#define SERIAL_PIN_PORT PORTD 24#define SERIAL_PIN_PORT PORTD
25#define SERIAL_PIN_MASK _BV(PD3) 25#define SERIAL_PIN_MASK _BV(PD3)
26#define SERIAL_DELAY 52 26#define SERIAL_DELAY 52
27 27
28inline static 28inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
29void serial_delay(void) {
30 _delay_us(SERIAL_DELAY);
31}
32 29
33inline static 30inline static void serial_high(void) { SERIAL_PIN_PORT |= SERIAL_PIN_MASK; }
34void serial_high(void) {
35 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
36}
37 31
38inline static 32inline static void serial_low(void) { SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; }
39void serial_low(void) {
40 SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
41}
42
43inline static
44void serial_output(void) {
45 SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
46}
47 33
34inline static void serial_output(void) { SERIAL_PIN_DDR |= SERIAL_PIN_MASK; }
48 35
49void enable_printing() { 36void enable_printing() {
50 printing_enabled = true; 37 printing_enabled = true;
51 serial_output(); 38 serial_output();
52 serial_high(); 39 serial_high();
53} 40}
54 41
55void disable_printing() { 42void disable_printing() { printing_enabled = false; }
56 printing_enabled = false;
57}
58 43
59uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; 44uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
60 45
@@ -63,214 +48,212 @@ uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0
63// keycode_to_ascii[KC_MINS] = {0x2D, 0x5F}; 48// keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
64 49
65void print_char(char c) { 50void print_char(char c) {
66 uint8_t b = 8; 51 uint8_t b = 8;
67 serial_output(); 52 serial_output();
68 while( b-- ) { 53 while (b--) {
69 if(c & (1 << b)) { 54 if (c & (1 << b)) {
70 serial_high(); 55 serial_high();
71 } else { 56 } else {
72 serial_low(); 57 serial_low();
58 }
59 serial_delay();
73 } 60 }
74 serial_delay();
75 }
76} 61}
77 62
78void print_string(char c[]) { 63void print_string(char c[]) {
79 for(uint8_t i = 0; i < strlen(c); i++) 64 for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]);
80 print_char(c[i]);
81} 65}
82 66
83bool process_printer(uint16_t keycode, keyrecord_t *record) { 67bool process_printer(uint16_t keycode, keyrecord_t *record) {
84 if (keycode == PRINT_ON) { 68 if (keycode == PRINT_ON) {
85 enable_printing(); 69 enable_printing();
86 return false; 70 return false;
87 } 71 }
88 if (keycode == PRINT_OFF) { 72 if (keycode == PRINT_OFF) {
89 disable_printing(); 73 disable_printing();
90 return false; 74 return false;
91 } 75 }
92
93 if (printing_enabled) {
94 switch(keycode) {
95 case KC_EXLM ... KC_RPRN:
96 case KC_UNDS:
97 case KC_PLUS:
98 case KC_LCBR:
99 case KC_RCBR:
100 case KC_PIPE:
101 case KC_TILD:
102 keycode &= 0xFF;
103 case KC_LSFT:
104 case KC_RSFT:
105 if (record->event.pressed) {
106 character_shift++;
107 } else {
108 character_shift--;
109 }
110 return false;
111 break;
112 }
113 76
114 switch(keycode) { 77 if (printing_enabled) {
115 case KC_F1: 78 switch (keycode) {
116 if (record->event.pressed) { 79 case KC_EXLM ... KC_RPRN:
117 print_string("This is a line of text!\n\n\n"); 80 case KC_UNDS:
118 } 81 case KC_PLUS:
119 return false; 82 case KC_LCBR:
120 case KC_ESC: 83 case KC_RCBR:
121 if (record->event.pressed) { 84 case KC_PIPE:
122 print_char(0x1B); 85 case KC_TILD:
123 } 86 keycode &= 0xFF;
124 return false; 87 case KC_LSFT:
125 break; 88 case KC_RSFT:
126 case KC_SPC: 89 if (record->event.pressed) {
127 if (record->event.pressed) { 90 character_shift++;
128 print_char(0x20); 91 } else {
129 } 92 character_shift--;
130 return false; 93 }
131 break; 94 return false;
132 case KC_A ... KC_Z: 95 break;
133 if (record->event.pressed) { 96 }
134 if (character_shift) {
135 print_char(0x41 + (keycode - KC_A));
136 } else {
137 print_char(0x61 + (keycode - KC_A));
138 }
139 }
140 return false;
141 break;
142 case KC_1 ... KC_0:
143 if (record->event.pressed) {
144 if (character_shift) {
145 print_char(shifted_numbers[keycode - KC_1]);
146 } else {
147 print_char(0x30 + ((keycode - KC_1 + 1) % 10));
148 }
149 }
150 return false;
151 break;
152 case KC_ENT:
153 if (record->event.pressed) {
154 if (character_shift) {
155 print_char(0x0C);
156 } else {
157 print_char(0x0A);
158 }
159 }
160 return false;
161 break;
162 case KC_BSPC:
163 if (record->event.pressed) {
164 if (character_shift) {
165 print_char(0x18);
166 } else {
167 print_char(0x1A);
168 }
169 }
170 return false;
171 break;
172 case KC_DOT:
173 if (record->event.pressed) {
174 if (character_shift) {
175 print_char(0x3E);
176 } else {
177 print_char(0x2E);
178 }
179 }
180 return false;
181 break;
182 case KC_COMM:
183 if (record->event.pressed) {
184 if (character_shift) {
185 print_char(0x3C);
186 } else {
187 print_char(0x2C);
188 }
189 }
190 return false;
191 break;
192 case KC_SLSH:
193 if (record->event.pressed) {
194 if (character_shift) {
195 print_char(0x3F);
196 } else {
197 print_char(0x2F);
198 }
199 }
200 return false;
201 break;
202 case KC_QUOT:
203 if (record->event.pressed) {
204 if (character_shift) {
205 print_char(0x22);
206 } else {
207 print_char(0x27);
208 }
209 }
210 return false;
211 break;
212 case KC_GRV:
213 if (record->event.pressed) {
214 if (character_shift) {
215 print_char(0x7E);
216 } else {
217 print_char(0x60);
218 }
219 }
220 return false;
221 break;
222 case KC_MINS:
223 if (record->event.pressed) {
224 if (character_shift) {
225 print_char(0x5F);
226 } else {
227 print_char(0x2D);
228 }
229 }
230 return false;
231 break;
232 case KC_EQL:
233 if (record->event.pressed) {
234 if (character_shift) {
235 print_char(0x2B);
236 } else {
237 print_char(0x3D);
238 }
239 }
240 return false;
241 break;
242 case KC_LBRC:
243 if (record->event.pressed) {
244 if (character_shift) {
245 print_char(0x7B);
246 } else {
247 print_char(0x5B);
248 }
249 }
250 return false;
251 break;
252 case KC_RBRC:
253 if (record->event.pressed) {
254 if (character_shift) {
255 print_char(0x7D);
256 } else {
257 print_char(0x5D);
258 }
259 }
260 return false;
261 break;
262 case KC_BSLS:
263 if (record->event.pressed) {
264 if (character_shift) {
265 print_char(0x7C);
266 } else {
267 print_char(0x5C);
268 }
269 }
270 return false;
271 break;
272 }
273 }
274 return true;
275 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;
276} 259}