diff options
Diffstat (limited to 'keyboards/sixkeyboard/matrix.c')
| -rw-r--r-- | keyboards/sixkeyboard/matrix.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/keyboards/sixkeyboard/matrix.c b/keyboards/sixkeyboard/matrix.c new file mode 100644 index 000000000..6dc93cda1 --- /dev/null +++ b/keyboards/sixkeyboard/matrix.c | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | /* | ||
| 2 | |||
| 3 | Note for ErgoDox EZ customizers: Here be dragons! | ||
| 4 | This is not a file you want to be messing with. | ||
| 5 | All of the interesting stuff for you is under keymaps/ :) | ||
| 6 | Love, Erez | ||
| 7 | |||
| 8 | Copyright 2013 Oleg Kostyuk <cub.uanic@gmail.com> | ||
| 9 | |||
| 10 | This program is free software: you can redistribute it and/or modify | ||
| 11 | it under the terms of the GNU General Public License as published by | ||
| 12 | the Free Software Foundation, either version 2 of the License, or | ||
| 13 | (at your option) any later version. | ||
| 14 | |||
| 15 | This program is distributed in the hope that it will be useful, | ||
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | GNU General Public License for more details. | ||
| 19 | |||
| 20 | You should have received a copy of the GNU General Public License | ||
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 22 | */ | ||
| 23 | |||
| 24 | /* | ||
| 25 | * scan matrix | ||
| 26 | */ | ||
| 27 | #include <stdint.h> | ||
| 28 | #include <stdbool.h> | ||
| 29 | #include <avr/io.h> | ||
| 30 | #include <util/delay.h> | ||
| 31 | #include "action_layer.h" | ||
| 32 | #include "print.h" | ||
| 33 | #include "debug.h" | ||
| 34 | #include "util.h" | ||
| 35 | #include "matrix.h" | ||
| 36 | #include "sixkeyboard.h" | ||
| 37 | |||
| 38 | /* matrix state(1:on, 0:off) */ | ||
| 39 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 40 | |||
| 41 | __attribute__ ((weak)) | ||
| 42 | void matrix_init_kb(void) { | ||
| 43 | } | ||
| 44 | |||
| 45 | __attribute__ ((weak)) | ||
| 46 | void matrix_scan_kb(void) { | ||
| 47 | } | ||
| 48 | |||
| 49 | inline | ||
| 50 | uint8_t matrix_rows(void) | ||
| 51 | { | ||
| 52 | return MATRIX_ROWS; | ||
| 53 | } | ||
| 54 | |||
| 55 | inline | ||
| 56 | uint8_t matrix_cols(void) | ||
| 57 | { | ||
| 58 | return MATRIX_COLS; | ||
| 59 | } | ||
| 60 | |||
| 61 | void matrix_init(void) | ||
| 62 | { | ||
| 63 | |||
| 64 | DDRC &= ~(1<<7); | ||
| 65 | PORTC |= (1<<7); | ||
| 66 | DDRB &= ~(1<<7 | 1<<5); | ||
| 67 | PORTB |= (1<<7 | 1<<5); | ||
| 68 | DDRD &= ~(1<<6 | 1<<4 | 1<<1); | ||
| 69 | PORTD |= (1<<6 | 1<<4 | 1<<1); | ||
| 70 | |||
| 71 | matrix_init_kb(); | ||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 | uint8_t matrix_scan(void) | ||
| 76 | { | ||
| 77 | matrix[0] = (PINC&(1<<7) ? 0 : (1<<0)) | (PINB&(1<<7) ? 0 : (1<<1)) | (PINB&(1<<5) ? 0 : (1<<2)); | ||
| 78 | matrix[1] = (PIND&(1<<6) ? 0 : (1<<0)) | (PIND&(1<<1) ? 0 : (1<<1)) | (PIND&(1<<4) ? 0 : (1<<2)); | ||
| 79 | |||
| 80 | matrix_scan_kb(); | ||
| 81 | |||
| 82 | return 1; | ||
| 83 | } | ||
| 84 | |||
| 85 | bool matrix_is_modified(void) | ||
| 86 | { | ||
| 87 | return true; | ||
| 88 | } | ||
| 89 | |||
| 90 | inline | ||
| 91 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 92 | { | ||
| 93 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 94 | } | ||
| 95 | |||
| 96 | inline | ||
| 97 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 98 | { | ||
| 99 | return matrix[row]; | ||
| 100 | } | ||
| 101 | |||
| 102 | void matrix_print(void) | ||
| 103 | { | ||
| 104 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 105 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 106 | phex(row); print(": "); | ||
| 107 | pbin_reverse16(matrix_get_row(row)); | ||
| 108 | print("\n"); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | uint8_t matrix_key_count(void) | ||
| 113 | { | ||
| 114 | uint8_t count = 0; | ||
| 115 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 116 | count += bitpop16(matrix[i]); | ||
| 117 | } | ||
| 118 | return count; | ||
| 119 | } | ||
| 120 | |||
