diff options
| author | Salicylic-acid3 <46864619+Salicylic-acid3@users.noreply.github.com> | 2019-10-17 02:26:43 +0900 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-10-16 10:26:43 -0700 |
| commit | f360c27f9302b1f916985dc32f68657ec22b3b9c (patch) | |
| tree | b3c3210e6c0c450b5d27d643c6d6817309ac83fc /keyboards/naked60/rev1 | |
| parent | 2fc3494fd967bb2d8ffba3dcd33fa4a7ef1066ed (diff) | |
| download | qmk_firmware-f360c27f9302b1f916985dc32f68657ec22b3b9c.tar.gz qmk_firmware-f360c27f9302b1f916985dc32f68657ec22b3b9c.zip | |
[Keyboard] Add keyboard Naked60 (#6527)
* Add Naked60
* readme Update
* Update keyboards/naked60/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Updated keymaps
Changed the alias.
* updated rule.mk
Unnecessary part was deleted and explanation was added to the boot loader.
* Update keyboards/naked60/rules.mk
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update keyboards/naked60/rules.mk
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update keyboards/naked60/rev1/rev1.h
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update keyboards/naked60/rev1/rev1.h
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update keyboards/naked60/rev1/config.h
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update keyboards/naked60/rev1/config.h
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Updated keymaps rules.mk.
Cleaned up declarations in rules.mk.
* Updated keymap
Changed remaining aliases.
* Update rev1.c
Cleaned up declarations in rev1.c.
* Update readme
The appearance has been adjusted.
* Update keyboards/naked60/keymaps/default/readme.md
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/default_with_nafuda/readme.md
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/default_with_nafuda/readme.md
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/salicylic/readme.md
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/salicylic/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/salicylic_with_nafuda/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/salicylic_with_nafuda/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/salicylic_with_setta21/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/salicylic_with_setta21/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/rev1/rev1.c
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/default_with_nafuda/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/salicylic/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/default_with_nafuda/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/default_with_setta21/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/naked60/keymaps/default_with_setta21/rules.mk
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Updated keymaps
The appearance has been adjusted.
Unnecessary rules.mk was deleted.
* Update keyboards/naked60/readme.md
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update readme
Changed to markdown format.
* Update keyboards/naked60/keymaps/default/readme.md
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update keyboards/naked60/keymaps/salicylic/readme.md
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update keyboards/naked60/keymaps/salicylic/readme.md
Co-Authored-By: fauxpark <fauxpark@gmail.com>
Diffstat (limited to 'keyboards/naked60/rev1')
| -rw-r--r-- | keyboards/naked60/rev1/config.h | 119 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/matrix.c | 357 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/rev1.c | 1 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/rev1.h | 97 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/rules.mk | 3 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/serial_config.h | 8 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/serial_config_simpleapi.h | 8 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/split_scomm.c | 92 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/split_scomm.h | 22 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/split_util.c | 70 | ||||
| -rw-r--r-- | keyboards/naked60/rev1/split_util.h | 16 |
11 files changed, 793 insertions, 0 deletions
diff --git a/keyboards/naked60/rev1/config.h b/keyboards/naked60/rev1/config.h new file mode 100644 index 000000000..1724ef060 --- /dev/null +++ b/keyboards/naked60/rev1/config.h | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | Copyright 2015 Jack Humbert | ||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation, either version 2 of the License, or | ||
| 8 | (at your option) any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #pragma once | ||
| 20 | |||
| 21 | /* USB Device descriptor parameter */ | ||
| 22 | #define VENDOR_ID 0xFEED | ||
| 23 | #define PRODUCT_ID 0x3060 | ||
| 24 | #define DEVICE_VER 0x0002 | ||
| 25 | #define MANUFACTURER Salicylic_Acid | ||
| 26 | #define PRODUCT naked60 | ||
| 27 | #define DESCRIPTION Ortholinear 60 Keys Keyboard | ||
| 28 | |||
| 29 | /* Use I2C or Serial */ | ||
| 30 | //#define USE_I2C | ||
| 31 | #define USE_SERIAL | ||
| 32 | //#define USE_MATRIX_I2C | ||
| 33 | |||
| 34 | /* Select hand configuration */ | ||
| 35 | #define MASTER_LEFT | ||
| 36 | // #define MASTER_RIGHT | ||
| 37 | // #define EE_HANDS | ||
| 38 | |||
| 39 | // OLED support | ||
| 40 | // see ./rules.mk: OLED_ENABLE=yes or no | ||
| 41 | #ifdef OLED_ENABLE | ||
| 42 | #define SSD1306OLED | ||
| 43 | #endif | ||
| 44 | |||
| 45 | /* key matrix size */ | ||
| 46 | #define MATRIX_ROWS 10 | ||
| 47 | #define MATRIX_COLS 14 | ||
| 48 | |||
| 49 | // Rows are doubled-up | ||
| 50 | #define MATRIX_ROW_PINS { B6, D1, D0, D4, C6 } | ||
| 51 | |||
| 52 | // wiring of each half | ||
| 53 | #define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3, B2, D7, E6, B4, B5, D3 } | ||
| 54 | // #define MATRIX_COL_PINS { D3, B5, B4, E6, D7, B2, B3, B1, F7, F6, F5, F4 } //uncomment this line and comment line above if you need to reverse left-to-right key order | ||
| 55 | |||
| 56 | /* define if matrix has ghost */ | ||
| 57 | //#define MATRIX_HAS_GHOST | ||
| 58 | |||
| 59 | /* number of backlight levels */ | ||
| 60 | // #define BACKLIGHT_LEVELS 3 | ||
| 61 | |||
| 62 | /* Set 0 if debouncing isn't needed */ | ||
| 63 | #define DEBOUNCE 5 | ||
| 64 | |||
| 65 | /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ | ||
| 66 | //#define LOCKING_SUPPORT_ENABLE | ||
| 67 | /* Locking resynchronize hack */ | ||
| 68 | //#define LOCKING_RESYNC_ENABLE | ||
| 69 | |||
| 70 | /* ws2812 RGB LED */ | ||
| 71 | #define RGB_DI_PIN D3 | ||
| 72 | #define RGBLIGHT_TIMER | ||
| 73 | |||
| 74 | // naked60 keyboard RGB LED support | ||
| 75 | //#define RGBLIGHT_ANIMATIONS : see ./rules.mk: LED_ANIMATIONS = yes or no | ||
| 76 | // see ./rules.mk: LED_BACK_ENABLE or LED_UNDERGLOW_ENABLE set yes | ||
| 77 | //#define RGBLED_NUM 21 | ||
| 78 | |||
| 79 | #ifndef IOS_DEVICE_ENABLE | ||
| 80 | #define RGBLIGHT_LIMIT_VAL 180 | ||
| 81 | #define RGBLIGHT_VAL_STEP 17 | ||
| 82 | #else | ||
| 83 | #define RGBLIGHT_LIMIT_VAL 50 | ||
| 84 | #define RGBLIGHT_VAL_STEP 4 | ||
| 85 | #endif | ||
| 86 | #define RGBLIGHT_HUE_STEP 10 | ||
| 87 | #define RGBLIGHT_SAT_STEP 17 | ||
| 88 | |||
| 89 | #if defined(RGBLIGHT_ENABLE) && !defined(IOS_DEVICE_ENABLE) | ||
| 90 | // USB_MAX_POWER_CONSUMPTION value for naked60 keyboard | ||
| 91 | // 120 RGBoff, OLEDoff | ||
| 92 | // 120 OLED | ||
| 93 | // 330 RGB 6 | ||
| 94 | // 300 RGB 32 | ||
| 95 | // 310 OLED & RGB 32 | ||
| 96 | #define USB_MAX_POWER_CONSUMPTION 400 | ||
| 97 | #else | ||
| 98 | // fix iPhone and iPad power adapter issue | ||
| 99 | // iOS device need lessthan 100 | ||
| 100 | #define USB_MAX_POWER_CONSUMPTION 100 | ||
| 101 | #endif | ||
| 102 | |||
| 103 | /* | ||
| 104 | * Feature disable options | ||
| 105 | * These options are also useful to firmware size reduction. | ||
| 106 | */ | ||
| 107 | |||
| 108 | /* disable debug print */ | ||
| 109 | // #define NO_DEBUG | ||
| 110 | |||
| 111 | /* disable print */ | ||
| 112 | // #define NO_PRINT | ||
| 113 | |||
| 114 | /* disable action features */ | ||
| 115 | //#define NO_ACTION_LAYER | ||
| 116 | //#define NO_ACTION_TAPPING | ||
| 117 | //#define NO_ACTION_ONESHOT | ||
| 118 | //#define NO_ACTION_MACRO | ||
| 119 | //#define NO_ACTION_FUNCTION | ||
diff --git a/keyboards/naked60/rev1/matrix.c b/keyboards/naked60/rev1/matrix.c new file mode 100644 index 000000000..8685a8125 --- /dev/null +++ b/keyboards/naked60/rev1/matrix.c | |||
| @@ -0,0 +1,357 @@ | |||
| 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 "pro_micro.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 | TX_RX_LED_INIT; | ||
| 106 | TXLED0; | ||
| 107 | RXLED0; | ||
| 108 | |||
| 109 | // initialize matrix state: all keys off | ||
| 110 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 111 | matrix[i] = 0; | ||
| 112 | matrix_debouncing[i] = 0; | ||
| 113 | } | ||
| 114 | |||
| 115 | is_master = has_usb(); | ||
| 116 | |||
| 117 | matrix_init_quantum(); | ||
| 118 | } | ||
| 119 | |||
| 120 | uint8_t _matrix_scan(void) | ||
| 121 | { | ||
| 122 | // Right hand is stored after the left in the matirx so, we need to offset it | ||
| 123 | int offset = isLeftHand ? 0 : (ROWS_PER_HAND); | ||
| 124 | |||
| 125 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 126 | select_row(i); | ||
| 127 | _delay_us(30); // without this wait read unstable value. | ||
| 128 | matrix_row_t cols = read_cols(); | ||
| 129 | if (matrix_debouncing[i+offset] != cols) { | ||
| 130 | matrix_debouncing[i+offset] = cols; | ||
| 131 | debouncing = DEBOUNCE; | ||
| 132 | } | ||
| 133 | unselect_rows(); | ||
| 134 | } | ||
| 135 | |||
| 136 | if (debouncing) { | ||
| 137 | if (--debouncing) { | ||
| 138 | _delay_ms(1); | ||
| 139 | } else { | ||
| 140 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 141 | matrix[i+offset] = matrix_debouncing[i+offset]; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | return 1; | ||
| 147 | } | ||
| 148 | |||
| 149 | #ifdef USE_MATRIX_I2C | ||
| 150 | |||
| 151 | // Get rows from other half over i2c | ||
| 152 | int i2c_transaction(void) { | ||
| 153 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 154 | |||
| 155 | int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); | ||
| 156 | if (err) goto i2c_error; | ||
| 157 | |||
| 158 | // start of matrix stored at 0x00 | ||
| 159 | err = i2c_master_write(0x00); | ||
| 160 | if (err) goto i2c_error; | ||
| 161 | |||
| 162 | // Start read | ||
| 163 | err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); | ||
| 164 | if (err) goto i2c_error; | ||
| 165 | |||
| 166 | if (!err) { | ||
| 167 | int i; | ||
| 168 | for (i = 0; i < ROWS_PER_HAND-1; ++i) { | ||
| 169 | matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); | ||
| 170 | } | ||
| 171 | matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); | ||
| 172 | i2c_master_stop(); | ||
| 173 | } else { | ||
| 174 | i2c_error: // the cable is disconnceted, or something else went wrong | ||
| 175 | i2c_reset_state(); | ||
| 176 | return err; | ||
| 177 | } | ||
| 178 | |||
| 179 | return 0; | ||
| 180 | } | ||
| 181 | |||
| 182 | #else // USE_SERIAL | ||
| 183 | |||
| 184 | int serial_transaction(int master_changed) { | ||
| 185 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 186 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 187 | int ret=serial_update_buffers(master_changed); | ||
| 188 | #else | ||
| 189 | int ret=serial_update_buffers(); | ||
| 190 | #endif | ||
| 191 | if (ret ) { | ||
| 192 | if(ret==2) RXLED1; | ||
| 193 | return 1; | ||
| 194 | } | ||
| 195 | RXLED0; | ||
| 196 | memcpy(&matrix[slaveOffset], | ||
| 197 | (void *)serial_slave_buffer, sizeof(serial_slave_buffer)); | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | #endif | ||
| 201 | |||
| 202 | uint8_t matrix_scan(void) | ||
| 203 | { | ||
| 204 | if (is_master) { | ||
| 205 | matrix_master_scan(); | ||
| 206 | }else{ | ||
| 207 | matrix_slave_scan(); | ||
| 208 | int offset = (isLeftHand) ? ROWS_PER_HAND : 0; | ||
| 209 | memcpy(&matrix[offset], | ||
| 210 | (void *)serial_master_buffer, sizeof(serial_master_buffer)); | ||
| 211 | matrix_scan_quantum(); | ||
| 212 | } | ||
| 213 | return 1; | ||
| 214 | } | ||
| 215 | |||
| 216 | |||
| 217 | uint8_t matrix_master_scan(void) { | ||
| 218 | |||
| 219 | int ret = _matrix_scan(); | ||
| 220 | int mchanged = 1; | ||
| 221 | |||
| 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 | TXLED1; | ||
| 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 | TXLED0; | ||
| 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/naked60/rev1/rev1.c b/keyboards/naked60/rev1/rev1.c new file mode 100644 index 000000000..520a869e5 --- /dev/null +++ b/keyboards/naked60/rev1/rev1.c | |||
| @@ -0,0 +1 @@ | |||
| #include "rev1.h" | |||
diff --git a/keyboards/naked60/rev1/rev1.h b/keyboards/naked60/rev1/rev1.h new file mode 100644 index 000000000..38e355cfc --- /dev/null +++ b/keyboards/naked60/rev1/rev1.h | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "naked60.h" | ||
| 4 | |||
| 5 | #include "quantum.h" | ||
| 6 | |||
| 7 | #ifdef RGBLIGHT_ENABLE | ||
| 8 | //rgb led driver | ||
| 9 | #include "ws2812.h" | ||
| 10 | #endif | ||
| 11 | |||
| 12 | |||
| 13 | ////////////////////////////////////////////////////////////////////////////// | ||
| 14 | // When only use naked60. | ||
| 15 | ////////////////////////////////////////////////////////////////////////////// | ||
| 16 | /* | ||
| 17 | * ,------------------------------------ ------------------------------------. | ||
| 18 | * | L00 | L01 | L02 | L03 | L04 | L05 | | L06 | L07 | L08 | L09 | L0A | L0B | | ||
| 19 | * |------------------------------------ ------------------------------------+ | ||
| 20 | * | L10 | L11 | L12 | L13 | L14 | L15 | | L16 | L17 | L18 | L19 | L1A | L1B | | ||
| 21 | * |------------------------------------ ------------------------------------+ | ||
| 22 | * | L20 | L21 | L22 | L23 | L24 | L25 | | L26 | L17 | L28 | L29 | L2A | L2B | | ||
| 23 | * |------------------------------------ ------------------------------------+ | ||
| 24 | * | L30 | L31 | L32 | L33 | L34 | L35 | | L36 | L37 | L38 | L39 | L3A | L3B | | ||
| 25 | * |-----------------------------------------------------------------------' | ||
| 26 | * | L40 | L41 | L42 | L43 | L44 | L45 | L46 | L47 | L48 | L49 | L4A | L4B | | ||
| 27 | * |-----------------------------------------------------------------------' | ||
| 28 | */ | ||
| 29 | |||
| 30 | #define LAYOUT( \ | ||
| 31 | L00, L01, L02, L03, L04, L05, L06, L07, L08, L09, L0A, L0B, \ | ||
| 32 | L10, L11, L12, L13, L14, L15, L16, L17, L18, L19, L1A, L1B, \ | ||
| 33 | L20, L21, L22, L23, L24, L25, L26, L27, L28, L29, L2A, L2B, \ | ||
| 34 | L30, L31, L32, L33, L34, L35, L36, L37, L38, L39, L3A, L3B, \ | ||
| 35 | L40, L41, L42, L43, L44, L45, L46, L47, L48, L49, L4A, L4B \ | ||
| 36 | ) \ | ||
| 37 | { \ | ||
| 38 | { L00, L01, L02, L03, L04, L05, L06, L07, L08, L09, L0A, L0B }, \ | ||
| 39 | { L10, L11, L12, L13, L14, L15, L16, L17, L18, L19, L1A, L1B }, \ | ||
| 40 | { L20, L21, L22, L23, L24, L25, L26, L27, L28, L29, L2A, L2B }, \ | ||
| 41 | { L30, L31, L32, L33, L34, L35, L36, L37, L38, L39, L3A, L3B }, \ | ||
| 42 | { L40, L41, L42, L43, L44, L45, L46, L47, L48, L49, L4A, L4B }, \ | ||
| 43 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 44 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 45 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 46 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 47 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO } \ | ||
| 48 | } | ||
| 49 | |||
| 50 | ////////////////////////////////////////////////////////////////////////////// | ||
| 51 | // When connecting Setta21 to naked60. | ||
| 52 | ////////////////////////////////////////////////////////////////////////////// | ||
| 53 | |||
| 54 | #define LAYOUT_with_setta21( \ | ||
| 55 | L00, L01, L02, L03, L04, L05, L06, L07, L08, L09, L0A, L0B, R00, R01, R02, R03, R04, R05, \ | ||
| 56 | L10, L11, L12, L13, L14, L15, L16, L17, L18, L19, L1A, L1B, R11, R12, R13, R14, R15, \ | ||
| 57 | L20, L21, L22, L23, L24, L25, L26, L27, L28, L29, L2A, L2B, R20, R21, R22, R23, R24, R25, \ | ||
| 58 | L30, L31, L32, L33, L34, L35, L36, L37, L38, L39, L3A, L3B, R30, R32, R34, R35, \ | ||
| 59 | L40, L41, L42, L43, L44, L45, L46, L47, L48, L49, L4A, L4B \ | ||
| 60 | ) \ | ||
| 61 | { \ | ||
| 62 | { L00, L01, L02, L03, L04, L05, L06, L07, L08, L09, L0A, L0B,KC_NO,KC_NO }, \ | ||
| 63 | { L10, L11, L12, L13, L14, L15, L16, L17, L18, L19, L1A, L1B,KC_NO,KC_NO }, \ | ||
| 64 | { L20, L21, L22, L23, L24, L25, L26, L27, L28, L29, L2A, L2B,KC_NO,KC_NO }, \ | ||
| 65 | { L30, L31, L32, L33, L34, L35, L36, L37, L38, L39, L3A, L3B,KC_NO,KC_NO }, \ | ||
| 66 | { L40, L41, L42, L43, L44, L45, L46, L47, L48, L49, L4A, L4B,KC_NO,KC_NO }, \ | ||
| 67 | { R00, R01, R02, R03, R04, R05,KC_NO,KC_NO,KC_NO, R11, R12, R13, R14, R15 }, \ | ||
| 68 | { R20, R21, R22, R23, R24, R25,KC_NO,KC_NO, R30,KC_NO, R32,KC_NO, R34, R35 }, \ | ||
| 69 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 70 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 71 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO } \ | ||
| 72 | } | ||
| 73 | |||
| 74 | ////////////////////////////////////////////////////////////////////////////// | ||
| 75 | // When connecting Nafuda to naked60. | ||
| 76 | ////////////////////////////////////////////////////////////////////////////// | ||
| 77 | |||
| 78 | #define LAYOUT_with_nafuda( \ | ||
| 79 | L00, L01, L02, L03, L04, L05, L06, L07, L08, L09, L0A, L0B, R01, \ | ||
| 80 | L10, L11, L12, L13, L14, L15, L16, L17, L18, L19, L1A, L1B, R10, R11, R12, \ | ||
| 81 | L20, L21, L22, L23, L24, L25, L26, L27, L28, L29, L2A, L2B, R20, R21, R22, \ | ||
| 82 | L30, L31, L32, L33, L34, L35, L36, L37, L38, L39, L3A, L3B, \ | ||
| 83 | L40, L41, L42, L43, L44, L45, L46, L47, L48, L49, L4A, L4B \ | ||
| 84 | ) \ | ||
| 85 | { \ | ||
| 86 | { L00, L01, L02, L03, L04, L05, L06, L07, L08, L09, L0A, L0B,KC_NO,KC_NO }, \ | ||
| 87 | { L10, L11, L12, L13, L14, L15, L16, L17, L18, L19, L1A, L1B,KC_NO,KC_NO }, \ | ||
| 88 | { L20, L21, L22, L23, L24, L25, L26, L27, L28, L29, L2A, L2B,KC_NO,KC_NO }, \ | ||
| 89 | { L30, L31, L32, L33, L34, L35, L36, L37, L38, L39, L3A, L3B,KC_NO,KC_NO }, \ | ||
| 90 | { L40, L41, L42, L43, L44, L45, L46, L47, L48, L49, L4A, L4B,KC_NO,KC_NO }, \ | ||
| 91 | {KC_NO, R01,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO, R10, R11, R12,KC_NO,KC_NO,KC_NO }, \ | ||
| 92 | { R20, R21, R22,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 93 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 94 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \ | ||
| 95 | {KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO } \ | ||
| 96 | } | ||
| 97 | |||
diff --git a/keyboards/naked60/rev1/rules.mk b/keyboards/naked60/rev1/rules.mk new file mode 100644 index 000000000..a71181033 --- /dev/null +++ b/keyboards/naked60/rev1/rules.mk | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | SRC += matrix.c \ | ||
| 2 | split_util.c \ | ||
| 3 | split_scomm.c | ||
diff --git a/keyboards/naked60/rev1/serial_config.h b/keyboards/naked60/rev1/serial_config.h new file mode 100644 index 000000000..37135213d --- /dev/null +++ b/keyboards/naked60/rev1/serial_config.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | //// #error rev2 serial config | ||
| 2 | |||
| 3 | #ifndef SOFT_SERIAL_PIN | ||
| 4 | /* Soft Serial defines */ | ||
| 5 | #define SOFT_SERIAL_PIN D2 | ||
| 6 | |||
| 7 | #define SERIAL_USE_MULTI_TRANSACTION | ||
| 8 | #endif | ||
diff --git a/keyboards/naked60/rev1/serial_config_simpleapi.h b/keyboards/naked60/rev1/serial_config_simpleapi.h new file mode 100644 index 000000000..e2d22a41e --- /dev/null +++ b/keyboards/naked60/rev1/serial_config_simpleapi.h | |||
| @@ -0,0 +1,8 @@ | |||
| 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/naked60/rev1/split_scomm.c b/keyboards/naked60/rev1/split_scomm.c new file mode 100644 index 000000000..ada786796 --- /dev/null +++ b/keyboards/naked60/rev1/split_scomm.c | |||
| @@ -0,0 +1,92 @@ | |||
| 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 CONSOLE_ENABLE | ||
| 11 | #include <print.h> | ||
| 12 | #endif | ||
| 13 | |||
| 14 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
| 15 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
| 16 | uint8_t volatile status_com = 0; | ||
| 17 | uint8_t volatile status1 = 0; | ||
| 18 | uint8_t slave_buffer_change_count = 0; | ||
| 19 | uint8_t s_change_old = 0xff; | ||
| 20 | uint8_t s_change_new = 0xff; | ||
| 21 | |||
| 22 | SSTD_t transactions[] = { | ||
| 23 | #define GET_SLAVE_STATUS 0 | ||
| 24 | /* master buffer not changed, only recive slave_buffer_change_count */ | ||
| 25 | { (uint8_t *)&status_com, | ||
| 26 | 0, NULL, | ||
| 27 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 28 | }, | ||
| 29 | #define PUT_MASTER_GET_SLAVE_STATUS 1 | ||
| 30 | /* master buffer changed need send, and recive slave_buffer_change_count */ | ||
| 31 | { (uint8_t *)&status_com, | ||
| 32 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
| 33 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 34 | }, | ||
| 35 | #define GET_SLAVE_BUFFER 2 | ||
| 36 | /* recive serial_slave_buffer */ | ||
| 37 | { (uint8_t *)&status1, | ||
| 38 | 0, NULL, | ||
| 39 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
| 40 | } | ||
| 41 | }; | ||
| 42 | |||
| 43 | void serial_master_init(void) | ||
| 44 | { | ||
| 45 | soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); | ||
| 46 | } | ||
| 47 | |||
| 48 | void serial_slave_init(void) | ||
| 49 | { | ||
| 50 | soft_serial_target_init(transactions, TID_LIMIT(transactions)); | ||
| 51 | } | ||
| 52 | |||
| 53 | // 0 => no error | ||
| 54 | // 1 => slave did not respond | ||
| 55 | // 2 => checksum error | ||
| 56 | int serial_update_buffers(int master_update) | ||
| 57 | { | ||
| 58 | int status, smatstatus; | ||
| 59 | static int need_retry = 0; | ||
| 60 | |||
| 61 | if( s_change_old != s_change_new ) { | ||
| 62 | smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER); | ||
| 63 | if( smatstatus == TRANSACTION_END ) { | ||
| 64 | s_change_old = s_change_new; | ||
| 65 | #ifdef CONSOLE_ENABLE | ||
| 66 | uprintf("slave matrix = %b %b %b %b %b\n", | ||
| 67 | serial_slave_buffer[0], serial_slave_buffer[1], | ||
| 68 | serial_slave_buffer[2], serial_slave_buffer[3], | ||
| 69 | serial_slave_buffer[4] ); | ||
| 70 | #endif | ||
| 71 | } | ||
| 72 | } else { | ||
| 73 | // serial_slave_buffer dosen't change | ||
| 74 | smatstatus = TRANSACTION_END; // dummy status | ||
| 75 | } | ||
| 76 | |||
| 77 | if( !master_update && !need_retry) { | ||
| 78 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
| 79 | } else { | ||
| 80 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
| 81 | } | ||
| 82 | if( status == TRANSACTION_END ) { | ||
| 83 | s_change_new = slave_buffer_change_count; | ||
| 84 | need_retry = 0; | ||
| 85 | } else { | ||
| 86 | need_retry = 1; | ||
| 87 | } | ||
| 88 | return smatstatus; | ||
| 89 | } | ||
| 90 | |||
| 91 | #endif // SERIAL_USE_MULTI_TRANSACTION | ||
| 92 | #endif /* USE_SERIAL */ | ||
diff --git a/keyboards/naked60/rev1/split_scomm.h b/keyboards/naked60/rev1/split_scomm.h new file mode 100644 index 000000000..537ec4080 --- /dev/null +++ b/keyboards/naked60/rev1/split_scomm.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 4 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */ | ||
| 5 | #include "serial.h" | ||
| 6 | |||
| 7 | #else | ||
| 8 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 9 | // Buffers for master - slave communication | ||
| 10 | #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 11 | #define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 12 | |||
| 13 | extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; | ||
| 14 | extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; | ||
| 15 | extern uint8_t slave_buffer_change_count; | ||
| 16 | |||
| 17 | void serial_master_init(void); | ||
| 18 | void serial_slave_init(void); | ||
| 19 | int serial_update_buffers(int master_changed); | ||
| 20 | |||
| 21 | #endif | ||
| 22 | |||
diff --git a/keyboards/naked60/rev1/split_util.c b/keyboards/naked60/rev1/split_util.c new file mode 100644 index 000000000..e1ff8b437 --- /dev/null +++ b/keyboards/naked60/rev1/split_util.c | |||
| @@ -0,0 +1,70 @@ | |||
| 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/naked60/rev1/split_util.h b/keyboards/naked60/rev1/split_util.h new file mode 100644 index 000000000..f59304756 --- /dev/null +++ b/keyboards/naked60/rev1/split_util.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <stdbool.h> | ||
| 4 | #include "eeconfig.h" | ||
| 5 | |||
| 6 | #define SLAVE_I2C_ADDRESS 0x32 | ||
| 7 | |||
| 8 | extern volatile bool isLeftHand; | ||
| 9 | |||
| 10 | // slave version of matix scan, defined in matrix.c | ||
| 11 | void matrix_slave_scan(void); | ||
| 12 | |||
| 13 | void split_keyboard_setup(void); | ||
| 14 | bool has_usb(void); | ||
| 15 | |||
| 16 | void matrix_master_OLED_init (void); | ||
