aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2015-08-21 10:46:53 -0400
committerJack Humbert <jack.humb@gmail.com>2015-08-21 10:46:53 -0400
commit04885a3b447c82437d919d467328800eb00af629 (patch)
treeaf1603f20b8d28aee533ccaaed7992ce29619a94
parentfb4fe52c0a5be527e6c9bfa006a5fb3ea79b4b0e (diff)
downloadqmk_firmware-04885a3b447c82437d919d467328800eb00af629.tar.gz
qmk_firmware-04885a3b447c82437d919d467328800eb00af629.zip
preonic
-rw-r--r--common.mk4
-rw-r--r--keyboard/atomic/README.md6
-rw-r--r--keyboard/atomic_old/Makefile135
-rw-r--r--keyboard/atomic_old/Makefile.pjrc116
-rw-r--r--keyboard/atomic_old/README 2.md141
-rw-r--r--keyboard/atomic_old/config.h70
-rw-r--r--keyboard/atomic_old/keymap_common.c30
-rw-r--r--keyboard/atomic_old/keymap_common.h87
-rw-r--r--keyboard/atomic_old/keymap_plain.c46
-rw-r--r--keyboard/atomic_old/keymap_ricky.c15
-rw-r--r--keyboard/atomic_old/keymap_vlad.c14
-rw-r--r--keyboard/atomic_old/led.c25
-rw-r--r--keyboard/atomic_old/matrix.c211
-rw-r--r--keyboard/planck/Makefile6
-rw-r--r--keyboard/planck/config.h5
-rw-r--r--keyboard/planck/config_definitions.h50
-rw-r--r--keyboard/planck/extended_keymaps/extended_keymap_default.c15
-rw-r--r--keyboard/planck/matrix.c235
-rw-r--r--keyboard/preonic/Makefile138
-rw-r--r--keyboard/preonic/Makefile.pjrc116
-rw-r--r--keyboard/preonic/PCB_GUIDE.md116
-rw-r--r--keyboard/preonic/README.md56
-rw-r--r--keyboard/preonic/__avr_gdbinit6
-rw-r--r--keyboard/preonic/analog.c53
-rw-r--r--keyboard/preonic/analog.h36
-rw-r--r--keyboard/preonic/backlight.c61
-rw-r--r--keyboard/preonic/beeps.c238
-rw-r--r--keyboard/preonic/beeps.h9
-rw-r--r--keyboard/preonic/config.h76
-rw-r--r--keyboard/preonic/config_definitions.h50
-rw-r--r--keyboard/preonic/extended_keymap_common.c210
-rw-r--r--keyboard/preonic/extended_keymap_common.h180
-rw-r--r--keyboard/preonic/extended_keymaps/extended_keymap_default.c65
-rw-r--r--keyboard/preonic/extended_keymaps/extended_keymap_lock.c73
-rw-r--r--keyboard/preonic/led.c38
-rw-r--r--keyboard/preonic/matrix.c234
-rw-r--r--protocol/lufa/descriptor.c11
-rw-r--r--protocol/lufa/descriptor.h18
-rw-r--r--protocol/lufa/lufa.c61
-rwxr-xr-xprotocol/lufa/midi/Config/LUFAConfig.h93
40 files changed, 3111 insertions, 38 deletions
diff --git a/common.mk b/common.mk
index b854f09cd..e61ae69e5 100644
--- a/common.mk
+++ b/common.mk
@@ -49,6 +49,10 @@ ifdef NKRO_ENABLE
49 OPT_DEFS += -DNKRO_ENABLE 49 OPT_DEFS += -DNKRO_ENABLE
50endif 50endif
51 51
52ifdef MIDI_ENABLE
53 OPT_DEFS += -DMIDI_ENABLE
54endif
55
52ifdef USB_6KRO_ENABLE 56ifdef USB_6KRO_ENABLE
53 OPT_DEFS += -DUSB_6KRO_ENABLE 57 OPT_DEFS += -DUSB_6KRO_ENABLE
54endif 58endif
diff --git a/keyboard/atomic/README.md b/keyboard/atomic/README.md
index ee824d26e..3ddaed3a3 100644
--- a/keyboard/atomic/README.md
+++ b/keyboard/atomic/README.md
@@ -1,9 +1,9 @@
1Planck keyboard firmware 1Atomic keyboard firmware
2====================== 2======================
3DIY/Assembled compact ortholinear 40% keyboard by [Ortholinear Keyboards](http://ortholinearkeyboards.com). 3DIY/Assembled ortholinear 60% keyboard by [Ortholinear Keyboards](http://ortholinearkeyboards.com).
4 4
5## Extended Keymap 5## Extended Keymap
6If you include extended_keymap_common.h instead of keymap_common.h at the top of your file, you'll have access to a bunch of goodies: 6If you include extended_keymap_common.h instead of keymap_common.h at the top of your file, you'll have access to a bunch of goodies:t
7 7
8- Use `LSFT()`, `LCTL()`, et. al. (listed in extended_keymap_common.h) as modifiers for keys (daisy-chain-able) 8- Use `LSFT()`, `LCTL()`, et. al. (listed in extended_keymap_common.h) as modifiers for keys (daisy-chain-able)
9- Use `FUNC(1)` instead of `FN1` (etc.) to access the function layers beyond the 32 function layer limit 9- Use `FUNC(1)` instead of `FN1` (etc.) to access the function layers beyond the 32 function layer limit
diff --git a/keyboard/atomic_old/Makefile b/keyboard/atomic_old/Makefile
new file mode 100644
index 000000000..c4e0cb45d
--- /dev/null
+++ b/keyboard/atomic_old/Makefile
@@ -0,0 +1,135 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = atomic_lufa
43
44# Directory common source filess exist
45TOP_DIR = ../..
46
47# Directory keyboard dependent files exist
48TARGET_DIR = .
49
50# project specific files
51SRC = keymap_common.c \
52 matrix.c \
53 led.c
54
55ifdef KEYMAP
56 SRC := keymap_$(KEYMAP).c $(SRC)
57else
58 SRC := keymap_vlad.c $(SRC)
59endif
60
61CONFIG_H = config.h
62
63
64# MCU name
65#MCU = at90usb1287
66MCU = atmega32u4
67
68# Processor frequency.
69# This will define a symbol, F_CPU, in all source code files equal to the
70# processor frequency in Hz. You can then use this symbol in your source code to
71# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
72# automatically to create a 32-bit value in your source code.
73#
74# This will be an integer division of F_USB below, as it is sourced by
75# F_USB after it has run through any CPU prescalers. Note that this value
76# does not *change* the processor frequency - it should merely be updated to
77# reflect the processor speed set externally so that the code can use accurate
78# software delays.
79F_CPU = 16000000
80
81
82#
83# LUFA specific
84#
85# Target architecture (see library "Board Types" documentation).
86ARCH = AVR8
87
88# Input clock frequency.
89# This will define a symbol, F_USB, in all source code files equal to the
90# input clock frequency (before any prescaling is performed) in Hz. This value may
91# differ from F_CPU if prescaling is used on the latter, and is required as the
92# raw input clock is fed directly to the PLL sections of the AVR for high speed
93# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
94# at the end, this will be done automatically to create a 32-bit value in your
95# source code.
96#
97# If no clock division is performed on the input clock inside the AVR (via the
98# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
99F_USB = $(F_CPU)
100
101# Interrupt driven control endpoint task(+60)
102OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
103
104
105# Boot Section Size in *bytes*
106# Teensy halfKay 512
107# Teensy++ halfKay 1024
108# Atmel DFU loader 4096
109# LUFA bootloader 4096
110# USBaspLoader 2048
111OPT_DEFS += -DBOOTLOADER_SIZE=4096
112
113
114# Build Options
115# comment out to disable the options.
116#
117BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
118MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
119EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
120CONSOLE_ENABLE = yes # Console for debug(+400)
121COMMAND_ENABLE = yes # Commands for debug and configuration
122#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
123NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
124
125
126# Optimize size but this may cause error "relocation truncated to fit"
127#EXTRALDFLAGS = -Wl,--relax
128
129# Search Path
130VPATH += $(TARGET_DIR)
131VPATH += $(TOP_DIR)
132
133include $(TOP_DIR)/protocol/lufa.mk
134include $(TOP_DIR)/common.mk
135include $(TOP_DIR)/rules.mk
diff --git a/keyboard/atomic_old/Makefile.pjrc b/keyboard/atomic_old/Makefile.pjrc
new file mode 100644
index 000000000..9655ff65a
--- /dev/null
+++ b/keyboard/atomic_old/Makefile.pjrc
@@ -0,0 +1,116 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = gh60_pjrc
43
44# Directory common source filess exist
45TOP_DIR = ../..
46
47# Directory keyboard dependent files exist
48TARGET_DIR = .
49
50# project specific files
51SRC = keymap_common.c \
52 matrix.c \
53 led.c
54
55ifdef KEYMAP
56 SRC := keymap_$(KEYMAP).c $(SRC)
57else
58 SRC := keymap_poker.c $(SRC)
59endif
60
61CONFIG_H = config.h
62
63
64# MCU name, you MUST set this to match the board you are using
65# type "make clean" after changing this, so all files will be rebuilt
66MCU = atmega32u4
67#MCU = at90usb1286
68
69
70# Processor frequency.
71# Normally the first thing your program should do is set the clock prescaler,
72# so your program will run at the correct speed. You should also set this
73# variable to same clock speed. The _delay_ms() macro uses this, and many
74# examples use this variable to calculate timings. Do not add a "UL" here.
75F_CPU = 16000000
76
77
78# Boot Section Size in *bytes*
79# Teensy halfKay 512
80# Atmel DFU loader 4096
81# LUFA bootloader 4096
82OPT_DEFS += -DBOOTLOADER_SIZE=4096
83
84
85# Build Options
86# comment out to disable the options.
87#
88BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
89MOUSEKEY_ENABLE = yes # Mouse keys(+5000)
90EXTRAKEY_ENABLE = yes # Audio control and System control(+600)
91CONSOLE_ENABLE = yes # Console for debug
92COMMAND_ENABLE = yes # Commands for debug and configuration
93SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
94NKRO_ENABLE = yes # USB Nkey Rollover(+500)
95#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
96
97
98# Search Path
99VPATH += $(TARGET_DIR)
100VPATH += $(TOP_DIR)
101
102include $(TOP_DIR)/protocol/pjrc.mk
103include $(TOP_DIR)/common.mk
104include $(TOP_DIR)/rules.mk
105
106plain: OPT_DEFS += -DKEYMAP_PLAIN
107plain: all
108
109poker: OPT_DEFS += -DKEYMAP_POKER
110poker: all
111
112poker_set: OPT_DEFS += -DKEYMAP_POKER_SET
113poker_set: all
114
115poker_bit: OPT_DEFS += -DKEYMAP_POKER_BIT
116poker_bit: all
diff --git a/keyboard/atomic_old/README 2.md b/keyboard/atomic_old/README 2.md
new file mode 100644
index 000000000..510cb5c8b
--- /dev/null
+++ b/keyboard/atomic_old/README 2.md
@@ -0,0 +1,141 @@
1GH60 keyboard firmware
2======================
3DIY compact keyboard designed and run by komar007 and Geekhack community.
4
5- Both Rev.A and Rev.B PCB are supported by one firmware binary(issue #64)
6
7## GH60 Resources
8- [KOMAR's project page](http://blog.komar.be/projects/gh60-programmable-keyboard/)
9- [Prototyping](http://geekhack.org/index.php?topic=34959.0)
10- [Rev.A PCB test](http://geekhack.org/index.php?topic=37570.0)
11- [Rev.B PCB test](http://geekhack.org/index.php?topic=50685.0)
12- [Group buy](http://geekhack.org/index.php?topic=41464.0)
13
14
15## Build
16Move to this directory then just run `make` like:
17
18 $ make
19
20Use `make -f Makefile.pjrc` if you want to use PJRC stack but I find no reason to do so now.
21
22
23## Keymap
24Several version of keymap are available in advance but you are recommended to define your favorite layout yourself. To define your own keymap create file named `keymap_<name>.c` and see keymap document(you can find in top README.md) and existent keymap files.
25
26To build firmware binary hex file with a certain keymap just do `make` with `KEYMAP` option like:
27
28 $ make KEYMAP=[poker|poker_set|poker_bit|plain|hasu|spacefn|hhkb|<name>]
29
30
31### 1 Poker
32[keymap_poker.c](keymap_poker.c) emulates original Poker layers
33while both [keymap_poker_bit.c](keymap_poker_bit.c) and [keymap_poker_set.c](keymap_poker_set.c) implements same layout in different way and they fix a minor issue of original Poker and enhance arrow keys.
34
35 Fn + Esc = `
36 Fn + {left, down, up, right} = {home, pgdown, pgup, end}
37
38#### 1.0 Default layer
39 ,-----------------------------------------------------------.
40 | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp |
41 |-----------------------------------------------------------|
42 |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
43 |-----------------------------------------------------------|
44 |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
45 |-----------------------------------------------------------|
46 |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |
47 |-----------------------------------------------------------|
48 |Ctrl|Gui |Alt | Space |Fn |Gui |App |Ctrl|
49 `-----------------------------------------------------------'
50#### 1.1 Poker Fn layer
51 ,-----------------------------------------------------------.
52 |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| |
53 |-----------------------------------------------------------|
54 | |FnQ| Up| | | | | | |Cal| |Hom|Ins| |
55 |-----------------------------------------------------------|
56 | |Lef|Dow|Rig| | |Psc|Slk|Pau| |Tsk|End| |
57 |-----------------------------------------------------------|
58 | |Del| |Web|Mut|VoU|VoD| |PgU|PgD|Del| Up |
59 |-----------------------------------------------------------|
60 | | | | FnS |Fn |Left|Down|Righ|
61 `-----------------------------------------------------------'
62
63
64### 2. Plain
65Without any Fn layer this will be useful if you want to use key remapping tool like AHK on host.
66See [keymap_plain.c](keymap_plain.c) for detail.
67
68#### 1.0 Plain Default layer
69 ,-----------------------------------------------------------.
70 |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp |
71 |-----------------------------------------------------------|
72 |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
73 |-----------------------------------------------------------|
74 |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
75 |-----------------------------------------------------------|
76 |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |
77 |-----------------------------------------------------------|
78 |Ctrl|Gui |Alt | Space |Alt |Gui |App |Ctrl|
79 `-----------------------------------------------------------'
80
81
82### 3. Hasu
83This is my favorite keymap with HHKB Fn, Vi cursor and Mousekey layer. See [keymap_hasu.c](keymap_hasu.c) for detail.
84
85
86### 4. SpaceFN
87This layout proposed by spiceBar uses space bar to change layer with using Dual role key technique. See [keymap_spacefn.c](keymap_spacefn.c) and [SpaceFN discussion](http://geekhack.org/index.php?topic=51069.0).
88
89#### 4.0 Default layer
90 ,-----------------------------------------------------------.
91 |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp |
92 |-----------------------------------------------------------|
93 |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
94 |-----------------------------------------------------------|
95 |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
96 |-----------------------------------------------------------|
97 |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |
98 |-----------------------------------------------------------|
99 |Ctrl|Gui |Alt | Space/Fn |Alt |Gui |App |Ctrl|
100 `-----------------------------------------------------------'
101#### 4.1 SpaceFN layer
102 ,-----------------------------------------------------------.
103 |` | F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete |
104 |-----------------------------------------------------------|
105 | | | | | | | |Hom|Up |End|Psc|Slk|Pau|Ins |
106 |-----------------------------------------------------------|
107 | | | | | | |PgU|Lef|Dow|Rig| | | |
108 |-----------------------------------------------------------|
109 | | | | | |Spc|PgD|` |~ | | | |
110 |-----------------------------------------------------------|
111 | | | | Fn | | | | |
112 `-----------------------------------------------------------'
113
114
115### 5. HHKB
116[keymap_hhkb.c](keymap_hhkb.c) emulates original HHKB layers.
117#### 5.0: Default layer
118 ,-----------------------------------------------------------.
119 |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
120 |-----------------------------------------------------------|
121 |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Bspc |
122 |-----------------------------------------------------------|
123 |Ctrl | A| S| D| F| G| H| J| K| L|Fn3| '|Return |
124 |-----------------------------------------------------------|
125 |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn |
126 |-----------------------------------------------------------|
127 | |Gui |Alt | Space | |Alt |Gui | |
128 `-----------------------------------------------------------'
129#### 5.1: HHKB Fn layer
130 ,-----------------------------------------------------------.
131 |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
132 |-----------------------------------------------------------|
133 |Caps | | | | | | | |Psc|Slk|Pus|Up | | |
134 |-----------------------------------------------------------|
135 | |VoD|VoU|Mut|Ejc| | *| /|Hom|PgU|Lef|Rig|Enter |
136 |-----------------------------------------------------------|
137 | | | | | | | +| -|End|PgD|Dow| | |
138 |-----------------------------------------------------------|
139 | | | | | | | | |
140 `-----------------------------------------------------------'
141
diff --git a/keyboard/atomic_old/config.h b/keyboard/atomic_old/config.h
new file mode 100644
index 000000000..5ea953805
--- /dev/null
+++ b/keyboard/atomic_old/config.h
@@ -0,0 +1,70 @@
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
22/* USB Device descriptor parameter */
23#define VENDOR_ID 0xFEED
24#define PRODUCT_ID 0x6060
25#define DEVICE_VER 0x0001
26#define MANUFACTURER Ortholinear Keyboards
27#define PRODUCT Atomic Keyboard
28#define DESCRIPTION t.m.k. keyboard firmware for Atomic
29
30/* key matrix size */
31#define MATRIX_ROWS 5
32#define MATRIX_COLS 15
33
34/* define if matrix has ghost */
35//#define MATRIX_HAS_GHOST
36
37/* Set 0 if debouncing isn't needed */
38#define DEBOUNCE 5
39
40/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
41#define LOCKING_SUPPORT_ENABLE
42/* Locking resynchronize hack */
43#define LOCKING_RESYNC_ENABLE
44
45/* key combination for command */
46#define IS_COMMAND() ( \
47 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
48)
49
50
51
52/*
53 * Feature disable options
54 * These options are also useful to firmware size reduction.
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#endif
diff --git a/keyboard/atomic_old/keymap_common.c b/keyboard/atomic_old/keymap_common.c
new file mode 100644
index 000000000..fdb1769e1
--- /dev/null
+++ b/keyboard/atomic_old/keymap_common.c
@@ -0,0 +1,30 @@
1/*
2Copyright 2012,2013 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#include "keymap_common.h"
18
19
20/* translates key to keycode */
21uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
22{
23 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
24}
25
26/* translates Fn keycode to action */
27action_t keymap_fn_to_action(uint8_t keycode)
28{
29 return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
30}
diff --git a/keyboard/atomic_old/keymap_common.h b/keyboard/atomic_old/keymap_common.h
new file mode 100644
index 000000000..c582c0135
--- /dev/null
+++ b/keyboard/atomic_old/keymap_common.h
@@ -0,0 +1,87 @@
1/*
2Copyright 2012,2013 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#ifndef KEYMAP_COMMON_H
18#define KEYMAP_COMMON_H
19
20#include <stdint.h>
21#include <stdbool.h>
22#include <avr/pgmspace.h>
23#include "keycode.h"
24#include "action.h"
25#include "action_macro.h"
26#include "report.h"
27#include "host.h"
28#include "print.h"
29#include "debug.h"
30#include "keymap.h"
31
32
33extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
34extern const uint16_t fn_actions[];
35
36// JCK: Semi-Standard layout
37#define KEYMAP_JCK( \
38 K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0E, \
39 K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \
40 K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, K2E, \
41 K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3C, K3D, K3E, \
42 K40, K41, K43, K46, K4A, K4B, K4C, K4D, K4E \
43) { \
44 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_NO, KC_##K0E }, \
45 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E }, \
46 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_NO, KC_##K2D, KC_##K2E }, \
47 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_NO, KC_##K3C, KC_##K3D, KC_##K3E }, \
48 { KC_##K40, KC_##K41, KC_NO, KC_##K43, KC_NO, KC_NO, KC_##K46, KC_NO, KC_NO, KC_NO, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E } \
49}
50
51// ASK: Short Space layout
52#define KEYMAP_ASK_MESSY( \
53 K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0E, \
54 K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \
55 K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, K2E, \
56 K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3C, K3D, K3E, \
57 K40, K41, K43, K44, K46, K48, K49, K4A, K4B, K4C, K4D, K4E \
58) { \
59 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_NO, KC_##K0E }, \
60 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E }, \
61 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_NO, KC_##K2D, KC_##K2E }, \
62 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_NO, KC_##K3C, KC_##K3D, KC_##K3E }, \
63 { KC_##K40, KC_##K41, KC_NO, KC_##K43, KC_##K44, KC_NO, KC_##K46, KC_NO, KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E } \
64}
65
66#define KEYMAP_ASK( \
67 K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0E, \
68 K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \
69 K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2E, \
70 K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3D, K3E, \
71 K40, K41, K43, K44, K46, K47, K48, K4A, K4B, K4C, K4D, K4E \
72) { \
73 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_NO, KC_##K0E }, \
74 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E }, \
75 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_NO, KC_##K2E }, \
76 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_NO, KC_##K3D, KC_##K3E }, \
77 { KC_##K40, KC_##K41, KC_NO, KC_##K43, KC_##K44, KC_NO, KC_##K46, KC_##K47, KC_##K48, KC_NO, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E } \
78}
79
80
81// MLO: Semi-Grid layout
82
83// KLN: Grid layout
84
85// PKR: Standard layout
86
87#endif
diff --git a/keyboard/atomic_old/keymap_plain.c b/keyboard/atomic_old/keymap_plain.c
new file mode 100644
index 000000000..e7f53649f
--- /dev/null
+++ b/keyboard/atomic_old/keymap_plain.c
@@ -0,0 +1,46 @@
1#include "keymap_common.h"
2
3// JCK: Semi-Standard layout
4
5const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
6 /* 0: qwerty */
7 [0] = KEYMAP_JCK(GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC, \
8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC, RBRC, BSLS, DEL, \
9 ESC, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, MPLY, \
10 LSFT, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, VOLD, VOLU, \
11 LCTL, LALT, LGUI, SPC, FN1, LEFT, DOWN, UP, RGHT),
12 [1] = KEYMAP_JCK(GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC, \
13 TAB, Q, W, F, P, G, J, L, U, Y, SCLN, LBRC, RBRC, BSLS, DEL, \
14 ESC, A, R, S, T, D, H, N, E, I, O, QUOT, ENT, MPLY, \
15 LSFT, Z, X, C, V, B, K, M, COMM, DOT, SLSH, RSFT, VOLD, VOLU, \
16 LCTL, LALT, LGUI, SPC, FN1, LEFT, DOWN, UP, RGHT),
17 [2] = KEYMAP_JCK(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, BSPC, \
18 TAB, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC, RBRC, BSLS, DEL, \
19 ESC, FN3, FN4, TRNS, TRNS, TRNS, TRNS, MINS, EQL, LBRC, RBRC, BSLS, ENT, MPLY, \
20 LSFT, FN9, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, VOLD, VOLU, \
21 LCTL, LALT, LGUI, SPC, TRNS, MNXT, VOLD, VOLU, MPLY),
22};
23const uint16_t PROGMEM fn_actions[] = {
24 [1] = ACTION_LAYER_MOMENTARY(2), // to Fn overlay
25 [3] = ACTION_DEFAULT_LAYER_SET(0),
26 [4] = ACTION_DEFAULT_LAYER_SET(1),
27
28 [9] = ACTION_MODS_KEY(MOD_LSFT | MOD_RSFT, KC_PAUSE),
29
30 [10] = ACTION_MODS_KEY(MOD_LSFT, KC_1),
31 [11] = ACTION_MODS_KEY(MOD_LSFT, KC_2),
32 [12] = ACTION_MODS_KEY(MOD_LSFT, KC_3),
33 [13] = ACTION_MODS_KEY(MOD_LSFT, KC_4),
34 [14] = ACTION_MODS_KEY(MOD_LSFT, KC_5),
35 [15] = ACTION_MODS_KEY(MOD_LSFT, KC_6),
36 [16] = ACTION_MODS_KEY(MOD_LSFT, KC_7),
37 [17] = ACTION_MODS_KEY(MOD_LSFT, KC_8),
38 [18] = ACTION_MODS_KEY(MOD_LSFT, KC_9),
39 [19] = ACTION_MODS_KEY(MOD_LSFT, KC_0),
40 [20] = ACTION_MODS_KEY(MOD_LSFT, KC_MINS),
41 [21] = ACTION_MODS_KEY(MOD_LSFT, KC_EQL),
42 [22] = ACTION_MODS_KEY(MOD_LSFT, KC_GRV),
43 [23] = ACTION_MODS_KEY(MOD_LSFT, KC_LBRC),
44 [24] = ACTION_MODS_KEY(MOD_LSFT, KC_RBRC),
45 [28] = ACTION_MODS_KEY(MOD_LSFT, KC_BSLS),
46};
diff --git a/keyboard/atomic_old/keymap_ricky.c b/keyboard/atomic_old/keymap_ricky.c
new file mode 100644
index 000000000..fcc91a1fa
--- /dev/null
+++ b/keyboard/atomic_old/keymap_ricky.c
@@ -0,0 +1,15 @@
1#include "keymap_common.h"
2
3// JCK: Semi-Standard layout
4
5const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
6 /* 0: qwerty */
7 [0] = KEYMAP_JCK(GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC, \
8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC, RBRC, BSLS, PSCR, \
9 CAPS, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, INS, \
10 LSFT, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, UP, DEL, \
11 LCTL, LGUI, LALT, SPC, RALT, RCTL, LEFT, DOWN, RGHT)
12};
13const uint16_t PROGMEM fn_actions[] = {
14};
15
diff --git a/keyboard/atomic_old/keymap_vlad.c b/keyboard/atomic_old/keymap_vlad.c
new file mode 100644
index 000000000..e56bcf161
--- /dev/null
+++ b/keyboard/atomic_old/keymap_vlad.c
@@ -0,0 +1,14 @@
1#include "keymap_common.h"
2
3// JCK: Semi-Standard layout
4
5const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
6 /* 0: qwerty */
7 [0] = KEYMAP_ASK(GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC, \
8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC, RBRC, BSLS, DEL, \
9 CAPS, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, VOLU, \
10 LSFT, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, UP, VOLD, \
11 LCTL, LGUI, LALT, LGUI, SPC, RGUI, RALT, RGUI, RCTL, LEFT, DOWN, RGHT)
12};
13const uint16_t PROGMEM fn_actions[] = {
14}; \ No newline at end of file
diff --git a/keyboard/atomic_old/led.c b/keyboard/atomic_old/led.c
new file mode 100644
index 000000000..2d52fbf1c
--- /dev/null
+++ b/keyboard/atomic_old/led.c
@@ -0,0 +1,25 @@
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#include <avr/io.h>
19#include "stdint.h"
20#include "led.h"
21
22
23void led_set(uint8_t usb_led)
24{
25}
diff --git a/keyboard/atomic_old/matrix.c b/keyboard/atomic_old/matrix.c
new file mode 100644
index 000000000..98102cb69
--- /dev/null
+++ b/keyboard/atomic_old/matrix.c
@@ -0,0 +1,211 @@
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 <util/delay.h>
25#include "action_layer.h"
26#include "print.h"
27#include "debug.h"
28#include "util.h"
29#include "matrix.h"
30
31
32#ifndef DEBOUNCE
33# define DEBOUNCE 10
34#endif
35static uint8_t debouncing = DEBOUNCE;
36
37/* matrix state(1:on, 0:off) */
38static matrix_row_t matrix[MATRIX_ROWS];
39static matrix_row_t matrix_debouncing[MATRIX_ROWS];
40
41static matrix_row_t read_cols(void);
42static void init_cols(void);
43static void unselect_rows(void);
44static void select_row(uint8_t row);
45
46
47inline
48uint8_t matrix_rows(void)
49{
50 return MATRIX_ROWS;
51}
52
53inline
54uint8_t matrix_cols(void)
55{
56 return MATRIX_COLS;
57}
58
59
60void matrix_init(void)
61{
62 // initialize row and col
63 unselect_rows();
64 init_cols();
65
66 // initialize matrix state: all keys off
67 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
68 matrix[i] = 0;
69 matrix_debouncing[i] = 0;
70 }
71}
72
73uint8_t matrix_scan(void)
74{
75 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
76 select_row(i);
77 _delay_us(30); // without this wait read unstable value.
78 matrix_row_t cols = read_cols();
79 if (matrix_debouncing[i] != cols) {
80 matrix_debouncing[i] = cols;
81 if (debouncing) {
82 debug("bounce!: "); debug_hex(debouncing); debug("\n");
83 }
84 debouncing = DEBOUNCE;
85 }
86 unselect_rows();
87 }
88
89 if (debouncing) {
90 if (--debouncing) {
91 _delay_ms(1);
92 } else {
93 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
94 matrix[i] = matrix_debouncing[i];
95 }
96 }
97 }
98
99
100 return 1;
101}
102
103bool matrix_is_modified(void)
104{
105 if (debouncing) return false;
106 return true;
107}
108
109inline
110bool matrix_is_on(uint8_t row, uint8_t col)
111{
112 return (matrix[row] & ((matrix_row_t)1<<col));
113}
114
115inline
116matrix_row_t matrix_get_row(uint8_t row)
117{
118 return matrix[row];
119}
120
121void matrix_print(void)
122{
123 print("\nr/c 0123456789ABCDEF\n");
124 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
125 phex(row); print(": ");
126 pbin_reverse16(matrix_get_row(row));
127 print("\n");
128 }
129}
130
131uint8_t matrix_key_count(void)
132{
133 uint8_t count = 0;
134 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
135 count += bitpop16(matrix[i]);
136 }
137 return count;
138}
139
140/* Column pin configuration
141 * col: 0 1 2 3 4 5 6 7 8 9 10 11
142 * pin: F0 F1 F4 F5 F6 F7 B6 B5 B4 D7 D5 D4
143 */
144
145static void init_cols(void)
146{
147 DDRC &= ~(1<<6 | 1<<7);
148 PORTC |= (1<<6 | 1<<7);
149 DDRD &= ~(1<<4 | 1<<5 | 1<<6 | 1<<7);
150 PORTD |= (1<<4 | 1<<5 | 1<<6 | 1<<7);
151 DDRB &= ~(1<<4 | 1<<5 | 1<<6);
152 PORTB |= (1<<4 | 1<<5 | 1<<6);
153 DDRF &= ~(1<<0 | 1<<1 | 1<<4 | 1<<5 | 1<<6 | 1<<7);
154 PORTF |= (1<<0 | 1<<1 | 1<<4 | 1<<5 | 1<<6 | 1<<7);
155}
156
157static matrix_row_t read_cols(void)
158{
159 return (PINC&(1<<6) ? 0 : (1<< 0)) |
160 (PINC&(1<<7) ? 0 : (1<< 1)) |
161 (PIND&(1<<5) ? 0 : (1<< 2)) |
162 (PIND&(1<<4) ? 0 : (1<< 3)) |
163 (PIND&(1<<6) ? 0 : (1<< 4)) |
164 (PIND&(1<<7) ? 0 : (1<< 5)) |
165 (PINB&(1<<4) ? 0 : (1<< 6)) |
166 (PINB&(1<<5) ? 0 : (1<< 7)) |
167 (PINB&(1<<6) ? 0 : (1<< 8)) |
168 (PINF&(1<<7) ? 0 : (1<< 9)) |
169 (PINF&(1<<6) ? 0 : (1<<10)) |
170 (PINF&(1<<5) ? 0 : (1<<11)) |
171 (PINF&(1<<4) ? 0 : (1<<12)) |
172 (PINF&(1<<1) ? 0 : (1<<13)) |
173 (PINF&(1<<0) ? 0 : (1<<14));
174}
175
176/* Row pin configuration
177 * row: 0 1 2 3
178 * pin: B0 B1 B2 B3
179 */
180static void unselect_rows(void)
181{
182 // Hi-Z(DDR:0, PORT:0) to unselect
183 DDRB &= ~(1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<7);
184 PORTB |= (1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<7);
185}
186
187static void select_row(uint8_t row)
188{
189 switch (row) {
190 case 0:
191 DDRB |= (1<<0);
192 PORTB &= ~(1<<0);
193 break;
194 case 1:
195 DDRB |= (1<<1);
196 PORTB &= ~(1<<1);
197 break;
198 case 2:
199 DDRB |= (1<<2);
200 PORTB &= ~(1<<2);
201 break;
202 case 3:
203 DDRB |= (1<<3);
204 PORTB &= ~(1<<3);
205 break;
206 case 4:
207 DDRB |= (1<<7);
208 PORTB &= ~(1<<7);
209 break;
210 }
211}
diff --git a/keyboard/planck/Makefile b/keyboard/planck/Makefile
index 7ea71af51..ad25854e6 100644
--- a/keyboard/planck/Makefile
+++ b/keyboard/planck/Makefile
@@ -60,8 +60,7 @@ ifdef COMMON
60 SRC = keymap_common.c \ 60 SRC = keymap_common.c \
61 $(MATRIX) \ 61 $(MATRIX) \
62 led.c \ 62 led.c \
63 backlight.c \ 63 backlight.c
64 beeps.c
65 64
66ifdef KEYMAP 65ifdef KEYMAP
67 SRC := common_keymaps/keymap_$(KEYMAP).c $(SRC) 66 SRC := common_keymaps/keymap_$(KEYMAP).c $(SRC)
@@ -74,8 +73,7 @@ else
74SRC = extended_keymap_common.c \ 73SRC = extended_keymap_common.c \
75 $(MATRIX) \ 74 $(MATRIX) \
76 led.c \ 75 led.c \
77 backlight.c \ 76 backlight.c
78 beeps.c
79 77
80ifdef KEYMAP 78ifdef KEYMAP
81 SRC := extended_keymaps/extended_keymap_$(KEYMAP).c $(SRC) 79 SRC := extended_keymaps/extended_keymap_$(KEYMAP).c $(SRC)
diff --git a/keyboard/planck/config.h b/keyboard/planck/config.h
index 4ac9f766e..47cf39a90 100644
--- a/keyboard/planck/config.h
+++ b/keyboard/planck/config.h
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#ifndef CONFIG_H 18#ifndef CONFIG_H
19#define CONFIG_H 19#define CONFIG_H
20 20
21#include "config_definitions.h"
21 22
22/* USB Device descriptor parameter */ 23/* USB Device descriptor parameter */
23#define VENDOR_ID 0xFEED 24#define VENDOR_ID 0xFEED
@@ -31,6 +32,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31#define MATRIX_ROWS 4 32#define MATRIX_ROWS 4
32#define MATRIX_COLS 12 33#define MATRIX_COLS 12
33 34
35/* Planck PCB default pin-out */
36#define COLS (int []){ F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 }
37#define ROWS (int []){ D0, D5, B5, B6 }
38
34/* define if matrix has ghost */ 39/* define if matrix has ghost */
35//#define MATRIX_HAS_GHOST 40//#define MATRIX_HAS_GHOST
36 41
diff --git a/keyboard/planck/config_definitions.h b/keyboard/planck/config_definitions.h
new file mode 100644
index 000000000..fd138b884
--- /dev/null
+++ b/keyboard/planck/config_definitions.h
@@ -0,0 +1,50 @@
1#ifndef CONFIG_DEFINITIONS_H
2#define CONFIG_DEFINITIONS_H
3
4#define B0 0x20
5#define B1 0x21
6#define B2 0x22
7#define B3 0x23
8#define B4 0x24
9#define B5 0x25
10#define B6 0x26
11#define B7 0x27
12#define C0 0x30
13#define C1 0x31
14#define C2 0x32
15#define C3 0x33
16#define C4 0x34
17#define C5 0x35
18#define C6 0x36
19#define C7 0x37
20#define D0 0x40
21#define D1 0x41
22#define D2 0x42
23#define D3 0x43
24#define D4 0x44
25#define D5 0x45
26#define D6 0x46
27#define D7 0x47
28#define E0 0x50
29#define E1 0x51
30#define E2 0x52
31#define E3 0x53
32#define E4 0x54
33#define E5 0x55
34#define E6 0x56
35#define E7 0x57
36#define F0 0x60
37#define F1 0x61
38#define F2 0x62
39#define F3 0x63
40#define F4 0x64
41#define F5 0x65
42#define F6 0x66
43#define F7 0x67
44
45
46
47
48
49#endif
50
diff --git a/keyboard/planck/extended_keymaps/extended_keymap_default.c b/keyboard/planck/extended_keymaps/extended_keymap_default.c
index 710611c3c..c75144bf4 100644
--- a/keyboard/planck/extended_keymaps/extended_keymap_default.c
+++ b/keyboard/planck/extended_keymaps/extended_keymap_default.c
@@ -1,6 +1,7 @@
1#include "extended_keymap_common.h" 1#include "extended_keymap_common.h"
2#include "backlight.h" 2#include "backlight.h"
3#include "lufa.h" 3#include "lufa.h"
4#include "debug.h"
4 5
5const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 6const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
6[0] = { /* Qwerty */ 7[0] = { /* Qwerty */
@@ -51,18 +52,12 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
51 switch(id) { 52 switch(id) {
52 case 0: 53 case 0:
53 if (record->event.pressed) { 54 if (record->event.pressed) {
54 if (!&midi_device) { 55 register_code(KC_RSFT);
55 register_code(KC_RSFT); 56 midi_send_noteon(&midi_device, 1, 64, 127);
56 } else {
57 midi_send_noteon(&midi_device, 1, 64, 127);
58 }
59 backlight_step(); 57 backlight_step();
60 } else { 58 } else {
61 if (!&midi_device) { 59 unregister_code(KC_RSFT);
62 unregister_code(KC_RSFT); 60 midi_send_noteoff(&midi_device, 1, 64, 127);
63 } else {
64 midi_send_noteoff(&midi_device, 1, 64, 127);
65 }
66 } 61 }
67 break; 62 break;
68 } 63 }
diff --git a/keyboard/planck/matrix.c b/keyboard/planck/matrix.c
new file mode 100644
index 000000000..58bd61f75
--- /dev/null
+++ b/keyboard/planck/matrix.c
@@ -0,0 +1,235 @@
1/*
2Copyright 2012 Jun Wako
3Generated by planckkeyboard.com (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
19/*
20 * scan matrix
21 */
22#include <stdint.h>
23#include <stdbool.h>
24#include <avr/io.h>
25#include <util/delay.h>
26#include "print.h"
27#include "debug.h"
28#include "util.h"
29#include "matrix.h"
30#include "backlight.h" // TODO fix this dependency
31
32#ifndef DEBOUNCE
33# define DEBOUNCE 10
34#endif
35static uint8_t debouncing = DEBOUNCE;
36
37/* matrix state(1:on, 0:off) */
38static matrix_row_t matrix[MATRIX_ROWS];
39static matrix_row_t matrix_debouncing[MATRIX_ROWS];
40
41static matrix_row_t read_cols(void);
42static void init_cols(void);
43static void unselect_rows(void);
44static void select_row(uint8_t row);
45
46inline
47uint8_t matrix_rows(void)
48{
49 return MATRIX_ROWS;
50}
51
52inline
53uint8_t matrix_cols(void)
54{
55 return MATRIX_COLS;
56}
57
58void matrix_init(void)
59{
60 // To use PORTF disable JTAG with writing JTD bit twice within four cycles.
61 MCUCR |= (1<<JTD);
62 MCUCR |= (1<<JTD);
63
64 backlight_init_ports();
65
66 // Turn status LED on
67 DDRE |= (1<<6);
68 PORTE |= (1<<6);
69
70 // initialize row and col
71 unselect_rows();
72 init_cols();
73
74 // initialize matrix state: all keys off
75 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
76 matrix[i] = 0;
77 matrix_debouncing[i] = 0;
78 }
79}
80
81
82uint8_t matrix_scan(void)
83{
84 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
85 select_row(i);
86 _delay_us(30); // without this wait read unstable value.
87 matrix_row_t cols = read_cols();
88 if (matrix_debouncing[i] != cols) {
89 matrix_debouncing[i] = cols;
90 if (debouncing) {
91 debug("bounce!: "); debug_hex(debouncing); debug("\n");
92 }
93 debouncing = DEBOUNCE;
94 }
95 unselect_rows();
96 }
97
98 if (debouncing) {
99 if (--debouncing) {
100 _delay_ms(1);
101 } else {
102 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
103 matrix[i] = matrix_debouncing[i];
104 }
105 }
106 }
107
108 return 1;
109}
110
111bool matrix_is_modified(void)
112{
113 if (debouncing) return false;
114 return true;
115}
116
117inline
118bool matrix_is_on(uint8_t row, uint8_t col)
119{
120 return (matrix[row] & ((matrix_row_t)1<col));
121}
122
123inline
124matrix_row_t matrix_get_row(uint8_t row)
125{
126 return matrix[row];
127}
128
129void matrix_print(void)
130{
131 print("\nr/c 0123456789ABCDEF\n");
132 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
133 phex(row); print(": ");
134 pbin_reverse16(matrix_get_row(row));
135 print("\n");
136 }
137}
138
139uint8_t matrix_key_count(void)
140{
141 uint8_t count = 0;
142 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
143 count += bitpop16(matrix[i]);
144 }
145 return count;
146}
147
148static void init_cols(void)
149{
150 int B = 0, C = 0, D = 0, E = 0, F = 0;
151 for(int x = 0; x < MATRIX_COLS; x++) {
152 int col = COLS[x];
153 if ((col & 0xF0) == 0x20) {
154 B |= (1<<(col & 0x0F));
155 } else if ((col & 0xF0) == 0x30) {
156 C |= (1<<(col & 0x0F));
157 } else if ((col & 0xF0) == 0x40) {
158 D |= (1<<(col & 0x0F));
159 } else if ((col & 0xF0) == 0x50) {
160 E |= (1<<(col & 0x0F));
161 } else if ((col & 0xF0) == 0x60) {
162 F |= (1<<(col & 0x0F));
163 }
164 }
165 DDRB &= ~(B); PORTB |= (B);
166 DDRC &= ~(C); PORTC |= (C);
167 DDRD &= ~(D); PORTD |= (D);
168 DDRE &= ~(E); PORTE |= (E);
169 DDRF &= ~(F); PORTF |= (F);
170}
171
172static matrix_row_t read_cols(void)
173{
174 matrix_row_t result = 0;
175 for(int x = 0; x < MATRIX_COLS; x++) {
176 int col = COLS[x];
177 if ((col & 0xF0) == 0x20) {
178 result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<<x));
179 } else if ((col & 0xF0) == 0x30) {
180 result |= (PINC&(1<<(col & 0x0F)) ? 0 : (1<<x));
181 } else if ((col & 0xF0) == 0x40) {
182 result |= (PIND&(1<<(col & 0x0F)) ? 0 : (1<<x));
183 } else if ((col & 0xF0) == 0x50) {
184 result |= (PINE&(1<<(col & 0x0F)) ? 0 : (1<<x));
185 } else if ((col & 0xF0) == 0x60) {
186 result |= (PINF&(1<<(col & 0x0F)) ? 0 : (1<<x));
187 }
188 }
189 return result;
190}
191
192static void unselect_rows(void)
193{
194 int B = 0, C = 0, D = 0, E = 0, F = 0;
195 for(int x = 0; x < MATRIX_ROWS; x++) {
196 int row = ROWS[x];
197 if ((row & 0xF0) == 0x20) {
198 B |= (1<<(row & 0x0F));
199 } else if ((row & 0xF0) == 0x30) {
200 C |= (1<<(row & 0x0F));
201 } else if ((row & 0xF0) == 0x40) {
202 D |= (1<<(row & 0x0F));
203 } else if ((row & 0xF0) == 0x50) {
204 E |= (1<<(row & 0x0F));
205 } else if ((row & 0xF0) == 0x60) {
206 F |= (1<<(row & 0x0F));
207 }
208 }
209 DDRB &= ~(B); PORTB |= (B);
210 DDRC &= ~(C); PORTC |= (C);
211 DDRD &= ~(D); PORTD |= (D);
212 DDRE &= ~(E); PORTE |= (E);
213 DDRF &= ~(F); PORTF |= (F);
214}
215
216static void select_row(uint8_t row)
217{
218 int row_pin = ROWS[row];
219 if ((row_pin & 0xF0) == 0x20) {
220 DDRB |= (1<<(row_pin & 0x0F));
221 PORTB &= ~(1<<(row_pin & 0x0F));
222 } else if ((row_pin & 0xF0) == 0x30) {
223 DDRC |= (1<<(row_pin & 0x0F));
224 PORTC &= ~(1<<(row_pin & 0x0F));
225 } else if ((row_pin & 0xF0) == 0x40) {
226 DDRD |= (1<<(row_pin & 0x0F));
227 PORTD &= ~(1<<(row_pin & 0x0F));
228 } else if ((row_pin & 0xF0) == 0x50) {
229 DDRE |= (1<<(row_pin & 0x0F));
230 PORTE &= ~(1<<(row_pin & 0x0F));
231 } else if ((row_pin & 0xF0) == 0x60) {
232 DDRF |= (1<<(row_pin & 0x0F));
233 PORTF &= ~(1<<(row_pin & 0x0F));
234 }
235} \ No newline at end of file
diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile
new file mode 100644
index 000000000..5eb45fe1c
--- /dev/null
+++ b/keyboard/preonic/Makefile
@@ -0,0 +1,138 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = preonic_lufa
43
44# Directory common source filess exist
45TOP_DIR = ../..
46
47# Directory keyboard dependent files exist
48TARGET_DIR = .
49
50# # project specific files
51SRC = extended_keymap_common.c \
52 matrix.c \
53 led.c \
54 backlight.c
55
56ifdef KEYMAP
57 SRC := extended_keymaps/extended_keymap_$(KEYMAP).c $(SRC)
58else
59 SRC := extended_keymaps/extended_keymap_default.c $(SRC)
60endif
61
62CONFIG_H = config.h
63
64# MCU name
65#MCU = at90usb1287
66MCU = atmega32u4
67
68# Processor frequency.
69# This will define a symbol, F_CPU, in all source code files equal to the
70# processor frequency in Hz. You can then use this symbol in your source code to
71# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
72# automatically to create a 32-bit value in your source code.
73#
74# This will be an integer division of F_USB below, as it is sourced by
75# F_USB after it has run through any CPU prescalers. Note that this value
76# does not *change* the processor frequency - it should merely be updated to
77# reflect the processor speed set externally so that the code can use accurate
78# software delays.
79F_CPU = 16000000
80
81
82#
83# LUFA specific
84#
85# Target architecture (see library "Board Types" documentation).
86ARCH = AVR8
87
88# Input clock frequency.
89# This will define a symbol, F_USB, in all source code files equal to the
90# input clock frequency (before any prescaling is performed) in Hz. This value may
91# differ from F_CPU if prescaling is used on the latter, and is required as the
92# raw input clock is fed directly to the PLL sections of the AVR for high speed
93# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
94# at the end, this will be done automatically to create a 32-bit value in your
95# source code.
96#
97# If no clock division is performed on the input clock inside the AVR (via the
98# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
99F_USB = $(F_CPU)
100
101# Interrupt driven control endpoint task(+60)
102OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
103
104
105# Boot Section Size in *bytes*
106# Teensy halfKay 512
107# Teensy++ halfKay 1024
108# Atmel DFU loader 4096
109# LUFA bootloader 4096
110# USBaspLoader 2048
111OPT_DEFS += -DBOOTLOADER_SIZE=4096
112
113
114# Build Options
115# comment out to disable the options.
116#
117BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
118MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
119EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
120CONSOLE_ENABLE = yes # Console for debug(+400)
121COMMAND_ENABLE = yes # Commands for debug and configuration
122# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
123#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
124NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
125BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
126MIDI_ENABLE = yes # MIDI controls
127BACKLIGHT_ENABLE = yes
128
129# Optimize size but this may cause error "relocation truncated to fit"
130#EXTRALDFLAGS = -Wl,--relax
131
132# Search Path
133VPATH += $(TARGET_DIR)
134VPATH += $(TOP_DIR)
135
136include $(TOP_DIR)/protocol/lufa.mk
137include $(TOP_DIR)/common.mk
138include $(TOP_DIR)/rules.mk
diff --git a/keyboard/preonic/Makefile.pjrc b/keyboard/preonic/Makefile.pjrc
new file mode 100644
index 000000000..be83ba18b
--- /dev/null
+++ b/keyboard/preonic/Makefile.pjrc
@@ -0,0 +1,116 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = gh60_pjrc
43
44# Directory common source filess exist
45TOP_DIR = ../..
46
47# Directory keyboard dependent files exist
48TARGET_DIR = .
49
50# project specific files
51SRC = keymap_common.c \
52 matrix.c \
53 led.c
54
55ifdef KEYMAP
56 SRC := keymap_$(KEYMAP).c $(SRC)
57else
58 SRC := keymap_jack.c $(SRC)
59endif
60
61CONFIG_H = config.h
62
63
64# MCU name, you MUST set this to match the board you are using
65# type "make clean" after changing this, so all files will be rebuilt
66MCU = atmega32u4
67#MCU = at90usb1286
68
69
70# Processor frequency.
71# Normally the first thing your program should do is set the clock prescaler,
72# so your program will run at the correct speed. You should also set this
73# variable to same clock speed. The _delay_ms() macro uses this, and many
74# examples use this variable to calculate timings. Do not add a "UL" here.
75F_CPU = 16000000
76
77
78# Boot Section Size in *bytes*
79# Teensy halfKay 512
80# Atmel DFU loader 4096
81# LUFA bootloader 4096
82OPT_DEFS += -DBOOTLOADER_SIZE=4096
83
84
85# Build Options
86# comment out to disable the options.
87#
88BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
89MOUSEKEY_ENABLE = yes # Mouse keys(+5000)
90EXTRAKEY_ENABLE = yes # Audio control and System control(+600)
91CONSOLE_ENABLE = yes # Console for debug
92COMMAND_ENABLE = yes # Commands for debug and configuration
93SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
94NKRO_ENABLE = yes # USB Nkey Rollover(+500)
95#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
96
97
98# Search Path
99VPATH += $(TARGET_DIR)
100VPATH += $(TOP_DIR)
101
102include $(TOP_DIR)/protocol/pjrc.mk
103include $(TOP_DIR)/common.mk
104include $(TOP_DIR)/rules.mk
105
106plain: OPT_DEFS += -DKEYMAP_PLAIN
107plain: all
108
109poker: OPT_DEFS += -DKEYMAP_POKER
110poker: all
111
112poker_set: OPT_DEFS += -DKEYMAP_POKER_SET
113poker_set: all
114
115poker_bit: OPT_DEFS += -DKEYMAP_POKER_BIT
116poker_bit: all
diff --git a/keyboard/preonic/PCB_GUIDE.md b/keyboard/preonic/PCB_GUIDE.md
new file mode 100644
index 000000000..c3004c75a
--- /dev/null
+++ b/keyboard/preonic/PCB_GUIDE.md
@@ -0,0 +1,116 @@
1# Planck Firmware Guide
2
3## Setting up the environment
4
5### Windows
61. Install [WinAVR Tools](http://sourceforge.net/projects/winavr/) for AVR GCC compiler.
72. Install [DFU-Programmer][dfu-prog] (the -win one).
83. Start DFU bootloader on the chip first time you will see 'Found New Hardware Wizard' to install driver. If you install device driver properly you can find chip name like 'ATmega32U4' under 'LibUSB-Win32 Devices' tree on 'Device Manager'. If not you will need to update its driver on 'Device Manager' to the `dfu-programmer` driver.
9
10### Mac
111. Install [CrossPack](http://www.obdev.at/products/crosspack/index.html) or install Xcode from the App Store and install the Command Line Tools from `Xcode->Preferences->Downloads`.
122. Install [DFU-Programmer][dfu-prog].
13
14### Linux
151. Install AVR GCC with your favorite package manager.
162. Install [DFU-Programmer][dfu-prog].
17
18##Verify Your Installation
191. Clone the following repository: https://github.com/jackhumbert/tmk_keyboard
202. Open a Terminal and `cd` into `tmk_keyboard/keyboard/planck`
213. Run `make`. This should output a lot of information about the build process.
22
23## Using the built-in functions
24
25Here is a list of some of the functions available from the command line:
26
27* `make clean`: clean the environment - may be required in-between builds
28* `make`: compile the code
29* `make COMMON=true`: compile with the common (non-extended) keymap
30* `make MATRIX=<matrix_file>`: compile with the referenced matrix file. Default if unspecified is `matrix_pcb.c`. For handwired boards, use `matrix_handwired.c`.
31* `make KEYMAP=<keymap>`: compile with the extended keymap file `extended_keymaps/extended_keymap_<keymap>.c`
32* `make COMMON=true KEYMAP=<keymap>`: compile with the common keymap file `common_keymaps/keymap_<keymap>.c`
33* `make dfu`: build and flash the layout to the PCB
34* `make dfu-force`: build and force-flash the layout to the PCB (may be require for first flash)
35
36Generally, the instructions to flash the PCB are as follows:
37
381. Make changes to the appropriate keymap file
392. Save the file
403. `make clean`
414. Press the reset button on the PCB/press the key with the `RESET` keycode
425. `make <arguments> dfu` - use the necessary `KEYMAP=<keymap>` and/or `COMMON=true` arguments here.
43
44## Extended keymap
45
46### Keymap
47
48Unlike the common keymap, prefixing the keycodes with `KC_` is required. A full list of the keycodes is available [here](https://github.com/jackhumbert/tmk_keyboard/blob/master/doc/keycode.txt). For the keycodes available only in the extended keymap, see this [header file](https://github.com/jackhumbert/tmk_keyboard/blob/master/keyboard/planck/extended_keymap_common.h).
49
50You can use modifiers with keycodes like this:
51
52 LCTL(KC_C)
53
54Which will generate Ctrl+c. These are daisy-chainable, meaning you can do things like:
55
56 LCTL(LALT(KC_C))
57
58That will generate Ctrl+Alt+c. The entire list of these functions is here:
59
60* `LCTL()`: Left control
61* `LSFT()` / `S()`: Left shift
62* `LALT()`: Left alt/opt
63* `LGUI()`: Left win/cmd
64* `RCTL()`: Right control
65* `RSFT()`: Right shift
66* `RALT()`: Right alt/opt
67* `RGUI()`: Right win/cmd
68
69`S(KC_1)`-like entries are useful in writing keymaps for the Planck.
70
71### Other keycodes
72
73A number of other keycodes have been added that you may find useful:
74
75* `CM_<key>`: the Colemak equivalent of a key (in place of `KC_<key>`), when using Colemak in software (`CM_O` generates `KC_SCLN`)
76* `RESET`: jump to bootloader for flashing (same as press the reset button)
77* `BL_STEP`: step through the backlight brightnesses
78* `BL_<0-15>`: set backlight brightness to 0-15
79* `BL_DEC`: lower the backlight brightness
80* `BL_INC`: raise the backlight brightness
81* `BL_TOGG`: toggle the backlight on/off
82
83### Function layers
84
85The extended keymap extends the number of function layers from 32 to the near-infinite value of 256. Rather than using `FN<num>` notation (still available, but limited to `FN0`-`FN31`), you can use the `FUNC(<num>)` notation. `F(<num>)` is a shortcut for this.
86
87The function actions are unchanged, and you can see the full list of them [here](https://github.com/jackhumbert/tmk_keyboard/blob/master/common/action_code.h). They are explained in detail [here](https://github.com/jackhumbert/tmk_keyboard/blob/master/doc/keymap.md#2-action).
88
89### Macros
90
91Macros have been setup in the `extended_keymaps/extended_keymaps_default.c` file so that you can use `M(<num>)` to access a macro in the `action_get_macro` section on your keymap. The switch/case structure you see here is required, and is setup for `M(0)` - you'll need to copy and paste the code to look like this (e.g. to support `M(3)`):
92
93 switch(id) {
94 case 0:
95 return MACRODOWN(TYPE(KC_A), END);
96 break;
97 case 1:
98 return MACRODOWN(TYPE(KC_B), END);
99 break;
100 case 2:
101 return MACRODOWN(TYPE(KC_C), END);
102 break;
103 case 3:
104 return MACRODOWN(TYPE(KC_D), END);
105 break;
106 }
107 return MACRO_NONE;
108
109`MACRODOWN()` is a shortcut for `(record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)` which tells the macro to execute when the key is pressed. Without this, the macro will be executed on both the down and up stroke.
110
111[cygwin]: https://www.cygwin.com/
112[mingw]: http://www.mingw.org/
113[mhv]: https://infernoembedded.com/products/avr-tools
114[winavr]: http://winavr.sourceforge.net/
115[crosspack]: http://www.obdev.at/products/crosspack/index.html
116[dfu-prog]: http://dfu-programmer.sourceforge.net/
diff --git a/keyboard/preonic/README.md b/keyboard/preonic/README.md
new file mode 100644
index 000000000..ee824d26e
--- /dev/null
+++ b/keyboard/preonic/README.md
@@ -0,0 +1,56 @@
1Planck keyboard firmware
2======================
3DIY/Assembled compact ortholinear 40% keyboard by [Ortholinear Keyboards](http://ortholinearkeyboards.com).
4
5## Extended Keymap
6If you include extended_keymap_common.h instead of keymap_common.h at the top of your file, you'll have access to a bunch of goodies:
7
8- Use `LSFT()`, `LCTL()`, et. al. (listed in extended_keymap_common.h) as modifiers for keys (daisy-chain-able)
9- Use `FUNC(1)` instead of `FN1` (etc.) to access the function layers beyond the 32 function layer limit
10- Use `CM_F` instead of `KC_F` to get the ColeMak equivilent for shortcuts (maps backwards)
11- Use `MACRODOWN()` instead of `MACRO()` to easily make a keydown macro (`CM_*` works here too)
12
13### Some notes on usage:
14
15- The `KEYMAP()` macro is unable to be used due to the bitwise modifications that take place - refer to extended_keymap_jack.c to see how to set things up with the `KC_` prefix
16- Keep an eye on the Makefile - this needs to include the correct files to work
17- Don't forget to use `const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {` instead of the 8bit equivilent
18
19## Build
20
21Follow [this guide](http://deskthority.net/workshop-f7/how-to-build-your-very-own-keyboard-firmware-t7177.html) to setup your development environment before anything else. Abbreviated instructions are provide at the [bottom of this document](https://github.com/rswiernik/tmk_keyboard/tree/rswiernik_dev/keyboard/planck#environment-setup)
22
23Download the whole firmware [here](https://github.com/jackhumbert/tmk_keyboard/archive/master.zip) and navigate to the keyboard/planck folder. Once your dev env is setup, you'll be able to type `make` to generate your .hex that you can load with the Teensy app onto your Planck (once you've hit reset/shorted GND & RST).
24
25Depending on which keymap you would like to use, you will have to compile slightly differently.
26
27####Default
28To build with the default keymap, simply move to the tmk\_keyboard/keyboard/planck/ and run `make` as follows:
29```
30$ make
31```
32
33## Keymap
34Several version of keymap are available in advance but you are recommended to define your favorite layout yourself. To define your own keymap create file named `keymap_<name>.c` and see keymap document (you can find in top README.md) and existent keymap files.
35
36####**Extended Keymaps**
37
38To build the firmware binary hex file with an extended keymap just do `make` with `KEYMAP` option like:
39```
40$ make KEYMAP=[common|jack|<name>]
41```
42_The only applicable keymaps will work with this option._ Extended keymaps follow the format **__extended\_keymap\_\<name\>.c__**
43
44####**Common Keymaps**
45
46Building with a common keymap is as simple as adding the COMMON option. Note that only
47```
48$ make KEYMAP=[common|jack|<name>] COMMON=true
49```
50_The only applicable keymaps will work with this option._ Common keymaps follow the format **__keymap\_\<name\>.c__**
51
52## Notable TMK forks (which some of the keymap files are from)
53- [Shane's Fork](https://github.com/shanecelis/tmk_keyboard/tree/master/keyboard/planck)
54- [Pierre's Fork](https://github.com/pcarrier/tmk_keyboard/blob/pcarrier/planck/keyboard/gh60/keymap_planck.c)
55- [Nathan's Fork](https://github.com/nathanrosspowell/tmk_keyboard/tree/planck-jack/keyboard/planck)
56- [Matthew's Fork](https://github.com/pepers/tmk_keyboard/tree/master/keyboard/planck_grid)
diff --git a/keyboard/preonic/__avr_gdbinit b/keyboard/preonic/__avr_gdbinit
new file mode 100644
index 000000000..afc51e6d1
--- /dev/null
+++ b/keyboard/preonic/__avr_gdbinit
@@ -0,0 +1,6 @@
1define reset
2SIGNAL SIGHUP
3end
4file planck_lufa.elf
5target remote localhost:4242
6break main
diff --git a/keyboard/preonic/analog.c b/keyboard/preonic/analog.c
new file mode 100644
index 000000000..49b84ee0e
--- /dev/null
+++ b/keyboard/preonic/analog.c
@@ -0,0 +1,53 @@
1// Simple analog to digitial conversion
2
3#include <avr/io.h>
4#include <avr/pgmspace.h>
5#include <stdint.h>
6#include "analog.h"
7
8
9static uint8_t aref = (1<<REFS0); // default to AREF = Vcc
10
11
12void analogReference(uint8_t mode)
13{
14 aref = mode & 0xC0;
15}
16
17
18// Arduino compatible pin input
19int16_t analogRead(uint8_t pin)
20{
21#if defined(__AVR_ATmega32U4__)
22 static const uint8_t PROGMEM pin_to_mux[] = {
23 0x00, 0x01, 0x04, 0x05, 0x06, 0x07,
24 0x25, 0x24, 0x23, 0x22, 0x21, 0x20};
25 if (pin >= 12) return 0;
26 return adc_read(pgm_read_byte(pin_to_mux + pin));
27#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
28 if (pin >= 8) return 0;
29 return adc_read(pin);
30#else
31 return 0;
32#endif
33}
34
35// Mux input
36int16_t adc_read(uint8_t mux)
37{
38#if defined(__AVR_AT90USB162__)
39 return 0;
40#else
41 uint8_t low;
42
43 ADCSRA = (1<<ADEN) | ADC_PRESCALER; // enable ADC
44 ADCSRB = (1<<ADHSM) | (mux & 0x20); // high speed mode
45 ADMUX = aref | (mux & 0x1F); // configure mux input
46 ADCSRA = (1<<ADEN) | ADC_PRESCALER | (1<<ADSC); // start the conversion
47 while (ADCSRA & (1<<ADSC)) ; // wait for result
48 low = ADCL; // must read LSB first
49 return (ADCH << 8) | low; // must read MSB only once!
50#endif
51}
52
53
diff --git a/keyboard/preonic/analog.h b/keyboard/preonic/analog.h
new file mode 100644
index 000000000..9b95a93be
--- /dev/null
+++ b/keyboard/preonic/analog.h
@@ -0,0 +1,36 @@
1#ifndef _analog_h_included__
2#define _analog_h_included__
3
4#include <stdint.h>
5
6void analogReference(uint8_t mode);
7int16_t analogRead(uint8_t pin);
8int16_t adc_read(uint8_t mux);
9
10#define ADC_REF_POWER (1<<REFS0)
11#define ADC_REF_INTERNAL ((1<<REFS1) | (1<<REFS0))
12#define ADC_REF_EXTERNAL (0)
13
14// These prescaler values are for high speed mode, ADHSM = 1
15#if F_CPU == 16000000L
16#define ADC_PRESCALER ((1<<ADPS2) | (1<<ADPS1))
17#elif F_CPU == 8000000L
18#define ADC_PRESCALER ((1<<ADPS2) | (1<<ADPS0))
19#elif F_CPU == 4000000L
20#define ADC_PRESCALER ((1<<ADPS2))
21#elif F_CPU == 2000000L
22#define ADC_PRESCALER ((1<<ADPS1) | (1<<ADPS0))
23#elif F_CPU == 1000000L
24#define ADC_PRESCALER ((1<<ADPS1))
25#else
26#define ADC_PRESCALER ((1<<ADPS0))
27#endif
28
29// some avr-libc versions do not properly define ADHSM
30#if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
31#if !defined(ADHSM)
32#define ADHSM (7)
33#endif
34#endif
35
36#endif
diff --git a/keyboard/preonic/backlight.c b/keyboard/preonic/backlight.c
new file mode 100644
index 000000000..f69364b2a
--- /dev/null
+++ b/keyboard/preonic/backlight.c
@@ -0,0 +1,61 @@
1
2#include <avr/io.h>
3#include "backlight.h"
4
5#define CHANNEL OCR1C
6
7void backlight_init_ports()
8{
9
10 // Setup PB7 as output and output low.
11 DDRB |= (1<<7);
12 PORTB &= ~(1<<7);
13
14 // Use full 16-bit resolution.
15 ICR1 = 0xFFFF;
16
17 // I could write a wall of text here to explain... but TL;DW
18 // Go read the ATmega32u4 datasheet.
19 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
20
21 // Pin PB7 = OCR1C (Timer 1, Channel C)
22 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
23 // (i.e. start high, go low when counter matches.)
24 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
25 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
26
27 TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010;
28 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
29
30 backlight_init();
31}
32
33void backlight_set(uint8_t level)
34{
35 if ( level == 0 )
36 {
37 // Turn off PWM control on PB7, revert to output low.
38 TCCR1A &= ~(_BV(COM1C1));
39 CHANNEL = 0x0;
40 // Prevent backlight blink on lowest level
41 PORTB &= ~(_BV(PORTB7));
42 }
43 else if ( level == BACKLIGHT_LEVELS )
44 {
45 // Prevent backlight blink on lowest level
46 PORTB &= ~(_BV(PORTB7));
47 // Turn on PWM control of PB7
48 TCCR1A |= _BV(COM1C1);
49 // Set the brightness
50 CHANNEL = 0xFFFF;
51 }
52 else
53 {
54 // Prevent backlight blink on lowest level
55 PORTB &= ~(_BV(PORTB7));
56 // Turn on PWM control of PB7
57 TCCR1A |= _BV(COM1C1);
58 // Set the brightness
59 CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
60 }
61} \ No newline at end of file
diff --git a/keyboard/preonic/beeps.c b/keyboard/preonic/beeps.c
new file mode 100644
index 000000000..13e46e1da
--- /dev/null
+++ b/keyboard/preonic/beeps.c
@@ -0,0 +1,238 @@
1#include "beeps.h"
2#include <math.h>
3#include <avr/pgmspace.h>
4#include <avr/interrupt.h>
5#include <avr/io.h>
6
7#define PI 3.14159265
8#define CHANNEL OCR1C
9
10volatile uint16_t sample;
11uint16_t lastSample;
12
13const int sounddata_length=200;
14
15const unsigned char sounddata_data[] PROGMEM = {128,
16128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
17128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
18128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
19128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
20128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
21128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
22128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
23128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
24128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
25128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 127, 129, 128, 127, 133,
26117, 109, 125, 121, 116, 132, 140, 126, 114, 114, 116, 120, 114, 93, 73, 66, 76, 116, 142, 129,
27128, 129, 120, 119, 118, 104, 87, 123, 181, 194, 196, 198, 189, 176, 160, 162, 172, 164, 164, 183,
28197, 188, 168, 167, 170, 165, 185, 209, 206, 196, 196, 199, 185, 162, 156, 167, 176, 173, 170, 166,
29151, 142, 140, 134, 130, 127, 113, 86, 67, 66, 69, 75, 73, 75, 86, 90, 91, 84, 65, 48,
3041, 30, 26, 56, 91, 88, 72, 70, 73, 82, 89, 73, 57, 60, 74, 89, 92, 77, 63, 60,
3153, 47, 56, 64, 63, 61, 56, 54, 52, 36, 16, 22, 51, 66, 67, 70, 76, 88, 99, 92,
3277, 74, 85, 100, 106, 97, 83, 85, 96, 108, 133, 160, 164};
33
34void delay_us(int count) {
35 while(count--) {
36 _delay_us(1);
37 }
38}
39
40void beeps() {
41 // DDRB |= (1<<7);
42 // PORTB &= ~(1<<7);
43
44 // // Use full 16-bit resolution.
45 // ICR1 = 0xFFFF;
46
47 // // I could write a wall of text here to explain... but TL;DW
48 // // Go read the ATmega32u4 datasheet.
49 // // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
50
51 // // Pin PB7 = OCR1C (Timer 1, Channel C)
52 // // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
53 // // (i.e. start high, go low when counter matches.)
54 // // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
55 // // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
56
57 // TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010;
58 // TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
59
60
61 // // Turn off PWM control on PB7, revert to output low.
62 // // TCCR1A &= ~(_BV(COM1C1));
63 // // CHANNEL = ((1 << level) - 1);
64
65 // // Turn on PWM control of PB7
66 // TCCR1A |= _BV(COM1C1);
67 // // CHANNEL = level << OFFSET | 0x0FFF;
68 // // CHANNEL = 0b1010101010101010;
69
70 // float x = 12;
71 // float y = 24;
72 // float length = 50;
73 // float scale = 1;
74
75 // // int f1 = 1000000/440;
76 // // int f2 = 1000000/880;
77 // // for (uint32_t i = 0; i < length * 1000; i++) {
78 // // // int frequency = 1/((sin(PI*2*i*scale*pow(2, x/12.0))*.5+1 + sin(PI*2*i*scale*pow(2, y/12.0))*.5+1) / 2);
79
80 // // ICR1 = f1; // Set max to the period
81 // // OCR1C = f1 >> 1; // Set compare to half the period
82 // // // _delay_us(10);
83 // // }
84 // int frequency = 1000000/440;
85 // ICR1 = frequency; // Set max to the period
86 // OCR1C = frequency >> 1; // Set compare to half the period
87 // _delay_us(500000);
88
89 // TCCR1A &= ~(_BV(COM1C1));
90 // CHANNEL = 0;
91play_notes();
92
93
94 // play_note(55*pow(2, 0/12.0), 1);
95 // play_note(55*pow(2, 12/12.0), 1);
96 // play_note(55*pow(2, 24/12.0), 1);
97 // play_note(55*pow(2, 0/12.0), 1);
98 // play_note(55*pow(2, 12/12.0), 1);
99 // play_note(55*pow(2, 24/12.0), 1);
100
101 // play_note(0, 4);
102
103 // play_note(55*pow(2, 0/12.0), 8);
104 // play_note(55*pow(2, 12/12.0), 4);
105 // play_note(55*pow(2, 10/12.0), 4);
106 // play_note(55*pow(2, 12/12.0), 8);
107 // play_note(55*pow(2, 10/12.0), 4);
108 // play_note(55*pow(2, 7/12.0), 2);
109 // play_note(55*pow(2, 8/12.0), 2);
110 // play_note(55*pow(2, 7/12.0), 16);
111 // play_note(0, 4);
112 // play_note(55*pow(2, 3/12.0), 8);
113 // play_note(55*pow(2, 5/12.0), 4);
114 // play_note(55*pow(2, 7/12.0), 4);
115 // play_note(55*pow(2, 7/12.0), 8);
116 // play_note(55*pow(2, 5/12.0), 4);
117 // play_note(55*pow(2, 3/12.0), 4);
118 // play_note(55*pow(2, 2/12.0), 16);
119
120
121}
122
123void play_note(float freq, int length) {
124 DDRB |= (1<<7);
125 PORTB &= ~(1<<7);
126
127 if (freq > 0) {
128 int frequency = 1000000/freq;
129 ICR1 = frequency; // Set max to the period
130 OCR1C = frequency >> 1; // Set compare to half the period
131
132 TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010;
133 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
134 }
135
136 for (int i = 0; i < length; i++) {
137 _delay_us(50000);
138 }
139
140 TCCR1A &= ~(_BV(COM1C1));
141}
142
143// This is called at 8000 Hz to load the next sample.
144ISR(TIMER1_COMPA_vect) {
145 if (sample >= sounddata_length) {
146 if (sample == sounddata_length + lastSample) {
147 TIMSK1 &= ~_BV(OCIE1A);
148
149 // Disable the per-sample timer completely.
150 TCCR1B &= ~_BV(CS10);
151 }
152 else {
153 OCR1C = sounddata_length + lastSample - sample;
154 }
155 }
156 else {
157 OCR1C = pgm_read_byte(&sounddata_data[sample]);
158 }
159
160 ++sample;
161}
162
163void play_notes() {
164
165
166 // Set up Timer 2 to do pulse width modulation on the speaker
167 // pin.
168
169 DDRB |= (1<<7);
170 PORTB &= ~(1<<7);
171
172 // Use internal clock (datasheet p.160)
173 // ASSR &= ~(_BV(EXCLK) | _BV(AS2));
174
175 // Set fast PWM mode (p.157)
176 TCCR1A |= _BV(WGM21) | _BV(WGM20);
177 TCCR1B &= ~_BV(WGM22);
178
179 // Do non-inverting PWM on pin OC2A (p.155)
180 // On the Arduino this is pin 11.
181 TCCR1A = (TCCR2A | _BV(COM2A1)) & ~_BV(COM2A0);
182 TCCR1A &= ~(_BV(COM2B1) | _BV(COM2B0));
183 // No prescaler (p.158)
184 TCCR1B = (TCCR1B & ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);
185
186 // Set initial pulse width to the first sample.
187 OCR1A = pgm_read_byte(&sounddata_data[0]);
188
189
190
191
192 cli();
193
194 // Set CTC mode (Clear Timer on Compare Match) (p.133)
195 // Have to set OCR1A *after*, otherwise it gets reset to 0!
196 TCCR2B = (TCCR2B & ~_BV(WGM13)) | _BV(WGM12);
197 TCCR2A = TCCR2A & ~(_BV(WGM11) | _BV(WGM10));
198
199 // No prescaler (p.134)
200 TCCR2B = (TCCR2B & ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);
201
202 // Set the compare register (OCR1A).
203 // OCR1A is a 16-bit register, so we have to do this with
204 // interrupts disabled to be safe.
205 // OCR2A = F_CPU / SAMPLE_RATE; // 16e6 / 8000 = 2000
206 OCR2A = 2000;
207
208 // Enable interrupt when TCNT1 == OCR1A (p.136)
209 TIMSK1 |= _BV(OCIE2A);
210
211 sample = 0;
212 sei();
213}
214
215void note(int x, float length) {
216 DDRB |= (1<<1);
217 int t = (int)(440*pow(2,-x/12.0)); // starting note
218 for (int y = 0; y < length*1000/t; y++) { // note length
219 PORTB |= (1<<1);
220 delay_us(t);
221 PORTB &= ~(1<<1);
222 delay_us(t);
223 }
224 PORTB &= ~(1<<1);
225}
226
227void true_note(float x, float y, float length) {
228 for (uint32_t i = 0; i < length * 50; i++) {
229 uint32_t v = (uint32_t) (round(sin(PI*2*i*640000*pow(2, x/12.0))*.5+1 + sin(PI*2*i*640000*pow(2, y/12.0))*.5+1) / 2 * pow(2, 8));
230 for (int u = 0; u < 8; u++) {
231 if (v & (1 << u) && !(PORTB&(1<<1)))
232 PORTB |= (1<<1);
233 else if (PORTB&(1<<1))
234 PORTB &= ~(1<<1);
235 }
236 }
237 PORTB &= ~(1<<1);
238} \ No newline at end of file
diff --git a/keyboard/preonic/beeps.h b/keyboard/preonic/beeps.h
new file mode 100644
index 000000000..3e3c634ff
--- /dev/null
+++ b/keyboard/preonic/beeps.h
@@ -0,0 +1,9 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include <avr/io.h>
4#include <util/delay.h>
5
6void note(int x, float length);
7void beeps();
8void true_note(float x, float y, float length);
9void play_note(float freq, int length); \ No newline at end of file
diff --git a/keyboard/preonic/config.h b/keyboard/preonic/config.h
new file mode 100644
index 000000000..00486c470
--- /dev/null
+++ b/keyboard/preonic/config.h
@@ -0,0 +1,76 @@
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_definitions.h"
22
23/* USB Device descriptor parameter */
24#define VENDOR_ID 0xFEED
25#define PRODUCT_ID 0x6060
26#define DEVICE_VER 0x0001
27#define MANUFACTURER Ortholinear Keyboards
28#define PRODUCT The Preonic Keyboard
29#define DESCRIPTION A compact ortholinear keyboard
30
31/* key matrix size */
32#define MATRIX_ROWS 5
33#define MATRIX_COLS 12
34
35/* Planck PCB default pin-out */
36#define COLS (int []){ F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 }
37#define ROWS (int []){ D1, D0, D5, B5, B6 }
38
39/* define if matrix has ghost */
40//#define MATRIX_HAS_GHOST
41
42/* number of backlight levels */
43#define BACKLIGHT_LEVELS 3
44
45/* Set 0 if debouncing isn't needed */
46#define DEBOUNCE 5
47
48/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
49#define LOCKING_SUPPORT_ENABLE
50/* Locking resynchronize hack */
51#define LOCKING_RESYNC_ENABLE
52
53/* key combination for command */
54#define IS_COMMAND() ( \
55 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
56)
57
58/*
59 * Feature disable options
60 * These options are also useful to firmware size reduction.
61 */
62
63/* disable debug print */
64#define NO_DEBUG
65
66/* disable print */
67#define NO_PRINT
68
69/* disable action features */
70//#define NO_ACTION_LAYER
71//#define NO_ACTION_TAPPING
72//#define NO_ACTION_ONESHOT
73//#define NO_ACTION_MACRO
74//#define NO_ACTION_FUNCTION
75
76#endif
diff --git a/keyboard/preonic/config_definitions.h b/keyboard/preonic/config_definitions.h
new file mode 100644
index 000000000..fd138b884
--- /dev/null
+++ b/keyboard/preonic/config_definitions.h
@@ -0,0 +1,50 @@
1#ifndef CONFIG_DEFINITIONS_H
2#define CONFIG_DEFINITIONS_H
3
4#define B0 0x20
5#define B1 0x21
6#define B2 0x22
7#define B3 0x23
8#define B4 0x24
9#define B5 0x25
10#define B6 0x26
11#define B7 0x27
12#define C0 0x30
13#define C1 0x31
14#define C2 0x32
15#define C3 0x33
16#define C4 0x34
17#define C5 0x35
18#define C6 0x36
19#define C7 0x37
20#define D0 0x40
21#define D1 0x41
22#define D2 0x42
23#define D3 0x43
24#define D4 0x44
25#define D5 0x45
26#define D6 0x46
27#define D7 0x47
28#define E0 0x50
29#define E1 0x51
30#define E2 0x52
31#define E3 0x53
32#define E4 0x54
33#define E5 0x55
34#define E6 0x56
35#define E7 0x57
36#define F0 0x60
37#define F1 0x61
38#define F2 0x62
39#define F3 0x63
40#define F4 0x64
41#define F5 0x65
42#define F6 0x66
43#define F7 0x67
44
45
46
47
48
49#endif
50
diff --git a/keyboard/preonic/extended_keymap_common.c b/keyboard/preonic/extended_keymap_common.c
new file mode 100644
index 000000000..ade850844
--- /dev/null
+++ b/keyboard/preonic/extended_keymap_common.c
@@ -0,0 +1,210 @@
1/*
2Copyright 2012,2013 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#include "extended_keymap_common.h"
19#include "report.h"
20#include "keycode.h"
21#include "action_layer.h"
22#include "action.h"
23#include "action_macro.h"
24#include "debug.h"
25#include "backlight.h"
26
27static action_t keycode_to_action(uint16_t keycode);
28
29
30/* converts key to action */
31action_t action_for_key(uint8_t layer, keypos_t key)
32{
33 // 16bit keycodes - important
34 uint16_t keycode = keymap_key_to_keycode(layer, key);
35
36 if (keycode >= 0x0100 && keycode < 0x2000) {
37 // Has a modifier
38 action_t action;
39 // Split it up
40 action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF);
41 return action;
42 } else if (keycode >= 0x2000 && keycode < 0x3000) {
43 // Is a shortcut for function layer, pull last 12bits
44 return keymap_func_to_action(keycode & 0xFFF);
45 } else if (keycode >= 0x3000 && keycode < 0x4000) {
46 action_t action;
47 action.code = ACTION_MACRO(keycode & 0xFF);
48 return action;
49 } else if (keycode >= BL_0 & keycode <= BL_15) {
50 action_t action;
51 action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
52 return action;
53 } else if (keycode == BL_DEC) {
54 action_t action;
55 action.code = ACTION_BACKLIGHT_DECREASE();
56 return action;
57 } else if (keycode == BL_INC) {
58 action_t action;
59 action.code = ACTION_BACKLIGHT_INCREASE();
60 return action;
61 } else if (keycode == BL_TOGG) {
62 action_t action;
63 action.code = ACTION_BACKLIGHT_TOGGLE();
64 return action;
65 } else if (keycode == BL_STEP) {
66 action_t action;
67 action.code = ACTION_BACKLIGHT_STEP();
68 return action;
69 } else if (keycode == RESET) {
70 bootloader_jump();
71 return;
72 } else if (keycode > RESET) {
73 // MIDI
74 return;
75 }
76
77 switch (keycode) {
78 case KC_FN0 ... KC_FN31:
79 return keymap_fn_to_action(keycode);
80#ifdef BOOTMAGIC_ENABLE
81 case KC_CAPSLOCK:
82 case KC_LOCKING_CAPS:
83 if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
84 return keycode_to_action(KC_LCTL);
85 }
86 return keycode_to_action(keycode);
87 case KC_LCTL:
88 if (keymap_config.swap_control_capslock) {
89 return keycode_to_action(KC_CAPSLOCK);
90 }
91 return keycode_to_action(KC_LCTL);
92 case KC_LALT:
93 if (keymap_config.swap_lalt_lgui) {
94 if (keymap_config.no_gui) {
95 return keycode_to_action(ACTION_NO);
96 }
97 return keycode_to_action(KC_LGUI);
98 }
99 return keycode_to_action(KC_LALT);
100 case KC_LGUI:
101 if (keymap_config.swap_lalt_lgui) {
102 return keycode_to_action(KC_LALT);
103 }
104 if (keymap_config.no_gui) {
105 return keycode_to_action(ACTION_NO);
106 }
107 return keycode_to_action(KC_LGUI);
108 case KC_RALT:
109 if (keymap_config.swap_ralt_rgui) {
110 if (keymap_config.no_gui) {
111 return keycode_to_action(ACTION_NO);
112 }
113 return keycode_to_action(KC_RGUI);
114 }
115 return keycode_to_action(KC_RALT);
116 case KC_RGUI:
117 if (keymap_config.swap_ralt_rgui) {
118 return keycode_to_action(KC_RALT);
119 }
120 if (keymap_config.no_gui) {
121 return keycode_to_action(ACTION_NO);
122 }
123 return keycode_to_action(KC_RGUI);
124 case KC_GRAVE:
125 if (keymap_config.swap_grave_esc) {
126 return keycode_to_action(KC_ESC);
127 }
128 return keycode_to_action(KC_GRAVE);
129 case KC_ESC:
130 if (keymap_config.swap_grave_esc) {
131 return keycode_to_action(KC_GRAVE);
132 }
133 return keycode_to_action(KC_ESC);
134 case KC_BSLASH:
135 if (keymap_config.swap_backslash_backspace) {
136 return keycode_to_action(KC_BSPACE);
137 }
138 return keycode_to_action(KC_BSLASH);
139 case KC_BSPACE:
140 if (keymap_config.swap_backslash_backspace) {
141 return keycode_to_action(KC_BSLASH);
142 }
143 return keycode_to_action(KC_BSPACE);
144#endif
145 default:
146 return keycode_to_action(keycode);
147 }
148}
149
150
151/* Macro */
152__attribute__ ((weak))
153const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
154{
155 return MACRO_NONE;
156}
157
158/* Function */
159__attribute__ ((weak))
160void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
161{
162}
163
164/* translates keycode to action */
165static action_t keycode_to_action(uint16_t keycode)
166{
167 action_t action;
168 switch (keycode) {
169 case KC_A ... KC_EXSEL:
170 case KC_LCTRL ... KC_RGUI:
171 action.code = ACTION_KEY(keycode);
172 break;
173 case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
174 action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
175 break;
176 case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
177 action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
178 break;
179 case KC_MS_UP ... KC_MS_ACCEL2:
180 action.code = ACTION_MOUSEKEY(keycode);
181 break;
182 case KC_TRNS:
183 action.code = ACTION_TRANSPARENT;
184 break;
185 default:
186 action.code = ACTION_NO;
187 break;
188 }
189 return action;
190}
191
192
193/* translates key to keycode */
194uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
195{
196 // Read entire word (16bits)
197 return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);
198}
199
200/* translates Fn keycode to action */
201action_t keymap_fn_to_action(uint16_t keycode)
202{
203 return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
204}
205
206action_t keymap_func_to_action(uint16_t keycode)
207{
208 // For FUNC without 8bit limit
209 return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) };
210}
diff --git a/keyboard/preonic/extended_keymap_common.h b/keyboard/preonic/extended_keymap_common.h
new file mode 100644
index 000000000..e6a7dac5b
--- /dev/null
+++ b/keyboard/preonic/extended_keymap_common.h
@@ -0,0 +1,180 @@
1/*
2Copyright 2012,2013 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 KEYMAP_H
19#define KEYMAP_H
20
21#include <stdint.h>
22#include <stdbool.h>
23#include "action.h"
24#include <avr/pgmspace.h>
25#include "keycode.h"
26#include "keymap.h"
27#include "action_macro.h"
28#include "report.h"
29#include "host.h"
30// #include "print.h"
31#include "debug.h"
32
33#ifdef BOOTMAGIC_ENABLE
34/* NOTE: Not portable. Bit field order depends on implementation */
35typedef union {
36 uint16_t raw;
37 struct {
38 bool swap_control_capslock:1;
39 bool capslock_to_control:1;
40 bool swap_lalt_lgui:1;
41 bool swap_ralt_rgui:1;
42 bool no_gui:1;
43 bool swap_grave_esc:1;
44 bool swap_backslash_backspace:1;
45 bool nkro:1;
46 };
47} keymap_config_t;
48keymap_config_t keymap_config;
49#endif
50
51
52/* translates key to keycode */
53uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
54
55/* translates Fn keycode to action */
56action_t keymap_fn_to_action(uint16_t keycode);
57
58/* translates Fn keycode to action */
59action_t keymap_func_to_action(uint16_t keycode);
60
61extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
62extern const uint16_t fn_actions[];
63
64// Ability to use mods in layouts
65#define LCTL(kc) kc | 0x0100
66#define LSFT(kc) kc | 0x0200
67#define LALT(kc) kc | 0x0400
68#define LGUI(kc) kc | 0x0800
69#define RCTL(kc) kc | 0x1100
70#define RSFT(kc) kc | 0x1200
71#define RALT(kc) kc | 0x1400
72#define RGUI(kc) kc | 0x1800
73
74// Alias for function layers than expand past FN31
75#define FUNC(kc) kc | 0x2000
76
77// Aliases
78#define S(kc) LSFT(kc)
79#define F(kc) FUNC(kc)
80
81// For software implementation of colemak
82#define CM_Q KC_Q
83#define CM_W KC_W
84#define CM_F KC_E
85#define CM_P KC_R
86#define CM_G KC_T
87#define CM_J KC_Y
88#define CM_L KC_U
89#define CM_U KC_I
90#define CM_Y KC_O
91#define CM_SCLN KC_P
92
93#define CM_A KC_A
94#define CM_R KC_S
95#define CM_S KC_D
96#define CM_T KC_F
97#define CM_D KC_G
98#define CM_H KC_H
99#define CM_N KC_J
100#define CM_E KC_K
101#define CM_I KC_L
102#define CM_O KC_SCLN
103
104#define CM_Z KC_Z
105#define CM_X KC_X
106#define CM_C KC_C
107#define CM_V KC_V
108#define CM_B KC_B
109#define CM_K KC_N
110#define CM_M KC_M
111#define CM_COMM KC_COMM
112#define CM_DOT KC_DOT
113#define CM_SLSH KC_SLSH
114
115// Make it easy to support these in macros
116#define KC_CM_Q CM_Q
117#define KC_CM_W CM_W
118#define KC_CM_F CM_F
119#define KC_CM_P CM_P
120#define KC_CM_G CM_G
121#define KC_CM_J CM_J
122#define KC_CM_L CM_L
123#define KC_CM_U CM_U
124#define KC_CM_Y CM_Y
125#define KC_CM_SCLN CM_SCLN
126
127#define KC_CM_A CM_A
128#define KC_CM_R CM_R
129#define KC_CM_S CM_S
130#define KC_CM_T CM_T
131#define KC_CM_D CM_D
132#define KC_CM_H CM_H
133#define KC_CM_N CM_N
134#define KC_CM_E CM_E
135#define KC_CM_I CM_I
136#define KC_CM_O CM_O
137
138#define KC_CM_Z CM_Z
139#define KC_CM_X CM_X
140#define KC_CM_C CM_C
141#define KC_CM_V CM_V
142#define KC_CM_B CM_B
143#define KC_CM_K CM_K
144#define KC_CM_M CM_M
145#define KC_CM_COMM CM_COMM
146#define KC_CM_DOT CM_DOT
147#define KC_CM_SLSH CM_SLSH
148
149#define M(kc) kc | 0x3000
150
151#define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
152
153#define BL_ON 0x4009
154#define BL_OFF 0x4000
155#define BL_0 0x4000
156#define BL_1 0x4001
157#define BL_2 0x4002
158#define BL_3 0x4003
159#define BL_4 0x4004
160#define BL_5 0x4005
161#define BL_6 0x4006
162#define BL_7 0x4007
163#define BL_8 0x4008
164#define BL_9 0x4009
165#define BL_10 0x400A
166#define BL_11 0x400B
167#define BL_12 0x400C
168#define BL_13 0x400D
169#define BL_14 0x400E
170#define BL_15 0x400F
171#define BL_DEC 0x4010
172#define BL_INC 0x4011
173#define BL_TOGG 0x4012
174#define BL_STEP 0x4013
175
176#define RESET 0x5000
177
178#define MIDI(n) n | 0x6000
179
180#endif
diff --git a/keyboard/preonic/extended_keymaps/extended_keymap_default.c b/keyboard/preonic/extended_keymaps/extended_keymap_default.c
new file mode 100644
index 000000000..c75144bf4
--- /dev/null
+++ b/keyboard/preonic/extended_keymaps/extended_keymap_default.c
@@ -0,0 +1,65 @@
1#include "extended_keymap_common.h"
2#include "backlight.h"
3#include "lufa.h"
4#include "debug.h"
5
6const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
7[0] = { /* Qwerty */
8 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
9 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
10 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT},
11 {M(0), KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
12 // Space is repeated to accommadate for both spacebar wiring positions
13},
14[1] = { /* Colemak */
15 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
16 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
17 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT},
18 {KC_FN3, KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
19},
20[2] = { /* RAISE */
21 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
22 {KC_TRNS, FUNC(3), FUNC(4), RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
23 {KC_TRNS, KC_F11, KC_F12, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS},
24 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FUNC(1), KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
25},
26[3] = { /* LOWER */
27 {S(KC_GRV), S(KC_1), S(KC_2), S(KC_3), S(KC_4), S(KC_5), S(KC_6), S(KC_7), S(KC_8), S(KC_9), S(KC_0), KC_BSPC},
28 {KC_TRNS, FUNC(3), FUNC(4), RESET, KC_TRNS, KC_TRNS, KC_TRNS, S(KC_MINS), S(KC_EQL), S(KC_LBRC), S(KC_RBRC), S(KC_BSLS)},
29 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_TRNS},
30 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FUNC(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
31},
32[4] = { /* TENKEY */
33 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_KP_7, KC_KP_8, KC_KP_9, KC_P, KC_BSPC},
34 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_KP_4, KC_KP_5, KC_KP_6, KC_SCLN, KC_QUOT},
35 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_KP_1, KC_KP_2, KC_KP_3, KC_SLSH, KC_ENT},
36 {KC_TRNS, KC_LCTL, KC_LALT, KC_LGUI, KC_TRNS, KC_SPC, KC_SPC, KC_KP_0, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
37}
38};
39
40const uint16_t PROGMEM fn_actions[] = {
41 [1] = ACTION_LAYER_MOMENTARY(2), // to RAISE
42 [2] = ACTION_LAYER_MOMENTARY(3), // to LOWER
43
44 [3] = ACTION_DEFAULT_LAYER_SET(0),
45 [4] = ACTION_DEFAULT_LAYER_SET(1),
46
47};
48
49const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
50{
51 // MACRODOWN only works in this function
52 switch(id) {
53 case 0:
54 if (record->event.pressed) {
55 register_code(KC_RSFT);
56 midi_send_noteon(&midi_device, 1, 64, 127);
57 backlight_step();
58 } else {
59 unregister_code(KC_RSFT);
60 midi_send_noteoff(&midi_device, 1, 64, 127);
61 }
62 break;
63 }
64 return MACRO_NONE;
65};
diff --git a/keyboard/preonic/extended_keymaps/extended_keymap_lock.c b/keyboard/preonic/extended_keymaps/extended_keymap_lock.c
new file mode 100644
index 000000000..c35ca8a10
--- /dev/null
+++ b/keyboard/preonic/extended_keymaps/extended_keymap_lock.c
@@ -0,0 +1,73 @@
1#include "extended_keymap_common.h"
2#include "backlight.h"
3#include "action_layer.h"
4#include "lufa.h"
5
6const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
7[0] = { /* Qwerty */
8 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
9 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
10 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
11 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT},
12 {M(0), KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
13 // Space is repeated to accommadate for both spacebar wiring positions
14},
15[1] = { /* Colemak */
16 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
17 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
18 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
19 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT},
20 {KC_FN3, KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
21},
22[2] = { /* RAISE */
23 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
24 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
25 {KC_TRNS, FUNC(3), FUNC(4), RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
26 {KC_TRNS, KC_F11, KC_F12, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS},
27 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FUNC(1), KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
28},
29[3] = { /* LOWER */
30 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
31 {S(KC_GRV), S(KC_1), S(KC_2), S(KC_3), S(KC_4), S(KC_5), S(KC_6), S(KC_7), S(KC_8), S(KC_9), S(KC_0), KC_BSPC},
32 {KC_TRNS, FUNC(3), FUNC(4), RESET, KC_TRNS, KC_TRNS, KC_TRNS, S(KC_MINS), S(KC_EQL), S(KC_LBRC), S(KC_RBRC), S(KC_BSLS)},
33 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_TRNS},
34 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FUNC(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
35},
36[4] = { /* TENKEY */
37 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
38 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_KP_7, KC_KP_8, KC_KP_9, KC_P, KC_BSPC},
39 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_KP_4, KC_KP_5, KC_KP_6, KC_SCLN, KC_QUOT},
40 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_KP_1, KC_KP_2, KC_KP_3, KC_SLSH, KC_ENT},
41 {KC_TRNS, KC_LCTL, KC_LALT, KC_LGUI, KC_TRNS, KC_SPC, KC_SPC, KC_KP_0, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
42}
43};
44
45const uint16_t PROGMEM fn_actions[] = {
46 [1] = ACTION_LAYER_MOMENTARY(2), // to RAISE
47 [2] = ACTION_LAYER_MOMENTARY(3), // to LOWER
48
49 [3] = ACTION_DEFAULT_LAYER_SET(0),
50 [4] = ACTION_DEFAULT_LAYER_SET(1),
51
52};
53
54const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
55{
56 // MACRODOWN only works in this function
57 switch(id) {
58 case 0:
59 if (record->event.pressed) {
60 // register_code(KC_RSFT);
61 backlight_set(BACKLIGHT_LEVELS);
62 midi_send_noteon(&midi_device, 1, 64, 127);
63 layer_on(4);
64 } else {
65 // unregister_code(KC_RSFT);
66 backlight_set(0);
67 midi_send_noteoff(&midi_device, 1, 64, 127);
68 layer_clear();
69 }
70 break;
71 }
72 return MACRO_NONE;
73};
diff --git a/keyboard/preonic/led.c b/keyboard/preonic/led.c
new file mode 100644
index 000000000..2c0574660
--- /dev/null
+++ b/keyboard/preonic/led.c
@@ -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#include <avr/io.h>
19#include "stdint.h"
20#include "led.h"
21
22
23void led_set(uint8_t usb_led)
24{
25 // // Using PE6 Caps Lock LED
26 // if (usb_led & (1<<USB_LED_CAPS_LOCK))
27 // {
28 // // Output high.
29 // DDRE |= (1<<6);
30 // PORTE |= (1<<6);
31 // }
32 // else
33 // {
34 // // Output low.
35 // DDRE &= ~(1<<6);
36 // PORTE &= ~(1<<6);
37 // }
38}
diff --git a/keyboard/preonic/matrix.c b/keyboard/preonic/matrix.c
new file mode 100644
index 000000000..98ef55ed6
--- /dev/null
+++ b/keyboard/preonic/matrix.c
@@ -0,0 +1,234 @@
1/*
2Copyright 2012 Jun Wako
3Generated by planckkeyboard.com (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
19/*
20 * scan matrix
21 */
22#include <stdint.h>
23#include <stdbool.h>
24#include <avr/io.h>
25#include <util/delay.h>
26#include "print.h"
27#include "debug.h"
28#include "util.h"
29#include "matrix.h"
30
31#ifndef DEBOUNCE
32# define DEBOUNCE 10
33#endif
34static uint8_t debouncing = DEBOUNCE;
35
36/* matrix state(1:on, 0:off) */
37static matrix_row_t matrix[MATRIX_ROWS];
38static matrix_row_t matrix_debouncing[MATRIX_ROWS];
39
40static matrix_row_t read_cols(void);
41static void init_cols(void);
42static void unselect_rows(void);
43static void select_row(uint8_t row);
44
45inline
46uint8_t matrix_rows(void)
47{
48 return MATRIX_ROWS;
49}
50
51inline
52uint8_t matrix_cols(void)
53{
54 return MATRIX_COLS;
55}
56
57void matrix_init(void)
58{
59 // To use PORTF disable JTAG with writing JTD bit twice within four cycles.
60 MCUCR |= (1<<JTD);
61 MCUCR |= (1<<JTD);
62
63 backlight_init_ports();
64
65 // Turn status LED on
66 DDRE |= (1<<6);
67 PORTE |= (1<<6);
68
69 // initialize row and col
70 unselect_rows();
71 init_cols();
72
73 // initialize matrix state: all keys off
74 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
75 matrix[i] = 0;
76 matrix_debouncing[i] = 0;
77 }
78}
79
80
81uint8_t matrix_scan(void)
82{
83 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
84 select_row(i);
85 _delay_us(30); // without this wait read unstable value.
86 matrix_row_t cols = read_cols();
87 if (matrix_debouncing[i] != cols) {
88 matrix_debouncing[i] = cols;
89 if (debouncing) {
90 debug("bounce!: "); debug_hex(debouncing); debug("\n");
91 }
92 debouncing = DEBOUNCE;
93 }
94 unselect_rows();
95 }
96
97 if (debouncing) {
98 if (--debouncing) {
99 _delay_ms(1);
100 } else {
101 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
102 matrix[i] = matrix_debouncing[i];
103 }
104 }
105 }
106
107 return 1;
108}
109
110bool matrix_is_modified(void)
111{
112 if (debouncing) return false;
113 return true;
114}
115
116inline
117bool matrix_is_on(uint8_t row, uint8_t col)
118{
119 return (matrix[row] & ((matrix_row_t)1<col));
120}
121
122inline
123matrix_row_t matrix_get_row(uint8_t row)
124{
125 return matrix[row];
126}
127
128void matrix_print(void)
129{
130 print("\nr/c 0123456789ABCDEF\n");
131 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
132 phex(row); print(": ");
133 pbin_reverse16(matrix_get_row(row));
134 print("\n");
135 }
136}
137
138uint8_t matrix_key_count(void)
139{
140 uint8_t count = 0;
141 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
142 count += bitpop16(matrix[i]);
143 }
144 return count;
145}
146
147static void init_cols(void)
148{
149 int B = 0, C = 0, D = 0, E = 0, F = 0;
150 for(int x = 0; x < MATRIX_COLS; x++) {
151 int col = COLS[x];
152 if ((col & 0xF0) == 0x20) {
153 B |= (1<<(col & 0x0F));
154 } else if ((col & 0xF0) == 0x30) {
155 C |= (1<<(col & 0x0F));
156 } else if ((col & 0xF0) == 0x40) {
157 D |= (1<<(col & 0x0F));
158 } else if ((col & 0xF0) == 0x50) {
159 E |= (1<<(col & 0x0F));
160 } else if ((col & 0xF0) == 0x60) {
161 F |= (1<<(col & 0x0F));
162 }
163 }
164 DDRB &= ~(B); PORTB |= (B);
165 DDRC &= ~(C); PORTC |= (C);
166 DDRD &= ~(D); PORTD |= (D);
167 DDRE &= ~(E); PORTE |= (E);
168 DDRF &= ~(F); PORTF |= (F);
169}
170
171static matrix_row_t read_cols(void)
172{
173 matrix_row_t result = 0;
174 for(int x = 0; x < MATRIX_COLS; x++) {
175 int col = COLS[x];
176 if ((col & 0xF0) == 0x20) {
177 result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<<x));
178 } else if ((col & 0xF0) == 0x30) {
179 result |= (PINC&(1<<(col & 0x0F)) ? 0 : (1<<x));
180 } else if ((col & 0xF0) == 0x40) {
181 result |= (PIND&(1<<(col & 0x0F)) ? 0 : (1<<x));
182 } else if ((col & 0xF0) == 0x50) {
183 result |= (PINE&(1<<(col & 0x0F)) ? 0 : (1<<x));
184 } else if ((col & 0xF0) == 0x60) {
185 result |= (PINF&(1<<(col & 0x0F)) ? 0 : (1<<x));
186 }
187 }
188 return result;
189}
190
191static void unselect_rows(void)
192{
193 int B = 0, C = 0, D = 0, E = 0, F = 0;
194 for(int x = 0; x < MATRIX_ROWS; x++) {
195 int row = ROWS[x];
196 if ((row & 0xF0) == 0x20) {
197 B |= (1<<(row & 0x0F));
198 } else if ((row & 0xF0) == 0x30) {
199 C |= (1<<(row & 0x0F));
200 } else if ((row & 0xF0) == 0x40) {
201 D |= (1<<(row & 0x0F));
202 } else if ((row & 0xF0) == 0x50) {
203 E |= (1<<(row & 0x0F));
204 } else if ((row & 0xF0) == 0x60) {
205 F |= (1<<(row & 0x0F));
206 }
207 }
208 DDRB &= ~(B); PORTB |= (B);
209 DDRC &= ~(C); PORTC |= (C);
210 DDRD &= ~(D); PORTD |= (D);
211 DDRE &= ~(E); PORTE |= (E);
212 DDRF &= ~(F); PORTF |= (F);
213}
214
215static void select_row(uint8_t row)
216{
217 int row_pin = ROWS[row];
218 if ((row_pin & 0xF0) == 0x20) {
219 DDRB |= (1<<(row_pin & 0x0F));
220 PORTB &= ~(1<<(row_pin & 0x0F));
221 } else if ((row_pin & 0xF0) == 0x30) {
222 DDRC |= (1<<(row_pin & 0x0F));
223 PORTC &= ~(1<<(row_pin & 0x0F));
224 } else if ((row_pin & 0xF0) == 0x40) {
225 DDRD |= (1<<(row_pin & 0x0F));
226 PORTD &= ~(1<<(row_pin & 0x0F));
227 } else if ((row_pin & 0xF0) == 0x50) {
228 DDRE |= (1<<(row_pin & 0x0F));
229 PORTE &= ~(1<<(row_pin & 0x0F));
230 } else if ((row_pin & 0xF0) == 0x60) {
231 DDRF |= (1<<(row_pin & 0x0F));
232 PORTF &= ~(1<<(row_pin & 0x0F));
233 }
234} \ No newline at end of file
diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c
index 6eedd5700..0536b7911 100644
--- a/protocol/lufa/descriptor.c
+++ b/protocol/lufa/descriptor.c
@@ -487,6 +487,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
487 }, 487 },
488#endif 488#endif
489 489
490#ifdef MIDI_ENABLE
490 .Audio_ControlInterface = 491 .Audio_ControlInterface =
491 { 492 {
492 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, 493 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
@@ -508,7 +509,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
508 .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface}, 509 .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
509 .Subtype = AUDIO_DSUBTYPE_CSInterface_Header, 510 .Subtype = AUDIO_DSUBTYPE_CSInterface_Header,
510 511
511 .ACSpecification = VERSION_BCD(1,1,1), 512 .ACSpecification = VERSION_BCD(1,0,0),
512 .TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t), 513 .TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t),
513 514
514 .InCollection = 1, 515 .InCollection = 1,
@@ -536,7 +537,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
536 .Header = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = DTYPE_CSInterface}, 537 .Header = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = DTYPE_CSInterface},
537 .Subtype = AUDIO_DSUBTYPE_CSInterface_General, 538 .Subtype = AUDIO_DSUBTYPE_CSInterface_General,
538 539
539 .AudioSpecification = VERSION_BCD(1,1,1), 540 .AudioSpecification = VERSION_BCD(1,0,0),
540 541
541 .TotalLength = (sizeof(USB_Descriptor_Configuration_t) - 542 .TotalLength = (sizeof(USB_Descriptor_Configuration_t) -
542 offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC)) 543 offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC))
@@ -603,7 +604,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
603 .EndpointAddress = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM), 604 .EndpointAddress = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM),
604 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 605 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
605 .EndpointSize = MIDI_STREAM_EPSIZE, 606 .EndpointSize = MIDI_STREAM_EPSIZE,
606 .PollingIntervalMS = 0x01 607 .PollingIntervalMS = 0x05
607 }, 608 },
608 609
609 .Refresh = 0, 610 .Refresh = 0,
@@ -628,7 +629,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
628 .EndpointAddress = (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM), 629 .EndpointAddress = (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
629 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 630 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
630 .EndpointSize = MIDI_STREAM_EPSIZE, 631 .EndpointSize = MIDI_STREAM_EPSIZE,
631 .PollingIntervalMS = 0x01 632 .PollingIntervalMS = 0x05
632 }, 633 },
633 634
634 .Refresh = 0, 635 .Refresh = 0,
@@ -643,7 +644,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
643 .TotalEmbeddedJacks = 0x01, 644 .TotalEmbeddedJacks = 0x01,
644 .AssociatedJackID = {0x03} 645 .AssociatedJackID = {0x03}
645 } 646 }
646 647#endif
647}; 648};
648 649
649 650
diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h
index 58a7df440..44f4c8f4a 100644
--- a/protocol/lufa/descriptor.h
+++ b/protocol/lufa/descriptor.h
@@ -86,6 +86,7 @@ typedef struct
86 USB_Descriptor_Endpoint_t NKRO_INEndpoint; 86 USB_Descriptor_Endpoint_t NKRO_INEndpoint;
87#endif 87#endif
88 88
89#ifdef MIDI_ENABLE
89 // MIDI Audio Control Interface 90 // MIDI Audio Control Interface
90 USB_Descriptor_Interface_t Audio_ControlInterface; 91 USB_Descriptor_Interface_t Audio_ControlInterface;
91 USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC; 92 USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;
@@ -101,6 +102,7 @@ typedef struct
101 USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC; 102 USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
102 USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint; 103 USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
103 USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC; 104 USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;
105#endif
104 106
105} USB_Descriptor_Configuration_t; 107} USB_Descriptor_Configuration_t;
106 108
@@ -132,9 +134,14 @@ typedef struct
132# define NKRO_INTERFACE CONSOLE_INTERFACE 134# define NKRO_INTERFACE CONSOLE_INTERFACE
133#endif 135#endif
134 136
137#ifdef MIDI_ENABLE
138# define MIDI_INTERFACE (NKRO_INTERFACE + 1)
139#else
140# define MIDI_INTERFACE NKRO_INTERFACE
141#endif
135 142
136/* nubmer of interfaces */ 143/* nubmer of interfaces */
137#define TOTAL_INTERFACES (NKRO_INTERFACE + 3) 144#define TOTAL_INTERFACES (MIDI_INTERFACE + 1)
138 145
139 146
140// Endopoint number and size 147// Endopoint number and size
@@ -167,8 +174,13 @@ typedef struct
167# endif 174# endif
168#endif 175#endif
169 176
170#define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1) 177#ifdef MIDI_ENABLE
171#define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1) 178# define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1)
179# define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1)
180#else
181# define MIDI_STREAM_IN_EPNUM NKRO_IN_EPNUM
182# define MIDI_STREAM_OUT_EPNUM NKRO_IN_EPNUM
183#endif
172 184
173 185
174#define KEYBOARD_EPSIZE 8 186#define KEYBOARD_EPSIZE 8
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index d4c8eb169..0bb667a4e 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -66,27 +66,35 @@ static void send_keyboard(report_keyboard_t *report);
66static void send_mouse(report_mouse_t *report); 66static void send_mouse(report_mouse_t *report);
67static void send_system(uint16_t data); 67static void send_system(uint16_t data);
68static void send_consumer(uint16_t data); 68static void send_consumer(uint16_t data);
69
70#ifdef MIDI_ENABLE
69void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); 71void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2);
70void usb_get_midi(MidiDevice * device); 72void usb_get_midi(MidiDevice * device);
71void midi_usb_init(MidiDevice * device); 73void midi_usb_init(MidiDevice * device);
74#endif
75
72host_driver_t lufa_driver = { 76host_driver_t lufa_driver = {
73 keyboard_leds, 77 keyboard_leds,
74 send_keyboard, 78 send_keyboard,
75 send_mouse, 79 send_mouse,
76 send_system, 80 send_system,
77 send_consumer, 81 send_consumer,
82#ifdef MIDI_ENABLE
78 usb_send_func, 83 usb_send_func,
79 usb_get_midi, 84 usb_get_midi,
80 midi_usb_init 85 midi_usb_init,
86#endif
87
81}; 88};
82 89
83void SetupHardware(void); 90void SetupHardware(void);
84 91
92
85USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = 93USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface =
86{ 94{
87 .Config = 95 .Config =
88 { 96 {
89 .StreamingInterfaceNumber = 1, 97 .StreamingInterfaceNumber = (NKRO_INTERFACE + 2),
90 .DataINEndpoint = 98 .DataINEndpoint =
91 { 99 {
92 .Address = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM), 100 .Address = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM),
@@ -112,6 +120,7 @@ USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface =
112#define SYS_COMMON_3 0x30 120#define SYS_COMMON_3 0x30
113 121
114 122
123
115/******************************************************************************* 124/*******************************************************************************
116 * Console 125 * Console
117 ******************************************************************************/ 126 ******************************************************************************/
@@ -279,8 +288,15 @@ void EVENT_USB_Device_ConfigurationChanged(void)
279 NKRO_EPSIZE, ENDPOINT_BANK_SINGLE); 288 NKRO_EPSIZE, ENDPOINT_BANK_SINGLE);
280#endif 289#endif
281 290
291#ifdef MIDI_ENABLE
292 // ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&USB_MIDI_Interface);
293
294 ConfigSuccess &= ENDPOINT_CONFIG(MIDI_STREAM_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
295 MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
296 ConfigSuccess &= ENDPOINT_CONFIG(MIDI_STREAM_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
297 MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
298#endif
282 299
283 ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&USB_MIDI_Interface);
284} 300}
285 301
286 302
@@ -589,32 +605,37 @@ int8_t sendchar(uint8_t c)
589 605
590 606
591 607
608#ifdef MIDI_ENABLE
592void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) { 609void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
593 MIDI_EventPacket_t event; 610 MIDI_EventPacket_t event;
594 event.Data1 = byte0; 611 event.Data1 = byte0;
595 event.Data2 = byte1; 612 event.Data2 = byte1;
596 event.Data3 = byte2; 613 event.Data3 = byte2;
597 614
615 uint8_t cable = 0;
616
617Endpoint_SelectEndpoint(MIDI_STREAM_IN_EPNUM);
618
598 //if the length is undefined we assume it is a SYSEX message 619 //if the length is undefined we assume it is a SYSEX message
599 if (midi_packet_length(byte0) == UNDEFINED) { 620 if (midi_packet_length(byte0) == UNDEFINED) {
600 switch(cnt) { 621 switch(cnt) {
601 case 3: 622 case 3:
602 if (byte2 == SYSEX_END) 623 if (byte2 == SYSEX_END)
603 event.Event = MIDI_EVENT(0, SYSEX_ENDS_IN_3); 624 event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_3);
604 else 625 else
605 event.Event = MIDI_EVENT(0, SYSEX_START_OR_CONT); 626 event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
606 break; 627 break;
607 case 2: 628 case 2:
608 if (byte1 == SYSEX_END) 629 if (byte1 == SYSEX_END)
609 event.Event = MIDI_EVENT(0, SYSEX_ENDS_IN_2); 630 event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_2);
610 else 631 else
611 event.Event = MIDI_EVENT(0, SYSEX_START_OR_CONT); 632 event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
612 break; 633 break;
613 case 1: 634 case 1:
614 if (byte0 == SYSEX_END) 635 if (byte0 == SYSEX_END)
615 event.Event = MIDI_EVENT(0, SYSEX_ENDS_IN_1); 636 event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_1);
616 else 637 else
617 event.Event = MIDI_EVENT(0, SYSEX_START_OR_CONT); 638 event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
618 break; 639 break;
619 default: 640 default:
620 return; //invalid cnt 641 return; //invalid cnt
@@ -624,18 +645,21 @@ void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byt
624 //TODO are there any more? 645 //TODO are there any more?
625 switch(byte0 & 0xF0){ 646 switch(byte0 & 0xF0){
626 case MIDI_SONGPOSITION: 647 case MIDI_SONGPOSITION:
627 event.Event = MIDI_EVENT(0, SYS_COMMON_3); 648 event.Event = MIDI_EVENT(cable, SYS_COMMON_3);
628 break; 649 break;
629 case MIDI_SONGSELECT: 650 case MIDI_SONGSELECT:
630 case MIDI_TC_QUARTERFRAME: 651 case MIDI_TC_QUARTERFRAME:
631 event.Event = MIDI_EVENT(0, SYS_COMMON_2); 652 event.Event = MIDI_EVENT(cable, SYS_COMMON_2);
632 break; 653 break;
633 default: 654 default:
634 event.Event = MIDI_EVENT(0, byte0); 655 event.Event = MIDI_EVENT(cable, byte0);
635 break; 656 break;
636 } 657 }
637 } 658 }
638 659
660Endpoint_Write_Stream_LE(&event, sizeof(event), NULL);
661Endpoint_ClearIN();
662
639 MIDI_Device_SendEventPacket(&USB_MIDI_Interface, &event); 663 MIDI_Device_SendEventPacket(&USB_MIDI_Interface, &event);
640 MIDI_Device_Flush(&USB_MIDI_Interface); 664 MIDI_Device_Flush(&USB_MIDI_Interface);
641 MIDI_Device_USBTask(&USB_MIDI_Interface); 665 MIDI_Device_USBTask(&USB_MIDI_Interface);
@@ -680,7 +704,7 @@ void midi_usb_init(MidiDevice * device){
680 SetupHardware(); 704 SetupHardware();
681 sei(); 705 sei();
682} 706}
683 707#endif
684 708
685 709
686 710
@@ -707,25 +731,30 @@ void SetupHardware(void)
707 print_set_sendchar(sendchar); 731 print_set_sendchar(sendchar);
708} 732}
709 733
734#ifdef MIDI_ENABLE
710void fallthrough_callback(MidiDevice * device, 735void fallthrough_callback(MidiDevice * device,
711 uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); 736 uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2);
712void cc_callback(MidiDevice * device, 737void cc_callback(MidiDevice * device,
713 uint8_t chan, uint8_t num, uint8_t val); 738 uint8_t chan, uint8_t num, uint8_t val);
714void sysex_callback(MidiDevice * device, 739void sysex_callback(MidiDevice * device,
715 uint16_t start, uint8_t length, uint8_t * data); 740 uint16_t start, uint8_t length, uint8_t * data);
741#endif
716 742
717int main(void) __attribute__ ((weak)); 743int main(void) __attribute__ ((weak));
718int main(void) 744int main(void)
719{ 745{
720 //setup the device 746 //setup the device
721 747
748#ifdef MIDI_ENABLE
722 midi_device_init(&midi_device); 749 midi_device_init(&midi_device);
723 midi_device_set_send_func(&midi_device, usb_send_func); 750 midi_device_set_send_func(&midi_device, usb_send_func);
724 midi_device_set_pre_input_process_func(&midi_device, usb_get_midi); 751 midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
752#endif
725 753
726 SetupHardware(); 754 SetupHardware();
727 sei(); 755 sei();
728 756
757#ifdef MIDI_ENABLE
729 midi_register_fallthrough_callback(&midi_device, fallthrough_callback); 758 midi_register_fallthrough_callback(&midi_device, fallthrough_callback);
730 midi_register_cc_callback(&midi_device, cc_callback); 759 midi_register_cc_callback(&midi_device, cc_callback);
731 midi_register_sysex_callback(&midi_device, sysex_callback); 760 midi_register_sysex_callback(&midi_device, sysex_callback);
@@ -734,6 +763,8 @@ int main(void)
734 midi_send_cc(&midi_device, 15, 1, 0); 763 midi_send_cc(&midi_device, 15, 1, 0);
735 midi_send_noteon(&midi_device, 0, 64, 127); 764 midi_send_noteon(&midi_device, 0, 64, 127);
736 midi_send_noteoff(&midi_device, 0, 64, 127); 765 midi_send_noteoff(&midi_device, 0, 64, 127);
766#endif
767
737 768
738 /* wait for USB startup & debug output */ 769 /* wait for USB startup & debug output */
739 while (USB_DeviceState != DEVICE_STATE_Configured) { 770 while (USB_DeviceState != DEVICE_STATE_Configured) {
@@ -764,7 +795,9 @@ int main(void)
764 795
765 keyboard_task(); 796 keyboard_task();
766 797
798#ifdef MIDI_ENABLE
767 midi_device_process(&midi_device); 799 midi_device_process(&midi_device);
800#endif
768 801
769#if !defined(INTERRUPT_CONTROL_ENDPOINT) 802#if !defined(INTERRUPT_CONTROL_ENDPOINT)
770 USB_USBTask(); 803 USB_USBTask();
@@ -772,6 +805,7 @@ int main(void)
772 } 805 }
773} 806}
774 807
808#ifdef MIDI_ENABLE
775//echo data back 809//echo data back
776void fallthrough_callback(MidiDevice * device, 810void fallthrough_callback(MidiDevice * device,
777 uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2){ 811 uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2){
@@ -790,3 +824,4 @@ void sysex_callback(MidiDevice * device,
790 for (int i = 0; i < length; i++) 824 for (int i = 0; i < length; i++)
791 midi_send_cc(device, 15, 0x7F & data[i], 0x7F & (start + i)); 825 midi_send_cc(device, 15, 0x7F & data[i], 0x7F & (start + i));
792} 826}
827#endif
diff --git a/protocol/lufa/midi/Config/LUFAConfig.h b/protocol/lufa/midi/Config/LUFAConfig.h
new file mode 100755
index 000000000..fa9404498
--- /dev/null
+++ b/protocol/lufa/midi/Config/LUFAConfig.h
@@ -0,0 +1,93 @@
1/*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7*/
8
9/*
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29*/
30
31/** \file
32 * \brief LUFA Library Configuration Header File
33 *
34 * This header file is used to configure LUFA's compile time options,
35 * as an alternative to the compile time constants supplied through
36 * a makefile.
37 *
38 * For information on what each token does, refer to the LUFA
39 * manual section "Summary of Compile Tokens".
40 */
41
42#ifndef _LUFA_CONFIG_H_
43#define _LUFA_CONFIG_H_
44
45 #if (ARCH == ARCH_AVR8)
46
47 /* Non-USB Related Configuration Tokens: */
48// #define DISABLE_TERMINAL_CODES
49
50 /* USB Class Driver Related Tokens: */
51// #define HID_HOST_BOOT_PROTOCOL_ONLY
52// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
53// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
54// #define HID_MAX_COLLECTIONS {Insert Value Here}
55// #define HID_MAX_REPORTITEMS {Insert Value Here}
56// #define HID_MAX_REPORT_IDS {Insert Value Here}
57// #define NO_CLASS_DRIVER_AUTOFLUSH
58
59 /* General USB Driver Related Tokens: */
60// #define ORDERED_EP_CONFIG
61 #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
62 #define USB_DEVICE_ONLY
63// #define USB_HOST_ONLY
64// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
65// #define NO_LIMITED_CONTROLLER_CONNECT
66// #define NO_SOF_EVENTS
67
68 /* USB Device Mode Driver Related Tokens: */
69// #define USE_RAM_DESCRIPTORS
70 #define USE_FLASH_DESCRIPTORS
71// #define USE_EEPROM_DESCRIPTORS
72// #define NO_INTERNAL_SERIAL
73 #define FIXED_CONTROL_ENDPOINT_SIZE 8
74// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
75 #define FIXED_NUM_CONFIGURATIONS 1
76// #define CONTROL_ONLY_DEVICE
77// #define INTERRUPT_CONTROL_ENDPOINT
78// #define NO_DEVICE_REMOTE_WAKEUP
79// #define NO_DEVICE_SELF_POWER
80
81 /* USB Host Mode Driver Related Tokens: */
82// #define HOST_STATE_AS_GPIOR {Insert Value Here}
83// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
84// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
85// #define NO_AUTO_VBUS_MANAGEMENT
86// #define INVERTED_VBUS_ENABLE_LINE
87
88 #else
89
90 #error Unsupported architecture for this LUFA configuration file.
91
92 #endif
93#endif