diff options
| author | Monksoffunk <monksoffunk@users.noreply.github.com> | 2018-10-27 13:23:49 +0900 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2018-10-26 21:23:49 -0700 |
| commit | 23cd9f4dee791464196faaf6692599325cfe6f3c (patch) | |
| tree | 51a18c3beaa8f1937b1aa1efd5209ca8583b944a /keyboards/zinc | |
| parent | 73e92ef0c06de389d39d3ca0a8c98da2196ebec7 (diff) | |
| download | qmk_firmware-23cd9f4dee791464196faaf6692599325cfe6f3c.tar.gz qmk_firmware-23cd9f4dee791464196faaf6692599325cfe6f3c.zip | |
Keyboard: Add new keyboard Zinc (#4245)
* Add Zinc keyboard
* Fix photo
* Fix readme.md
* Fix RGB LED init of monks/keymap.c
* Fix default keymap and readme.jp
* Fix change DEFS of RGB ANIMATIONS to LED_ANIMATIONS
* Add EOL
* Use serial_config_simpleapi.h
* Fix comment char
* Fix error handling in split_scomm.c : mtei works
* Fix keymaps
* Remove DISABLE_LEADER definition
* Remove pro_micro.h
* Add 2 spaces after Hardware name
* Fix keymaps
- remove audio codes
- change LAYOUT to LAYOUT_ortho_4X12
- change "persistent_default_layer_set" to core function
* Use the Community Layouts feature
- with some clean up
Diffstat (limited to 'keyboards/zinc')
42 files changed, 3671 insertions, 0 deletions
diff --git a/keyboards/zinc/config.h b/keyboards/zinc/config.h new file mode 100644 index 000000000..9c60d631b --- /dev/null +++ b/keyboards/zinc/config.h | |||
| @@ -0,0 +1,50 @@ | |||
| 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 | //#ifndef CONFIG_H | ||
| 21 | //#define CONFIG_H | ||
| 22 | |||
| 23 | #include "config_common.h" | ||
| 24 | |||
| 25 | // GCC include 'config.h" sequence in qmk_firmware/keyboards/zinc/ | ||
| 26 | // -include keyboards/zinc/config.h | ||
| 27 | // -include keyboards/zinc/rev?/config.h | ||
| 28 | // -include keyboards/zinc/rev?/keymaps/MAPNAME/config.h | ||
| 29 | // XXXX.c | ||
| 30 | |||
| 31 | #include <serial_config.h> | ||
| 32 | |||
| 33 | // GCC include search path in qmk_firmare/keyboards/zinc/ | ||
| 34 | // #include "..." search starts here: | ||
| 35 | // #include <...> search starts here: | ||
| 36 | // keyboards/zinc/rev?/keymaps/MAPNAME | ||
| 37 | // keyboards/zinc | ||
| 38 | // keyboards/zinc/rev? | ||
| 39 | // . | ||
| 40 | // ./tmk_core | ||
| 41 | // ...... | ||
| 42 | |||
| 43 | #ifdef USE_Link_Time_Optimization | ||
| 44 | // LTO has issues with macros (action_get_macro) and "functions" (fn_actions), | ||
| 45 | // so just disable them | ||
| 46 | #define NO_ACTION_MACRO | ||
| 47 | #define NO_ACTION_FUNCTION | ||
| 48 | #endif // USE_Link_Time_Optimization | ||
| 49 | |||
| 50 | //#endif /* CONFIG_H */ | ||
diff --git a/keyboards/zinc/i2c.c b/keyboards/zinc/i2c.c new file mode 100644 index 000000000..4bee5c639 --- /dev/null +++ b/keyboards/zinc/i2c.c | |||
| @@ -0,0 +1,162 @@ | |||
| 1 | #include <util/twi.h> | ||
| 2 | #include <avr/io.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <avr/interrupt.h> | ||
| 5 | #include <util/twi.h> | ||
| 6 | #include <stdbool.h> | ||
| 7 | #include "i2c.h" | ||
| 8 | |||
| 9 | #ifdef USE_I2C | ||
| 10 | |||
| 11 | // Limits the amount of we wait for any one i2c transaction. | ||
| 12 | // Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is | ||
| 13 | // 9 bits, a single transaction will take around 90μs to complete. | ||
| 14 | // | ||
| 15 | // (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit | ||
| 16 | // poll loop takes at least 8 clock cycles to execute | ||
| 17 | #define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8 | ||
| 18 | |||
| 19 | #define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE) | ||
| 20 | |||
| 21 | volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; | ||
| 22 | |||
| 23 | static volatile uint8_t slave_buffer_pos; | ||
| 24 | static volatile bool slave_has_register_set = false; | ||
| 25 | |||
| 26 | // Wait for an i2c operation to finish | ||
| 27 | inline static | ||
| 28 | void i2c_delay(void) { | ||
| 29 | uint16_t lim = 0; | ||
| 30 | while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT) | ||
| 31 | lim++; | ||
| 32 | |||
| 33 | // easier way, but will wait slightly longer | ||
| 34 | // _delay_us(100); | ||
| 35 | } | ||
| 36 | |||
| 37 | // Setup twi to run at 100kHz or 400kHz (see ./i2c.h SCL_CLOCK) | ||
| 38 | void i2c_master_init(void) { | ||
| 39 | // no prescaler | ||
| 40 | TWSR = 0; | ||
| 41 | // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10. | ||
| 42 | // Check datasheets for more info. | ||
| 43 | TWBR = ((F_CPU/SCL_CLOCK)-16)/2; | ||
| 44 | } | ||
| 45 | |||
| 46 | // Start a transaction with the given i2c slave address. The direction of the | ||
| 47 | // transfer is set with I2C_READ and I2C_WRITE. | ||
| 48 | // returns: 0 => success | ||
| 49 | // 1 => error | ||
| 50 | uint8_t i2c_master_start(uint8_t address) { | ||
| 51 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTA); | ||
| 52 | |||
| 53 | i2c_delay(); | ||
| 54 | |||
| 55 | // check that we started successfully | ||
| 56 | if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START)) | ||
| 57 | return 1; | ||
| 58 | |||
| 59 | TWDR = address; | ||
| 60 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
| 61 | |||
| 62 | i2c_delay(); | ||
| 63 | |||
| 64 | if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) ) | ||
| 65 | return 1; // slave did not acknowledge | ||
| 66 | else | ||
| 67 | return 0; // success | ||
| 68 | } | ||
| 69 | |||
| 70 | |||
| 71 | // Finish the i2c transaction. | ||
| 72 | void i2c_master_stop(void) { | ||
| 73 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
| 74 | |||
| 75 | uint16_t lim = 0; | ||
| 76 | while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT) | ||
| 77 | lim++; | ||
| 78 | } | ||
| 79 | |||
| 80 | // Write one byte to the i2c slave. | ||
| 81 | // returns 0 => slave ACK | ||
| 82 | // 1 => slave NACK | ||
| 83 | uint8_t i2c_master_write(uint8_t data) { | ||
| 84 | TWDR = data; | ||
| 85 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
| 86 | |||
| 87 | i2c_delay(); | ||
| 88 | |||
| 89 | // check if the slave acknowledged us | ||
| 90 | return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1; | ||
| 91 | } | ||
| 92 | |||
| 93 | // Read one byte from the i2c slave. If ack=1 the slave is acknowledged, | ||
| 94 | // if ack=0 the acknowledge bit is not set. | ||
| 95 | // returns: byte read from i2c device | ||
| 96 | uint8_t i2c_master_read(int ack) { | ||
| 97 | TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA); | ||
| 98 | |||
| 99 | i2c_delay(); | ||
| 100 | return TWDR; | ||
| 101 | } | ||
| 102 | |||
| 103 | void i2c_reset_state(void) { | ||
| 104 | TWCR = 0; | ||
| 105 | } | ||
| 106 | |||
| 107 | void i2c_slave_init(uint8_t address) { | ||
| 108 | TWAR = address << 0; // slave i2c address | ||
| 109 | // TWEN - twi enable | ||
| 110 | // TWEA - enable address acknowledgement | ||
| 111 | // TWINT - twi interrupt flag | ||
| 112 | // TWIE - enable the twi interrupt | ||
| 113 | TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN); | ||
| 114 | } | ||
| 115 | |||
| 116 | ISR(TWI_vect); | ||
| 117 | |||
| 118 | ISR(TWI_vect) { | ||
| 119 | uint8_t ack = 1; | ||
| 120 | switch(TW_STATUS) { | ||
| 121 | case TW_SR_SLA_ACK: | ||
| 122 | // this device has been addressed as a slave receiver | ||
| 123 | slave_has_register_set = false; | ||
| 124 | break; | ||
| 125 | |||
| 126 | case TW_SR_DATA_ACK: | ||
| 127 | // this device has received data as a slave receiver | ||
| 128 | // The first byte that we receive in this transaction sets the location | ||
| 129 | // of the read/write location of the slaves memory that it exposes over | ||
| 130 | // i2c. After that, bytes will be written at slave_buffer_pos, incrementing | ||
| 131 | // slave_buffer_pos after each write. | ||
| 132 | if(!slave_has_register_set) { | ||
| 133 | slave_buffer_pos = TWDR; | ||
| 134 | // don't acknowledge the master if this memory loctaion is out of bounds | ||
| 135 | if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) { | ||
| 136 | ack = 0; | ||
| 137 | slave_buffer_pos = 0; | ||
| 138 | } | ||
| 139 | slave_has_register_set = true; | ||
| 140 | } else { | ||
| 141 | i2c_slave_buffer[slave_buffer_pos] = TWDR; | ||
| 142 | BUFFER_POS_INC(); | ||
| 143 | } | ||
| 144 | break; | ||
| 145 | |||
| 146 | case TW_ST_SLA_ACK: | ||
| 147 | case TW_ST_DATA_ACK: | ||
| 148 | // master has addressed this device as a slave transmitter and is | ||
| 149 | // requesting data. | ||
| 150 | TWDR = i2c_slave_buffer[slave_buffer_pos]; | ||
| 151 | BUFFER_POS_INC(); | ||
| 152 | break; | ||
| 153 | |||
| 154 | case TW_BUS_ERROR: // something went wrong, reset twi state | ||
| 155 | TWCR = 0; | ||
| 156 | default: | ||
| 157 | break; | ||
| 158 | } | ||
| 159 | // Reset everything, so we are ready for the next TWI interrupt | ||
| 160 | TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN); | ||
| 161 | } | ||
| 162 | #endif | ||
diff --git a/keyboards/zinc/i2c.h b/keyboards/zinc/i2c.h new file mode 100644 index 000000000..47cf6bd1b --- /dev/null +++ b/keyboards/zinc/i2c.h | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | #ifndef I2C_H | ||
| 2 | #define I2C_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #ifndef F_CPU | ||
| 7 | #define F_CPU 16000000UL | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #define I2C_READ 1 | ||
| 11 | #define I2C_WRITE 0 | ||
| 12 | |||
| 13 | #define I2C_ACK 1 | ||
| 14 | #define I2C_NACK 0 | ||
| 15 | |||
| 16 | #define SLAVE_BUFFER_SIZE 0x10 | ||
| 17 | |||
| 18 | // i2c SCL clock frequency 400kHz | ||
| 19 | #define SCL_CLOCK 400000L | ||
| 20 | |||
| 21 | extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; | ||
| 22 | |||
| 23 | void i2c_master_init(void); | ||
| 24 | uint8_t i2c_master_start(uint8_t address); | ||
| 25 | void i2c_master_stop(void); | ||
| 26 | uint8_t i2c_master_write(uint8_t data); | ||
| 27 | uint8_t i2c_master_read(int); | ||
| 28 | void i2c_reset_state(void); | ||
| 29 | void i2c_slave_init(uint8_t address); | ||
| 30 | |||
| 31 | |||
| 32 | static inline unsigned char i2c_start_read(unsigned char addr) { | ||
| 33 | return i2c_master_start((addr << 1) | I2C_READ); | ||
| 34 | } | ||
| 35 | |||
| 36 | static inline unsigned char i2c_start_write(unsigned char addr) { | ||
| 37 | return i2c_master_start((addr << 1) | I2C_WRITE); | ||
| 38 | } | ||
| 39 | |||
| 40 | // from SSD1306 scrips | ||
| 41 | extern unsigned char i2c_rep_start(unsigned char addr); | ||
| 42 | extern void i2c_start_wait(unsigned char addr); | ||
| 43 | extern unsigned char i2c_readAck(void); | ||
| 44 | extern unsigned char i2c_readNak(void); | ||
| 45 | extern unsigned char i2c_read(unsigned char ack); | ||
| 46 | |||
| 47 | #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); | ||
| 48 | |||
| 49 | #endif | ||
diff --git a/keyboards/zinc/info.json b/keyboards/zinc/info.json new file mode 100644 index 000000000..740f31ae6 --- /dev/null +++ b/keyboards/zinc/info.json | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | { | ||
| 2 | "keyboard_name": "Zinc", | ||
| 3 | "url": "https://github.com/monksoffunk/", | ||
| 4 | "maintainer": "monksoffunk", | ||
| 5 | "width": 15, | ||
| 6 | "height": 5, | ||
| 7 | "layouts": { | ||
| 8 | "LAYOUT": { | ||
| 9 | "key_count": 48, | ||
| 10 | "layout": [{"x":0, "y":0}, {"x":1, "y":0}, {"x":2, "y":0}, {"x":3, "y":0}, {"x":4, "y":0}, {"x":5, "y":0}, {"x":9, "y":0}, {"x":10, "y":0}, {"x":11, "y":0}, {"x":12, "y":0}, {"x":13, "y":0}, {"x":14, "y":0}, {"x":0, "y":1}, {"x":1, "y":1}, {"x":2, "y":1}, {"x":3, "y":1}, {"x":4, "y":1}, {"x":5, "y":1}, {"x":9, "y":1}, {"x":10, "y":1}, {"x":11, "y":1}, {"x":12, "y":1}, {"x":13, "y":1}, {"x":14, "y":1}, {"x":0, "y":2}, {"x":1, "y":2}, {"x":2, "y":2}, {"x":3, "y":2}, {"x":4, "y":2}, {"x":5, "y":2}, {"x":9, "y":2}, {"x":10, "y":2}, {"x":11, "y":2}, {"x":12, "y":2}, {"x":13, "y":2}, {"x":14, "y":2}, {"x":0, "y":3}, {"x":1, "y":3}, {"x":2, "y":3}, {"x":3, "y":3}, {"x":4, "y":3}, {"x":5, "y":3}, {"x":9, "y":3}, {"x":10, "y":3}, {"x":11, "y":3}, {"x":12, "y":3}, {"x":13, "y":3}, {"x":14, "y":3}] | ||
| 11 | } | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/keyboards/zinc/keymaps/default/config.h b/keyboards/zinc/keymaps/default/config.h new file mode 100644 index 000000000..4dcb0724f --- /dev/null +++ b/keyboards/zinc/keymaps/default/config.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | /* | ||
| 2 | This is the c configuration file for the keymap | ||
| 3 | |||
| 4 | Copyright 2018 monksoffunk | ||
| 5 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 6 | Copyright 2015 Jack Humbert | ||
| 7 | |||
| 8 | This program is free software: you can redistribute it and/or modify | ||
| 9 | it under the terms of the GNU General Public License as published by | ||
| 10 | the Free Software Foundation, either version 2 of the License, or | ||
| 11 | (at your option) any later version. | ||
| 12 | |||
| 13 | This program is distributed in the hope that it will be useful, | ||
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | GNU General Public License for more details. | ||
| 17 | |||
| 18 | You should have received a copy of the GNU General Public License | ||
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #pragma once | ||
| 23 | // if you need more program area, try uncomment follow line | ||
| 24 | #include "serial_config_simpleapi.h" | ||
| 25 | |||
| 26 | // place overrides here | ||
| 27 | // Selection of RGBLIGHT MODE to use. | ||
| 28 | #if defined(LED_ANIMATIONS) | ||
| 29 | #define RGBLIGHT_EFFECT_BREATHING | ||
| 30 | #define RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 31 | #define RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 32 | #define RGBLIGHT_EFFECT_SNAKE | ||
| 33 | #define RGBLIGHT_EFFECT_KNIGHT | ||
| 34 | #define RGBLIGHT_EFFECT_CHRISTMAS | ||
| 35 | #define RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
| 36 | //#define RGBLIGHT_EFFECT_RGB_TEST | ||
| 37 | //#define RGBLIGHT_EFFECT_ALTERNATING | ||
| 38 | #endif | ||
diff --git a/keyboards/zinc/keymaps/default/keymap.c b/keyboards/zinc/keymaps/default/keymap.c new file mode 100644 index 000000000..7729914ec --- /dev/null +++ b/keyboards/zinc/keymaps/default/keymap.c | |||
| @@ -0,0 +1,306 @@ | |||
| 1 | #include QMK_KEYBOARD_H | ||
| 2 | |||
| 3 | extern keymap_config_t keymap_config; | ||
| 4 | |||
| 5 | #ifdef RGBLIGHT_ENABLE | ||
| 6 | //Following line allows macro to read current RGB settings | ||
| 7 | extern rgblight_config_t rgblight_config; | ||
| 8 | rgblight_config_t RGB_current_config; | ||
| 9 | #endif | ||
| 10 | |||
| 11 | extern uint8_t is_master; | ||
| 12 | |||
| 13 | // Each layer gets a name for readability, which is then used in the keymap matrix below. | ||
| 14 | // The underscores don't mean anything - you can have a layer called STUFF or any other name. | ||
| 15 | // Layer names don't all need to be of the same length, obviously, and you can also skip them | ||
| 16 | // entirely and just use numbers. | ||
| 17 | enum layer_number { | ||
| 18 | _QWERTY = 0, | ||
| 19 | _COLEMAK, | ||
| 20 | _DVORAK, | ||
| 21 | _LOWER, | ||
| 22 | _RAISE, | ||
| 23 | _ADJUST | ||
| 24 | }; | ||
| 25 | |||
| 26 | enum custom_keycodes { | ||
| 27 | QWERTY = SAFE_RANGE, | ||
| 28 | COLEMAK, | ||
| 29 | DVORAK, | ||
| 30 | LOWER, | ||
| 31 | RAISE, | ||
| 32 | ADJUST, | ||
| 33 | BACKLIT, | ||
| 34 | KANA, | ||
| 35 | EISU, | ||
| 36 | RGBRST | ||
| 37 | }; | ||
| 38 | |||
| 39 | enum macro_keycodes { | ||
| 40 | KC_SAMPLEMACRO, | ||
| 41 | }; | ||
| 42 | |||
| 43 | //Macros | ||
| 44 | #define M_SAMPLE M(KC_SAMPLEMACRO) | ||
| 45 | |||
| 46 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { \ | ||
| 47 | /* Qwerty | ||
| 48 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 49 | * | Tab | Q | W | E | R | T | | Y | U | I | O | P | Bksp | | ||
| 50 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 51 | * | Ctrl | A | S | D | F | G | | H | J | K | L | ; | ' | | ||
| 52 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 53 | * | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter | | ||
| 54 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 55 | * | Esc |ADJUST| Win | Alt |LOWER |Space | | Space| RAISE| Left | Down | Up | Right| | ||
| 56 | * `-----------------------------------------' `-----------------------------------------' | ||
| 57 | */ | ||
| 58 | [_QWERTY] = LAYOUT_ortho_4x12( | ||
| 59 | KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \ | ||
| 60 | KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \ | ||
| 61 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \ | ||
| 62 | KC_ESC, ADJUST, KC_LGUI, KC_LALT, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \ | ||
| 63 | ), | ||
| 64 | |||
| 65 | /* Colemak | ||
| 66 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 67 | * | Tab | Q | W | F | P | G | | J | L | U | Y | ; | Bksp | | ||
| 68 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 69 | * | Ctrl | A | R | S | T | D | | H | N | E | I | O | ' | | ||
| 70 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 71 | * | Shift| Z | X | C | V | B | | K | M | , | . | / |Enter | | ||
| 72 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 73 | * | Esc |ADJUST| Alt | Win |LOWER |Space | | Space| RAISE| Left | Down | Up | Right| | ||
| 74 | * `-----------------------------------------' `-----------------------------------------' | ||
| 75 | */ | ||
| 76 | [_COLEMAK] = LAYOUT_ortho_4x12( \ | ||
| 77 | KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, \ | ||
| 78 | KC_LCTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, \ | ||
| 79 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \ | ||
| 80 | KC_ESC, ADJUST, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \ | ||
| 81 | ), | ||
| 82 | |||
| 83 | /* Dvorak | ||
| 84 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 85 | * | Tab | ' | , | . | P | Y | | F | G | C | R | L | Del | | ||
| 86 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 87 | * | Ctrl | A | O | E | U | I | | D | H | T | N | S | / | | ||
| 88 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 89 | * | Shift| ; | Q | J | K | X | | B | M | W | V | Z |Enter | | ||
| 90 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 91 | * | Esc |ADJUST| Alt | Win |LOWER |Space | | Space| RAISE| Left | Down | Up | Right| | ||
| 92 | * `-----------------------------------------' `-----------------------------------------' | ||
| 93 | */ | ||
| 94 | [_DVORAK] = LAYOUT_ortho_4x12( \ | ||
| 95 | KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_DEL, \ | ||
| 96 | KC_LCTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH, \ | ||
| 97 | KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT , \ | ||
| 98 | KC_ESC, ADJUST, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \ | ||
| 99 | ), | ||
| 100 | |||
| 101 | /* Lower | ||
| 102 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 103 | * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | | | ||
| 104 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 105 | * | | | | | | | | - | _ | + | { | } | | | | ||
| 106 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 107 | * | | | | | | | | | | | Home | End | | | ||
| 108 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 109 | * | | | | | | | | | | Next | Vol- | Vol+ | Play | | ||
| 110 | * `-----------------------------------------' `-----------------------------------------' | ||
| 111 | */ | ||
| 112 | [_LOWER] = LAYOUT_ortho_4x12( \ | ||
| 113 | KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______, \ | ||
| 114 | _______, _______, _______, _______, _______, _______, KC_MINS, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \ | ||
| 115 | _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_END, _______, \ | ||
| 116 | _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \ | ||
| 117 | ), | ||
| 118 | |||
| 119 | /* Raise | ||
| 120 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 121 | * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Del | | ||
| 122 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 123 | * | | F1 | F2 | F3 | F4 | F5 | | F6 | - | = | [ | ] | \ | | ||
| 124 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 125 | * | | F7 | F8 | F9 | F10 | F11 | | F12 | | | | | | ||
| 126 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 127 | * | | | | | | | | | | Next | Vol- | Vol+ | Play | | ||
| 128 | * `-----------------------------------------' `-----------------------------------------' | ||
| 129 | */ | ||
| 130 | [_RAISE] = LAYOUT_ortho_4x12( \ | ||
| 131 | KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \ | ||
| 132 | _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \ | ||
| 133 | _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______, \ | ||
| 134 | _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \ | ||
| 135 | ), | ||
| 136 | |||
| 137 | /* Adjust (Lower + Raise) | ||
| 138 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 139 | * | | Reset|RGBRST|Aud on|Audoff| | | |Qwerty|Colemk|Dvorak| | Ins | | ||
| 140 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 141 | * | |RGB ON| HUE+ | SAT+ | VAL+ | Mac | | Win | - | = |Print |ScLock|Pause | | ||
| 142 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 143 | * | | MODE | HUE- | SAT- | VAL- | | | | | | | | | | ||
| 144 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 145 | * | | | | EISU | EISU | EISU | | KANA | KANA | Home |PageDn|PageUp| End | | ||
| 146 | * `-----------------------------------------' `-----------------------------------------' | ||
| 147 | */ | ||
| 148 | [_ADJUST] = LAYOUT_ortho_4x12( \ | ||
| 149 | _______, RESET, RGBRST, _______, _______, _______, _______, QWERTY, COLEMAK, DVORAK, _______, KC_INS, \ | ||
| 150 | _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, AG_NORM, AG_SWAP, KC_MINS, KC_EQL, KC_PSCR, KC_SLCK, KC_PAUS,\ | ||
| 151 | _______, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, _______, _______, _______, _______, _______, _______, _______,\ | ||
| 152 | _______, _______, _______, EISU, EISU, EISU, KANA, KANA, KC_HOME, KC_PGDN, KC_PGUP, KC_END\ | ||
| 153 | ) | ||
| 154 | }; | ||
| 155 | |||
| 156 | // define variables for reactive RGB | ||
| 157 | bool TOG_STATUS = false; | ||
| 158 | |||
| 159 | // Setting ADJUST layer RGB back to default | ||
| 160 | void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) { | ||
| 161 | if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { | ||
| 162 | #ifdef RGBLIGHT_ENABLE | ||
| 163 | rgblight_mode_noeeprom(RGB_current_config.mode); | ||
| 164 | #endif | ||
| 165 | layer_on(layer3); | ||
| 166 | } else { | ||
| 167 | layer_off(layer3); | ||
| 168 | } | ||
| 169 | } | ||
| 170 | |||
| 171 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 172 | switch (keycode) { | ||
| 173 | case QWERTY: | ||
| 174 | if (record->event.pressed) { | ||
| 175 | set_single_persistent_default_layer(_QWERTY); | ||
| 176 | } | ||
| 177 | return false; | ||
| 178 | break; | ||
| 179 | case COLEMAK: | ||
| 180 | if (record->event.pressed) { | ||
| 181 | set_single_persistent_default_layer(_COLEMAK); | ||
| 182 | } | ||
| 183 | return false; | ||
| 184 | break; | ||
| 185 | case DVORAK: | ||
| 186 | if (record->event.pressed) { | ||
| 187 | set_single_persistent_default_layer(_DVORAK); | ||
| 188 | } | ||
| 189 | return false; | ||
| 190 | break; | ||
| 191 | |||
| 192 | case LOWER: | ||
| 193 | if (record->event.pressed) { | ||
| 194 | //not sure how to have keyboard check mode and set it to a variable, so my work around | ||
| 195 | //uses another variable that would be set to true after the first time a reactive key is pressed. | ||
| 196 | if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false | ||
| 197 | } else { | ||
| 198 | TOG_STATUS = !TOG_STATUS; | ||
| 199 | #ifdef RGBLIGHT_ENABLE | ||
| 200 | rgblight_mode_noeeprom(16); | ||
| 201 | #endif | ||
| 202 | } | ||
| 203 | layer_on(_LOWER); | ||
| 204 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); | ||
| 205 | } else { | ||
| 206 | #ifdef RGBLIGHT_ENABLE | ||
| 207 | rgblight_mode_noeeprom(RGB_current_config.mode); // revert RGB to initial mode prior to RGB mode change | ||
| 208 | #endif | ||
| 209 | TOG_STATUS = false; | ||
| 210 | layer_off(_LOWER); | ||
| 211 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); | ||
| 212 | } | ||
| 213 | return false; | ||
| 214 | break; | ||
| 215 | |||
| 216 | case RAISE: | ||
| 217 | if (record->event.pressed) { | ||
| 218 | //not sure how to have keyboard check mode and set it to a variable, so my work around | ||
| 219 | //uses another variable that would be set to true after the first time a reactive key is pressed. | ||
| 220 | if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false | ||
| 221 | } else { | ||
| 222 | TOG_STATUS = !TOG_STATUS; | ||
| 223 | #ifdef RGBLIGHT_ENABLE | ||
| 224 | rgblight_mode_noeeprom(15); | ||
| 225 | #endif | ||
| 226 | } | ||
| 227 | layer_on(_RAISE); | ||
| 228 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); | ||
| 229 | } else { | ||
| 230 | #ifdef RGBLIGHT_ENABLE | ||
| 231 | rgblight_mode_noeeprom(RGB_current_config.mode); // revert RGB to initial mode prior to RGB mode change | ||
| 232 | #endif | ||
| 233 | layer_off(_RAISE); | ||
| 234 | TOG_STATUS = false; | ||
| 235 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); | ||
| 236 | } | ||
| 237 | return false; | ||
| 238 | break; | ||
| 239 | |||
| 240 | case ADJUST: | ||
| 241 | if (record->event.pressed) { | ||
| 242 | layer_on(_ADJUST); | ||
| 243 | } else { | ||
| 244 | layer_off(_ADJUST); | ||
| 245 | } | ||
| 246 | return false; | ||
| 247 | break; | ||
| 248 | //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released | ||
| 249 | case RGB_MOD: | ||
| 250 | #ifdef RGBLIGHT_ENABLE | ||
| 251 | if (record->event.pressed) { | ||
| 252 | rgblight_mode_noeeprom(RGB_current_config.mode); | ||
| 253 | rgblight_step(); | ||
| 254 | RGB_current_config.mode = rgblight_config.mode; | ||
| 255 | } | ||
| 256 | #endif | ||
| 257 | return false; | ||
| 258 | break; | ||
| 259 | |||
| 260 | case EISU: | ||
| 261 | if (record->event.pressed) { | ||
| 262 | if(keymap_config.swap_lalt_lgui==false){ | ||
| 263 | register_code(KC_LANG2); | ||
| 264 | }else{ | ||
| 265 | SEND_STRING(SS_LALT("`")); | ||
| 266 | } | ||
| 267 | } else { | ||
| 268 | unregister_code(KC_LANG2); | ||
| 269 | } | ||
| 270 | return false; | ||
| 271 | break; | ||
| 272 | case KANA: | ||
| 273 | if (record->event.pressed) { | ||
| 274 | if(keymap_config.swap_lalt_lgui==false){ | ||
| 275 | register_code(KC_LANG1); | ||
| 276 | }else{ | ||
| 277 | SEND_STRING(SS_LALT("`")); | ||
| 278 | } | ||
| 279 | } else { | ||
| 280 | unregister_code(KC_LANG1); | ||
| 281 | } | ||
| 282 | return false; | ||
| 283 | break; | ||
| 284 | |||
| 285 | case RGBRST: | ||
| 286 | #ifdef RGBLIGHT_ENABLE | ||
| 287 | if (record->event.pressed) { | ||
| 288 | eeconfig_update_rgblight_default(); | ||
| 289 | rgblight_enable(); | ||
| 290 | RGB_current_config = rgblight_config; | ||
| 291 | } | ||
| 292 | #endif | ||
| 293 | break; | ||
| 294 | } | ||
| 295 | return true; | ||
| 296 | } | ||
| 297 | |||
| 298 | |||
| 299 | void matrix_init_user(void) { | ||
| 300 | #ifdef RGBLIGHT_ENABLE | ||
| 301 | rgblight_init(); | ||
| 302 | RGB_current_config = rgblight_config; | ||
| 303 | #endif | ||
| 304 | } | ||
| 305 | |||
| 306 | |||
diff --git a/keyboards/zinc/keymaps/default/readme_jp.md b/keyboards/zinc/keymaps/default/readme_jp.md new file mode 100644 index 000000000..f6e91f0c8 --- /dev/null +++ b/keyboards/zinc/keymaps/default/readme_jp.md | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | # The Default Zinc Layout | ||
| 2 | ## 配列 | ||
| 3 | |||
| 4 | ### Qwerty配列 | ||
| 5 | |||
| 6 | ``` | ||
| 7 | ,-----------------------------------------. ,-----------------------------------------. | ||
| 8 | | Tab | Q | W | E | R | T | | Y | U | I | O | P | Bksp | | ||
| 9 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 10 | | Ctrl | A | S | D | F | G | | H | J | K | L | ; | ' | | ||
| 11 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 12 | | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter | | ||
| 13 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 14 | | Esc | Fn | Alt | Win |Lower |Space | | Space| Raise| Left | Down | Up | Right| | ||
| 15 | `------------------------------------------ ------------------------------------------' | ||
| 16 | ``` | ||
| 17 | |||
| 18 | ### Colemak | ||
| 19 | |||
| 20 | ``` | ||
| 21 | ,-----------------------------------------. ,-----------------------------------------. | ||
| 22 | | Tab | Q | W | F | P | G | | J | L | U | Y | ; | Bksp | | ||
| 23 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 24 | | Ctrl | A | R | S | T | D | | H | N | E | I | O | ' | | ||
| 25 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 26 | | Shift| Z | X | C | V | B | | K | M | , | . | / |Enter | | ||
| 27 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 28 | | Esc |ADJUST| Alt | Win |LOWER |Space | | Space| RAISE| Left | Down | Up | Right| | ||
| 29 | `------------------------------------------ ------------------------------------------' | ||
| 30 | ``` | ||
| 31 | |||
| 32 | ### Dvorak | ||
| 33 | |||
| 34 | ``` | ||
| 35 | ,-----------------------------------------. ,-----------------------------------------. | ||
| 36 | | Tab | ' | , | . | P | Y | | F | G | C | R | L | Del | | ||
| 37 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 38 | | Ctrl | A | O | E | U | I | | D | H | T | N | S | / | | ||
| 39 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 40 | | Shift| ; | Q | J | K | X | | B | M | W | V | Z |Enter | | ||
| 41 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 42 | | Esc |ADJUST| Alt | Win |LOWER |Space | | Space| RAISE| Left | Down | Up | Right| | ||
| 43 | `-----------------------------------------' `-----------------------------------------' | ||
| 44 | ``` | ||
| 45 | |||
| 46 | |||
| 47 | ## コンパイルの仕方 | ||
| 48 | |||
| 49 | コンパイルは、qmk_firmware のトップディレクトリで行います。 | ||
| 50 | |||
| 51 | ``` | ||
| 52 | $ cd qmk_firmware | ||
| 53 | ``` | ||
| 54 | qmk_firmwareでは各キーボードのコンパイルは、`<キーボード名>:<キーマップ名>`という指定で行います。 | ||
| 55 | |||
| 56 | ``` | ||
| 57 | $ make zinc:default | ||
| 58 | ``` | ||
| 59 | |||
| 60 | キーボードへの書き込みまで同時に行うには下記のように`:avrdude`を付けます。 | ||
| 61 | |||
| 62 | ``` | ||
| 63 | $ make zinc:default:avrdude | ||
| 64 | ``` | ||
| 65 | |||
| 66 | コンパイル結果と中間生成物を消去したい場合は以下のようにします。 | ||
| 67 | |||
| 68 | ``` | ||
| 69 | $ make zinc:default:clean | ||
| 70 | ``` | ||
| 71 | |||
| 72 | ## カスタマイズ | ||
| 73 | |||
| 74 | コマンドラインからオプションを指定してビルドすることが出来ます。 | ||
| 75 | |||
| 76 | ``` | ||
| 77 | # Zinc keyboard 'default' keymap: convenient command line option | ||
| 78 | make ZINC=<options> zinc:defualt | ||
| 79 | # option= back | under | na | ios | ||
| 80 | # ex. | ||
| 81 | # make ZINC=under zinc:defualt | ||
| 82 | # make ZINC=under,ios zinc:defualt | ||
| 83 | # make ZINC=back zinc:default | ||
| 84 | # make ZINC=back,na zinc:default | ||
| 85 | # make ZINC=back,ios zinc:default | ||
| 86 | ``` | ||
| 87 | |||
| 88 | あるいは`qmk_firmware/keyboards/zinc/rev1/keymaps/default/rules.mk` の以下の部分を直接編集して機能を有効化してください。 | ||
| 89 | |||
| 90 | ``` | ||
| 91 | # Zinc keyboard customize | ||
| 92 | LED_BACK_ENABLE = no # LED backlight (Enable SK6812mini backlight) | ||
| 93 | LED_UNDERGLOW_ENABLE = no # LED underglow (Enable WS2812 RGB underlight) | ||
| 94 | LED_ANIMATIONS = yes # LED animations | ||
| 95 | IOS_DEVICE_ENABLE = no # connect to IOS device (iPad,iPhone) | ||
| 96 | |||
| 97 | |||
| 98 | ``` | ||
| 99 | |||
| 100 | ## RGB backlight を有効にする | ||
| 101 | |||
| 102 | rules.mk の下記の部分を編集して no を yes に変更してください。 | ||
| 103 | ``` | ||
| 104 | LED_BACK_ENABLE = yes # LED backlight (Enable SK6812mini backlight) | ||
| 105 | ``` | ||
| 106 | |||
| 107 | |||
| 108 | ## RGB Underglow を有効にする | ||
| 109 | |||
| 110 | rules.mk の下記の部分を編集して no を yes に変更してください。 | ||
| 111 | ``` | ||
| 112 | LED_UNDERGLOW_ENABLE = yes # LED underglow (Enable WS2812 RGB underlight.) | ||
| 113 | ``` | ||
| 114 | |||
| 115 | |||
| 116 | ## iPad/iPhoneサポートを有効にする。 | ||
| 117 | |||
| 118 | rules.mk の下記の部分を編集して no を yes に変更してください。 | ||
| 119 | RBG Underglow や RGBバックライトの輝度を抑えて、iPad, iPhone にも接続できるようになります。 | ||
| 120 | |||
| 121 | ``` | ||
| 122 | IOS_DEVICE_ENABLE = no # connect to IOS device (iPad,iPhone) | ||
| 123 | ``` \ No newline at end of file | ||
diff --git a/keyboards/zinc/keymaps/default/rules.mk b/keyboards/zinc/keymaps/default/rules.mk new file mode 100644 index 000000000..2dcefc001 --- /dev/null +++ b/keyboards/zinc/keymaps/default/rules.mk | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | |||
| 2 | # Build Options | ||
| 3 | # change to "no" to disable the options, or define them in the Makefile in | ||
| 4 | # the appropriate keymap folder that will get included automatically | ||
| 5 | # | ||
| 6 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | ||
| 7 | MOUSEKEY_ENABLE = no # Mouse keys(+4700) | ||
| 8 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | ||
| 9 | CONSOLE_ENABLE = no # Console for debug(+400) | ||
| 10 | COMMAND_ENABLE = no # Commands for debug and configuration | ||
| 11 | NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | ||
| 12 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | ||
| 13 | MIDI_ENABLE = no # MIDI controls | ||
| 14 | AUDIO_ENABLE = no # Audio output on port C6 | ||
| 15 | UNICODE_ENABLE = no # Unicode | ||
| 16 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | ||
| 17 | RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. | ||
| 18 | SWAP_HANDS_ENABLE = no # Enable one-hand typing | ||
| 19 | |||
| 20 | define ZINC_CUSTOMISE_MSG | ||
| 21 | $(info Zinc customize) | ||
| 22 | $(info - LED_BACK_ENABLE=$(LED_BACK_ENABLE)) | ||
| 23 | $(info - LED_UNDERGLOW_ENABLE=$(LED_UNDERGLOW_ENABLE)) | ||
| 24 | $(info - LED_ANIMATION=$(LED_ANIMATIONS)) | ||
| 25 | $(info - IOS_DEVICE_ENABLE=$(IOS_DEVICE_ENABLE)) | ||
| 26 | endef | ||
| 27 | |||
| 28 | # Zinc keyboard customize | ||
| 29 | LED_BACK_ENABLE = no # LED backlight (Enable SK6812mini backlight) | ||
| 30 | LED_UNDERGLOW_ENABLE = no # LED underglow (Enable WS2812 RGB underlight) | ||
| 31 | LED_ANIMATIONS = yes # LED animations | ||
| 32 | IOS_DEVICE_ENABLE = no # connect to IOS device (iPad,iPhone) | ||
| 33 | Link_Time_Optimization = no # if firmware size over limit, try this option | ||
| 34 | |||
| 35 | #### LED_BACK_ENABLE and LED_UNDERGLOW_ENABLE. | ||
| 36 | #### Do not enable these with audio at the same time. | ||
| 37 | |||
| 38 | ### Zinc keyboard 'default' keymap: convenient command line option | ||
| 39 | ## make ZINC=<options> zinc:defualt | ||
| 40 | ## option= back | under | na | ios | ||
| 41 | ## ex. | ||
| 42 | ## make ZINC=under zinc:defualt | ||
| 43 | ## make ZINC=under,ios zinc:defualt | ||
| 44 | ## make ZINC=back zinc:default | ||
| 45 | ## make ZINC=back,na zinc:default | ||
| 46 | ## make ZINC=back,ios zinc:default | ||
| 47 | |||
| 48 | ifneq ($(strip $(ZINC)),) | ||
| 49 | ifeq ($(findstring back,$(ZINC)), back) | ||
| 50 | LED_BACK_ENABLE = yes | ||
| 51 | else ifeq ($(findstring under,$(ZINC)), under) | ||
| 52 | LED_UNDERGLOW_ENABLE = yes | ||
| 53 | endif | ||
| 54 | ifeq ($(findstring na,$(ZINC)), na) | ||
| 55 | LED_ANIMATIONS = no | ||
| 56 | endif | ||
| 57 | ifeq ($(findstring ios,$(ZINC)), ios) | ||
| 58 | IOS_DEVICE_ENABLE = yes | ||
| 59 | endif | ||
| 60 | $(eval $(call ZINC_CUSTOMISE_MSG)) | ||
| 61 | $(info ) | ||
| 62 | endif | ||
| 63 | |||
| 64 | ifeq ($(strip $(LED_BACK_ENABLE)), yes) | ||
| 65 | RGBLIGHT_ENABLE = yes | ||
| 66 | OPT_DEFS += -DRGBLED_BACK | ||
| 67 | ifeq ($(strip $(LED_UNDERGLOW_ENABLE)), yes) | ||
| 68 | $(eval $(call ZINC_CUSTOMISE_MSG)) | ||
| 69 | $(error LED_BACK_ENABLE and LED_UNDERGLOW_ENABLE both 'yes') | ||
| 70 | endif | ||
| 71 | else ifeq ($(strip $(LED_UNDERGLOW_ENABLE)), yes) | ||
| 72 | RGBLIGHT_ENABLE = yes | ||
| 73 | else | ||
| 74 | RGBLIGHT_ENABLE = no | ||
| 75 | endif | ||
| 76 | |||
| 77 | ifeq ($(strip $(IOS_DEVICE_ENABLE)), yes) | ||
| 78 | OPT_DEFS += -DIOS_DEVICE_ENABLE | ||
| 79 | endif | ||
| 80 | |||
| 81 | ifeq ($(strip $(LED_ANIMATIONS)), yes) | ||
| 82 | # OPT_DEFS += -DRGBLIGHT_ANIMATIONS | ||
| 83 | OPT_DEFS += -DLED_ANIMATIONS | ||
| 84 | |||
| 85 | endif | ||
| 86 | |||
| 87 | ifeq ($(strip $(Link_Time_Optimization)),yes) | ||
| 88 | EXTRAFLAGS += -flto -DUSE_Link_Time_Optimization | ||
| 89 | endif | ||
| 90 | |||
| 91 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | ||
| 92 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | ||
| 93 | |||
| 94 | |||
| 95 | # Uncomment these for debugging | ||
| 96 | # $(info -- RGBLIGHT_ENABLE=$(RGBLIGHT_ENABLE)) | ||
| 97 | # $(info -- OPT_DEFS=$(OPT_DEFS)) | ||
| 98 | # $(info ) | ||
diff --git a/keyboards/zinc/keymaps/monks/config.h b/keyboards/zinc/keymaps/monks/config.h new file mode 100644 index 000000000..4dcb0724f --- /dev/null +++ b/keyboards/zinc/keymaps/monks/config.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | /* | ||
| 2 | This is the c configuration file for the keymap | ||
| 3 | |||
| 4 | Copyright 2018 monksoffunk | ||
| 5 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 6 | Copyright 2015 Jack Humbert | ||
| 7 | |||
| 8 | This program is free software: you can redistribute it and/or modify | ||
| 9 | it under the terms of the GNU General Public License as published by | ||
| 10 | the Free Software Foundation, either version 2 of the License, or | ||
| 11 | (at your option) any later version. | ||
| 12 | |||
| 13 | This program is distributed in the hope that it will be useful, | ||
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | GNU General Public License for more details. | ||
| 17 | |||
| 18 | You should have received a copy of the GNU General Public License | ||
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #pragma once | ||
| 23 | // if you need more program area, try uncomment follow line | ||
| 24 | #include "serial_config_simpleapi.h" | ||
| 25 | |||
| 26 | // place overrides here | ||
| 27 | // Selection of RGBLIGHT MODE to use. | ||
| 28 | #if defined(LED_ANIMATIONS) | ||
| 29 | #define RGBLIGHT_EFFECT_BREATHING | ||
| 30 | #define RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 31 | #define RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 32 | #define RGBLIGHT_EFFECT_SNAKE | ||
| 33 | #define RGBLIGHT_EFFECT_KNIGHT | ||
| 34 | #define RGBLIGHT_EFFECT_CHRISTMAS | ||
| 35 | #define RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
| 36 | //#define RGBLIGHT_EFFECT_RGB_TEST | ||
| 37 | //#define RGBLIGHT_EFFECT_ALTERNATING | ||
| 38 | #endif | ||
diff --git a/keyboards/zinc/keymaps/monks/keymap.c b/keyboards/zinc/keymaps/monks/keymap.c new file mode 100644 index 000000000..5fd7c6aa8 --- /dev/null +++ b/keyboards/zinc/keymaps/monks/keymap.c | |||
| @@ -0,0 +1,255 @@ | |||
| 1 | #include QMK_KEYBOARD_H | ||
| 2 | |||
| 3 | extern keymap_config_t keymap_config; | ||
| 4 | |||
| 5 | #ifdef RGBLIGHT_ENABLE | ||
| 6 | //Following line allows macro to read current RGB settings | ||
| 7 | extern rgblight_config_t rgblight_config; | ||
| 8 | rgblight_config_t RGB_current_config; | ||
| 9 | #endif | ||
| 10 | |||
| 11 | extern uint8_t is_master; | ||
| 12 | |||
| 13 | // Each layer gets a name for readability, which is then used in the keymap matrix below. | ||
| 14 | // The underscores don't mean anything - you can have a layer called STUFF or any other name. | ||
| 15 | // Layer names don't all need to be of the same length, obviously, and you can also skip them | ||
| 16 | // entirely and just use numbers. | ||
| 17 | enum layer_number { | ||
| 18 | _QWERTY = 0, | ||
| 19 | _LOWER, | ||
| 20 | _RAISE, | ||
| 21 | _ADJUST | ||
| 22 | }; | ||
| 23 | |||
| 24 | enum custom_keycodes { | ||
| 25 | QWERTY = SAFE_RANGE, | ||
| 26 | COLEMAK, | ||
| 27 | DVORAK, | ||
| 28 | LOWER, | ||
| 29 | RAISE, | ||
| 30 | ADJUST, | ||
| 31 | BACKLIT, | ||
| 32 | KANA, | ||
| 33 | EISU, | ||
| 34 | RGBRST | ||
| 35 | }; | ||
| 36 | |||
| 37 | enum macro_keycodes { | ||
| 38 | KC_SAMPLEMACRO, | ||
| 39 | }; | ||
| 40 | |||
| 41 | |||
| 42 | //Macros | ||
| 43 | #define M_SAMPLE M(KC_SAMPLEMACRO) | ||
| 44 | |||
| 45 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { \ | ||
| 46 | /* Qwerty | ||
| 47 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 48 | * | Tab | Q | W | E | R | T | | Y | U | I | O | P | Bksp | | ||
| 49 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 50 | * | Ctrl | A | S | D | F | G | | H | J | K | L | ; | ' | | ||
| 51 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 52 | * | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter | | ||
| 53 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 54 | * | Esc |ADJUST| Alt | GUI |LOWER |Space | | Space| RAISE| KANA | Left | Down | Right| | ||
| 55 | * `-----------------------------------------' `-----------------------------------------' | ||
| 56 | */ | ||
| 57 | [_QWERTY] = LAYOUT_ortho_4x12( | ||
| 58 | KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \ | ||
| 59 | KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \ | ||
| 60 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \ | ||
| 61 | KC_ESC, ADJUST, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KANA, KC_LEFT, KC_DOWN, KC_RGHT \ | ||
| 62 | ), | ||
| 63 | |||
| 64 | /* Lower | ||
| 65 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 66 | * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | | | ||
| 67 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 68 | * | | | | | | | | - | _ | + | { | } | | | | ||
| 69 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 70 | * | | | | | | | | | | | | UP | | | ||
| 71 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 72 | * | | | | | | | | | | | | | | | ||
| 73 | * `-----------------------------------------' `-----------------------------------------' | ||
| 74 | */ | ||
| 75 | [_LOWER] = LAYOUT_ortho_4x12( \ | ||
| 76 | KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______, \ | ||
| 77 | _______, _______, _______, _______, _______, _______, KC_MINS, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \ | ||
| 78 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_UP, _______, \ | ||
| 79 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \ | ||
| 80 | ), | ||
| 81 | |||
| 82 | /* Raise | ||
| 83 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 84 | * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Del | | ||
| 85 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 86 | * | | F1 | F2 | F3 | F4 | F5 | | F6 | - | = | [ | ] | \ | | ||
| 87 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 88 | * | | F7 | F8 | F9 | F10 | F11 | | F12 | | | | ? | | | ||
| 89 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 90 | * | | | | | | | | | | Next | Vol- | Vol+ | Play | | ||
| 91 | * `-----------------------------------------' `-----------------------------------------' | ||
| 92 | */ | ||
| 93 | [_RAISE] = LAYOUT_ortho_4x12( \ | ||
| 94 | KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \ | ||
| 95 | _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \ | ||
| 96 | _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, S(KC_SLSH), _______, \ | ||
| 97 | _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \ | ||
| 98 | ), | ||
| 99 | |||
| 100 | /* Adjust (Lower + Raise) | ||
| 101 | * ,-----------------------------------------. ,-----------------------------------------. | ||
| 102 | * | | Reset|RGBRST| | | | | | | | | | Ins | | ||
| 103 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 104 | * | |RGB ON| HUE+ | SAT+ | VAL+ | Mac | | Win | - | = |Print |ScLock|Pause | | ||
| 105 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 106 | * | | MODE | HUE- | SAT- | VAL- | | | | | | |PageUp| | | ||
| 107 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 108 | * | | | | EISU | EISU | EISU | | KANA | KANA | KANA | Home |PageDn| End | | ||
| 109 | * `-----------------------------------------' `-----------------------------------------' | ||
| 110 | */ | ||
| 111 | [_ADJUST] = LAYOUT_ortho_4x12( \ | ||
| 112 | _______, RESET, RGBRST, _______, _______, _______, _______, _______, _______, _______, _______, KC_INS, \ | ||
| 113 | _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, AG_NORM, AG_SWAP, KC_MINS, KC_EQL, KC_PSCR, KC_SLCK, KC_PAUS,\ | ||
| 114 | _______, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, _______, _______, _______, _______, _______, KC_PGUP, _______,\ | ||
| 115 | _______, _______, _______, EISU, EISU, EISU, KANA, KANA, KANA, KC_HOME, KC_PGDN, KC_END\ | ||
| 116 | ) | ||
| 117 | }; | ||
| 118 | |||
| 119 | // define variables for reactive RGB | ||
| 120 | bool TOG_STATUS = false; | ||
| 121 | |||
| 122 | // Setting ADJUST layer RGB back to default | ||
| 123 | void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) { | ||
| 124 | if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { | ||
| 125 | #ifdef RGBLIGHT_ENABLE | ||
| 126 | rgblight_mode_noeeprom(RGB_current_config.mode); | ||
| 127 | #endif | ||
| 128 | layer_on(layer3); | ||
| 129 | } else { | ||
| 130 | layer_off(layer3); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 135 | switch (keycode) { | ||
| 136 | case QWERTY: | ||
| 137 | if (record->event.pressed) { | ||
| 138 | set_single_persistent_default_layer(_QWERTY); | ||
| 139 | } | ||
| 140 | return false; | ||
| 141 | break; | ||
| 142 | |||
| 143 | case LOWER: | ||
| 144 | if (record->event.pressed) { | ||
| 145 | //not sure how to have keyboard check mode and set it to a variable, so my work around | ||
| 146 | //uses another variable that would be set to true after the first time a reactive key is pressed. | ||
| 147 | if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false | ||
| 148 | } else { | ||
| 149 | TOG_STATUS = !TOG_STATUS; | ||
| 150 | #ifdef RGBLIGHT_ENABLE | ||
| 151 | rgblight_mode_noeeprom(16); | ||
| 152 | #endif | ||
| 153 | } | ||
| 154 | layer_on(_LOWER); | ||
| 155 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); | ||
| 156 | } else { | ||
| 157 | #ifdef RGBLIGHT_ENABLE | ||
| 158 | rgblight_mode_noeeprom(RGB_current_config.mode); // revert RGB to initial mode prior to RGB mode change | ||
| 159 | #endif | ||
| 160 | TOG_STATUS = false; | ||
| 161 | layer_off(_LOWER); | ||
| 162 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); | ||
| 163 | } | ||
| 164 | return false; | ||
| 165 | break; | ||
| 166 | |||
| 167 | case RAISE: | ||
| 168 | if (record->event.pressed) { | ||
| 169 | //not sure how to have keyboard check mode and set it to a variable, so my work around | ||
| 170 | //uses another variable that would be set to true after the first time a reactive key is pressed. | ||
| 171 | if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false | ||
| 172 | } else { | ||
| 173 | TOG_STATUS = !TOG_STATUS; | ||
| 174 | #ifdef RGBLIGHT_ENABLE | ||
| 175 | rgblight_mode_noeeprom(15); | ||
| 176 | #endif | ||
| 177 | } | ||
| 178 | layer_on(_RAISE); | ||
| 179 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); | ||
| 180 | } else { | ||
| 181 | #ifdef RGBLIGHT_ENABLE | ||
| 182 | rgblight_mode_noeeprom(RGB_current_config.mode); // revert RGB to initial mode prior to RGB mode change | ||
| 183 | #endif | ||
| 184 | layer_off(_RAISE); | ||
| 185 | TOG_STATUS = false; | ||
| 186 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); | ||
| 187 | } | ||
| 188 | return false; | ||
| 189 | break; | ||
| 190 | |||
| 191 | case ADJUST: | ||
| 192 | if (record->event.pressed) { | ||
| 193 | layer_on(_ADJUST); | ||
| 194 | } else { | ||
| 195 | layer_off(_ADJUST); | ||
| 196 | } | ||
| 197 | return false; | ||
| 198 | break; | ||
| 199 | //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released | ||
| 200 | case RGB_MOD: | ||
| 201 | #ifdef RGBLIGHT_ENABLE | ||
| 202 | if (record->event.pressed) { | ||
| 203 | rgblight_mode_noeeprom(RGB_current_config.mode); | ||
| 204 | rgblight_step(); | ||
| 205 | RGB_current_config.mode = rgblight_config.mode; | ||
| 206 | } | ||
| 207 | #endif | ||
| 208 | return false; | ||
| 209 | break; | ||
| 210 | |||
| 211 | case EISU: | ||
| 212 | if (record->event.pressed) { | ||
| 213 | if(keymap_config.swap_lalt_lgui==false){ | ||
| 214 | register_code(KC_LANG2); | ||
| 215 | }else{ | ||
| 216 | SEND_STRING(SS_LALT("`")); | ||
| 217 | } | ||
| 218 | } else { | ||
| 219 | unregister_code(KC_LANG2); | ||
| 220 | } | ||
| 221 | return false; | ||
| 222 | break; | ||
| 223 | case KANA: | ||
| 224 | if (record->event.pressed) { | ||
| 225 | if(keymap_config.swap_lalt_lgui==false){ | ||
| 226 | register_code(KC_LANG1); | ||
| 227 | }else{ | ||
| 228 | SEND_STRING(SS_LALT("`")); | ||
| 229 | } | ||
| 230 | } else { | ||
| 231 | unregister_code(KC_LANG1); | ||
| 232 | } | ||
| 233 | return false; | ||
| 234 | break; | ||
| 235 | |||
| 236 | case RGBRST: | ||
| 237 | #ifdef RGBLIGHT_ENABLE | ||
| 238 | if (record->event.pressed) { | ||
| 239 | eeconfig_update_rgblight_default(); | ||
| 240 | rgblight_enable(); | ||
| 241 | RGB_current_config = rgblight_config; | ||
| 242 | } | ||
| 243 | #endif | ||
| 244 | break; | ||
| 245 | } | ||
| 246 | return true; | ||
| 247 | } | ||
| 248 | |||
| 249 | |||
| 250 | void matrix_init_user(void) { | ||
| 251 | #ifdef RGBLIGHT_ENABLE | ||
| 252 | rgblight_init(); | ||
| 253 | RGB_current_config = rgblight_config; | ||
| 254 | #endif | ||
| 255 | } | ||
diff --git a/keyboards/zinc/keymaps/monks/readme_jp.md b/keyboards/zinc/keymaps/monks/readme_jp.md new file mode 100644 index 000000000..680e2866c --- /dev/null +++ b/keyboards/zinc/keymaps/monks/readme_jp.md | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | # monksoffunk's personal zinc Layout | ||
| 2 | ## 配列 | ||
| 3 | |||
| 4 | ### Qwerty配列 | ||
| 5 | |||
| 6 | ``` | ||
| 7 | ,-----------------------------------------. ,-----------------------------------------. | ||
| 8 | | Tab | Q | W | E | R | T | | Y | U | I | O | P | Bksp | | ||
| 9 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 10 | | Ctrl | A | S | D | F | G | | H | J | K | L | ; | ' | | ||
| 11 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 12 | | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter | | ||
| 13 | |------+------+------+------+------+------| |------+------+------+------+------+------| | ||
| 14 | | Esc |ADJUST| Alt | GUI |LOWER |Space | | Space| RAISE| KANA | Left | Down | Right| | ||
| 15 | `------------------------------------------ ------------------------------------------' | ||
| 16 | ``` | ||
| 17 | |||
| 18 | KANAキーを独立させ、UPキーをLOWER+スラッシュに当てています。そのほかデフォルトからレイヤーをかなりいじっています。 | ||
| 19 | また、RGB LEDがアンコメントしてありますので、実装していない場合はソースを見て適宜コメントアウトしてください。 | ||
| 20 | |||
| 21 | ## コンパイルの仕方 | ||
| 22 | |||
| 23 | コンパイルは、qmk_firmware のトップディレクトリで行います。 | ||
| 24 | |||
| 25 | ``` | ||
| 26 | $ cd qmk_firmware | ||
| 27 | ``` | ||
| 28 | qmk_firmwareでは各キーボードのコンパイルは、`<キーボード名>:<キーマップ名>`という指定で行います。 | ||
| 29 | |||
| 30 | ``` | ||
| 31 | $ make zinc:monks | ||
| 32 | ``` | ||
| 33 | |||
| 34 | キーボードへの書き込みまで同時に行うには下記のように`:avrdude`を付けます。 | ||
| 35 | |||
| 36 | ``` | ||
| 37 | $ make zinc:monks:avrdude | ||
| 38 | ``` | ||
| 39 | |||
| 40 | コンパイル結果と中間生成物を消去したい場合は以下のようにします。 | ||
| 41 | |||
| 42 | ``` | ||
| 43 | $ make zinc:monks:clean | ||
| 44 | ``` | ||
| 45 | |||
| 46 | なお、avrdudeではなくQMK Toolbox(GUIツール)を使う方法もあります。 | ||
| 47 | |||
| 48 | https://github.com/qmk/qmk_toolbox/releases | ||
| 49 | |||
| 50 | その場合は、$ make zinc:monksでビルドした成果物をQMK Toolboxから指定してください。 | ||
| 51 | |||
| 52 | ## カスタマイズ | ||
| 53 | |||
| 54 | コマンドラインからオプションを指定してビルドすることが出来ます。 | ||
| 55 | |||
| 56 | ``` | ||
| 57 | # Zinc keyboard 'monks' keymap: convenient command line option | ||
| 58 | make ZINC=<options> zinc:monks | ||
| 59 | # option= back | under | na | ios | ||
| 60 | # ex. | ||
| 61 | # make ZINC=under zinc:monks | ||
| 62 | # make ZINC=under,ios zinc:monks | ||
| 63 | # make ZINC=back zinc:monks | ||
| 64 | # make ZINC=back,na zinc:monks | ||
| 65 | # make ZINC=back,ios zinc:monks | ||
| 66 | ``` | ||
| 67 | |||
| 68 | あるいは`qmk_firmware/keyboards/zinc/rev1/keymaps/monks/rules.mk` の以下の部分を編集して機能を有効化してください。 | ||
| 69 | |||
| 70 | ``` | ||
| 71 | # Zinc keyboard customize | ||
| 72 | LED_BACK_ENABLE = no # LED backlight (Enable SK6812mini backlight) | ||
| 73 | LED_UNDERGLOW_ENABLE = no # LED underglow (Enable WS2812 RGB underlight) | ||
| 74 | LED_ANIMATIONS = yes # LED animations | ||
| 75 | IOS_DEVICE_ENABLE = no # connect to IOS device (iPad,iPhone) | ||
| 76 | |||
| 77 | |||
| 78 | ``` | ||
| 79 | |||
| 80 | ## RGB backlight を有効にする | ||
| 81 | |||
| 82 | rules.mk の下記の部分を編集して no を yes に変更してください。 | ||
| 83 | ``` | ||
| 84 | LED_BACK_ENABLE = yes # LED backlight (Enable SK6812mini backlight) | ||
| 85 | ``` | ||
| 86 | |||
| 87 | |||
| 88 | ## RGB Underglow を有効にする | ||
| 89 | |||
| 90 | rules.mk の下記の部分を編集して no を yes に変更してください。 | ||
| 91 | ``` | ||
| 92 | LED_UNDERGLOW_ENABLE = yes # LED underglow (Enable WS2812 RGB underlight) | ||
| 93 | ``` | ||
| 94 | |||
| 95 | |||
| 96 | ## iPad/iPhoneサポートを有効にする。 | ||
| 97 | |||
| 98 | rules.mk の下記の部分を編集して no を yes に変更してください。 | ||
| 99 | RBG Underglow や RGBバックライトの輝度を抑えて、iPad, iPhone にも接続できるようになります。 | ||
| 100 | |||
| 101 | ``` | ||
| 102 | IOS_DEVICE_ENABLE = no # connect to IOS device (iPad,iPhone) | ||
| 103 | ``` \ No newline at end of file | ||
diff --git a/keyboards/zinc/keymaps/monks/rules.mk b/keyboards/zinc/keymaps/monks/rules.mk new file mode 100644 index 000000000..a5335def8 --- /dev/null +++ b/keyboards/zinc/keymaps/monks/rules.mk | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | |||
| 2 | # Build Options | ||
| 3 | # change to "no" to disable the options, or define them in the Makefile in | ||
| 4 | # the appropriate keymap folder that will get included automatically | ||
| 5 | # | ||
| 6 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | ||
| 7 | MOUSEKEY_ENABLE = no # Mouse keys(+4700) | ||
| 8 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | ||
| 9 | CONSOLE_ENABLE = no # Console for debug(+400) | ||
| 10 | COMMAND_ENABLE = no # Commands for debug and configuration | ||
| 11 | NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | ||
| 12 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | ||
| 13 | MIDI_ENABLE = no # MIDI controls | ||
| 14 | AUDIO_ENABLE = no # Audio output on port C6 | ||
| 15 | UNICODE_ENABLE = no # Unicode | ||
| 16 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | ||
| 17 | RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. | ||
| 18 | SWAP_HANDS_ENABLE = no # Enable one-hand typing | ||
| 19 | |||
| 20 | define ZINC_CUSTOMISE_MSG | ||
| 21 | $(info Zinc customize) | ||
| 22 | $(info - LED_BACK_ENABLE=$(LED_BACK_ENABLE)) | ||
| 23 | $(info - LED_UNDERGLOW_ENABLE=$(LED_UNDERGLOW_ENABLE)) | ||
| 24 | $(info - LED_ANIMATION=$(LED_ANIMATIONS)) | ||
| 25 | $(info - IOS_DEVICE_ENABLE=$(IOS_DEVICE_ENABLE)) | ||
| 26 | endef | ||
| 27 | |||
| 28 | # Zinc keyboard customize | ||
| 29 | LED_BACK_ENABLE = no # LED backlight (Enable SK6812mini backlight) | ||
| 30 | LED_UNDERGLOW_ENABLE = no # LED underglow (Enable WS2812 RGB underlight) | ||
| 31 | LED_ANIMATIONS = yes # LED animations | ||
| 32 | IOS_DEVICE_ENABLE = no # connect to IOS device (iPad,iPhone) | ||
| 33 | Link_Time_Optimization = no # if firmware size over limit, try this option | ||
| 34 | |||
| 35 | #### LED_BACK_ENABLE and LED_UNDERGLOW_ENABLE. | ||
| 36 | #### Do not enable these with audio at the same time. | ||
| 37 | |||
| 38 | ### Zinc keyboard 'default' keymap: convenient command line option | ||
| 39 | ## make ZINC=<options> zinc:defualt | ||
| 40 | ## option= back | under | na | ios | ||
| 41 | ## ex. | ||
| 42 | ## make ZINC=under zinc:defualt | ||
| 43 | ## make ZINC=under,ios zinc:defualt | ||
| 44 | ## make ZINC=back zinc:default | ||
| 45 | ## make ZINC=back,na zinc:default | ||
| 46 | ## make ZINC=back,ios zinc:default | ||
| 47 | |||
| 48 | ifneq ($(strip $(ZINC)),) | ||
| 49 | ifeq ($(findstring back,$(ZINC)), back) | ||
| 50 | LED_BACK_ENABLE = yes | ||
| 51 | else ifeq ($(findstring under,$(ZINC)), under) | ||
| 52 | LED_UNDERGLOW_ENABLE = yes | ||
| 53 | endif | ||
| 54 | ifeq ($(findstring na,$(ZINC)), na) | ||
| 55 | LED_ANIMATIONS = no | ||
| 56 | endif | ||
| 57 | ifeq ($(findstring ios,$(ZINC)), ios) | ||
| 58 | IOS_DEVICE_ENABLE = yes | ||
| 59 | endif | ||
| 60 | $(eval $(call ZINC_CUSTOMISE_MSG)) | ||
| 61 | $(info ) | ||
| 62 | endif | ||
| 63 | |||
| 64 | ifeq ($(strip $(LED_BACK_ENABLE)), yes) | ||
| 65 | RGBLIGHT_ENABLE = yes | ||
| 66 | OPT_DEFS += -DRGBLED_BACK | ||
| 67 | ifeq ($(strip $(LED_UNDERGLOW_ENABLE)), yes) | ||
| 68 | $(eval $(call ZINC_CUSTOMISE_MSG)) | ||
| 69 | $(error LED_BACK_ENABLE and LED_UNDERGLOW_ENABLE both 'yes') | ||
| 70 | endif | ||
| 71 | else ifeq ($(strip $(LED_UNDERGLOW_ENABLE)), yes) | ||
| 72 | RGBLIGHT_ENABLE = yes | ||
| 73 | else | ||
| 74 | RGBLIGHT_ENABLE = no | ||
| 75 | endif | ||
| 76 | |||
| 77 | ifeq ($(strip $(IOS_DEVICE_ENABLE)), yes) | ||
| 78 | OPT_DEFS += -DIOS_DEVICE_ENABLE | ||
| 79 | endif | ||
| 80 | |||
| 81 | ifeq ($(strip $(LED_ANIMATIONS)), yes) | ||
| 82 | # OPT_DEFS += -DRGBLIGHT_ANIMATIONS | ||
| 83 | OPT_DEFS += -DLED_ANIMATIONS | ||
| 84 | endif | ||
| 85 | |||
| 86 | ifeq ($(strip $(Link_Time_Optimization)),yes) | ||
| 87 | EXTRAFLAGS += -flto -DUSE_Link_Time_Optimization | ||
| 88 | endif | ||
| 89 | |||
| 90 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | ||
| 91 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | ||
| 92 | |||
| 93 | ifndef QUANTUM_DIR | ||
| 94 | include ../../../../Makefile | ||
| 95 | endif | ||
| 96 | |||
| 97 | # Uncomment these for debugging | ||
| 98 | # $(info -- RGBLIGHT_ENABLE=$(RGBLIGHT_ENABLE)) | ||
| 99 | # $(info -- OPT_DEFS=$(OPT_DEFS)) | ||
| 100 | # $(info ) | ||
diff --git a/keyboards/zinc/readme.md b/keyboards/zinc/readme.md new file mode 100644 index 000000000..3b4ce105c --- /dev/null +++ b/keyboards/zinc/readme.md | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | Zinc | ||
| 2 | === | ||
| 3 | |||
| 4 |  | ||
| 5 | |||
| 6 | 40% row-staggered split keyboard. | ||
| 7 | |||
| 8 | Keyboard Maintainer: [monksoffunk](https://github.com/monksoffunk/) [@monksoffunkJP](https://twitter.com/monksoffunkJP) | ||
| 9 | Hardware Supported: Zinc PCB | ||
| 10 | Hardware Availability: (https://twitter.com/monksoffunkJP) | ||
| 11 | |||
| 12 | Make example for this keyboard (after setting up your build environment): | ||
| 13 | |||
| 14 | make zinc:default | ||
| 15 | |||
| 16 | |||
| 17 | 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). | ||
diff --git a/keyboards/zinc/rev1/config.h b/keyboards/zinc/rev1/config.h new file mode 100644 index 000000000..c628400f2 --- /dev/null +++ b/keyboards/zinc/rev1/config.h | |||
| @@ -0,0 +1,149 @@ | |||
| 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 | //#ifndef REV1_CONFIG_H | ||
| 22 | //#define REV1_CONFIG_H | ||
| 23 | |||
| 24 | /* USB Device descriptor parameter */ | ||
| 25 | #define VENDOR_ID 0xFEED | ||
| 26 | #define PRODUCT_ID 0x9991 | ||
| 27 | #define DEVICE_VER 0x0001 | ||
| 28 | #define MANUFACTURER monksoffunk | ||
| 29 | #define PRODUCT zinc rev.1 | ||
| 30 | #define DESCRIPTION A split keyboard | ||
| 31 | |||
| 32 | |||
| 33 | #define PREVENT_STUCK_MODIFIERS | ||
| 34 | #define TAPPING_FORCE_HOLD | ||
| 35 | #define TAPPING_TERM 100 | ||
| 36 | |||
| 37 | /* Use I2C or Serial */ | ||
| 38 | //#define USE_I2C | ||
| 39 | #define USE_SERIAL | ||
| 40 | //#define USE_MATRIX_I2C | ||
| 41 | |||
| 42 | /* Select hand configuration */ | ||
| 43 | #define MASTER_LEFT | ||
| 44 | //#define MASTER_RIGHT | ||
| 45 | //#define EE_HANDS | ||
| 46 | |||
| 47 | |||
| 48 | /* key matrix size */ | ||
| 49 | // Rows are doubled-up | ||
| 50 | #define MATRIX_ROWS 8 | ||
| 51 | #define MATRIX_ROW_PINS { F6, F7, B1, B3 } | ||
| 52 | |||
| 53 | // wiring of each half | ||
| 54 | #define MATRIX_COLS 6 | ||
| 55 | #define MATRIX_COL_PINS { F4, D4, C6, D7, E6, B4 } | ||
| 56 | |||
| 57 | /* define if matrix has ghost */ | ||
| 58 | //#define MATRIX_HAS_GHOST | ||
| 59 | |||
| 60 | /* number of backlight levels */ | ||
| 61 | // #define BACKLIGHT_LEVELS 3 | ||
| 62 | |||
| 63 | /* Set 0 if debouncing isn't needed */ | ||
| 64 | #define DEBOUNCING_DELAY 5 | ||
| 65 | |||
| 66 | /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ | ||
| 67 | //#define LOCKING_SUPPORT_ENABLE | ||
| 68 | /* Locking resynchronize hack */ | ||
| 69 | //#define LOCKING_RESYNC_ENABLE | ||
| 70 | |||
| 71 | /* key combination for command */ | ||
| 72 | #define IS_COMMAND() ( \ | ||
| 73 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ | ||
| 74 | ) | ||
| 75 | |||
| 76 | /* ws2812 RGB LED */ | ||
| 77 | #define RGB_DI_PIN D3 | ||
| 78 | #define RGBLIGHT_TIMER | ||
| 79 | //#define RGBLED_NUM 12 // Number of LEDs. see ./keymaps/default/config.h | ||
| 80 | #define ws2812_PORTREG PORTD | ||
| 81 | #define ws2812_DDRREG DDRD | ||
| 82 | |||
| 83 | // RGB LED support | ||
| 84 | //#define RGBLIGHT_ANIMATIONS : see ./rules.mk: LED_ANIMATIONS = yes or no | ||
| 85 | // see ./rules.mk: LED_BACK_ENABLE or LED_UNDERGLOW_ENABLE set yes | ||
| 86 | #ifdef RGBLED_BACK | ||
| 87 | #define RGBLED_NUM 24 | ||
| 88 | #else | ||
| 89 | #define RGBLED_NUM 6 | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #ifndef IOS_DEVICE_ENABLE | ||
| 93 | #if RGBLED_NUM <= 6 | ||
| 94 | #define RGBLIGHT_LIMIT_VAL 255 | ||
| 95 | #else | ||
| 96 | #if RGBLED_NUM <= 16 | ||
| 97 | #define RGBLIGHT_LIMIT_VAL 130 | ||
| 98 | #else | ||
| 99 | #define RGBLIGHT_LIMIT_VAL 120 | ||
| 100 | #endif | ||
| 101 | #endif | ||
| 102 | #define RGBLIGHT_VAL_STEP 17 | ||
| 103 | #else | ||
| 104 | #if RGBLED_NUM <= 6 | ||
| 105 | #define RGBLIGHT_LIMIT_VAL 90 | ||
| 106 | #else | ||
| 107 | #if RGBLED_NUM <= 16 | ||
| 108 | #define RGBLIGHT_LIMIT_VAL 45 | ||
| 109 | #else | ||
| 110 | #define RGBLIGHT_LIMIT_VAL 35 | ||
| 111 | #endif | ||
| 112 | #endif | ||
| 113 | #define RGBLIGHT_VAL_STEP 4 | ||
| 114 | #endif | ||
| 115 | #define RGBLIGHT_HUE_STEP 10 | ||
| 116 | #define RGBLIGHT_SAT_STEP 17 | ||
| 117 | |||
| 118 | #if defined(RGBLIGHT_ENABLE) && !defined(IOS_DEVICE_ENABLE) | ||
| 119 | // USB_MAX_POWER_CONSUMPTION value | ||
| 120 | // 120 RGBoff | ||
| 121 | // 330 RGB 6 | ||
| 122 | // 300 RGB 32 | ||
| 123 | #define USB_MAX_POWER_CONSUMPTION 400 | ||
| 124 | #else | ||
| 125 | // fix iPhone and iPad power adapter issue | ||
| 126 | // iOS device need lessthan 100 | ||
| 127 | #define USB_MAX_POWER_CONSUMPTION 100 | ||
| 128 | #endif | ||
| 129 | |||
| 130 | /* | ||
| 131 | * Feature disable options | ||
| 132 | * These options are also useful to firmware size reduction. | ||
| 133 | */ | ||
| 134 | |||
| 135 | /* disable debug print */ | ||
| 136 | // #define NO_DEBUG | ||
| 137 | |||
| 138 | /* disable print */ | ||
| 139 | // #define NO_PRINT | ||
| 140 | |||
| 141 | /* disable action features */ | ||
| 142 | //#define NO_ACTION_LAYER | ||
| 143 | //#define NO_ACTION_TAPPING | ||
| 144 | //#define NO_ACTION_ONESHOT | ||
| 145 | //#define NO_ACTION_MACRO | ||
| 146 | //#define NO_ACTION_FUNCTION | ||
| 147 | |||
| 148 | |||
| 149 | //#endif | ||
diff --git a/keyboards/zinc/rev1/info.json b/keyboards/zinc/rev1/info.json new file mode 100644 index 000000000..0ca8acded --- /dev/null +++ b/keyboards/zinc/rev1/info.json | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | { | ||
| 2 | "keyboard_name": "Zinc rev.1", | ||
| 3 | "url": "https://github.com/monksoffunk/zinc", | ||
| 4 | "maintainer": "monksoffunk", | ||
| 5 | "width": 15, | ||
| 6 | "height": 4, | ||
| 7 | "layouts": { | ||
| 8 | "LAYOUT": { | ||
| 9 | "key_count": 48, | ||
| 10 | "layout": [{"x":0, "y":0}, {"x":1, "y":0}, {"x":2, "y":0}, {"x":3, "y":0}, {"x":4, "y":0}, {"x":5, "y":0}, {"x":9, "y":0}, {"x":10, "y":0}, {"x":11, "y":0}, {"x":12, "y":0}, {"x":13, "y":0}, {"x":14, "y":0}, {"x":0, "y":1}, {"x":1, "y":1}, {"x":2, "y":1}, {"x":3, "y":1}, {"x":4, "y":1}, {"x":5, "y":1}, {"x":9, "y":1}, {"x":10, "y":1}, {"x":11, "y":1}, {"x":12, "y":1}, {"x":13, "y":1}, {"x":14, "y":1}, {"x":0, "y":2}, {"x":1, "y":2}, {"x":2, "y":2}, {"x":3, "y":2}, {"x":4, "y":2}, {"x":5, "y":2}, {"x":9, "y":2}, {"x":10, "y":2}, {"x":11, "y":2}, {"x":12, "y":2}, {"x":13, "y":2}, {"x":14, "y":2}, {"x":0, "y":3}, {"x":1, "y":3}, {"x":2, "y":3}, {"x":3, "y":3}, {"x":4, "y":3}, {"x":5, "y":3}, {"x":9, "y":3}, {"x":10, "y":3}, {"x":11, "y":3}, {"x":12, "y":3}, {"x":13, "y":3}, {"x":14, "y":3}] | ||
| 11 | } | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/keyboards/zinc/rev1/matrix.c b/keyboards/zinc/rev1/matrix.c new file mode 100644 index 000000000..220954f05 --- /dev/null +++ b/keyboards/zinc/rev1/matrix.c | |||
| @@ -0,0 +1,356 @@ | |||
| 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 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 222 | |||
| 223 | #ifdef USE_MATRIX_I2C | ||
| 224 | // for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 225 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 226 | // i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 227 | // } | ||
| 228 | #else // USE_SERIAL | ||
| 229 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 230 | mchanged = memcmp((void *)serial_master_buffer, | ||
| 231 | &matrix[offset], sizeof(serial_master_buffer)); | ||
| 232 | #endif | ||
| 233 | memcpy((void *)serial_master_buffer, | ||
| 234 | &matrix[offset], sizeof(serial_master_buffer)); | ||
| 235 | #endif | ||
| 236 | |||
| 237 | #ifdef USE_MATRIX_I2C | ||
| 238 | if( i2c_transaction() ) { | ||
| 239 | #else // USE_SERIAL | ||
| 240 | if( serial_transaction(mchanged) ) { | ||
| 241 | #endif | ||
| 242 | // turn on the indicator led when halves are disconnected | ||
| 243 | TXLED1; | ||
| 244 | |||
| 245 | error_count++; | ||
| 246 | |||
| 247 | if (error_count > ERROR_DISCONNECT_COUNT) { | ||
| 248 | // reset other half if disconnected | ||
| 249 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 250 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 251 | matrix[slaveOffset+i] = 0; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | } else { | ||
| 255 | // turn off the indicator led on no error | ||
| 256 | TXLED0; | ||
| 257 | error_count = 0; | ||
| 258 | } | ||
| 259 | matrix_scan_quantum(); | ||
| 260 | return ret; | ||
| 261 | } | ||
| 262 | |||
| 263 | void matrix_slave_scan(void) { | ||
| 264 | _matrix_scan(); | ||
| 265 | |||
| 266 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 267 | |||
| 268 | #ifdef USE_MATRIX_I2C | ||
| 269 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 270 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 271 | i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 272 | } | ||
| 273 | #else // USE_SERIAL | ||
| 274 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 275 | int change = 0; | ||
| 276 | #endif | ||
| 277 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 278 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 279 | if( serial_slave_buffer[i] != matrix[offset+i] ) | ||
| 280 | change = 1; | ||
| 281 | #endif | ||
| 282 | serial_slave_buffer[i] = matrix[offset+i]; | ||
| 283 | } | ||
| 284 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 285 | slave_buffer_change_count += change; | ||
| 286 | #endif | ||
| 287 | #endif | ||
| 288 | } | ||
| 289 | |||
| 290 | bool matrix_is_modified(void) | ||
| 291 | { | ||
| 292 | if (debouncing) return false; | ||
| 293 | return true; | ||
| 294 | } | ||
| 295 | |||
| 296 | inline | ||
| 297 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 298 | { | ||
| 299 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 300 | } | ||
| 301 | |||
| 302 | inline | ||
| 303 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 304 | { | ||
| 305 | return matrix[row]; | ||
| 306 | } | ||
| 307 | |||
| 308 | void matrix_print(void) | ||
| 309 | { | ||
| 310 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 311 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 312 | phex(row); print(": "); | ||
| 313 | pbin_reverse16(matrix_get_row(row)); | ||
| 314 | print("\n"); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | uint8_t matrix_key_count(void) | ||
| 319 | { | ||
| 320 | uint8_t count = 0; | ||
| 321 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 322 | count += bitpop16(matrix[i]); | ||
| 323 | } | ||
| 324 | return count; | ||
| 325 | } | ||
| 326 | |||
| 327 | static void init_cols(void) | ||
| 328 | { | ||
| 329 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 330 | _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF); | ||
| 331 | _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF); | ||
| 332 | } | ||
| 333 | } | ||
| 334 | |||
| 335 | static matrix_row_t read_cols(void) | ||
| 336 | { | ||
| 337 | matrix_row_t result = 0; | ||
| 338 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 339 | result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x); | ||
| 340 | } | ||
| 341 | return result; | ||
| 342 | } | ||
| 343 | |||
| 344 | static void unselect_rows(void) | ||
| 345 | { | ||
| 346 | for(int x = 0; x < ROWS_PER_HAND; x++) { | ||
| 347 | _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF); | ||
| 348 | _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF); | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | static void select_row(uint8_t row) | ||
| 353 | { | ||
| 354 | _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF); | ||
| 355 | _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF); | ||
| 356 | } | ||
diff --git a/keyboards/zinc/rev1/rev1.c b/keyboards/zinc/rev1/rev1.c new file mode 100644 index 000000000..2ce08a07c --- /dev/null +++ b/keyboards/zinc/rev1/rev1.c | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #include "zinc.h" | ||
| 2 | |||
| 3 | void matrix_init_kb(void) { | ||
| 4 | matrix_init_user(); | ||
| 5 | }; | ||
| 6 | |||
diff --git a/keyboards/zinc/rev1/rev1.h b/keyboards/zinc/rev1/rev1.h new file mode 100644 index 000000000..933e635c2 --- /dev/null +++ b/keyboards/zinc/rev1/rev1.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../zinc.h" | ||
| 4 | |||
| 5 | //void promicro_bootloader_jmp(bool program); | ||
| 6 | #include "quantum.h" | ||
| 7 | |||
| 8 | #ifdef RGBLIGHT_ENABLE | ||
| 9 | //rgb led driver | ||
| 10 | #include "ws2812.h" | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #ifdef USE_I2C | ||
| 14 | #include <stddef.h> | ||
| 15 | #ifdef __AVR__ | ||
| 16 | #include <avr/io.h> | ||
| 17 | #include <avr/interrupt.h> | ||
| 18 | #endif | ||
| 19 | #endif | ||
| 20 | |||
| 21 | //void promicro_bootloader_jmp(bool program); | ||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | // Standard Keymap | ||
| 26 | // (TRRS jack on both halves are to the left side) | ||
| 27 | #define LAYOUT( \ | ||
| 28 | L00, L01, L02, L03, L04, L05, R00, R01, R02, R03, R04, R05, \ | ||
| 29 | L10, L11, L12, L13, L14, L15, R10, R11, R12, R13, R14, R15, \ | ||
| 30 | L20, L21, L22, L23, L24, L25, R20, R21, R22, R23, R24, R25, \ | ||
| 31 | L30, L31, L32, L33, L34, L35, R30, R31, R32, R33, R34, R35 \ | ||
| 32 | ) \ | ||
| 33 | { \ | ||
| 34 | { L00, L01, L02, L03, L04, L05}, \ | ||
| 35 | { L10, L11, L12, L13, L14, L15}, \ | ||
| 36 | { L20, L21, L22, L23, L24, L25}, \ | ||
| 37 | { L30, L31, L32, L33, L34, L35}, \ | ||
| 38 | { R00, R01, R02, R03, R04, R05 }, \ | ||
| 39 | { R10, R11, R12, R13, R14, R15 }, \ | ||
| 40 | { R20, R21, R22, R23, R24, R25 }, \ | ||
| 41 | { R30, R31, R32, R33, R34, R35 }, \ | ||
| 42 | } | ||
| 43 | |||
| 44 | #define LAYOUT_ortho_4x12 LAYOUT | ||
diff --git a/keyboards/zinc/rev1/rules.mk b/keyboards/zinc/rev1/rules.mk new file mode 100644 index 000000000..e78b9258d --- /dev/null +++ b/keyboards/zinc/rev1/rules.mk | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | SRC += rev1/matrix.c | ||
| 2 | SRC += rev1/split_util.c | ||
| 3 | SRC += rev1/split_scomm.c | ||
| 4 | SRC += ws2812.c | ||
diff --git a/keyboards/zinc/rev1/serial_config.h b/keyboards/zinc/rev1/serial_config.h new file mode 100644 index 000000000..9fb5dfc67 --- /dev/null +++ b/keyboards/zinc/rev1/serial_config.h | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #ifndef SOFT_SERIAL_CONFIG_H | ||
| 2 | #define SOFT_SERIAL_CONFIG_H | ||
| 3 | |||
| 4 | #ifndef SOFT_SERIAL_PIN | ||
| 5 | /* Soft Serial defines */ | ||
| 6 | #define SOFT_SERIAL_PIN D2 | ||
| 7 | // OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5 | ||
| 8 | // // 1: about 137kbps (default) | ||
| 9 | // // 2: about 75kbps | ||
| 10 | // // 3: about 39kbps | ||
| 11 | // // 4: about 26kbps | ||
| 12 | // // 5: about 20kbps | ||
| 13 | #endif | ||
| 14 | |||
| 15 | //// USE flexible API (using multi-type transaction function) | ||
| 16 | #define SERIAL_USE_MULTI_TRANSACTION | ||
| 17 | |||
| 18 | #endif /* SOFT_SERIAL_CONFIG_H */ | ||
diff --git a/keyboards/zinc/rev1/serial_config_simpleapi.h b/keyboards/zinc/rev1/serial_config_simpleapi.h new file mode 100644 index 000000000..e2d22a41e --- /dev/null +++ b/keyboards/zinc/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/zinc/rev1/split_scomm.c b/keyboards/zinc/rev1/split_scomm.c new file mode 100644 index 000000000..50d233ce9 --- /dev/null +++ b/keyboards/zinc/rev1/split_scomm.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | #ifdef USE_SERIAL | ||
| 2 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 3 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 4 | |||
| 5 | #include <stdbool.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <stddef.h> | ||
| 8 | #include <split_scomm.h> | ||
| 9 | #include "serial.h" | ||
| 10 | #ifdef SERIAL_DEBUG_MODE | ||
| 11 | #include <avr/io.h> | ||
| 12 | #endif | ||
| 13 | #ifdef CONSOLE_ENABLE | ||
| 14 | #include <print.h> | ||
| 15 | #endif | ||
| 16 | |||
| 17 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
| 18 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
| 19 | uint8_t volatile status_com = 0; | ||
| 20 | uint8_t volatile status1 = 0; | ||
| 21 | uint8_t slave_buffer_change_count = 0; | ||
| 22 | uint8_t s_change_old = 0xff; | ||
| 23 | uint8_t s_change_new = 0xff; | ||
| 24 | |||
| 25 | SSTD_t transactions[] = { | ||
| 26 | #define GET_SLAVE_STATUS 0 | ||
| 27 | /* master buffer not changed, only recive slave_buffer_change_count */ | ||
| 28 | { (uint8_t *)&status_com, | ||
| 29 | 0, NULL, | ||
| 30 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 31 | }, | ||
| 32 | #define PUT_MASTER_GET_SLAVE_STATUS 1 | ||
| 33 | /* master buffer changed need send, and recive slave_buffer_change_count */ | ||
| 34 | { (uint8_t *)&status_com, | ||
| 35 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
| 36 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 37 | }, | ||
| 38 | #define GET_SLAVE_BUFFER 2 | ||
| 39 | /* recive serial_slave_buffer */ | ||
| 40 | { (uint8_t *)&status1, | ||
| 41 | 0, NULL, | ||
| 42 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
| 43 | } | ||
| 44 | }; | ||
| 45 | |||
| 46 | void serial_master_init(void) | ||
| 47 | { | ||
| 48 | soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); | ||
| 49 | } | ||
| 50 | |||
| 51 | void serial_slave_init(void) | ||
| 52 | { | ||
| 53 | soft_serial_target_init(transactions, TID_LIMIT(transactions)); | ||
| 54 | } | ||
| 55 | |||
| 56 | // 0 => no error | ||
| 57 | // 1 => slave did not respond | ||
| 58 | // 2 => checksum error | ||
| 59 | int serial_update_buffers(int master_update) | ||
| 60 | { | ||
| 61 | int status, smatstatus; | ||
| 62 | static int need_retry = 0; | ||
| 63 | |||
| 64 | if( s_change_old != s_change_new ) { | ||
| 65 | smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER); | ||
| 66 | if( smatstatus == TRANSACTION_END ) { | ||
| 67 | s_change_old = s_change_new; | ||
| 68 | #ifdef CONSOLE_ENABLE | ||
| 69 | uprintf("slave matrix = %b %b %b %b %b\n", | ||
| 70 | serial_slave_buffer[0], serial_slave_buffer[1], | ||
| 71 | serial_slave_buffer[2], serial_slave_buffer[3], | ||
| 72 | serial_slave_buffer[4] ); | ||
| 73 | #endif | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | // serial_slave_buffer dosen't change | ||
| 77 | smatstatus = TRANSACTION_END; // dummy status | ||
| 78 | } | ||
| 79 | |||
| 80 | if( !master_update && !need_retry) { | ||
| 81 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
| 82 | } else { | ||
| 83 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
| 84 | } | ||
| 85 | if( status == TRANSACTION_END ) { | ||
| 86 | s_change_new = slave_buffer_change_count; | ||
| 87 | need_retry = 0; | ||
| 88 | } else { | ||
| 89 | need_retry = 1; | ||
| 90 | } | ||
| 91 | return smatstatus; | ||
| 92 | } | ||
| 93 | |||
| 94 | #endif // SERIAL_USE_MULTI_TRANSACTION | ||
| 95 | #endif /* USE_SERIAL */ | ||
diff --git a/keyboards/zinc/rev1/split_scomm.h b/keyboards/zinc/rev1/split_scomm.h new file mode 100644 index 000000000..873d8939d --- /dev/null +++ b/keyboards/zinc/rev1/split_scomm.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #ifndef SPLIT_COMM_H | ||
| 2 | #define SPLIT_COMM_H | ||
| 3 | |||
| 4 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 5 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */ | ||
| 6 | #include "serial.h" | ||
| 7 | |||
| 8 | #else | ||
| 9 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 10 | // Buffers for master - slave communication | ||
| 11 | #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 12 | #define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 13 | |||
| 14 | extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; | ||
| 15 | extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; | ||
| 16 | extern uint8_t slave_buffer_change_count; | ||
| 17 | |||
| 18 | void serial_master_init(void); | ||
| 19 | void serial_slave_init(void); | ||
| 20 | int serial_update_buffers(int master_changed); | ||
| 21 | |||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif /* SPLIT_COMM_H */ | ||
diff --git a/keyboards/zinc/rev1/split_util.c b/keyboards/zinc/rev1/split_util.c new file mode 100644 index 000000000..e1ff8b437 --- /dev/null +++ b/keyboards/zinc/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/zinc/rev1/split_util.h b/keyboards/zinc/rev1/split_util.h new file mode 100644 index 000000000..687ca19bd --- /dev/null +++ b/keyboards/zinc/rev1/split_util.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #ifndef SPLIT_KEYBOARD_UTIL_H | ||
| 2 | #define SPLIT_KEYBOARD_UTIL_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include "eeconfig.h" | ||
| 6 | |||
| 7 | #define SLAVE_I2C_ADDRESS 0x32 | ||
| 8 | |||
| 9 | extern volatile bool isLeftHand; | ||
| 10 | |||
| 11 | // slave version of matix scan, defined in matrix.c | ||
| 12 | void matrix_slave_scan(void); | ||
| 13 | |||
| 14 | void split_keyboard_setup(void); | ||
| 15 | bool has_usb(void); | ||
| 16 | |||
| 17 | void matrix_master_OLED_init (void); | ||
| 18 | |||
| 19 | #endif | ||
diff --git a/keyboards/zinc/reva/config.h b/keyboards/zinc/reva/config.h new file mode 100644 index 000000000..158051890 --- /dev/null +++ b/keyboards/zinc/reva/config.h | |||
| @@ -0,0 +1,143 @@ | |||
| 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 0x9991 | ||
| 24 | #define DEVICE_VER 0x0001 | ||
| 25 | #define MANUFACTURER monksoffunk | ||
| 26 | #define PRODUCT zinc rev.A | ||
| 27 | #define DESCRIPTION A split keyboard | ||
| 28 | |||
| 29 | |||
| 30 | #define PREVENT_STUCK_MODIFIERS | ||
| 31 | #define TAPPING_FORCE_HOLD | ||
| 32 | #define TAPPING_TERM 100 | ||
| 33 | |||
| 34 | /* Use I2C or Serial */ | ||
| 35 | //#define USE_I2C | ||
| 36 | #define USE_SERIAL | ||
| 37 | //#define USE_MATRIX_I2C | ||
| 38 | |||
| 39 | /* Select hand configuration */ | ||
| 40 | #define MASTER_LEFT | ||
| 41 | //#define MASTER_RIGHT | ||
| 42 | //#define EE_HANDS | ||
| 43 | |||
| 44 | |||
| 45 | /* key matrix size */ | ||
| 46 | // Rows are doubled-up | ||
| 47 | #define MATRIX_ROWS 8 | ||
| 48 | #define MATRIX_ROW_PINS { D4, C6, D7, E6 } | ||
| 49 | |||
| 50 | // wiring of each half | ||
| 51 | #define MATRIX_COLS 6 | ||
| 52 | #define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3} | ||
| 53 | |||
| 54 | /* define if matrix has ghost */ | ||
| 55 | //#define MATRIX_HAS_GHOST | ||
| 56 | |||
| 57 | /* number of backlight levels */ | ||
| 58 | // #define BACKLIGHT_LEVELS 3 | ||
| 59 | |||
| 60 | /* Set 0 if debouncing isn't needed */ | ||
| 61 | #define DEBOUNCING_DELAY 5 | ||
| 62 | |||
| 63 | /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ | ||
| 64 | //#define LOCKING_SUPPORT_ENABLE | ||
| 65 | /* Locking resynchronize hack */ | ||
| 66 | //#define LOCKING_RESYNC_ENABLE | ||
| 67 | |||
| 68 | /* key combination for command */ | ||
| 69 | #define IS_COMMAND() ( \ | ||
| 70 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ | ||
| 71 | ) | ||
| 72 | |||
| 73 | /* ws2812 RGB LED */ | ||
| 74 | #define RGB_DI_PIN D3 | ||
| 75 | #define RGBLIGHT_TIMER | ||
| 76 | //#define RGBLED_NUM 24 // Number of LEDs. see ./keymaps/default/config.h | ||
| 77 | #define ws2812_PORTREG PORTD | ||
| 78 | #define ws2812_DDRREG DDRD | ||
| 79 | |||
| 80 | // RGB LED support | ||
| 81 | //#define RGBLIGHT_ANIMATIONS : see ./rules.mk: LED_ANIMATIONS = yes or no | ||
| 82 | // see ./rules.mk: LED_BACK_ENABLE or LED_UNDERGLOW_ENABLE set yes | ||
| 83 | #ifdef RGBLED_BACK | ||
| 84 | #define RGBLED_NUM 24 | ||
| 85 | #else | ||
| 86 | #define RGBLED_NUM 6 | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #ifndef IOS_DEVICE_ENABLE | ||
| 90 | #if RGBLED_NUM <= 6 | ||
| 91 | #define RGBLIGHT_LIMIT_VAL 255 | ||
| 92 | #else | ||
| 93 | #if RGBLED_NUM <= 16 | ||
| 94 | #define RGBLIGHT_LIMIT_VAL 130 | ||
| 95 | #else | ||
| 96 | #define RGBLIGHT_LIMIT_VAL 120 | ||
| 97 | #endif | ||
| 98 | #endif | ||
| 99 | #define RGBLIGHT_VAL_STEP 17 | ||
| 100 | #else | ||
| 101 | #if RGBLED_NUM <= 6 | ||
| 102 | #define RGBLIGHT_LIMIT_VAL 90 | ||
| 103 | #else | ||
| 104 | #if RGBLED_NUM <= 16 | ||
| 105 | #define RGBLIGHT_LIMIT_VAL 45 | ||
| 106 | #else | ||
| 107 | #define RGBLIGHT_LIMIT_VAL 35 | ||
| 108 | #endif | ||
| 109 | #endif | ||
| 110 | #define RGBLIGHT_VAL_STEP 4 | ||
| 111 | #endif | ||
| 112 | #define RGBLIGHT_HUE_STEP 10 | ||
| 113 | #define RGBLIGHT_SAT_STEP 17 | ||
| 114 | |||
| 115 | #if defined(RGBLIGHT_ENABLE) && !defined(IOS_DEVICE_ENABLE) | ||
| 116 | // USB_MAX_POWER_CONSUMPTION value | ||
| 117 | // 120 RGBoff | ||
| 118 | // 330 RGB 6 | ||
| 119 | // 300 RGB 32 | ||
| 120 | #define USB_MAX_POWER_CONSUMPTION 400 | ||
| 121 | #else | ||
| 122 | // fix iPhone and iPad power adapter issue | ||
| 123 | // iOS device need lessthan 100 | ||
| 124 | #define USB_MAX_POWER_CONSUMPTION 100 | ||
| 125 | #endif | ||
| 126 | |||
| 127 | /* | ||
| 128 | * Feature disable options | ||
| 129 | * These options are also useful to firmware size reduction. | ||
| 130 | */ | ||
| 131 | |||
| 132 | /* disable debug print */ | ||
| 133 | // #define NO_DEBUG | ||
| 134 | |||
| 135 | /* disable print */ | ||
| 136 | // #define NO_PRINT | ||
| 137 | |||
| 138 | /* disable action features */ | ||
| 139 | //#define NO_ACTION_LAYER | ||
| 140 | //#define NO_ACTION_TAPPING | ||
| 141 | //#define NO_ACTION_ONESHOT | ||
| 142 | //#define NO_ACTION_MACRO | ||
| 143 | //#define NO_ACTION_FUNCTION | ||
diff --git a/keyboards/zinc/reva/info.json b/keyboards/zinc/reva/info.json new file mode 100644 index 000000000..138c79068 --- /dev/null +++ b/keyboards/zinc/reva/info.json | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | { | ||
| 2 | "keyboard_name": "Zinc rev.A", | ||
| 3 | "url": "https://github.com/monksoffunk/zinc", | ||
| 4 | "maintainer": "monksoffunk", | ||
| 5 | "width": 15, | ||
| 6 | "height": 4, | ||
| 7 | "layouts": { | ||
| 8 | "LAYOUT": { | ||
| 9 | "key_count": 48, | ||
| 10 | "layout": [{"x":0, "y":0}, {"x":1, "y":0}, {"x":2, "y":0}, {"x":3, "y":0}, {"x":4, "y":0}, {"x":5, "y":0}, {"x":9, "y":0}, {"x":10, "y":0}, {"x":11, "y":0}, {"x":12, "y":0}, {"x":13, "y":0}, {"x":14, "y":0}, {"x":0, "y":1}, {"x":1, "y":1}, {"x":2, "y":1}, {"x":3, "y":1}, {"x":4, "y":1}, {"x":5, "y":1}, {"x":9, "y":1}, {"x":10, "y":1}, {"x":11, "y":1}, {"x":12, "y":1}, {"x":13, "y":1}, {"x":14, "y":1}, {"x":0, "y":2}, {"x":1, "y":2}, {"x":2, "y":2}, {"x":3, "y":2}, {"x":4, "y":2}, {"x":5, "y":2}, {"x":9, "y":2}, {"x":10, "y":2}, {"x":11, "y":2}, {"x":12, "y":2}, {"x":13, "y":2}, {"x":14, "y":2}, {"x":0, "y":3}, {"x":1, "y":3}, {"x":2, "y":3}, {"x":3, "y":3}, {"x":4, "y":3}, {"x":5, "y":3}, {"x":9, "y":3}, {"x":10, "y":3}, {"x":11, "y":3}, {"x":12, "y":3}, {"x":13, "y":3}, {"x":14, "y":3}] | ||
| 11 | } | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/keyboards/zinc/reva/matrix.c b/keyboards/zinc/reva/matrix.c new file mode 100644 index 000000000..220954f05 --- /dev/null +++ b/keyboards/zinc/reva/matrix.c | |||
| @@ -0,0 +1,356 @@ | |||
| 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 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 222 | |||
| 223 | #ifdef USE_MATRIX_I2C | ||
| 224 | // for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 225 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 226 | // i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 227 | // } | ||
| 228 | #else // USE_SERIAL | ||
| 229 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 230 | mchanged = memcmp((void *)serial_master_buffer, | ||
| 231 | &matrix[offset], sizeof(serial_master_buffer)); | ||
| 232 | #endif | ||
| 233 | memcpy((void *)serial_master_buffer, | ||
| 234 | &matrix[offset], sizeof(serial_master_buffer)); | ||
| 235 | #endif | ||
| 236 | |||
| 237 | #ifdef USE_MATRIX_I2C | ||
| 238 | if( i2c_transaction() ) { | ||
| 239 | #else // USE_SERIAL | ||
| 240 | if( serial_transaction(mchanged) ) { | ||
| 241 | #endif | ||
| 242 | // turn on the indicator led when halves are disconnected | ||
| 243 | TXLED1; | ||
| 244 | |||
| 245 | error_count++; | ||
| 246 | |||
| 247 | if (error_count > ERROR_DISCONNECT_COUNT) { | ||
| 248 | // reset other half if disconnected | ||
| 249 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 250 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 251 | matrix[slaveOffset+i] = 0; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | } else { | ||
| 255 | // turn off the indicator led on no error | ||
| 256 | TXLED0; | ||
| 257 | error_count = 0; | ||
| 258 | } | ||
| 259 | matrix_scan_quantum(); | ||
| 260 | return ret; | ||
| 261 | } | ||
| 262 | |||
| 263 | void matrix_slave_scan(void) { | ||
| 264 | _matrix_scan(); | ||
| 265 | |||
| 266 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 267 | |||
| 268 | #ifdef USE_MATRIX_I2C | ||
| 269 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 270 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 271 | i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 272 | } | ||
| 273 | #else // USE_SERIAL | ||
| 274 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 275 | int change = 0; | ||
| 276 | #endif | ||
| 277 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 278 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 279 | if( serial_slave_buffer[i] != matrix[offset+i] ) | ||
| 280 | change = 1; | ||
| 281 | #endif | ||
| 282 | serial_slave_buffer[i] = matrix[offset+i]; | ||
| 283 | } | ||
| 284 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 285 | slave_buffer_change_count += change; | ||
| 286 | #endif | ||
| 287 | #endif | ||
| 288 | } | ||
| 289 | |||
| 290 | bool matrix_is_modified(void) | ||
| 291 | { | ||
| 292 | if (debouncing) return false; | ||
| 293 | return true; | ||
| 294 | } | ||
| 295 | |||
| 296 | inline | ||
| 297 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 298 | { | ||
| 299 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 300 | } | ||
| 301 | |||
| 302 | inline | ||
| 303 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 304 | { | ||
| 305 | return matrix[row]; | ||
| 306 | } | ||
| 307 | |||
| 308 | void matrix_print(void) | ||
| 309 | { | ||
| 310 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 311 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 312 | phex(row); print(": "); | ||
| 313 | pbin_reverse16(matrix_get_row(row)); | ||
| 314 | print("\n"); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | uint8_t matrix_key_count(void) | ||
| 319 | { | ||
| 320 | uint8_t count = 0; | ||
| 321 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 322 | count += bitpop16(matrix[i]); | ||
| 323 | } | ||
| 324 | return count; | ||
| 325 | } | ||
| 326 | |||
| 327 | static void init_cols(void) | ||
| 328 | { | ||
| 329 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 330 | _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF); | ||
| 331 | _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF); | ||
| 332 | } | ||
| 333 | } | ||
| 334 | |||
| 335 | static matrix_row_t read_cols(void) | ||
| 336 | { | ||
| 337 | matrix_row_t result = 0; | ||
| 338 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 339 | result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x); | ||
| 340 | } | ||
| 341 | return result; | ||
| 342 | } | ||
| 343 | |||
| 344 | static void unselect_rows(void) | ||
| 345 | { | ||
| 346 | for(int x = 0; x < ROWS_PER_HAND; x++) { | ||
| 347 | _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF); | ||
| 348 | _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF); | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | static void select_row(uint8_t row) | ||
| 353 | { | ||
| 354 | _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF); | ||
| 355 | _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF); | ||
| 356 | } | ||
diff --git a/keyboards/zinc/reva/reva.c b/keyboards/zinc/reva/reva.c new file mode 100644 index 000000000..2ce08a07c --- /dev/null +++ b/keyboards/zinc/reva/reva.c | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #include "zinc.h" | ||
| 2 | |||
| 3 | void matrix_init_kb(void) { | ||
| 4 | matrix_init_user(); | ||
| 5 | }; | ||
| 6 | |||
diff --git a/keyboards/zinc/reva/reva.h b/keyboards/zinc/reva/reva.h new file mode 100644 index 000000000..933e635c2 --- /dev/null +++ b/keyboards/zinc/reva/reva.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../zinc.h" | ||
| 4 | |||
| 5 | //void promicro_bootloader_jmp(bool program); | ||
| 6 | #include "quantum.h" | ||
| 7 | |||
| 8 | #ifdef RGBLIGHT_ENABLE | ||
| 9 | //rgb led driver | ||
| 10 | #include "ws2812.h" | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #ifdef USE_I2C | ||
| 14 | #include <stddef.h> | ||
| 15 | #ifdef __AVR__ | ||
| 16 | #include <avr/io.h> | ||
| 17 | #include <avr/interrupt.h> | ||
| 18 | #endif | ||
| 19 | #endif | ||
| 20 | |||
| 21 | //void promicro_bootloader_jmp(bool program); | ||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | // Standard Keymap | ||
| 26 | // (TRRS jack on both halves are to the left side) | ||
| 27 | #define LAYOUT( \ | ||
| 28 | L00, L01, L02, L03, L04, L05, R00, R01, R02, R03, R04, R05, \ | ||
| 29 | L10, L11, L12, L13, L14, L15, R10, R11, R12, R13, R14, R15, \ | ||
| 30 | L20, L21, L22, L23, L24, L25, R20, R21, R22, R23, R24, R25, \ | ||
| 31 | L30, L31, L32, L33, L34, L35, R30, R31, R32, R33, R34, R35 \ | ||
| 32 | ) \ | ||
| 33 | { \ | ||
| 34 | { L00, L01, L02, L03, L04, L05}, \ | ||
| 35 | { L10, L11, L12, L13, L14, L15}, \ | ||
| 36 | { L20, L21, L22, L23, L24, L25}, \ | ||
| 37 | { L30, L31, L32, L33, L34, L35}, \ | ||
| 38 | { R00, R01, R02, R03, R04, R05 }, \ | ||
| 39 | { R10, R11, R12, R13, R14, R15 }, \ | ||
| 40 | { R20, R21, R22, R23, R24, R25 }, \ | ||
| 41 | { R30, R31, R32, R33, R34, R35 }, \ | ||
| 42 | } | ||
| 43 | |||
| 44 | #define LAYOUT_ortho_4x12 LAYOUT | ||
diff --git a/keyboards/zinc/reva/rules.mk b/keyboards/zinc/reva/rules.mk new file mode 100644 index 000000000..3ea61267a --- /dev/null +++ b/keyboards/zinc/reva/rules.mk | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | SRC += reva/matrix.c | ||
| 2 | SRC += reva/split_util.c | ||
| 3 | SRC += reva/split_scomm.c | ||
| 4 | SRC += ws2812.c | ||
diff --git a/keyboards/zinc/reva/serial_config.h b/keyboards/zinc/reva/serial_config.h new file mode 100644 index 000000000..9fb5dfc67 --- /dev/null +++ b/keyboards/zinc/reva/serial_config.h | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #ifndef SOFT_SERIAL_CONFIG_H | ||
| 2 | #define SOFT_SERIAL_CONFIG_H | ||
| 3 | |||
| 4 | #ifndef SOFT_SERIAL_PIN | ||
| 5 | /* Soft Serial defines */ | ||
| 6 | #define SOFT_SERIAL_PIN D2 | ||
| 7 | // OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5 | ||
| 8 | // // 1: about 137kbps (default) | ||
| 9 | // // 2: about 75kbps | ||
| 10 | // // 3: about 39kbps | ||
| 11 | // // 4: about 26kbps | ||
| 12 | // // 5: about 20kbps | ||
| 13 | #endif | ||
| 14 | |||
| 15 | //// USE flexible API (using multi-type transaction function) | ||
| 16 | #define SERIAL_USE_MULTI_TRANSACTION | ||
| 17 | |||
| 18 | #endif /* SOFT_SERIAL_CONFIG_H */ | ||
diff --git a/keyboards/zinc/reva/serial_config_simpleapi.h b/keyboards/zinc/reva/serial_config_simpleapi.h new file mode 100644 index 000000000..e2d22a41e --- /dev/null +++ b/keyboards/zinc/reva/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/zinc/reva/split_scomm.c b/keyboards/zinc/reva/split_scomm.c new file mode 100644 index 000000000..50d233ce9 --- /dev/null +++ b/keyboards/zinc/reva/split_scomm.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | #ifdef USE_SERIAL | ||
| 2 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 3 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 4 | |||
| 5 | #include <stdbool.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <stddef.h> | ||
| 8 | #include <split_scomm.h> | ||
| 9 | #include "serial.h" | ||
| 10 | #ifdef SERIAL_DEBUG_MODE | ||
| 11 | #include <avr/io.h> | ||
| 12 | #endif | ||
| 13 | #ifdef CONSOLE_ENABLE | ||
| 14 | #include <print.h> | ||
| 15 | #endif | ||
| 16 | |||
| 17 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
| 18 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
| 19 | uint8_t volatile status_com = 0; | ||
| 20 | uint8_t volatile status1 = 0; | ||
| 21 | uint8_t slave_buffer_change_count = 0; | ||
| 22 | uint8_t s_change_old = 0xff; | ||
| 23 | uint8_t s_change_new = 0xff; | ||
| 24 | |||
| 25 | SSTD_t transactions[] = { | ||
| 26 | #define GET_SLAVE_STATUS 0 | ||
| 27 | /* master buffer not changed, only recive slave_buffer_change_count */ | ||
| 28 | { (uint8_t *)&status_com, | ||
| 29 | 0, NULL, | ||
| 30 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 31 | }, | ||
| 32 | #define PUT_MASTER_GET_SLAVE_STATUS 1 | ||
| 33 | /* master buffer changed need send, and recive slave_buffer_change_count */ | ||
| 34 | { (uint8_t *)&status_com, | ||
| 35 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
| 36 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 37 | }, | ||
| 38 | #define GET_SLAVE_BUFFER 2 | ||
| 39 | /* recive serial_slave_buffer */ | ||
| 40 | { (uint8_t *)&status1, | ||
| 41 | 0, NULL, | ||
| 42 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
| 43 | } | ||
| 44 | }; | ||
| 45 | |||
| 46 | void serial_master_init(void) | ||
| 47 | { | ||
| 48 | soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); | ||
| 49 | } | ||
| 50 | |||
| 51 | void serial_slave_init(void) | ||
| 52 | { | ||
| 53 | soft_serial_target_init(transactions, TID_LIMIT(transactions)); | ||
| 54 | } | ||
| 55 | |||
| 56 | // 0 => no error | ||
| 57 | // 1 => slave did not respond | ||
| 58 | // 2 => checksum error | ||
| 59 | int serial_update_buffers(int master_update) | ||
| 60 | { | ||
| 61 | int status, smatstatus; | ||
| 62 | static int need_retry = 0; | ||
| 63 | |||
| 64 | if( s_change_old != s_change_new ) { | ||
| 65 | smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER); | ||
| 66 | if( smatstatus == TRANSACTION_END ) { | ||
| 67 | s_change_old = s_change_new; | ||
| 68 | #ifdef CONSOLE_ENABLE | ||
| 69 | uprintf("slave matrix = %b %b %b %b %b\n", | ||
| 70 | serial_slave_buffer[0], serial_slave_buffer[1], | ||
| 71 | serial_slave_buffer[2], serial_slave_buffer[3], | ||
| 72 | serial_slave_buffer[4] ); | ||
| 73 | #endif | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | // serial_slave_buffer dosen't change | ||
| 77 | smatstatus = TRANSACTION_END; // dummy status | ||
| 78 | } | ||
| 79 | |||
| 80 | if( !master_update && !need_retry) { | ||
| 81 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
| 82 | } else { | ||
| 83 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
| 84 | } | ||
| 85 | if( status == TRANSACTION_END ) { | ||
| 86 | s_change_new = slave_buffer_change_count; | ||
| 87 | need_retry = 0; | ||
| 88 | } else { | ||
| 89 | need_retry = 1; | ||
| 90 | } | ||
| 91 | return smatstatus; | ||
| 92 | } | ||
| 93 | |||
| 94 | #endif // SERIAL_USE_MULTI_TRANSACTION | ||
| 95 | #endif /* USE_SERIAL */ | ||
diff --git a/keyboards/zinc/reva/split_scomm.h b/keyboards/zinc/reva/split_scomm.h new file mode 100644 index 000000000..873d8939d --- /dev/null +++ b/keyboards/zinc/reva/split_scomm.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #ifndef SPLIT_COMM_H | ||
| 2 | #define SPLIT_COMM_H | ||
| 3 | |||
| 4 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 5 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */ | ||
| 6 | #include "serial.h" | ||
| 7 | |||
| 8 | #else | ||
| 9 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 10 | // Buffers for master - slave communication | ||
| 11 | #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 12 | #define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 13 | |||
| 14 | extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; | ||
| 15 | extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; | ||
| 16 | extern uint8_t slave_buffer_change_count; | ||
| 17 | |||
| 18 | void serial_master_init(void); | ||
| 19 | void serial_slave_init(void); | ||
| 20 | int serial_update_buffers(int master_changed); | ||
| 21 | |||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif /* SPLIT_COMM_H */ | ||
diff --git a/keyboards/zinc/reva/split_util.c b/keyboards/zinc/reva/split_util.c new file mode 100644 index 000000000..e1ff8b437 --- /dev/null +++ b/keyboards/zinc/reva/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/zinc/reva/split_util.h b/keyboards/zinc/reva/split_util.h new file mode 100644 index 000000000..687ca19bd --- /dev/null +++ b/keyboards/zinc/reva/split_util.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #ifndef SPLIT_KEYBOARD_UTIL_H | ||
| 2 | #define SPLIT_KEYBOARD_UTIL_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include "eeconfig.h" | ||
| 6 | |||
| 7 | #define SLAVE_I2C_ADDRESS 0x32 | ||
| 8 | |||
| 9 | extern volatile bool isLeftHand; | ||
| 10 | |||
| 11 | // slave version of matix scan, defined in matrix.c | ||
| 12 | void matrix_slave_scan(void); | ||
| 13 | |||
| 14 | void split_keyboard_setup(void); | ||
| 15 | bool has_usb(void); | ||
| 16 | |||
| 17 | void matrix_master_OLED_init (void); | ||
| 18 | |||
| 19 | #endif | ||
diff --git a/keyboards/zinc/rules.mk b/keyboards/zinc/rules.mk new file mode 100644 index 000000000..5236c0bb0 --- /dev/null +++ b/keyboards/zinc/rules.mk | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | #SRC += i2c.c | ||
| 2 | SRC += serial.c | ||
| 3 | |||
| 4 | # MCU name | ||
| 5 | #MCU = at90usb1287 | ||
| 6 | MCU = atmega32u4 | ||
| 7 | |||
| 8 | # Processor frequency. | ||
| 9 | # This will define a symbol, F_CPU, in all source code files equal to the | ||
| 10 | # processor frequency in Hz. You can then use this symbol in your source code to | ||
| 11 | # calculate timings. Do NOT tack on a 'UL' at the end, this will be done | ||
| 12 | # automatically to create a 32-bit value in your source code. | ||
| 13 | # | ||
| 14 | # This will be an integer division of F_USB below, as it is sourced by | ||
| 15 | # F_USB after it has run through any CPU prescalers. Note that this value | ||
| 16 | # does not *change* the processor frequency - it should merely be updated to | ||
| 17 | # reflect the processor speed set externally so that the code can use accurate | ||
| 18 | # software delays. | ||
| 19 | F_CPU = 16000000 | ||
| 20 | |||
| 21 | # | ||
| 22 | # LUFA specific | ||
| 23 | # | ||
| 24 | # Target architecture (see library "Board Types" documentation). | ||
| 25 | ARCH = AVR8 | ||
| 26 | |||
| 27 | # Input clock frequency. | ||
| 28 | # This will define a symbol, F_USB, in all source code files equal to the | ||
| 29 | # input clock frequency (before any prescaling is performed) in Hz. This value may | ||
| 30 | # differ from F_CPU if prescaling is used on the latter, and is required as the | ||
| 31 | # raw input clock is fed directly to the PLL sections of the AVR for high speed | ||
| 32 | # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' | ||
| 33 | # at the end, this will be done automatically to create a 32-bit value in your | ||
| 34 | # source code. | ||
| 35 | # | ||
| 36 | # If no clock division is performed on the input clock inside the AVR (via the | ||
| 37 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. | ||
| 38 | F_USB = $(F_CPU) | ||
| 39 | |||
| 40 | # Bootloader | ||
| 41 | # This definition is optional, and if your keyboard supports multiple bootloaders of | ||
| 42 | # different sizes, comment this out, and the correct address will be loaded | ||
| 43 | # automatically (+60). See bootloader.mk for all options. | ||
| 44 | BOOTLOADER = caterina | ||
| 45 | |||
| 46 | # Interrupt driven control endpoint task(+60) | ||
| 47 | OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT | ||
| 48 | |||
| 49 | # Build Options | ||
| 50 | # change to "no" to disable the options, or define them in the Makefile in | ||
| 51 | # the appropriate keymap folder that will get included automatically | ||
| 52 | # | ||
| 53 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | ||
| 54 | MOUSEKEY_ENABLE = no # Mouse keys(+4700) | ||
| 55 | EXTRAKEY_ENABLE = no # Audio control and System control(+450) | ||
| 56 | CONSOLE_ENABLE = no # Console for debug(+400) | ||
| 57 | COMMAND_ENABLE = no # Commands for debug and configuration | ||
| 58 | NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | ||
| 59 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | ||
| 60 | MIDI_ENABLE = no # MIDI controls | ||
| 61 | AUDIO_ENABLE = no # Audio output on port C6 | ||
| 62 | UNICODE_ENABLE = no # Unicode | ||
| 63 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | ||
| 64 | RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. | ||
| 65 | SUBPROJECT_rev1 = no | ||
| 66 | USE_I2C = yes | ||
| 67 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | ||
| 68 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | ||
| 69 | |||
| 70 | CUSTOM_MATRIX = yes | ||
| 71 | |||
| 72 | DEFAULT_FOLDER = zinc/rev1 | ||
diff --git a/keyboards/zinc/serial.c b/keyboards/zinc/serial.c new file mode 100644 index 000000000..830f86b55 --- /dev/null +++ b/keyboards/zinc/serial.c | |||
| @@ -0,0 +1,542 @@ | |||
| 1 | /* | ||
| 2 | * WARNING: be careful changing this code, it is very timing dependent | ||
| 3 | */ | ||
| 4 | |||
| 5 | #ifndef F_CPU | ||
| 6 | #define F_CPU 16000000 | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #include <avr/io.h> | ||
| 10 | #include <avr/interrupt.h> | ||
| 11 | #include <util/delay.h> | ||
| 12 | #include <stddef.h> | ||
| 13 | #include <stdbool.h> | ||
| 14 | #include "serial.h" | ||
| 15 | //#include <pro_micro.h> | ||
| 16 | |||
| 17 | #ifdef SOFT_SERIAL_PIN | ||
| 18 | |||
| 19 | #ifdef __AVR_ATmega32U4__ | ||
| 20 | // if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial. | ||
| 21 | #ifdef USE_I2C | ||
| 22 | #if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1 | ||
| 23 | #error Using ATmega32U4 I2C, so can not use PD0, PD1 | ||
| 24 | #endif | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3 | ||
| 28 | #define SERIAL_PIN_DDR DDRD | ||
| 29 | #define SERIAL_PIN_PORT PORTD | ||
| 30 | #define SERIAL_PIN_INPUT PIND | ||
| 31 | #if SOFT_SERIAL_PIN == D0 | ||
| 32 | #define SERIAL_PIN_MASK _BV(PD0) | ||
| 33 | #define EIMSK_BIT _BV(INT0) | ||
| 34 | #define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01))) | ||
| 35 | #define SERIAL_PIN_INTERRUPT INT0_vect | ||
| 36 | #elif SOFT_SERIAL_PIN == D1 | ||
| 37 | #define SERIAL_PIN_MASK _BV(PD1) | ||
| 38 | #define EIMSK_BIT _BV(INT1) | ||
| 39 | #define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11))) | ||
| 40 | #define SERIAL_PIN_INTERRUPT INT1_vect | ||
| 41 | #elif SOFT_SERIAL_PIN == D2 | ||
| 42 | #define SERIAL_PIN_MASK _BV(PD2) | ||
| 43 | #define EIMSK_BIT _BV(INT2) | ||
| 44 | #define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21))) | ||
| 45 | #define SERIAL_PIN_INTERRUPT INT2_vect | ||
| 46 | #elif SOFT_SERIAL_PIN == D3 | ||
| 47 | #define SERIAL_PIN_MASK _BV(PD3) | ||
| 48 | #define EIMSK_BIT _BV(INT3) | ||
| 49 | #define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31))) | ||
| 50 | #define SERIAL_PIN_INTERRUPT INT3_vect | ||
| 51 | #endif | ||
| 52 | #elif SOFT_SERIAL_PIN == E6 | ||
| 53 | #define SERIAL_PIN_DDR DDRE | ||
| 54 | #define SERIAL_PIN_PORT PORTE | ||
| 55 | #define SERIAL_PIN_INPUT PINE | ||
| 56 | #define SERIAL_PIN_MASK _BV(PE6) | ||
| 57 | #define EIMSK_BIT _BV(INT6) | ||
| 58 | #define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61))) | ||
| 59 | #define SERIAL_PIN_INTERRUPT INT6_vect | ||
| 60 | #else | ||
| 61 | #error invalid SOFT_SERIAL_PIN value | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #else | ||
| 65 | #error serial.c now support ATmega32U4 only | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 69 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) */ | ||
| 70 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 | ||
| 71 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
| 72 | #endif | ||
| 73 | #if SERIAL_MASTER_BUFFER_LENGTH > 0 | ||
| 74 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
| 75 | #endif | ||
| 76 | uint8_t volatile status0 = 0; | ||
| 77 | |||
| 78 | SSTD_t transactions[] = { | ||
| 79 | { (uint8_t *)&status0, | ||
| 80 | #if SERIAL_MASTER_BUFFER_LENGTH > 0 | ||
| 81 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
| 82 | #else | ||
| 83 | 0, (uint8_t *)NULL, | ||
| 84 | #endif | ||
| 85 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 | ||
| 86 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
| 87 | #else | ||
| 88 | 0, (uint8_t *)NULL, | ||
| 89 | #endif | ||
| 90 | } | ||
| 91 | }; | ||
| 92 | |||
| 93 | void serial_master_init(void) | ||
| 94 | { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } | ||
| 95 | |||
| 96 | void serial_slave_init(void) | ||
| 97 | { soft_serial_target_init(transactions, TID_LIMIT(transactions)); } | ||
| 98 | |||
| 99 | // 0 => no error | ||
| 100 | // 1 => slave did not respond | ||
| 101 | // 2 => checksum error | ||
| 102 | int serial_update_buffers() | ||
| 103 | { | ||
| 104 | int result; | ||
| 105 | result = soft_serial_transaction(); | ||
| 106 | return result; | ||
| 107 | } | ||
| 108 | |||
| 109 | #endif // Simple API (OLD API, compatible with let's split serial.c) | ||
| 110 | |||
| 111 | #define ALWAYS_INLINE __attribute__((always_inline)) | ||
| 112 | #define NO_INLINE __attribute__((noinline)) | ||
| 113 | #define _delay_sub_us(x) __builtin_avr_delay_cycles(x) | ||
| 114 | |||
| 115 | // parity check | ||
| 116 | #define ODD_PARITY 1 | ||
| 117 | #define EVEN_PARITY 0 | ||
| 118 | #define PARITY EVEN_PARITY | ||
| 119 | |||
| 120 | #ifdef SERIAL_DELAY | ||
| 121 | // custom setup in config.h | ||
| 122 | // #define TID_SEND_ADJUST 2 | ||
| 123 | // #define SERIAL_DELAY 6 // micro sec | ||
| 124 | // #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 125 | // #define READ_WRITE_WIDTH_ADJUST 8 // cycles | ||
| 126 | #else | ||
| 127 | // ============ Standard setups ============ | ||
| 128 | |||
| 129 | #ifndef SELECT_SOFT_SERIAL_SPEED | ||
| 130 | #define SELECT_SOFT_SERIAL_SPEED 1 | ||
| 131 | // 0: about 189kbps | ||
| 132 | // 1: about 137kbps (default) | ||
| 133 | // 2: about 75kbps | ||
| 134 | // 3: about 39kbps | ||
| 135 | // 4: about 26kbps | ||
| 136 | // 5: about 20kbps | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #define TID_SEND_ADJUST 2 | ||
| 140 | |||
| 141 | #if SELECT_SOFT_SERIAL_SPEED == 0 | ||
| 142 | // Very High speed | ||
| 143 | #define SERIAL_DELAY 4 // micro sec | ||
| 144 | #define READ_WRITE_START_ADJUST 33 // cycles | ||
| 145 | #define READ_WRITE_WIDTH_ADJUST 6 // cycles | ||
| 146 | #elif SELECT_SOFT_SERIAL_SPEED == 1 | ||
| 147 | // High speed | ||
| 148 | #define SERIAL_DELAY 6 // micro sec | ||
| 149 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 150 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 151 | #elif SELECT_SOFT_SERIAL_SPEED == 2 | ||
| 152 | // Middle speed | ||
| 153 | #define SERIAL_DELAY 12 // micro sec | ||
| 154 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 155 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 156 | #elif SELECT_SOFT_SERIAL_SPEED == 3 | ||
| 157 | // Low speed | ||
| 158 | #define SERIAL_DELAY 24 // micro sec | ||
| 159 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 160 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 161 | #elif SELECT_SOFT_SERIAL_SPEED == 4 | ||
| 162 | // Very Low speed | ||
| 163 | #define SERIAL_DELAY 36 // micro sec | ||
| 164 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 165 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 166 | #elif SELECT_SOFT_SERIAL_SPEED == 5 | ||
| 167 | // Ultra Low speed | ||
| 168 | #define SERIAL_DELAY 48 // micro sec | ||
| 169 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 170 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 171 | #else | ||
| 172 | #error invalid SELECT_SOFT_SERIAL_SPEED value | ||
| 173 | #endif /* SELECT_SOFT_SERIAL_SPEED */ | ||
| 174 | #endif /* SERIAL_DELAY */ | ||
| 175 | |||
| 176 | #define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2) | ||
| 177 | #define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2) | ||
| 178 | |||
| 179 | #define SLAVE_INT_WIDTH_US 1 | ||
| 180 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 181 | #define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY | ||
| 182 | #else | ||
| 183 | #define SLAVE_INT_ACK_WIDTH_UNIT 2 | ||
| 184 | #define SLAVE_INT_ACK_WIDTH 4 | ||
| 185 | #endif | ||
| 186 | |||
| 187 | static SSTD_t *Transaction_table = NULL; | ||
| 188 | static uint8_t Transaction_table_size = 0; | ||
| 189 | |||
| 190 | inline static | ||
| 191 | void serial_delay(void) { | ||
| 192 | _delay_us(SERIAL_DELAY); | ||
| 193 | } | ||
| 194 | |||
| 195 | inline static | ||
| 196 | void serial_delay_half1(void) { | ||
| 197 | _delay_us(SERIAL_DELAY_HALF1); | ||
| 198 | } | ||
| 199 | |||
| 200 | inline static | ||
| 201 | void serial_delay_half2(void) { | ||
| 202 | _delay_us(SERIAL_DELAY_HALF2); | ||
| 203 | } | ||
| 204 | |||
| 205 | inline static void serial_output(void) ALWAYS_INLINE; | ||
| 206 | inline static | ||
| 207 | void serial_output(void) { | ||
| 208 | SERIAL_PIN_DDR |= SERIAL_PIN_MASK; | ||
| 209 | } | ||
| 210 | |||
| 211 | // make the serial pin an input with pull-up resistor | ||
| 212 | inline static void serial_input_with_pullup(void) ALWAYS_INLINE; | ||
| 213 | inline static | ||
| 214 | void serial_input_with_pullup(void) { | ||
| 215 | SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK; | ||
| 216 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | ||
| 217 | } | ||
| 218 | |||
| 219 | inline static | ||
| 220 | uint8_t serial_read_pin(void) { | ||
| 221 | return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK); | ||
| 222 | } | ||
| 223 | |||
| 224 | inline static void serial_low(void) ALWAYS_INLINE; | ||
| 225 | inline static | ||
| 226 | void serial_low(void) { | ||
| 227 | SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; | ||
| 228 | } | ||
| 229 | |||
| 230 | inline static void serial_high(void) ALWAYS_INLINE; | ||
| 231 | inline static | ||
| 232 | void serial_high(void) { | ||
| 233 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | ||
| 234 | } | ||
| 235 | |||
| 236 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) | ||
| 237 | { | ||
| 238 | Transaction_table = sstd_table; | ||
| 239 | Transaction_table_size = (uint8_t)sstd_table_size; | ||
| 240 | serial_output(); | ||
| 241 | serial_high(); | ||
| 242 | } | ||
| 243 | |||
| 244 | void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size) | ||
| 245 | { | ||
| 246 | Transaction_table = sstd_table; | ||
| 247 | Transaction_table_size = (uint8_t)sstd_table_size; | ||
| 248 | serial_input_with_pullup(); | ||
| 249 | |||
| 250 | // Enable INT0-INT3,INT6 | ||
| 251 | EIMSK |= EIMSK_BIT; | ||
| 252 | #if SERIAL_PIN_MASK == _BV(PE6) | ||
| 253 | // Trigger on falling edge of INT6 | ||
| 254 | EICRB &= EICRx_BIT; | ||
| 255 | #else | ||
| 256 | // Trigger on falling edge of INT0-INT3 | ||
| 257 | EICRA &= EICRx_BIT; | ||
| 258 | #endif | ||
| 259 | } | ||
| 260 | |||
| 261 | // Used by the sender to synchronize timing with the reciver. | ||
| 262 | static void sync_recv(void) NO_INLINE; | ||
| 263 | static | ||
| 264 | void sync_recv(void) { | ||
| 265 | for (uint8_t i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) { | ||
| 266 | } | ||
| 267 | // This shouldn't hang if the target disconnects because the | ||
| 268 | // serial line will float to high if the target does disconnect. | ||
| 269 | while (!serial_read_pin()); | ||
| 270 | } | ||
| 271 | |||
| 272 | // Used by the reciver to send a synchronization signal to the sender. | ||
| 273 | static void sync_send(void)NO_INLINE; | ||
| 274 | static | ||
| 275 | void sync_send(void) { | ||
| 276 | serial_low(); | ||
| 277 | serial_delay(); | ||
| 278 | serial_high(); | ||
| 279 | } | ||
| 280 | |||
| 281 | // Reads a byte from the serial line | ||
| 282 | static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) NO_INLINE; | ||
| 283 | static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) { | ||
| 284 | uint8_t byte, i, p, pb; | ||
| 285 | |||
| 286 | _delay_sub_us(READ_WRITE_START_ADJUST); | ||
| 287 | for( i = 0, byte = 0, p = PARITY; i < bit; i++ ) { | ||
| 288 | serial_delay_half1(); // read the middle of pulses | ||
| 289 | if( serial_read_pin() ) { | ||
| 290 | byte = (byte << 1) | 1; p ^= 1; | ||
| 291 | } else { | ||
| 292 | byte = (byte << 1) | 0; p ^= 0; | ||
| 293 | } | ||
| 294 | _delay_sub_us(READ_WRITE_WIDTH_ADJUST); | ||
| 295 | serial_delay_half2(); | ||
| 296 | } | ||
| 297 | /* recive parity bit */ | ||
| 298 | serial_delay_half1(); // read the middle of pulses | ||
| 299 | pb = serial_read_pin(); | ||
| 300 | _delay_sub_us(READ_WRITE_WIDTH_ADJUST); | ||
| 301 | serial_delay_half2(); | ||
| 302 | |||
| 303 | *pterrcount += (p != pb)? 1 : 0; | ||
| 304 | |||
| 305 | return byte; | ||
| 306 | } | ||
| 307 | |||
| 308 | // Sends a byte with MSB ordering | ||
| 309 | void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE; | ||
| 310 | void serial_write_chunk(uint8_t data, uint8_t bit) { | ||
| 311 | uint8_t b, p; | ||
| 312 | for( p = PARITY, b = 1<<(bit-1); b ; b >>= 1) { | ||
| 313 | if(data & b) { | ||
| 314 | serial_high(); p ^= 1; | ||
| 315 | } else { | ||
| 316 | serial_low(); p ^= 0; | ||
| 317 | } | ||
| 318 | serial_delay(); | ||
| 319 | } | ||
| 320 | /* send parity bit */ | ||
| 321 | if(p & 1) { serial_high(); } | ||
| 322 | else { serial_low(); } | ||
| 323 | serial_delay(); | ||
| 324 | |||
| 325 | serial_low(); // sync_send() / senc_recv() need raise edge | ||
| 326 | } | ||
| 327 | |||
| 328 | static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE; | ||
| 329 | static | ||
| 330 | void serial_send_packet(uint8_t *buffer, uint8_t size) { | ||
| 331 | for (uint8_t i = 0; i < size; ++i) { | ||
| 332 | uint8_t data; | ||
| 333 | data = buffer[i]; | ||
| 334 | sync_send(); | ||
| 335 | serial_write_chunk(data,8); | ||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) NO_INLINE; | ||
| 340 | static | ||
| 341 | uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) { | ||
| 342 | uint8_t pecount = 0; | ||
| 343 | for (uint8_t i = 0; i < size; ++i) { | ||
| 344 | uint8_t data; | ||
| 345 | sync_recv(); | ||
| 346 | data = serial_read_chunk(&pecount, 8); | ||
| 347 | buffer[i] = data; | ||
| 348 | } | ||
| 349 | return pecount == 0; | ||
| 350 | } | ||
| 351 | |||
| 352 | inline static | ||
| 353 | void change_sender2reciver(void) { | ||
| 354 | sync_send(); //0 | ||
| 355 | serial_delay_half1(); //1 | ||
| 356 | serial_low(); //2 | ||
| 357 | serial_input_with_pullup(); //2 | ||
| 358 | serial_delay_half1(); //3 | ||
| 359 | } | ||
| 360 | |||
| 361 | inline static | ||
| 362 | void change_reciver2sender(void) { | ||
| 363 | sync_recv(); //0 | ||
| 364 | serial_delay(); //1 | ||
| 365 | serial_low(); //3 | ||
| 366 | serial_output(); //3 | ||
| 367 | serial_delay_half1(); //4 | ||
| 368 | } | ||
| 369 | |||
| 370 | static inline uint8_t nibble_bits_count(uint8_t bits) | ||
| 371 | { | ||
| 372 | bits = (bits & 0x5) + (bits >> 1 & 0x5); | ||
| 373 | bits = (bits & 0x3) + (bits >> 2 & 0x3); | ||
| 374 | return bits; | ||
| 375 | } | ||
| 376 | |||
| 377 | // interrupt handle to be used by the target device | ||
| 378 | ISR(SERIAL_PIN_INTERRUPT) { | ||
| 379 | |||
| 380 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 381 | serial_low(); | ||
| 382 | serial_output(); | ||
| 383 | SSTD_t *trans = Transaction_table; | ||
| 384 | #else | ||
| 385 | // recive transaction table index | ||
| 386 | uint8_t tid, bits; | ||
| 387 | uint8_t pecount = 0; | ||
| 388 | sync_recv(); | ||
| 389 | bits = serial_read_chunk(&pecount,7); | ||
| 390 | tid = bits>>3; | ||
| 391 | bits = (bits&7) != nibble_bits_count(tid); | ||
| 392 | if( bits || pecount> 0 || tid > Transaction_table_size ) { | ||
| 393 | return; | ||
| 394 | } | ||
| 395 | serial_delay_half1(); | ||
| 396 | |||
| 397 | serial_high(); // response step1 low->high | ||
| 398 | serial_output(); | ||
| 399 | _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT*SLAVE_INT_ACK_WIDTH); | ||
| 400 | SSTD_t *trans = &Transaction_table[tid]; | ||
| 401 | serial_low(); // response step2 ack high->low | ||
| 402 | #endif | ||
| 403 | |||
| 404 | // target send phase | ||
| 405 | if( trans->target2initiator_buffer_size > 0 ) | ||
| 406 | serial_send_packet((uint8_t *)trans->target2initiator_buffer, | ||
| 407 | trans->target2initiator_buffer_size); | ||
| 408 | // target switch to input | ||
| 409 | change_sender2reciver(); | ||
| 410 | |||
| 411 | // target recive phase | ||
| 412 | if( trans->initiator2target_buffer_size > 0 ) { | ||
| 413 | if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer, | ||
| 414 | trans->initiator2target_buffer_size) ) { | ||
| 415 | *trans->status = TRANSACTION_ACCEPTED; | ||
| 416 | } else { | ||
| 417 | *trans->status = TRANSACTION_DATA_ERROR; | ||
| 418 | } | ||
| 419 | } else { | ||
| 420 | *trans->status = TRANSACTION_ACCEPTED; | ||
| 421 | } | ||
| 422 | |||
| 423 | sync_recv(); //weit initiator output to high | ||
| 424 | } | ||
| 425 | |||
| 426 | ///////// | ||
| 427 | // start transaction by initiator | ||
| 428 | // | ||
| 429 | // int soft_serial_transaction(int sstd_index) | ||
| 430 | // | ||
| 431 | // Returns: | ||
| 432 | // TRANSACTION_END | ||
| 433 | // TRANSACTION_NO_RESPONSE | ||
| 434 | // TRANSACTION_DATA_ERROR | ||
| 435 | // this code is very time dependent, so we need to disable interrupts | ||
| 436 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 437 | int soft_serial_transaction(void) { | ||
| 438 | SSTD_t *trans = Transaction_table; | ||
| 439 | #else | ||
| 440 | int soft_serial_transaction(int sstd_index) { | ||
| 441 | if( sstd_index > Transaction_table_size ) | ||
| 442 | return TRANSACTION_TYPE_ERROR; | ||
| 443 | SSTD_t *trans = &Transaction_table[sstd_index]; | ||
| 444 | #endif | ||
| 445 | cli(); | ||
| 446 | |||
| 447 | // signal to the target that we want to start a transaction | ||
| 448 | serial_output(); | ||
| 449 | serial_low(); | ||
| 450 | _delay_us(SLAVE_INT_WIDTH_US); | ||
| 451 | |||
| 452 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 453 | // wait for the target response | ||
| 454 | serial_input_with_pullup(); | ||
| 455 | _delay_us(SLAVE_INT_RESPONSE_TIME); | ||
| 456 | |||
| 457 | // check if the target is present | ||
| 458 | if (serial_read_pin()) { | ||
| 459 | // target failed to pull the line low, assume not present | ||
| 460 | serial_output(); | ||
| 461 | serial_high(); | ||
| 462 | *trans->status = TRANSACTION_NO_RESPONSE; | ||
| 463 | sei(); | ||
| 464 | return TRANSACTION_NO_RESPONSE; | ||
| 465 | } | ||
| 466 | |||
| 467 | #else | ||
| 468 | // send transaction table index | ||
| 469 | int tid = (sstd_index<<3) | (7 & nibble_bits_count(sstd_index)); | ||
| 470 | sync_send(); | ||
| 471 | _delay_sub_us(TID_SEND_ADJUST); | ||
| 472 | serial_write_chunk(tid, 7); | ||
| 473 | serial_delay_half1(); | ||
| 474 | |||
| 475 | // wait for the target response (step1 low->high) | ||
| 476 | serial_input_with_pullup(); | ||
| 477 | while( !serial_read_pin() ) { | ||
| 478 | _delay_sub_us(2); | ||
| 479 | } | ||
| 480 | |||
| 481 | // check if the target is present (step2 high->low) | ||
| 482 | for( int i = 0; serial_read_pin(); i++ ) { | ||
| 483 | if (i > SLAVE_INT_ACK_WIDTH + 1) { | ||
| 484 | // slave failed to pull the line low, assume not present | ||
| 485 | serial_output(); | ||
| 486 | serial_high(); | ||
| 487 | *trans->status = TRANSACTION_NO_RESPONSE; | ||
| 488 | sei(); | ||
| 489 | return TRANSACTION_NO_RESPONSE; | ||
| 490 | } | ||
| 491 | _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT); | ||
| 492 | } | ||
| 493 | #endif | ||
| 494 | |||
| 495 | // initiator recive phase | ||
| 496 | // if the target is present syncronize with it | ||
| 497 | if( trans->target2initiator_buffer_size > 0 ) { | ||
| 498 | if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer, | ||
| 499 | trans->target2initiator_buffer_size) ) { | ||
| 500 | serial_output(); | ||
| 501 | serial_high(); | ||
| 502 | *trans->status = TRANSACTION_DATA_ERROR; | ||
| 503 | sei(); | ||
| 504 | return TRANSACTION_DATA_ERROR; | ||
| 505 | } | ||
| 506 | } | ||
| 507 | |||
| 508 | // initiator switch to output | ||
| 509 | change_reciver2sender(); | ||
| 510 | |||
| 511 | // initiator send phase | ||
| 512 | if( trans->initiator2target_buffer_size > 0 ) { | ||
| 513 | serial_send_packet((uint8_t *)trans->initiator2target_buffer, | ||
| 514 | trans->initiator2target_buffer_size); | ||
| 515 | } | ||
| 516 | |||
| 517 | // always, release the line when not in use | ||
| 518 | sync_send(); | ||
| 519 | |||
| 520 | *trans->status = TRANSACTION_END; | ||
| 521 | sei(); | ||
| 522 | return TRANSACTION_END; | ||
| 523 | } | ||
| 524 | |||
| 525 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 526 | int soft_serial_get_and_clean_status(int sstd_index) { | ||
| 527 | SSTD_t *trans = &Transaction_table[sstd_index]; | ||
| 528 | cli(); | ||
| 529 | int retval = *trans->status; | ||
| 530 | *trans->status = 0;; | ||
| 531 | sei(); | ||
| 532 | return retval; | ||
| 533 | } | ||
| 534 | #endif | ||
| 535 | |||
| 536 | #endif | ||
| 537 | |||
| 538 | // Helix serial.c history | ||
| 539 | // 2018-1-29 fork from let's split (#2308) | ||
| 540 | // 2018-6-28 bug fix master to slave comm (#3255) | ||
| 541 | // 2018-8-11 improvements (#3608) | ||
| 542 | // 2018-10-21 fix serial and RGB animation conflict (#4191) | ||
diff --git a/keyboards/zinc/serial.h b/keyboards/zinc/serial.h new file mode 100644 index 000000000..7e0c0847a --- /dev/null +++ b/keyboards/zinc/serial.h | |||
| @@ -0,0 +1,84 @@ | |||
| 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 Simple API (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 flexible API (using multi-type transaction function) | ||
| 24 | // #define SERIAL_USE_MULTI_TRANSACTION | ||
| 25 | // | ||
| 26 | // ///////////////////////////////////////////////////////////////// | ||
| 27 | |||
| 28 | |||
| 29 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 30 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) */ | ||
| 31 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 | ||
| 32 | extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; | ||
| 33 | #endif | ||
| 34 | #if SERIAL_MASTER_BUFFER_LENGTH > 0 | ||
| 35 | extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; | ||
| 36 | #endif | ||
| 37 | |||
| 38 | void serial_master_init(void); | ||
| 39 | void serial_slave_init(void); | ||
| 40 | int serial_update_buffers(void); | ||
| 41 | |||
| 42 | #endif // USE Simple API | ||
| 43 | |||
| 44 | // Soft Serial Transaction Descriptor | ||
| 45 | typedef struct _SSTD_t { | ||
| 46 | uint8_t *status; | ||
| 47 | uint8_t initiator2target_buffer_size; | ||
| 48 | uint8_t *initiator2target_buffer; | ||
| 49 | uint8_t target2initiator_buffer_size; | ||
| 50 | uint8_t *target2initiator_buffer; | ||
| 51 | } SSTD_t; | ||
| 52 | #define TID_LIMIT( table ) (sizeof(table) / sizeof(SSTD_t)) | ||
| 53 | |||
| 54 | // initiator is transaction start side | ||
| 55 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size); | ||
| 56 | // target is interrupt accept side | ||
| 57 | void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size); | ||
| 58 | |||
| 59 | // initiator resullt | ||
| 60 | #define TRANSACTION_END 0 | ||
| 61 | #define TRANSACTION_NO_RESPONSE 0x1 | ||
| 62 | #define TRANSACTION_DATA_ERROR 0x2 | ||
| 63 | #define TRANSACTION_TYPE_ERROR 0x4 | ||
| 64 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 65 | int soft_serial_transaction(void); | ||
| 66 | #else | ||
| 67 | int soft_serial_transaction(int sstd_index); | ||
| 68 | #endif | ||
| 69 | |||
| 70 | // target status | ||
| 71 | // *SSTD_t.status has | ||
| 72 | // initiator: | ||
| 73 | // TRANSACTION_END | ||
| 74 | // or TRANSACTION_NO_RESPONSE | ||
| 75 | // or TRANSACTION_DATA_ERROR | ||
| 76 | // target: | ||
| 77 | // TRANSACTION_DATA_ERROR | ||
| 78 | // or TRANSACTION_ACCEPTED | ||
| 79 | #define TRANSACTION_ACCEPTED 0x8 | ||
| 80 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 81 | int soft_serial_get_and_clean_status(int sstd_index); | ||
| 82 | #endif | ||
| 83 | |||
| 84 | #endif /* SOFT_SERIAL_H */ | ||
diff --git a/keyboards/zinc/zinc.c b/keyboards/zinc/zinc.c new file mode 100644 index 000000000..139919d5a --- /dev/null +++ b/keyboards/zinc/zinc.c | |||
| @@ -0,0 +1 @@ | |||
| #include "zinc.h" | |||
diff --git a/keyboards/zinc/zinc.h b/keyboards/zinc/zinc.h new file mode 100644 index 000000000..87d889da0 --- /dev/null +++ b/keyboards/zinc/zinc.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #ifndef ZINC_H | ||
| 2 | #define ZINC_H | ||
| 3 | |||
| 4 | #ifdef KEYBOARD_zinc_reva | ||
| 5 | #include "reva.h" | ||
| 6 | #endif | ||
| 7 | #ifdef KEYBOARD_zinc_rev1 | ||
| 8 | #include "rev1.h" | ||
| 9 | #endif | ||
| 10 | |||
| 11 | |||
| 12 | #include "quantum.h" | ||
| 13 | |||
| 14 | #endif | ||
