aboutsummaryrefslogtreecommitdiff
path: root/keyboards/dc01/left
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/dc01/left')
-rw-r--r--keyboards/dc01/left/config.h152
-rw-r--r--keyboards/dc01/left/i2c.c159
-rw-r--r--keyboards/dc01/left/i2c.h31
-rw-r--r--keyboards/dc01/left/info.json0
-rw-r--r--keyboards/dc01/left/keymaps/default/keymap.c38
-rw-r--r--keyboards/dc01/left/keymaps/default/readme.md9
-rw-r--r--keyboards/dc01/left/left.c43
-rw-r--r--keyboards/dc01/left/left.h41
-rw-r--r--keyboards/dc01/left/matrix.c479
-rw-r--r--keyboards/dc01/left/readme.md15
-rw-r--r--keyboards/dc01/left/rules.mk73
11 files changed, 1040 insertions, 0 deletions
diff --git a/keyboards/dc01/left/config.h b/keyboards/dc01/left/config.h
new file mode 100644
index 000000000..68484d835
--- /dev/null
+++ b/keyboards/dc01/left/config.h
@@ -0,0 +1,152 @@
1/*
2Copyright 2018 Yiancar
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
22/* USB Device descriptor parameter */
23#define VENDOR_ID 0xFEED
24#define PRODUCT_ID 0x1010
25#define DEVICE_VER 0x0001
26#define MANUFACTURER Mechboards
27#define PRODUCT DC01 Left
28#define DESCRIPTION Left half of DC01 keyboard
29
30/* key matrix size */
31#define MATRIX_ROWS 5
32#define MATRIX_COLS 21
33#define MATRIX_COLS_SCANNED 6
34
35/*
36 * Keyboard Matrix Assignments
37 *
38 * Change this to how you wired your keyboard
39 * COLS: AVR pins used for columns, left to right
40 * ROWS: AVR pins used for rows, top to bottom
41 * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
42 * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
43 *
44*/
45#define MATRIX_ROW_PINS { B6, B5, B4, D7, D6 }
46#define MATRIX_COL_PINS { F4, F1, F0, F7, F6, F5 }
47#define UNUSED_PINS
48
49/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
50#define DIODE_DIRECTION COL2ROW
51
52// #define BACKLIGHT_PIN B7
53// #define BACKLIGHT_BREATHING
54// #define BACKLIGHT_LEVELS 3
55
56
57/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
58#define DEBOUNCING_DELAY 5
59
60/* define if matrix has ghost (lacks anti-ghosting diodes) */
61//#define MATRIX_HAS_GHOST
62
63/* number of backlight levels */
64
65/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
66#define LOCKING_SUPPORT_ENABLE
67/* Locking resynchronize hack */
68#define LOCKING_RESYNC_ENABLE
69
70/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
71 * This is userful for the Windows task manager shortcut (ctrl+shift+esc).
72 */
73// #define GRAVE_ESC_CTRL_OVERRIDE
74
75/*
76 * Force NKRO
77 *
78 * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
79 * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
80 * makefile for this to work.)
81 *
82 * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
83 * until the next keyboard reset.
84 *
85 * NKRO may prevent your keystrokes from being detected in the BIOS, but it is
86 * fully operational during normal computer usage.
87 *
88 * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
89 * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
90 * bootmagic, NKRO mode will always be enabled until it is toggled again during a
91 * power-up.
92 *
93 */
94//#define FORCE_NKRO
95
96/*
97 * Magic Key Options
98 *
99 * Magic keys are hotkey commands that allow control over firmware functions of
100 * the keyboard. They are best used in combination with the HID Listen program,
101 * found here: https://www.pjrc.com/teensy/hid_listen.html
102 *
103 * The options below allow the magic key functionality to be changed. This is
104 * useful if your keyboard/keypad is missing keys and you want magic key support.
105 *
106 */
107
108/* key combination for magic key command */
109#define IS_COMMAND() ( \
110 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
111)
112
113/*
114 * Feature disable options
115 * These options are also useful to firmware size reduction.
116 */
117
118/* disable debug print */
119//#define NO_DEBUG
120
121/* disable print */
122//#define NO_PRINT
123
124/* disable action features */
125//#define NO_ACTION_LAYER
126//#define NO_ACTION_TAPPING
127//#define NO_ACTION_ONESHOT
128//#define NO_ACTION_MACRO
129//#define NO_ACTION_FUNCTION
130
131/*
132 * MIDI options
133 */
134
135/* Prevent use of disabled MIDI features in the keymap */
136//#define MIDI_ENABLE_STRICT 1
137
138/* enable basic MIDI features:
139 - MIDI notes can be sent when in Music mode is on
140*/
141//#define MIDI_BASIC
142
143/* enable advanced MIDI features:
144 - MIDI notes can be added to the keymap
145 - Octave shift and transpose
146 - Virtual sustain, portamento, and modulation wheel
147 - etc.
148*/
149//#define MIDI_ADVANCED
150
151/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
152//#define MIDI_TONE_KEYCODE_OCTAVES 1 \ No newline at end of file
diff --git a/keyboards/dc01/left/i2c.c b/keyboards/dc01/left/i2c.c
new file mode 100644
index 000000000..c72789403
--- /dev/null
+++ b/keyboards/dc01/left/i2c.c
@@ -0,0 +1,159 @@
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// Limits the amount of we wait for any one i2c transaction.
10// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
11// 9 bits, a single transaction will take around 90μs to complete.
12//
13// (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit
14// poll loop takes at least 8 clock cycles to execute
15#define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8
16
17#define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE)
18
19volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
20
21static volatile uint8_t slave_buffer_pos;
22static volatile bool slave_has_register_set = false;
23
24// Wait for an i2c operation to finish
25inline static
26void i2c_delay(void) {
27 uint16_t lim = 0;
28 while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT)
29 lim++;
30
31 // easier way, but will wait slightly longer
32 // _delay_us(100);
33}
34
35// Setup twi to run at 100kHz
36void i2c_master_init(void) {
37 // no prescaler
38 TWSR = 0;
39 // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10.
40 // Check datasheets for more info.
41 TWBR = ((F_CPU/SCL_CLOCK)-16)/2;
42}
43
44// Start a transaction with the given i2c slave address. The direction of the
45// transfer is set with I2C_READ and I2C_WRITE.
46// returns: 0 => success
47// 1 => error
48uint8_t i2c_master_start(uint8_t address) {
49 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTA);
50
51 i2c_delay();
52
53 // check that we started successfully
54 if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START))
55 return 1;
56
57 TWDR = address;
58 TWCR = (1<<TWINT) | (1<<TWEN);
59
60 i2c_delay();
61
62 if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) )
63 return 1; // slave did not acknowledge
64 else
65 return 0; // success
66}
67
68
69// Finish the i2c transaction.
70void i2c_master_stop(void) {
71 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
72
73 uint16_t lim = 0;
74 while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT)
75 lim++;
76}
77
78// Write one byte to the i2c slave.
79// returns 0 => slave ACK
80// 1 => slave NACK
81uint8_t i2c_master_write(uint8_t data) {
82 TWDR = data;
83 TWCR = (1<<TWINT) | (1<<TWEN);
84
85 i2c_delay();
86
87 // check if the slave acknowledged us
88 return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1;
89}
90
91// Read one byte from the i2c slave. If ack=1 the slave is acknowledged,
92// if ack=0 the acknowledge bit is not set.
93// returns: byte read from i2c device
94uint8_t i2c_master_read(int ack) {
95 TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA);
96
97 i2c_delay();
98 return TWDR;
99}
100
101void i2c_reset_state(void) {
102 TWCR = 0;
103}
104
105void i2c_slave_init(uint8_t address) {
106 TWAR = address << 0; // slave i2c address
107 // TWEN - twi enable
108 // TWEA - enable address acknowledgement
109 // TWINT - twi interrupt flag
110 // TWIE - enable the twi interrupt
111 TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN);
112}
113
114ISR(TWI_vect);
115
116ISR(TWI_vect) {
117 uint8_t ack = 1;
118 switch(TW_STATUS) {
119 case TW_SR_SLA_ACK:
120 // this device has been addressed as a slave receiver
121 slave_has_register_set = false;
122 break;
123
124 case TW_SR_DATA_ACK:
125 // this device has received data as a slave receiver
126 // The first byte that we receive in this transaction sets the location
127 // of the read/write location of the slaves memory that it exposes over
128 // i2c. After that, bytes will be written at slave_buffer_pos, incrementing
129 // slave_buffer_pos after each write.
130 if(!slave_has_register_set) {
131 slave_buffer_pos = TWDR;
132 // don't acknowledge the master if this memory loctaion is out of bounds
133 if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) {
134 ack = 0;
135 slave_buffer_pos = 0;
136 }
137 slave_has_register_set = true;
138 } else {
139 i2c_slave_buffer[slave_buffer_pos] = TWDR;
140 BUFFER_POS_INC();
141 }
142 break;
143
144 case TW_ST_SLA_ACK:
145 case TW_ST_DATA_ACK:
146 // master has addressed this device as a slave transmitter and is
147 // requesting data.
148 TWDR = i2c_slave_buffer[slave_buffer_pos];
149 BUFFER_POS_INC();
150 break;
151
152 case TW_BUS_ERROR: // something went wrong, reset twi state
153 TWCR = 0;
154 default:
155 break;
156 }
157 // Reset everything, so we are ready for the next TWI interrupt
158 TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
159}
diff --git a/keyboards/dc01/left/i2c.h b/keyboards/dc01/left/i2c.h
new file mode 100644
index 000000000..25e876658
--- /dev/null
+++ b/keyboards/dc01/left/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 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#endif
diff --git a/keyboards/dc01/left/info.json b/keyboards/dc01/left/info.json
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/keyboards/dc01/left/info.json
diff --git a/keyboards/dc01/left/keymaps/default/keymap.c b/keyboards/dc01/left/keymaps/default/keymap.c
new file mode 100644
index 000000000..07db66c8e
--- /dev/null
+++ b/keyboards/dc01/left/keymaps/default/keymap.c
@@ -0,0 +1,38 @@
1/* Copyright 2018 Yiancar
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
18const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
19[0] = LAYOUT_ANSI( /* Base */
20 KC_ESC, 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, KC_INS, KC_HOME, KC_PGUP, KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, \
21 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, KC_DEL, KC_END, KC_PGDN, KC_P7, KC_P8, KC_P9, KC_PPLS, \
22 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, KC_P4, KC_P5, KC_P6, KC_NO, \
23 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, KC_P1, KC_P2, KC_P3, \
24 KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_SPC, KC_SPC, KC_RALT, KC_RGUI, KC_RGUI, KC_RCTL, KC_LEFT, KC_DOWN, KC_RIGHT, KC_P0, KC_NO, KC_PDOT, KC_PENT \
25),
26};
27
28void matrix_init_user(void) {
29
30}
31
32void matrix_scan_user(void) {
33
34}
35
36bool process_record_user(uint16_t keycode, keyrecord_t *record) {
37 return true;
38} \ No newline at end of file
diff --git a/keyboards/dc01/left/keymaps/default/readme.md b/keyboards/dc01/left/keymaps/default/readme.md
new file mode 100644
index 000000000..36207e511
--- /dev/null
+++ b/keyboards/dc01/left/keymaps/default/readme.md
@@ -0,0 +1,9 @@
1# The default ANSI keymap for DC01 Left
2
3The keymap looks like a full layout keymap.
4
5This is because the left part of the keyboard acts as the masterm coordinating all four part.
6
7When using the keyboard to connect the other three parts, this keymap overwrites the individual keymaps of the single modules.
8
9When using a module individually, the keymap of that module will take effect.
diff --git a/keyboards/dc01/left/left.c b/keyboards/dc01/left/left.c
new file mode 100644
index 000000000..1d8da186b
--- /dev/null
+++ b/keyboards/dc01/left/left.c
@@ -0,0 +1,43 @@
1/* Copyright 2018 Yiancar
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 "left.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/dc01/left/left.h b/keyboards/dc01/left/left.h
new file mode 100644
index 000000000..82b0c6995
--- /dev/null
+++ b/keyboards/dc01/left/left.h
@@ -0,0 +1,41 @@
1/* Copyright 2018 Yiancar
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 LEFT_H
17#define LEFT_H
18
19#include "quantum.h"
20
21#define XXX KC_NO
22
23// This a shortcut to help you visually see your layout.
24// The first section contains all of the arguments
25// The second converts the arguments into a two-dimensional array
26#define LAYOUT_ANSI( \
27 K00, K01, K02, K03, K04, K05, K45, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G, K0H, K0J, K0K, K0L, \
28 K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, K1F, K1G, K1H, K1J, K1K, K1L, \
29 K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, K2H, K2J, K2K, K2L, \
30 K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3D, K3F, K3H, K3J, K3K, \
31 K40, K41, K42, K43, K46, K47, K48, K49, K4A, K4B, K4E, K4F, K4G, K4H, K4J, K4K, K4L \
32) \
33{ \
34 { K00, K01, K02, K03, K04, K05, XXX, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G, K0H, K0J, K0K, K0L }, \
35 { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, K1F, K1G, K1H, K1J, K1K, K1L }, \
36 { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, XXX, K2D, XXX, XXX, XXX, K2H, K2J, K2K, K2L }, \
37 { K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, XXX, XXX, K3D, XXX, K3F, XXX, K3H, K3J, K3K, XXX }, \
38 { K40, K41, K42, K43, XXX, K45, K46, K47, K48, K49, K4A, K4B, XXX, XXX, K4E, K4F, K4G, K4H, K4J, K4K, K4L } \
39}
40
41#endif
diff --git a/keyboards/dc01/left/matrix.c b/keyboards/dc01/left/matrix.c
new file mode 100644
index 000000000..792376635
--- /dev/null
+++ b/keyboards/dc01/left/matrix.c
@@ -0,0 +1,479 @@
1/*
2Copyright 2012 Jun Wako
3Copyright 2014 Jack Humbert
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include <stdint.h>
19#include <stdbool.h>
20#if defined(__AVR__)
21#include <avr/io.h>
22#include <avr/wdt.h>
23#include <avr/interrupt.h>
24#include <util/delay.h>
25#endif
26#include "wait.h"
27#include "print.h"
28#include "debug.h"
29#include "util.h"
30#include "matrix.h"
31#include "timer.h"
32#include "i2c_master.h"
33
34#define SLAVE_I2C_ADDRESS_RIGHT 0x19
35#define SLAVE_I2C_ADDRESS_NUMPAD 0x21
36#define SLAVE_I2C_ADDRESS_ARROW 0x23
37
38#define ERROR_DISCONNECT_COUNT 5
39static uint8_t error_count_right = 0;
40static uint8_t error_count_numpad = 0;
41static uint8_t error_count_arrow = 0;
42
43/* Set 0 if debouncing isn't needed */
44
45#ifndef DEBOUNCING_DELAY
46# define DEBOUNCING_DELAY 5
47#endif
48
49#if (DEBOUNCING_DELAY > 0)
50 static uint16_t debouncing_time;
51 static bool debouncing = false;
52#endif
53
54#if (MATRIX_COLS <= 8)
55# define print_matrix_header() print("\nr/c 01234567\n")
56# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
57# define matrix_bitpop(i) bitpop(matrix[i])
58# define ROW_SHIFTER ((uint8_t)1)
59#elif (MATRIX_COLS <= 16)
60# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
61# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
62# define matrix_bitpop(i) bitpop16(matrix[i])
63# define ROW_SHIFTER ((uint16_t)1)
64#elif (MATRIX_COLS <= 32)
65# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
66# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
67# define matrix_bitpop(i) bitpop32(matrix[i])
68# define ROW_SHIFTER ((uint32_t)1)
69#endif
70
71#ifdef MATRIX_MASKED
72 extern const matrix_row_t matrix_mask[];
73#endif
74
75#if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
76static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
77static const uint8_t col_pins[MATRIX_COLS_SCANNED] = MATRIX_COL_PINS;
78#endif
79
80/* matrix state(1:on, 0:off) */
81static matrix_row_t matrix[MATRIX_ROWS];
82
83static matrix_row_t matrix_debouncing[MATRIX_ROWS];
84
85
86#if (DIODE_DIRECTION == COL2ROW)
87 static void init_cols(void);
88 static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row);
89 static void unselect_rows(void);
90 static void select_row(uint8_t row);
91 static void unselect_row(uint8_t row);
92#elif (DIODE_DIRECTION == ROW2COL)
93 static void init_rows(void);
94 static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col);
95 static void unselect_cols(void);
96 static void unselect_col(uint8_t col);
97 static void select_col(uint8_t col);
98#endif
99
100__attribute__ ((weak))
101void matrix_init_quantum(void) {
102 matrix_init_kb();
103}
104
105__attribute__ ((weak))
106void matrix_scan_quantum(void) {
107 matrix_scan_kb();
108}
109
110__attribute__ ((weak))
111void matrix_init_kb(void) {
112 matrix_init_user();
113}
114
115__attribute__ ((weak))
116void matrix_scan_kb(void) {
117 matrix_scan_user();
118}
119
120__attribute__ ((weak))
121void matrix_init_user(void) {
122}
123
124__attribute__ ((weak))
125void matrix_scan_user(void) {
126}
127
128inline
129uint8_t matrix_rows(void) {
130 return MATRIX_ROWS;
131}
132
133inline
134uint8_t matrix_cols(void) {
135 return MATRIX_COLS;
136}
137
138
139i2c_status_t i2c_transaction(uint8_t address, uint32_t mask, uint8_t col_offset);
140//uint8_t i2c_transaction_numpad(void);
141//uint8_t i2c_transaction_arrow(void);
142
143//this replases tmk code
144void matrix_setup(void){
145 i2c_init();
146}
147
148void matrix_init(void) {
149
150 // initialize row and col
151#if (DIODE_DIRECTION == COL2ROW)
152 unselect_rows();
153 init_cols();
154#elif (DIODE_DIRECTION == ROW2COL)
155 unselect_cols();
156 init_rows();
157#endif
158
159 // initialize matrix state: all keys off
160 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
161 matrix[i] = 0;
162 matrix_debouncing[i] = 0;
163 }
164
165 matrix_init_quantum();
166}
167
168uint8_t matrix_scan(void)
169{
170
171#if (DIODE_DIRECTION == COL2ROW)
172
173 // Set row, read cols
174 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
175# if (DEBOUNCING_DELAY > 0)
176 bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row);
177
178 if (matrix_changed) {
179 debouncing = true;
180 debouncing_time = timer_read();
181 }
182
183# else
184 read_cols_on_row(matrix, current_row);
185# endif
186
187 }
188
189#elif (DIODE_DIRECTION == ROW2COL)
190
191 // Set col, read rows
192 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
193# if (DEBOUNCING_DELAY > 0)
194 bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col);
195 if (matrix_changed) {
196 debouncing = true;
197 debouncing_time = timer_read();
198 }
199# else
200 read_rows_on_col(matrix, current_col);
201# endif
202
203 }
204
205#endif
206
207# if (DEBOUNCING_DELAY > 0)
208 if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
209 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
210 matrix[i] = matrix_debouncing[i];
211 }
212 debouncing = false;
213 }
214# endif
215
216 if (i2c_transaction(SLAVE_I2C_ADDRESS_RIGHT, 0x3F, 0)){ //error has occured for main right half
217 error_count_right++;
218 if (error_count_right > ERROR_DISCONNECT_COUNT){ //disconnect half
219 for (uint8_t i = 0; i < MATRIX_ROWS ; i++) {
220 matrix[i] &= 0x3F; //mask bits to keep
221 }
222 }
223 }else{ //no error
224 error_count_right = 0;
225 }
226
227 if (i2c_transaction(SLAVE_I2C_ADDRESS_ARROW, 0X3FFF, 8)){ //error has occured for arrow cluster
228 error_count_arrow++;
229 if (error_count_arrow > ERROR_DISCONNECT_COUNT){ //disconnect arrow cluster
230 for (uint8_t i = 0; i < MATRIX_ROWS ; i++) {
231 matrix[i] &= 0x3FFF; //mask bits to keep
232 }
233 }
234 }else{ //no error
235 error_count_arrow = 0;
236 }
237
238 if (i2c_transaction(SLAVE_I2C_ADDRESS_NUMPAD, 0x1FFFF, 11)){ //error has occured for numpad
239 error_count_numpad++;
240 if (error_count_numpad > ERROR_DISCONNECT_COUNT){ //disconnect numpad
241 for (uint8_t i = 0; i < MATRIX_ROWS ; i++) {
242 matrix[i] &= 0x1FFFF; //mask bits to keep
243 }
244 }
245 }else{ //no error
246 error_count_numpad = 0;
247 }
248
249 matrix_scan_quantum();
250 return 1;
251}
252
253bool matrix_is_modified(void)
254{
255#if (DEBOUNCING_DELAY > 0)
256 if (debouncing) return false;
257#endif
258 return true;
259}
260
261inline
262bool matrix_is_on(uint8_t row, uint8_t col)
263{
264 return (matrix[row] & ((matrix_row_t)1<col));
265}
266
267inline
268matrix_row_t matrix_get_row(uint8_t row)
269{
270 // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
271 // switch blocker installed and the switch is always pressed.
272#ifdef MATRIX_MASKED
273 return matrix[row] & matrix_mask[row];
274#else
275 return matrix[row];
276#endif
277}
278
279void matrix_print(void)
280{
281 print_matrix_header();
282
283 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
284 phex(row); print(": ");
285 print_matrix_row(row);
286 print("\n");
287 }
288}
289
290uint8_t matrix_key_count(void)
291{
292 uint8_t count = 0;
293 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
294 count += matrix_bitpop(i);
295 }
296 return count;
297}
298
299
300
301#if (DIODE_DIRECTION == COL2ROW)
302
303static void init_cols(void)
304{
305 for(uint8_t x = 0; x < MATRIX_COLS_SCANNED; x++) {
306 uint8_t pin = col_pins[x];
307 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
308 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
309 }
310}
311
312static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
313{
314 // Store last value of row prior to reading
315 matrix_row_t last_row_value = current_matrix[current_row];
316
317 // Clear data in matrix row
318 current_matrix[current_row] = 0;
319
320 // Select row and wait for row selecton to stabilize
321 select_row(current_row);
322 wait_us(30);
323
324 // For each col...
325 for(uint8_t col_index = 0; col_index < MATRIX_COLS_SCANNED; col_index++) {
326
327 // Select the col pin to read (active low)
328 uint8_t pin = col_pins[col_index];
329 uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
330
331 // Populate the matrix row with the state of the col pin
332 current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
333 }
334
335 // Unselect row
336 unselect_row(current_row);
337
338 return (last_row_value != current_matrix[current_row]);
339}
340
341static void select_row(uint8_t row)
342{
343 uint8_t pin = row_pins[row];
344 _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
345 _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
346}
347
348static void unselect_row(uint8_t row)
349{
350 uint8_t pin = row_pins[row];
351 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
352 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
353}
354
355static void unselect_rows(void)
356{
357 for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
358 uint8_t pin = row_pins[x];
359 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
360 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
361 }
362}
363
364#elif (DIODE_DIRECTION == ROW2COL)
365
366static void init_rows(void)
367{
368 for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
369 uint8_t pin = row_pins[x];
370 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
371 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
372 }
373}
374
375static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
376{
377 bool matrix_changed = false;
378
379 // Select col and wait for col selecton to stabilize
380 select_col(current_col);
381 wait_us(30);
382
383 // For each row...
384 for(uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++)
385 {
386
387 // Store last value of row prior to reading
388 matrix_row_t last_row_value = current_matrix[row_index];
389
390 // Check row pin state
391 if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0)
392 {
393 // Pin LO, set col bit
394 current_matrix[row_index] |= (ROW_SHIFTER << current_col);
395 }
396 else
397 {
398 // Pin HI, clear col bit
399 current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
400 }
401
402 // Determine if the matrix changed state
403 if ((last_row_value != current_matrix[row_index]) && !(matrix_changed))
404 {
405 matrix_changed = true;
406 }
407 }
408
409 // Unselect col
410 unselect_col(current_col);
411
412 return matrix_changed;
413}
414
415static void select_col(uint8_t col)
416{
417 uint8_t pin = col_pins[col];
418 _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
419 _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
420}
421
422static void unselect_col(uint8_t col)
423{
424 uint8_t pin = col_pins[col];
425 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
426 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
427}
428
429static void unselect_cols(void)
430{
431 for(uint8_t x = 0; x < MATRIX_COLS_SCANNED; x++) {
432 uint8_t pin = col_pins[x];
433 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
434 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
435 }
436}
437
438#endif
439
440// Complete rows from other modules over i2c
441i2c_status_t i2c_transaction(uint8_t address, uint32_t mask, uint8_t col_offset) {
442 i2c_status_t err = i2c_start((address << 1) | I2C_WRITE, 10);
443 if (err) return err;
444 i2c_write(0x01, 10);
445 if (err) return err;
446
447 i2c_start((address << 1) | I2C_READ, 10);
448 if (err) return err;
449
450 err = i2c_read_ack(10);
451 if (err == 0x55) { //synchronization byte
452
453 for (uint8_t i = 0; i < MATRIX_ROWS-1 ; i++) { //assemble slave matrix in main matrix
454 matrix[i] &= mask; //mask bits to keep
455 err = i2c_read_ack(10);
456 if (err >= 0) {
457 matrix[i] |= ((uint32_t)err << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end
458 } else {
459 return err;
460 }
461 }
462 //last read request must be followed by a NACK
463 matrix[MATRIX_ROWS - 1] &= mask; //mask bits to keep
464 err = i2c_read_nack(10);
465 if (err >= 0) {
466 matrix[MATRIX_ROWS - 1] |= ((uint32_t)err << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end
467 } else {
468 return err;
469 }
470 } else {
471 i2c_stop(10);
472 return 1;
473 }
474
475 i2c_stop(10);
476 if (err) return err;
477
478 return 0;
479} \ No newline at end of file
diff --git a/keyboards/dc01/left/readme.md b/keyboards/dc01/left/readme.md
new file mode 100644
index 000000000..1613297d0
--- /dev/null
+++ b/keyboards/dc01/left/readme.md
@@ -0,0 +1,15 @@
1# DC01 Left Half
2
3![DC01 Left Half](https://i.imgur.com/PTn0sp8.jpg)
4
5A hotpluggable four part keyboard which comes together with magnets and pogo pins! This is the left part that also acts as the master.
6
7Keyboard Maintainer: [Yiancar](https://github.com/yiancar)
8Hardware Supported: Runs on an atmega32u4
9Hardware Availability: [Mechboards](https://mechboards.co.uk/)
10
11Make example for this keyboard (after setting up your build environment):
12
13 make dc01/left: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/dc01/left/rules.mk b/keyboards/dc01/left/rules.mk
new file mode 100644
index 000000000..1ea1f275b
--- /dev/null
+++ b/keyboards/dc01/left/rules.mk
@@ -0,0 +1,73 @@
1SRC += matrix.c \
2 ../../../drivers/avr/i2c_master.c
3
4# MCU name
5#MCU = at90usb1286
6MCU = atmega32u4
7
8# Processor frequency.
9# This will define a symbol, F_CPU, in all source code files equal to the
10# processor frequency in Hz. You can then use this symbol in your source code to
11# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
12# automatically to create a 32-bit value in your source code.
13#
14# This will be an integer division of F_USB below, as it is sourced by
15# F_USB after it has run through any CPU prescalers. Note that this value
16# does not *change* the processor frequency - it should merely be updated to
17# reflect the processor speed set externally so that the code can use accurate
18# software delays.
19F_CPU = 16000000
20
21
22#
23# LUFA specific
24#
25# Target architecture (see library "Board Types" documentation).
26ARCH = AVR8
27
28# Input clock frequency.
29# This will define a symbol, F_USB, in all source code files equal to the
30# input clock frequency (before any prescaling is performed) in Hz. This value may
31# differ from F_CPU if prescaling is used on the latter, and is required as the
32# raw input clock is fed directly to the PLL sections of the AVR for high speed
33# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
34# at the end, this will be done automatically to create a 32-bit value in your
35# source code.
36#
37# If no clock division is performed on the input clock inside the AVR (via the
38# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
39F_USB = $(F_CPU)
40
41# Interrupt driven control endpoint task(+60)
42OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
43
44
45# Boot Section Size in *bytes*
46# Teensy halfKay 512
47# Teensy++ halfKay 1024
48# Atmel DFU loader 4096
49# LUFA bootloader 4096
50# USBaspLoader 2048
51OPT_DEFS += -DBOOTLOADER_SIZE=4096
52
53
54# Build Options
55# change yes to no to disable
56#
57BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
58MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
59EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
60CONSOLE_ENABLE = no # Console for debug(+400)
61COMMAND_ENABLE = no # Commands for debug and configuration
62# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
63SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
64# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
65NKRO_ENABLE = yes # USB Nkey Rollover
66BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
67MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
68UNICODE_ENABLE = no # Unicode
69BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
70AUDIO_ENABLE = no # Audio output on port C6
71FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
72HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
73CUSTOM_MATRIX = yes # Use custom matrix