aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIBNobody <ibnobody@gmail.com>2016-04-16 19:31:32 -0500
committerIBNobody <ibnobody@gmail.com>2016-04-16 19:31:32 -0500
commit4aea806aa8aa585930a89b67d7206050ac6adb3a (patch)
treead8b36cc2ebb7500a531ff4601a6fbdf1086ffe2
parentb5c22ab5b5b77d5e21cc4145831608eed6756ad7 (diff)
parentb8d2e66638409066661e7dd3c66473d583256ec5 (diff)
downloadqmk_firmware-4aea806aa8aa585930a89b67d7206050ac6adb3a.tar.gz
qmk_firmware-4aea806aa8aa585930a89b67d7206050ac6adb3a.zip
Adding Musical Notes
-rw-r--r--README.md22
-rw-r--r--keyboard/planck/keymaps/bone2planck.c112
-rw-r--r--keyboard/planck/keymaps/default/README.md32
-rw-r--r--keyboard/planck/keymaps/default/keymap.c86
-rw-r--r--keyboard/preonic/Makefile55
-rw-r--r--keyboard/preonic/keymaps/default/README.md35
-rw-r--r--keyboard/preonic/keymaps/default/keymap.c337
-rw-r--r--keyboard/preonic/keymaps/default/makefile.mk1
-rw-r--r--quantum/audio.c146
-rw-r--r--quantum/audio.h18
-rw-r--r--quantum/keymap_common.c258
-rw-r--r--quantum/keymap_common.h32
-rw-r--r--quantum/musical_notes.h182
-rw-r--r--quantum/quantum.mk1
-rw-r--r--quantum/tools/README.md6
-rw-r--r--quantum/tools/eeprom_reset.hex9
-rw-r--r--tmk_core/common.mk3
-rw-r--r--tmk_core/common/avr/eeconfig.c8
-rw-r--r--tmk_core/common/eeconfig.h6
-rw-r--r--tmk_core/common/keyboard.c8
-rw-r--r--tmk_core/common/keymap.h3
-rw-r--r--tmk_core/common/magic.c36
-rw-r--r--tmk_core/common/magic.h6
23 files changed, 1069 insertions, 333 deletions
diff --git a/README.md b/README.md
index ab7373023..6e1ab9bc5 100644
--- a/README.md
+++ b/README.md
@@ -16,13 +16,21 @@ The documentation below explains QMK customizations and elaborates on some of th
16* If you're looking to customize a keyboard that currently runs QMK or TMK, find your keyboard's directory under `keyboard/` and run the make commands from there. 16* If you're looking to customize a keyboard that currently runs QMK or TMK, find your keyboard's directory under `keyboard/` and run the make commands from there.
17* If you're looking to apply this firmware to an entirely new hardware project (a new kind of keyboard), you can create your own Quantum-based project by using `./new_project.sh <project_name>`, which will create `/keyboard/<project_name>` with all the necessary components for a Quantum project. 17* If you're looking to apply this firmware to an entirely new hardware project (a new kind of keyboard), you can create your own Quantum-based project by using `./new_project.sh <project_name>`, which will create `/keyboard/<project_name>` with all the necessary components for a Quantum project.
18 18
19### Makefile Options
20
19You have access to a bunch of goodies! Check out the Makefile to enable/disable some of the features. Uncomment the `#` to enable them. Setting them to `no` does nothing and will only confuse future you. 21You have access to a bunch of goodies! Check out the Makefile to enable/disable some of the features. Uncomment the `#` to enable them. Setting them to `no` does nothing and will only confuse future you.
20 22
21 BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality 23 BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
22 MIDI_ENABLE = yes # MIDI controls 24 MIDI_ENABLE = yes # MIDI controls
23 # UNICODE_ENABLE = yes # Unicode support - this is commented out, just as an example. You have to use #, not // 25 UNICODE_ENABLE = no # <-- This is how you disable an option, just set it to "no"
24 BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID 26 BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
25 27
28### Customizing Makefile options on a per-keymap basis
29
30If your keymap directory has a file called `makefile.mk` (note the lowercase filename, and the `.mk` extension), any Makefile options you set in that file will take precedence over other Makefile options (those set for Quantum as a whole or for your particular keyboard).
31
32So let's say your keyboard's makefile has `CONSOLE_ENABLE = yes` (or maybe doesn't even list the `CONSOLE_ENABLE` option, which would cause it to revert to the global Quantum default). You want your particular keymap to not have the debug console, so you make a file called `makefile.mk` and specify `CONSOLE_ENABLE = no`.
33
26## Quick aliases to common actions 34## Quick aliases to common actions
27 35
28Your keymap can include shortcuts to common operations (called "function actions" in tmk). 36Your keymap can include shortcuts to common operations (called "function actions" in tmk).
@@ -199,6 +207,10 @@ This will clear all mods currently pressed.
199 207
200This will clear all keys besides the mods currently pressed. 208This will clear all keys besides the mods currently pressed.
201 209
210* `update_tri_layer(layer_1, layer_2, layer_3);`
211
212If the user attempts to activate layer 1 AND layer 2 at the same time (for example, by hitting their respective layer keys), layer 3 will be activated. Layers 1 and 2 will _also_ be activated, for the purposes of fallbacks (so a given key will fall back from 3 to 2, to 1 -- and only then to 0).
213
202#### Timer functionality 214#### Timer functionality
203 215
204It's possible to start timers and read values for time-specific events - here's an example: 216It's possible to start timers and read values for time-specific events - here's an example:
@@ -292,7 +304,7 @@ For this mod, you need an unused pin wiring to DI of WS2812 strip. After wiring
292 304
293Please note that the underglow is not compatible with audio output. So you cannot enable both of them at the same time. 305Please note that the underglow is not compatible with audio output. So you cannot enable both of them at the same time.
294 306
295Please add the following options into your config.h, and set them up according your hardware configuration. 307Please add the following options into your config.h, and set them up according your hardware configuration. These settings are for the F4 by default:
296 308
297 #define ws2812_PORTREG PORTF 309 #define ws2812_PORTREG PORTF
298 #define ws2812_DDRREG DDRF 310 #define ws2812_DDRREG DDRF
@@ -302,6 +314,12 @@ Please add the following options into your config.h, and set them up according y
302 #define RGBLIGHT_SAT_STEP 17 314 #define RGBLIGHT_SAT_STEP 17
303 #define RGBLIGHT_VAL_STEP 17 315 #define RGBLIGHT_VAL_STEP 17
304 316
317You'll need to edit `PORTF`, `DDRF`, and `PF4` on the first three lines to the port/pin you have your LED(s) wired to, eg for B3 change things to:
318
319 #define ws2812_PORTREG PORTB
320 #define ws2812_DDRREG DDRB
321 #define ws2812_pin PB3
322
305The firmware supports 5 different light effects, and the color (hue, saturation, brightness) can be customized in most effects. To control the underglow, you need to modify your keymap file to assign those functions to some keys/key combinations. For details, please check this keymap. `keyboard/planck/keymaps/yang/keymap.c` 323The firmware supports 5 different light effects, and the color (hue, saturation, brightness) can be customized in most effects. To control the underglow, you need to modify your keymap file to assign those functions to some keys/key combinations. For details, please check this keymap. `keyboard/planck/keymaps/yang/keymap.c`
306 324
307### WS2812 Wiring 325### WS2812 Wiring
diff --git a/keyboard/planck/keymaps/bone2planck.c b/keyboard/planck/keymaps/bone2planck.c
new file mode 100644
index 000000000..a99e7719f
--- /dev/null
+++ b/keyboard/planck/keymaps/bone2planck.c
@@ -0,0 +1,112 @@
1
2#include "planck.h"
3#ifdef BACKLIGHT_ENABLE
4#include "backlight.h"
5#endif
6#include "..\..\quantum\keymap_extras\keymap_german.h"
7
8/* This Layout tries to emulate the Bone2 Variant of Neo2, and is intended to be used with a German QWERTZ Softwarelayout.
9 It has Umlauts and "ß" as it is optimized for a mix of German & English.
10 My favourite features are the placement of the special characters often used for programming right on the home row
11 and the number & navigation block combo, so you never have to move your hands from their home position.
12
13 Bone2 wiki page: http://wiki.neo-layout.org/wiki/Bone
14*/
15
16const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
17
18 /* Bone2
19 * ,-----------------------------------------------------------------------------------.
20 * | Q | J | D | U | A | X | P | H | L | M | W | ẞ |
21 * |------+------+------+------+------+-------------+------+------+------+------+------|
22 * | M1 | C | T | I | E | O | B | N | R | S | G | M1 |
23 * |------+------+------+------+------+------|------+------+------+------+------+------|
24 * | Shift| F | V | Ü | Ä | Ö | Y | Z | , | . | K |Shift |
25 * |------+------+------+------+------+------+------+------+------+------+------+------|
26 * | Ctrl | GUI | Alt | M3 | M2 | Space | M2 | M3 | Esc | Tab |Enter |
27 * `-----------------------------------------------------------------------------------'
28 */
29 [0] = {
30 { DE_Q, DE_J, DE_D, DE_U, DE_A, DE_X, DE_P, DE_H, DE_L, DE_M, DE_W, DE_SS },
31 { MO(1), DE_C, DE_T, DE_I, DE_E, DE_O, DE_B, DE_N, DE_R, DE_S, DE_G, MO(1) },
32 { DE_S, DE_F, DE_V, DE_UE, DE_AE, DE_OE, DE_Y, DE_Z, DE_COMM, DE_DOT, DE_K, DE_S },
33 { KC_LCTL, KC_LGUI, KC_LALT, MO(3), MO(2), KC_SPC, KC_SPC, MO(2), MO(3), KC_ESC, KC_TAB, KC_ENT }
34 },
35
36 /* M1 Special Characters
37 * ,-----------------------------------------------------------------------------------.
38 * | ° | @ | _ | [ | ] | ^ | ! | < | > | = | & | |
39 * |------+------+------+------+------+-------------+------+------+------+------+------|
40 * | M1 | \ | / | { | } | * | ? | ( | ) | - | : | M1 |
41 * |------+------+------+------+------+------|------+------+------+------+------+------|
42 * | | # | $ | | | ~ | € | + | % | " | ' | ; | |
43 * |------+------+------+------+------+------+------+------+------+------+------+------|
44 * | Ctrl | GUI | Alt | M3 | M2 | Space | M2 | M3 | Esc | Tab |Enter |
45 * `-----------------------------------------------------------------------------------'
46 */
47 [1] = {
48 { DE_RING, DE_AT, DE_UNDS, DE_LBRC, DE_RBRC, DE_CIRC, DE_EXLM, DE_LESS, DE_MORE, DE_EQL, DE_AMPR, KC_NO },
49 { KC_TRNS, DE_BSLS, DE_SLSH, DE_LCBR, DE_RCBR, DE_ASTR, DE_QST, DE_LPRN, DE_RPRN, DE_MINS, DE_COLN, KC_TRNS },
50 { KC_NO , DE_HASH, DE_DLR, DE_PIPE, DE_TILD, DE_EURO, DE_PLUS, DE_PERC, DE_DQOT, DE_QUOT, DE_SCLN, KC_NO },
51 { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS }
52 },
53
54 /* Navigation & Number Blocks
55 * ,-----------------------------------------------------------------------------------.
56 * | | PgUp | Bksp | Up | DEL | PgDn | | 7 | 8 | 9 | | |
57 * |------+------+------+------+------+-------------+------+------+------+------+------|
58 * | | Home | Lft | Down | Right| End | . | 4 | 5 | 6 | , | |
59 * |------+------+------+------+------+------|------+------+------+------+------+------|
60 * | Shift| | Tab | Ins | Enter| | 0 | 1 | 2 | 3 | ; |Shift |
61 * |------+------+------+------+------+------+------+------+------+------+------+------|
62 * | Ctrl | GUI | Alt | M3 | M2 | Space | M2 | M3 | Esc | Tab |Enter |
63 * `-----------------------------------------------------------------------------------'
64 */
65 [2] = {
66 { KC_NO, KC_PGUP, KC_BSPC, KC_UP, KC_DEL, KC_PGDN, KC_NO, DE_7, DE_8, DE_9, KC_NO, KC_NO },
67 { KC_NO, KC_HOME, KC_LEFT, KC_DOWN, KC_RGHT, KC_END, DE_DOT, DE_4, DE_5, DE_6, DE_COMM, KC_NO },
68 { DE_S, KC_NO, KC_TAB, KC_INS, KC_ENT, KC_NO, KC_0, DE_1, DE_2, DE_3, DE_SCLN, DE_S },
69 { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS }
70 },
71
72 /* Function & Media Keys
73 * ,-----------------------------------------------------------------------------------.
74 * | | | Print|Scroll|Pause | | | F7 | F8 | F9 | F12 | |
75 * |------+------+------+------+------+-------------+------+------+------+------+------|
76 * | | | Mute | Vol- | Vol+ | | ³ | F4 | F5 | F6 | F11 | |
77 * |------+------+------+------+------+------|------+------+------+------+------+------|
78 * | Shift| | Prev | Play | Next | | ² | F1 | F2 | F3 | F10 |Shift |
79 * |------+------+------+------+------+------+------+------+------+------+------+------|
80 * | Ctrl | GUI | Alt | M3 | | Space | | M3 | Esc | Tab |Enter |
81 * `-----------------------------------------------------------------------------------'
82 */
83 [3] = {
84 { KC_NO, KC_NO, KC_PSCR, KC_SLCK, KC_PAUS, KC_NO, KC_NO, KC_F7, KC_F8, KC_F9, KC_F12, KC_NO },
85 { KC_NO, KC_NO, KC_MUTE, KC_VOLD, KC_VOLU, KC_NO, DE_SQ3, KC_F4, KC_F5, KC_F6, KC_F11, KC_NO },
86 { KC_TRNS, KC_NO, KC_MPRV, KC_MPLY, KC_MNXT, KC_NO, DE_SQ2, KC_F1, KC_F2, KC_F3, KC_F10, KC_TRNS},
87 { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_NO, KC_TRNS, KC_TRNS, KC_NO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS}
88 }
89};
90
91const uint16_t PROGMEM fn_actions[] = {
92
93};
94
95const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
96{
97 // MACRODOWN only works in this function
98 switch (id) {
99 case 0:
100 if (record->event.pressed) {
101 register_code(KC_RSFT);
102#ifdef BACKLIGHT_ENABLE
103 backlight_step();
104#endif
105 }
106 else {
107 unregister_code(KC_RSFT);
108 }
109 break;
110 }
111 return MACRO_NONE;
112};
diff --git a/keyboard/planck/keymaps/default/README.md b/keyboard/planck/keymaps/default/README.md
index d2f43bbdb..de9680b49 100644
--- a/keyboard/planck/keymaps/default/README.md
+++ b/keyboard/planck/keymaps/default/README.md
@@ -1,34 +1,2 @@
1# The Default Planck Layout 1# The Default Planck Layout
2 2
3 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
4 [_QW] = { /* Qwerty */
5 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
6 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
7 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
8 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
9 },
10 [_CM] = { /* Colemak */
11 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
12 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
13 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
14 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
15 },
16 [_DV] = { /* Dvorak */
17 {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC},
18 {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH},
19 {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT },
20 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
21 },
22 [_RS] = { /* 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_BSPC},
24 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
25 {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS},
26 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
27 },
28 [_LW] = { /* LOWER */
29 {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
30 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
31 {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS},
32 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
33 }
34 }; \ No newline at end of file
diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c
index dee2840f2..ede08ad7f 100644
--- a/keyboard/planck/keymaps/default/keymap.c
+++ b/keyboard/planck/keymaps/default/keymap.c
@@ -19,12 +19,16 @@
19#define _AD 5 19#define _AD 5
20 20
21// Macro name shortcuts 21// Macro name shortcuts
22#define M_QW 0 22#define QWERTY M(_QW)
23#define M_CM 1 23#define COLEMAK M(_CM)
24#define M_DV 2 24#define DVORAK M(_DV)
25#define M_LW 3 25#define LOWER M(_LW)
26#define M_RS 4 26#define RAISE M(_RS)
27#define M_BL 5 27#define M_BL 5
28#ifdef AUDIO_ENABLE
29 #define AUD_OFF M(6)
30 #define AUD_ON M(7)
31#endif
28 32
29// Fillers to make layering more clear 33// Fillers to make layering more clear
30#define _______ KC_TRNS 34#define _______ KC_TRNS
@@ -47,7 +51,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
47 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, 51 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
48 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, 52 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
49 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, 53 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
50 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, M(M_LW), KC_SPC, KC_SPC, M(M_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} 54 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
51}, 55},
52 56
53/* Colemak 57/* Colemak
@@ -65,7 +69,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
65 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, 69 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
66 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, 70 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
67 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, 71 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
68 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, M(M_LW), KC_SPC, KC_SPC, M(M_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} 72 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
69}, 73},
70 74
71/* Dvorak 75/* Dvorak
@@ -83,7 +87,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
83 {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, 87 {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC},
84 {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, 88 {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH},
85 {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, 89 {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT },
86 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, M(M_LW), KC_SPC, KC_SPC, M(M_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} 90 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
87}, 91},
88 92
89/* Lower 93/* Lower
@@ -126,7 +130,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
126 * ,-----------------------------------------------------------------------------------. 130 * ,-----------------------------------------------------------------------------------.
127 * | | Reset| | | | | | | | | | Del | 131 * | | Reset| | | | | | | | | | Del |
128 * |------+------+------+------+------+-------------+------+------+------+------+------| 132 * |------+------+------+------+------+-------------+------+------+------+------+------|
129 * | | | | | | | |Qwerty|Colemk|Dvorak| | | 133 * | | | |Aud on|Audoff| | |Qwerty|Colemk|Dvorak| | |
130 * |------+------+------+------+------+------|------+------+------+------+------+------| 134 * |------+------+------+------+------+------|------+------+------+------+------+------|
131 * | | | | | | | | | | | | | 135 * | | | | | | | | | | | | |
132 * |------+------+------+------+------+------+------+------+------+------+------+------| 136 * |------+------+------+------+------+------+------+------+------+------+------+------|
@@ -135,7 +139,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
135 */ 139 */
136[_AD] = { 140[_AD] = {
137 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, 141 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
138 {_______, _______, _______, _______, _______, _______, _______, M(M_QW), M(M_CM), M(M_DV), _______, _______}, 142 {_______, _______, _______, AUD_ON, AUD_OFF, _______, _______, QWERTY, COLEMAK, DVORAK, _______, _______},
139 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, 143 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
140 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} 144 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
141} 145}
@@ -146,6 +150,14 @@ const uint16_t PROGMEM fn_actions[] = {
146}; 150};
147 151
148#ifdef AUDIO_ENABLE 152#ifdef AUDIO_ENABLE
153float start_up[][2] = {
154 {440.0*pow(2.0,(67)/12.0), 12},
155 {440.0*pow(2.0,(64)/12.0), 8},
156 {440.0*pow(2.0,(55)/12.0), 8},
157 {440.0*pow(2.0,(60)/12.0), 8},
158 {440.0*pow(2.0,(64)/12.0), 20}
159};
160
149float tone_qw[][2] = { 161float tone_qw[][2] = {
150 {440.0*pow(2.0,(59)/12.0), 8}, 162 {440.0*pow(2.0,(59)/12.0), 8},
151 {440.0*pow(2.0,(60)/12.0), 8}, 163 {440.0*pow(2.0,(60)/12.0), 8},
@@ -157,38 +169,29 @@ float tone_cm[][2] = {
157 {440.0*pow(2.0,(59)/12.0), 8}, 169 {440.0*pow(2.0,(59)/12.0), 8},
158 {440.0*pow(2.0,(60)/12.0), 8}, 170 {440.0*pow(2.0,(60)/12.0), 8},
159 {0, 4}, 171 {0, 4},
160 {440.0*pow(2.0,(67)/12.0), 16}, 172 {440.0*pow(2.0,(67)/12.0), 12},
161 {0, 4}, 173 {0, 4},
162 {440.0*pow(2.0,(71)/12.0), 16} 174 {440.0*pow(2.0,(71)/12.0), 12}
163}; 175};
164 176
165float tone_dv[][2] = { 177float tone_dv[][2] = {
166 {440.0*pow(2.0,(59)/12.0), 8}, 178 {440.0*pow(2.0,(59)/12.0), 8},
167 {440.0*pow(2.0,(60)/12.0), 8}, 179 {440.0*pow(2.0,(60)/12.0), 8},
168 {0, 4}, 180 {0, 4},
169 {440.0*pow(2.0,(67)/12.0), 16}, 181 {440.0*pow(2.0,(67)/12.0), 8},
170 {0, 4}, 182 {0, 4},
171 {440.0*pow(2.0,(69)/12.0), 16}, 183 {440.0*pow(2.0,(69)/12.0), 8},
172 {0, 4}, 184 {0, 4},
173 {440.0*pow(2.0,(67)/12.0), 16} 185 {440.0*pow(2.0,(67)/12.0), 8}
174}; 186};
175#endif 187#endif
176 188
177#define IS_LAYER_ON(layer) ((layer_state) & (1<<(layer)))
178#define IS_LAYER_OFF(layer) ((!layer_state) & (1<<(layer)))
179 189
180void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
181 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
182 layer_on(layer3);
183 } else {
184 layer_off(layer3);
185 }
186}
187const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) 190const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
188{ 191{
189 // MACRODOWN only works in this function 192 // MACRODOWN only works in this function
190 switch(id) { 193 switch(id) {
191 case M_QW: 194 case _QW:
192 if (record->event.pressed) { 195 if (record->event.pressed) {
193 #ifdef AUDIO_ENABLE 196 #ifdef AUDIO_ENABLE
194 play_notes(&tone_qw, 4, false); 197 play_notes(&tone_qw, 4, false);
@@ -196,7 +199,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
196 default_layer_set(1UL<<_QW); 199 default_layer_set(1UL<<_QW);
197 } 200 }
198 break; 201 break;
199 case M_CM: 202 case _CM:
200 if (record->event.pressed) { 203 if (record->event.pressed) {
201 #ifdef AUDIO_ENABLE 204 #ifdef AUDIO_ENABLE
202 play_notes(&tone_cm, 6, false); 205 play_notes(&tone_cm, 6, false);
@@ -204,7 +207,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
204 default_layer_set(1UL<<_CM); 207 default_layer_set(1UL<<_CM);
205 } 208 }
206 break; 209 break;
207 case M_DV: 210 case _DV:
208 if (record->event.pressed) { 211 if (record->event.pressed) {
209 #ifdef AUDIO_ENABLE 212 #ifdef AUDIO_ENABLE
210 play_notes(&tone_dv, 8, false); 213 play_notes(&tone_dv, 8, false);
@@ -212,7 +215,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
212 default_layer_set(1UL<<_DV); 215 default_layer_set(1UL<<_DV);
213 } 216 }
214 break; 217 break;
215 case M_LW: 218 case _LW:
216 if (record->event.pressed) { 219 if (record->event.pressed) {
217 layer_on(_LW); 220 layer_on(_LW);
218 update_tri_layer(_LW, _RS, _AD); 221 update_tri_layer(_LW, _RS, _AD);
@@ -221,7 +224,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
221 update_tri_layer(_LW, _RS, _AD); 224 update_tri_layer(_LW, _RS, _AD);
222 } 225 }
223 break; 226 break;
224 case M_RS: 227 case _RS:
225 if (record->event.pressed) { 228 if (record->event.pressed) {
226 layer_on(_RS); 229 layer_on(_RS);
227 update_tri_layer(_LW, _RS, _AD); 230 update_tri_layer(_LW, _RS, _AD);
@@ -240,20 +243,25 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
240 unregister_code(KC_RSFT); 243 unregister_code(KC_RSFT);
241 } 244 }
242 break; 245 break;
246 case 6:
247 if (record->event.pressed) {
248 #ifdef AUDIO_ENABLE
249 audio_off();
250 #endif
251 }
252 break;
253 case 7:
254 if (record->event.pressed) {
255 #ifdef AUDIO_ENABLE
256 audio_on();
257 play_notes(&start_up, 5, false);
258 #endif
259 }
260 break;
243 } 261 }
244 return MACRO_NONE; 262 return MACRO_NONE;
245}; 263};
246 264
247#ifdef AUDIO_ENABLE
248float start_up[][2] = {
249 {440.0*pow(2.0,(67)/12.0), 12},
250 {440.0*pow(2.0,(64)/12.0), 8},
251 {440.0*pow(2.0,(55)/12.0), 8},
252 {440.0*pow(2.0,(60)/12.0), 8},
253 {440.0*pow(2.0,(64)/12.0), 20}
254};
255#endif
256
257void matrix_init_user(void) { 265void matrix_init_user(void) {
258 #ifdef AUDIO_ENABLE 266 #ifdef AUDIO_ENABLE
259 init_notes(); 267 init_notes();
diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile
index 664aff732..9199968c3 100644
--- a/keyboard/preonic/Makefile
+++ b/keyboard/preonic/Makefile
@@ -126,27 +126,44 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
126# USBaspLoader 2048 126# USBaspLoader 2048
127OPT_DEFS += -DBOOTLOADER_SIZE=4096 127OPT_DEFS += -DBOOTLOADER_SIZE=4096
128 128
129
130# Build Options 129# Build Options
131# comment out to disable the options. 130# change to "no" to disable the options, or define them in the makefile.mk in
132# 131# the appropriate keymap folder that will get included automatically
133BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) 132#
134MOUSEKEY_ENABLE = yes # Mouse keys(+4700) 133BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
135EXTRAKEY_ENABLE = yes # Audio control and System control(+450) 134MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
136CONSOLE_ENABLE = yes # Console for debug(+400) 135EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
137COMMAND_ENABLE = yes # Commands for debug and configuration 136CONSOLE_ENABLE = yes # Console for debug(+400)
137COMMAND_ENABLE = yes # Commands for debug and configuration
138NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
139BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
140MIDI_ENABLE = no # MIDI controls
141AUDIO_ENABLE = no # Audio output on port C6
142UNICODE_ENABLE = no # Unicode
143BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
144RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
145
138# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 146# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
139# SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 147SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
140# NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 148
141BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality 149ifdef KEYMAP
142MIDI_ENABLE = YES # MIDI controls 150
143AUDIO_ENABLE = YES # Audio output on port C6 151ifeq ("$(wildcard keymaps/$(KEYMAP).c)","")
144# UNICODE_ENABLE = YES # Unicode 152ifneq ("$(wildcard keymaps/$(KEYMAP)/makefile.mk)","")
145# BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID 153 include keymaps/$(KEYMAP)/makefile.mk
146# RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with MIDI at the same time. 154endif
147 155endif
148ifdef BACKLIGHT_ENABLE 156
149 SRC += backlight.c 157else
158
159ifneq ("$(wildcard keymaps/default/makefile.mk)","")
160 include keymaps/default/makefile.mk
161endif
162
163endif
164
165ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
166 SRC := backlight.c $(SRC)
150endif 167endif
151 168
152 169
diff --git a/keyboard/preonic/keymaps/default/README.md b/keyboard/preonic/keymaps/default/README.md
index d2f43bbdb..e911968dd 100644
--- a/keyboard/preonic/keymaps/default/README.md
+++ b/keyboard/preonic/keymaps/default/README.md
@@ -1,34 +1 @@
1# The Default Planck Layout # The default Preonic layout - largely based on the Planck's \ No newline at end of file
2
3 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
4 [_QW] = { /* Qwerty */
5 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
6 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
7 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
8 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
9 },
10 [_CM] = { /* Colemak */
11 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
12 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
13 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
14 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
15 },
16 [_DV] = { /* Dvorak */
17 {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC},
18 {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH},
19 {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT },
20 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
21 },
22 [_RS] = { /* 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_BSPC},
24 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
25 {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS},
26 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
27 },
28 [_LW] = { /* LOWER */
29 {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
30 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
31 {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS},
32 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
33 }
34 }; \ No newline at end of file
diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c
index 784670784..e1f9b6202 100644
--- a/keyboard/preonic/keymaps/default/keymap.c
+++ b/keyboard/preonic/keymaps/default/keymap.c
@@ -1,56 +1,182 @@
1// This is the canonical layout file for the Quantum project. If you want to add another keyboard,
2// this is the style you want to emulate.
3
4#include "preonic.h" 1#include "preonic.h"
5#ifdef BACKLIGHT_ENABLE 2#include "action_layer.h"
6 #include "backlight.h" 3#include "eeconfig.h"
4#ifdef AUDIO_ENABLE
5 #include "audio.h"
6 #define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
7 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
8 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
9 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
10 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
7#endif 11#endif
8 12
9// Each layer gets a name for readability, which is then used in the keymap matrix below. 13// Each layer gets a name for readability, which is then used in the keymap matrix below.
10// The underscores don't mean anything - you can have a layer called STUFF or any other name. 14// The underscores don't mean anything - you can have a layer called STUFF or any other name.
11// Layer names don't all need to be of the same length, obviously, and you can also skip them 15// Layer names don't all need to be of the same length, obviously, and you can also skip them
12// entirely and just use numbers. 16// entirely and just use numbers.
13#define _QW 0 17#define _QWERTY 0
14#define _CM 1 18#define _COLEMAK 1
15#define _DV 2 19#define _DVORAK 2
16#define _LW 3 20#define _LOWER 3
17#define _RS 4 21#define _RAISE 4
22#define _ADJUST 5
23#define _MUSIC 6
24
25// Macro name shortcuts
26#define QWERTY M(_QWERTY)
27#define COLEMAK M(_COLEMAK)
28#define DVORAK M(_DVORAK)
29#define LOWER M(_LOWER)
30#define RAISE M(_RAISE)
31#define M_BL 5
32#ifdef AUDIO_ENABLE
33 #define AUD_OFF M(6)
34 #define AUD_ON M(7)
35#endif
36#define MUS_OFF M(8)
37#define MUS_ON M(9)
38
39// Fillers to make layering more clear
40#define _______ KC_TRNS
41#define XXXXXXX KC_NO
18 42
19const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 43const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
20[_QW] = { /* Qwerty */ 44
45/* Qwerty
46 * ,-----------------------------------------------------------------------------------.
47 * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
48 * |------+------+------+------+------+------+------+------+------+------+------+------|
49 * | Tab | Q | W | E | R | T | Y | U | I | O | P | Del |
50 * |------+------+------+------+------+-------------+------+------+------+------+------|
51 * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
52 * |------+------+------+------+------+------|------+------+------+------+------+------|
53 * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
54 * |------+------+------+------+------+------+------+------+------+------+------+------|
55 * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
56 * `-----------------------------------------------------------------------------------'
57 */
58[_QWERTY] = {
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}, 59 {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_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, 60 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL},
23 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, 61 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
24 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, 62 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
25 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} 63 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
26}, 64},
27[_CM] = { /* Colemak */ 65
66/* Colemak
67 * ,-----------------------------------------------------------------------------------.
68 * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
69 * |------+------+------+------+------+------+------+------+------+------+------+------|
70 * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Del |
71 * |------+------+------+------+------+-------------+------+------+------+------+------|
72 * | Esc | A | R | S | T | D | H | N | E | I | O | " |
73 * |------+------+------+------+------+------|------+------+------+------+------+------|
74 * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
75 * |------+------+------+------+------+------+------+------+------+------+------+------|
76 * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
77 * `-----------------------------------------------------------------------------------'
78 */
79[_COLEMAK] = {
28 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, 80 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
29 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, 81 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_DEL},
30 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, 82 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
31 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, 83 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
32 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} 84 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
33}, 85},
34[_DV] = { /* Dvorak */ 86
87/* Dvorak
88 * ,-----------------------------------------------------------------------------------.
89 * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
90 * |------+------+------+------+------+------+------+------+------+------+------+------|
91 * | Tab | " | , | . | P | Y | F | G | C | R | L | Del |
92 * |------+------+------+------+------+-------------+------+------+------+------+------|
93 * | Esc | A | O | E | U | I | D | H | T | N | S | / |
94 * |------+------+------+------+------+------|------+------+------+------+------+------|
95 * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
96 * |------+------+------+------+------+------+------+------+------+------+------+------|
97 * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
98 * `-----------------------------------------------------------------------------------'
99 */
100[_DVORAK] = {
35 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, 101 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
36 {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, 102 {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_DEL},
37 {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, 103 {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH},
38 {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, 104 {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT },
39 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} 105 {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
40}, 106},
41[_RS] = { /* RAISE */ 107
42 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, 108/* Lower
43 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, 109 * ,-----------------------------------------------------------------------------------.
44 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, 110 * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
45 {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS}, 111 * |------+------+------+------+------+-------------+------+------+------+------+------|
46 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} 112 * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Del |
113 * |------+------+------+------+------+-------------+------+------+------+------+------|
114 * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
115 * |------+------+------+------+------+------|------+------+------+------+------+------|
116 * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | |Enter |
117 * |------+------+------+------+------+------+------+------+------+------+------+------|
118 * | | | | | | | | Next | Vol- | Vol+ | Play |
119 * `-----------------------------------------------------------------------------------'
120 */
121[_LOWER] = {
122 {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
123 {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL},
124 {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
125 {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______},
126 {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
47}, 127},
48[_LW] = { /* LOWER */ 128
129/* Raise
130 * ,-----------------------------------------------------------------------------------.
131 * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
132 * |------+------+------+------+------+------+------+------+------+------+------+------|
133 * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Del |
134 * |------+------+------+------+------+-------------+------+------+------+------+------|
135 * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
136 * |------+------+------+------+------+------|------+------+------+------+------+------|
137 * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | |Enter |
138 * |------+------+------+------+------+------+------+------+------+------+------+------|
139 * | | | | | | | | Next | Vol- | Vol+ | Play |
140 * `-----------------------------------------------------------------------------------'
141 */
142[_RAISE] = {
49 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, 143 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
50 {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC}, 144 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
51 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, 145 {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
52 {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS}, 146 {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______},
53 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} 147 {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
148},
149
150/* Adjust (Lower + Raise)
151 * ,-----------------------------------------------------------------------------------.
152 * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
153 * |------+------+------+------+------+------+------+------+------+------+------+------|
154 * | | Reset| | | | | | | | | | Del |
155 * |------+------+------+------+------+-------------+------+------+------+------+------|
156 * | | | |Audoff|Aud on|AGnorm|AGswap|Qwerty|Colemk|Dvorak| | |
157 * |------+------+------+------+------+------|------+------+------+------+------+------|
158 * | | | |Musoff|Mus on| | | | | | | |
159 * |------+------+------+------+------+------+------+------+------+------+------+------|
160 * | | | | | | | | | | | |
161 * `-----------------------------------------------------------------------------------'
162 */
163[_ADJUST] = {
164 {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12},
165 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
166 {_______, _______, _______, AUD_ON, AUD_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______},
167 {_______, _______, _______, MUS_ON, MUS_OFF, _______, _______, _______, _______, _______, _______, _______},
168 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
169},
170
171/* Music (reserved for process_action_user)
172 *
173 */
174[_MUSIC] = {
175 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
176 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
177 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
178 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
179 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
54} 180}
55}; 181};
56 182
@@ -58,19 +184,104 @@ const uint16_t PROGMEM fn_actions[] = {
58 184
59}; 185};
60 186
187#ifdef AUDIO_ENABLE
61float start_up[][2] = { 188float start_up[][2] = {
62 {440.0*pow(2.0,(67)/12.0), 600}, 189 {440.0*pow(2.0,(50)/12.0), 20},
63 {440.0*pow(2.0,(64)/12.0), 400}, 190 {440.0*pow(2.0,(62)/12.0), 8},
64 {440.0*pow(2.0,(55)/12.0), 400}, 191 {440.0*pow(2.0,(54)/12.0), 20},
65 {440.0*pow(2.0,(60)/12.0), 400}, 192 {440.0*pow(2.0,(62)/12.0), 8}
66 {440.0*pow(2.0,(64)/12.0), 1000},
67}; 193};
68 194
195float tone_qwerty[][2] = {
196 {440.0*pow(2.0,(59)/12.0), 8},
197 {440.0*pow(2.0,(60)/12.0), 8},
198 {0, 4},
199 {440.0*pow(2.0,(67)/12.0), 16}
200};
201
202float tone_colemak[][2] = {
203 {440.0*pow(2.0,(59)/12.0), 8},
204 {440.0*pow(2.0,(60)/12.0), 8},
205 {0, 4},
206 {440.0*pow(2.0,(67)/12.0), 12},
207 {0, 4},
208 {440.0*pow(2.0,(71)/12.0), 12}
209};
210
211float tone_dvorak[][2] = {
212 {440.0*pow(2.0,(59)/12.0), 8},
213 {440.0*pow(2.0,(60)/12.0), 8},
214 {0, 4},
215 {440.0*pow(2.0,(67)/12.0), 8},
216 {0, 4},
217 {440.0*pow(2.0,(69)/12.0), 8},
218 {0, 4},
219 {440.0*pow(2.0,(67)/12.0), 8}
220};
221
222float tone_music[][2] = {
223 {440.0*pow(2.0,(48)/12.0), 8},
224 {440.0*pow(2.0,(50)/12.0), 8},
225 {440.0*pow(2.0,(52)/12.0), 8},
226 {440.0*pow(2.0,(53)/12.0), 8},
227 {440.0*pow(2.0,(55)/12.0), 8},
228 {440.0*pow(2.0,(57)/12.0), 8},
229 {440.0*pow(2.0,(59)/12.0), 8},
230 {440.0*pow(2.0,(60)/12.0), 8}
231};
232#endif
233
234void persistant_default_layer_set(uint16_t default_layer) {
235 eeconfig_write_default_layer(default_layer);
236 default_layer_set(default_layer);
237}
238
69const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) 239const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
70{ 240{
71 // MACRODOWN only works in this function
72 switch(id) { 241 switch(id) {
73 case 0: 242 case _QWERTY:
243 if (record->event.pressed) {
244 #ifdef AUDIO_ENABLE
245 play_notes(&tone_qwerty, 4, false);
246 #endif
247 persistant_default_layer_set(1UL<<_QWERTY);
248 }
249 break;
250 case _COLEMAK:
251 if (record->event.pressed) {
252 #ifdef AUDIO_ENABLE
253 play_notes(&tone_colemak, 6, false);
254 #endif
255 persistant_default_layer_set(1UL<<_COLEMAK);
256 }
257 break;
258 case _DVORAK:
259 if (record->event.pressed) {
260 #ifdef AUDIO_ENABLE
261 play_notes(&tone_dvorak, 8, false);
262 #endif
263 persistant_default_layer_set(1UL<<_DVORAK);
264 }
265 break;
266 case _LOWER:
267 if (record->event.pressed) {
268 layer_on(_LOWER);
269 update_tri_layer(_LOWER, _RAISE, _ADJUST);
270 } else {
271 layer_off(_LOWER);
272 update_tri_layer(_LOWER, _RAISE, _ADJUST);
273 }
274 break;
275 case _RAISE:
276 if (record->event.pressed) {
277 layer_on(_RAISE);
278 update_tri_layer(_LOWER, _RAISE, _ADJUST);
279 } else {
280 layer_off(_RAISE);
281 update_tri_layer(_LOWER, _RAISE, _ADJUST);
282 }
283 break;
284 case M_BL:
74 if (record->event.pressed) { 285 if (record->event.pressed) {
75 register_code(KC_RSFT); 286 register_code(KC_RSFT);
76 #ifdef BACKLIGHT_ENABLE 287 #ifdef BACKLIGHT_ENABLE
@@ -80,13 +291,59 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
80 unregister_code(KC_RSFT); 291 unregister_code(KC_RSFT);
81 } 292 }
82 break; 293 break;
294 case 6:
295 if (record->event.pressed) {
296 #ifdef AUDIO_ENABLE
297 audio_off();
298 #endif
299 }
300 break;
301 case 7:
302 if (record->event.pressed) {
303 #ifdef AUDIO_ENABLE
304 audio_on();
305 play_notes(&start_up, 4, false);
306 #endif
307 }
308 break;
309 case 8:
310 if (record->event.pressed) {
311 #ifdef AUDIO_ENABLE
312 layer_off(_MUSIC);
313 stop_all_notes();
314 #endif
315 }
316 break;
317 case 9:
318 if (record->event.pressed) {
319 #ifdef AUDIO_ENABLE
320 play_notes(&tone_music, 8, false);
321 layer_on(_MUSIC);
322 #endif
323 }
324 break;
83 } 325 }
84 return MACRO_NONE; 326 return MACRO_NONE;
85}; 327};
86 328
329uint8_t starting_note = 0x0C;
330int offset = 7;
331
332void process_action_user(keyrecord_t *record) {
333
334 if (IS_LAYER_ON(_MUSIC)) {
335 if (record->event.pressed) {
336 play_note(((double)261.626)*pow(2.0, -2.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF);
337 } else {
338 stop_note(((double)261.626)*pow(2.0, -2.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)));
339 }
340 }
341
342}
343
87void matrix_init_user(void) { 344void matrix_init_user(void) {
88#ifdef AUDIO_ENABLE 345 #ifdef AUDIO_ENABLE
89 init_notes(); 346 init_notes();
90 play_notes(&start_up, 5, false); 347 play_notes(&start_up, 4, false);
91#endif 348 #endif
92} 349}
diff --git a/keyboard/preonic/keymaps/default/makefile.mk b/keyboard/preonic/keymaps/default/makefile.mk
new file mode 100644
index 000000000..628167ff6
--- /dev/null
+++ b/keyboard/preonic/keymaps/default/makefile.mk
@@ -0,0 +1 @@
AUDIO_ENABLE = yes \ No newline at end of file
diff --git a/quantum/audio.c b/quantum/audio.c
index 50e5505fe..5edcccdbe 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -8,6 +8,8 @@
8#include "audio.h" 8#include "audio.h"
9#include "keymap_common.h" 9#include "keymap_common.h"
10 10
11#include "eeconfig.h"
12
11#define PI 3.14159265 13#define PI 3.14159265
12 14
13// #define PWM_AUDIO 15// #define PWM_AUDIO
@@ -30,6 +32,8 @@ int voice_place = 0;
30double frequency = 0; 32double frequency = 0;
31int volume = 0; 33int volume = 0;
32long position = 0; 34long position = 0;
35int duty_place = 1;
36int duty_counter = 0;
33 37
34double frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 38double frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
35int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 39int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
@@ -57,6 +61,25 @@ uint8_t notes_length;
57bool notes_repeat; 61bool notes_repeat;
58uint8_t current_note = 0; 62uint8_t current_note = 0;
59 63
64audio_config_t audio_config;
65
66
67void audio_toggle(void) {
68 audio_config.enable ^= 1;
69 eeconfig_write_audio(audio_config.raw);
70}
71
72void audio_on(void) {
73 audio_config.enable = 1;
74 eeconfig_write_audio(audio_config.raw);
75}
76
77void audio_off(void) {
78 audio_config.enable = 0;
79 eeconfig_write_audio(audio_config.raw);
80}
81
82
60void stop_all_notes() { 83void stop_all_notes() {
61 voices = 0; 84 voices = 0;
62 #ifdef PWM_AUDIO 85 #ifdef PWM_AUDIO
@@ -77,58 +100,66 @@ void stop_all_notes() {
77} 100}
78 101
79void stop_note(double freq) { 102void stop_note(double freq) {
80 #ifdef PWM_AUDIO 103 if (note) {
81 freq = freq / SAMPLE_RATE;
82 #endif
83 for (int i = 7; i >= 0; i--) {
84 if (frequencies[i] == freq) {
85 frequencies[i] = 0;
86 volumes[i] = 0;
87 for (int j = i; (j < 7); j++) {
88 frequencies[j] = frequencies[j+1];
89 frequencies[j+1] = 0;
90 volumes[j] = volumes[j+1];
91 volumes[j+1] = 0;
92 }
93 }
94 }
95 voices--;
96 if (voices < 0)
97 voices = 0;
98 if (voices == 0) {
99 #ifdef PWM_AUDIO 104 #ifdef PWM_AUDIO
100 TIMSK3 &= ~_BV(OCIE3A); 105 freq = freq / SAMPLE_RATE;
101 #else
102 TIMSK3 &= ~_BV(OCIE3A);
103 TCCR3A &= ~_BV(COM3A1);
104 #endif 106 #endif
105 frequency = 0; 107 for (int i = 7; i >= 0; i--) {
106 volume = 0; 108 if (frequencies[i] == freq) {
107 note = false; 109 frequencies[i] = 0;
108 } else { 110 volumes[i] = 0;
109 double freq = frequencies[voices - 1]; 111 for (int j = i; (j < 7); j++) {
110 int vol = volumes[voices - 1]; 112 frequencies[j] = frequencies[j+1];
111 double starting_f = frequency; 113 frequencies[j+1] = 0;
112 if (frequency < freq) { 114 volumes[j] = volumes[j+1];
113 sliding = true; 115 volumes[j+1] = 0;
114 for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { 116 }
115 frequency = f;
116 } 117 }
117 sliding = false; 118 }
118 } else if (frequency > freq) { 119 voices--;
119 sliding = true; 120 if (voices < 0)
120 for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) { 121 voices = 0;
121 frequency = f; 122 if (voices == 0) {
123 #ifdef PWM_AUDIO
124 TIMSK3 &= ~_BV(OCIE3A);
125 #else
126 TIMSK3 &= ~_BV(OCIE3A);
127 TCCR3A &= ~_BV(COM3A1);
128 #endif
129 frequency = 0;
130 volume = 0;
131 note = false;
132 } else {
133 double freq = frequencies[voices - 1];
134 int vol = volumes[voices - 1];
135 double starting_f = frequency;
136 if (frequency < freq) {
137 sliding = true;
138 for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) {
139 frequency = f;
140 }
141 sliding = false;
142 } else if (frequency > freq) {
143 sliding = true;
144 for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) {
145 frequency = f;
146 }
147 sliding = false;
122 } 148 }
123 sliding = false; 149 frequency = freq;
150 volume = vol;
124 } 151 }
125 frequency = freq;
126 volume = vol;
127 } 152 }
128} 153}
129 154
130void init_notes() { 155void init_notes() {
131 156
157 /* check signature */
158 if (!eeconfig_is_enabled()) {
159 eeconfig_init();
160 }
161 audio_config.raw = eeconfig_read_audio();
162
132 #ifdef PWM_AUDIO 163 #ifdef PWM_AUDIO
133 PLLFRQ = _BV(PDIV2); 164 PLLFRQ = _BV(PDIV2);
134 PLLCSR = _BV(PLLE); 165 PLLCSR = _BV(PLLE);
@@ -160,7 +191,6 @@ void init_notes() {
160 191
161 192
162ISR(TIMER3_COMPA_vect) { 193ISR(TIMER3_COMPA_vect) {
163
164 if (note) { 194 if (note) {
165 #ifdef PWM_AUDIO 195 #ifdef PWM_AUDIO
166 if (voices == 1) { 196 if (voices == 1) {
@@ -213,13 +243,19 @@ ISR(TIMER3_COMPA_vect) {
213 if (frequency > 0) { 243 if (frequency > 0) {
214 // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period 244 // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period
215 // OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period 245 // OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period
216 if (place > 10) { 246 voice_place %= voices;
247 if (place > (frequencies[voice_place] / 500)) {
217 voice_place = (voice_place + 1) % voices; 248 voice_place = (voice_place + 1) % voices;
218 place = 0.0; 249 place = 0.0;
219 } 250 }
220 ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period 251 ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period
221 OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1; // Set compare to half the period 252 OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1 * duty_place; // Set compare to half the period
222 place++; 253 place++;
254 // if (duty_counter > (frequencies[voice_place] / 500)) {
255 // duty_place = (duty_place % 3) + 1;
256 // duty_counter = 0;
257 // }
258 // duty_counter++;
223 } 259 }
224 #endif 260 #endif
225 } 261 }
@@ -288,9 +324,16 @@ ISR(TIMER3_COMPA_vect) {
288 324
289 } 325 }
290 326
327 if (!audio_config.enable) {
328 notes = false;
329 note = false;
330 }
291} 331}
292 332
293void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) { 333void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
334
335if (audio_config.enable) {
336
294 if (note) 337 if (note)
295 stop_all_notes(); 338 stop_all_notes();
296 notes = true; 339 notes = true;
@@ -319,7 +362,12 @@ void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
319 #endif 362 #endif
320} 363}
321 364
365}
366
322void play_sample(uint8_t * s, uint16_t l, bool r) { 367void play_sample(uint8_t * s, uint16_t l, bool r) {
368
369if (audio_config.enable) {
370
323 stop_all_notes(); 371 stop_all_notes();
324 place_int = 0; 372 place_int = 0;
325 sample = s; 373 sample = s;
@@ -330,9 +378,15 @@ void play_sample(uint8_t * s, uint16_t l, bool r) {
330 TIMSK3 |= _BV(OCIE3A); 378 TIMSK3 |= _BV(OCIE3A);
331 #else 379 #else
332 #endif 380 #endif
381
382}
383
333} 384}
334 385
335void play_note(double freq, int vol) { 386void play_note(double freq, int vol) {
387
388if (audio_config.enable && voices < 8) {
389
336 if (notes) 390 if (notes)
337 stop_all_notes(); 391 stop_all_notes();
338 note = true; 392 note = true;
@@ -367,4 +421,6 @@ void play_note(double freq, int vol) {
367 TCCR3A |= _BV(COM3A1); 421 TCCR3A |= _BV(COM3A1);
368 #endif 422 #endif
369 423
424}
425
370} \ No newline at end of file 426} \ No newline at end of file
diff --git a/quantum/audio.h b/quantum/audio.h
index 31f9a3579..58270015d 100644
--- a/quantum/audio.h
+++ b/quantum/audio.h
@@ -3,9 +3,21 @@
3#include <avr/io.h> 3#include <avr/io.h>
4#include <util/delay.h> 4#include <util/delay.h>
5 5
6typedef union {
7 uint8_t raw;
8 struct {
9 bool enable :1;
10 uint8_t level :7;
11 };
12} audio_config_t;
13
14void audio_toggle(void);
15void audio_on(void);
16void audio_off(void);
17
6void play_sample(uint8_t * s, uint16_t l, bool r); 18void play_sample(uint8_t * s, uint16_t l, bool r);
7void play_note(double freq, int vol); 19void play_note(double freq, int vol);
8void stop_note(double freq); 20void stop_note(double freq);
9void stop_all_notes(void); 21void stop_all_notes();
10void init_notes(void); 22void init_notes();
11void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat); \ No newline at end of file 23void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat);
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index e3030a886..b91916685 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27#include "keymap_midi.h" 27#include "keymap_midi.h"
28#include "bootloader.h" 28#include "bootloader.h"
29 29
30extern keymap_config_t keymap_config;
31
30#include <stdio.h> 32#include <stdio.h>
31#include <inttypes.h> 33#include <inttypes.h>
32#ifdef AUDIO_ENABLE 34#ifdef AUDIO_ENABLE
@@ -47,120 +49,9 @@ action_t action_for_key(uint8_t layer, keypos_t key)
47 // 16bit keycodes - important 49 // 16bit keycodes - important
48 uint16_t keycode = keymap_key_to_keycode(layer, key); 50 uint16_t keycode = keymap_key_to_keycode(layer, key);
49 51
50 if (keycode >= 0x0100 && keycode < 0x2000) {
51 // Has a modifier
52 action_t action;
53 // Split it up
54 action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
55 return action;
56 } else if (keycode >= 0x2000 && keycode < 0x3000) {
57 // Is a shortcut for function layer, pull last 12bits
58 // This means we have 4,096 FN macros at our disposal
59 return keymap_func_to_action(keycode & 0xFFF);
60 } else if (keycode >= 0x3000 && keycode < 0x4000) {
61 // When the code starts with 3, it's an action macro.
62 action_t action;
63 action.code = ACTION_MACRO(keycode & 0xFF);
64 return action;
65#ifdef BACKLIGHT_ENABLE
66 } else if (keycode >= BL_0 && keycode <= BL_15) {
67 action_t action;
68 action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
69 return action;
70 } else if (keycode == BL_DEC) {
71 action_t action;
72 action.code = ACTION_BACKLIGHT_DECREASE();
73 return action;
74 } else if (keycode == BL_INC) {
75 action_t action;
76 action.code = ACTION_BACKLIGHT_INCREASE();
77 return action;
78 } else if (keycode == BL_TOGG) {
79 action_t action;
80 action.code = ACTION_BACKLIGHT_TOGGLE();
81 return action;
82 } else if (keycode == BL_STEP) {
83 action_t action;
84 action.code = ACTION_BACKLIGHT_STEP();
85 return action;
86#endif
87 } else if (keycode == RESET) { // RESET is 0x5000, which is why this is here
88 action_t action;
89 clear_keyboard();
90 #ifdef AUDIO_ENABLE
91 play_notes(&goodbye, 3, false);
92 #endif
93 _delay_ms(250);
94 #ifdef ATREUS_ASTAR
95 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
96 #endif
97 bootloader_jump();
98 return action;
99 } else if (keycode == DEBUG) { // DEBUG is 0x5001
100 // TODO: Does this actually work?
101 action_t action;
102 print("\nDEBUG: enabled.\n");
103 debug_enable = true;
104 return action;
105 } else if (keycode >= 0x5000 && keycode < 0x6000) {
106 // Layer movement shortcuts
107 // See .h to see constraints/usage
108 int type = (keycode >> 0x8) & 0xF;
109 if (type == 0x1) {
110 // Layer set "GOTO"
111 int when = (keycode >> 0x4) & 0x3;
112 int layer = keycode & 0xF;
113 action_t action;
114 action.code = ACTION_LAYER_SET(layer, when);
115 return action;
116 } else if (type == 0x2) {
117 // Momentary layer
118 int layer = keycode & 0xFF;
119 action_t action;
120 action.code = ACTION_LAYER_MOMENTARY(layer);
121 return action;
122 } else if (type == 0x3) {
123 // Set default layer
124 int layer = keycode & 0xFF;
125 action_t action;
126 action.code = ACTION_DEFAULT_LAYER_SET(layer);
127 return action;
128 } else if (type == 0x4) {
129 // Set default layer
130 int layer = keycode & 0xFF;
131 action_t action;
132 action.code = ACTION_LAYER_TOGGLE(layer);
133 return action;
134 }
135#ifdef MIDI_ENABLE
136 } else if (keycode >= 0x6000 && keycode < 0x7000) {
137 action_t action;
138 action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8);
139 return action;
140#endif
141 } else if (keycode >= 0x7000 && keycode < 0x8000) {
142 action_t action;
143 action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
144 return action;
145 } else if (keycode >= 0x8000 && keycode < 0x9000) {
146 action_t action;
147 action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
148 return action;
149#ifdef UNICODE_ENABLE
150 } else if (keycode >= 0x8000000) {
151 action_t action;
152 uint16_t unicode = keycode & ~(0x8000);
153 action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
154 return action;
155#endif
156 } else {
157
158 }
159
160 switch (keycode) { 52 switch (keycode) {
161 case KC_FN0 ... KC_FN31: 53 case KC_FN0 ... KC_FN31:
162 return keymap_fn_to_action(keycode); 54 return keymap_fn_to_action(keycode);
163#ifdef BOOTMAGIC_ENABLE
164 case KC_CAPSLOCK: 55 case KC_CAPSLOCK:
165 case KC_LOCKING_CAPS: 56 case KC_LOCKING_CAPS:
166 if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) { 57 if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
@@ -224,7 +115,6 @@ action_t action_for_key(uint8_t layer, keypos_t key)
224 return keycode_to_action(KC_BSLASH); 115 return keycode_to_action(KC_BSLASH);
225 } 116 }
226 return keycode_to_action(KC_BSPACE); 117 return keycode_to_action(KC_BSPACE);
227#endif
228 default: 118 default:
229 return keycode_to_action(keycode); 119 return keycode_to_action(keycode);
230 } 120 }
@@ -265,6 +155,142 @@ static action_t keycode_to_action(uint16_t keycode)
265 case KC_TRNS: 155 case KC_TRNS:
266 action.code = ACTION_TRANSPARENT; 156 action.code = ACTION_TRANSPARENT;
267 break; 157 break;
158 case 0x0100 ... 0x1FFF: ;
159 // Has a modifier
160 // Split it up
161 action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
162 break;
163 case 0x2000 ... 0x2FFF:
164 // Is a shortcut for function layer, pull last 12bits
165 // This means we have 4,096 FN macros at our disposal
166 return keymap_func_to_action(keycode & 0xFFF);
167 break;
168 case 0x3000 ... 0x3FFF: ;
169 // When the code starts with 3, it's an action macro.
170 action.code = ACTION_MACRO(keycode & 0xFF);
171 break;
172 #ifdef BACKLIGHT_ENABLE
173 case BL_0 ... BL_15:
174 action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
175 break;
176 case BL_DEC:
177 action.code = ACTION_BACKLIGHT_DECREASE();
178 break;
179 case BL_INC:
180 action.code = ACTION_BACKLIGHT_INCREASE();
181 break;
182 case BL_TOGG:
183 action.code = ACTION_BACKLIGHT_TOGGLE();
184 break;
185 case BL_STEP:
186 action.code = ACTION_BACKLIGHT_STEP();
187 break;
188 #endif
189 case RESET: ; // RESET is 0x5000, which is why this is here
190 clear_keyboard();
191 #ifdef AUDIO_ENABLE
192 play_notes(&goodbye, 3, false);
193 #endif
194 _delay_ms(250);
195 #ifdef ATREUS_ASTAR
196 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
197 #endif
198 bootloader_jump();
199 break;
200 case DEBUG: ; // DEBUG is 0x5001
201 print("\nDEBUG: enabled.\n");
202 debug_enable = true;
203 break;
204 case 0x5002 ... 0x50FF:
205 // MAGIC actions (BOOTMAGIC without the boot)
206 if (!eeconfig_is_enabled()) {
207 eeconfig_init();
208 }
209 /* keymap config */
210 keymap_config.raw = eeconfig_read_keymap();
211 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
212 keymap_config.swap_control_capslock = 1;
213 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
214 keymap_config.capslock_to_control = 1;
215 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
216 keymap_config.swap_lalt_lgui = 1;
217 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
218 keymap_config.swap_ralt_rgui = 1;
219 } else if (keycode == MAGIC_NO_GUI) {
220 keymap_config.no_gui = 1;
221 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
222 keymap_config.swap_grave_esc = 1;
223 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
224 keymap_config.swap_backslash_backspace = 1;
225 } else if (keycode == MAGIC_HOST_NKRO) {
226 keymap_config.nkro = 1;
227 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
228 keymap_config.swap_lalt_lgui = 1;
229 keymap_config.swap_ralt_rgui = 1;
230 }
231 /* UNs */
232 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
233 keymap_config.swap_control_capslock = 0;
234 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
235 keymap_config.capslock_to_control = 0;
236 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
237 keymap_config.swap_lalt_lgui = 0;
238 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
239 keymap_config.swap_ralt_rgui = 0;
240 } else if (keycode == MAGIC_UNNO_GUI) {
241 keymap_config.no_gui = 0;
242 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
243 keymap_config.swap_grave_esc = 0;
244 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
245 keymap_config.swap_backslash_backspace = 0;
246 } else if (keycode == MAGIC_UNHOST_NKRO) {
247 keymap_config.nkro = 0;
248 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
249 keymap_config.swap_lalt_lgui = 0;
250 keymap_config.swap_ralt_rgui = 0;
251 }
252 eeconfig_write_keymap(keymap_config.raw);
253 break;
254 case 0x5100 ... 0x5FFF: ;
255 // Layer movement shortcuts
256 // See .h to see constraints/usage
257 int type = (keycode >> 0x8) & 0xF;
258 if (type == 0x1) {
259 // Layer set "GOTO"
260 int when = (keycode >> 0x4) & 0x3;
261 int layer = keycode & 0xF;
262 action.code = ACTION_LAYER_SET(layer, when);
263 } else if (type == 0x2) {
264 // Momentary layer
265 int layer = keycode & 0xFF;
266 action.code = ACTION_LAYER_MOMENTARY(layer);
267 } else if (type == 0x3) {
268 // Set default layer
269 int layer = keycode & 0xFF;
270 action.code = ACTION_DEFAULT_LAYER_SET(layer);
271 } else if (type == 0x4) {
272 // Set default layer
273 int layer = keycode & 0xFF;
274 action.code = ACTION_LAYER_TOGGLE(layer);
275 }
276 break;
277 #ifdef MIDI_ENABLE
278 case 0x6000 ... 0x6FFF:
279 action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8);
280 break;
281 #endif
282 case 0x7000 ... 0x7FFF:
283 action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
284 break;
285 case 0x8000 ... 0x8FFF:
286 action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
287 break;
288 #ifdef UNICODE_ENABLE
289 case 0x8000000 ... 0x8FFFFFF:
290 uint16_t unicode = keycode & ~(0x8000);
291 action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
292 break;
293 #endif
268 default: 294 default:
269 action.code = ACTION_NO; 295 action.code = ACTION_NO;
270 break; 296 break;
@@ -291,3 +317,11 @@ action_t keymap_func_to_action(uint16_t keycode)
291 // For FUNC without 8bit limit 317 // For FUNC without 8bit limit
292 return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) }; 318 return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) };
293} 319}
320
321void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
322 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
323 layer_on(layer3);
324 } else {
325 layer_off(layer3);
326 }
327}
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
index 4a877d2a7..ce87e4770 100644
--- a/quantum/keymap_common.h
+++ b/quantum/keymap_common.h
@@ -30,7 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30// #include "print.h" 30// #include "print.h"
31#include "debug.h" 31#include "debug.h"
32 32
33#ifdef BOOTMAGIC_ENABLE
34/* NOTE: Not portable. Bit field order depends on implementation */ 33/* NOTE: Not portable. Bit field order depends on implementation */
35typedef union { 34typedef union {
36 uint16_t raw; 35 uint16_t raw;
@@ -45,8 +44,6 @@ typedef union {
45 bool nkro:1; 44 bool nkro:1;
46 }; 45 };
47} keymap_config_t; 46} keymap_config_t;
48keymap_config_t keymap_config;
49#endif
50 47
51 48
52/* translates key to keycode */ 49/* translates key to keycode */
@@ -168,6 +165,30 @@ extern const uint16_t fn_actions[];
168#define RESET 0x5000 165#define RESET 0x5000
169#define DEBUG 0x5001 166#define DEBUG 0x5001
170 167
168// MAGIC keycodes
169#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002
170#define MAGIC_UNSWAP_CONTROL_CAPSLOCK 0x5003
171#define MAGIC_CAPSLOCK_TO_CONTROL 0x5004
172#define MAGIC_UNCAPSLOCK_TO_CONTROL 0x5005
173#define MAGIC_SWAP_LALT_LGUI 0x5006
174#define MAGIC_UNSWAP_LALT_LGUI 0x5007
175#define MAGIC_SWAP_RALT_RGUI 0x5008
176#define MAGIC_UNSWAP_RALT_RGUI 0x5009
177#define MAGIC_NO_GUI 0x500a
178#define MAGIC_UNNO_GUI 0x500b
179#define MAGIC_SWAP_GRAVE_ESC 0x500c
180#define MAGIC_UNSWAP_GRAVE_ESC 0x500d
181#define MAGIC_SWAP_BACKSLASH_BACKSPACE 0x500e
182#define MAGIC_UNSWAP_BACKSLASH_BACKSPACE 0x500f
183#define MAGIC_HOST_NKRO 0x5010
184#define MAGIC_UNHOST_NKRO 0x5011
185#define MAGIC_SWAP_ALT_GUI 0x5012
186#define MAGIC_UNSWAP_ALT_GUI 0x5013
187
188#define AG_SWAP MAGIC_SWAP_ALT_GUI
189#define AG_NORM MAGIC_UNSWAP_ALT_GUI
190
191
171// GOTO layer - 16 layers max 192// GOTO layer - 16 layers max
172// when: 193// when:
173// ON_PRESS = 1 194// ON_PRESS = 1
@@ -208,5 +229,10 @@ extern const uint16_t fn_actions[];
208#define UNICODE(n) (n | 0x8000) 229#define UNICODE(n) (n | 0x8000)
209#define UC(n) UNICODE(n) 230#define UC(n) UNICODE(n)
210 231
232// For tri-layer
233void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
234#define IS_LAYER_ON(layer) ((layer_state) & (1UL<<(layer)))
235#define IS_LAYER_OFF(layer) ((!layer_state) & (1UL<<(layer)))
236
211 237
212#endif 238#endif
diff --git a/quantum/musical_notes.h b/quantum/musical_notes.h
new file mode 100644
index 000000000..79f04fd98
--- /dev/null
+++ b/quantum/musical_notes.h
@@ -0,0 +1,182 @@
1#ifndef MUSICAL_NOTES_H
2#define MUSICAL_NOTES_H
3
4// Tempo Placeholder
5#define TEMPO 120
6
7
8// Note Types
9#define WHOLE_NOTE(note) {(NOTE##note), 64}
10#define HALF_NOTE(note) {(NOTE##note), 32}
11#define QUARTER_NOTE(note) {(NOTE##note), 16}
12#define EIGTH_NOTE(note) {(NOTE##note), 8}
13#define SIXTEENTH_NOTE(note) {(NOTE##note), 4}
14
15// Note Types Short
16#define W_NOTE(n) WHOLE_NOTE(n)
17#define H_NOTE(n) HALF_NOTE(n)
18#define Q_NOTE(n) QUARTER_NOTE(n)
19#define E_NOTE(n) EIGTH_NOTE(n)
20#define S_NOTE(n) SIXTEENTH_NOTE(n)
21
22
23// Notes - # = Octave
24#define NOTE_REST 0.00
25#define NOTE_C0 16.35
26#define NOTE_CS0 17.32
27#define NOTE_D0 18.35
28#define NOTE_DS0 19.45
29#define NOTE_E0 20.60
30#define NOTE_F0 21.83
31#define NOTE_FS0 23.12
32#define NOTE_G0 24.50
33#define NOTE_GS0 25.96
34#define NOTE_A0 27.50
35#define NOTE_AS0 29.14
36#define NOTE_B0 30.87
37#define NOTE_C1 32.70
38#define NOTE_CS1 34.65
39#define NOTE_D1 36.71
40#define NOTE_DS1 38.89
41#define NOTE_E1 41.20
42#define NOTE_F1 43.65
43#define NOTE_FS1 46.25
44#define NOTE_G1 49.00
45#define NOTE_GS1 51.91
46#define NOTE_A1 55.00
47#define NOTE_AS1 58.27
48#define NOTE_B1 61.74
49#define NOTE_C2 65.41
50#define NOTE_CS2 69.30
51#define NOTE_D2 73.42
52#define NOTE_DS2 77.78
53#define NOTE_E2 82.41
54#define NOTE_F2 87.31
55#define NOTE_FS2 92.50
56#define NOTE_G2 98.00
57#define NOTE_GS2 103.83
58#define NOTE_A2 110.00
59#define NOTE_AS2 116.54
60#define NOTE_B2 123.47
61#define NOTE_C3 130.81
62#define NOTE_CS3 138.59
63#define NOTE_D3 146.83
64#define NOTE_DS3 155.56
65#define NOTE_E3 164.81
66#define NOTE_F3 174.61
67#define NOTE_FS3 185.00
68#define NOTE_G3 196.00
69#define NOTE_GS3 207.65
70#define NOTE_A3 220.00
71#define NOTE_AS3 233.08
72#define NOTE_B3 246.94
73#define NOTE_C4 261.63
74#define NOTE_CS4 277.18
75#define NOTE_D4 293.66
76#define NOTE_DS4 311.13
77#define NOTE_E4 329.63
78#define NOTE_F4 349.23
79#define NOTE_FS4 369.99
80#define NOTE_G4 392.00
81#define NOTE_GS4 415.30
82#define NOTE_A4 440.00
83#define NOTE_AS4 466.16
84#define NOTE_B4 493.88
85#define NOTE_C5 523.25
86#define NOTE_CS5 554.37
87#define NOTE_D5 587.33
88#define NOTE_DS5 622.25
89#define NOTE_E5 659.26
90#define NOTE_F5 698.46
91#define NOTE_FS5 739.99
92#define NOTE_G5 783.99
93#define NOTE_GS5 830.61
94#define NOTE_A5 880.00
95#define NOTE_AS5 932.33
96#define NOTE_B5 987.77
97#define NOTE_C6 1046.50
98#define NOTE_CS6 1108.73
99#define NOTE_D6 1174.66
100#define NOTE_DS6 1244.51
101#define NOTE_E6 1318.51
102#define NOTE_F6 1396.91
103#define NOTE_FS6 1479.98
104#define NOTE_G6 1567.98
105#define NOTE_GS6 1661.22
106#define NOTE_A6 1760.00
107#define NOTE_AS6 1864.66
108#define NOTE_B6 1975.53
109#define NOTE_C7 2093.00
110#define NOTE_CS7 2217.46
111#define NOTE_D7 2349.32
112#define NOTE_DS7 2489.02
113#define NOTE_E7 2637.02
114#define NOTE_F7 2793.83
115#define NOTE_FS7 2959.96
116#define NOTE_G7 3135.96
117#define NOTE_GS7 3322.44
118#define NOTE_A7 3520.00
119#define NOTE_AS7 3729.31
120#define NOTE_B7 3951.07
121#define NOTE_C8 4186.01
122#define NOTE_CS8 4434.92
123#define NOTE_D8 4698.64
124#define NOTE_DS8 4978.03
125#define NOTE_E8 5274.04
126#define NOTE_F8 5587.65
127#define NOTE_FS8 5919.91
128#define NOTE_G8 6271.93
129#define NOTE_GS8 6644.88
130#define NOTE_A8 7040.00
131#define NOTE_AS8 7458.62
132#define NOTE_B8 7902.13
133
134// Flat Aliases
135#define NOTE_DF0 NOTE_CS0
136#define NOTE_EF0 NOTE_DS0
137#define NOTE_GF0 NOTE_FS0
138#define NOTE_AF0 NOTE_GS0
139#define NOTE_BF0 NOTE_AS0
140#define NOTE_DF1 NOTE_CS1
141#define NOTE_EF1 NOTE_DS1
142#define NOTE_GF1 NOTE_FS1
143#define NOTE_AF1 NOTE_GS1
144#define NOTE_BF1 NOTE_AS1
145#define NOTE_DF2 NOTE_CS2
146#define NOTE_EF2 NOTE_DS2
147#define NOTE_GF2 NOTE_FS2
148#define NOTE_AF2 NOTE_GS2
149#define NOTE_BF2 NOTE_AS2
150#define NOTE_DF3 NOTE_CS3
151#define NOTE_EF3 NOTE_DS3
152#define NOTE_GF3 NOTE_FS3
153#define NOTE_AF3 NOTE_GS3
154#define NOTE_BF3 NOTE_AS3
155#define NOTE_DF4 NOTE_CS4
156#define NOTE_EF4 NOTE_DS4
157#define NOTE_GF4 NOTE_FS4
158#define NOTE_AF4 NOTE_GS4
159#define NOTE_BF4 NOTE_AS4
160#define NOTE_DF5 NOTE_CS5
161#define NOTE_EF5 NOTE_DS5
162#define NOTE_GF5 NOTE_FS5
163#define NOTE_AF5 NOTE_GS5
164#define NOTE_BF5 NOTE_AS5
165#define NOTE_DF6 NOTE_CS6
166#define NOTE_EF6 NOTE_DS6
167#define NOTE_GF6 NOTE_FS6
168#define NOTE_AF6 NOTE_GS6
169#define NOTE_BF6 NOTE_AS6
170#define NOTE_DF7 NOTE_CS7
171#define NOTE_EF7 NOTE_DS7
172#define NOTE_GF7 NOTE_FS7
173#define NOTE_AF7 NOTE_GS7
174#define NOTE_BF7 NOTE_AS7
175#define NOTE_DF8 NOTE_CS8
176#define NOTE_EF8 NOTE_DS8
177#define NOTE_GF8 NOTE_FS8
178#define NOTE_AF8 NOTE_GS8
179#define NOTE_BF8 NOTE_AS8
180
181
182#endif \ No newline at end of file
diff --git a/quantum/quantum.mk b/quantum/quantum.mk
index 17bb50171..1fe7390eb 100644
--- a/quantum/quantum.mk
+++ b/quantum/quantum.mk
@@ -46,6 +46,7 @@ endif
46 46
47# Search Path 47# Search Path
48VPATH += $(TOP_DIR)/$(QUANTUM_DIR) 48VPATH += $(TOP_DIR)/$(QUANTUM_DIR)
49VPATH += $(TOP_DIR)/$(QUANTUM_DIR)/keymap_extras
49 50
50include $(TMK_DIR)/protocol/lufa.mk 51include $(TMK_DIR)/protocol/lufa.mk
51 52
diff --git a/quantum/tools/README.md b/quantum/tools/README.md
new file mode 100644
index 000000000..070214423
--- /dev/null
+++ b/quantum/tools/README.md
@@ -0,0 +1,6 @@
1`eeprom_reset.hex` is to reset the eeprom on the Atmega32u4, like this:
2
3 dfu-programmer atmega32u4 erase
4 dfu-programmer atmega32u4 flash --eeprom eeprom-reset.bin
5
6 You'll need to reflash afterwards, because DFU requires the flash to be erased before messing with the eeprom. \ No newline at end of file
diff --git a/quantum/tools/eeprom_reset.hex b/quantum/tools/eeprom_reset.hex
new file mode 100644
index 000000000..a8a75389f
--- /dev/null
+++ b/quantum/tools/eeprom_reset.hex
@@ -0,0 +1,9 @@
1:10000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
2:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0
3:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0
4:10003000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0
5:10004000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0
6:10005000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB0
7:10006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA0
8:10007000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF90
9:00000001FF
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index f8006c670..9cb2eb8ec 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -21,6 +21,9 @@ ifeq ($(strip $(BOOTMAGIC_ENABLE)), yes)
21 SRC += $(COMMON_DIR)/bootmagic.c 21 SRC += $(COMMON_DIR)/bootmagic.c
22 SRC += $(COMMON_DIR)/avr/eeconfig.c 22 SRC += $(COMMON_DIR)/avr/eeconfig.c
23 OPT_DEFS += -DBOOTMAGIC_ENABLE 23 OPT_DEFS += -DBOOTMAGIC_ENABLE
24else
25 SRC += $(COMMON_DIR)/magic.c
26 SRC += $(COMMON_DIR)/avr/eeconfig.c
24endif 27endif
25 28
26ifeq ($(strip $(MOUSEKEY_ENABLE)), yes) 29ifeq ($(strip $(MOUSEKEY_ENABLE)), yes)
diff --git a/tmk_core/common/avr/eeconfig.c b/tmk_core/common/avr/eeconfig.c
index 5bd47dc6a..25bb9e849 100644
--- a/tmk_core/common/avr/eeconfig.c
+++ b/tmk_core/common/avr/eeconfig.c
@@ -13,6 +13,9 @@ void eeconfig_init(void)
13#ifdef BACKLIGHT_ENABLE 13#ifdef BACKLIGHT_ENABLE
14 eeprom_write_byte(EECONFIG_BACKLIGHT, 0); 14 eeprom_write_byte(EECONFIG_BACKLIGHT, 0);
15#endif 15#endif
16#ifdef AUDIO_ENABLE
17 eeprom_write_byte(EECONFIG_AUDIO, 0xFF); // On by default
18#endif
16} 19}
17 20
18void eeconfig_enable(void) 21void eeconfig_enable(void)
@@ -43,3 +46,8 @@ void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val
43uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } 46uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
44void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } 47void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); }
45#endif 48#endif
49
50#ifdef AUDIO_ENABLE
51uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); }
52void eeconfig_write_audio(uint8_t val) { eeprom_write_byte(EECONFIG_AUDIO, val); }
53#endif \ No newline at end of file
diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h
index 3cd1a174f..ddefca134 100644
--- a/tmk_core/common/eeconfig.h
+++ b/tmk_core/common/eeconfig.h
@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31#define EECONFIG_KEYMAP (uint8_t *)4 31#define EECONFIG_KEYMAP (uint8_t *)4
32#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 32#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5
33#define EECONFIG_BACKLIGHT (uint8_t *)6 33#define EECONFIG_BACKLIGHT (uint8_t *)6
34#define EECONFIG_AUDIO (uint8_t *)7
34 35
35 36
36/* debug bit */ 37/* debug bit */
@@ -72,4 +73,9 @@ uint8_t eeconfig_read_backlight(void);
72void eeconfig_write_backlight(uint8_t val); 73void eeconfig_write_backlight(uint8_t val);
73#endif 74#endif
74 75
76#ifdef AUDIO_ENABLE
77uint8_t eeconfig_read_audio(void);
78void eeconfig_write_audio(uint8_t val);
79#endif
80
75#endif 81#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 302b3ec87..1d9981848 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -27,7 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27#include "command.h" 27#include "command.h"
28#include "util.h" 28#include "util.h"
29#include "sendchar.h" 29#include "sendchar.h"
30#include "bootmagic.h" 30#ifdef BOOTMAGIC_ENABLE
31 #include "bootmagic.h"
32#else
33 #include "magic.h"
34#endif
31#include "eeconfig.h" 35#include "eeconfig.h"
32#include "backlight.h" 36#include "backlight.h"
33#ifdef MOUSEKEY_ENABLE 37#ifdef MOUSEKEY_ENABLE
@@ -86,6 +90,8 @@ void keyboard_init(void)
86 90
87#ifdef BOOTMAGIC_ENABLE 91#ifdef BOOTMAGIC_ENABLE
88 bootmagic(); 92 bootmagic();
93#else
94 magic();
89#endif 95#endif
90 96
91#ifdef BACKLIGHT_ENABLE 97#ifdef BACKLIGHT_ENABLE
diff --git a/tmk_core/common/keymap.h b/tmk_core/common/keymap.h
index e1a6f992e..abc9bdb32 100644
--- a/tmk_core/common/keymap.h
+++ b/tmk_core/common/keymap.h
@@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22#include <stdbool.h> 22#include <stdbool.h>
23#include "action.h" 23#include "action.h"
24 24
25
26#ifdef BOOTMAGIC_ENABLE
27/* NOTE: Not portable. Bit field order depends on implementation */ 25/* NOTE: Not portable. Bit field order depends on implementation */
28typedef union { 26typedef union {
29 uint8_t raw; 27 uint8_t raw;
@@ -39,7 +37,6 @@ typedef union {
39 }; 37 };
40} keymap_config_t; 38} keymap_config_t;
41keymap_config_t keymap_config; 39keymap_config_t keymap_config;
42#endif
43 40
44 41
45/* translates key to keycode */ 42/* translates key to keycode */
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
new file mode 100644
index 000000000..f21d1346c
--- /dev/null
+++ b/tmk_core/common/magic.c
@@ -0,0 +1,36 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include <util/delay.h>
4#include "matrix.h"
5#include "bootloader.h"
6#include "debug.h"
7#include "keymap.h"
8#include "host.h"
9#include "action_layer.h"
10#include "eeconfig.h"
11#include "magic.h"
12
13keymap_config_t keymap_config;
14
15void magic(void)
16{
17 /* check signature */
18 if (!eeconfig_is_enabled()) {
19 eeconfig_init();
20 }
21
22 /* debug enable */
23 debug_config.raw = eeconfig_read_debug();
24
25 /* keymap config */
26 keymap_config.raw = eeconfig_read_keymap();
27
28#ifdef NKRO_ENABLE
29 keyboard_nkro = keymap_config.nkro;
30#endif
31
32 uint8_t default_layer = 0;
33 default_layer = eeconfig_read_default_layer();
34 default_layer_set((uint32_t)default_layer);
35
36} \ No newline at end of file
diff --git a/tmk_core/common/magic.h b/tmk_core/common/magic.h
new file mode 100644
index 000000000..3fa2d8b81
--- /dev/null
+++ b/tmk_core/common/magic.h
@@ -0,0 +1,6 @@
1#ifndef MAGIC_H
2#define MAGIC_H
3
4void magic(void);
5
6#endif