diff options
| -rw-r--r-- | keyboards/fortitude60/config.h | 8 | ||||
| -rw-r--r-- | keyboards/fortitude60/fortitude60.h | 5 | ||||
| -rw-r--r-- | keyboards/fortitude60/keymaps/default/keymap.c | 17 | ||||
| -rw-r--r-- | keyboards/fortitude60/matrix.c | 423 | ||||
| -rw-r--r-- | keyboards/fortitude60/readme.md | 10 | ||||
| -rw-r--r-- | keyboards/fortitude60/rev1/config.h | 12 | ||||
| -rw-r--r-- | keyboards/fortitude60/rev1/rev1.c | 21 | ||||
| -rw-r--r-- | keyboards/fortitude60/rev1/rev1.h | 13 | ||||
| -rw-r--r-- | keyboards/fortitude60/rev1/rules.mk | 3 | ||||
| -rw-r--r-- | keyboards/fortitude60/rules.mk | 25 | ||||
| -rw-r--r-- | keyboards/fortitude60/serial.c | 589 | ||||
| -rw-r--r-- | keyboards/fortitude60/serial.h | 89 | ||||
| -rw-r--r-- | keyboards/fortitude60/serial_config.h | 10 | ||||
| -rw-r--r-- | keyboards/fortitude60/split_util.c | 85 | ||||
| -rw-r--r-- | keyboards/fortitude60/split_util.h | 18 |
15 files changed, 38 insertions, 1290 deletions
diff --git a/keyboards/fortitude60/config.h b/keyboards/fortitude60/config.h index 27a44ab92..7e9b510ff 100644 --- a/keyboards/fortitude60/config.h +++ b/keyboards/fortitude60/config.h | |||
| @@ -15,10 +15,4 @@ 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/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #ifndef CONFIG_H | 18 | #pragma once |
| 19 | #define CONFIG_H | ||
| 20 | |||
| 21 | #include "config_common.h" | ||
| 22 | #include <serial_config.h> | ||
| 23 | |||
| 24 | #endif // CONFIG_H | ||
diff --git a/keyboards/fortitude60/fortitude60.h b/keyboards/fortitude60/fortitude60.h index db2ce07a6..61404fa75 100644 --- a/keyboards/fortitude60/fortitude60.h +++ b/keyboards/fortitude60/fortitude60.h | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | #ifndef FORTITUDE60_H | 1 | #pragma once |
| 2 | #define FORTITUDE60_H | ||
| 3 | 2 | ||
| 4 | #ifdef KEYBOARD_fortitude60_rev1 | 3 | #ifdef KEYBOARD_fortitude60_rev1 |
| 5 | #include "rev1.h" | 4 | #include "rev1.h" |
| @@ -22,5 +21,3 @@ | |||
| 22 | KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##LT5, KC_##RT5, KC_##R30, KC_##R31, KC_##R32, KC_##R33, KC_##R34, KC_##R35, \ | 21 | KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##LT5, KC_##RT5, KC_##R30, KC_##R31, KC_##R32, KC_##R33, KC_##R34, KC_##R35, \ |
| 23 | KC_##LT0, KC_##LT1, KC_##LT2, KC_##LT3, KC_##LT4, KC_##RT4, KC_##RT3, KC_##RT2, KC_##RT1, KC_##RT0 \ | 22 | KC_##LT0, KC_##LT1, KC_##LT2, KC_##LT3, KC_##LT4, KC_##RT4, KC_##RT3, KC_##RT2, KC_##RT1, KC_##RT0 \ |
| 24 | ) | 23 | ) |
| 25 | |||
| 26 | #endif | ||
diff --git a/keyboards/fortitude60/keymaps/default/keymap.c b/keyboards/fortitude60/keymaps/default/keymap.c index c476fed85..8db5de904 100644 --- a/keyboards/fortitude60/keymaps/default/keymap.c +++ b/keyboards/fortitude60/keymaps/default/keymap.c | |||
| @@ -5,12 +5,14 @@ | |||
| 5 | // The underscores don't mean anything - you can have a layer called STUFF or any other name. | 5 | // The underscores don't mean anything - you can have a layer called STUFF or any other name. |
| 6 | // Layer names don't all need to be of the same length, obviously, and you can also skip them | 6 | // Layer names don't all need to be of the same length, obviously, and you can also skip them |
| 7 | // entirely and just use numbers. | 7 | // entirely and just use numbers. |
| 8 | #define _QWERTY 0 | 8 | enum my_layers { |
| 9 | #define _COLEMAK 1 | 9 | _QWERTY, |
| 10 | #define _DVORAK 2 | 10 | _COLEMAK, |
| 11 | #define _LOWER 3 | 11 | _DVORAK, |
| 12 | #define _RAISE 4 | 12 | _LOWER, |
| 13 | #define _ADJUST 16 | 13 | _RAISE, |
| 14 | _ADJUST | ||
| 15 | }; | ||
| 14 | 16 | ||
| 15 | enum custom_keycodes { | 17 | enum custom_keycodes { |
| 16 | QWERTY = SAFE_RANGE, | 18 | QWERTY = SAFE_RANGE, |
| @@ -166,19 +168,16 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 166 | set_single_persistent_default_layer(_QWERTY); | 168 | set_single_persistent_default_layer(_QWERTY); |
| 167 | } | 169 | } |
| 168 | return false; | 170 | return false; |
| 169 | break; | ||
| 170 | case COLEMAK: | 171 | case COLEMAK: |
| 171 | if (record->event.pressed) { | 172 | if (record->event.pressed) { |
| 172 | set_single_persistent_default_layer(_COLEMAK); | 173 | set_single_persistent_default_layer(_COLEMAK); |
| 173 | } | 174 | } |
| 174 | return false; | 175 | return false; |
| 175 | break; | ||
| 176 | case DVORAK: | 176 | case DVORAK: |
| 177 | if (record->event.pressed) { | 177 | if (record->event.pressed) { |
| 178 | set_single_persistent_default_layer(_DVORAK); | 178 | set_single_persistent_default_layer(_DVORAK); |
| 179 | } | 179 | } |
| 180 | return false; | 180 | return false; |
| 181 | break; | ||
| 182 | } | 181 | } |
| 183 | return true; | 182 | return true; |
| 184 | } | 183 | } |
diff --git a/keyboards/fortitude60/matrix.c b/keyboards/fortitude60/matrix.c deleted file mode 100644 index 9037d53a6..000000000 --- a/keyboards/fortitude60/matrix.c +++ /dev/null | |||
| @@ -1,423 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2017 Danny Nguyen <danny@keeb.io> | ||
| 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 <avr/io.h> | ||
| 24 | #include "wait.h" | ||
| 25 | #include "print.h" | ||
| 26 | #include "debug.h" | ||
| 27 | #include "util.h" | ||
| 28 | #include "matrix.h" | ||
| 29 | #include "split_util.h" | ||
| 30 | #include "pro_micro.h" | ||
| 31 | #include "config.h" | ||
| 32 | #include "timer.h" | ||
| 33 | |||
| 34 | #ifdef BACKLIGHT_ENABLE | ||
| 35 | #include "backlight.h" | ||
| 36 | extern backlight_config_t backlight_config; | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #include "serial.h" | ||
| 40 | |||
| 41 | #ifndef DEBOUNCE | ||
| 42 | # define DEBOUNCE 5 | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #if (DEBOUNCE > 0) | ||
| 46 | static uint16_t debouncing_time; | ||
| 47 | static bool debouncing = false; | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #if (MATRIX_COLS <= 8) | ||
| 51 | # define print_matrix_header() print("\nr/c 01234567\n") | ||
| 52 | # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) | ||
| 53 | # define matrix_bitpop(i) bitpop(matrix[i]) | ||
| 54 | # define ROW_SHIFTER ((uint8_t)1) | ||
| 55 | #else | ||
| 56 | # error "Currently only supports 8 COLS" | ||
| 57 | #endif | ||
| 58 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 59 | |||
| 60 | #define ERROR_DISCONNECT_COUNT 5 | ||
| 61 | |||
| 62 | #define SERIAL_LED_ADDR 0x00 | ||
| 63 | |||
| 64 | #define ROWS_PER_HAND (MATRIX_ROWS/2) | ||
| 65 | |||
| 66 | static uint8_t error_count = 0; | ||
| 67 | |||
| 68 | static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | ||
| 69 | static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | ||
| 70 | |||
| 71 | /* matrix state(1:on, 0:off) */ | ||
| 72 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 73 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 74 | |||
| 75 | #if (DIODE_DIRECTION == COL2ROW) | ||
| 76 | static void init_cols(void); | ||
| 77 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); | ||
| 78 | static void unselect_rows(void); | ||
| 79 | static void select_row(uint8_t row); | ||
| 80 | static void unselect_row(uint8_t row); | ||
| 81 | #elif (DIODE_DIRECTION == ROW2COL) | ||
| 82 | static void init_rows(void); | ||
| 83 | static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col); | ||
| 84 | static void unselect_cols(void); | ||
| 85 | static void unselect_col(uint8_t col); | ||
| 86 | static void select_col(uint8_t col); | ||
| 87 | #endif | ||
| 88 | |||
| 89 | |||
| 90 | __attribute__ ((weak)) | ||
| 91 | void matrix_init_kb(void) { | ||
| 92 | matrix_init_user(); | ||
| 93 | } | ||
| 94 | |||
| 95 | __attribute__ ((weak)) | ||
| 96 | void matrix_scan_kb(void) { | ||
| 97 | matrix_scan_user(); | ||
| 98 | } | ||
| 99 | |||
| 100 | __attribute__ ((weak)) | ||
| 101 | void matrix_init_user(void) { | ||
| 102 | } | ||
| 103 | |||
| 104 | __attribute__ ((weak)) | ||
| 105 | void matrix_scan_user(void) { | ||
| 106 | } | ||
| 107 | |||
| 108 | inline | ||
| 109 | uint8_t matrix_rows(void) | ||
| 110 | { | ||
| 111 | return MATRIX_ROWS; | ||
| 112 | } | ||
| 113 | |||
| 114 | inline | ||
| 115 | uint8_t matrix_cols(void) | ||
| 116 | { | ||
| 117 | return MATRIX_COLS; | ||
| 118 | } | ||
| 119 | |||
| 120 | void matrix_init(void) | ||
| 121 | { | ||
| 122 | debug_enable = true; | ||
| 123 | debug_matrix = true; | ||
| 124 | debug_mouse = true; | ||
| 125 | // initialize row and col | ||
| 126 | unselect_rows(); | ||
| 127 | init_cols(); | ||
| 128 | |||
| 129 | TX_RX_LED_INIT; | ||
| 130 | |||
| 131 | // initialize matrix state: all keys off | ||
| 132 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 133 | matrix[i] = 0; | ||
| 134 | matrix_debouncing[i] = 0; | ||
| 135 | } | ||
| 136 | |||
| 137 | matrix_init_quantum(); | ||
| 138 | |||
| 139 | } | ||
| 140 | |||
| 141 | uint8_t _matrix_scan(void) | ||
| 142 | { | ||
| 143 | int offset = isLeftHand ? 0 : (ROWS_PER_HAND); | ||
| 144 | #if (DIODE_DIRECTION == COL2ROW) | ||
| 145 | // Set row, read cols | ||
| 146 | for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { | ||
| 147 | # if (DEBOUNCE > 0) | ||
| 148 | bool matrix_changed = read_cols_on_row(matrix_debouncing+offset, current_row); | ||
| 149 | |||
| 150 | if (matrix_changed) { | ||
| 151 | debouncing = true; | ||
| 152 | debouncing_time = timer_read(); | ||
| 153 | } | ||
| 154 | |||
| 155 | # else | ||
| 156 | read_cols_on_row(matrix+offset, current_row); | ||
| 157 | # endif | ||
| 158 | |||
| 159 | } | ||
| 160 | |||
| 161 | #elif (DIODE_DIRECTION == ROW2COL) | ||
| 162 | // Set col, read rows | ||
| 163 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | ||
| 164 | # if (DEBOUNCE > 0) | ||
| 165 | bool matrix_changed = read_rows_on_col(matrix_debouncing+offset, current_col); | ||
| 166 | if (matrix_changed) { | ||
| 167 | debouncing = true; | ||
| 168 | debouncing_time = timer_read(); | ||
| 169 | } | ||
| 170 | # else | ||
| 171 | read_rows_on_col(matrix+offset, current_col); | ||
| 172 | # endif | ||
| 173 | |||
| 174 | } | ||
| 175 | #endif | ||
| 176 | |||
| 177 | # if (DEBOUNCE > 0) | ||
| 178 | if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCE)) { | ||
| 179 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 180 | matrix[i+offset] = matrix_debouncing[i+offset]; | ||
| 181 | } | ||
| 182 | debouncing = false; | ||
| 183 | } | ||
| 184 | # endif | ||
| 185 | |||
| 186 | return 1; | ||
| 187 | } | ||
| 188 | |||
| 189 | int serial_transaction(void) { | ||
| 190 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 191 | |||
| 192 | if (serial_update_buffers()) { | ||
| 193 | return 1; | ||
| 194 | } | ||
| 195 | |||
| 196 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 197 | matrix[slaveOffset+i] = serial_slave_buffer[i]; | ||
| 198 | } | ||
| 199 | |||
| 200 | #ifdef BACKLIGHT_ENABLE | ||
| 201 | // Write backlight level for slave to read | ||
| 202 | serial_master_buffer[SERIAL_LED_ADDR] = backlight_config.enable ? backlight_config.level : 0; | ||
| 203 | #endif | ||
| 204 | return 0; | ||
| 205 | } | ||
| 206 | |||
| 207 | |||
| 208 | uint8_t matrix_scan(void) | ||
| 209 | { | ||
| 210 | uint8_t ret = _matrix_scan(); | ||
| 211 | |||
| 212 | if( serial_transaction() ) { | ||
| 213 | // turn on the indicator led when halves are disconnected | ||
| 214 | TXLED1; | ||
| 215 | |||
| 216 | error_count++; | ||
| 217 | |||
| 218 | if (error_count > ERROR_DISCONNECT_COUNT) { | ||
| 219 | // reset other half if disconnected | ||
| 220 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 221 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 222 | matrix[slaveOffset+i] = 0; | ||
| 223 | } | ||
| 224 | } | ||
| 225 | } else { | ||
| 226 | // turn off the indicator led on no error | ||
| 227 | TXLED0; | ||
| 228 | error_count = 0; | ||
| 229 | } | ||
| 230 | matrix_scan_quantum(); | ||
| 231 | return ret; | ||
| 232 | } | ||
| 233 | |||
| 234 | void matrix_slave_scan(void) { | ||
| 235 | _matrix_scan(); | ||
| 236 | |||
| 237 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 238 | |||
| 239 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 240 | serial_slave_buffer[i] = matrix[offset+i]; | ||
| 241 | } | ||
| 242 | |||
| 243 | #ifdef BACKLIGHT_ENABLE | ||
| 244 | // Read backlight level sent from master and update level on slave | ||
| 245 | backlight_set(serial_master_buffer[SERIAL_LED_ADDR]); | ||
| 246 | #endif | ||
| 247 | } | ||
| 248 | |||
| 249 | bool matrix_is_modified(void) | ||
| 250 | { | ||
| 251 | if (debouncing) return false; | ||
| 252 | return true; | ||
| 253 | } | ||
| 254 | |||
| 255 | inline | ||
| 256 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 257 | { | ||
| 258 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 259 | } | ||
| 260 | |||
| 261 | inline | ||
| 262 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 263 | { | ||
| 264 | return matrix[row]; | ||
| 265 | } | ||
| 266 | |||
| 267 | void matrix_print(void) | ||
| 268 | { | ||
| 269 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 270 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 271 | phex(row); print(": "); | ||
| 272 | pbin_reverse16(matrix_get_row(row)); | ||
| 273 | print("\n"); | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | uint8_t matrix_key_count(void) | ||
| 278 | { | ||
| 279 | uint8_t count = 0; | ||
| 280 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 281 | count += bitpop16(matrix[i]); | ||
| 282 | } | ||
| 283 | return count; | ||
| 284 | } | ||
| 285 | |||
| 286 | #if (DIODE_DIRECTION == COL2ROW) | ||
| 287 | |||
| 288 | static void init_cols(void) | ||
| 289 | { | ||
| 290 | for(uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
| 291 | uint8_t pin = col_pins[x]; | ||
| 292 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 293 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | ||
| 298 | { | ||
| 299 | // Store last value of row prior to reading | ||
| 300 | matrix_row_t last_row_value = current_matrix[current_row]; | ||
| 301 | |||
| 302 | // Clear data in matrix row | ||
| 303 | current_matrix[current_row] = 0; | ||
| 304 | |||
| 305 | // Select row and wait for row selecton to stabilize | ||
| 306 | select_row(current_row); | ||
| 307 | wait_us(30); | ||
| 308 | |||
| 309 | // For each col... | ||
| 310 | for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | ||
| 311 | |||
| 312 | // Select the col pin to read (active low) | ||
| 313 | uint8_t pin = col_pins[col_index]; | ||
| 314 | uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)); | ||
| 315 | |||
| 316 | // Populate the matrix row with the state of the col pin | ||
| 317 | current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); | ||
| 318 | } | ||
| 319 | |||
| 320 | // Unselect row | ||
| 321 | unselect_row(current_row); | ||
| 322 | |||
| 323 | return (last_row_value != current_matrix[current_row]); | ||
| 324 | } | ||
| 325 | |||
| 326 | static void select_row(uint8_t row) | ||
| 327 | { | ||
| 328 | uint8_t pin = row_pins[row]; | ||
| 329 | _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT | ||
| 330 | _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW | ||
| 331 | } | ||
| 332 | |||
| 333 | static void unselect_row(uint8_t row) | ||
| 334 | { | ||
| 335 | uint8_t pin = row_pins[row]; | ||
| 336 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 337 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 338 | } | ||
| 339 | |||
| 340 | static void unselect_rows(void) | ||
| 341 | { | ||
| 342 | for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { | ||
| 343 | uint8_t pin = row_pins[x]; | ||
| 344 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 345 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | #elif (DIODE_DIRECTION == ROW2COL) | ||
| 350 | |||
| 351 | static void init_rows(void) | ||
| 352 | { | ||
| 353 | for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { | ||
| 354 | uint8_t pin = row_pins[x]; | ||
| 355 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 356 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 357 | } | ||
| 358 | } | ||
| 359 | |||
| 360 | static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) | ||
| 361 | { | ||
| 362 | bool matrix_changed = false; | ||
| 363 | |||
| 364 | // Select col and wait for col selecton to stabilize | ||
| 365 | select_col(current_col); | ||
| 366 | wait_us(30); | ||
| 367 | |||
| 368 | // For each row... | ||
| 369 | for(uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) | ||
| 370 | { | ||
| 371 | |||
| 372 | // Store last value of row prior to reading | ||
| 373 | matrix_row_t last_row_value = current_matrix[row_index]; | ||
| 374 | |||
| 375 | // Check row pin state | ||
| 376 | if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0) | ||
| 377 | { | ||
| 378 | // Pin LO, set col bit | ||
| 379 | current_matrix[row_index] |= (ROW_SHIFTER << current_col); | ||
| 380 | } | ||
| 381 | else | ||
| 382 | { | ||
| 383 | // Pin HI, clear col bit | ||
| 384 | current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); | ||
| 385 | } | ||
| 386 | |||
| 387 | // Determine if the matrix changed state | ||
| 388 | if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) | ||
| 389 | { | ||
| 390 | matrix_changed = true; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | // Unselect col | ||
| 395 | unselect_col(current_col); | ||
| 396 | |||
| 397 | return matrix_changed; | ||
| 398 | } | ||
| 399 | |||
| 400 | static void select_col(uint8_t col) | ||
| 401 | { | ||
| 402 | uint8_t pin = col_pins[col]; | ||
| 403 | _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT | ||
| 404 | _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW | ||
| 405 | } | ||
| 406 | |||
| 407 | static void unselect_col(uint8_t col) | ||
| 408 | { | ||
| 409 | uint8_t pin = col_pins[col]; | ||
| 410 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 411 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 412 | } | ||
| 413 | |||
| 414 | static void unselect_cols(void) | ||
| 415 | { | ||
| 416 | for(uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
| 417 | uint8_t pin = col_pins[x]; | ||
| 418 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 419 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 420 | } | ||
| 421 | } | ||
| 422 | |||
| 423 | #endif | ||
diff --git a/keyboards/fortitude60/readme.md b/keyboards/fortitude60/readme.md index 369f5e24b..21884df3c 100644 --- a/keyboards/fortitude60/readme.md +++ b/keyboards/fortitude60/readme.md | |||
| @@ -4,12 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | 👊A 60% (12x5) split keyboard with staggerd column layout.👊 | 5 | 👊A 60% (12x5) split keyboard with staggerd column layout.👊 |
| 6 | 6 | ||
| 7 | Keyboard Maintainer: [Pekaso](https://github.com/Pekaso) [@Pekaso](https://twitter.com/Pekaso) | 7 | * Keyboard Maintainer: [Pekaso](https://github.com/Pekaso) [@Pekaso](https://twitter.com/Pekaso) |
| 8 | Hardware Supported: Fortitude60 PCB, Beetle 32u4 | 8 | * Hardware Supported: Fortitude60 PCB, Beetle 32u4 |
| 9 | Hardware Availability: [plustk2s.com](http://plustk2s.com) | 9 | * Hardware Availability: [plustk2s.com](http://plustk2s.com) |
| 10 | 10 | ||
| 11 | Make example for this keyboard (after setting up your build environment): | 11 | Make example for this keyboard (after setting up your build environment): |
| 12 | 12 | ||
| 13 | make fortitude60/rev1:default:avrdude | 13 | make fortitude60/rev1:default:flash |
| 14 | 14 | ||
| 15 | See [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) then the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. \ No newline at end of file | 15 | See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). \ No newline at end of file |
diff --git a/keyboards/fortitude60/rev1/config.h b/keyboards/fortitude60/rev1/config.h index 98f610461..aa5a6f3b0 100644 --- a/keyboards/fortitude60/rev1/config.h +++ b/keyboards/fortitude60/rev1/config.h | |||
| @@ -15,8 +15,9 @@ 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/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #ifndef REV1_CONFIG_H | 18 | #pragma once |
| 19 | #define REV1_CONFIG_H | 19 | |
| 20 | #include "config_common.h" | ||
| 20 | 21 | ||
| 21 | /* USB Device descriptor parameter */ | 22 | /* USB Device descriptor parameter */ |
| 22 | #define VENDOR_ID 0xCB10 | 23 | #define VENDOR_ID 0xCB10 |
| @@ -38,6 +39,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 38 | /* COL2ROW or ROW2COL */ | 39 | /* COL2ROW or ROW2COL */ |
| 39 | #define DIODE_DIRECTION COL2ROW | 40 | #define DIODE_DIRECTION COL2ROW |
| 40 | 41 | ||
| 42 | /* | ||
| 43 | * Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk, and define SOFT_SERIAL_PIN. | ||
| 44 | */ | ||
| 45 | #define SOFT_SERIAL_PIN D2 | ||
| 46 | |||
| 41 | /* define if matrix has ghost */ | 47 | /* define if matrix has ghost */ |
| 42 | //#define MATRIX_HAS_GHOST | 48 | //#define MATRIX_HAS_GHOST |
| 43 | 49 | ||
| @@ -79,5 +85,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 79 | //#define NO_ACTION_ONESHOT | 85 | //#define NO_ACTION_ONESHOT |
| 80 | //#define NO_ACTION_MACRO | 86 | //#define NO_ACTION_MACRO |
| 81 | //#define NO_ACTION_FUNCTION | 87 | //#define NO_ACTION_FUNCTION |
| 82 | |||
| 83 | #endif | ||
diff --git a/keyboards/fortitude60/rev1/rev1.c b/keyboards/fortitude60/rev1/rev1.c index 5f4cd32f6..520a869e5 100644 --- a/keyboards/fortitude60/rev1/rev1.c +++ b/keyboards/fortitude60/rev1/rev1.c | |||
| @@ -1,22 +1 @@ | |||
| 1 | #include "rev1.h" | #include "rev1.h" | |
| 2 | |||
| 3 | #ifdef SSD1306OLED | ||
| 4 | void led_set_kb(uint8_t usb_led) { | ||
| 5 | // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here | ||
| 6 | led_set_user(usb_led); | ||
| 7 | } | ||
| 8 | #endif | ||
| 9 | |||
| 10 | void matrix_init_kb(void) { | ||
| 11 | |||
| 12 | // // green led on | ||
| 13 | // DDRD |= (1<<5); | ||
| 14 | // PORTD &= ~(1<<5); | ||
| 15 | |||
| 16 | // // orange led on | ||
| 17 | // DDRB |= (1<<0); | ||
| 18 | // PORTB &= ~(1<<0); | ||
| 19 | |||
| 20 | matrix_init_user(); | ||
| 21 | }; | ||
| 22 | |||
diff --git a/keyboards/fortitude60/rev1/rev1.h b/keyboards/fortitude60/rev1/rev1.h index bb133b3d8..ed62b2683 100644 --- a/keyboards/fortitude60/rev1/rev1.h +++ b/keyboards/fortitude60/rev1/rev1.h | |||
| @@ -1,18 +1,9 @@ | |||
| 1 | #ifndef REV1_H | 1 | #pragma once |
| 2 | #define REV1_H | ||
| 3 | 2 | ||
| 4 | #include "fortitude60.h" | 3 | #include "fortitude60.h" |
| 5 | 4 | ||
| 6 | #include "quantum.h" | 5 | #include "quantum.h" |
| 7 | 6 | ||
| 8 | #ifdef USE_I2C | ||
| 9 | #include <stddef.h> | ||
| 10 | #ifdef __AVR__ | ||
| 11 | #include <avr/io.h> | ||
| 12 | #include <avr/interrupt.h> | ||
| 13 | #endif | ||
| 14 | #endif | ||
| 15 | |||
| 16 | // Standard Keymap | 7 | // Standard Keymap |
| 17 | // (TRRS jack on the left half is to the right, TRRS jack on the right half is to the left) | 8 | // (TRRS jack on the left half is to the right, TRRS jack on the right half is to the left) |
| 18 | #define LAYOUT( \ | 9 | #define LAYOUT( \ |
| @@ -34,5 +25,3 @@ | |||
| 34 | { R35, R34, R33, R32, R31, R30 }, \ | 25 | { R35, R34, R33, R32, R31, R30 }, \ |
| 35 | { RT0, RT1, RT2, RT3, RT4, RT5 } \ | 26 | { RT0, RT1, RT2, RT3, RT4, RT5 } \ |
| 36 | } | 27 | } |
| 37 | |||
| 38 | #endif | ||
diff --git a/keyboards/fortitude60/rev1/rules.mk b/keyboards/fortitude60/rev1/rules.mk index e69de29bb..fff00a1b5 100644 --- a/keyboards/fortitude60/rev1/rules.mk +++ b/keyboards/fortitude60/rev1/rules.mk | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | # Revision Specific Build Options | ||
| 2 | # change yes to no to disable | ||
| 3 | # | ||
diff --git a/keyboards/fortitude60/rules.mk b/keyboards/fortitude60/rules.mk index 43d682cce..707f6a375 100644 --- a/keyboards/fortitude60/rules.mk +++ b/keyboards/fortitude60/rules.mk | |||
| @@ -12,28 +12,25 @@ MCU = atmega32u4 | |||
| 12 | BOOTLOADER = caterina | 12 | BOOTLOADER = caterina |
| 13 | 13 | ||
| 14 | # Build Options | 14 | # Build Options |
| 15 | # change to "no" to disable the options, or define them in the Makefile in | 15 | # change yes to no to disable |
| 16 | # the appropriate keymap folder that will get included automatically | ||
| 17 | # | 16 | # |
| 18 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration | 17 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration |
| 19 | MOUSEKEY_ENABLE = yes # Mouse keys | 18 | MOUSEKEY_ENABLE = yes # Mouse keys |
| 20 | EXTRAKEY_ENABLE = yes # Audio control and System control | 19 | EXTRAKEY_ENABLE = yes # Audio control and System control |
| 21 | CONSOLE_ENABLE = no # Console for debug | 20 | CONSOLE_ENABLE = no # Console for debug |
| 22 | COMMAND_ENABLE = yes # Commands for debug and configuration | 21 | COMMAND_ENABLE = yes # Commands for debug and configuration |
| 23 | NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 22 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
| 23 | SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | ||
| 24 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | ||
| 25 | NKRO_ENABLE = no # USB Nkey Rollover | ||
| 24 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | 26 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality |
| 25 | MIDI_ENABLE = no # MIDI controls | 27 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow |
| 26 | AUDIO_ENABLE = no # Audio output on port C6 | 28 | MIDI_ENABLE = no # MIDI support |
| 27 | UNICODE_ENABLE = no # Unicode | ||
| 28 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | 29 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID |
| 29 | RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. | 30 | AUDIO_ENABLE = no # Audio output on port C6 |
| 30 | USE_SERIAL = yes # Serial support only on fortitude60 | 31 | FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches |
| 31 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 32 | HD44780_ENABLE = no # Enable support for HD44780 based LCDs |
| 32 | SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | ||
| 33 | 33 | ||
| 34 | CUSTOM_MATRIX = yes | 34 | SPLIT_KEYBOARD = yes |
| 35 | SRC += matrix.c \ | ||
| 36 | split_util.c \ | ||
| 37 | serial.c | ||
| 38 | 35 | ||
| 39 | DEFAULT_FOLDER = fortitude60/rev1 | 36 | DEFAULT_FOLDER = fortitude60/rev1 |
diff --git a/keyboards/fortitude60/serial.c b/keyboards/fortitude60/serial.c deleted file mode 100644 index 674c42d59..000000000 --- a/keyboards/fortitude60/serial.c +++ /dev/null | |||
| @@ -1,589 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * WARNING: be careful changing this code, it is very timing dependent | ||
| 3 | * | ||
| 4 | * 2018-10-28 checked | ||
| 5 | * avr-gcc 4.9.2 | ||
| 6 | * avr-gcc 5.4.0 | ||
| 7 | * avr-gcc 7.3.0 | ||
| 8 | */ | ||
| 9 | |||
| 10 | #ifndef F_CPU | ||
| 11 | #define F_CPU 16000000 | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #include <avr/io.h> | ||
| 15 | #include <avr/interrupt.h> | ||
| 16 | #include <util/delay.h> | ||
| 17 | #include <stddef.h> | ||
| 18 | #include <stdbool.h> | ||
| 19 | #include "serial.h" | ||
| 20 | |||
| 21 | #ifdef SOFT_SERIAL_PIN | ||
| 22 | |||
| 23 | #ifdef __AVR_ATmega32U4__ | ||
| 24 | // if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial. | ||
| 25 | #ifdef USE_I2C | ||
| 26 | #if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1 | ||
| 27 | #error Using ATmega32U4 I2C, so can not use PD0, PD1 | ||
| 28 | #endif | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3 | ||
| 32 | #define SERIAL_PIN_DDR DDRD | ||
| 33 | #define SERIAL_PIN_PORT PORTD | ||
| 34 | #define SERIAL_PIN_INPUT PIND | ||
| 35 | #if SOFT_SERIAL_PIN == D0 | ||
| 36 | #define SERIAL_PIN_MASK _BV(PD0) | ||
| 37 | #define EIMSK_BIT _BV(INT0) | ||
| 38 | #define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01))) | ||
| 39 | #define SERIAL_PIN_INTERRUPT INT0_vect | ||
| 40 | #elif SOFT_SERIAL_PIN == D1 | ||
| 41 | #define SERIAL_PIN_MASK _BV(PD1) | ||
| 42 | #define EIMSK_BIT _BV(INT1) | ||
| 43 | #define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11))) | ||
| 44 | #define SERIAL_PIN_INTERRUPT INT1_vect | ||
| 45 | #elif SOFT_SERIAL_PIN == D2 | ||
| 46 | #define SERIAL_PIN_MASK _BV(PD2) | ||
| 47 | #define EIMSK_BIT _BV(INT2) | ||
| 48 | #define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21))) | ||
| 49 | #define SERIAL_PIN_INTERRUPT INT2_vect | ||
| 50 | #elif SOFT_SERIAL_PIN == D3 | ||
| 51 | #define SERIAL_PIN_MASK _BV(PD3) | ||
| 52 | #define EIMSK_BIT _BV(INT3) | ||
| 53 | #define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31))) | ||
| 54 | #define SERIAL_PIN_INTERRUPT INT3_vect | ||
| 55 | #endif | ||
| 56 | #elif SOFT_SERIAL_PIN == E6 | ||
| 57 | #define SERIAL_PIN_DDR DDRE | ||
| 58 | #define SERIAL_PIN_PORT PORTE | ||
| 59 | #define SERIAL_PIN_INPUT PINE | ||
| 60 | #define SERIAL_PIN_MASK _BV(PE6) | ||
| 61 | #define EIMSK_BIT _BV(INT6) | ||
| 62 | #define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61))) | ||
| 63 | #define SERIAL_PIN_INTERRUPT INT6_vect | ||
| 64 | #else | ||
| 65 | #error invalid SOFT_SERIAL_PIN value | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #else | ||
| 69 | #error serial.c now support ATmega32U4 only | ||
| 70 | #endif | ||
| 71 | |||
| 72 | //////////////// for backward compatibility //////////////////////////////// | ||
| 73 | #if !defined(SERIAL_USE_SINGLE_TRANSACTION) && !defined(SERIAL_USE_MULTI_TRANSACTION) | ||
| 74 | /* --- USE OLD API (compatible with let's split serial.c) */ | ||
| 75 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 | ||
| 76 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
| 77 | #endif | ||
| 78 | #if SERIAL_MASTER_BUFFER_LENGTH > 0 | ||
| 79 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
| 80 | #endif | ||
| 81 | uint8_t volatile status0 = 0; | ||
| 82 | |||
| 83 | SSTD_t transactions[] = { | ||
| 84 | { (uint8_t *)&status0, | ||
| 85 | #if SERIAL_MASTER_BUFFER_LENGTH > 0 | ||
| 86 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
| 87 | #else | ||
| 88 | 0, (uint8_t *)NULL, | ||
| 89 | #endif | ||
| 90 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 | ||
| 91 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
| 92 | #else | ||
| 93 | 0, (uint8_t *)NULL, | ||
| 94 | #endif | ||
| 95 | } | ||
| 96 | }; | ||
| 97 | |||
| 98 | void serial_master_init(void) | ||
| 99 | { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } | ||
| 100 | |||
| 101 | void serial_slave_init(void) | ||
| 102 | { soft_serial_target_init(transactions, TID_LIMIT(transactions)); } | ||
| 103 | |||
| 104 | // 0 => no error | ||
| 105 | // 1 => slave did not respond | ||
| 106 | // 2 => checksum error | ||
| 107 | int serial_update_buffers() | ||
| 108 | { | ||
| 109 | int result; | ||
| 110 | result = soft_serial_transaction(); | ||
| 111 | return result; | ||
| 112 | } | ||
| 113 | |||
| 114 | #endif // end of OLD API (compatible with let's split serial.c) | ||
| 115 | //////////////////////////////////////////////////////////////////////////// | ||
| 116 | |||
| 117 | #define ALWAYS_INLINE __attribute__((always_inline)) | ||
| 118 | #define NO_INLINE __attribute__((noinline)) | ||
| 119 | #define _delay_sub_us(x) __builtin_avr_delay_cycles(x) | ||
| 120 | |||
| 121 | // parity check | ||
| 122 | #define ODD_PARITY 1 | ||
| 123 | #define EVEN_PARITY 0 | ||
| 124 | #define PARITY EVEN_PARITY | ||
| 125 | |||
| 126 | #ifdef SERIAL_DELAY | ||
| 127 | // custom setup in config.h | ||
| 128 | // #define TID_SEND_ADJUST 2 | ||
| 129 | // #define SERIAL_DELAY 6 // micro sec | ||
| 130 | // #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 131 | // #define READ_WRITE_WIDTH_ADJUST 8 // cycles | ||
| 132 | #else | ||
| 133 | // ============ Standard setups ============ | ||
| 134 | |||
| 135 | #ifndef SELECT_SOFT_SERIAL_SPEED | ||
| 136 | #define SELECT_SOFT_SERIAL_SPEED 1 | ||
| 137 | // 0: about 189kbps | ||
| 138 | // 1: about 137kbps (default) | ||
| 139 | // 2: about 75kbps | ||
| 140 | // 3: about 39kbps | ||
| 141 | // 4: about 26kbps | ||
| 142 | // 5: about 20kbps | ||
| 143 | #endif | ||
| 144 | |||
| 145 | #if __GNUC__ < 6 | ||
| 146 | #define TID_SEND_ADJUST 14 | ||
| 147 | #else | ||
| 148 | #define TID_SEND_ADJUST 2 | ||
| 149 | #endif | ||
| 150 | |||
| 151 | #if SELECT_SOFT_SERIAL_SPEED == 0 | ||
| 152 | // Very High speed | ||
| 153 | #define SERIAL_DELAY 4 // micro sec | ||
| 154 | #if __GNUC__ < 6 | ||
| 155 | #define READ_WRITE_START_ADJUST 33 // cycles | ||
| 156 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | ||
| 157 | #else | ||
| 158 | #define READ_WRITE_START_ADJUST 34 // cycles | ||
| 159 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 160 | #endif | ||
| 161 | #elif SELECT_SOFT_SERIAL_SPEED == 1 | ||
| 162 | // High speed | ||
| 163 | #define SERIAL_DELAY 6 // micro sec | ||
| 164 | #if __GNUC__ < 6 | ||
| 165 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 166 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | ||
| 167 | #else | ||
| 168 | #define READ_WRITE_START_ADJUST 33 // cycles | ||
| 169 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 170 | #endif | ||
| 171 | #elif SELECT_SOFT_SERIAL_SPEED == 2 | ||
| 172 | // Middle speed | ||
| 173 | #define SERIAL_DELAY 12 // micro sec | ||
| 174 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 175 | #if __GNUC__ < 6 | ||
| 176 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | ||
| 177 | #else | ||
| 178 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 179 | #endif | ||
| 180 | #elif SELECT_SOFT_SERIAL_SPEED == 3 | ||
| 181 | // Low speed | ||
| 182 | #define SERIAL_DELAY 24 // micro sec | ||
| 183 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 184 | #if __GNUC__ < 6 | ||
| 185 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | ||
| 186 | #else | ||
| 187 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 188 | #endif | ||
| 189 | #elif SELECT_SOFT_SERIAL_SPEED == 4 | ||
| 190 | // Very Low speed | ||
| 191 | #define SERIAL_DELAY 36 // micro sec | ||
| 192 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 193 | #if __GNUC__ < 6 | ||
| 194 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | ||
| 195 | #else | ||
| 196 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 197 | #endif | ||
| 198 | #elif SELECT_SOFT_SERIAL_SPEED == 5 | ||
| 199 | // Ultra Low speed | ||
| 200 | #define SERIAL_DELAY 48 // micro sec | ||
| 201 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 202 | #if __GNUC__ < 6 | ||
| 203 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | ||
| 204 | #else | ||
| 205 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 206 | #endif | ||
| 207 | #else | ||
| 208 | #error invalid SELECT_SOFT_SERIAL_SPEED value | ||
| 209 | #endif /* SELECT_SOFT_SERIAL_SPEED */ | ||
| 210 | #endif /* SERIAL_DELAY */ | ||
| 211 | |||
| 212 | #define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2) | ||
| 213 | #define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2) | ||
| 214 | |||
| 215 | #define SLAVE_INT_WIDTH_US 1 | ||
| 216 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 217 | #define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY | ||
| 218 | #else | ||
| 219 | #define SLAVE_INT_ACK_WIDTH_UNIT 2 | ||
| 220 | #define SLAVE_INT_ACK_WIDTH 4 | ||
| 221 | #endif | ||
| 222 | |||
| 223 | static SSTD_t *Transaction_table = NULL; | ||
| 224 | static uint8_t Transaction_table_size = 0; | ||
| 225 | |||
| 226 | inline static void serial_delay(void) ALWAYS_INLINE; | ||
| 227 | inline static | ||
| 228 | void serial_delay(void) { | ||
| 229 | _delay_us(SERIAL_DELAY); | ||
| 230 | } | ||
| 231 | |||
| 232 | inline static void serial_delay_half1(void) ALWAYS_INLINE; | ||
| 233 | inline static | ||
| 234 | void serial_delay_half1(void) { | ||
| 235 | _delay_us(SERIAL_DELAY_HALF1); | ||
| 236 | } | ||
| 237 | |||
| 238 | inline static void serial_delay_half2(void) ALWAYS_INLINE; | ||
| 239 | inline static | ||
| 240 | void serial_delay_half2(void) { | ||
| 241 | _delay_us(SERIAL_DELAY_HALF2); | ||
| 242 | } | ||
| 243 | |||
| 244 | inline static void serial_output(void) ALWAYS_INLINE; | ||
| 245 | inline static | ||
| 246 | void serial_output(void) { | ||
| 247 | SERIAL_PIN_DDR |= SERIAL_PIN_MASK; | ||
| 248 | } | ||
| 249 | |||
| 250 | // make the serial pin an input with pull-up resistor | ||
| 251 | inline static void serial_input_with_pullup(void) ALWAYS_INLINE; | ||
| 252 | inline static | ||
| 253 | void serial_input_with_pullup(void) { | ||
| 254 | SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK; | ||
| 255 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | ||
| 256 | } | ||
| 257 | |||
| 258 | inline static uint8_t serial_read_pin(void) ALWAYS_INLINE; | ||
| 259 | inline static | ||
| 260 | uint8_t serial_read_pin(void) { | ||
| 261 | return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK); | ||
| 262 | } | ||
| 263 | |||
| 264 | inline static void serial_low(void) ALWAYS_INLINE; | ||
| 265 | inline static | ||
| 266 | void serial_low(void) { | ||
| 267 | SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; | ||
| 268 | } | ||
| 269 | |||
| 270 | inline static void serial_high(void) ALWAYS_INLINE; | ||
| 271 | inline static | ||
| 272 | void serial_high(void) { | ||
| 273 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | ||
| 274 | } | ||
| 275 | |||
| 276 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) | ||
| 277 | { | ||
| 278 | Transaction_table = sstd_table; | ||
| 279 | Transaction_table_size = (uint8_t)sstd_table_size; | ||
| 280 | serial_output(); | ||
| 281 | serial_high(); | ||
| 282 | } | ||
| 283 | |||
| 284 | void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size) | ||
| 285 | { | ||
| 286 | Transaction_table = sstd_table; | ||
| 287 | Transaction_table_size = (uint8_t)sstd_table_size; | ||
| 288 | serial_input_with_pullup(); | ||
| 289 | |||
| 290 | // Enable INT0-INT3,INT6 | ||
| 291 | EIMSK |= EIMSK_BIT; | ||
| 292 | #if SERIAL_PIN_MASK == _BV(PE6) | ||
| 293 | // Trigger on falling edge of INT6 | ||
| 294 | EICRB &= EICRx_BIT; | ||
| 295 | #else | ||
| 296 | // Trigger on falling edge of INT0-INT3 | ||
| 297 | EICRA &= EICRx_BIT; | ||
| 298 | #endif | ||
| 299 | } | ||
| 300 | |||
| 301 | // Used by the sender to synchronize timing with the reciver. | ||
| 302 | static void sync_recv(void) NO_INLINE; | ||
| 303 | static | ||
| 304 | void sync_recv(void) { | ||
| 305 | for (uint8_t i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) { | ||
| 306 | } | ||
| 307 | // This shouldn't hang if the target disconnects because the | ||
| 308 | // serial line will float to high if the target does disconnect. | ||
| 309 | while (!serial_read_pin()); | ||
| 310 | } | ||
| 311 | |||
| 312 | // Used by the reciver to send a synchronization signal to the sender. | ||
| 313 | static void sync_send(void) NO_INLINE; | ||
| 314 | static | ||
| 315 | void sync_send(void) { | ||
| 316 | serial_low(); | ||
| 317 | serial_delay(); | ||
| 318 | serial_high(); | ||
| 319 | } | ||
| 320 | |||
| 321 | // Reads a byte from the serial line | ||
| 322 | static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) NO_INLINE; | ||
| 323 | static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) { | ||
| 324 | uint8_t byte, i, p, pb; | ||
| 325 | |||
| 326 | _delay_sub_us(READ_WRITE_START_ADJUST); | ||
| 327 | for( i = 0, byte = 0, p = PARITY; i < bit; i++ ) { | ||
| 328 | serial_delay_half1(); // read the middle of pulses | ||
| 329 | if( serial_read_pin() ) { | ||
| 330 | byte = (byte << 1) | 1; p ^= 1; | ||
| 331 | } else { | ||
| 332 | byte = (byte << 1) | 0; p ^= 0; | ||
| 333 | } | ||
| 334 | _delay_sub_us(READ_WRITE_WIDTH_ADJUST); | ||
| 335 | serial_delay_half2(); | ||
| 336 | } | ||
| 337 | /* recive parity bit */ | ||
| 338 | serial_delay_half1(); // read the middle of pulses | ||
| 339 | pb = serial_read_pin(); | ||
| 340 | _delay_sub_us(READ_WRITE_WIDTH_ADJUST); | ||
| 341 | serial_delay_half2(); | ||
| 342 | |||
| 343 | *pterrcount += (p != pb)? 1 : 0; | ||
| 344 | |||
| 345 | return byte; | ||
| 346 | } | ||
| 347 | |||
| 348 | // Sends a byte with MSB ordering | ||
| 349 | void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE; | ||
| 350 | void serial_write_chunk(uint8_t data, uint8_t bit) { | ||
| 351 | uint8_t b, p; | ||
| 352 | for( p = PARITY, b = 1<<(bit-1); b ; b >>= 1) { | ||
| 353 | if(data & b) { | ||
| 354 | serial_high(); p ^= 1; | ||
| 355 | } else { | ||
| 356 | serial_low(); p ^= 0; | ||
| 357 | } | ||
| 358 | serial_delay(); | ||
| 359 | } | ||
| 360 | /* send parity bit */ | ||
| 361 | if(p & 1) { serial_high(); } | ||
| 362 | else { serial_low(); } | ||
| 363 | serial_delay(); | ||
| 364 | |||
| 365 | serial_low(); // sync_send() / senc_recv() need raise edge | ||
| 366 | } | ||
| 367 | |||
| 368 | static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE; | ||
| 369 | static | ||
| 370 | void serial_send_packet(uint8_t *buffer, uint8_t size) { | ||
| 371 | for (uint8_t i = 0; i < size; ++i) { | ||
| 372 | uint8_t data; | ||
| 373 | data = buffer[i]; | ||
| 374 | sync_send(); | ||
| 375 | serial_write_chunk(data,8); | ||
| 376 | } | ||
| 377 | } | ||
| 378 | |||
| 379 | static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) NO_INLINE; | ||
| 380 | static | ||
| 381 | uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) { | ||
| 382 | uint8_t pecount = 0; | ||
| 383 | for (uint8_t i = 0; i < size; ++i) { | ||
| 384 | uint8_t data; | ||
| 385 | sync_recv(); | ||
| 386 | data = serial_read_chunk(&pecount, 8); | ||
| 387 | buffer[i] = data; | ||
| 388 | } | ||
| 389 | return pecount == 0; | ||
| 390 | } | ||
| 391 | |||
| 392 | inline static | ||
| 393 | void change_sender2reciver(void) { | ||
| 394 | sync_send(); //0 | ||
| 395 | serial_delay_half1(); //1 | ||
| 396 | serial_low(); //2 | ||
| 397 | serial_input_with_pullup(); //2 | ||
| 398 | serial_delay_half1(); //3 | ||
| 399 | } | ||
| 400 | |||
| 401 | inline static | ||
| 402 | void change_reciver2sender(void) { | ||
| 403 | sync_recv(); //0 | ||
| 404 | serial_delay(); //1 | ||
| 405 | serial_low(); //3 | ||
| 406 | serial_output(); //3 | ||
| 407 | serial_delay_half1(); //4 | ||
| 408 | } | ||
| 409 | |||
| 410 | static inline uint8_t nibble_bits_count(uint8_t bits) | ||
| 411 | { | ||
| 412 | bits = (bits & 0x5) + (bits >> 1 & 0x5); | ||
| 413 | bits = (bits & 0x3) + (bits >> 2 & 0x3); | ||
| 414 | return bits; | ||
| 415 | } | ||
| 416 | |||
| 417 | // interrupt handle to be used by the target device | ||
| 418 | ISR(SERIAL_PIN_INTERRUPT) { | ||
| 419 | |||
| 420 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 421 | serial_low(); | ||
| 422 | serial_output(); | ||
| 423 | SSTD_t *trans = Transaction_table; | ||
| 424 | #else | ||
| 425 | // recive transaction table index | ||
| 426 | uint8_t tid, bits; | ||
| 427 | uint8_t pecount = 0; | ||
| 428 | sync_recv(); | ||
| 429 | bits = serial_read_chunk(&pecount,7); | ||
| 430 | tid = bits>>3; | ||
| 431 | bits = (bits&7) != nibble_bits_count(tid); | ||
| 432 | if( bits || pecount> 0 || tid > Transaction_table_size ) { | ||
| 433 | return; | ||
| 434 | } | ||
| 435 | serial_delay_half1(); | ||
| 436 | |||
| 437 | serial_high(); // response step1 low->high | ||
| 438 | serial_output(); | ||
| 439 | _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT*SLAVE_INT_ACK_WIDTH); | ||
| 440 | SSTD_t *trans = &Transaction_table[tid]; | ||
| 441 | serial_low(); // response step2 ack high->low | ||
| 442 | #endif | ||
| 443 | |||
| 444 | // target send phase | ||
| 445 | if( trans->target2initiator_buffer_size > 0 ) | ||
| 446 | serial_send_packet((uint8_t *)trans->target2initiator_buffer, | ||
| 447 | trans->target2initiator_buffer_size); | ||
| 448 | // target switch to input | ||
| 449 | change_sender2reciver(); | ||
| 450 | |||
| 451 | // target recive phase | ||
| 452 | if( trans->initiator2target_buffer_size > 0 ) { | ||
| 453 | if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer, | ||
| 454 | trans->initiator2target_buffer_size) ) { | ||
| 455 | *trans->status = TRANSACTION_ACCEPTED; | ||
| 456 | } else { | ||
| 457 | *trans->status = TRANSACTION_DATA_ERROR; | ||
| 458 | } | ||
| 459 | } else { | ||
| 460 | *trans->status = TRANSACTION_ACCEPTED; | ||
| 461 | } | ||
| 462 | |||
| 463 | sync_recv(); //weit initiator output to high | ||
| 464 | } | ||
| 465 | |||
| 466 | ///////// | ||
| 467 | // start transaction by initiator | ||
| 468 | // | ||
| 469 | // int soft_serial_transaction(int sstd_index) | ||
| 470 | // | ||
| 471 | // Returns: | ||
| 472 | // TRANSACTION_END | ||
| 473 | // TRANSACTION_NO_RESPONSE | ||
| 474 | // TRANSACTION_DATA_ERROR | ||
| 475 | // this code is very time dependent, so we need to disable interrupts | ||
| 476 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 477 | int soft_serial_transaction(void) { | ||
| 478 | SSTD_t *trans = Transaction_table; | ||
| 479 | #else | ||
| 480 | int soft_serial_transaction(int sstd_index) { | ||
| 481 | if( sstd_index > Transaction_table_size ) | ||
| 482 | return TRANSACTION_TYPE_ERROR; | ||
| 483 | SSTD_t *trans = &Transaction_table[sstd_index]; | ||
| 484 | #endif | ||
| 485 | cli(); | ||
| 486 | |||
| 487 | // signal to the target that we want to start a transaction | ||
| 488 | serial_output(); | ||
| 489 | serial_low(); | ||
| 490 | _delay_us(SLAVE_INT_WIDTH_US); | ||
| 491 | |||
| 492 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 493 | // wait for the target response | ||
| 494 | serial_input_with_pullup(); | ||
| 495 | _delay_us(SLAVE_INT_RESPONSE_TIME); | ||
| 496 | |||
| 497 | // check if the target is present | ||
| 498 | if (serial_read_pin()) { | ||
| 499 | // target failed to pull the line low, assume not present | ||
| 500 | serial_output(); | ||
| 501 | serial_high(); | ||
| 502 | *trans->status = TRANSACTION_NO_RESPONSE; | ||
| 503 | sei(); | ||
| 504 | return TRANSACTION_NO_RESPONSE; | ||
| 505 | } | ||
| 506 | |||
| 507 | #else | ||
| 508 | // send transaction table index | ||
| 509 | int tid = (sstd_index<<3) | (7 & nibble_bits_count(sstd_index)); | ||
| 510 | sync_send(); | ||
| 511 | _delay_sub_us(TID_SEND_ADJUST); | ||
| 512 | serial_write_chunk(tid, 7); | ||
| 513 | serial_delay_half1(); | ||
| 514 | |||
| 515 | // wait for the target response (step1 low->high) | ||
| 516 | serial_input_with_pullup(); | ||
| 517 | while( !serial_read_pin() ) { | ||
| 518 | _delay_sub_us(2); | ||
| 519 | } | ||
| 520 | |||
| 521 | // check if the target is present (step2 high->low) | ||
| 522 | for( int i = 0; serial_read_pin(); i++ ) { | ||
| 523 | if (i > SLAVE_INT_ACK_WIDTH + 1) { | ||
| 524 | // slave failed to pull the line low, assume not present | ||
| 525 | serial_output(); | ||
| 526 | serial_high(); | ||
| 527 | *trans->status = TRANSACTION_NO_RESPONSE; | ||
| 528 | sei(); | ||
| 529 | return TRANSACTION_NO_RESPONSE; | ||
| 530 | } | ||
| 531 | _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT); | ||
| 532 | } | ||
| 533 | #endif | ||
| 534 | |||
| 535 | // initiator recive phase | ||
| 536 | // if the target is present syncronize with it | ||
| 537 | if( trans->target2initiator_buffer_size > 0 ) { | ||
| 538 | if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer, | ||
| 539 | trans->target2initiator_buffer_size) ) { | ||
| 540 | serial_output(); | ||
| 541 | serial_high(); | ||
| 542 | *trans->status = TRANSACTION_DATA_ERROR; | ||
| 543 | sei(); | ||
| 544 | return TRANSACTION_DATA_ERROR; | ||
| 545 | } | ||
| 546 | } | ||
| 547 | |||
| 548 | // initiator switch to output | ||
| 549 | change_reciver2sender(); | ||
| 550 | |||
| 551 | // initiator send phase | ||
| 552 | if( trans->initiator2target_buffer_size > 0 ) { | ||
| 553 | serial_send_packet((uint8_t *)trans->initiator2target_buffer, | ||
| 554 | trans->initiator2target_buffer_size); | ||
| 555 | } | ||
| 556 | |||
| 557 | // always, release the line when not in use | ||
| 558 | sync_send(); | ||
| 559 | |||
| 560 | *trans->status = TRANSACTION_END; | ||
| 561 | sei(); | ||
| 562 | return TRANSACTION_END; | ||
| 563 | } | ||
| 564 | |||
| 565 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 566 | int soft_serial_get_and_clean_status(int sstd_index) { | ||
| 567 | SSTD_t *trans = &Transaction_table[sstd_index]; | ||
| 568 | cli(); | ||
| 569 | int retval = *trans->status; | ||
| 570 | *trans->status = 0;; | ||
| 571 | sei(); | ||
| 572 | return retval; | ||
| 573 | } | ||
| 574 | #endif | ||
| 575 | |||
| 576 | #endif | ||
| 577 | |||
| 578 | // Helix serial.c history | ||
| 579 | // 2018-1-29 fork from let's split and add PD2, modify sync_recv() (#2308, bceffdefc) | ||
| 580 | // 2018-6-28 bug fix master to slave comm and speed up (#3255, 1038bbef4) | ||
| 581 | // (adjusted with avr-gcc 4.9.2) | ||
| 582 | // 2018-7-13 remove USE_SERIAL_PD2 macro (#3374, f30d6dd78) | ||
| 583 | // (adjusted with avr-gcc 4.9.2) | ||
| 584 | // 2018-8-11 add support multi-type transaction (#3608, feb5e4aae) | ||
| 585 | // (adjusted with avr-gcc 4.9.2) | ||
| 586 | // 2018-10-21 fix serial and RGB animation conflict (#4191, 4665e4fff) | ||
| 587 | // (adjusted with avr-gcc 7.3.0) | ||
| 588 | // 2018-10-28 re-adjust compiler depend value of delay (#4269, 8517f8a66) | ||
| 589 | // (adjusted with avr-gcc 5.4.0, 7.3.0) | ||
diff --git a/keyboards/fortitude60/serial.h b/keyboards/fortitude60/serial.h deleted file mode 100644 index 2e53928df..000000000 --- a/keyboards/fortitude60/serial.h +++ /dev/null | |||
| @@ -1,89 +0,0 @@ | |||
| 1 | #ifndef SOFT_SERIAL_H | ||
| 2 | #define SOFT_SERIAL_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | |||
| 6 | // ///////////////////////////////////////////////////////////////// | ||
| 7 | // Need Soft Serial defines in config.h | ||
| 8 | // ///////////////////////////////////////////////////////////////// | ||
| 9 | // ex. | ||
| 10 | // #define SOFT_SERIAL_PIN ?? // ?? = D0,D1,D2,D3,E6 | ||
| 11 | // OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5 | ||
| 12 | // // 1: about 137kbps (default) | ||
| 13 | // // 2: about 75kbps | ||
| 14 | // // 3: about 39kbps | ||
| 15 | // // 4: about 26kbps | ||
| 16 | // // 5: about 20kbps | ||
| 17 | // | ||
| 18 | // //// USE OLD API (compatible with let's split serial.c) | ||
| 19 | // ex. | ||
| 20 | // #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 21 | // #define SERIAL_MASTER_BUFFER_LENGTH 1 | ||
| 22 | // | ||
| 23 | // //// USE NEW API | ||
| 24 | // //// USE simple API (using signle-type transaction function) | ||
| 25 | // #define SERIAL_USE_SINGLE_TRANSACTION | ||
| 26 | // //// USE flexible API (using multi-type transaction function) | ||
| 27 | // #define SERIAL_USE_MULTI_TRANSACTION | ||
| 28 | // | ||
| 29 | // ///////////////////////////////////////////////////////////////// | ||
| 30 | |||
| 31 | |||
| 32 | //////////////// for backward compatibility //////////////////////////////// | ||
| 33 | #if !defined(SERIAL_USE_SINGLE_TRANSACTION) && !defined(SERIAL_USE_MULTI_TRANSACTION) | ||
| 34 | /* --- USE OLD API (compatible with let's split serial.c) */ | ||
| 35 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 | ||
| 36 | extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; | ||
| 37 | #endif | ||
| 38 | #if SERIAL_MASTER_BUFFER_LENGTH > 0 | ||
| 39 | extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; | ||
| 40 | #endif | ||
| 41 | |||
| 42 | void serial_master_init(void); | ||
| 43 | void serial_slave_init(void); | ||
| 44 | int serial_update_buffers(void); | ||
| 45 | |||
| 46 | #endif // end of USE OLD API | ||
| 47 | //////////////////////////////////////////////////////////////////////////// | ||
| 48 | |||
| 49 | // Soft Serial Transaction Descriptor | ||
| 50 | typedef struct _SSTD_t { | ||
| 51 | uint8_t *status; | ||
| 52 | uint8_t initiator2target_buffer_size; | ||
| 53 | uint8_t *initiator2target_buffer; | ||
| 54 | uint8_t target2initiator_buffer_size; | ||
| 55 | uint8_t *target2initiator_buffer; | ||
| 56 | } SSTD_t; | ||
| 57 | #define TID_LIMIT( table ) (sizeof(table) / sizeof(SSTD_t)) | ||
| 58 | |||
| 59 | // initiator is transaction start side | ||
| 60 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size); | ||
| 61 | // target is interrupt accept side | ||
| 62 | void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size); | ||
| 63 | |||
| 64 | // initiator resullt | ||
| 65 | #define TRANSACTION_END 0 | ||
| 66 | #define TRANSACTION_NO_RESPONSE 0x1 | ||
| 67 | #define TRANSACTION_DATA_ERROR 0x2 | ||
| 68 | #define TRANSACTION_TYPE_ERROR 0x4 | ||
| 69 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 70 | int soft_serial_transaction(void); | ||
| 71 | #else | ||
| 72 | int soft_serial_transaction(int sstd_index); | ||
| 73 | #endif | ||
| 74 | |||
| 75 | // target status | ||
| 76 | // *SSTD_t.status has | ||
| 77 | // initiator: | ||
| 78 | // TRANSACTION_END | ||
| 79 | // or TRANSACTION_NO_RESPONSE | ||
| 80 | // or TRANSACTION_DATA_ERROR | ||
| 81 | // target: | ||
| 82 | // TRANSACTION_DATA_ERROR | ||
| 83 | // or TRANSACTION_ACCEPTED | ||
| 84 | #define TRANSACTION_ACCEPTED 0x8 | ||
| 85 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 86 | int soft_serial_get_and_clean_status(int sstd_index); | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #endif /* SOFT_SERIAL_H */ | ||
diff --git a/keyboards/fortitude60/serial_config.h b/keyboards/fortitude60/serial_config.h deleted file mode 100644 index d4a42bce3..000000000 --- a/keyboards/fortitude60/serial_config.h +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | #ifndef SOFT_SERIAL_CONFIG_H | ||
| 2 | #define SOFT_SERIAL_CONFIG_H | ||
| 3 | |||
| 4 | /* Soft Serial defines */ | ||
| 5 | #define SOFT_SERIAL_PIN D2 | ||
| 6 | |||
| 7 | #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 8 | #define SERIAL_MASTER_BUFFER_LENGTH 1 | ||
| 9 | |||
| 10 | #endif /* SOFT_SERIAL_CONFIG_H */ | ||
diff --git a/keyboards/fortitude60/split_util.c b/keyboards/fortitude60/split_util.c deleted file mode 100644 index 1adae7844..000000000 --- a/keyboards/fortitude60/split_util.c +++ /dev/null | |||
| @@ -1,85 +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 | #include "config.h" | ||
| 11 | #include "timer.h" | ||
| 12 | |||
| 13 | #include "serial.h" | ||
| 14 | |||
| 15 | volatile bool isLeftHand = true; | ||
| 16 | |||
| 17 | static void setup_handedness(void) { | ||
| 18 | #ifdef EE_HANDS | ||
| 19 | isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); | ||
| 20 | #else | ||
| 21 | // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c | ||
| 22 | #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) | ||
| 23 | isLeftHand = !has_usb(); | ||
| 24 | #else | ||
| 25 | isLeftHand = has_usb(); | ||
| 26 | #endif | ||
| 27 | #endif | ||
| 28 | } | ||
| 29 | |||
| 30 | static void keyboard_master_setup(void) { | ||
| 31 | #ifdef USE_I2C | ||
| 32 | i2c_master_init(); | ||
| 33 | #ifdef SSD1306OLED | ||
| 34 | matrix_master_OLED_init (); | ||
| 35 | #endif | ||
| 36 | #else | ||
| 37 | serial_master_init(); | ||
| 38 | #endif | ||
| 39 | } | ||
| 40 | |||
| 41 | static void keyboard_slave_setup(void) { | ||
| 42 | timer_init(); | ||
| 43 | #ifdef USE_I2C | ||
| 44 | i2c_slave_init(SLAVE_I2C_ADDRESS); | ||
| 45 | #else | ||
| 46 | serial_slave_init(); | ||
| 47 | #endif | ||
| 48 | } | ||
| 49 | |||
| 50 | bool has_usb(void) { | ||
| 51 | /* return (UDADDR & _BV(ADDEN)); */ | ||
| 52 | USBCON |= (1 << OTGPADE); //enables VBUS pad | ||
| 53 | _delay_us(5); | ||
| 54 | return (USBSTA & (1<<VBUS)); //checks state of VBUS | ||
| 55 | } | ||
| 56 | |||
| 57 | void split_keyboard_setup(void) { | ||
| 58 | setup_handedness(); | ||
| 59 | |||
| 60 | if (isLeftHand) { | ||
| 61 | /* if (has_usb()) { */ | ||
| 62 | keyboard_master_setup(); | ||
| 63 | } else { | ||
| 64 | keyboard_slave_setup(); | ||
| 65 | } | ||
| 66 | sei(); | ||
| 67 | } | ||
| 68 | |||
| 69 | void keyboard_slave_loop(void) { | ||
| 70 | matrix_init(); | ||
| 71 | |||
| 72 | while (1) { | ||
| 73 | matrix_slave_scan(); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | // this code runs before the usb and keyboard is initialized | ||
| 78 | void matrix_setup(void) { | ||
| 79 | split_keyboard_setup(); | ||
| 80 | |||
| 81 | if (!isLeftHand) { | ||
| 82 | /* if (!has_usb()) { */ | ||
| 83 | keyboard_slave_loop(); | ||
| 84 | } | ||
| 85 | } | ||
diff --git a/keyboards/fortitude60/split_util.h b/keyboards/fortitude60/split_util.h deleted file mode 100644 index 28fff3e79..000000000 --- a/keyboards/fortitude60/split_util.h +++ /dev/null | |||
| @@ -1,18 +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 | extern volatile bool isLeftHand; | ||
| 8 | |||
| 9 | // slave version of matix scan, defined in matrix.c | ||
| 10 | void matrix_slave_scan(void); | ||
| 11 | |||
| 12 | void split_keyboard_setup(void); | ||
| 13 | bool has_usb(void); | ||
| 14 | void keyboard_slave_loop(void); | ||
| 15 | |||
| 16 | void matrix_master_OLED_init (void); | ||
| 17 | |||
| 18 | #endif | ||
