diff options
Diffstat (limited to 'quantum/process_keycode/process_printer_bb.c')
| -rw-r--r-- | quantum/process_keycode/process_printer_bb.c | 260 |
1 files changed, 260 insertions, 0 deletions
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 | |||
| 4 | bool printing_enabled = false; | ||
| 5 | uint8_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 | |||
| 12 | inline static | ||
| 13 | void serial_delay(void) { | ||
| 14 | _delay_us(SERIAL_DELAY); | ||
| 15 | } | ||
| 16 | |||
| 17 | inline static | ||
| 18 | void serial_high(void) { | ||
| 19 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | ||
| 20 | } | ||
| 21 | |||
| 22 | inline static | ||
| 23 | void serial_low(void) { | ||
| 24 | SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; | ||
| 25 | } | ||
| 26 | |||
| 27 | inline static | ||
| 28 | void serial_output(void) { | ||
| 29 | SERIAL_PIN_DDR |= SERIAL_PIN_MASK; | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | void enabled_printing() { | ||
| 34 | printing_enabled = true; | ||
| 35 | serial_output(); | ||
| 36 | serial_high(); | ||
| 37 | } | ||
| 38 | |||
| 39 | void disable_printing() { | ||
| 40 | printing_enabled = false; | ||
| 41 | } | ||
| 42 | |||
| 43 | uint8_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 | |||
| 49 | void 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 | |||
| 62 | void print_string(char c[]) { | ||
| 63 | for(uint8_t i = 0; i < strlen(c); i++) | ||
| 64 | print_char(c[i]); | ||
| 65 | } | ||
| 66 | |||
| 67 | bool 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 | ||
