diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2015-09-14 23:54:49 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2015-09-14 23:54:49 -0400 |
| commit | 6ec03b22187fb3c16677c4c0583e66d6d6a5c4f1 (patch) | |
| tree | 37265cdf66290a33ce588e9b12ce0ecc816543c4 | |
| parent | 5bb7ef0012378cd800bff74680b08c587e6338e4 (diff) | |
| download | qmk_firmware-6ec03b22187fb3c16677c4c0583e66d6d6a5c4f1.tar.gz qmk_firmware-6ec03b22187fb3c16677c4c0583e66d6d6a5c4f1.zip | |
unicode working, i think
| -rw-r--r-- | keyboard/planck/Makefile | 7 | ||||
| -rw-r--r-- | keyboard/planck/keymap_common.c | 15 | ||||
| -rw-r--r-- | keyboard/planck/keymap_common.h | 4 | ||||
| -rw-r--r-- | keyboard/planck/keymap_unicode.c | 49 | ||||
| -rw-r--r-- | keyboard/planck/keymaps/keymap_monkey.c | 76 | ||||
| -rw-r--r-- | keyboard/planck/matrix_steno.c | 234 |
6 files changed, 383 insertions, 2 deletions
diff --git a/keyboard/planck/Makefile b/keyboard/planck/Makefile index ad0c82437..3ac20a55a 100644 --- a/keyboard/planck/Makefile +++ b/keyboard/planck/Makefile | |||
| @@ -125,13 +125,18 @@ COMMAND_ENABLE = yes # Commands for debug and configuration | |||
| 125 | #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | 125 | #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend |
| 126 | # NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA | 126 | # NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA |
| 127 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | 127 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality |
| 128 | MIDI_ENABLE = YES # MIDI controls | 128 | # MIDI_ENABLE = YES # MIDI controls |
| 129 | UNICODE_ENABLE = YES # MIDI controls | ||
| 129 | BACKLIGHT_ENABLE = yes | 130 | BACKLIGHT_ENABLE = yes |
| 130 | 131 | ||
| 131 | ifdef MIDI_ENABLE | 132 | ifdef MIDI_ENABLE |
| 132 | SRC += keymap_midi.c | 133 | SRC += keymap_midi.c |
| 133 | endif | 134 | endif |
| 134 | 135 | ||
| 136 | ifdef UNICODE_ENABLE | ||
| 137 | SRC += keymap_unicode.c | ||
| 138 | endif | ||
| 139 | |||
| 135 | # Optimize size but this may cause error "relocation truncated to fit" | 140 | # Optimize size but this may cause error "relocation truncated to fit" |
| 136 | #EXTRALDFLAGS = -Wl,--relax | 141 | #EXTRALDFLAGS = -Wl,--relax |
| 137 | 142 | ||
diff --git a/keyboard/planck/keymap_common.c b/keyboard/planck/keymap_common.c index 886bfe23c..dd6639113 100644 --- a/keyboard/planck/keymap_common.c +++ b/keyboard/planck/keymap_common.c | |||
| @@ -28,6 +28,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 28 | static action_t keycode_to_action(uint16_t keycode); | 28 | static action_t keycode_to_action(uint16_t keycode); |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | uint16_t hextokeycode(int hex) { | ||
| 32 | if (hex == 0x0) { | ||
| 33 | return KC_0; | ||
| 34 | } else if (hex < 0xA) { | ||
| 35 | return KC_1 + (hex - 0x1); | ||
| 36 | } else { | ||
| 37 | return KC_A + (hex - 0xA); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 31 | /* converts key to action */ | 41 | /* converts key to action */ |
| 32 | action_t action_for_key(uint8_t layer, keypos_t key) | 42 | action_t action_for_key(uint8_t layer, keypos_t key) |
| 33 | { | 43 | { |
| @@ -78,6 +88,11 @@ action_t action_for_key(uint8_t layer, keypos_t key) | |||
| 78 | action_t action; | 88 | action_t action; |
| 79 | action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8); | 89 | action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8); |
| 80 | return action; | 90 | return action; |
| 91 | } else if (keycode >= 0x8000 && keycode < 0x9000) { | ||
| 92 | action_t action; | ||
| 93 | uint16_t unicode = keycode & ~(0x8000); | ||
| 94 | action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8); | ||
| 95 | return action; | ||
| 81 | } | 96 | } |
| 82 | 97 | ||
| 83 | switch (keycode) { | 98 | switch (keycode) { |
diff --git a/keyboard/planck/keymap_common.h b/keyboard/planck/keymap_common.h index 7ccfa1b03..73df8424a 100644 --- a/keyboard/planck/keymap_common.h +++ b/keyboard/planck/keymap_common.h | |||
| @@ -176,6 +176,8 @@ extern const uint16_t fn_actions[]; | |||
| 176 | #define RESET 0x5000 | 176 | #define RESET 0x5000 |
| 177 | #define DEBUG 0x5001 | 177 | #define DEBUG 0x5001 |
| 178 | 178 | ||
| 179 | #define MIDI(n) n | 0x6000 | 179 | #define MIDI(n) (n | 0x6000) |
| 180 | |||
| 181 | #define UNI(n) (n | 0x8000) | ||
| 180 | 182 | ||
| 181 | #endif | 183 | #endif |
diff --git a/keyboard/planck/keymap_unicode.c b/keyboard/planck/keymap_unicode.c new file mode 100644 index 000000000..8e187d99f --- /dev/null +++ b/keyboard/planck/keymap_unicode.c | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2015 Jack Humbert <jack.humb@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "keymap_common.h" | ||
| 19 | |||
| 20 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) | ||
| 21 | { | ||
| 22 | |||
| 23 | if (record->event.pressed) { | ||
| 24 | uint16_t unicode = (opt << 8) | id; | ||
| 25 | register_code(KC_LALT); | ||
| 26 | |||
| 27 | register_code(hextokeycode((unicode & 0xF000) >> 12)); | ||
| 28 | unregister_code(hextokeycode((unicode & 0xF000) >> 12)); | ||
| 29 | register_code(hextokeycode((unicode & 0x0F00) >> 8)); | ||
| 30 | unregister_code(hextokeycode((unicode & 0x0F00) >> 8)); | ||
| 31 | register_code(hextokeycode((unicode & 0x00F0) >> 4)); | ||
| 32 | unregister_code(hextokeycode((unicode & 0x00F0) >> 4)); | ||
| 33 | register_code(hextokeycode((unicode & 0x000F))); | ||
| 34 | unregister_code(hextokeycode((unicode & 0x000F))); | ||
| 35 | |||
| 36 | /* Test 'a' */ | ||
| 37 | // register_code(hextokeycode(0x0)); | ||
| 38 | // unregister_code(hextokeycode(0x0)); | ||
| 39 | // register_code(hextokeycode(0x0)); | ||
| 40 | // unregister_code(hextokeycode(0x0)); | ||
| 41 | // register_code(hextokeycode(0x6)); | ||
| 42 | // unregister_code(hextokeycode(0x6)); | ||
| 43 | // register_code(hextokeycode(0x1)); | ||
| 44 | // unregister_code(hextokeycode(0x1)); | ||
| 45 | |||
| 46 | unregister_code(KC_LALT); | ||
| 47 | } | ||
| 48 | return; | ||
| 49 | } \ No newline at end of file | ||
diff --git a/keyboard/planck/keymaps/keymap_monkey.c b/keyboard/planck/keymaps/keymap_monkey.c new file mode 100644 index 000000000..c0c453408 --- /dev/null +++ b/keyboard/planck/keymaps/keymap_monkey.c | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | #include "keymap_common.h" | ||
| 2 | #include "backlight.h" | ||
| 3 | #include "debug.h" | ||
| 4 | |||
| 5 | #define COLEMAK_LAYER 0 | ||
| 6 | #define QWERTY_LAYER 1 | ||
| 7 | #define LOWER_LAYER 2 | ||
| 8 | #define UPPER_LAYER 3 | ||
| 9 | #define SPACEFN_LAYER 4 | ||
| 10 | #define TENKEY_LAYER 5 | ||
| 11 | |||
| 12 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 13 | [COLEMAK_LAYER] = { /* Colemak */ | ||
| 14 | {KC_TAB, UNI(0x0061), KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, | ||
| 15 | {KC_LCTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, | ||
| 16 | {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT}, | ||
| 17 | {FUNC(5), KC_ESC, KC_LGUI, KC_LALT, FUNC(1), FUNC(6), FUNC(6), FUNC(2), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} | ||
| 18 | }, | ||
| 19 | [QWERTY_LAYER] = { /* Qwerty */ | ||
| 20 | {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, | ||
| 21 | {KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, | ||
| 22 | {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT}, | ||
| 23 | {FUNC(5), KC_ESC, KC_LGUI, KC_LALT, FUNC(1), FUNC(6), FUNC(6), FUNC(2), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} | ||
| 24 | }, | ||
| 25 | [LOWER_LAYER] = { /* LOWER */ | ||
| 26 | {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DELETE}, | ||
| 27 | {KC_TRNS, FUNC(3), FUNC(4), RESET, DEBUG, KC_TRNS, KC_TRNS, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, | ||
| 28 | {KC_TRNS, KC_F11, KC_F12, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS}, | ||
| 29 | {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_PGUP, KC_END} | ||
| 30 | }, | ||
| 31 | [UPPER_LAYER] = { /* RAISE */ | ||
| 32 | {S(KC_GRV), S(KC_1), S(KC_2), S(KC_3), S(KC_4), S(KC_5), S(KC_6), S(KC_7), S(KC_8), S(KC_9), S(KC_0), KC_DELETE}, | ||
| 33 | {KC_CALC, FUNC(3), FUNC(4), RESET, DEBUG, KC_TRNS, KC_TRNS, S(KC_MINS), S(KC_EQL), S(KC_LBRC), S(KC_RBRC), S(KC_BSLS)}, | ||
| 34 | {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_TRNS}, | ||
| 35 | {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} | ||
| 36 | }, | ||
| 37 | [SPACEFN_LAYER] = { /* SpaceFN */ | ||
| 38 | {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_UP, KC_END, KC_TRNS, KC_TRNS}, | ||
| 39 | {KC_TRNS, FUNC(3), FUNC(4), KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_LEFT, KC_DOWN, KC_RIGHT, KC_TRNS, KC_TRNS}, | ||
| 40 | {KC_TRNS, KC_F11, KC_F12, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGDN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS}, | ||
| 41 | {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS} | ||
| 42 | }, | ||
| 43 | [TENKEY_LAYER] = { /* TENKEY */ | ||
| 44 | {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_7, KC_KP_8, KC_KP_9, KC_PMNS, KC_BSPC}, | ||
| 45 | {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_4, KC_KP_5, KC_KP_6, KC_PPLS, KC_NLCK}, | ||
| 46 | {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_1, KC_KP_2, KC_KP_3, KC_PDOT, KC_ENT}, | ||
| 47 | {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_SPC, KC_SPC, KC_KP_0, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS} | ||
| 48 | } | ||
| 49 | }; | ||
| 50 | |||
| 51 | const uint16_t PROGMEM fn_actions[] = { | ||
| 52 | [1] = ACTION_LAYER_TAP_KEY(LOWER_LAYER, KC_BSPC), // Tap for backspace, hold for LOWER | ||
| 53 | [2] = ACTION_LAYER_TAP_KEY(UPPER_LAYER, KC_ENT), // Tap for enter, hold for RAISE | ||
| 54 | |||
| 55 | [3] = ACTION_DEFAULT_LAYER_SET(COLEMAK_LAYER), | ||
| 56 | [4] = ACTION_DEFAULT_LAYER_SET(QWERTY_LAYER), | ||
| 57 | [5] = ACTION_LAYER_TOGGLE(TENKEY_LAYER), | ||
| 58 | |||
| 59 | [6] = ACTION_LAYER_TAP_KEY(SPACEFN_LAYER, KC_SPC), // Tap for space, hold for SpaceFN | ||
| 60 | }; | ||
| 61 | |||
| 62 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) | ||
| 63 | { | ||
| 64 | // MACRODOWN only works in this function | ||
| 65 | switch(id) { | ||
| 66 | case 0: | ||
| 67 | if (record->event.pressed) { | ||
| 68 | register_code(KC_RSFT); | ||
| 69 | backlight_step(); | ||
| 70 | } else { | ||
| 71 | unregister_code(KC_RSFT); | ||
| 72 | } | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | return MACRO_NONE; | ||
| 76 | }; \ No newline at end of file | ||
diff --git a/keyboard/planck/matrix_steno.c b/keyboard/planck/matrix_steno.c new file mode 100644 index 000000000..98ef55ed6 --- /dev/null +++ b/keyboard/planck/matrix_steno.c | |||
| @@ -0,0 +1,234 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako | ||
| 3 | Generated by planckkeyboard.com (2014 Jack Humbert) | ||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation, either version 2 of the License, or | ||
| 8 | (at your option) any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | */ | ||
| 18 | |||
| 19 | /* | ||
| 20 | * scan matrix | ||
| 21 | */ | ||
| 22 | #include <stdint.h> | ||
| 23 | #include <stdbool.h> | ||
| 24 | #include <avr/io.h> | ||
| 25 | #include <util/delay.h> | ||
| 26 | #include "print.h" | ||
| 27 | #include "debug.h" | ||
| 28 | #include "util.h" | ||
| 29 | #include "matrix.h" | ||
| 30 | |||
| 31 | #ifndef DEBOUNCE | ||
| 32 | # define DEBOUNCE 10 | ||
| 33 | #endif | ||
| 34 | static uint8_t debouncing = DEBOUNCE; | ||
| 35 | |||
| 36 | /* matrix state(1:on, 0:off) */ | ||
| 37 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 38 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 39 | |||
| 40 | static matrix_row_t read_cols(void); | ||
| 41 | static void init_cols(void); | ||
| 42 | static void unselect_rows(void); | ||
| 43 | static void select_row(uint8_t row); | ||
| 44 | |||
| 45 | inline | ||
| 46 | uint8_t matrix_rows(void) | ||
| 47 | { | ||
| 48 | return MATRIX_ROWS; | ||
| 49 | } | ||
| 50 | |||
| 51 | inline | ||
| 52 | uint8_t matrix_cols(void) | ||
| 53 | { | ||
| 54 | return MATRIX_COLS; | ||
| 55 | } | ||
| 56 | |||
| 57 | void matrix_init(void) | ||
| 58 | { | ||
| 59 | // To use PORTF disable JTAG with writing JTD bit twice within four cycles. | ||
| 60 | MCUCR |= (1<<JTD); | ||
| 61 | MCUCR |= (1<<JTD); | ||
| 62 | |||
| 63 | backlight_init_ports(); | ||
| 64 | |||
| 65 | // Turn status LED on | ||
| 66 | DDRE |= (1<<6); | ||
| 67 | PORTE |= (1<<6); | ||
| 68 | |||
| 69 | // initialize row and col | ||
| 70 | unselect_rows(); | ||
| 71 | init_cols(); | ||
| 72 | |||
| 73 | // initialize matrix state: all keys off | ||
| 74 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 75 | matrix[i] = 0; | ||
| 76 | matrix_debouncing[i] = 0; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | uint8_t matrix_scan(void) | ||
| 82 | { | ||
| 83 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 84 | select_row(i); | ||
| 85 | _delay_us(30); // without this wait read unstable value. | ||
| 86 | matrix_row_t cols = read_cols(); | ||
| 87 | if (matrix_debouncing[i] != cols) { | ||
| 88 | matrix_debouncing[i] = cols; | ||
| 89 | if (debouncing) { | ||
| 90 | debug("bounce!: "); debug_hex(debouncing); debug("\n"); | ||
| 91 | } | ||
| 92 | debouncing = DEBOUNCE; | ||
| 93 | } | ||
| 94 | unselect_rows(); | ||
| 95 | } | ||
| 96 | |||
| 97 | if (debouncing) { | ||
| 98 | if (--debouncing) { | ||
| 99 | _delay_ms(1); | ||
| 100 | } else { | ||
| 101 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 102 | matrix[i] = matrix_debouncing[i]; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | return 1; | ||
| 108 | } | ||
| 109 | |||
| 110 | bool matrix_is_modified(void) | ||
| 111 | { | ||
| 112 | if (debouncing) return false; | ||
| 113 | return true; | ||
| 114 | } | ||
| 115 | |||
| 116 | inline | ||
| 117 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 118 | { | ||
| 119 | return (matrix[row] & ((matrix_row_t)1<col)); | ||
| 120 | } | ||
| 121 | |||
| 122 | inline | ||
| 123 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 124 | { | ||
| 125 | return matrix[row]; | ||
| 126 | } | ||
| 127 | |||
| 128 | void matrix_print(void) | ||
| 129 | { | ||
| 130 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 131 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 132 | phex(row); print(": "); | ||
| 133 | pbin_reverse16(matrix_get_row(row)); | ||
| 134 | print("\n"); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | uint8_t matrix_key_count(void) | ||
| 139 | { | ||
| 140 | uint8_t count = 0; | ||
| 141 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 142 | count += bitpop16(matrix[i]); | ||
| 143 | } | ||
| 144 | return count; | ||
| 145 | } | ||
| 146 | |||
| 147 | static void init_cols(void) | ||
| 148 | { | ||
| 149 | int B = 0, C = 0, D = 0, E = 0, F = 0; | ||
| 150 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 151 | int col = COLS[x]; | ||
| 152 | if ((col & 0xF0) == 0x20) { | ||
| 153 | B |= (1<<(col & 0x0F)); | ||
| 154 | } else if ((col & 0xF0) == 0x30) { | ||
| 155 | C |= (1<<(col & 0x0F)); | ||
| 156 | } else if ((col & 0xF0) == 0x40) { | ||
| 157 | D |= (1<<(col & 0x0F)); | ||
| 158 | } else if ((col & 0xF0) == 0x50) { | ||
| 159 | E |= (1<<(col & 0x0F)); | ||
| 160 | } else if ((col & 0xF0) == 0x60) { | ||
| 161 | F |= (1<<(col & 0x0F)); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | DDRB &= ~(B); PORTB |= (B); | ||
| 165 | DDRC &= ~(C); PORTC |= (C); | ||
| 166 | DDRD &= ~(D); PORTD |= (D); | ||
| 167 | DDRE &= ~(E); PORTE |= (E); | ||
| 168 | DDRF &= ~(F); PORTF |= (F); | ||
| 169 | } | ||
| 170 | |||
| 171 | static matrix_row_t read_cols(void) | ||
| 172 | { | ||
| 173 | matrix_row_t result = 0; | ||
| 174 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 175 | int col = COLS[x]; | ||
| 176 | if ((col & 0xF0) == 0x20) { | ||
| 177 | result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<<x)); | ||
| 178 | } else if ((col & 0xF0) == 0x30) { | ||
| 179 | result |= (PINC&(1<<(col & 0x0F)) ? 0 : (1<<x)); | ||
| 180 | } else if ((col & 0xF0) == 0x40) { | ||
| 181 | result |= (PIND&(1<<(col & 0x0F)) ? 0 : (1<<x)); | ||
| 182 | } else if ((col & 0xF0) == 0x50) { | ||
| 183 | result |= (PINE&(1<<(col & 0x0F)) ? 0 : (1<<x)); | ||
| 184 | } else if ((col & 0xF0) == 0x60) { | ||
| 185 | result |= (PINF&(1<<(col & 0x0F)) ? 0 : (1<<x)); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | return result; | ||
| 189 | } | ||
| 190 | |||
| 191 | static void unselect_rows(void) | ||
| 192 | { | ||
| 193 | int B = 0, C = 0, D = 0, E = 0, F = 0; | ||
| 194 | for(int x = 0; x < MATRIX_ROWS; x++) { | ||
| 195 | int row = ROWS[x]; | ||
| 196 | if ((row & 0xF0) == 0x20) { | ||
| 197 | B |= (1<<(row & 0x0F)); | ||
| 198 | } else if ((row & 0xF0) == 0x30) { | ||
| 199 | C |= (1<<(row & 0x0F)); | ||
| 200 | } else if ((row & 0xF0) == 0x40) { | ||
| 201 | D |= (1<<(row & 0x0F)); | ||
| 202 | } else if ((row & 0xF0) == 0x50) { | ||
| 203 | E |= (1<<(row & 0x0F)); | ||
| 204 | } else if ((row & 0xF0) == 0x60) { | ||
| 205 | F |= (1<<(row & 0x0F)); | ||
| 206 | } | ||
| 207 | } | ||
| 208 | DDRB &= ~(B); PORTB |= (B); | ||
| 209 | DDRC &= ~(C); PORTC |= (C); | ||
| 210 | DDRD &= ~(D); PORTD |= (D); | ||
| 211 | DDRE &= ~(E); PORTE |= (E); | ||
| 212 | DDRF &= ~(F); PORTF |= (F); | ||
| 213 | } | ||
| 214 | |||
| 215 | static void select_row(uint8_t row) | ||
| 216 | { | ||
| 217 | int row_pin = ROWS[row]; | ||
| 218 | if ((row_pin & 0xF0) == 0x20) { | ||
| 219 | DDRB |= (1<<(row_pin & 0x0F)); | ||
| 220 | PORTB &= ~(1<<(row_pin & 0x0F)); | ||
| 221 | } else if ((row_pin & 0xF0) == 0x30) { | ||
| 222 | DDRC |= (1<<(row_pin & 0x0F)); | ||
| 223 | PORTC &= ~(1<<(row_pin & 0x0F)); | ||
| 224 | } else if ((row_pin & 0xF0) == 0x40) { | ||
| 225 | DDRD |= (1<<(row_pin & 0x0F)); | ||
| 226 | PORTD &= ~(1<<(row_pin & 0x0F)); | ||
| 227 | } else if ((row_pin & 0xF0) == 0x50) { | ||
| 228 | DDRE |= (1<<(row_pin & 0x0F)); | ||
| 229 | PORTE &= ~(1<<(row_pin & 0x0F)); | ||
| 230 | } else if ((row_pin & 0xF0) == 0x60) { | ||
| 231 | DDRF |= (1<<(row_pin & 0x0F)); | ||
| 232 | PORTF &= ~(1<<(row_pin & 0x0F)); | ||
| 233 | } | ||
| 234 | } \ No newline at end of file | ||
