aboutsummaryrefslogtreecommitdiff
path: root/keyboards/mint60
diff options
context:
space:
mode:
authoreucalyn <hi.eucalyn@gmail.com>2018-08-20 05:26:42 +0900
committerDrashna Jaelre <drashna@live.com>2018-08-19 13:26:42 -0700
commit99da48c72b90e11e5ef945263530c6f8746848fd (patch)
tree9b70da4e151b00283553651c10cd2ae01067d967 /keyboards/mint60
parent4cc1edbb67beecd0081fb84d3b5365e55d1a41e1 (diff)
downloadqmk_firmware-99da48c72b90e11e5ef945263530c6f8746848fd.tar.gz
qmk_firmware-99da48c72b90e11e5ef945263530c6f8746848fd.zip
Keyboard: add mint60 keyboard (#3543)
* add mint60 * change source by reviews
Diffstat (limited to 'keyboards/mint60')
-rw-r--r--keyboards/mint60/config.h235
-rw-r--r--keyboards/mint60/i2c.c162
-rw-r--r--keyboards/mint60/i2c.h49
-rw-r--r--keyboards/mint60/info.json0
-rw-r--r--keyboards/mint60/keymaps/default/config.h23
-rw-r--r--keyboards/mint60/keymaps/default/keymap.c104
-rw-r--r--keyboards/mint60/keymaps/default/readme.md1
-rw-r--r--keyboards/mint60/keymaps/eucalyn/config.h23
-rw-r--r--keyboards/mint60/keymaps/eucalyn/keymap.c104
-rw-r--r--keyboards/mint60/keymaps/eucalyn/readme.md3
-rw-r--r--keyboards/mint60/matrix.c349
-rw-r--r--keyboards/mint60/mint60.c43
-rw-r--r--keyboards/mint60/mint60.h59
-rw-r--r--keyboards/mint60/readme.md15
-rw-r--r--keyboards/mint60/rules.mk78
-rw-r--r--keyboards/mint60/serial.c295
-rw-r--r--keyboards/mint60/serial.h27
-rw-r--r--keyboards/mint60/serial_config.h16
-rw-r--r--keyboards/mint60/split_util.c70
-rw-r--r--keyboards/mint60/split_util.h19
20 files changed, 1675 insertions, 0 deletions
diff --git a/keyboards/mint60/config.h b/keyboards/mint60/config.h
new file mode 100644
index 000000000..37b69e93a
--- /dev/null
+++ b/keyboards/mint60/config.h
@@ -0,0 +1,235 @@
1/*
2Copyright 2018 Eucalyn
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#pragma once
19
20#include "config_common.h"
21#include <serial_config.h>
22
23
24/* USB Device descriptor parameter */
25#define VENDOR_ID 0xFEED
26#define PRODUCT_ID 0x0000
27#define DEVICE_VER 0x0001
28#define MANUFACTURER Eucalyn
29#define PRODUCT Mint60
30#define DESCRIPTION A row staggered split keyboard
31
32#define PREVENT_STUCK_MODIFIERS
33#define TAPPING_FORCE_HOLD
34#define TAPPING_TERM 100
35
36/* key matrix size */
37#define MATRIX_ROWS 10
38#define MATRIX_COLS 8
39
40/*
41 * Keyboard Matrix Assignments
42 *
43 * Change this to how you wired your keyboard
44 * COLS: AVR pins used for columns, left to right
45 * ROWS: AVR pins used for rows, top to bottom
46 * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
47 * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
48 *
49*/
50#define MATRIX_ROW_PINS { C6, D7, E6, B4, B5 }
51#define MATRIX_COL_PINS { D4, B3, B1, F7, B2, B6, F6, F5 }
52#define UNUSED_PINS
53
54/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
55#define DIODE_DIRECTION COL2ROW
56
57// #define BACKLIGHT_PIN B7
58// #define BACKLIGHT_BREATHING
59// #define BACKLIGHT_LEVELS 3
60
61
62/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
63#define DEBOUNCING_DELAY 5
64
65/* define if matrix has ghost (lacks anti-ghosting diodes) */
66//#define MATRIX_HAS_GHOST
67
68/* number of backlight levels */
69
70/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
71#define LOCKING_SUPPORT_ENABLE
72/* Locking resynchronize hack */
73#define LOCKING_RESYNC_ENABLE
74
75/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
76 * This is userful for the Windows task manager shortcut (ctrl+shift+esc).
77 */
78// #define GRAVE_ESC_CTRL_OVERRIDE
79
80/*
81 * Force NKRO
82 *
83 * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
84 * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
85 * makefile for this to work.)
86 *
87 * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
88 * until the next keyboard reset.
89 *
90 * NKRO may prevent your keystrokes from being detected in the BIOS, but it is
91 * fully operational during normal computer usage.
92 *
93 * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
94 * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
95 * bootmagic, NKRO mode will always be enabled until it is toggled again during a
96 * power-up.
97 *
98 */
99//#define FORCE_NKRO
100
101/*
102 * Magic Key Options
103 *
104 * Magic keys are hotkey commands that allow control over firmware functions of
105 * the keyboard. They are best used in combination with the HID Listen program,
106 * found here: https://www.pjrc.com/teensy/hid_listen.html
107 *
108 * The options below allow the magic key functionality to be changed. This is
109 * useful if your keyboard/keypad is missing keys and you want magic key support.
110 *
111 */
112
113/* key combination for magic key command */
114#define IS_COMMAND() ( \
115 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
116)
117
118/* control how magic key switches layers */
119//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true
120//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true
121//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false
122
123/* override magic key keymap */
124//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
125//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
126//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
127//#define MAGIC_KEY_HELP1 H
128//#define MAGIC_KEY_HELP2 SLASH
129//#define MAGIC_KEY_DEBUG D
130//#define MAGIC_KEY_DEBUG_MATRIX X
131//#define MAGIC_KEY_DEBUG_KBD K
132//#define MAGIC_KEY_DEBUG_MOUSE M
133//#define MAGIC_KEY_VERSION V
134//#define MAGIC_KEY_STATUS S
135//#define MAGIC_KEY_CONSOLE C
136//#define MAGIC_KEY_LAYER0_ALT1 ESC
137//#define MAGIC_KEY_LAYER0_ALT2 GRAVE
138//#define MAGIC_KEY_LAYER0 0
139//#define MAGIC_KEY_LAYER1 1
140//#define MAGIC_KEY_LAYER2 2
141//#define MAGIC_KEY_LAYER3 3
142//#define MAGIC_KEY_LAYER4 4
143//#define MAGIC_KEY_LAYER5 5
144//#define MAGIC_KEY_LAYER6 6
145//#define MAGIC_KEY_LAYER7 7
146//#define MAGIC_KEY_LAYER8 8
147//#define MAGIC_KEY_LAYER9 9
148//#define MAGIC_KEY_BOOTLOADER PAUSE
149//#define MAGIC_KEY_LOCK CAPS
150//#define MAGIC_KEY_EEPROM E
151//#define MAGIC_KEY_NKRO N
152//#define MAGIC_KEY_SLEEP_LED Z
153
154/* ws2812 RGB LED */
155#define RGB_DI_PIN D3
156#define RGBLIGHT_TIMER
157#define RGBLED_NUM 8
158#define ws2812_PORTREG PORTD
159#define ws2812_DDRREG DDRD
160
161#define RGBLIGHT_HUE_STEP 10
162#define RGBLIGHT_SAT_STEP 17
163
164#define RGBLIGHT_ANIMATIONS
165
166
167
168/*
169 * Feature disable options
170 * These options are also useful to firmware size reduction.
171 */
172
173/* disable debug print */
174//#define NO_DEBUG
175
176/* disable print */
177//#define NO_PRINT
178
179/* disable action features */
180//#define NO_ACTION_LAYER
181//#define NO_ACTION_TAPPING
182//#define NO_ACTION_ONESHOT
183//#define NO_ACTION_MACRO
184//#define NO_ACTION_FUNCTION
185
186/*
187 * MIDI options
188 */
189
190/* Prevent use of disabled MIDI features in the keymap */
191//#define MIDI_ENABLE_STRICT 1
192
193/* enable basic MIDI features:
194 - MIDI notes can be sent when in Music mode is on
195*/
196//#define MIDI_BASIC
197
198/* enable advanced MIDI features:
199 - MIDI notes can be added to the keymap
200 - Octave shift and transpose
201 - Virtual sustain, portamento, and modulation wheel
202 - etc.
203*/
204//#define MIDI_ADVANCED
205
206/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
207//#define MIDI_TONE_KEYCODE_OCTAVES 1
208
209/*
210 * HD44780 LCD Display Configuration
211 */
212/*
213#define LCD_LINES 2 //< number of visible lines of the display
214#define LCD_DISP_LENGTH 16 //< visibles characters per line of the display
215
216#define LCD_IO_MODE 1 //< 0: memory mapped mode, 1: IO port mode
217
218#if LCD_IO_MODE
219#define LCD_PORT PORTB //< port for the LCD lines
220#define LCD_DATA0_PORT LCD_PORT //< port for 4bit data bit 0
221#define LCD_DATA1_PORT LCD_PORT //< port for 4bit data bit 1
222#define LCD_DATA2_PORT LCD_PORT //< port for 4bit data bit 2
223#define LCD_DATA3_PORT LCD_PORT //< port for 4bit data bit 3
224#define LCD_DATA0_PIN 4 //< pin for 4bit data bit 0
225#define LCD_DATA1_PIN 5 //< pin for 4bit data bit 1
226#define LCD_DATA2_PIN 6 //< pin for 4bit data bit 2
227#define LCD_DATA3_PIN 7 //< pin for 4bit data bit 3
228#define LCD_RS_PORT LCD_PORT //< port for RS line
229#define LCD_RS_PIN 3 //< pin for RS line
230#define LCD_RW_PORT LCD_PORT //< port for RW line
231#define LCD_RW_PIN 2 //< pin for RW line
232#define LCD_E_PORT LCD_PORT //< port for Enable line
233#define LCD_E_PIN 1 //< pin for Enable line
234#endif
235*/
diff --git a/keyboards/mint60/i2c.c b/keyboards/mint60/i2c.c
new file mode 100644
index 000000000..4bee5c639
--- /dev/null
+++ b/keyboards/mint60/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
21volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
22
23static volatile uint8_t slave_buffer_pos;
24static volatile bool slave_has_register_set = false;
25
26// Wait for an i2c operation to finish
27inline static
28void 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)
38void 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
50uint8_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.
72void 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
83uint8_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
96uint8_t i2c_master_read(int ack) {
97 TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA);
98
99 i2c_delay();
100 return TWDR;
101}
102
103void i2c_reset_state(void) {
104 TWCR = 0;
105}
106
107void 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
116ISR(TWI_vect);
117
118ISR(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/mint60/i2c.h b/keyboards/mint60/i2c.h
new file mode 100644
index 000000000..47cf6bd1b
--- /dev/null
+++ b/keyboards/mint60/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
21extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
22
23void i2c_master_init(void);
24uint8_t i2c_master_start(uint8_t address);
25void i2c_master_stop(void);
26uint8_t i2c_master_write(uint8_t data);
27uint8_t i2c_master_read(int);
28void i2c_reset_state(void);
29void i2c_slave_init(uint8_t address);
30
31
32static inline unsigned char i2c_start_read(unsigned char addr) {
33 return i2c_master_start((addr << 1) | I2C_READ);
34}
35
36static inline unsigned char i2c_start_write(unsigned char addr) {
37 return i2c_master_start((addr << 1) | I2C_WRITE);
38}
39
40// from SSD1306 scrips
41extern unsigned char i2c_rep_start(unsigned char addr);
42extern void i2c_start_wait(unsigned char addr);
43extern unsigned char i2c_readAck(void);
44extern unsigned char i2c_readNak(void);
45extern 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/mint60/info.json b/keyboards/mint60/info.json
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/keyboards/mint60/info.json
diff --git a/keyboards/mint60/keymaps/default/config.h b/keyboards/mint60/keymaps/default/config.h
new file mode 100644
index 000000000..0195c61df
--- /dev/null
+++ b/keyboards/mint60/keymaps/default/config.h
@@ -0,0 +1,23 @@
1/* Copyright 2018 Eucalyn
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19/* Use I2C or Serial, not both */
20#define USE_SERIAL
21// #define USE_I2C
22
23// #define MASTER_RIGHT
diff --git a/keyboards/mint60/keymaps/default/keymap.c b/keyboards/mint60/keymaps/default/keymap.c
new file mode 100644
index 000000000..42c61ffaa
--- /dev/null
+++ b/keyboards/mint60/keymaps/default/keymap.c
@@ -0,0 +1,104 @@
1/* Copyright 2018 Eucalyn
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include QMK_KEYBOARD_H
17#ifdef PROTOCOL_LUFA
18#include "lufa.h"
19#include "split_util.h"
20#endif
21
22extern keymap_config_t keymap_config;
23
24#ifdef RGBLIGHT_ENABLE
25//Following line allows macro to read current RGB settings
26extern rgblight_config_t rgblight_config;
27#endif
28
29// Fillers to make layering more clear
30#define _______ KC_TRNS
31#define XXXXXXX KC_NO
32
33enum custom_keycodes {
34 RGBRST
35};
36
37
38const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
39 [0] = LAYOUT( \
40 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \
41 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, \
42 KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
43 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, MO(1), \
44 KC_ESC, KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_BSPC, KC_ENT, LALT(KC_GRV), KC_LEFT,KC_DOWN,KC_RGHT \
45 ),
46 [1] = LAYOUT( \
47 KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, \
48 RGB_TOG, RGBRST, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
49 XXXXXXX, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
50 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, KC_PGUP, _______, \
51 XXXXXXX, _______, _______, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_HOME, KC_PGDN, KC_END \
52 )
53};
54
55const uint16_t PROGMEM fn_actions[] = {
56
57};
58
59// define variables for reactive RGB
60bool TOG_STATUS = false;
61int RGB_current_mode;
62
63
64const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
65{
66 // MACRODOWN only works in this function
67 switch(id) {
68 case 0:
69 if (record->event.pressed) {
70 register_code(KC_RSFT);
71 } else {
72 unregister_code(KC_RSFT);
73 }
74 break;
75 }
76 return MACRO_NONE;
77};
78
79bool process_record_user(uint16_t keycode, keyrecord_t *record) {
80 switch (keycode) {
81 case RGBRST:
82 #ifdef RGBLIGHT_ENABLE
83 if (record->event.pressed) {
84 eeconfig_update_rgblight_default();
85 rgblight_enable();
86 RGB_current_mode = rgblight_config.mode;
87 }
88 #endif
89 break;
90 }
91 return true;
92}
93
94void matrix_init_user(void) {
95
96}
97
98void matrix_scan_user(void) {
99
100}
101
102void led_set_user(uint8_t usb_led) {
103
104}
diff --git a/keyboards/mint60/keymaps/default/readme.md b/keyboards/mint60/keymaps/default/readme.md
new file mode 100644
index 000000000..37dec75a6
--- /dev/null
+++ b/keyboards/mint60/keymaps/default/readme.md
@@ -0,0 +1 @@
# The default keymap for Mint60
diff --git a/keyboards/mint60/keymaps/eucalyn/config.h b/keyboards/mint60/keymaps/eucalyn/config.h
new file mode 100644
index 000000000..0195c61df
--- /dev/null
+++ b/keyboards/mint60/keymaps/eucalyn/config.h
@@ -0,0 +1,23 @@
1/* Copyright 2018 Eucalyn
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19/* Use I2C or Serial, not both */
20#define USE_SERIAL
21// #define USE_I2C
22
23// #define MASTER_RIGHT
diff --git a/keyboards/mint60/keymaps/eucalyn/keymap.c b/keyboards/mint60/keymaps/eucalyn/keymap.c
new file mode 100644
index 000000000..09b30730a
--- /dev/null
+++ b/keyboards/mint60/keymaps/eucalyn/keymap.c
@@ -0,0 +1,104 @@
1/* Copyright 2018 Eucalyn
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include QMK_KEYBOARD_H
17#ifdef PROTOCOL_LUFA
18#include "lufa.h"
19#include "split_util.h"
20#endif
21
22extern keymap_config_t keymap_config;
23
24#ifdef RGBLIGHT_ENABLE
25//Following line allows macro to read current RGB settings
26extern rgblight_config_t rgblight_config;
27#endif
28
29// Fillers to make layering more clear
30#define _______ KC_TRNS
31#define XXXXXXX KC_NO
32
33enum custom_keycodes {
34 RGBRST
35};
36
37
38const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
39 [0] = LAYOUT( \
40 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \
41 KC_TAB, KC_Q, KC_W, KC_COMM, KC_DOT, KC_SCLN, KC_M, KC_R, KC_D, KC_Y, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, \
42 KC_CAPS, KC_A, KC_O, KC_E, KC_I, KC_U, KC_G, KC_T, KC_K, KC_S, KC_N, KC_QUOT, KC_ENT, \
43 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_F, KC_B, KC_H, KC_J, KC_L, KC_SLSH, KC_RSFT, KC_UP, MO(1), \
44 KC_ESC, KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_BSPC, KC_ENT, LALT(KC_GRV), KC_LEFT,KC_DOWN,KC_RGHT \
45 ),
46 [1] = LAYOUT( \
47 KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, \
48 RGB_TOG, RGBRST, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
49 XXXXXXX, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
50 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, KC_PGUP, _______, \
51 XXXXXXX, _______, _______, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_HOME, KC_PGDN, KC_END \
52 )
53};
54
55const uint16_t PROGMEM fn_actions[] = {
56
57};
58
59// define variables for reactive RGB
60bool TOG_STATUS = false;
61int RGB_current_mode;
62
63
64const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
65{
66 // MACRODOWN only works in this function
67 switch(id) {
68 case 0:
69 if (record->event.pressed) {
70 register_code(KC_RSFT);
71 } else {
72 unregister_code(KC_RSFT);
73 }
74 break;
75 }
76 return MACRO_NONE;
77};
78
79bool process_record_user(uint16_t keycode, keyrecord_t *record) {
80 switch (keycode) {
81 case RGBRST:
82 #ifdef RGBLIGHT_ENABLE
83 if (record->event.pressed) {
84 eeconfig_update_rgblight_default();
85 rgblight_enable();
86 RGB_current_mode = rgblight_config.mode;
87 }
88 #endif
89 break;
90 }
91 return true;
92}
93
94void matrix_init_user(void) {
95
96}
97
98void matrix_scan_user(void) {
99
100}
101
102void led_set_user(uint8_t usb_led) {
103
104}
diff --git a/keyboards/mint60/keymaps/eucalyn/readme.md b/keyboards/mint60/keymaps/eucalyn/readme.md
new file mode 100644
index 000000000..1478b951f
--- /dev/null
+++ b/keyboards/mint60/keymaps/eucalyn/readme.md
@@ -0,0 +1,3 @@
1# The Eucalyn keymap for Mint60
2
3It use "Eucalyn" Kemboard Layout.
diff --git a/keyboards/mint60/matrix.c b/keyboards/mint60/matrix.c
new file mode 100644
index 000000000..6d8878332
--- /dev/null
+++ b/keyboards/mint60/matrix.c
@@ -0,0 +1,349 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * scan matrix
20 */
21#include <stdint.h>
22#include <stdbool.h>
23#include <avr/io.h>
24#include <avr/wdt.h>
25#include <avr/interrupt.h>
26#include <util/delay.h>
27#include "print.h"
28#include "debug.h"
29#include "util.h"
30#include "matrix.h"
31#include "split_util.h"
32#include "pro_micro.h"
33
34#ifdef USE_I2C
35# include "i2c.h"
36#else // USE_SERIAL
37# include "serial.h"
38#endif
39
40#ifndef DEBOUNCE
41# define DEBOUNCE 5
42#endif
43
44#define ERROR_DISCONNECT_COUNT 5
45
46static uint8_t debouncing = DEBOUNCE;
47static const int ROWS_PER_HAND = MATRIX_ROWS/2;
48static uint8_t error_count = 0;
49uint8_t is_master = 0 ;
50
51static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
52static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
53
54/* matrix state(1:on, 0:off) */
55static matrix_row_t matrix[MATRIX_ROWS];
56static matrix_row_t matrix_debouncing[MATRIX_ROWS];
57
58static matrix_row_t read_cols(void);
59static void init_cols(void);
60static void unselect_rows(void);
61static void select_row(uint8_t row);
62static uint8_t matrix_master_scan(void);
63
64
65__attribute__ ((weak))
66void matrix_init_kb(void) {
67 matrix_init_user();
68}
69
70__attribute__ ((weak))
71void matrix_scan_kb(void) {
72 matrix_scan_user();
73}
74
75__attribute__ ((weak))
76void matrix_init_user(void) {
77}
78
79__attribute__ ((weak))
80void matrix_scan_user(void) {
81}
82
83inline
84uint8_t matrix_rows(void)
85{
86 return MATRIX_ROWS;
87}
88
89inline
90uint8_t matrix_cols(void)
91{
92 return MATRIX_COLS;
93}
94
95void matrix_init(void)
96{
97 debug_enable = true;
98 debug_matrix = true;
99 debug_mouse = true;
100 // initialize row and col
101 unselect_rows();
102 init_cols();
103
104 TX_RX_LED_INIT;
105
106 // initialize matrix state: all keys off
107 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
108 matrix[i] = 0;
109 matrix_debouncing[i] = 0;
110 }
111
112 is_master = has_usb();
113
114 matrix_init_quantum();
115}
116
117uint8_t _matrix_scan(void)
118{
119 // Right hand is stored after the left in the matirx so, we need to offset it
120 int offset = isLeftHand ? 0 : (ROWS_PER_HAND);
121
122 for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
123 select_row(i);
124 _delay_us(30); // without this wait read unstable value.
125 matrix_row_t cols = read_cols();
126 if (matrix_debouncing[i+offset] != cols) {
127 matrix_debouncing[i+offset] = cols;
128 debouncing = DEBOUNCE;
129 }
130 unselect_rows();
131 }
132
133 if (debouncing) {
134 if (--debouncing) {
135 _delay_ms(1);
136 } else {
137 for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
138 matrix[i+offset] = matrix_debouncing[i+offset];
139 }
140 }
141 }
142
143 return 1;
144}
145
146#ifdef USE_I2C
147
148// Get rows from other half over i2c
149int i2c_transaction(void) {
150 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
151
152 int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
153 if (err) goto i2c_error;
154
155 // start of matrix stored at 0x00
156 err = i2c_master_write(0x00);
157 if (err) goto i2c_error;
158
159 // Start read
160 err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ);
161 if (err) goto i2c_error;
162
163 if (!err) {
164 int i;
165 for (i = 0; i < ROWS_PER_HAND-1; ++i) {
166 matrix[slaveOffset+i] = i2c_master_read(I2C_ACK);
167 }
168 matrix[slaveOffset+i] = i2c_master_read(I2C_NACK);
169 i2c_master_stop();
170 } else {
171i2c_error: // the cable is disconnceted, or something else went wrong
172 i2c_reset_state();
173 return err;
174 }
175
176 return 0;
177}
178
179#else // USE_SERIAL
180
181int serial_transaction(void) {
182 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
183 int ret=serial_update_buffers();
184 if (ret ) {
185 if(ret==2)RXLED1;
186 return 1;
187 }
188RXLED0;
189 for (int i = 0; i < ROWS_PER_HAND; ++i) {
190 matrix[slaveOffset+i] = serial_slave_buffer[i];
191 }
192 return 0;
193}
194#endif
195
196uint8_t matrix_scan(void)
197{
198 if (is_master) {
199 matrix_master_scan();
200 }else{
201 matrix_slave_scan();
202
203// if(serial_slave_DATA_CORRUPT()){
204// TXLED0;
205 int offset = (isLeftHand) ? ROWS_PER_HAND : 0;
206
207 for (int i = 0; i < ROWS_PER_HAND; ++i) {
208 matrix[offset+i] = serial_master_buffer[i];
209 }
210
211// }else{
212// TXLED1;
213// }
214
215 matrix_scan_quantum();
216 }
217 return 1;
218}
219
220
221uint8_t matrix_master_scan(void) {
222
223 int ret = _matrix_scan();
224
225#ifndef KEYBOARD_helix_rev1
226 int offset = (isLeftHand) ? 0 : ROWS_PER_HAND;
227
228#ifdef USE_I2C
229// for (int i = 0; i < ROWS_PER_HAND; ++i) {
230 /* i2c_slave_buffer[i] = matrix[offset+i]; */
231// i2c_slave_buffer[i] = matrix[offset+i];
232// }
233#else // USE_SERIAL
234 for (int i = 0; i < ROWS_PER_HAND; ++i) {
235 serial_master_buffer[i] = matrix[offset+i];
236 }
237#endif
238#endif
239
240#ifdef USE_I2C
241 if( i2c_transaction() ) {
242#else // USE_SERIAL
243 if( serial_transaction() ) {
244#endif
245 // turn on the indicator led when halves are disconnected
246 TXLED1;
247
248 error_count++;
249
250 if (error_count > ERROR_DISCONNECT_COUNT) {
251 // reset other half if disconnected
252 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
253 for (int i = 0; i < ROWS_PER_HAND; ++i) {
254 matrix[slaveOffset+i] = 0;
255 }
256 }
257 } else {
258 // turn off the indicator led on no error
259 TXLED0;
260 error_count = 0;
261 }
262 matrix_scan_quantum();
263 return ret;
264}
265
266void matrix_slave_scan(void) {
267 _matrix_scan();
268
269 int offset = (isLeftHand) ? 0 : ROWS_PER_HAND;
270
271#ifdef USE_I2C
272 for (int i = 0; i < ROWS_PER_HAND; ++i) {
273 /* i2c_slave_buffer[i] = matrix[offset+i]; */
274 i2c_slave_buffer[i] = matrix[offset+i];
275 }
276#else // USE_SERIAL
277 for (int i = 0; i < ROWS_PER_HAND; ++i) {
278 serial_slave_buffer[i] = matrix[offset+i];
279 }
280#endif
281}
282
283bool matrix_is_modified(void)
284{
285 if (debouncing) return false;
286 return true;
287}
288
289inline
290bool matrix_is_on(uint8_t row, uint8_t col)
291{
292 return (matrix[row] & ((matrix_row_t)1<<col));
293}
294
295inline
296matrix_row_t matrix_get_row(uint8_t row)
297{
298 return matrix[row];
299}
300
301void matrix_print(void)
302{
303 print("\nr/c 0123456789ABCDEF\n");
304 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
305 phex(row); print(": ");
306 pbin_reverse16(matrix_get_row(row));
307 print("\n");
308 }
309}
310
311uint8_t matrix_key_count(void)
312{
313 uint8_t count = 0;
314 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
315 count += bitpop16(matrix[i]);
316 }
317 return count;
318}
319
320static void init_cols(void)
321{
322 for(int x = 0; x < MATRIX_COLS; x++) {
323 _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF);
324 _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF);
325 }
326}
327
328static matrix_row_t read_cols(void)
329{
330 matrix_row_t result = 0;
331 for(int x = 0; x < MATRIX_COLS; x++) {
332 result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x);
333 }
334 return result;
335}
336
337static void unselect_rows(void)
338{
339 for(int x = 0; x < ROWS_PER_HAND; x++) {
340 _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF);
341 _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF);
342 }
343}
344
345static void select_row(uint8_t row)
346{
347 _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF);
348 _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF);
349}
diff --git a/keyboards/mint60/mint60.c b/keyboards/mint60/mint60.c
new file mode 100644
index 000000000..724bea757
--- /dev/null
+++ b/keyboards/mint60/mint60.c
@@ -0,0 +1,43 @@
1/* Copyright 2018 Eucalyn
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "mint60.h"
17
18void matrix_init_kb(void) {
19 // put your keyboard start-up code here
20 // runs once when the firmware starts up
21
22 matrix_init_user();
23}
24
25void matrix_scan_kb(void) {
26 // put your looping keyboard code here
27 // runs every cycle (a lot)
28
29 matrix_scan_user();
30}
31
32bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
33 // put your per-action keyboard code here
34 // runs for every action, just before processing by the firmware
35
36 return process_record_user(keycode, record);
37}
38
39void led_set_kb(uint8_t usb_led) {
40 // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
41
42 led_set_user(usb_led);
43}
diff --git a/keyboards/mint60/mint60.h b/keyboards/mint60/mint60.h
new file mode 100644
index 000000000..ed2ee255f
--- /dev/null
+++ b/keyboards/mint60/mint60.h
@@ -0,0 +1,59 @@
1/* Copyright 2018 Eucalyn
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#ifndef MINT60_H
17#define MINT60_H
18
19#include "quantum.h"
20
21#ifdef RGBLIGHT_ENABLE
22//rgb led driver
23#include "ws2812.h"
24#endif
25
26#ifdef USE_I2C
27#include <stddef.h>
28#ifdef __AVR__
29 #include <avr/io.h>
30 #include <avr/interrupt.h>
31#endif
32#endif
33
34
35// This a shortcut to help you visually see your layout.
36// The following is an example using the Planck MIT layout
37// The first section contains all of the arguments
38// The second converts the arguments into a two-dimensional array
39#define LAYOUT( \
40 L00,L01,L02,L03,L04,L05, R00,R01,R02,R03,R04,R05,R06, R07, \
41 L10, L11,L12,L13,L14,L15, R10,R11,R12,R13,R14,R15,R16,R17, \
42 L20, L21,L22,L23,L24,L25, R20,R21,R22,R23,R24,R25, R27, \
43 L30, L31,L32,L33,L34,L35, R30,R31,R32,R33,R34,R35,R36,R37, \
44 L40,L41, L42, L43, L44, R40, R41, R43, R45,R46,R47 \
45) \
46{ \
47 { L00, L01, L02, L03, L04, L05, KC_NO, KC_NO }, \
48 { L10, L11, L12, L13, L14, L15, KC_NO, KC_NO }, \
49 { L20, L21, L22, L23, L24, L25, KC_NO, KC_NO }, \
50 { L30, L31, L32, L33, L34, L35, KC_NO, KC_NO }, \
51 { L40, L41, L42, L43, L44, KC_NO, KC_NO, KC_NO }, \
52 { R00, R01, R02, R03, R04, R05, R06, R07 }, \
53 { R10, R11, R12, R13, R14, R15, R16, R17 }, \
54 { R20, R21, R22, R23, R24, R25, KC_NO, R27 }, \
55 { R30, R31, R32, R33, R34, R35, R36, R37 }, \
56 { R40, R41, KC_NO, R43, KC_NO, R45, R46, R47 }, \
57}
58
59#endif
diff --git a/keyboards/mint60/readme.md b/keyboards/mint60/readme.md
new file mode 100644
index 000000000..c425b213b
--- /dev/null
+++ b/keyboards/mint60/readme.md
@@ -0,0 +1,15 @@
1# Mint60
2
3![Mint60](https://imgur.com/a/8xnTS4U)
4
5A short description of the keyboard/project
6
7Keyboard Maintainer: [Eucalyn](https://github.com/eucalyn) [@eucalyn_](https://twitter.com/eucalyn_)
8Hardware Supported: The Mint60 PCBs, ProMicro supported
9Hardware Availability: links to where you can find this hardware
10
11Make example for this keyboard (after setting up your build environment):
12
13 make mint60:default
14
15See [build environment setup](https://docs.qmk.fm/build_environment_setup.html) then the [make instructions](https://docs.qmk.fm/make_instructions.html) for more information.
diff --git a/keyboards/mint60/rules.mk b/keyboards/mint60/rules.mk
new file mode 100644
index 000000000..b4d4bddd3
--- /dev/null
+++ b/keyboards/mint60/rules.mk
@@ -0,0 +1,78 @@
1SRC += i2c.c \
2 serial.c \
3 matrix.c \
4 split_util.c \
5
6# MCU name
7#MCU = at90usb1286
8MCU = atmega32u4
9
10# Processor frequency.
11# This will define a symbol, F_CPU, in all source code files equal to the
12# processor frequency in Hz. You can then use this symbol in your source code to
13# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
14# automatically to create a 32-bit value in your source code.
15#
16# This will be an integer division of F_USB below, as it is sourced by
17# F_USB after it has run through any CPU prescalers. Note that this value
18# does not *change* the processor frequency - it should merely be updated to
19# reflect the processor speed set externally so that the code can use accurate
20# software delays.
21F_CPU = 16000000
22
23
24#
25# LUFA specific
26#
27# Target architecture (see library "Board Types" documentation).
28ARCH = AVR8
29
30# Input clock frequency.
31# This will define a symbol, F_USB, in all source code files equal to the
32# input clock frequency (before any prescaling is performed) in Hz. This value may
33# differ from F_CPU if prescaling is used on the latter, and is required as the
34# raw input clock is fed directly to the PLL sections of the AVR for high speed
35# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
36# at the end, this will be done automatically to create a 32-bit value in your
37# source code.
38#
39# If no clock division is performed on the input clock inside the AVR (via the
40# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
41F_USB = $(F_CPU)
42
43# Interrupt driven control endpoint task(+60)
44OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
45
46
47# Boot Section Size in *bytes*
48# Teensy halfKay 512
49# Teensy++ halfKay 1024
50# Atmel DFU loader 4096
51# LUFA bootloader 4096
52# USBaspLoader 2048
53OPT_DEFS += -DBOOTLOADER_SIZE=4096
54
55
56# Build Options
57# change yes to no to disable
58#
59BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
60MOUSEKEY_ENABLE = no # Mouse keys(+4700)
61EXTRAKEY_ENABLE = no # Audio control and System control(+450)
62CONSOLE_ENABLE = no # Console for debug(+400)
63COMMAND_ENABLE = no # Commands for debug and configuration
64# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
65SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
66# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
67NKRO_ENABLE = no # USB Nkey Rollover
68BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
69MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
70UNICODE_ENABLE = no # Unicode
71BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
72AUDIO_ENABLE = no # Audio output on port C6
73FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
74HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
75
76CUSTOM_MATRIX = yes
77USE_I2C = yes
78RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
diff --git a/keyboards/mint60/serial.c b/keyboards/mint60/serial.c
new file mode 100644
index 000000000..591941587
--- /dev/null
+++ b/keyboards/mint60/serial.c
@@ -0,0 +1,295 @@
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 <stdbool.h>
13#include "serial.h"
14
15#ifdef USE_SERIAL
16
17#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
18
19// Serial pulse period in microseconds.
20#define SELECT_SERIAL_SPEED 1
21#if SELECT_SERIAL_SPEED == 0
22 // Very High speed
23 #define SERIAL_DELAY 4 // micro sec
24 #define READ_WRITE_START_ADJUST 30 // cycles
25 #define READ_WRITE_WIDTH_ADJUST 10 // cycles
26#elif SELECT_SERIAL_SPEED == 1
27 // High speed
28 #define SERIAL_DELAY 6 // micro sec
29 #define READ_WRITE_START_ADJUST 23 // cycles
30 #define READ_WRITE_WIDTH_ADJUST 10 // cycles
31#elif SELECT_SERIAL_SPEED == 2
32 // Middle speed
33 #define SERIAL_DELAY 12 // micro sec
34 #define READ_WRITE_START_ADJUST 25 // cycles
35 #define READ_WRITE_WIDTH_ADJUST 10 // cycles
36#elif SELECT_SERIAL_SPEED == 3
37 // Low speed
38 #define SERIAL_DELAY 24 // micro sec
39 #define READ_WRITE_START_ADJUST 25 // cycles
40 #define READ_WRITE_WIDTH_ADJUST 10 // cycles
41#elif SELECT_SERIAL_SPEED == 4
42 // Very Low speed
43 #define SERIAL_DELAY 50 // micro sec
44 #define READ_WRITE_START_ADJUST 25 // cycles
45 #define READ_WRITE_WIDTH_ADJUST 10 // cycles
46#else
47#error Illegal Serial Speed
48#endif
49
50
51#define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2)
52#define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2)
53
54#define SLAVE_INT_WIDTH 1
55#define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
56
57uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
58uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
59
60#define SLAVE_DATA_CORRUPT (1<<0)
61volatile uint8_t status = 0;
62
63inline static
64void serial_delay(void) {
65 _delay_us(SERIAL_DELAY);
66}
67
68inline static
69void serial_delay_half1(void) {
70 _delay_us(SERIAL_DELAY_HALF1);
71}
72
73inline static
74void serial_delay_half2(void) {
75 _delay_us(SERIAL_DELAY_HALF2);
76}
77
78inline static
79void serial_output(void) {
80 SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
81}
82
83// make the serial pin an input with pull-up resistor
84inline static
85void serial_input_with_pullup(void) {
86 SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK;
87 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
88}
89
90inline static
91uint8_t serial_read_pin(void) {
92 return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
93}
94
95inline static
96void serial_low(void) {
97 SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
98}
99
100inline static
101void serial_high(void) {
102 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
103}
104
105void serial_master_init(void) {
106 serial_output();
107 serial_high();
108}
109
110void serial_slave_init(void) {
111 serial_input_with_pullup();
112
113#if SERIAL_PIN_MASK == _BV(PD0)
114 // Enable INT0
115 EIMSK |= _BV(INT0);
116 // Trigger on falling edge of INT0
117 EICRA &= ~(_BV(ISC00) | _BV(ISC01));
118#elif SERIAL_PIN_MASK == _BV(PD2)
119 // Enable INT2
120 EIMSK |= _BV(INT2);
121 // Trigger on falling edge of INT2
122 EICRA &= ~(_BV(ISC20) | _BV(ISC21));
123#else
124 #error unknown SERIAL_PIN_MASK value
125#endif
126}
127
128// Used by the sender to synchronize timing with the reciver.
129static
130void sync_recv(void) {
131 for (int i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) {
132 }
133 // This shouldn't hang if the slave disconnects because the
134 // serial line will float to high if the slave does disconnect.
135 while (!serial_read_pin());
136}
137
138// Used by the reciver to send a synchronization signal to the sender.
139static
140void sync_send(void) {
141 serial_low();
142 serial_delay();
143 serial_high();
144}
145
146// Reads a byte from the serial line
147static
148uint8_t serial_read_byte(void) {
149 uint8_t byte = 0;
150 _delay_sub_us(READ_WRITE_START_ADJUST);
151 for ( uint8_t i = 0; i < 8; ++i) {
152 serial_delay_half1(); // read the middle of pulses
153 byte = (byte << 1) | serial_read_pin();
154 _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
155 serial_delay_half2();
156 }
157 return byte;
158}
159
160// Sends a byte with MSB ordering
161static
162void serial_write_byte(uint8_t data) {
163 uint8_t b = 1<<7;
164 while( b ) {
165 if(data & b) {
166 serial_high();
167 } else {
168 serial_low();
169 }
170 b >>= 1;
171 serial_delay();
172 }
173 serial_low(); // sync_send() / senc_recv() need raise edge
174}
175
176// interrupt handle to be used by the slave device
177ISR(SERIAL_PIN_INTERRUPT) {
178 serial_output();
179
180 // slave send phase
181 uint8_t checksum = 0;
182 for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
183 sync_send();
184 serial_write_byte(serial_slave_buffer[i]);
185 checksum += serial_slave_buffer[i];
186 }
187 sync_send();
188 serial_write_byte(checksum);
189
190 // slave switch to input
191 sync_send(); //0
192 serial_delay_half1(); //1
193 serial_low(); //2
194 serial_input_with_pullup(); //2
195 serial_delay_half1(); //3
196
197 // slave recive phase
198 uint8_t checksum_computed = 0;
199 for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
200 sync_recv();
201 serial_master_buffer[i] = serial_read_byte();
202 checksum_computed += serial_master_buffer[i];
203 }
204 sync_recv();
205 uint8_t checksum_received = serial_read_byte();
206
207 if ( checksum_computed != checksum_received ) {
208 status |= SLAVE_DATA_CORRUPT;
209 } else {
210 status &= ~SLAVE_DATA_CORRUPT;
211 }
212
213 sync_recv(); //weit master output to high
214}
215
216inline
217bool serial_slave_DATA_CORRUPT(void) {
218 return status & SLAVE_DATA_CORRUPT;
219}
220
221// Copies the serial_slave_buffer to the master and sends the
222// serial_master_buffer to the slave.
223//
224// Returns:
225// 0 => no error
226// 1 => slave did not respond
227// 2 => checksum error
228int serial_update_buffers(void) {
229 // this code is very time dependent, so we need to disable interrupts
230 cli();
231
232 // signal to the slave that we want to start a transaction
233 serial_output();
234 serial_low();
235 _delay_us(SLAVE_INT_WIDTH);
236
237 // wait for the slaves response
238 serial_input_with_pullup();
239 _delay_us(SLAVE_INT_RESPONSE_TIME);
240
241 // check if the slave is present
242 if (serial_read_pin()) {
243 // slave failed to pull the line low, assume not present
244 serial_output();
245 serial_high();
246 sei();
247 return 1;
248 }
249
250 // master recive phase
251 // if the slave is present syncronize with it
252
253 uint8_t checksum_computed = 0;
254 // receive data from the slave
255 for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
256 sync_recv();
257 serial_slave_buffer[i] = serial_read_byte();
258 checksum_computed += serial_slave_buffer[i];
259 }
260 sync_recv();
261 uint8_t checksum_received = serial_read_byte();
262
263 if (checksum_computed != checksum_received) {
264 serial_output();
265 serial_high();
266 sei();
267 return 2;
268 }
269
270 // master switch to output
271 sync_recv(); //0
272 serial_delay(); //1
273 serial_low(); //3
274 serial_output(); // 3
275 serial_delay_half1(); //4
276
277 // master send phase
278 uint8_t checksum = 0;
279
280 for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
281 sync_send();
282 serial_write_byte(serial_master_buffer[i]);
283 checksum += serial_master_buffer[i];
284 }
285 sync_send();
286 serial_write_byte(checksum);
287
288 // always, release the line when not in use
289 sync_send();
290
291 sei();
292 return 0;
293}
294
295#endif
diff --git a/keyboards/mint60/serial.h b/keyboards/mint60/serial.h
new file mode 100644
index 000000000..c3c9569b2
--- /dev/null
+++ b/keyboards/mint60/serial.h
@@ -0,0 +1,27 @@
1#ifndef SOFT_SERIAL_H
2#define SOFT_SERIAL_H
3
4#include <stdbool.h>
5
6// ////////////////////////////////////////////
7// Need Soft Serial defines in serial_config.h
8// ////////////////////////////////////////////
9// ex.
10// #define SERIAL_PIN_DDR DDRD
11// #define SERIAL_PIN_PORT PORTD
12// #define SERIAL_PIN_INPUT PIND
13// #define SERIAL_PIN_MASK _BV(PD?) ?=0,2
14// #define SERIAL_PIN_INTERRUPT INT?_vect ?=0,2
15// #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
16// #define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
17
18// Buffers for master - slave communication
19extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
20extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
21
22void serial_master_init(void);
23void serial_slave_init(void);
24int serial_update_buffers(void);
25bool serial_slave_data_corrupt(void);
26
27#endif /* SOFT_SERIAL_H */
diff --git a/keyboards/mint60/serial_config.h b/keyboards/mint60/serial_config.h
new file mode 100644
index 000000000..82c6e4e83
--- /dev/null
+++ b/keyboards/mint60/serial_config.h
@@ -0,0 +1,16 @@
1#ifndef SOFT_SERIAL_CONFIG_H
2#define SOFT_SERIAL_CONFIG_H
3
4/* Soft Serial defines */
5#define SERIAL_PIN_DDR DDRD
6#define SERIAL_PIN_PORT PORTD
7#define SERIAL_PIN_INPUT PIND
8#define SERIAL_PIN_MASK _BV(PD2)
9#define SERIAL_PIN_INTERRUPT INT2_vect
10
11#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
12#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
13
14//// #error rev2 serial config
15
16#endif /* SOFT_SERIAL_CONFIG_H */
diff --git a/keyboards/mint60/split_util.c b/keyboards/mint60/split_util.c
new file mode 100644
index 000000000..cd3a1896e
--- /dev/null
+++ b/keyboards/mint60/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_I2C
12# include "i2c.h"
13#else
14# include "serial.h"
15#endif
16
17volatile bool isLeftHand = true;
18
19static 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
32static void keyboard_master_setup(void) {
33
34#ifdef USE_I2C
35 i2c_master_init();
36#else
37 serial_master_init();
38#endif
39}
40
41static void keyboard_slave_setup(void) {
42
43#ifdef USE_I2C
44 i2c_slave_init(SLAVE_I2C_ADDRESS);
45#else
46 serial_slave_init();
47#endif
48}
49
50bool 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
56void 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
68void matrix_setup(void) {
69 split_keyboard_setup();
70}
diff --git a/keyboards/mint60/split_util.h b/keyboards/mint60/split_util.h
new file mode 100644
index 000000000..687ca19bd
--- /dev/null
+++ b/keyboards/mint60/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
9extern volatile bool isLeftHand;
10
11// slave version of matix scan, defined in matrix.c
12void matrix_slave_scan(void);
13
14void split_keyboard_setup(void);
15bool has_usb(void);
16
17void matrix_master_OLED_init (void);
18
19#endif