aboutsummaryrefslogtreecommitdiff
path: root/keyboards/minidox
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/minidox')
-rw-r--r--keyboards/minidox/Makefile5
-rw-r--r--keyboards/minidox/config.h74
-rw-r--r--keyboards/minidox/i2c.c162
-rw-r--r--keyboards/minidox/i2c.h31
-rw-r--r--keyboards/minidox/keymaps/default/keymap.c168
-rw-r--r--keyboards/minidox/keymaps/that_canadian/Makefile5
-rw-r--r--keyboards/minidox/keymaps/that_canadian/config.h37
-rw-r--r--keyboards/minidox/keymaps/that_canadian/keymap.c172
-rw-r--r--keyboards/minidox/matrix.c318
-rw-r--r--keyboards/minidox/minidox.c1
-rw-r--r--keyboards/minidox/minidox.h10
-rw-r--r--keyboards/minidox/pro_micro.h362
-rw-r--r--keyboards/minidox/readme.md15
-rw-r--r--keyboards/minidox/rev1/Makefile3
-rw-r--r--keyboards/minidox/rev1/config.h38
-rw-r--r--keyboards/minidox/rev1/rev1.c1
-rw-r--r--keyboards/minidox/rev1/rev1.h28
-rw-r--r--keyboards/minidox/rev1/rules.mk5
-rw-r--r--keyboards/minidox/rules.mk74
-rw-r--r--keyboards/minidox/serial.c228
-rw-r--r--keyboards/minidox/serial.h26
-rw-r--r--keyboards/minidox/split_util.c80
-rw-r--r--keyboards/minidox/split_util.h22
23 files changed, 1865 insertions, 0 deletions
diff --git a/keyboards/minidox/Makefile b/keyboards/minidox/Makefile
new file mode 100644
index 000000000..30b43c4ea
--- /dev/null
+++ b/keyboards/minidox/Makefile
@@ -0,0 +1,5 @@
1SUBPROJECT_DEFAULT = rev1
2
3ifndef MAKEFILE_INCLUDED
4 include ../../Makefile
5endif \ No newline at end of file
diff --git a/keyboards/minidox/config.h b/keyboards/minidox/config.h
new file mode 100644
index 000000000..306a486cb
--- /dev/null
+++ b/keyboards/minidox/config.h
@@ -0,0 +1,74 @@
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#ifndef CONFIG_H
19#define CONFIG_H
20
21#include "config_common.h"
22
23/* USB Device descriptor parameter */
24#define VENDOR_ID 0xFEED
25#define PRODUCT_ID 0x3060
26#define MANUFACTURER That-Canadian
27#define PRODUCT MiniDox
28#define DESCRIPTION A compact version of the Ergo Dox
29
30/* key matrix size */
31// Rows are doubled-up
32#define MATRIX_ROWS 8
33#define MATRIX_COLS 5
34
35/* COL2ROW or ROW2COL */
36#define DIODE_DIRECTION COL2ROW
37
38/* define if matrix has ghost */
39//#define MATRIX_HAS_GHOST
40
41/* number of backlight levels */
42// #define BACKLIGHT_LEVELS 3
43
44/* Set 0 if debouncing isn't needed */
45#define DEBOUNCING_DELAY 5
46
47/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
48#define LOCKING_SUPPORT_ENABLE
49/* Locking resynchronize hack */
50#define LOCKING_RESYNC_ENABLE
51
52/* key combination for command */
53#define IS_COMMAND() ( \
54 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
55)
56
57/* disable debug print */
58//#define NO_DEBUG
59
60/* disable print */
61//#define NO_PRINT
62
63/* disable action features */
64//#define NO_ACTION_LAYER
65//#define NO_ACTION_TAPPING
66//#define NO_ACTION_ONESHOT
67//#define NO_ACTION_MACRO
68//#define NO_ACTION_FUNCTION
69
70#ifdef SUBPROJECT_rev1
71 #include "rev1/config.h"
72#endif
73
74#endif
diff --git a/keyboards/minidox/i2c.c b/keyboards/minidox/i2c.c
new file mode 100644
index 000000000..084c890c4
--- /dev/null
+++ b/keyboards/minidox/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
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/minidox/i2c.h b/keyboards/minidox/i2c.h
new file mode 100644
index 000000000..08ce4b009
--- /dev/null
+++ b/keyboards/minidox/i2c.h
@@ -0,0 +1,31 @@
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
19#define SCL_CLOCK 100000L
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#endif
diff --git a/keyboards/minidox/keymaps/default/keymap.c b/keyboards/minidox/keymaps/default/keymap.c
new file mode 100644
index 000000000..3fa20e1eb
--- /dev/null
+++ b/keyboards/minidox/keymaps/default/keymap.c
@@ -0,0 +1,168 @@
1#include "minidox.h"
2#include "action_layer.h"
3#include "eeconfig.h"
4
5extern keymap_config_t keymap_config;
6
7// Each layer gets a name for readability, which is then used in the keymap matrix below.
8// The underscores don't mean anything - you can have a layer called STUFF or any other name.
9// Layer names don't all need to be of the same length, obviously, and you can also skip them
10// entirely and just use numbers.
11#define _QWERTY 0
12#define _LOWER 1
13#define _RAISE 2
14#define _ADJUST 16
15
16enum custom_keycodes {
17 QWERTY = SAFE_RANGE,
18 LOWER,
19 RAISE,
20 ADJUST,
21};
22
23// Fillers to make layering more clear
24#define _______ KC_TRNS
25#define XXXXXXX KC_NO
26
27// Defines for task manager and such
28#define CALTDEL LCTL(LALT(KC_DEL))
29#define TSKMGR LCTL(LSFT(KC_ESC))
30
31const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
32
33/* Qwerty
34 *
35 * ,----------------------------------. ,----------------------------------.
36 * | Q | W | E | R | T | | Y | U | I | O | P |
37 * |------+------+------+------+------| |------+------+------+------+------|
38 * | A | S | D | F | G | | H | J | K | L | ; |
39 * |------+------+------+------+------| |------+------+------+------+------|
40 * | Z | X | C | V | B | | N | M | , | . | / |
41 * `----------------------------------' `----------------------------------'
42 * ,--------------------. ,------,-------------.
43 * | Ctrl | LOWER| | | | RAISE| Shift|
44 * `-------------| Space| |BckSpc|------+------.
45 * | | | |
46 * `------' `------'
47 */
48[_QWERTY] = KEYMAP( \
49 KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, \
50 KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, \
51 KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, \
52 KC_LCTL, LOWER, KC_SPC, KC_BSPC, RAISE, OSM(MOD_LSFT) \
53),
54
55/* Raise
56 *
57 * ,----------------------------------. ,----------------------------------.
58 * | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 |
59 * |------+------+------+------+------| |------+------+------+------+------|
60 * | Tab | Left | Down | Up | Right| | | - | = | [ | ] |
61 * |------+------+------+------+------| |------+------+------+------+------|
62 * | Ctrl| ` | GUI | Alt | | | | | | \ | ' |
63 * `----------------------------------' `----------------------------------'
64 * ,--------------------. ,------,-------------.
65 * | | LOWER| | | | RAISE| |
66 * `-------------| | | |------+------.
67 * | | | |
68 * `------' `------'
69 */
70[_RAISE] = KEYMAP( \
71 KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, \
72 KC_TAB, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, \
73 KC_LCTL, KC_GRV, KC_LGUI, KC_LALT, _______, _______, _______, _______, KC_BSLS, KC_QUOT, \
74 _______, _______, _______, _______, _______, _______ \
75),
76
77/* Lower
78 *
79 * ,----------------------------------. ,----------------------------------.
80 * | ! | @ | # | $ | % | | ^ | & | * | ( | ) |
81 * |------+------+------+------+------| |------+------+------+------+------|
82 * | Esc | | | | | | | _ | + | { | } |
83 * |------+------+------+------+------| |------+------+------+------+------|
84 * | Caps| ~ | | | | | | | | | | " |
85 * `----------------------------------' `----------------------------------'
86 * ,--------------------. ,------,-------------.
87 * | | LOWER| | | | RAISE| Del |
88 * `-------------| | | Enter|------+------.
89 * | | | |
90 * `------' `------'
91 */
92[_LOWER] = KEYMAP( \
93 KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, \
94 KC_ESC, _______, _______, _______, _______, _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, \
95 KC_CAPS, KC_TILD, _______, _______, _______, _______, _______, _______, KC_PIPE, KC_DQT, \
96 _______, _______, _______, KC_ENT, _______, KC_DEL \
97),
98
99/* Adjust (Lower + Raise)
100 *
101 * ,----------------------------------. ,----------------------------------.
102 * | F1 | F2 | F3 | F4 | F5 | | F6 | F7 | F8 | F9 | F10 |
103 * |------+------+------+------+------| |------+------+------+------+------|
104 * | F11 | F12 | | | | | | | |Taskmg|caltde|
105 * |------+------+------+------+------| |------+------+------+------+------|
106 * | Reset| | | | | | | | | | |
107 * `----------------------------------' `----------------------------------'
108 * ,--------------------. ,------,-------------.
109 * | | LOWER| | | | RAISE| |
110 * `-------------| | | |------+------.
111 * | | | |
112 * `------' `------'
113 */
114[_ADJUST] = KEYMAP( \
115 KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, \
116 KC_F11, KC_F12, _______, _______, _______, _______, _______, _______, TSKMGR, CALTDEL, \
117 RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
118 _______, _______, _______, _______, _______, _______ \
119)
120};
121
122void persistant_default_layer_set(uint16_t default_layer) {
123 eeconfig_update_default_layer(default_layer);
124 default_layer_set(default_layer);
125}
126
127bool process_record_user(uint16_t keycode, keyrecord_t *record) {
128 switch (keycode) {
129 case QWERTY:
130 if (record->event.pressed) {
131 #ifdef AUDIO_ENABLE
132 PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
133 #endif
134 persistant_default_layer_set(1UL<<_QWERTY);
135 }
136 return false;
137 break;
138 case LOWER:
139 if (record->event.pressed) {
140 layer_on(_LOWER);
141 update_tri_layer(_LOWER, _RAISE, _ADJUST);
142 } else {
143 layer_off(_LOWER);
144 update_tri_layer(_LOWER, _RAISE, _ADJUST);
145 }
146 return false;
147 break;
148 case RAISE:
149 if (record->event.pressed) {
150 layer_on(_RAISE);
151 update_tri_layer(_LOWER, _RAISE, _ADJUST);
152 } else {
153 layer_off(_RAISE);
154 update_tri_layer(_LOWER, _RAISE, _ADJUST);
155 }
156 return false;
157 break;
158 case ADJUST:
159 if (record->event.pressed) {
160 layer_on(_ADJUST);
161 } else {
162 layer_off(_ADJUST);
163 }
164 return false;
165 break;
166 }
167 return true;
168} \ No newline at end of file
diff --git a/keyboards/minidox/keymaps/that_canadian/Makefile b/keyboards/minidox/keymaps/that_canadian/Makefile
new file mode 100644
index 000000000..52ef1ad3e
--- /dev/null
+++ b/keyboards/minidox/keymaps/that_canadian/Makefile
@@ -0,0 +1,5 @@
1RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
2
3ifndef QUANTUM_DIR
4 include ../../../../Makefile
5endif
diff --git a/keyboards/minidox/keymaps/that_canadian/config.h b/keyboards/minidox/keymaps/that_canadian/config.h
new file mode 100644
index 000000000..7a8193e08
--- /dev/null
+++ b/keyboards/minidox/keymaps/that_canadian/config.h
@@ -0,0 +1,37 @@
1/*
2This is the c configuration file for the keymap
3
4Copyright 2012 Jun Wako <wakojun@gmail.com>
5Copyright 2015 Jack Humbert
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef CONFIG_USER_H
22#define CONFIG_USER_H
23
24#include "../../config.h"
25
26#define USE_SERIAL
27
28/* ws2812 RGB LED */
29#define RGB_DI_PIN D7
30#define RGBLIGHT_TIMER
31#define RGBLED_NUM 4 // Number of LEDs
32#define RGBLIGHT_ANIMATIONS
33#define RGBLIGHT_HUE_STEP 10
34#define RGBLIGHT_SAT_STEP 17
35#define RGBLIGHT_VAL_STEP 17
36
37#endif \ No newline at end of file
diff --git a/keyboards/minidox/keymaps/that_canadian/keymap.c b/keyboards/minidox/keymaps/that_canadian/keymap.c
new file mode 100644
index 000000000..da9905346
--- /dev/null
+++ b/keyboards/minidox/keymaps/that_canadian/keymap.c
@@ -0,0 +1,172 @@
1#include "minidox.h"
2#include "action_layer.h"
3#include "eeconfig.h"
4
5extern keymap_config_t keymap_config;
6
7// Each layer gets a name for readability, which is then used in the keymap matrix below.
8// The underscores don't mean anything - you can have a layer called STUFF or any other name.
9// Layer names don't all need to be of the same length, obviously, and you can also skip them
10// entirely and just use numbers.
11#define _QWERTY 0
12#define _LOWER 1
13#define _RAISE 2
14#define _ADJUST 16
15
16enum custom_keycodes {
17 QWERTY = SAFE_RANGE,
18 LOWER,
19 RAISE,
20 ADJUST,
21};
22
23// Fillers to make layering more clear
24#define _______ KC_TRNS
25#define XXXXXXX KC_NO
26
27// Defines for task manager and such
28#define CALTDEL LCTL(LALT(KC_DEL))
29#define TSKMGR LCTL(LSFT(KC_ESC))
30
31const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
32
33/* Qwerty
34 *
35 * ,----------------------------------. ,----------------------------------.
36 * | Q | W | E | R | T | | Y | U | I | O | P |
37 * |------+------+------+------+------| |------+------+------+------+------|
38 * | A | S | D | F | G | | H | J | K | L | ; |
39 * |------+------+------+------+------| |------+------+------+------+------|
40 * | Z | X | C | V | B | | N | M | , | . | / |
41 * `----------------------------------' `----------------------------------'
42 * ,--------------------. ,------,-------------.
43 * | Ctrl | LOWER| | | | RAISE| Shift|
44 * `-------------| Space| |BckSpc|------+------.
45 * | | | |
46 * `------' `------'
47 */
48[_QWERTY] = KEYMAP( \
49 KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, \
50 KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, \
51 KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, \
52 KC_LCTL, LOWER, KC_SPC, KC_BSPC, RAISE, OSM(MOD_LSFT) \
53),
54
55/* Raise
56 *
57 * ,----------------------------------. ,----------------------------------.
58 * | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 |
59 * |------+------+------+------+------| |------+------+------+------+------|
60 * | Tab | Left | Down | Up | Right| | | - | = | [ | ] |
61 * |------+------+------+------+------| |------+------+------+------+------|
62 * | Ctrl| ` | GUI | Alt | | | | | | \ | ' |
63 * `----------------------------------' `----------------------------------'
64 * ,--------------------. ,------,-------------.
65 * | | LOWER| | | | RAISE| |
66 * `-------------| | | |------+------.
67 * | | | |
68 * `------' `------'
69 */
70[_RAISE] = KEYMAP( \
71 KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, \
72 KC_TAB, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, \
73 KC_LCTL, KC_GRV, KC_LGUI, KC_LALT, _______, _______, _______, _______, KC_BSLS, KC_QUOT, \
74 _______, _______, _______, _______, _______, _______ \
75),
76
77/* Lower
78 *
79 * ,----------------------------------. ,----------------------------------.
80 * | ! | @ | # | $ | % | | ^ | & | * | ( | ) |
81 * |------+------+------+------+------| |------+------+------+------+------|
82 * | Esc | | | | | | | _ | + | { | } |
83 * |------+------+------+------+------| |------+------+------+------+------|
84 * | Caps| ~ | | | | | | | | | | " |
85 * `----------------------------------' `----------------------------------'
86 * ,--------------------. ,------,-------------.
87 * | | LOWER| | | | RAISE| Del |
88 * `-------------| | | Enter|------+------.
89 * | | | |
90 * `------' `------'
91 */
92[_LOWER] = KEYMAP( \
93 KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, \
94 KC_ESC, _______, _______, _______, _______, _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, \
95 KC_CAPS, KC_TILD, _______, _______, _______, _______, _______, _______, KC_PIPE, KC_DQT, \
96 _______, _______, _______, KC_ENT, _______, KC_DEL \
97),
98
99/* Adjust (Lower + Raise)
100 *
101 * ,----------------------------------. ,----------------------------------.
102 * | F1 | F2 | F3 | F4 | F5 | | F6 | F7 | Up | F9 | F10 |
103 * |------+------+------+------+------| |------+------+------+------+------|
104 * | F11 | F12 | | | | | | Left | Down |Right |caltde|
105 * |------+------+------+------+------| |------+------+------+------+------|
106 * | Reset| | | | | | | | F8 |Taskmg| |
107 * `----------------------------------' `----------------------------------'
108 * ,--------------------. ,------,-------------.
109 * | | LOWER| | | | RAISE| |
110 * `-------------| | | |------+------.
111 * | | | |
112 * `------' `------'
113 */
114[_ADJUST] = KEYMAP( \
115 KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_UP, KC_F9, KC_F10, \
116 KC_F11, KC_F12, _______, RGB_SAI, RGB_SAD, _______, KC_LEFT, KC_DOWN, KC_RGHT, CALTDEL, \
117 RESET, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_VAI, RGB_VAD, KC_F8, TSKMGR, _______, \
118 _______, _______, _______, _______, _______, _______ \
119)
120};
121
122#ifdef AUDIO_ENABLE
123float tone_qwerty[][2] = SONG(QWERTY_SOUND);
124#endif
125
126void persistant_default_layer_set(uint16_t default_layer) {
127 eeconfig_update_default_layer(default_layer);
128 default_layer_set(default_layer);
129}
130
131bool process_record_user(uint16_t keycode, keyrecord_t *record) {
132 switch (keycode) {
133 case QWERTY:
134 if (record->event.pressed) {
135 #ifdef AUDIO_ENABLE
136 PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
137 #endif
138 persistant_default_layer_set(1UL<<_QWERTY);
139 }
140 return false;
141 break;
142 case LOWER:
143 if (record->event.pressed) {
144 layer_on(_LOWER);
145 update_tri_layer(_LOWER, _RAISE, _ADJUST);
146 } else {
147 layer_off(_LOWER);
148 update_tri_layer(_LOWER, _RAISE, _ADJUST);
149 }
150 return false;
151 break;
152 case RAISE:
153 if (record->event.pressed) {
154 layer_on(_RAISE);
155 update_tri_layer(_LOWER, _RAISE, _ADJUST);
156 } else {
157 layer_off(_RAISE);
158 update_tri_layer(_LOWER, _RAISE, _ADJUST);
159 }
160 return false;
161 break;
162 case ADJUST:
163 if (record->event.pressed) {
164 layer_on(_ADJUST);
165 } else {
166 layer_off(_ADJUST);
167 }
168 return false;
169 break;
170 }
171 return true;
172} \ No newline at end of file
diff --git a/keyboards/minidox/matrix.c b/keyboards/minidox/matrix.c
new file mode 100644
index 000000000..138969004
--- /dev/null
+++ b/keyboards/minidox/matrix.c
@@ -0,0 +1,318 @@
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#include "config.h"
34
35#ifdef USE_I2C
36# include "i2c.h"
37#else // USE_SERIAL
38# include "serial.h"
39#endif
40
41#ifndef DEBOUNCE
42# define DEBOUNCE 5
43#endif
44
45#define ERROR_DISCONNECT_COUNT 5
46
47static uint8_t debouncing = DEBOUNCE;
48static const int ROWS_PER_HAND = MATRIX_ROWS/2;
49static uint8_t error_count = 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);
62
63__attribute__ ((weak))
64void matrix_init_quantum(void) {
65 matrix_init_kb();
66}
67
68__attribute__ ((weak))
69void matrix_scan_quantum(void) {
70 matrix_scan_kb();
71}
72
73__attribute__ ((weak))
74void matrix_init_kb(void) {
75 matrix_init_user();
76}
77
78__attribute__ ((weak))
79void matrix_scan_kb(void) {
80 matrix_scan_user();
81}
82
83__attribute__ ((weak))
84void matrix_init_user(void) {
85}
86
87__attribute__ ((weak))
88void matrix_scan_user(void) {
89}
90
91inline
92uint8_t matrix_rows(void)
93{
94 return MATRIX_ROWS;
95}
96
97inline
98uint8_t matrix_cols(void)
99{
100 return MATRIX_COLS;
101}
102
103void matrix_init(void)
104{
105 debug_enable = true;
106 debug_matrix = true;
107 debug_mouse = true;
108 // initialize row and col
109 unselect_rows();
110 init_cols();
111
112 TX_RX_LED_INIT;
113
114 // initialize matrix state: all keys off
115 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
116 matrix[i] = 0;
117 matrix_debouncing[i] = 0;
118 }
119
120 matrix_init_quantum();
121}
122
123uint8_t _matrix_scan(void)
124{
125 // Right hand is stored after the left in the matirx so, we need to offset it
126 int offset = isLeftHand ? 0 : (ROWS_PER_HAND);
127
128 for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
129 select_row(i);
130 _delay_us(30); // without this wait read unstable value.
131 matrix_row_t cols = read_cols();
132 if (matrix_debouncing[i+offset] != cols) {
133 matrix_debouncing[i+offset] = cols;
134 debouncing = DEBOUNCE;
135 }
136 unselect_rows();
137 }
138
139 if (debouncing) {
140 if (--debouncing) {
141 _delay_ms(1);
142 } else {
143 for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
144 matrix[i+offset] = matrix_debouncing[i+offset];
145 }
146 }
147 }
148
149 return 1;
150}
151
152#ifdef USE_I2C
153
154// Get rows from other half over i2c
155int i2c_transaction(void) {
156 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
157
158 int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
159 if (err) goto i2c_error;
160
161 // start of matrix stored at 0x00
162 err = i2c_master_write(0x00);
163 if (err) goto i2c_error;
164
165 // Start read
166 err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ);
167 if (err) goto i2c_error;
168
169 if (!err) {
170 int i;
171 for (i = 0; i < ROWS_PER_HAND-1; ++i) {
172 matrix[slaveOffset+i] = i2c_master_read(I2C_ACK);
173 }
174 matrix[slaveOffset+i] = i2c_master_read(I2C_NACK);
175 i2c_master_stop();
176 } else {
177i2c_error: // the cable is disconnceted, or something else went wrong
178 i2c_reset_state();
179 return err;
180 }
181
182 return 0;
183}
184
185#else // USE_SERIAL
186
187int serial_transaction(void) {
188 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
189
190 if (serial_update_buffers()) {
191 return 1;
192 }
193
194 for (int i = 0; i < ROWS_PER_HAND; ++i) {
195 matrix[slaveOffset+i] = serial_slave_buffer[i];
196 }
197 return 0;
198}
199#endif
200
201uint8_t matrix_scan(void)
202{
203 int ret = _matrix_scan();
204
205
206
207#ifdef USE_I2C
208 if( i2c_transaction() ) {
209#else // USE_SERIAL
210 if( serial_transaction() ) {
211#endif
212 // turn on the indicator led when halves are disconnected
213 TXLED1;
214
215 error_count++;
216
217 if (error_count > ERROR_DISCONNECT_COUNT) {
218 // reset other half if disconnected
219 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
220 for (int i = 0; i < ROWS_PER_HAND; ++i) {
221 matrix[slaveOffset+i] = 0;
222 }
223 }
224 } else {
225 // turn off the indicator led on no error
226 TXLED0;
227 error_count = 0;
228 }
229
230 matrix_scan_quantum();
231
232 return ret;
233}
234
235void matrix_slave_scan(void) {
236 _matrix_scan();
237
238 int offset = (isLeftHand) ? 0 : (MATRIX_ROWS / 2);
239
240#ifdef USE_I2C
241 for (int i = 0; i < ROWS_PER_HAND; ++i) {
242 /* i2c_slave_buffer[i] = matrix[offset+i]; */
243 i2c_slave_buffer[i] = matrix[offset+i];
244 }
245#else // USE_SERIAL
246 for (int i = 0; i < ROWS_PER_HAND; ++i) {
247 serial_slave_buffer[i] = matrix[offset+i];
248 }
249#endif
250}
251
252bool matrix_is_modified(void)
253{
254 if (debouncing) return false;
255 return true;
256}
257
258inline
259bool matrix_is_on(uint8_t row, uint8_t col)
260{
261 return (matrix[row] & ((matrix_row_t)1<<col));
262}
263
264inline
265matrix_row_t matrix_get_row(uint8_t row)
266{
267 return matrix[row];
268}
269
270void matrix_print(void)
271{
272 print("\nr/c 0123456789ABCDEF\n");
273 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
274 phex(row); print(": ");
275 pbin_reverse16(matrix_get_row(row));
276 print("\n");
277 }
278}
279
280uint8_t matrix_key_count(void)
281{
282 uint8_t count = 0;
283 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
284 count += bitpop16(matrix[i]);
285 }
286 return count;
287}
288
289static void init_cols(void)
290{
291 for(int x = 0; x < MATRIX_COLS; x++) {
292 _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF);
293 _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF);
294 }
295}
296
297static matrix_row_t read_cols(void)
298{
299 matrix_row_t result = 0;
300 for(int x = 0; x < MATRIX_COLS; x++) {
301 result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x);
302 }
303 return result;
304}
305
306static void unselect_rows(void)
307{
308 for(int x = 0; x < ROWS_PER_HAND; x++) {
309 _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF);
310 _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF);
311 }
312}
313
314static void select_row(uint8_t row)
315{
316 _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF);
317 _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF);
318}
diff --git a/keyboards/minidox/minidox.c b/keyboards/minidox/minidox.c
new file mode 100644
index 000000000..b4bffbb3e
--- /dev/null
+++ b/keyboards/minidox/minidox.c
@@ -0,0 +1 @@
#include "minidox.h" \ No newline at end of file
diff --git a/keyboards/minidox/minidox.h b/keyboards/minidox/minidox.h
new file mode 100644
index 000000000..479c7aec7
--- /dev/null
+++ b/keyboards/minidox/minidox.h
@@ -0,0 +1,10 @@
1#ifndef MINIDOX_H
2#define MINIDOX_H
3
4#ifdef SUBPROJECT_rev1
5 #include "rev1.h"
6#endif
7
8#include "quantum.h"
9
10#endif \ No newline at end of file
diff --git a/keyboards/minidox/pro_micro.h b/keyboards/minidox/pro_micro.h
new file mode 100644
index 000000000..f9e7ed75d
--- /dev/null
+++ b/keyboards/minidox/pro_micro.h
@@ -0,0 +1,362 @@
1/*
2 pins_arduino.h - Pin definition functions for Arduino
3 Part of Arduino - http://www.arduino.cc/
4
5 Copyright (c) 2007 David A. Mellis
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General
18 Public License along with this library; if not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 Boston, MA 02111-1307 USA
21
22 $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
23*/
24
25#ifndef Pins_Arduino_h
26#define Pins_Arduino_h
27
28#include <avr/pgmspace.h>
29
30// Workaround for wrong definitions in "iom32u4.h".
31// This should be fixed in the AVR toolchain.
32#undef UHCON
33#undef UHINT
34#undef UHIEN
35#undef UHADDR
36#undef UHFNUM
37#undef UHFNUML
38#undef UHFNUMH
39#undef UHFLEN
40#undef UPINRQX
41#undef UPINTX
42#undef UPNUM
43#undef UPRST
44#undef UPCONX
45#undef UPCFG0X
46#undef UPCFG1X
47#undef UPSTAX
48#undef UPCFG2X
49#undef UPIENX
50#undef UPDATX
51#undef TCCR2A
52#undef WGM20
53#undef WGM21
54#undef COM2B0
55#undef COM2B1
56#undef COM2A0
57#undef COM2A1
58#undef TCCR2B
59#undef CS20
60#undef CS21
61#undef CS22
62#undef WGM22
63#undef FOC2B
64#undef FOC2A
65#undef TCNT2
66#undef TCNT2_0
67#undef TCNT2_1
68#undef TCNT2_2
69#undef TCNT2_3
70#undef TCNT2_4
71#undef TCNT2_5
72#undef TCNT2_6
73#undef TCNT2_7
74#undef OCR2A
75#undef OCR2_0
76#undef OCR2_1
77#undef OCR2_2
78#undef OCR2_3
79#undef OCR2_4
80#undef OCR2_5
81#undef OCR2_6
82#undef OCR2_7
83#undef OCR2B
84#undef OCR2_0
85#undef OCR2_1
86#undef OCR2_2
87#undef OCR2_3
88#undef OCR2_4
89#undef OCR2_5
90#undef OCR2_6
91#undef OCR2_7
92
93#define NUM_DIGITAL_PINS 30
94#define NUM_ANALOG_INPUTS 12
95
96#define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
97#define TXLED0 PORTD |= (1<<5)
98#define TXLED1 PORTD &= ~(1<<5)
99#define RXLED0 PORTB |= (1<<0)
100#define RXLED1 PORTB &= ~(1<<0)
101
102static const uint8_t SDA = 2;
103static const uint8_t SCL = 3;
104#define LED_BUILTIN 13
105
106// Map SPI port to 'new' pins D14..D17
107static const uint8_t SS = 17;
108static const uint8_t MOSI = 16;
109static const uint8_t MISO = 14;
110static const uint8_t SCK = 15;
111
112// Mapping of analog pins as digital I/O
113// A6-A11 share with digital pins
114static const uint8_t ADC0 = 18;
115static const uint8_t ADC1 = 19;
116static const uint8_t ADC2 = 20;
117static const uint8_t ADC3 = 21;
118static const uint8_t ADC4 = 22;
119static const uint8_t ADC5 = 23;
120static const uint8_t ADC6 = 24; // D4
121static const uint8_t ADC7 = 25; // D6
122static const uint8_t ADC8 = 26; // D8
123static const uint8_t ADC9 = 27; // D9
124static const uint8_t ADC10 = 28; // D10
125static const uint8_t ADC11 = 29; // D12
126
127#define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
128#define digitalPinToPCICRbit(p) 0
129#define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
130#define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
131
132// __AVR_ATmega32U4__ has an unusual mapping of pins to channels
133extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
134#define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
135
136#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
137
138#ifdef ARDUINO_MAIN
139
140// On the Arduino board, digital pins are also used
141// for the analog output (software PWM). Analog input
142// pins are a separate set.
143
144// ATMEL ATMEGA32U4 / ARDUINO LEONARDO
145//
146// D0 PD2 RXD1/INT2
147// D1 PD3 TXD1/INT3
148// D2 PD1 SDA SDA/INT1
149// D3# PD0 PWM8/SCL OC0B/SCL/INT0
150// D4 A6 PD4 ADC8
151// D5# PC6 ??? OC3A/#OC4A
152// D6# A7 PD7 FastPWM #OC4D/ADC10
153// D7 PE6 INT6/AIN0
154//
155// D8 A8 PB4 ADC11/PCINT4
156// D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
157// D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
158// D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
159// D12 A11 PD6 T1/#OC4D/ADC9
160// D13# PC7 PWM10 CLK0/OC4A
161//
162// A0 D18 PF7 ADC7
163// A1 D19 PF6 ADC6
164// A2 D20 PF5 ADC5
165// A3 D21 PF4 ADC4
166// A4 D22 PF1 ADC1
167// A5 D23 PF0 ADC0
168//
169// New pins D14..D17 to map SPI port to digital pins
170//
171// MISO D14 PB3 MISO,PCINT3
172// SCK D15 PB1 SCK,PCINT1
173// MOSI D16 PB2 MOSI,PCINT2
174// SS D17 PB0 RXLED,SS/PCINT0
175//
176// Connected LEDs on board for TX and RX
177// TXLED D24 PD5 XCK1
178// RXLED D17 PB0
179// HWB PE2 HWB
180
181// these arrays map port names (e.g. port B) to the
182// appropriate addresses for various functions (e.g. reading
183// and writing)
184const uint16_t PROGMEM port_to_mode_PGM[] = {
185 NOT_A_PORT,
186 NOT_A_PORT,
187 (uint16_t) &DDRB,
188 (uint16_t) &DDRC,
189 (uint16_t) &DDRD,
190 (uint16_t) &DDRE,
191 (uint16_t) &DDRF,
192};
193
194const uint16_t PROGMEM port_to_output_PGM[] = {
195 NOT_A_PORT,
196 NOT_A_PORT,
197 (uint16_t) &PORTB,
198 (uint16_t) &PORTC,
199 (uint16_t) &PORTD,
200 (uint16_t) &PORTE,
201 (uint16_t) &PORTF,
202};
203
204const uint16_t PROGMEM port_to_input_PGM[] = {
205 NOT_A_PORT,
206 NOT_A_PORT,
207 (uint16_t) &PINB,
208 (uint16_t) &PINC,
209 (uint16_t) &PIND,
210 (uint16_t) &PINE,
211 (uint16_t) &PINF,
212};
213
214const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
215 PD, // D0 - PD2
216 PD, // D1 - PD3
217 PD, // D2 - PD1
218 PD, // D3 - PD0
219 PD, // D4 - PD4
220 PC, // D5 - PC6
221 PD, // D6 - PD7
222 PE, // D7 - PE6
223
224 PB, // D8 - PB4
225 PB, // D9 - PB5
226 PB, // D10 - PB6
227 PB, // D11 - PB7
228 PD, // D12 - PD6
229 PC, // D13 - PC7
230
231 PB, // D14 - MISO - PB3
232 PB, // D15 - SCK - PB1
233 PB, // D16 - MOSI - PB2
234 PB, // D17 - SS - PB0
235
236 PF, // D18 - A0 - PF7
237 PF, // D19 - A1 - PF6
238 PF, // D20 - A2 - PF5
239 PF, // D21 - A3 - PF4
240 PF, // D22 - A4 - PF1
241 PF, // D23 - A5 - PF0
242
243 PD, // D24 - PD5
244 PD, // D25 / D6 - A7 - PD7
245 PB, // D26 / D8 - A8 - PB4
246 PB, // D27 / D9 - A9 - PB5
247 PB, // D28 / D10 - A10 - PB6
248 PD, // D29 / D12 - A11 - PD6
249};
250
251const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
252 _BV(2), // D0 - PD2
253 _BV(3), // D1 - PD3
254 _BV(1), // D2 - PD1
255 _BV(0), // D3 - PD0
256 _BV(4), // D4 - PD4
257 _BV(6), // D5 - PC6
258 _BV(7), // D6 - PD7
259 _BV(6), // D7 - PE6
260
261 _BV(4), // D8 - PB4
262 _BV(5), // D9 - PB5
263 _BV(6), // D10 - PB6
264 _BV(7), // D11 - PB7
265 _BV(6), // D12 - PD6
266 _BV(7), // D13 - PC7
267
268 _BV(3), // D14 - MISO - PB3
269 _BV(1), // D15 - SCK - PB1
270 _BV(2), // D16 - MOSI - PB2
271 _BV(0), // D17 - SS - PB0
272
273 _BV(7), // D18 - A0 - PF7
274 _BV(6), // D19 - A1 - PF6
275 _BV(5), // D20 - A2 - PF5
276 _BV(4), // D21 - A3 - PF4
277 _BV(1), // D22 - A4 - PF1
278 _BV(0), // D23 - A5 - PF0
279
280 _BV(5), // D24 - PD5
281 _BV(7), // D25 / D6 - A7 - PD7
282 _BV(4), // D26 / D8 - A8 - PB4
283 _BV(5), // D27 / D9 - A9 - PB5
284 _BV(6), // D28 / D10 - A10 - PB6
285 _BV(6), // D29 / D12 - A11 - PD6
286};
287
288const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
289 NOT_ON_TIMER,
290 NOT_ON_TIMER,
291 NOT_ON_TIMER,
292 TIMER0B, /* 3 */
293 NOT_ON_TIMER,
294 TIMER3A, /* 5 */
295 TIMER4D, /* 6 */
296 NOT_ON_TIMER,
297
298 NOT_ON_TIMER,
299 TIMER1A, /* 9 */
300 TIMER1B, /* 10 */
301 TIMER0A, /* 11 */
302
303 NOT_ON_TIMER,
304 TIMER4A, /* 13 */
305
306 NOT_ON_TIMER,
307 NOT_ON_TIMER,
308 NOT_ON_TIMER,
309 NOT_ON_TIMER,
310 NOT_ON_TIMER,
311 NOT_ON_TIMER,
312
313 NOT_ON_TIMER,
314 NOT_ON_TIMER,
315 NOT_ON_TIMER,
316 NOT_ON_TIMER,
317 NOT_ON_TIMER,
318 NOT_ON_TIMER,
319 NOT_ON_TIMER,
320 NOT_ON_TIMER,
321 NOT_ON_TIMER,
322 NOT_ON_TIMER,
323};
324
325const uint8_t PROGMEM analog_pin_to_channel_PGM[] = {
326 7, // A0 PF7 ADC7
327 6, // A1 PF6 ADC6
328 5, // A2 PF5 ADC5
329 4, // A3 PF4 ADC4
330 1, // A4 PF1 ADC1
331 0, // A5 PF0 ADC0
332 8, // A6 D4 PD4 ADC8
333 10, // A7 D6 PD7 ADC10
334 11, // A8 D8 PB4 ADC11
335 12, // A9 D9 PB5 ADC12
336 13, // A10 D10 PB6 ADC13
337 9 // A11 D12 PD6 ADC9
338};
339
340#endif /* ARDUINO_MAIN */
341
342// These serial port names are intended to allow libraries and architecture-neutral
343// sketches to automatically default to the correct port name for a particular type
344// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
345// the first hardware serial port whose RX/TX pins are not dedicated to another use.
346//
347// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
348//
349// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
350//
351// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
352//
353// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
354//
355// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
356// pins are NOT connected to anything by default.
357#define SERIAL_PORT_MONITOR Serial
358#define SERIAL_PORT_USBVIRTUAL Serial
359#define SERIAL_PORT_HARDWARE Serial1
360#define SERIAL_PORT_HARDWARE_OPEN Serial1
361
362#endif /* Pins_Arduino_h */
diff --git a/keyboards/minidox/readme.md b/keyboards/minidox/readme.md
new file mode 100644
index 000000000..f6227386d
--- /dev/null
+++ b/keyboards/minidox/readme.md
@@ -0,0 +1,15 @@
1ECO
2===
3
4![MimiDox](http://i.imgur.com/iWb3yO0.jpg)
5
6A compact version of the ErgoDox
7
8Keyboard Maintainer: That-Canadian
9Hardware Supported: MiniDox PCB rev1 Pro Micro
10
11Make example for this keyboard (after setting up your build environment):
12
13 make minidox-rev1-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/minidox/rev1/Makefile b/keyboards/minidox/rev1/Makefile
new file mode 100644
index 000000000..4e2a6f00f
--- /dev/null
+++ b/keyboards/minidox/rev1/Makefile
@@ -0,0 +1,3 @@
1ifndef MAKEFILE_INCLUDED
2 include ../../Makefile
3endif \ No newline at end of file
diff --git a/keyboards/minidox/rev1/config.h b/keyboards/minidox/rev1/config.h
new file mode 100644
index 000000000..a858a5b90
--- /dev/null
+++ b/keyboards/minidox/rev1/config.h
@@ -0,0 +1,38 @@
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#ifndef REV1_CONFIG_H
19#define REV1_CONFIG_H
20
21#include "../config.h"
22
23#define DEVICE_VER 0x0001
24
25// wiring of each half
26#define MATRIX_ROW_PINS { B2, B6, B4, B5 }
27#define MATRIX_COL_PINS { F4, D3, D2, D1, D4 }
28
29#define CATERINA_BOOTLOADER
30
31#define USE_SERIAL
32
33// #define EE_HANDS
34
35#define I2C_MASTER_LEFT
36//#define I2C_MASTER_RIGHT
37
38#endif
diff --git a/keyboards/minidox/rev1/rev1.c b/keyboards/minidox/rev1/rev1.c
new file mode 100644
index 000000000..72b473933
--- /dev/null
+++ b/keyboards/minidox/rev1/rev1.c
@@ -0,0 +1 @@
#include "minidox.h"
diff --git a/keyboards/minidox/rev1/rev1.h b/keyboards/minidox/rev1/rev1.h
new file mode 100644
index 000000000..379dbf64a
--- /dev/null
+++ b/keyboards/minidox/rev1/rev1.h
@@ -0,0 +1,28 @@
1#ifndef REV1_H
2#define REV1_H
3
4#include "../minidox.h"
5
6//void promicro_bootloader_jmp(bool program);
7#include "quantum.h"
8
9//void promicro_bootloader_jmp(bool program);
10
11#define KEYMAP( \
12 k01, k02, k03, k04, k05, k45, k44, k43, k42, k41, \
13 k11, k12, k13, k14, k15, k55, k54, k53, k52, k51, \
14 k21, k22, k23, k24, k25, k65, k64, k63, k62, k61, \
15 k33, k34, k35, k75, k74, k73 \
16 ) \
17 { \
18 { k01, k02, k03, k04, k05 }, \
19 { k11, k12, k13, k14, k15 }, \
20 { k21, k22, k23, k24, k25 }, \
21 { KC_NO, KC_NO, k33, k34, k35 }, \
22 { k41, k42, k43, k44, k45 }, \
23 { k51, k52, k53, k54, k55 }, \
24 { k61, k62, k63, k64, k65 }, \
25 { KC_NO, KC_NO, k73, k74, k75 } \
26 }
27
28#endif \ No newline at end of file
diff --git a/keyboards/minidox/rev1/rules.mk b/keyboards/minidox/rev1/rules.mk
new file mode 100644
index 000000000..a0825b4ef
--- /dev/null
+++ b/keyboards/minidox/rev1/rules.mk
@@ -0,0 +1,5 @@
1BACKLIGHT_ENABLE = no
2
3ifndef QUANTUM_DIR
4 include ../../../Makefile
5endif \ No newline at end of file
diff --git a/keyboards/minidox/rules.mk b/keyboards/minidox/rules.mk
new file mode 100644
index 000000000..539456ae0
--- /dev/null
+++ b/keyboards/minidox/rules.mk
@@ -0,0 +1,74 @@
1SRC += matrix.c \
2 i2c.c \
3 split_util.c \
4 serial.c
5
6# MCU name
7#MCU = at90usb1287
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# LUFA specific
25#
26# Target architecture (see library "Board Types" documentation).
27ARCH = AVR8
28
29# Input clock frequency.
30# This will define a symbol, F_USB, in all source code files equal to the
31# input clock frequency (before any prescaling is performed) in Hz. This value may
32# differ from F_CPU if prescaling is used on the latter, and is required as the
33# raw input clock is fed directly to the PLL sections of the AVR for high speed
34# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
35# at the end, this will be done automatically to create a 32-bit value in your
36# source code.
37#
38# If no clock division is performed on the input clock inside the AVR (via the
39# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
40F_USB = $(F_CPU)
41
42# Interrupt driven control endpoint task(+60)
43OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
44
45
46# Boot Section Size in *bytes*
47# Teensy halfKay 512
48# Teensy++ halfKay 1024
49# Atmel DFU loader 4096
50# LUFA bootloader 4096
51# USBaspLoader 2048
52OPT_DEFS += -DBOOTLOADER_SIZE=4096
53
54# Build Options
55# change to "no" to disable the options, or define them in the Makefile in
56# the appropriate keymap folder that will get included automatically
57#
58BOOTMAGIC_ENABLE ?= no # Virtual DIP switch configuration(+1000)
59MOUSEKEY_ENABLE ?= yes # Mouse keys(+4700)
60EXTRAKEY_ENABLE ?= no # Audio control and System control(+450)
61CONSOLE_ENABLE ?= no # Console for debug(+400)
62COMMAND_ENABLE ?= yes # Commands for debug and configuration
63NKRO_ENABLE ?= no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
64BACKLIGHT_ENABLE ?= no # Enable keyboard backlight functionality
65MIDI_ENABLE ?= no # MIDI controls
66AUDIO_ENABLE ?= no # Audio output on port C6
67UNICODE_ENABLE ?= no # Unicode
68BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID
69RGBLIGHT_ENABLE ?= no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
70USE_I2C ?= no
71# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
72SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend
73
74CUSTOM_MATRIX = yes
diff --git a/keyboards/minidox/serial.c b/keyboards/minidox/serial.c
new file mode 100644
index 000000000..6faed09ce
--- /dev/null
+++ b/keyboards/minidox/serial.c
@@ -0,0 +1,228 @@
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// Serial pulse period in microseconds. Its probably a bad idea to lower this
18// value.
19#define SERIAL_DELAY 24
20
21uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
22uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
23
24#define SLAVE_DATA_CORRUPT (1<<0)
25volatile uint8_t status = 0;
26
27inline static
28void serial_delay(void) {
29 _delay_us(SERIAL_DELAY);
30}
31
32inline static
33void serial_output(void) {
34 SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
35}
36
37// make the serial pin an input with pull-up resistor
38inline static
39void serial_input(void) {
40 SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK;
41 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
42}
43
44inline static
45uint8_t serial_read_pin(void) {
46 return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
47}
48
49inline static
50void serial_low(void) {
51 SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
52}
53
54inline static
55void serial_high(void) {
56 SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
57}
58
59void serial_master_init(void) {
60 serial_output();
61 serial_high();
62}
63
64void serial_slave_init(void) {
65 serial_input();
66
67 // Enable INT0
68 EIMSK |= _BV(INT0);
69 // Trigger on falling edge of INT0
70 EICRA &= ~(_BV(ISC00) | _BV(ISC01));
71}
72
73// Used by the master to synchronize timing with the slave.
74static
75void sync_recv(void) {
76 serial_input();
77 // This shouldn't hang if the slave disconnects because the
78 // serial line will float to high if the slave does disconnect.
79 while (!serial_read_pin());
80 serial_delay();
81}
82
83// Used by the slave to send a synchronization signal to the master.
84static
85void sync_send(void) {
86 serial_output();
87
88 serial_low();
89 serial_delay();
90
91 serial_high();
92}
93
94// Reads a byte from the serial line
95static
96uint8_t serial_read_byte(void) {
97 uint8_t byte = 0;
98 serial_input();
99 for ( uint8_t i = 0; i < 8; ++i) {
100 byte = (byte << 1) | serial_read_pin();
101 serial_delay();
102 _delay_us(1);
103 }
104
105 return byte;
106}
107
108// Sends a byte with MSB ordering
109static
110void serial_write_byte(uint8_t data) {
111 uint8_t b = 8;
112 serial_output();
113 while( b-- ) {
114 if(data & (1 << b)) {
115 serial_high();
116 } else {
117 serial_low();
118 }
119 serial_delay();
120 }
121}
122
123// interrupt handle to be used by the slave device
124ISR(SERIAL_PIN_INTERRUPT) {
125 sync_send();
126
127 uint8_t checksum = 0;
128 for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
129 serial_write_byte(serial_slave_buffer[i]);
130 sync_send();
131 checksum += serial_slave_buffer[i];
132 }
133 serial_write_byte(checksum);
134 sync_send();
135
136 // wait for the sync to finish sending
137 serial_delay();
138
139 // read the middle of pulses
140 _delay_us(SERIAL_DELAY/2);
141
142 uint8_t checksum_computed = 0;
143 for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
144 serial_master_buffer[i] = serial_read_byte();
145 sync_send();
146 checksum_computed += serial_master_buffer[i];
147 }
148 uint8_t checksum_received = serial_read_byte();
149 sync_send();
150
151 serial_input(); // end transaction
152
153 if ( checksum_computed != checksum_received ) {
154 status |= SLAVE_DATA_CORRUPT;
155 } else {
156 status &= ~SLAVE_DATA_CORRUPT;
157 }
158}
159
160inline
161bool serial_slave_DATA_CORRUPT(void) {
162 return status & SLAVE_DATA_CORRUPT;
163}
164
165// Copies the serial_slave_buffer to the master and sends the
166// serial_master_buffer to the slave.
167//
168// Returns:
169// 0 => no error
170// 1 => slave did not respond
171int serial_update_buffers(void) {
172 // this code is very time dependent, so we need to disable interrupts
173 cli();
174
175 // signal to the slave that we want to start a transaction
176 serial_output();
177 serial_low();
178 _delay_us(1);
179
180 // wait for the slaves response
181 serial_input();
182 serial_high();
183 _delay_us(SERIAL_DELAY);
184
185 // check if the slave is present
186 if (serial_read_pin()) {
187 // slave failed to pull the line low, assume not present
188 sei();
189 return 1;
190 }
191
192 // if the slave is present syncronize with it
193 sync_recv();
194
195 uint8_t checksum_computed = 0;
196 // receive data from the slave
197 for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
198 serial_slave_buffer[i] = serial_read_byte();
199 sync_recv();
200 checksum_computed += serial_slave_buffer[i];
201 }
202 uint8_t checksum_received = serial_read_byte();
203 sync_recv();
204
205 if (checksum_computed != checksum_received) {
206 sei();
207 return 1;
208 }
209
210 uint8_t checksum = 0;
211 // send data to the slave
212 for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
213 serial_write_byte(serial_master_buffer[i]);
214 sync_recv();
215 checksum += serial_master_buffer[i];
216 }
217 serial_write_byte(checksum);
218 sync_recv();
219
220 // always, release the line when not in use
221 serial_output();
222 serial_high();
223
224 sei();
225 return 0;
226}
227
228#endif
diff --git a/keyboards/minidox/serial.h b/keyboards/minidox/serial.h
new file mode 100644
index 000000000..15fe4db7b
--- /dev/null
+++ b/keyboards/minidox/serial.h
@@ -0,0 +1,26 @@
1#ifndef MY_SERIAL_H
2#define MY_SERIAL_H
3
4#include "config.h"
5#include <stdbool.h>
6
7/* TODO: some defines for interrupt setup */
8#define SERIAL_PIN_DDR DDRD
9#define SERIAL_PIN_PORT PORTD
10#define SERIAL_PIN_INPUT PIND
11#define SERIAL_PIN_MASK _BV(PD0)
12#define SERIAL_PIN_INTERRUPT INT0_vect
13
14#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
15#define SERIAL_MASTER_BUFFER_LENGTH 1
16
17// Buffers for master - slave communication
18extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
19extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
20
21void serial_master_init(void);
22void serial_slave_init(void);
23int serial_update_buffers(void);
24bool serial_slave_data_corrupt(void);
25
26#endif
diff --git a/keyboards/minidox/split_util.c b/keyboards/minidox/split_util.c
new file mode 100644
index 000000000..461921798
--- /dev/null
+++ b/keyboards/minidox/split_util.c
@@ -0,0 +1,80 @@
1#include <avr/io.h>
2#include <avr/wdt.h>
3#include <avr/power.h>
4#include <avr/interrupt.h>
5#include <util/delay.h>
6#include <avr/eeprom.h>
7#include "split_util.h"
8#include "matrix.h"
9#include "keyboard.h"
10#include "config.h"
11
12#ifdef USE_I2C
13# include "i2c.h"
14#else
15# include "serial.h"
16#endif
17
18volatile bool isLeftHand = true;
19
20static void setup_handedness(void) {
21 #ifdef EE_HANDS
22 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
23 #else
24 #ifdef I2C_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#ifdef USE_I2C
34 i2c_master_init();
35#else
36 serial_master_init();
37#endif
38}
39
40static void keyboard_slave_setup(void) {
41#ifdef USE_I2C
42 i2c_slave_init(SLAVE_I2C_ADDRESS);
43#else
44 serial_slave_init();
45#endif
46}
47
48bool has_usb(void) {
49 USBCON |= (1 << OTGPADE); //enables VBUS pad
50 _delay_us(5);
51 return (USBSTA & (1<<VBUS)); //checks state of VBUS
52}
53
54void split_keyboard_setup(void) {
55 setup_handedness();
56
57 if (has_usb()) {
58 keyboard_master_setup();
59 } else {
60 keyboard_slave_setup();
61 }
62 sei();
63}
64
65void keyboard_slave_loop(void) {
66 matrix_init();
67
68 while (1) {
69 matrix_slave_scan();
70 }
71}
72
73// this code runs before the usb and keyboard is initialized
74void matrix_setup(void) {
75 split_keyboard_setup();
76
77 if (!has_usb()) {
78 keyboard_slave_loop();
79 }
80}
diff --git a/keyboards/minidox/split_util.h b/keyboards/minidox/split_util.h
new file mode 100644
index 000000000..6b896679c
--- /dev/null
+++ b/keyboards/minidox/split_util.h
@@ -0,0 +1,22 @@
1#ifndef SPLIT_KEYBOARD_UTIL_H
2#define SPLIT_KEYBOARD_UTIL_H
3
4#include <stdbool.h>
5
6#ifdef EE_HANDS
7 #define EECONFIG_BOOTMAGIC_END (uint8_t *)10
8 #define EECONFIG_HANDEDNESS EECONFIG_BOOTMAGIC_END
9#endif
10
11#define SLAVE_I2C_ADDRESS 0x32
12
13extern volatile bool isLeftHand;
14
15// slave version of matix scan, defined in matrix.c
16void matrix_slave_scan(void);
17
18void split_keyboard_setup(void);
19bool has_usb(void);
20void keyboard_slave_loop(void);
21
22#endif