From 9cfc74c35b940884618b0fe1e6fd25c570e1c974 Mon Sep 17 00:00:00 2001 From: Erez Zukerman Date: Thu, 7 Apr 2016 15:21:06 +0300 Subject: [PATCH 01/11] [Erez & Jack] Makes tri-layer available across Quantum --- keyboard/planck/keymaps/default/keymap.c | 9 --------- quantum/keymap_common.c | 8 ++++++++ quantum/keymap_common.h | 4 ++++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c index dee2840f2..56092d04f 100644 --- a/keyboard/planck/keymaps/default/keymap.c +++ b/keyboard/planck/keymaps/default/keymap.c @@ -174,16 +174,7 @@ float tone_dv[][2] = { }; #endif -#define IS_LAYER_ON(layer) ((layer_state) & (1<<(layer))) -#define IS_LAYER_OFF(layer) ((!layer_state) & (1<<(layer))) -void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { - if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { - layer_on(layer3); - } else { - layer_off(layer3); - } -} const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { // MACRODOWN only works in this function diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index e3030a886..3a00d36f0 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -291,3 +291,11 @@ action_t keymap_func_to_action(uint16_t keycode) // For FUNC without 8bit limit return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) }; } + +void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { + if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { + layer_on(layer3); + } else { + layer_off(layer3); + } +} diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 4a877d2a7..7452a1ff3 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -208,5 +208,9 @@ extern const uint16_t fn_actions[]; #define UNICODE(n) (n | 0x8000) #define UC(n) UNICODE(n) +// For tri-layer +void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); +#define IS_LAYER_ON(layer) ((layer_state) & (1UL<<(layer))) +#define IS_LAYER_OFF(layer) ((!layer_state) & (1UL<<(layer))) #endif From 2557b91644d9565c43f0e5c27d45788d4a47f3eb Mon Sep 17 00:00:00 2001 From: Erez Zukerman Date: Thu, 7 Apr 2016 15:45:11 +0300 Subject: [PATCH 02/11] [Erez & Jack] Documents tri-layer and keymap-specific makefile options --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab7373023..613bdcf42 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,21 @@ The documentation below explains QMK customizations and elaborates on some of th * 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. * 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 `, which will create `/keyboard/` with all the necessary components for a Quantum project. +### Makefile Options + You 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. BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality MIDI_ENABLE = yes # MIDI controls - # UNICODE_ENABLE = yes # Unicode support - this is commented out, just as an example. You have to use #, not // + UNICODE_ENABLE = no # <-- This is how you disable an option, just set it to "no" BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID +### Customizing Makefile options on a per-keymap basis + +If 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). + +So 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`. + ## Quick aliases to common actions Your keymap can include shortcuts to common operations (called "function actions" in tmk). @@ -199,6 +207,10 @@ This will clear all mods currently pressed. This will clear all keys besides the mods currently pressed. +* `update_tri_layer(layer_1, layer_2, layer_3);` + +If 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). + #### Timer functionality It's possible to start timers and read values for time-specific events - here's an example: From 549b797ad1ebb30ebaa19af2cf3b7cc2a2c055bc Mon Sep 17 00:00:00 2001 From: Jason Janse van Rensburg Date: Sat, 16 Apr 2016 01:36:18 +0200 Subject: [PATCH 03/11] My Attempt at adapting the Bone2 layout with Neo2 navigation cluster & number block to the Planck. Very much a WIP, will most likely start tweaking further once my Planck kit has dropped --- keyboard/planck/keymaps/bone2planck.c | 112 ++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 keyboard/planck/keymaps/bone2planck.c 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 @@ + +#include "planck.h" +#ifdef BACKLIGHT_ENABLE +#include "backlight.h" +#endif +#include "..\..\quantum\keymap_extras\keymap_german.h" + +/* This Layout tries to emulate the Bone2 Variant of Neo2, and is intended to be used with a German QWERTZ Softwarelayout. + It has Umlauts and "ß" as it is optimized for a mix of German & English. + My favourite features are the placement of the special characters often used for programming right on the home row + and the number & navigation block combo, so you never have to move your hands from their home position. + + Bone2 wiki page: http://wiki.neo-layout.org/wiki/Bone +*/ + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + /* Bone2 + * ,-----------------------------------------------------------------------------------. + * | Q | J | D | U | A | X | P | H | L | M | W | ẞ | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | M1 | C | T | I | E | O | B | N | R | S | G | M1 | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| F | V | Ü | Ä | Ö | Y | Z | , | . | K |Shift | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Ctrl | GUI | Alt | M3 | M2 | Space | M2 | M3 | Esc | Tab |Enter | + * `-----------------------------------------------------------------------------------' + */ + [0] = { + { DE_Q, DE_J, DE_D, DE_U, DE_A, DE_X, DE_P, DE_H, DE_L, DE_M, DE_W, DE_SS }, + { MO(1), DE_C, DE_T, DE_I, DE_E, DE_O, DE_B, DE_N, DE_R, DE_S, DE_G, MO(1) }, + { DE_S, DE_F, DE_V, DE_UE, DE_AE, DE_OE, DE_Y, DE_Z, DE_COMM, DE_DOT, DE_K, DE_S }, + { KC_LCTL, KC_LGUI, KC_LALT, MO(3), MO(2), KC_SPC, KC_SPC, MO(2), MO(3), KC_ESC, KC_TAB, KC_ENT } + }, + + /* M1 Special Characters + * ,-----------------------------------------------------------------------------------. + * | ° | @ | _ | [ | ] | ^ | ! | < | > | = | & | | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | M1 | \ | / | { | } | * | ? | ( | ) | - | : | M1 | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | # | $ | | | ~ | € | + | % | " | ' | ; | | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Ctrl | GUI | Alt | M3 | M2 | Space | M2 | M3 | Esc | Tab |Enter | + * `-----------------------------------------------------------------------------------' + */ + [1] = { + { DE_RING, DE_AT, DE_UNDS, DE_LBRC, DE_RBRC, DE_CIRC, DE_EXLM, DE_LESS, DE_MORE, DE_EQL, DE_AMPR, KC_NO }, + { KC_TRNS, DE_BSLS, DE_SLSH, DE_LCBR, DE_RCBR, DE_ASTR, DE_QST, DE_LPRN, DE_RPRN, DE_MINS, DE_COLN, KC_TRNS }, + { KC_NO , DE_HASH, DE_DLR, DE_PIPE, DE_TILD, DE_EURO, DE_PLUS, DE_PERC, DE_DQOT, DE_QUOT, DE_SCLN, KC_NO }, + { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS } + }, + + /* Navigation & Number Blocks + * ,-----------------------------------------------------------------------------------. + * | | PgUp | Bksp | Up | DEL | PgDn | | 7 | 8 | 9 | | | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | | Home | Lft | Down | Right| End | . | 4 | 5 | 6 | , | | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| | Tab | Ins | Enter| | 0 | 1 | 2 | 3 | ; |Shift | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Ctrl | GUI | Alt | M3 | M2 | Space | M2 | M3 | Esc | Tab |Enter | + * `-----------------------------------------------------------------------------------' + */ + [2] = { + { KC_NO, KC_PGUP, KC_BSPC, KC_UP, KC_DEL, KC_PGDN, KC_NO, DE_7, DE_8, DE_9, KC_NO, KC_NO }, + { KC_NO, KC_HOME, KC_LEFT, KC_DOWN, KC_RGHT, KC_END, DE_DOT, DE_4, DE_5, DE_6, DE_COMM, KC_NO }, + { DE_S, KC_NO, KC_TAB, KC_INS, KC_ENT, KC_NO, KC_0, DE_1, DE_2, DE_3, DE_SCLN, DE_S }, + { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS } + }, + + /* Function & Media Keys + * ,-----------------------------------------------------------------------------------. + * | | | Print|Scroll|Pause | | | F7 | F8 | F9 | F12 | | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | | | Mute | Vol- | Vol+ | | ³ | F4 | F5 | F6 | F11 | | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| | Prev | Play | Next | | ² | F1 | F2 | F3 | F10 |Shift | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Ctrl | GUI | Alt | M3 | | Space | | M3 | Esc | Tab |Enter | + * `-----------------------------------------------------------------------------------' + */ + [3] = { + { KC_NO, KC_NO, KC_PSCR, KC_SLCK, KC_PAUS, KC_NO, KC_NO, KC_F7, KC_F8, KC_F9, KC_F12, KC_NO }, + { KC_NO, KC_NO, KC_MUTE, KC_VOLD, KC_VOLU, KC_NO, DE_SQ3, KC_F4, KC_F5, KC_F6, KC_F11, KC_NO }, + { KC_TRNS, KC_NO, KC_MPRV, KC_MPLY, KC_MNXT, KC_NO, DE_SQ2, KC_F1, KC_F2, KC_F3, KC_F10, KC_TRNS}, + { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_NO, KC_TRNS, KC_TRNS, KC_NO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS} + } +}; + +const uint16_t PROGMEM fn_actions[] = { + +}; + +const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) +{ + // MACRODOWN only works in this function + switch (id) { + case 0: + if (record->event.pressed) { + register_code(KC_RSFT); +#ifdef BACKLIGHT_ENABLE + backlight_step(); +#endif + } + else { + unregister_code(KC_RSFT); + } + break; + } + return MACRO_NONE; +}; From 0faa18eab996c2cfcc5da0b60b702f52335c5854 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 15 Apr 2016 23:38:21 -0400 Subject: [PATCH 04/11] audio enable stored in eeprom --- keyboard/planck/keymaps/default/keymap.c | 7 +++- keyboard/preonic/Makefile | 4 +- keyboard/preonic/keymaps/default/keymap.c | 12 +++--- quantum/audio.c | 48 ++++++++++++++++++++++- quantum/audio.h | 14 ++++++- tmk_core/common/avr/eeconfig.c | 8 ++++ tmk_core/common/eeconfig.h | 6 +++ 7 files changed, 89 insertions(+), 10 deletions(-) diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c index 56092d04f..3f34ba412 100644 --- a/keyboard/planck/keymaps/default/keymap.c +++ b/keyboard/planck/keymaps/default/keymap.c @@ -135,7 +135,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { */ [_AD] = { {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, - {_______, _______, _______, _______, _______, _______, _______, M(M_QW), M(M_CM), M(M_DV), _______, _______}, + {_______, _______, _______, _______, M(6), _______, _______, M(M_QW), M(M_CM), M(M_DV), _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} } @@ -231,6 +231,11 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) unregister_code(KC_RSFT); } break; + case 6: + if (record->event.pressed) { + audio_toggle(); + } + break; } return MACRO_NONE; }; diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile index 664aff732..e48052c82 100644 --- a/keyboard/preonic/Makefile +++ b/keyboard/preonic/Makefile @@ -139,8 +139,8 @@ COMMAND_ENABLE = yes # Commands for debug and configuration # SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend # NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality -MIDI_ENABLE = YES # MIDI controls -AUDIO_ENABLE = YES # Audio output on port C6 +MIDI_ENABLE = yes # MIDI controls +AUDIO_ENABLE = yes # Audio output on port C6 # UNICODE_ENABLE = YES # Unicode # BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID # RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with MIDI at the same time. diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c index 784670784..3da69c215 100644 --- a/keyboard/preonic/keymaps/default/keymap.c +++ b/keyboard/preonic/keymaps/default/keymap.c @@ -59,11 +59,11 @@ const uint16_t PROGMEM fn_actions[] = { }; float start_up[][2] = { - {440.0*pow(2.0,(67)/12.0), 600}, - {440.0*pow(2.0,(64)/12.0), 400}, - {440.0*pow(2.0,(55)/12.0), 400}, - {440.0*pow(2.0,(60)/12.0), 400}, - {440.0*pow(2.0,(64)/12.0), 1000}, + {440.0*pow(2.0,(67)/12.0), 4}, + {440.0*pow(2.0,(64)/12.0), 8}, + {440.0*pow(2.0,(55)/12.0), 8}, + {440.0*pow(2.0,(60)/12.0), 8}, + {440.0*pow(2.0,(64)/12.0), 10}, }; const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) @@ -76,8 +76,10 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef BACKLIGHT_ENABLE backlight_step(); #endif + audio_toggle(); } else { unregister_code(KC_RSFT); + play_notes(&start_up, 5, false); } break; } diff --git a/quantum/audio.c b/quantum/audio.c index 50e5505fe..73985479c 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -8,6 +8,8 @@ #include "audio.h" #include "keymap_common.h" +#include "eeconfig.h" + #define PI 3.14159265 // #define PWM_AUDIO @@ -57,6 +59,25 @@ uint8_t notes_length; bool notes_repeat; uint8_t current_note = 0; +audio_config_t audio_config; + + +void audio_toggle(void) { + audio_config.enable ^= 1; + eeconfig_write_audio(audio_config.raw); +} + +void audio_on(void) { + audio_config.enable = 1; + eeconfig_write_audio(audio_config.raw); +} + +void audio_off(void) { + audio_config.enable = 0; + eeconfig_write_audio(audio_config.raw); +} + + void stop_all_notes() { voices = 0; #ifdef PWM_AUDIO @@ -129,6 +150,12 @@ void stop_note(double freq) { void init_notes() { + /* check signature */ + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + audio_config.raw = eeconfig_read_audio(); + #ifdef PWM_AUDIO PLLFRQ = _BV(PDIV2); PLLCSR = _BV(PLLE); @@ -160,7 +187,6 @@ void init_notes() { ISR(TIMER3_COMPA_vect) { - if (note) { #ifdef PWM_AUDIO if (voices == 1) { @@ -288,9 +314,16 @@ ISR(TIMER3_COMPA_vect) { } + if (!audio_config.enable) { + notes = false; + note = false; + } } void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) { + +if (audio_config.enable) { + if (note) stop_all_notes(); notes = true; @@ -319,7 +352,12 @@ void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) { #endif } +} + void play_sample(uint8_t * s, uint16_t l, bool r) { + +if (audio_config.enable) { + stop_all_notes(); place_int = 0; sample = s; @@ -330,9 +368,15 @@ void play_sample(uint8_t * s, uint16_t l, bool r) { TIMSK3 |= _BV(OCIE3A); #else #endif + +} + } void play_note(double freq, int vol) { + +if (audio_config.enable) { + if (notes) stop_all_notes(); note = true; @@ -367,4 +411,6 @@ void play_note(double freq, int vol) { TCCR3A |= _BV(COM3A1); #endif +} + } \ No newline at end of file diff --git a/quantum/audio.h b/quantum/audio.h index 99203cea7..58270015d 100644 --- a/quantum/audio.h +++ b/quantum/audio.h @@ -3,9 +3,21 @@ #include #include +typedef union { + uint8_t raw; + struct { + bool enable :1; + uint8_t level :7; + }; +} audio_config_t; + +void audio_toggle(void); +void audio_on(void); +void audio_off(void); + void play_sample(uint8_t * s, uint16_t l, bool r); void play_note(double freq, int vol); void stop_note(double freq); void stop_all_notes(); void init_notes(); -void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat); \ No newline at end of file +void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat); diff --git a/tmk_core/common/avr/eeconfig.c b/tmk_core/common/avr/eeconfig.c index 5bd47dc6a..d0c3f4f57 100644 --- a/tmk_core/common/avr/eeconfig.c +++ b/tmk_core/common/avr/eeconfig.c @@ -13,6 +13,9 @@ void eeconfig_init(void) #ifdef BACKLIGHT_ENABLE eeprom_write_byte(EECONFIG_BACKLIGHT, 0); #endif +#ifdef AUDIO_ENABLE + eeprom_write_byte(EECONFIG_AUDIO, 0); +#endif } void eeconfig_enable(void) @@ -43,3 +46,8 @@ void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } #endif + +#ifdef AUDIO_ENABLE +uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); } +void eeconfig_write_audio(uint8_t val) { eeprom_write_byte(EECONFIG_AUDIO, val); } +#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 . #define EECONFIG_KEYMAP (uint8_t *)4 #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 #define EECONFIG_BACKLIGHT (uint8_t *)6 +#define EECONFIG_AUDIO (uint8_t *)7 /* debug bit */ @@ -72,4 +73,9 @@ uint8_t eeconfig_read_backlight(void); void eeconfig_write_backlight(uint8_t val); #endif +#ifdef AUDIO_ENABLE +uint8_t eeconfig_read_audio(void); +void eeconfig_write_audio(uint8_t val); +#endif + #endif From c294636c666a6c4a9c170a9a7f62607d48081b3c Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 15 Apr 2016 23:46:35 -0400 Subject: [PATCH 05/11] audio on by default --- tmk_core/common/avr/eeconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmk_core/common/avr/eeconfig.c b/tmk_core/common/avr/eeconfig.c index d0c3f4f57..25bb9e849 100644 --- a/tmk_core/common/avr/eeconfig.c +++ b/tmk_core/common/avr/eeconfig.c @@ -14,7 +14,7 @@ void eeconfig_init(void) eeprom_write_byte(EECONFIG_BACKLIGHT, 0); #endif #ifdef AUDIO_ENABLE - eeprom_write_byte(EECONFIG_AUDIO, 0); + eeprom_write_byte(EECONFIG_AUDIO, 0xFF); // On by default #endif } From 0b0ec82427aff54481103559066213056b6d7598 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 00:01:22 -0400 Subject: [PATCH 06/11] eeprom reset tool --- quantum/tools/README.md | 6 ++++++ quantum/tools/eeprom_reset.hex | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 quantum/tools/README.md create mode 100644 quantum/tools/eeprom_reset.hex 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 @@ +`eeprom_reset.hex` is to reset the eeprom on the Atmega32u4, like this: + + dfu-programmer atmega32u4 erase + dfu-programmer atmega32u4 flash --eeprom eeprom-reset.bin + + 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 @@ +:10000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00 +:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 +:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 +:10003000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0 +:10004000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0 +:10005000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB0 +:10006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA0 +:10007000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF90 +:00000001FF From d81ef5b7eb888ae2878e60d548854413ee3023c6 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 01:19:37 -0400 Subject: [PATCH 07/11] new defaults for planck and preonic --- keyboard/planck/keymaps/default/keymap.c | 74 +++--- keyboard/preonic/Makefile | 53 ++-- keyboard/preonic/keymaps/default/README.md | 35 +-- keyboard/preonic/keymaps/default/keymap.c | 264 ++++++++++++++++--- keyboard/preonic/keymaps/default/makefile.mk | 1 + 5 files changed, 309 insertions(+), 118 deletions(-) create mode 100644 keyboard/preonic/keymaps/default/makefile.mk diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c index 3f34ba412..ede08ad7f 100644 --- a/keyboard/planck/keymaps/default/keymap.c +++ b/keyboard/planck/keymaps/default/keymap.c @@ -19,12 +19,16 @@ #define _AD 5 // Macro name shortcuts -#define M_QW 0 -#define M_CM 1 -#define M_DV 2 -#define M_LW 3 -#define M_RS 4 +#define QWERTY M(_QW) +#define COLEMAK M(_CM) +#define DVORAK M(_DV) +#define LOWER M(_LW) +#define RAISE M(_RS) #define M_BL 5 +#ifdef AUDIO_ENABLE + #define AUD_OFF M(6) + #define AUD_ON M(7) +#endif // Fillers to make layering more clear #define _______ KC_TRNS @@ -47,7 +51,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {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} + {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} }, /* Colemak @@ -65,7 +69,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {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} + {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} }, /* Dvorak @@ -83,7 +87,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, - {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} + {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} }, /* Lower @@ -126,7 +130,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * ,-----------------------------------------------------------------------------------. * | | Reset| | | | | | | | | | Del | * |------+------+------+------+------+-------------+------+------+------+------+------| - * | | | | | | | |Qwerty|Colemk|Dvorak| | | + * | | | |Aud on|Audoff| | |Qwerty|Colemk|Dvorak| | | * |------+------+------+------+------+------|------+------+------+------+------+------| * | | | | | | | | | | | | | * |------+------+------+------+------+------+------+------+------+------+------+------| @@ -135,7 +139,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { */ [_AD] = { {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, - {_______, _______, _______, _______, M(6), _______, _______, M(M_QW), M(M_CM), M(M_DV), _______, _______}, + {_______, _______, _______, AUD_ON, AUD_OFF, _______, _______, QWERTY, COLEMAK, DVORAK, _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} } @@ -146,6 +150,14 @@ const uint16_t PROGMEM fn_actions[] = { }; #ifdef AUDIO_ENABLE +float start_up[][2] = { + {440.0*pow(2.0,(67)/12.0), 12}, + {440.0*pow(2.0,(64)/12.0), 8}, + {440.0*pow(2.0,(55)/12.0), 8}, + {440.0*pow(2.0,(60)/12.0), 8}, + {440.0*pow(2.0,(64)/12.0), 20} +}; + float tone_qw[][2] = { {440.0*pow(2.0,(59)/12.0), 8}, {440.0*pow(2.0,(60)/12.0), 8}, @@ -157,20 +169,20 @@ float tone_cm[][2] = { {440.0*pow(2.0,(59)/12.0), 8}, {440.0*pow(2.0,(60)/12.0), 8}, {0, 4}, - {440.0*pow(2.0,(67)/12.0), 16}, + {440.0*pow(2.0,(67)/12.0), 12}, {0, 4}, - {440.0*pow(2.0,(71)/12.0), 16} + {440.0*pow(2.0,(71)/12.0), 12} }; float tone_dv[][2] = { {440.0*pow(2.0,(59)/12.0), 8}, {440.0*pow(2.0,(60)/12.0), 8}, {0, 4}, - {440.0*pow(2.0,(67)/12.0), 16}, + {440.0*pow(2.0,(67)/12.0), 8}, {0, 4}, - {440.0*pow(2.0,(69)/12.0), 16}, + {440.0*pow(2.0,(69)/12.0), 8}, {0, 4}, - {440.0*pow(2.0,(67)/12.0), 16} + {440.0*pow(2.0,(67)/12.0), 8} }; #endif @@ -179,7 +191,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { // MACRODOWN only works in this function switch(id) { - case M_QW: + case _QW: if (record->event.pressed) { #ifdef AUDIO_ENABLE play_notes(&tone_qw, 4, false); @@ -187,7 +199,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) default_layer_set(1UL<<_QW); } break; - case M_CM: + case _CM: if (record->event.pressed) { #ifdef AUDIO_ENABLE play_notes(&tone_cm, 6, false); @@ -195,7 +207,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) default_layer_set(1UL<<_CM); } break; - case M_DV: + case _DV: if (record->event.pressed) { #ifdef AUDIO_ENABLE play_notes(&tone_dv, 8, false); @@ -203,7 +215,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) default_layer_set(1UL<<_DV); } break; - case M_LW: + case _LW: if (record->event.pressed) { layer_on(_LW); update_tri_layer(_LW, _RS, _AD); @@ -212,7 +224,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) update_tri_layer(_LW, _RS, _AD); } break; - case M_RS: + case _RS: if (record->event.pressed) { layer_on(_RS); update_tri_layer(_LW, _RS, _AD); @@ -233,23 +245,23 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) break; case 6: if (record->event.pressed) { - audio_toggle(); + #ifdef AUDIO_ENABLE + audio_off(); + #endif + } + break; + case 7: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + audio_on(); + play_notes(&start_up, 5, false); + #endif } break; } return MACRO_NONE; }; -#ifdef AUDIO_ENABLE -float start_up[][2] = { - {440.0*pow(2.0,(67)/12.0), 12}, - {440.0*pow(2.0,(64)/12.0), 8}, - {440.0*pow(2.0,(55)/12.0), 8}, - {440.0*pow(2.0,(60)/12.0), 8}, - {440.0*pow(2.0,(64)/12.0), 20} -}; -#endif - void matrix_init_user(void) { #ifdef AUDIO_ENABLE init_notes(); diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile index e48052c82..eaf9ef927 100644 --- a/keyboard/preonic/Makefile +++ b/keyboard/preonic/Makefile @@ -126,27 +126,44 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # USBaspLoader 2048 OPT_DEFS += -DBOOTLOADER_SIZE=4096 - # Build Options -# comment out to disable the options. +# change to "no" to disable the options, or define them in the makefile.mk in +# the appropriate keymap folder that will get included automatically # -BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) -MOUSEKEY_ENABLE = yes # Mouse keys(+4700) -EXTRAKEY_ENABLE = yes # Audio control and System control(+450) -CONSOLE_ENABLE = yes # Console for debug(+400) -COMMAND_ENABLE = yes # Commands for debug and configuration -# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE -# SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend -# NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work -BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality -MIDI_ENABLE = yes # MIDI controls -AUDIO_ENABLE = yes # Audio output on port C6 -# UNICODE_ENABLE = YES # Unicode -# BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID -# RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with MIDI at the same time. +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = yes # Console for debug(+400) +COMMAND_ENABLE = yes # Commands for debug and configuration +NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality +MIDI_ENABLE = no # MIDI controls +AUDIO_ENABLE = no # Audio output on port C6 +UNICODE_ENABLE = no # Unicode +BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID +RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. -ifdef BACKLIGHT_ENABLE - SRC += backlight.c +# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend + +ifdef KEYMAP + +ifeq ("$(wildcard keymaps/$(KEYMAP).c)","") +ifneq ("$(wildcard keymaps/$(KEYMAP)/makefile.mk)","") + include keymaps/$(KEYMAP)/makefile.mk +endif +endif + +else + +ifneq ("$(wildcard keymaps/default/makefile.mk)","") + include keymaps/default/makefile.mk +endif + +endif + +ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) + SRC := backlight.c $(SRC) endif 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 @@ -# The Default Planck Layout - - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [_QW] = { /* Qwerty */ - {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, - {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, - {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} - }, - [_CM] = { /* Colemak */ - {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, - {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, - {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} - }, - [_DV] = { /* Dvorak */ - {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, - {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, - {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} - }, - [_RS] = { /* RAISE */ - {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, - {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS}, - {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} - }, - [_LW] = { /* LOWER */ - {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC}, - {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, - {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS}, - {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} - } - }; \ No newline at end of file +# The default Preonic layout - largely based on the Planck's \ No newline at end of file diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c index 3da69c215..c52d8472f 100644 --- a/keyboard/preonic/keymaps/default/keymap.c +++ b/keyboard/preonic/keymaps/default/keymap.c @@ -1,9 +1,7 @@ -// This is the canonical layout file for the Quantum project. If you want to add another keyboard, -// this is the style you want to emulate. - #include "preonic.h" -#ifdef BACKLIGHT_ENABLE - #include "backlight.h" +#include "action_layer.h" +#ifdef AUDIO_ENABLE + #include "audio.h" #endif // Each layer gets a name for readability, which is then used in the keymap matrix below. @@ -15,42 +13,150 @@ #define _DV 2 #define _LW 3 #define _RS 4 +#define _AD 5 + +// Macro name shortcuts +#define QWERTY M(_QW) +#define COLEMAK M(_CM) +#define DVORAK M(_DV) +#define LOWER M(_LW) +#define RAISE M(_RS) +#define M_BL 5 +#ifdef AUDIO_ENABLE + #define AUD_OFF M(6) + #define AUD_ON M(7) +#endif + +// Fillers to make layering more clear +#define _______ KC_TRNS +#define XXXXXXX KC_NO const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -[_QW] = { /* Qwerty */ + +/* Qwerty + * ,-----------------------------------------------------------------------------------. + * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Tab | Q | W | E | R | T | Y | U | I | O | P | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | S | D | F | G | H | J | K | L | ; | " | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ +[_QW] = { {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, + {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL}, {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} }, -[_CM] = { /* Colemak */ + +/* Colemak + * ,-----------------------------------------------------------------------------------. + * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | R | S | T | D | H | N | E | I | O | " | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ +[_CM] = { {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, + {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_DEL}, {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} }, -[_DV] = { /* Dvorak */ + +/* Dvorak + * ,-----------------------------------------------------------------------------------. + * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Tab | " | , | . | P | Y | F | G | C | R | L | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | O | E | U | I | D | H | T | N | S | / | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ +[_DV] = { {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, + {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_DEL}, {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + {M(M_BL), KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} }, -[_RS] = { /* RAISE */ - {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, - {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS}, - {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} -}, -[_LW] = { /* LOWER */ - {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, + +/* Lower + * ,-----------------------------------------------------------------------------------. + * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | Next | Vol- | Vol+ | Play | + * `-----------------------------------------------------------------------------------' + */ +[_LW] = { {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC}, - {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, - {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS}, - {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} + {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL}, + {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, + {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} +}, + +/* Raise + * ,-----------------------------------------------------------------------------------. + * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | Next | Vol- | Vol+ | Play | + * `-----------------------------------------------------------------------------------' + */ +[_RS] = { + {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, + {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL}, + {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, + {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} +}, + +/* Adjust (Lower + Raise) + * ,-----------------------------------------------------------------------------------. + * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | Reset| | | | | | | | | | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | | | |Audoff|Aud on| | |Qwerty|Colemk|Dvorak| | | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | | | | | | | | | | | | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | | | | | + * `-----------------------------------------------------------------------------------' + */ +[_AD] = { + {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12}, + {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, + {_______, _______, _______, AUD_ON, AUD_OFF, _______, _______, QWERTY, COLEMAK, DVORAK, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} } }; @@ -58,28 +164,116 @@ const uint16_t PROGMEM fn_actions[] = { }; +#ifdef AUDIO_ENABLE float start_up[][2] = { - {440.0*pow(2.0,(67)/12.0), 4}, + {440.0*pow(2.0,(55)/12.0), 12}, + {0, 2}, + {440.0*pow(2.0,(67)/12.0), 8}, {440.0*pow(2.0,(64)/12.0), 8}, {440.0*pow(2.0,(55)/12.0), 8}, - {440.0*pow(2.0,(60)/12.0), 8}, - {440.0*pow(2.0,(64)/12.0), 10}, + {440.0*pow(2.0,(67)/12.0), 12}, + {0, 2}, + {440.0*pow(2.0,(67)/12.0), 12} }; +float tone_qw[][2] = { + {440.0*pow(2.0,(59)/12.0), 8}, + {440.0*pow(2.0,(60)/12.0), 8}, + {0, 4}, + {440.0*pow(2.0,(67)/12.0), 16} +}; + +float tone_cm[][2] = { + {440.0*pow(2.0,(59)/12.0), 8}, + {440.0*pow(2.0,(60)/12.0), 8}, + {0, 4}, + {440.0*pow(2.0,(67)/12.0), 12}, + {0, 4}, + {440.0*pow(2.0,(71)/12.0), 12} +}; + +float tone_dv[][2] = { + {440.0*pow(2.0,(59)/12.0), 8}, + {440.0*pow(2.0,(60)/12.0), 8}, + {0, 4}, + {440.0*pow(2.0,(67)/12.0), 8}, + {0, 4}, + {440.0*pow(2.0,(69)/12.0), 8}, + {0, 4}, + {440.0*pow(2.0,(67)/12.0), 8} +}; +#endif + + const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { // MACRODOWN only works in this function switch(id) { - case 0: + case _QW: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + play_notes(&tone_qw, 4, false); + #endif + default_layer_set(1UL<<_QW); + } + break; + case _CM: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + play_notes(&tone_cm, 6, false); + #endif + default_layer_set(1UL<<_CM); + } + break; + case _DV: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + play_notes(&tone_dv, 8, false); + #endif + default_layer_set(1UL<<_DV); + } + break; + case _LW: + if (record->event.pressed) { + layer_on(_LW); + update_tri_layer(_LW, _RS, _AD); + } else { + layer_off(_LW); + update_tri_layer(_LW, _RS, _AD); + } + break; + case _RS: + if (record->event.pressed) { + layer_on(_RS); + update_tri_layer(_LW, _RS, _AD); + } else { + layer_off(_RS); + update_tri_layer(_LW, _RS, _AD); + } + break; + case M_BL: if (record->event.pressed) { register_code(KC_RSFT); #ifdef BACKLIGHT_ENABLE backlight_step(); #endif - audio_toggle(); } else { unregister_code(KC_RSFT); - play_notes(&start_up, 5, false); + } + break; + case 6: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + audio_off(); + #endif + } + break; + case 7: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + audio_on(); + play_notes(&start_up, 7, false); + #endif } break; } @@ -87,8 +281,8 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) }; void matrix_init_user(void) { -#ifdef AUDIO_ENABLE + #ifdef AUDIO_ENABLE init_notes(); - play_notes(&start_up, 5, false); -#endif + play_notes(&start_up, 7, false); + #endif } 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 From 142ce47698613bb8fb757f13c29928a572a4d9d9 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 01:23:08 -0400 Subject: [PATCH 08/11] added keymap_extras to path --- quantum/quantum.mk | 1 + 1 file changed, 1 insertion(+) 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 # Search Path VPATH += $(TOP_DIR)/$(QUANTUM_DIR) +VPATH += $(TOP_DIR)/$(QUANTUM_DIR)/keymap_extras include $(TMK_DIR)/protocol/lufa.mk From 86169833c597fa5f2b5226e1587c48a6692ec017 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 15:47:17 -0400 Subject: [PATCH 09/11] updates to preonic default, music mode integrated --- keyboard/preonic/keymaps/default/keymap.c | 160 +++++++++++++++------- quantum/audio.c | 102 +++++++------- 2 files changed, 166 insertions(+), 96 deletions(-) diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c index c52d8472f..6824f68b6 100644 --- a/keyboard/preonic/keymaps/default/keymap.c +++ b/keyboard/preonic/keymaps/default/keymap.c @@ -1,31 +1,40 @@ #include "preonic.h" #include "action_layer.h" +#include "eeconfig.h" #ifdef AUDIO_ENABLE #include "audio.h" + #define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \ + 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \ + 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \ + 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \ + 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), } #endif // Each layer gets a name for readability, which is then used in the keymap matrix below. // The underscores don't mean anything - you can have a layer called STUFF or any other name. // Layer names don't all need to be of the same length, obviously, and you can also skip them // entirely and just use numbers. -#define _QW 0 -#define _CM 1 -#define _DV 2 -#define _LW 3 -#define _RS 4 -#define _AD 5 +#define _QWERTY 0 +#define _COLEMAK 1 +#define _DVORAK 2 +#define _LOWER 3 +#define _RAISE 4 +#define _ADJUST 5 +#define _MUSIC 6 // Macro name shortcuts -#define QWERTY M(_QW) -#define COLEMAK M(_CM) -#define DVORAK M(_DV) -#define LOWER M(_LW) -#define RAISE M(_RS) +#define QWERTY M(_QWERTY) +#define COLEMAK M(_COLEMAK) +#define DVORAK M(_DVORAK) +#define LOWER M(_LOWER) +#define RAISE M(_RAISE) #define M_BL 5 #ifdef AUDIO_ENABLE #define AUD_OFF M(6) #define AUD_ON M(7) #endif +#define MUS_OFF M(8) +#define MUS_ON M(9) // Fillers to make layering more clear #define _______ KC_TRNS @@ -46,7 +55,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | * `-----------------------------------------------------------------------------------' */ -[_QW] = { +[_QWERTY] = { {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL}, {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, @@ -67,7 +76,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | * `-----------------------------------------------------------------------------------' */ -[_CM] = { +[_COLEMAK] = { {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_DEL}, {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, @@ -88,7 +97,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | * `-----------------------------------------------------------------------------------' */ -[_DV] = { +[_DVORAK] = { {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_DEL}, {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, @@ -109,7 +118,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | | | | | | | | Next | Vol- | Vol+ | Play | * `-----------------------------------------------------------------------------------' */ -[_LW] = { +[_LOWER] = { {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC}, {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL}, {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, @@ -130,7 +139,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | | | | | | | | Next | Vol- | Vol+ | Play | * `-----------------------------------------------------------------------------------' */ -[_RS] = { +[_RAISE] = { {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL}, {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, @@ -151,10 +160,21 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | | | | | | | | | | | | * `-----------------------------------------------------------------------------------' */ -[_AD] = { +[_ADJUST] = { {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12}, {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, {_______, _______, _______, AUD_ON, AUD_OFF, _______, _______, QWERTY, COLEMAK, DVORAK, _______, _______}, + {_______, _______, _______, MUS_ON, MUS_OFF, _______, _______, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} +}, + +/* Music (reserved for process_action_user) + * + */ +[_MUSIC] = { + {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} } @@ -166,24 +186,20 @@ const uint16_t PROGMEM fn_actions[] = { #ifdef AUDIO_ENABLE float start_up[][2] = { - {440.0*pow(2.0,(55)/12.0), 12}, - {0, 2}, - {440.0*pow(2.0,(67)/12.0), 8}, - {440.0*pow(2.0,(64)/12.0), 8}, - {440.0*pow(2.0,(55)/12.0), 8}, - {440.0*pow(2.0,(67)/12.0), 12}, - {0, 2}, - {440.0*pow(2.0,(67)/12.0), 12} + {440.0*pow(2.0,(50)/12.0), 20}, + {440.0*pow(2.0,(62)/12.0), 8}, + {440.0*pow(2.0,(54)/12.0), 20}, + {440.0*pow(2.0,(62)/12.0), 8} }; -float tone_qw[][2] = { +float tone_qwerty[][2] = { {440.0*pow(2.0,(59)/12.0), 8}, {440.0*pow(2.0,(60)/12.0), 8}, {0, 4}, {440.0*pow(2.0,(67)/12.0), 16} }; -float tone_cm[][2] = { +float tone_colemak[][2] = { {440.0*pow(2.0,(59)/12.0), 8}, {440.0*pow(2.0,(60)/12.0), 8}, {0, 4}, @@ -192,7 +208,7 @@ float tone_cm[][2] = { {440.0*pow(2.0,(71)/12.0), 12} }; -float tone_dv[][2] = { +float tone_dvorak[][2] = { {440.0*pow(2.0,(59)/12.0), 8}, {440.0*pow(2.0,(60)/12.0), 8}, {0, 4}, @@ -202,53 +218,66 @@ float tone_dv[][2] = { {0, 4}, {440.0*pow(2.0,(67)/12.0), 8} }; + +float tone_music[][2] = { + {440.0*pow(2.0,(48)/12.0), 8}, + {440.0*pow(2.0,(50)/12.0), 8}, + {440.0*pow(2.0,(52)/12.0), 8}, + {440.0*pow(2.0,(53)/12.0), 8}, + {440.0*pow(2.0,(55)/12.0), 8}, + {440.0*pow(2.0,(57)/12.0), 8}, + {440.0*pow(2.0,(59)/12.0), 8}, + {440.0*pow(2.0,(60)/12.0), 8} +}; #endif const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { - // MACRODOWN only works in this function switch(id) { - case _QW: + case _QWERTY: if (record->event.pressed) { #ifdef AUDIO_ENABLE - play_notes(&tone_qw, 4, false); + play_notes(&tone_qwerty, 4, false); #endif - default_layer_set(1UL<<_QW); + eeconfig_write_default_layer(1UL<<_QWERTY); + default_layer_set(1UL<<_QWERTY); } break; - case _CM: + case _COLEMAK: if (record->event.pressed) { #ifdef AUDIO_ENABLE - play_notes(&tone_cm, 6, false); + play_notes(&tone_colemak, 6, false); #endif - default_layer_set(1UL<<_CM); + eeconfig_write_default_layer(1UL<<_COLEMAK); + default_layer_set(1UL<<_COLEMAK); } break; - case _DV: + case _DVORAK: if (record->event.pressed) { #ifdef AUDIO_ENABLE - play_notes(&tone_dv, 8, false); + play_notes(&tone_dvorak, 8, false); #endif - default_layer_set(1UL<<_DV); + eeconfig_write_default_layer(1UL<<_DVORAK); + default_layer_set(1UL<<_DVORAK); } break; - case _LW: + case _LOWER: if (record->event.pressed) { - layer_on(_LW); - update_tri_layer(_LW, _RS, _AD); + layer_on(_LOWER); + update_tri_layer(_LOWER, _RAISE, _ADJUST); } else { - layer_off(_LW); - update_tri_layer(_LW, _RS, _AD); + layer_off(_LOWER); + update_tri_layer(_LOWER, _RAISE, _ADJUST); } break; - case _RS: + case _RAISE: if (record->event.pressed) { - layer_on(_RS); - update_tri_layer(_LW, _RS, _AD); + layer_on(_RAISE); + update_tri_layer(_LOWER, _RAISE, _ADJUST); } else { - layer_off(_RS); - update_tri_layer(_LW, _RS, _AD); + layer_off(_RAISE); + update_tri_layer(_LOWER, _RAISE, _ADJUST); } break; case M_BL: @@ -272,7 +301,23 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) if (record->event.pressed) { #ifdef AUDIO_ENABLE audio_on(); - play_notes(&start_up, 7, false); + play_notes(&start_up, 4, false); + #endif + } + break; + case 8: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + layer_off(_MUSIC); + stop_all_notes(); + #endif + } + break; + case 9: + if (record->event.pressed) { + #ifdef AUDIO_ENABLE + play_notes(&tone_music, 8, false); + layer_on(_MUSIC); #endif } break; @@ -280,9 +325,24 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) return MACRO_NONE; }; +uint8_t starting_note = 0x0C; +int offset = 7; + +void process_action_user(keyrecord_t *record) { + + if (IS_LAYER_ON(_MUSIC)) { + if (record->event.pressed) { + 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); + } else { + 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))); + } + } + +} + void matrix_init_user(void) { #ifdef AUDIO_ENABLE init_notes(); - play_notes(&start_up, 7, false); + play_notes(&start_up, 4, false); #endif } diff --git a/quantum/audio.c b/quantum/audio.c index 73985479c..5edcccdbe 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -32,6 +32,8 @@ int voice_place = 0; double frequency = 0; int volume = 0; long position = 0; +int duty_place = 1; +int duty_counter = 0; double frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -98,53 +100,55 @@ void stop_all_notes() { } void stop_note(double freq) { - #ifdef PWM_AUDIO - freq = freq / SAMPLE_RATE; - #endif - for (int i = 7; i >= 0; i--) { - if (frequencies[i] == freq) { - frequencies[i] = 0; - volumes[i] = 0; - for (int j = i; (j < 7); j++) { - frequencies[j] = frequencies[j+1]; - frequencies[j+1] = 0; - volumes[j] = volumes[j+1]; - volumes[j+1] = 0; - } - } - } - voices--; - if (voices < 0) - voices = 0; - if (voices == 0) { + if (note) { #ifdef PWM_AUDIO - TIMSK3 &= ~_BV(OCIE3A); - #else - TIMSK3 &= ~_BV(OCIE3A); - TCCR3A &= ~_BV(COM3A1); + freq = freq / SAMPLE_RATE; #endif - frequency = 0; - volume = 0; - note = false; - } else { - double freq = frequencies[voices - 1]; - int vol = volumes[voices - 1]; - double starting_f = frequency; - if (frequency < freq) { - sliding = true; - for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { - frequency = f; + for (int i = 7; i >= 0; i--) { + if (frequencies[i] == freq) { + frequencies[i] = 0; + volumes[i] = 0; + for (int j = i; (j < 7); j++) { + frequencies[j] = frequencies[j+1]; + frequencies[j+1] = 0; + volumes[j] = volumes[j+1]; + volumes[j+1] = 0; + } } - sliding = false; - } else if (frequency > freq) { - sliding = true; - for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) { - frequency = f; - } - sliding = false; } - frequency = freq; - volume = vol; + voices--; + if (voices < 0) + voices = 0; + if (voices == 0) { + #ifdef PWM_AUDIO + TIMSK3 &= ~_BV(OCIE3A); + #else + TIMSK3 &= ~_BV(OCIE3A); + TCCR3A &= ~_BV(COM3A1); + #endif + frequency = 0; + volume = 0; + note = false; + } else { + double freq = frequencies[voices - 1]; + int vol = volumes[voices - 1]; + double starting_f = frequency; + if (frequency < freq) { + sliding = true; + for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { + frequency = f; + } + sliding = false; + } else if (frequency > freq) { + sliding = true; + for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) { + frequency = f; + } + sliding = false; + } + frequency = freq; + volume = vol; + } } } @@ -239,13 +243,19 @@ ISR(TIMER3_COMPA_vect) { if (frequency > 0) { // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period // OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period - if (place > 10) { + voice_place %= voices; + if (place > (frequencies[voice_place] / 500)) { voice_place = (voice_place + 1) % voices; place = 0.0; } ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period - OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1; // Set compare to half the period + OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1 * duty_place; // Set compare to half the period place++; + // if (duty_counter > (frequencies[voice_place] / 500)) { + // duty_place = (duty_place % 3) + 1; + // duty_counter = 0; + // } + // duty_counter++; } #endif } @@ -375,7 +385,7 @@ if (audio_config.enable) { void play_note(double freq, int vol) { -if (audio_config.enable) { +if (audio_config.enable && voices < 8) { if (notes) stop_all_notes(); From ab19ebd08a8b955775e6fa94cdf6b8d128d8b43c Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 18:51:58 -0400 Subject: [PATCH 10/11] MAGIC functionality, AG swap in default layout --- keyboard/planck/keymaps/default/README.md | 32 --- keyboard/preonic/Makefile | 2 +- keyboard/preonic/keymaps/default/keymap.c | 19 +- quantum/keymap_common.c | 250 ++++++++++++---------- quantum/keymap_common.h | 28 ++- tmk_core/common.mk | 3 + tmk_core/common/keyboard.c | 8 +- tmk_core/common/keymap.h | 3 - tmk_core/common/magic.c | 36 ++++ tmk_core/common/magic.h | 6 + 10 files changed, 226 insertions(+), 161 deletions(-) create mode 100644 tmk_core/common/magic.c create mode 100644 tmk_core/common/magic.h 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 @@ # The Default Planck Layout - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [_QW] = { /* Qwerty */ - {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, - {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, - {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} - }, - [_CM] = { /* Colemak */ - {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, - {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, - {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} - }, - [_DV] = { /* Dvorak */ - {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, - {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, - {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} - }, - [_RS] = { /* RAISE */ - {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, - {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS}, - {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} - }, - [_LW] = { /* LOWER */ - {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC}, - {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, - {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS}, - {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} - } - }; \ No newline at end of file diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile index eaf9ef927..9199968c3 100644 --- a/keyboard/preonic/Makefile +++ b/keyboard/preonic/Makefile @@ -130,7 +130,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096 # change to "no" to disable the options, or define them in the makefile.mk in # the appropriate keymap folder that will get included automatically # -BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) MOUSEKEY_ENABLE = yes # Mouse keys(+4700) EXTRAKEY_ENABLE = yes # Audio control and System control(+450) CONSOLE_ENABLE = yes # Console for debug(+400) diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c index 6824f68b6..e1f9b6202 100644 --- a/keyboard/preonic/keymaps/default/keymap.c +++ b/keyboard/preonic/keymaps/default/keymap.c @@ -153,9 +153,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * |------+------+------+------+------+------+------+------+------+------+------+------| * | | Reset| | | | | | | | | | Del | * |------+------+------+------+------+-------------+------+------+------+------+------| - * | | | |Audoff|Aud on| | |Qwerty|Colemk|Dvorak| | | + * | | | |Audoff|Aud on|AGnorm|AGswap|Qwerty|Colemk|Dvorak| | | * |------+------+------+------+------+------|------+------+------+------+------+------| - * | | | | | | | | | | | | | + * | | | |Musoff|Mus on| | | | | | | | * |------+------+------+------+------+------+------+------+------+------+------+------| * | | | | | | | | | | | | * `-----------------------------------------------------------------------------------' @@ -163,7 +163,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [_ADJUST] = { {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12}, {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, - {_______, _______, _______, AUD_ON, AUD_OFF, _______, _______, QWERTY, COLEMAK, DVORAK, _______, _______}, + {_______, _______, _______, AUD_ON, AUD_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______}, {_______, _______, _______, MUS_ON, MUS_OFF, _______, _______, _______, _______, _______, _______, _______}, {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} }, @@ -231,6 +231,10 @@ float tone_music[][2] = { }; #endif +void persistant_default_layer_set(uint16_t default_layer) { + eeconfig_write_default_layer(default_layer); + default_layer_set(default_layer); +} const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { @@ -240,8 +244,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef AUDIO_ENABLE play_notes(&tone_qwerty, 4, false); #endif - eeconfig_write_default_layer(1UL<<_QWERTY); - default_layer_set(1UL<<_QWERTY); + persistant_default_layer_set(1UL<<_QWERTY); } break; case _COLEMAK: @@ -249,8 +252,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef AUDIO_ENABLE play_notes(&tone_colemak, 6, false); #endif - eeconfig_write_default_layer(1UL<<_COLEMAK); - default_layer_set(1UL<<_COLEMAK); + persistant_default_layer_set(1UL<<_COLEMAK); } break; case _DVORAK: @@ -258,8 +260,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef AUDIO_ENABLE play_notes(&tone_dvorak, 8, false); #endif - eeconfig_write_default_layer(1UL<<_DVORAK); - default_layer_set(1UL<<_DVORAK); + persistant_default_layer_set(1UL<<_DVORAK); } break; case _LOWER: diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 3a00d36f0..b91916685 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -27,6 +27,8 @@ along with this program. If not, see . #include "keymap_midi.h" #include "bootloader.h" +extern keymap_config_t keymap_config; + #include #include #ifdef AUDIO_ENABLE @@ -47,120 +49,9 @@ action_t action_for_key(uint8_t layer, keypos_t key) // 16bit keycodes - important uint16_t keycode = keymap_key_to_keycode(layer, key); - if (keycode >= 0x0100 && keycode < 0x2000) { - // Has a modifier - action_t action; - // Split it up - action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key - return action; - } else if (keycode >= 0x2000 && keycode < 0x3000) { - // Is a shortcut for function layer, pull last 12bits - // This means we have 4,096 FN macros at our disposal - return keymap_func_to_action(keycode & 0xFFF); - } else if (keycode >= 0x3000 && keycode < 0x4000) { - // When the code starts with 3, it's an action macro. - action_t action; - action.code = ACTION_MACRO(keycode & 0xFF); - return action; -#ifdef BACKLIGHT_ENABLE - } else if (keycode >= BL_0 && keycode <= BL_15) { - action_t action; - action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F); - return action; - } else if (keycode == BL_DEC) { - action_t action; - action.code = ACTION_BACKLIGHT_DECREASE(); - return action; - } else if (keycode == BL_INC) { - action_t action; - action.code = ACTION_BACKLIGHT_INCREASE(); - return action; - } else if (keycode == BL_TOGG) { - action_t action; - action.code = ACTION_BACKLIGHT_TOGGLE(); - return action; - } else if (keycode == BL_STEP) { - action_t action; - action.code = ACTION_BACKLIGHT_STEP(); - return action; -#endif - } else if (keycode == RESET) { // RESET is 0x5000, which is why this is here - action_t action; - clear_keyboard(); - #ifdef AUDIO_ENABLE - play_notes(&goodbye, 3, false); - #endif - _delay_ms(250); - #ifdef ATREUS_ASTAR - *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific - #endif - bootloader_jump(); - return action; - } else if (keycode == DEBUG) { // DEBUG is 0x5001 - // TODO: Does this actually work? - action_t action; - print("\nDEBUG: enabled.\n"); - debug_enable = true; - return action; - } else if (keycode >= 0x5000 && keycode < 0x6000) { - // Layer movement shortcuts - // See .h to see constraints/usage - int type = (keycode >> 0x8) & 0xF; - if (type == 0x1) { - // Layer set "GOTO" - int when = (keycode >> 0x4) & 0x3; - int layer = keycode & 0xF; - action_t action; - action.code = ACTION_LAYER_SET(layer, when); - return action; - } else if (type == 0x2) { - // Momentary layer - int layer = keycode & 0xFF; - action_t action; - action.code = ACTION_LAYER_MOMENTARY(layer); - return action; - } else if (type == 0x3) { - // Set default layer - int layer = keycode & 0xFF; - action_t action; - action.code = ACTION_DEFAULT_LAYER_SET(layer); - return action; - } else if (type == 0x4) { - // Set default layer - int layer = keycode & 0xFF; - action_t action; - action.code = ACTION_LAYER_TOGGLE(layer); - return action; - } -#ifdef MIDI_ENABLE - } else if (keycode >= 0x6000 && keycode < 0x7000) { - action_t action; - action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8); - return action; -#endif - } else if (keycode >= 0x7000 && keycode < 0x8000) { - action_t action; - action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); - return action; - } else if (keycode >= 0x8000 && keycode < 0x9000) { - action_t action; - action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); - return action; -#ifdef UNICODE_ENABLE - } else if (keycode >= 0x8000000) { - action_t action; - uint16_t unicode = keycode & ~(0x8000); - action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8); - return action; -#endif - } else { - - } - switch (keycode) { case KC_FN0 ... KC_FN31: return keymap_fn_to_action(keycode); -#ifdef BOOTMAGIC_ENABLE case KC_CAPSLOCK: case KC_LOCKING_CAPS: 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) return keycode_to_action(KC_BSLASH); } return keycode_to_action(KC_BSPACE); -#endif default: return keycode_to_action(keycode); } @@ -265,6 +155,142 @@ static action_t keycode_to_action(uint16_t keycode) case KC_TRNS: action.code = ACTION_TRANSPARENT; break; + case 0x0100 ... 0x1FFF: ; + // Has a modifier + // Split it up + action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key + break; + case 0x2000 ... 0x2FFF: + // Is a shortcut for function layer, pull last 12bits + // This means we have 4,096 FN macros at our disposal + return keymap_func_to_action(keycode & 0xFFF); + break; + case 0x3000 ... 0x3FFF: ; + // When the code starts with 3, it's an action macro. + action.code = ACTION_MACRO(keycode & 0xFF); + break; + #ifdef BACKLIGHT_ENABLE + case BL_0 ... BL_15: + action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F); + break; + case BL_DEC: + action.code = ACTION_BACKLIGHT_DECREASE(); + break; + case BL_INC: + action.code = ACTION_BACKLIGHT_INCREASE(); + break; + case BL_TOGG: + action.code = ACTION_BACKLIGHT_TOGGLE(); + break; + case BL_STEP: + action.code = ACTION_BACKLIGHT_STEP(); + break; + #endif + case RESET: ; // RESET is 0x5000, which is why this is here + clear_keyboard(); + #ifdef AUDIO_ENABLE + play_notes(&goodbye, 3, false); + #endif + _delay_ms(250); + #ifdef ATREUS_ASTAR + *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific + #endif + bootloader_jump(); + break; + case DEBUG: ; // DEBUG is 0x5001 + print("\nDEBUG: enabled.\n"); + debug_enable = true; + break; + case 0x5002 ... 0x50FF: + // MAGIC actions (BOOTMAGIC without the boot) + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + /* keymap config */ + keymap_config.raw = eeconfig_read_keymap(); + if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) { + keymap_config.swap_control_capslock = 1; + } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) { + keymap_config.capslock_to_control = 1; + } else if (keycode == MAGIC_SWAP_LALT_LGUI) { + keymap_config.swap_lalt_lgui = 1; + } else if (keycode == MAGIC_SWAP_RALT_RGUI) { + keymap_config.swap_ralt_rgui = 1; + } else if (keycode == MAGIC_NO_GUI) { + keymap_config.no_gui = 1; + } else if (keycode == MAGIC_SWAP_GRAVE_ESC) { + keymap_config.swap_grave_esc = 1; + } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) { + keymap_config.swap_backslash_backspace = 1; + } else if (keycode == MAGIC_HOST_NKRO) { + keymap_config.nkro = 1; + } else if (keycode == MAGIC_SWAP_ALT_GUI) { + keymap_config.swap_lalt_lgui = 1; + keymap_config.swap_ralt_rgui = 1; + } + /* UNs */ + else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) { + keymap_config.swap_control_capslock = 0; + } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) { + keymap_config.capslock_to_control = 0; + } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) { + keymap_config.swap_lalt_lgui = 0; + } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) { + keymap_config.swap_ralt_rgui = 0; + } else if (keycode == MAGIC_UNNO_GUI) { + keymap_config.no_gui = 0; + } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) { + keymap_config.swap_grave_esc = 0; + } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) { + keymap_config.swap_backslash_backspace = 0; + } else if (keycode == MAGIC_UNHOST_NKRO) { + keymap_config.nkro = 0; + } else if (keycode == MAGIC_UNSWAP_ALT_GUI) { + keymap_config.swap_lalt_lgui = 0; + keymap_config.swap_ralt_rgui = 0; + } + eeconfig_write_keymap(keymap_config.raw); + break; + case 0x5100 ... 0x5FFF: ; + // Layer movement shortcuts + // See .h to see constraints/usage + int type = (keycode >> 0x8) & 0xF; + if (type == 0x1) { + // Layer set "GOTO" + int when = (keycode >> 0x4) & 0x3; + int layer = keycode & 0xF; + action.code = ACTION_LAYER_SET(layer, when); + } else if (type == 0x2) { + // Momentary layer + int layer = keycode & 0xFF; + action.code = ACTION_LAYER_MOMENTARY(layer); + } else if (type == 0x3) { + // Set default layer + int layer = keycode & 0xFF; + action.code = ACTION_DEFAULT_LAYER_SET(layer); + } else if (type == 0x4) { + // Set default layer + int layer = keycode & 0xFF; + action.code = ACTION_LAYER_TOGGLE(layer); + } + break; + #ifdef MIDI_ENABLE + case 0x6000 ... 0x6FFF: + action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8); + break; + #endif + case 0x7000 ... 0x7FFF: + action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); + break; + case 0x8000 ... 0x8FFF: + action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); + break; + #ifdef UNICODE_ENABLE + case 0x8000000 ... 0x8FFFFFF: + uint16_t unicode = keycode & ~(0x8000); + action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8); + break; + #endif default: action.code = ACTION_NO; break; diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 7452a1ff3..ce87e4770 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -30,7 +30,6 @@ along with this program. If not, see . // #include "print.h" #include "debug.h" -#ifdef BOOTMAGIC_ENABLE /* NOTE: Not portable. Bit field order depends on implementation */ typedef union { uint16_t raw; @@ -45,8 +44,6 @@ typedef union { bool nkro:1; }; } keymap_config_t; -keymap_config_t keymap_config; -#endif /* translates key to keycode */ @@ -168,6 +165,30 @@ extern const uint16_t fn_actions[]; #define RESET 0x5000 #define DEBUG 0x5001 +// MAGIC keycodes +#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002 +#define MAGIC_UNSWAP_CONTROL_CAPSLOCK 0x5003 +#define MAGIC_CAPSLOCK_TO_CONTROL 0x5004 +#define MAGIC_UNCAPSLOCK_TO_CONTROL 0x5005 +#define MAGIC_SWAP_LALT_LGUI 0x5006 +#define MAGIC_UNSWAP_LALT_LGUI 0x5007 +#define MAGIC_SWAP_RALT_RGUI 0x5008 +#define MAGIC_UNSWAP_RALT_RGUI 0x5009 +#define MAGIC_NO_GUI 0x500a +#define MAGIC_UNNO_GUI 0x500b +#define MAGIC_SWAP_GRAVE_ESC 0x500c +#define MAGIC_UNSWAP_GRAVE_ESC 0x500d +#define MAGIC_SWAP_BACKSLASH_BACKSPACE 0x500e +#define MAGIC_UNSWAP_BACKSLASH_BACKSPACE 0x500f +#define MAGIC_HOST_NKRO 0x5010 +#define MAGIC_UNHOST_NKRO 0x5011 +#define MAGIC_SWAP_ALT_GUI 0x5012 +#define MAGIC_UNSWAP_ALT_GUI 0x5013 + +#define AG_SWAP MAGIC_SWAP_ALT_GUI +#define AG_NORM MAGIC_UNSWAP_ALT_GUI + + // GOTO layer - 16 layers max // when: // ON_PRESS = 1 @@ -213,4 +234,5 @@ void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); #define IS_LAYER_ON(layer) ((layer_state) & (1UL<<(layer))) #define IS_LAYER_OFF(layer) ((!layer_state) & (1UL<<(layer))) + #endif 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) SRC += $(COMMON_DIR)/bootmagic.c SRC += $(COMMON_DIR)/avr/eeconfig.c OPT_DEFS += -DBOOTMAGIC_ENABLE +else + SRC += $(COMMON_DIR)/magic.c + SRC += $(COMMON_DIR)/avr/eeconfig.c endif ifeq ($(strip $(MOUSEKEY_ENABLE)), yes) 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 . #include "command.h" #include "util.h" #include "sendchar.h" -#include "bootmagic.h" +#ifdef BOOTMAGIC_ENABLE + #include "bootmagic.h" +#else + #include "magic.h" +#endif #include "eeconfig.h" #include "backlight.h" #ifdef MOUSEKEY_ENABLE @@ -86,6 +90,8 @@ void keyboard_init(void) #ifdef BOOTMAGIC_ENABLE bootmagic(); +#else + magic(); #endif #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 . #include #include "action.h" - -#ifdef BOOTMAGIC_ENABLE /* NOTE: Not portable. Bit field order depends on implementation */ typedef union { uint8_t raw; @@ -39,7 +37,6 @@ typedef union { }; } keymap_config_t; keymap_config_t keymap_config; -#endif /* 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 @@ +#include +#include +#include +#include "matrix.h" +#include "bootloader.h" +#include "debug.h" +#include "keymap.h" +#include "host.h" +#include "action_layer.h" +#include "eeconfig.h" +#include "magic.h" + +keymap_config_t keymap_config; + +void magic(void) +{ + /* check signature */ + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + + /* debug enable */ + debug_config.raw = eeconfig_read_debug(); + + /* keymap config */ + keymap_config.raw = eeconfig_read_keymap(); + +#ifdef NKRO_ENABLE + keyboard_nkro = keymap_config.nkro; +#endif + + uint8_t default_layer = 0; + default_layer = eeconfig_read_default_layer(); + default_layer_set((uint32_t)default_layer); + +} \ 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 @@ +#ifndef MAGIC_H +#define MAGIC_H + +void magic(void); + +#endif From b8d2e66638409066661e7dd3c66473d583256ec5 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 19:30:15 -0400 Subject: [PATCH 11/11] readme clarity for rgbleds --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 613bdcf42..6e1ab9bc5 100644 --- a/README.md +++ b/README.md @@ -304,7 +304,7 @@ For this mod, you need an unused pin wiring to DI of WS2812 strip. After wiring Please note that the underglow is not compatible with audio output. So you cannot enable both of them at the same time. -Please add the following options into your config.h, and set them up according your hardware configuration. +Please add the following options into your config.h, and set them up according your hardware configuration. These settings are for the F4 by default: #define ws2812_PORTREG PORTF #define ws2812_DDRREG DDRF @@ -314,6 +314,12 @@ Please add the following options into your config.h, and set them up according y #define RGBLIGHT_SAT_STEP 17 #define RGBLIGHT_VAL_STEP 17 +You'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: + + #define ws2812_PORTREG PORTB + #define ws2812_DDRREG DDRB + #define ws2812_pin PB3 + The 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` ### WS2812 Wiring