diff options
Diffstat (limited to 'keyboards/zinc/reva')
| -rw-r--r-- | keyboards/zinc/reva/config.h | 56 | ||||
| -rw-r--r-- | keyboards/zinc/reva/matrix.c | 357 | ||||
| -rw-r--r-- | keyboards/zinc/reva/reva.c | 1 | ||||
| -rw-r--r-- | keyboards/zinc/reva/reva.h | 15 | ||||
| -rw-r--r-- | keyboards/zinc/reva/rules.mk | 5 | ||||
| -rw-r--r-- | keyboards/zinc/reva/serial_config.h | 18 | ||||
| -rw-r--r-- | keyboards/zinc/reva/serial_config_simpleapi.h | 8 | ||||
| -rw-r--r-- | keyboards/zinc/reva/split_scomm.c | 95 | ||||
| -rw-r--r-- | keyboards/zinc/reva/split_scomm.h | 24 | ||||
| -rw-r--r-- | keyboards/zinc/reva/split_util.c | 70 | ||||
| -rw-r--r-- | keyboards/zinc/reva/split_util.h | 19 |
11 files changed, 36 insertions, 632 deletions
diff --git a/keyboards/zinc/reva/config.h b/keyboards/zinc/reva/config.h index 8eeb154ac..e94ffb7c6 100644 --- a/keyboards/zinc/reva/config.h +++ b/keyboards/zinc/reva/config.h | |||
| @@ -30,9 +30,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 30 | #define TAPPING_TERM 100 | 30 | #define TAPPING_TERM 100 |
| 31 | 31 | ||
| 32 | /* Use I2C or Serial */ | 32 | /* Use I2C or Serial */ |
| 33 | //#define USE_I2C | ||
| 34 | #define USE_SERIAL | 33 | #define USE_SERIAL |
| 35 | //#define USE_MATRIX_I2C | 34 | #define SOFT_SERIAL_PIN D2 |
| 36 | 35 | ||
| 37 | /* Select hand configuration */ | 36 | /* Select hand configuration */ |
| 38 | #define MASTER_LEFT | 37 | #define MASTER_LEFT |
| @@ -41,18 +40,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 41 | 40 | ||
| 42 | /* key matrix size */ | 41 | /* key matrix size */ |
| 43 | // Rows are doubled-up | 42 | // Rows are doubled-up |
| 44 | #define MATRIX_ROWS 8 | 43 | #define MATRIX_ROWS 8 |
| 45 | #define MATRIX_ROW_PINS { D4, C6, D7, E6 } | 44 | #define MATRIX_ROW_PINS { D4, C6, D7, E6 } |
| 46 | 45 | ||
| 47 | // wiring of each half | 46 | // wiring of each half |
| 48 | #define MATRIX_COLS 6 | 47 | #define MATRIX_COLS 6 |
| 49 | #define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3} | 48 | #define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3} |
| 50 | 49 | ||
| 51 | /* define if matrix has ghost */ | 50 | #define DIODE_DIRECTION COL2ROW |
| 52 | //#define MATRIX_HAS_GHOST | ||
| 53 | |||
| 54 | /* number of backlight levels */ | ||
| 55 | // #define BACKLIGHT_LEVELS 3 | ||
| 56 | 51 | ||
| 57 | /* Set 0 if debouncing isn't needed */ | 52 | /* Set 0 if debouncing isn't needed */ |
| 58 | #define DEBOUNCE 5 | 53 | #define DEBOUNCE 5 |
| @@ -64,25 +59,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 64 | 59 | ||
| 65 | /* ws2812 RGB LED */ | 60 | /* ws2812 RGB LED */ |
| 66 | #define RGB_DI_PIN D3 | 61 | #define RGB_DI_PIN D3 |
| 67 | #define RGBLIGHT_TIMER | ||
| 68 | //#define RGBLED_NUM 24 // Number of LEDs. see ./keymaps/default/config.h | ||
| 69 | #define ws2812_PORTREG PORTD | ||
| 70 | #define ws2812_DDRREG DDRD | ||
| 71 | 62 | ||
| 72 | // RGB LED support | 63 | // RGB LED support |
| 73 | //#define RGBLIGHT_ANIMATIONS : see ./rules.mk: LED_ANIMATIONS = yes or no | 64 | //#define RGBLIGHT_ANIMATIONS : see ./rules.mk: LED_ANIMATIONS = yes or no |
| 74 | // see ./rules.mk: LED_BACK_ENABLE or LED_UNDERGLOW_ENABLE set yes | 65 | // see ./rules.mk: LED_BACK_ENABLE or LED_UNDERGLOW_ENABLE set yes |
| 75 | #ifdef RGBLED_BACK | 66 | #ifdef RGBLIGHT_ENABLE |
| 76 | #define RGBLED_NUM 24 | 67 | #define RGBLIGHT_SPLIT |
| 77 | #else | 68 | #ifdef RGBLED_BACK |
| 78 | #define RGBLED_NUM 6 | 69 | #ifdef RGBLED_CONT |
| 70 | #define RGBLED_NUM 48 | ||
| 71 | #define RGBLED_SPLIT { 24, 24 } | ||
| 72 | #else | ||
| 73 | #define RGBLED_NUM 24 | ||
| 74 | #endif | ||
| 75 | #else | ||
| 76 | #ifdef RGBLED_BOTH | ||
| 77 | #ifdef RGBLED_CONT | ||
| 78 | #define RGBLED_NUM 60 | ||
| 79 | #define RGBLED_SPLIT { 30, 30 } | ||
| 80 | // #define RGBLIGHT_LED_MAP {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29} | ||
| 81 | #else | ||
| 82 | #define RGBLED_NUM 30 | ||
| 83 | #endif | ||
| 84 | #else | ||
| 85 | #ifdef RGBLED_CONT | ||
| 86 | #define RGBLED_NUM 12 | ||
| 87 | #define RGBLED_SPLIT { 6, 6 } | ||
| 88 | #else | ||
| 89 | #define RGBLED_NUM 6 | ||
| 90 | #endif | ||
| 91 | #endif | ||
| 92 | #endif | ||
| 79 | #endif | 93 | #endif |
| 80 | 94 | ||
| 81 | #ifndef IOS_DEVICE_ENABLE | 95 | #ifndef IOS_DEVICE_ENABLE |
| 82 | #if RGBLED_NUM <= 6 | 96 | #if (RGBLED_NUM <= 6) || (defined(RGBLED_CONT) && (RGBLED_NUM <= 12)) |
| 83 | #define RGBLIGHT_LIMIT_VAL 255 | 97 | #define RGBLIGHT_LIMIT_VAL 255 |
| 84 | #else | 98 | #else |
| 85 | #if RGBLED_NUM <= 16 | 99 | #if (RGBLED_NUM <= 16) || (defined(RGBLED_CONT) && (RGBLED_NUM <= 32)) |
| 86 | #define RGBLIGHT_LIMIT_VAL 130 | 100 | #define RGBLIGHT_LIMIT_VAL 130 |
| 87 | #else | 101 | #else |
| 88 | #define RGBLIGHT_LIMIT_VAL 120 | 102 | #define RGBLIGHT_LIMIT_VAL 120 |
| @@ -90,10 +104,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 90 | #endif | 104 | #endif |
| 91 | #define RGBLIGHT_VAL_STEP 17 | 105 | #define RGBLIGHT_VAL_STEP 17 |
| 92 | #else | 106 | #else |
| 93 | #if RGBLED_NUM <= 6 | 107 | #if (RGBLED_NUM <= 6) || (defined(RGBLED_CONT) && (RGBLED_NUM <= 12)) |
| 94 | #define RGBLIGHT_LIMIT_VAL 90 | 108 | #define RGBLIGHT_LIMIT_VAL 90 |
| 95 | #else | 109 | #else |
| 96 | #if RGBLED_NUM <= 16 | 110 | #if (RGBLED_NUM <= 16) || (defined(RGBLED_CONT) && (RGBLED_NUM <= 32)) |
| 97 | #define RGBLIGHT_LIMIT_VAL 45 | 111 | #define RGBLIGHT_LIMIT_VAL 45 |
| 98 | #else | 112 | #else |
| 99 | #define RGBLIGHT_LIMIT_VAL 35 | 113 | #define RGBLIGHT_LIMIT_VAL 35 |
diff --git a/keyboards/zinc/reva/matrix.c b/keyboards/zinc/reva/matrix.c deleted file mode 100644 index 5b58500db..000000000 --- a/keyboards/zinc/reva/matrix.c +++ /dev/null | |||
| @@ -1,357 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@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 | /* | ||
| 19 | * scan matrix | ||
| 20 | */ | ||
| 21 | #include <stdint.h> | ||
| 22 | #include <stdbool.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <avr/io.h> | ||
| 25 | #include <avr/wdt.h> | ||
| 26 | #include <avr/interrupt.h> | ||
| 27 | #include <util/delay.h> | ||
| 28 | #include "print.h" | ||
| 29 | #include "debug.h" | ||
| 30 | #include "util.h" | ||
| 31 | #include "matrix.h" | ||
| 32 | #include "split_util.h" | ||
| 33 | #include "quantum.h" | ||
| 34 | |||
| 35 | #ifdef USE_MATRIX_I2C | ||
| 36 | # include "i2c.h" | ||
| 37 | #else // USE_SERIAL | ||
| 38 | # include "split_scomm.h" | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #ifndef DEBOUNCE | ||
| 42 | # define DEBOUNCE 5 | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #define ERROR_DISCONNECT_COUNT 5 | ||
| 46 | |||
| 47 | static uint8_t debouncing = DEBOUNCE; | ||
| 48 | static const int ROWS_PER_HAND = MATRIX_ROWS/2; | ||
| 49 | static uint8_t error_count = 0; | ||
| 50 | uint8_t is_master = 0 ; | ||
| 51 | |||
| 52 | static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | ||
| 53 | static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | ||
| 54 | |||
| 55 | /* matrix state(1:on, 0:off) */ | ||
| 56 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 57 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 58 | |||
| 59 | static matrix_row_t read_cols(void); | ||
| 60 | static void init_cols(void); | ||
| 61 | static void unselect_rows(void); | ||
| 62 | static void select_row(uint8_t row); | ||
| 63 | static uint8_t matrix_master_scan(void); | ||
| 64 | |||
| 65 | |||
| 66 | __attribute__ ((weak)) | ||
| 67 | void matrix_init_kb(void) { | ||
| 68 | matrix_init_user(); | ||
| 69 | } | ||
| 70 | |||
| 71 | __attribute__ ((weak)) | ||
| 72 | void matrix_scan_kb(void) { | ||
| 73 | matrix_scan_user(); | ||
| 74 | } | ||
| 75 | |||
| 76 | __attribute__ ((weak)) | ||
| 77 | void matrix_init_user(void) { | ||
| 78 | } | ||
| 79 | |||
| 80 | __attribute__ ((weak)) | ||
| 81 | void matrix_scan_user(void) { | ||
| 82 | } | ||
| 83 | |||
| 84 | inline | ||
| 85 | uint8_t matrix_rows(void) | ||
| 86 | { | ||
| 87 | return MATRIX_ROWS; | ||
| 88 | } | ||
| 89 | |||
| 90 | inline | ||
| 91 | uint8_t matrix_cols(void) | ||
| 92 | { | ||
| 93 | return MATRIX_COLS; | ||
| 94 | } | ||
| 95 | |||
| 96 | void matrix_init(void) | ||
| 97 | { | ||
| 98 | debug_enable = true; | ||
| 99 | debug_matrix = true; | ||
| 100 | debug_mouse = true; | ||
| 101 | // initialize row and col | ||
| 102 | unselect_rows(); | ||
| 103 | init_cols(); | ||
| 104 | |||
| 105 | setPinOutput(B0); | ||
| 106 | setPinOutput(D5); | ||
| 107 | writePinHigh(B0); | ||
| 108 | writePinHigh(D5); | ||
| 109 | |||
| 110 | // initialize matrix state: all keys off | ||
| 111 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 112 | matrix[i] = 0; | ||
| 113 | matrix_debouncing[i] = 0; | ||
| 114 | } | ||
| 115 | |||
| 116 | is_master = has_usb(); | ||
| 117 | |||
| 118 | matrix_init_quantum(); | ||
| 119 | } | ||
| 120 | |||
| 121 | uint8_t _matrix_scan(void) | ||
| 122 | { | ||
| 123 | // Right hand is stored after the left in the matirx so, we need to offset it | ||
| 124 | int offset = isLeftHand ? 0 : (ROWS_PER_HAND); | ||
| 125 | |||
| 126 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 127 | select_row(i); | ||
| 128 | _delay_us(30); // without this wait read unstable value. | ||
| 129 | matrix_row_t cols = read_cols(); | ||
| 130 | if (matrix_debouncing[i+offset] != cols) { | ||
| 131 | matrix_debouncing[i+offset] = cols; | ||
| 132 | debouncing = DEBOUNCE; | ||
| 133 | } | ||
| 134 | unselect_rows(); | ||
| 135 | } | ||
| 136 | |||
| 137 | if (debouncing) { | ||
| 138 | if (--debouncing) { | ||
| 139 | _delay_ms(1); | ||
| 140 | } else { | ||
| 141 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 142 | matrix[i+offset] = matrix_debouncing[i+offset]; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | return 1; | ||
| 148 | } | ||
| 149 | |||
| 150 | #ifdef USE_MATRIX_I2C | ||
| 151 | |||
| 152 | // Get rows from other half over i2c | ||
| 153 | int i2c_transaction(void) { | ||
| 154 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 155 | |||
| 156 | int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); | ||
| 157 | if (err) goto i2c_error; | ||
| 158 | |||
| 159 | // start of matrix stored at 0x00 | ||
| 160 | err = i2c_master_write(0x00); | ||
| 161 | if (err) goto i2c_error; | ||
| 162 | |||
| 163 | // Start read | ||
| 164 | err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); | ||
| 165 | if (err) goto i2c_error; | ||
| 166 | |||
| 167 | if (!err) { | ||
| 168 | int i; | ||
| 169 | for (i = 0; i < ROWS_PER_HAND-1; ++i) { | ||
| 170 | matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); | ||
| 171 | } | ||
| 172 | matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); | ||
| 173 | i2c_master_stop(); | ||
| 174 | } else { | ||
| 175 | i2c_error: // the cable is disconnceted, or something else went wrong | ||
| 176 | i2c_reset_state(); | ||
| 177 | return err; | ||
| 178 | } | ||
| 179 | |||
| 180 | return 0; | ||
| 181 | } | ||
| 182 | |||
| 183 | #else // USE_SERIAL | ||
| 184 | |||
| 185 | int serial_transaction(int master_changed) { | ||
| 186 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 187 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 188 | int ret=serial_update_buffers(master_changed); | ||
| 189 | #else | ||
| 190 | int ret=serial_update_buffers(); | ||
| 191 | #endif | ||
| 192 | if (ret ) { | ||
| 193 | if(ret==2) writePinLow(B0); | ||
| 194 | return 1; | ||
| 195 | } | ||
| 196 | writePinHigh(B0); | ||
| 197 | memcpy(&matrix[slaveOffset], | ||
| 198 | (void *)serial_slave_buffer, sizeof(serial_slave_buffer)); | ||
| 199 | return 0; | ||
| 200 | } | ||
| 201 | #endif | ||
| 202 | |||
| 203 | uint8_t matrix_scan(void) | ||
| 204 | { | ||
| 205 | if (is_master) { | ||
| 206 | matrix_master_scan(); | ||
| 207 | }else{ | ||
| 208 | matrix_slave_scan(); | ||
| 209 | int offset = (isLeftHand) ? ROWS_PER_HAND : 0; | ||
| 210 | memcpy(&matrix[offset], | ||
| 211 | (void *)serial_master_buffer, sizeof(serial_master_buffer)); | ||
| 212 | matrix_scan_quantum(); | ||
| 213 | } | ||
| 214 | return 1; | ||
| 215 | } | ||
| 216 | |||
| 217 | |||
| 218 | uint8_t matrix_master_scan(void) { | ||
| 219 | |||
| 220 | int ret = _matrix_scan(); | ||
| 221 | int mchanged = 1; | ||
| 222 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 223 | |||
| 224 | #ifdef USE_MATRIX_I2C | ||
| 225 | // for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 226 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 227 | // i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 228 | // } | ||
| 229 | #else // USE_SERIAL | ||
| 230 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 231 | mchanged = memcmp((void *)serial_master_buffer, | ||
| 232 | &matrix[offset], sizeof(serial_master_buffer)); | ||
| 233 | #endif | ||
| 234 | memcpy((void *)serial_master_buffer, | ||
| 235 | &matrix[offset], sizeof(serial_master_buffer)); | ||
| 236 | #endif | ||
| 237 | |||
| 238 | #ifdef USE_MATRIX_I2C | ||
| 239 | if( i2c_transaction() ) { | ||
| 240 | #else // USE_SERIAL | ||
| 241 | if( serial_transaction(mchanged) ) { | ||
| 242 | #endif | ||
| 243 | // turn on the indicator led when halves are disconnected | ||
| 244 | writePinLow(D5); | ||
| 245 | |||
| 246 | error_count++; | ||
| 247 | |||
| 248 | if (error_count > ERROR_DISCONNECT_COUNT) { | ||
| 249 | // reset other half if disconnected | ||
| 250 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 251 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 252 | matrix[slaveOffset+i] = 0; | ||
| 253 | } | ||
| 254 | } | ||
| 255 | } else { | ||
| 256 | // turn off the indicator led on no error | ||
| 257 | writePinHigh(D5); | ||
| 258 | error_count = 0; | ||
| 259 | } | ||
| 260 | matrix_scan_quantum(); | ||
| 261 | return ret; | ||
| 262 | } | ||
| 263 | |||
| 264 | void matrix_slave_scan(void) { | ||
| 265 | _matrix_scan(); | ||
| 266 | |||
| 267 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 268 | |||
| 269 | #ifdef USE_MATRIX_I2C | ||
| 270 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 271 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 272 | i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 273 | } | ||
| 274 | #else // USE_SERIAL | ||
| 275 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 276 | int change = 0; | ||
| 277 | #endif | ||
| 278 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 279 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 280 | if( serial_slave_buffer[i] != matrix[offset+i] ) | ||
| 281 | change = 1; | ||
| 282 | #endif | ||
| 283 | serial_slave_buffer[i] = matrix[offset+i]; | ||
| 284 | } | ||
| 285 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 286 | slave_buffer_change_count += change; | ||
| 287 | #endif | ||
| 288 | #endif | ||
| 289 | } | ||
| 290 | |||
| 291 | bool matrix_is_modified(void) | ||
| 292 | { | ||
| 293 | if (debouncing) return false; | ||
| 294 | return true; | ||
| 295 | } | ||
| 296 | |||
| 297 | inline | ||
| 298 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 299 | { | ||
| 300 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 301 | } | ||
| 302 | |||
| 303 | inline | ||
| 304 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 305 | { | ||
| 306 | return matrix[row]; | ||
| 307 | } | ||
| 308 | |||
| 309 | void matrix_print(void) | ||
| 310 | { | ||
| 311 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 312 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 313 | phex(row); print(": "); | ||
| 314 | pbin_reverse16(matrix_get_row(row)); | ||
| 315 | print("\n"); | ||
| 316 | } | ||
| 317 | } | ||
| 318 | |||
| 319 | uint8_t matrix_key_count(void) | ||
| 320 | { | ||
| 321 | uint8_t count = 0; | ||
| 322 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 323 | count += bitpop16(matrix[i]); | ||
| 324 | } | ||
| 325 | return count; | ||
| 326 | } | ||
| 327 | |||
| 328 | static void init_cols(void) | ||
| 329 | { | ||
| 330 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 331 | _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF); | ||
| 332 | _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF); | ||
| 333 | } | ||
| 334 | } | ||
| 335 | |||
| 336 | static matrix_row_t read_cols(void) | ||
| 337 | { | ||
| 338 | matrix_row_t result = 0; | ||
| 339 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 340 | result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x); | ||
| 341 | } | ||
| 342 | return result; | ||
| 343 | } | ||
| 344 | |||
| 345 | static void unselect_rows(void) | ||
| 346 | { | ||
| 347 | for(int x = 0; x < ROWS_PER_HAND; x++) { | ||
| 348 | _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF); | ||
| 349 | _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF); | ||
| 350 | } | ||
| 351 | } | ||
| 352 | |||
| 353 | static void select_row(uint8_t row) | ||
| 354 | { | ||
| 355 | _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF); | ||
| 356 | _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF); | ||
| 357 | } | ||
diff --git a/keyboards/zinc/reva/reva.c b/keyboards/zinc/reva/reva.c index 2ce08a07c..a9c2cfdba 100644 --- a/keyboards/zinc/reva/reva.c +++ b/keyboards/zinc/reva/reva.c | |||
| @@ -3,4 +3,3 @@ | |||
| 3 | void matrix_init_kb(void) { | 3 | void matrix_init_kb(void) { |
| 4 | matrix_init_user(); | 4 | matrix_init_user(); |
| 5 | }; | 5 | }; |
| 6 | |||
diff --git a/keyboards/zinc/reva/reva.h b/keyboards/zinc/reva/reva.h index aa1c408b0..1bf2c565a 100644 --- a/keyboards/zinc/reva/reva.h +++ b/keyboards/zinc/reva/reva.h | |||
| @@ -1,22 +1,7 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include "../zinc.h" | ||
| 4 | |||
| 5 | #include "quantum.h" | 3 | #include "quantum.h" |
| 6 | 4 | ||
| 7 | #ifdef RGBLIGHT_ENABLE | ||
| 8 | //rgb led driver | ||
| 9 | #include "ws2812.h" | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #ifdef USE_I2C | ||
| 13 | #include <stddef.h> | ||
| 14 | #ifdef __AVR__ | ||
| 15 | #include <avr/io.h> | ||
| 16 | #include <avr/interrupt.h> | ||
| 17 | #endif | ||
| 18 | #endif | ||
| 19 | |||
| 20 | // Standard Keymap | 5 | // Standard Keymap |
| 21 | // (TRRS jack on both halves are to the left side) | 6 | // (TRRS jack on both halves are to the left side) |
| 22 | #define LAYOUT( \ | 7 | #define LAYOUT( \ |
diff --git a/keyboards/zinc/reva/rules.mk b/keyboards/zinc/reva/rules.mk index 3ea61267a..83895bdcb 100644 --- a/keyboards/zinc/reva/rules.mk +++ b/keyboards/zinc/reva/rules.mk | |||
| @@ -1,4 +1 @@ | |||
| 1 | SRC += reva/matrix.c | SPLIT_KEYBOARD = yes \ No newline at end of file | |
| 2 | SRC += reva/split_util.c | ||
| 3 | SRC += reva/split_scomm.c | ||
| 4 | SRC += ws2812.c | ||
diff --git a/keyboards/zinc/reva/serial_config.h b/keyboards/zinc/reva/serial_config.h deleted file mode 100644 index 9fb5dfc67..000000000 --- a/keyboards/zinc/reva/serial_config.h +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | #ifndef SOFT_SERIAL_CONFIG_H | ||
| 2 | #define SOFT_SERIAL_CONFIG_H | ||
| 3 | |||
| 4 | #ifndef SOFT_SERIAL_PIN | ||
| 5 | /* Soft Serial defines */ | ||
| 6 | #define SOFT_SERIAL_PIN D2 | ||
| 7 | // OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5 | ||
| 8 | // // 1: about 137kbps (default) | ||
| 9 | // // 2: about 75kbps | ||
| 10 | // // 3: about 39kbps | ||
| 11 | // // 4: about 26kbps | ||
| 12 | // // 5: about 20kbps | ||
| 13 | #endif | ||
| 14 | |||
| 15 | //// USE flexible API (using multi-type transaction function) | ||
| 16 | #define SERIAL_USE_MULTI_TRANSACTION | ||
| 17 | |||
| 18 | #endif /* SOFT_SERIAL_CONFIG_H */ | ||
diff --git a/keyboards/zinc/reva/serial_config_simpleapi.h b/keyboards/zinc/reva/serial_config_simpleapi.h deleted file mode 100644 index e2d22a41e..000000000 --- a/keyboards/zinc/reva/serial_config_simpleapi.h +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | #ifndef SERIAL_CONFIG_SIMPLEAPI_H | ||
| 2 | #define SERIAL_CONFIG_SIMPLEAPI_H | ||
| 3 | |||
| 4 | #undef SERIAL_USE_MULTI_TRANSACTION | ||
| 5 | #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 6 | #define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 7 | |||
| 8 | #endif // SERIAL_CONFIG_SIMPLEAPI_H | ||
diff --git a/keyboards/zinc/reva/split_scomm.c b/keyboards/zinc/reva/split_scomm.c deleted file mode 100644 index 50d233ce9..000000000 --- a/keyboards/zinc/reva/split_scomm.c +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | #ifdef USE_SERIAL | ||
| 2 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 3 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 4 | |||
| 5 | #include <stdbool.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <stddef.h> | ||
| 8 | #include <split_scomm.h> | ||
| 9 | #include "serial.h" | ||
| 10 | #ifdef SERIAL_DEBUG_MODE | ||
| 11 | #include <avr/io.h> | ||
| 12 | #endif | ||
| 13 | #ifdef CONSOLE_ENABLE | ||
| 14 | #include <print.h> | ||
| 15 | #endif | ||
| 16 | |||
| 17 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
| 18 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
| 19 | uint8_t volatile status_com = 0; | ||
| 20 | uint8_t volatile status1 = 0; | ||
| 21 | uint8_t slave_buffer_change_count = 0; | ||
| 22 | uint8_t s_change_old = 0xff; | ||
| 23 | uint8_t s_change_new = 0xff; | ||
| 24 | |||
| 25 | SSTD_t transactions[] = { | ||
| 26 | #define GET_SLAVE_STATUS 0 | ||
| 27 | /* master buffer not changed, only recive slave_buffer_change_count */ | ||
| 28 | { (uint8_t *)&status_com, | ||
| 29 | 0, NULL, | ||
| 30 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 31 | }, | ||
| 32 | #define PUT_MASTER_GET_SLAVE_STATUS 1 | ||
| 33 | /* master buffer changed need send, and recive slave_buffer_change_count */ | ||
| 34 | { (uint8_t *)&status_com, | ||
| 35 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
| 36 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 37 | }, | ||
| 38 | #define GET_SLAVE_BUFFER 2 | ||
| 39 | /* recive serial_slave_buffer */ | ||
| 40 | { (uint8_t *)&status1, | ||
| 41 | 0, NULL, | ||
| 42 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
| 43 | } | ||
| 44 | }; | ||
| 45 | |||
| 46 | void serial_master_init(void) | ||
| 47 | { | ||
| 48 | soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); | ||
| 49 | } | ||
| 50 | |||
| 51 | void serial_slave_init(void) | ||
| 52 | { | ||
| 53 | soft_serial_target_init(transactions, TID_LIMIT(transactions)); | ||
| 54 | } | ||
| 55 | |||
| 56 | // 0 => no error | ||
| 57 | // 1 => slave did not respond | ||
| 58 | // 2 => checksum error | ||
| 59 | int serial_update_buffers(int master_update) | ||
| 60 | { | ||
| 61 | int status, smatstatus; | ||
| 62 | static int need_retry = 0; | ||
| 63 | |||
| 64 | if( s_change_old != s_change_new ) { | ||
| 65 | smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER); | ||
| 66 | if( smatstatus == TRANSACTION_END ) { | ||
| 67 | s_change_old = s_change_new; | ||
| 68 | #ifdef CONSOLE_ENABLE | ||
| 69 | uprintf("slave matrix = %b %b %b %b %b\n", | ||
| 70 | serial_slave_buffer[0], serial_slave_buffer[1], | ||
| 71 | serial_slave_buffer[2], serial_slave_buffer[3], | ||
| 72 | serial_slave_buffer[4] ); | ||
| 73 | #endif | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | // serial_slave_buffer dosen't change | ||
| 77 | smatstatus = TRANSACTION_END; // dummy status | ||
| 78 | } | ||
| 79 | |||
| 80 | if( !master_update && !need_retry) { | ||
| 81 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
| 82 | } else { | ||
| 83 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
| 84 | } | ||
| 85 | if( status == TRANSACTION_END ) { | ||
| 86 | s_change_new = slave_buffer_change_count; | ||
| 87 | need_retry = 0; | ||
| 88 | } else { | ||
| 89 | need_retry = 1; | ||
| 90 | } | ||
| 91 | return smatstatus; | ||
| 92 | } | ||
| 93 | |||
| 94 | #endif // SERIAL_USE_MULTI_TRANSACTION | ||
| 95 | #endif /* USE_SERIAL */ | ||
diff --git a/keyboards/zinc/reva/split_scomm.h b/keyboards/zinc/reva/split_scomm.h deleted file mode 100644 index 873d8939d..000000000 --- a/keyboards/zinc/reva/split_scomm.h +++ /dev/null | |||
| @@ -1,24 +0,0 @@ | |||
| 1 | #ifndef SPLIT_COMM_H | ||
| 2 | #define SPLIT_COMM_H | ||
| 3 | |||
| 4 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 5 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */ | ||
| 6 | #include "serial.h" | ||
| 7 | |||
| 8 | #else | ||
| 9 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 10 | // Buffers for master - slave communication | ||
| 11 | #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 12 | #define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 13 | |||
| 14 | extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; | ||
| 15 | extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; | ||
| 16 | extern uint8_t slave_buffer_change_count; | ||
| 17 | |||
| 18 | void serial_master_init(void); | ||
| 19 | void serial_slave_init(void); | ||
| 20 | int serial_update_buffers(int master_changed); | ||
| 21 | |||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif /* SPLIT_COMM_H */ | ||
diff --git a/keyboards/zinc/reva/split_util.c b/keyboards/zinc/reva/split_util.c deleted file mode 100644 index e1ff8b437..000000000 --- a/keyboards/zinc/reva/split_util.c +++ /dev/null | |||
| @@ -1,70 +0,0 @@ | |||
| 1 | #include <avr/io.h> | ||
| 2 | #include <avr/wdt.h> | ||
| 3 | #include <avr/power.h> | ||
| 4 | #include <avr/interrupt.h> | ||
| 5 | #include <util/delay.h> | ||
| 6 | #include <avr/eeprom.h> | ||
| 7 | #include "split_util.h" | ||
| 8 | #include "matrix.h" | ||
| 9 | #include "keyboard.h" | ||
| 10 | |||
| 11 | #ifdef USE_MATRIX_I2C | ||
| 12 | # include "i2c.h" | ||
| 13 | #else | ||
| 14 | # include "split_scomm.h" | ||
| 15 | #endif | ||
| 16 | |||
| 17 | volatile bool isLeftHand = true; | ||
| 18 | |||
| 19 | static void setup_handedness(void) { | ||
| 20 | #ifdef EE_HANDS | ||
| 21 | isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); | ||
| 22 | #else | ||
| 23 | // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c | ||
| 24 | #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) | ||
| 25 | isLeftHand = !has_usb(); | ||
| 26 | #else | ||
| 27 | isLeftHand = has_usb(); | ||
| 28 | #endif | ||
| 29 | #endif | ||
| 30 | } | ||
| 31 | |||
| 32 | static void keyboard_master_setup(void) { | ||
| 33 | |||
| 34 | #ifdef USE_MATRIX_I2C | ||
| 35 | i2c_master_init(); | ||
| 36 | #else | ||
| 37 | serial_master_init(); | ||
| 38 | #endif | ||
| 39 | } | ||
| 40 | |||
| 41 | static void keyboard_slave_setup(void) { | ||
| 42 | |||
| 43 | #ifdef USE_MATRIX_I2C | ||
| 44 | i2c_slave_init(SLAVE_I2C_ADDRESS); | ||
| 45 | #else | ||
| 46 | serial_slave_init(); | ||
| 47 | #endif | ||
| 48 | } | ||
| 49 | |||
| 50 | bool has_usb(void) { | ||
| 51 | USBCON |= (1 << OTGPADE); //enables VBUS pad | ||
| 52 | _delay_us(5); | ||
| 53 | return (USBSTA & (1<<VBUS)); //checks state of VBUS | ||
| 54 | } | ||
| 55 | |||
| 56 | void split_keyboard_setup(void) { | ||
| 57 | setup_handedness(); | ||
| 58 | |||
| 59 | if (has_usb()) { | ||
| 60 | keyboard_master_setup(); | ||
| 61 | } else { | ||
| 62 | keyboard_slave_setup(); | ||
| 63 | } | ||
| 64 | sei(); | ||
| 65 | } | ||
| 66 | |||
| 67 | // this code runs before the usb and keyboard is initialized | ||
| 68 | void matrix_setup(void) { | ||
| 69 | split_keyboard_setup(); | ||
| 70 | } | ||
diff --git a/keyboards/zinc/reva/split_util.h b/keyboards/zinc/reva/split_util.h deleted file mode 100644 index 687ca19bd..000000000 --- a/keyboards/zinc/reva/split_util.h +++ /dev/null | |||
| @@ -1,19 +0,0 @@ | |||
| 1 | #ifndef SPLIT_KEYBOARD_UTIL_H | ||
| 2 | #define SPLIT_KEYBOARD_UTIL_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include "eeconfig.h" | ||
| 6 | |||
| 7 | #define SLAVE_I2C_ADDRESS 0x32 | ||
| 8 | |||
| 9 | extern volatile bool isLeftHand; | ||
| 10 | |||
| 11 | // slave version of matix scan, defined in matrix.c | ||
| 12 | void matrix_slave_scan(void); | ||
| 13 | |||
| 14 | void split_keyboard_setup(void); | ||
| 15 | bool has_usb(void); | ||
| 16 | |||
| 17 | void matrix_master_OLED_init (void); | ||
| 18 | |||
| 19 | #endif | ||
