diff options
author | Stephan Bösebeck <sb@caluga.de> | 2016-05-11 22:05:19 +0200 |
---|---|---|
committer | Stephan Bösebeck <sb@caluga.de> | 2016-05-11 22:05:19 +0200 |
commit | d09d2da1c25b377b0f68ea83706903344c240ae1 (patch) | |
tree | dc3e88ef91206ccc251af32543a01ec2e7a7c208 | |
parent | 2e02886a1ec6d92c07f1edd13d4e68af1e861991 (diff) | |
parent | 5845eb05b53ea685c9622abf011870ab4ce84f39 (diff) |
Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
51 files changed, 4081 insertions, 2722 deletions
diff --git a/BUILD_GUIDE.md b/BUILD_GUIDE.md index f7a57d2fc9..fd8b6202ff 100644 --- a/BUILD_GUIDE.md +++ b/BUILD_GUIDE.md @@ -47,8 +47,8 @@ If you have any problems building the firmware, you can try using a tool called Note: Some keyboard folders have non-standard organizations, and may not even support specifying alternate keymaps. Until these get reorganized, you will need to edit their default keymaps directly. -1. Running the `make` command from your keyboard's folder will generate a .hex file based on the default keymap. All keymaps for a particular keyboard live in the `keymaps` folder in that keyboard's folder. To create your own keymap, copy `keymaps/default/keymap.c` to the `keymaps` folder, and rename it with your name, for example jack.c. Or, if you don't care about the ability to share your keymap with the community via GitHub, you can just modify the default keymap itself. Details on how to program keymap files can be found in other guides. -2. To build a keymap other than the default, type `KEYMAP=<name>` after `make`. So if I've named my keymap jack.c, the full command would be `make KEYMAP=jack`. +1. Running the `make` command from your keyboard's folder will generate a .hex file based on the default keymap. All keymaps for a particular keyboard live in the `keymaps` folder in that keyboard's folder. To create your own keymap, duplicate the folder `keymaps/default`, and rename it with your name, for example `jack`. Or, if you don't care about the ability to share your keymap with the community via GitHub, you can just modify the default keymap itself. Details on how to program keymap files can be found in other guides. +2. To build a keymap other than the default, type `KEYMAP=<name>` after `make`. So if I've named my keymap `jack`, the full command would be `make KEYMAP=jack`. 3. How you deploy the firmware will depend on whether you are using a PCB or a Teensy. In both cases, you'll need to put the keyboard in bootloader mode, either by pressing a button on the PCB/Teensy or pressing the key with the `RESET` keycode. Then, if you're using a PCB, just run `make KEYMAP=<name> dfu` to both build and deploy the firmware. If you're using a Teensy, you'll probably need to take the <keyboardname>.hex file that make produces in the keyboard's folder, and deploy it using the [Teensy Loader.](https://www.pjrc.com/teensy/loader.html) ## Helpful Tips @@ -33,6 +33,10 @@ If your keymap directory has a file called `makefile.mk` (note the lowercase fil 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`. +### Customizing config.h on a per-keymap basis + +If you use the ErgoDox EZ, you can make a `config_user.h` file in your keymap directory and use it to override any `config.h` settings you don't like. Anything you set there will take precedence over the global `config.h` for the ErgoDox EZ. To see an example of this, check out `keymaps/erez_experimental`. + ## Quick aliases to common actions Your keymap can include shortcuts to common operations (called "function actions" in tmk). @@ -41,10 +45,13 @@ Your keymap can include shortcuts to common operations (called "function actions `MO(layer)` - momentary switch to *layer*. As soon as you let go of the key, the layer is deactivated and you pop back out to the previous layer. When you apply this to a key, that same key must be set as `KC_TRNS` on the destination layer. Otherwise, you won't make it back to the original layer when you release the key (and you'll get a keycode sent). You can only switch to layers *above* your current layer. If you're on layer 0 and you use `MO(1)`, that will switch to layer 1 just fine. But if you include `MO(3)` on layer 5, that won't do anything for you -- because layer 3 is lower than layer 5 on the stack. +`OSL(layer)` - momentary switch to *layer*, as a one-shot operation. So if you have a key that's defined as `OSL(1)`, and you tap that key, then only the very next keystroke would come from layer 1. You would drop back to layer zero immediately after that one keystroke. That's handy if you have a layer full of custom shortcuts -- for example, a dedicated key for closing a window. So you tap your one-shot layer mod, then tap that magic 'close window' key, and keep typing like a boss. Layer 1 would remain active as long as you hold that key down, too (so you can use it like a momentary toggle-layer key with extra powers). + `LT(layer, kc)` - momentary switch to *layer* when held, and *kc* when tapped. Like `MO()`, this only works upwards in the layer stack (`layer` must be higher than the current layer). `TG(layer)` - toggles a layer on or off. As with `MO()`, you should set this key as `KC_TRNS` in the destination layer so that tapping it again actually toggles back to the original layer. Only works upwards in the layer stack. + ### Fun with modifier keys * `LSFT(kc)` - applies left Shift to *kc* (keycode) - `S(kc)` is an alias @@ -80,17 +87,24 @@ The following shortcuts automatically add `LSFT()` to keycodes to get commonly u KC_PLUS + KC_LCBR { KC_RCBR } + KC_LABK < + KC_RABK > KC_PIPE | KC_COLN : +`OSM(mod)` - this is a "one shot" modifier. So let's say you have your left Shift key defined as `OSM(MOD_LSFT)`. Tap it, let go, and Shift is "on" -- but only for the next character you'll type. So to write "The", you don't need to hold down Shift -- you tap it, tap t, and move on with life. And if you hold down the left Shift key, it just works as a left Shift key, as you would expect (so you could type THE). There's also a magical, secret way to "lock" a modifier by tapping it multiple times. If you want to learn more about that, open an issue. :) + `MT(mod, kc)` - is *mod* (modifier key - MOD_LCTL, MOD_LSFT) when held, and *kc* when tapped. In other words, you can have a key that sends Esc (or the letter O or whatever) when you tap it, but works as a Control key or a Shift key when you hold it down. -These are the values you can use for the `mod` in `MT()` (right-hand modifiers are not available): +These are the values you can use for the `mod` in `MT()` and `OSM()` (right-hand modifiers are not available for `MT()`): * MOD_LCTL * MOD_LSFT * MOD_LALT * MOD_LGUI + * MOD_HYPR + * MOD_MEH + These can also be combined like `MOD_LCTL | MOD_LSFT` e.g. `MT(MOD_LCTL | MOD_LSFT, KC_ESC)` which would activate Control and Shift when held, and send Escape when tapped. @@ -363,6 +377,55 @@ You can currently send 4 hex digits with your OS-specific modifier key (RALT for Enable the backlight from the Makefile. +## Driving a speaker - audio support + +Your keyboard can make sounds! If you've got a Planck, Preonic, or basically any keyboard that allows access to the C6 port, you can hook up a simple speaker and have it beep. You can use those beeps to indicate layer transitions, modifiers, special keys, or just to play some funky 8bit tunes. + +The audio code lives in [quantum/audio/audio.h](/quantum/audio/audio.h) and in the other files in the audio directory. It's enabled by default on the Planck [stock keymap](/keyboard/planck/keymaps/default/keymap.c). Here are the important bits: + +``` +#include "audio.h" +``` + +Then, lower down the file: + +``` +float tone_startup[][2] = { + ED_NOTE(_E7 ), + E__NOTE(_CS7), + E__NOTE(_E6 ), + E__NOTE(_A6 ), + M__NOTE(_CS7, 20) +}; +``` + +This is how you write a song. Each of these lines is a note, so we have a little ditty composed of five notes here. + +Then, we have this chunk: + +``` +float tone_qwerty[][2] = SONG(QWERTY_SOUND); +float tone_dvorak[][2] = SONG(DVORAK_SOUND); +float tone_colemak[][2] = SONG(COLEMAK_SOUND); +float tone_plover[][2] = SONG(PLOVER_SOUND); +float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND); + +float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); +float goodbye[][2] = SONG(GOODBYE_SOUND); +``` + +Wherein we bind predefined songs (from [audio/song_list.h](/audio/song_list.h)) into named variables. This is one optimization that helps save on memory: These songs only take up memory when you reference them in your keymap, because they're essentially all preprocessor directives. + +So now you have something called `tone_plover` for example. How do you make it play the Plover tune, then? If you look further down the keymap, you'll see this: + +``` +PLAY_NOTE_ARRAY(tone_plover, false, 0); // Signature is: Song name, repeat, rest style +``` + +This is inside one of the macros. So when that macro executes, your keyboard plays that particular chime. + +"Rest style" in the method signature above (the last parameter) specifies if there's a rest (a moment of silence) between the notes. + ## MIDI functionalty This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile. diff --git a/keyboard/atomic/atomic.c b/keyboard/atomic/atomic.c index 3996497161..b4b2614572 100644 --- a/keyboard/atomic/atomic.c +++ b/keyboard/atomic/atomic.c @@ -2,27 +2,27 @@ __attribute__ ((weak)) void matrix_init_user(void) { - // leave this function blank - it can be defined in a keymap file + // leave this function blank - it can be defined in a keymap file }; __attribute__ ((weak)) void matrix_scan_user(void) { - // leave this function blank - it can be defined in a keymap file + // leave this function blank - it can be defined in a keymap file } __attribute__ ((weak)) void process_action_user(keyrecord_t *record) { - // leave this function blank - it can be defined in a keymap file + // leave this function blank - it can be defined in a keymap file } __attribute__ ((weak)) void led_set_user(uint8_t usb_led) { - // leave this function blank - it can be defined in a keymap file + // leave this function blank - it can be defined in a keymap file } void matrix_init_kb(void) { - // put your keyboard start-up code here - // runs once when the firmware starts up + // put your keyboard start-up code here + // runs once when the firmware starts up MCUCR |= (1<<JTD); MCUCR |= (1<<JTD); @@ -35,31 +35,39 @@ void matrix_init_kb(void) { DDRE |= (1<<6); PORTE |= (1<<6); - matrix_init_user(); + matrix_init_user(); } void matrix_scan_kb(void) { - // put your looping keyboard code here - // runs every cycle (a lot) + // put your looping keyboard code here + // runs every cycle (a lot) - matrix_scan_user(); + matrix_scan_user(); } void process_action_kb(keyrecord_t *record) { - // put your per-action keyboard code here - // runs for every action, just before processing by the firmware + // put your per-action keyboard code here + // runs for every action, just before processing by the firmware - process_action_user(record); + process_action_user(record); } void led_set_kb(uint8_t usb_led) { - // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here + // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here - led_set_user(usb_led); + led_set_user(usb_led); } #ifdef BACKLIGHT_ENABLE #define CHANNEL OCR1C +#define BREATHING_NO_HALT 0 +#define BREATHING_HALT_OFF 1 +#define BREATHING_HALT_ON 2 + +static uint8_t breath_intensity; +static uint8_t breath_speed; +static uint16_t breathing_index; +static uint8_t breathing_halt; void backlight_init_ports() { @@ -67,54 +75,250 @@ void backlight_init_ports() // Setup PB7 as output and output low. DDRB |= (1<<7); PORTB &= ~(1<<7); - - // Use full 16-bit resolution. + + // Use full 16-bit resolution. ICR1 = 0xFFFF; // I could write a wall of text here to explain... but TL;DW // Go read the ATmega32u4 datasheet. // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on - + // Pin PB7 = OCR1C (Timer 1, Channel C) // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 // (i.e. start high, go low when counter matches.) // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 - + TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; backlight_init(); + breathing_defaults(); } void backlight_set(uint8_t level) { + // Prevent backlight blink on lowest level + PORTB &= ~(_BV(PORTB7)); + if ( level == 0 ) { // Turn off PWM control on PB7, revert to output low. TCCR1A &= ~(_BV(COM1C1)); + + // Set the brightness to 0 CHANNEL = 0x0; - // Prevent backlight blink on lowest level - PORTB &= ~(_BV(PORTB7)); } - else if ( level == BACKLIGHT_LEVELS ) + else if ( level >= BACKLIGHT_LEVELS ) { - // Prevent backlight blink on lowest level - PORTB &= ~(_BV(PORTB7)); // Turn on PWM control of PB7 TCCR1A |= _BV(COM1C1); - // Set the brightness + + // Set the brightness to max CHANNEL = 0xFFFF; } - else + else { - // Prevent backlight blink on lowest level - PORTB &= ~(_BV(PORTB7)); // Turn on PWM control of PB7 TCCR1A |= _BV(COM1C1); + // Set the brightness CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); } + breathing_intensity_default(); +} + + +void breathing_enable(void) +{ + if (get_backlight_level() == 0) + { + breathing_index = 0; + } + else + { + // Set breathing_index to be at the midpoint (brightest point) + breathing_index = 0x20 << breath_speed; + } + + breathing_halt = BREATHING_NO_HALT; + + // Enable breathing interrupt + TIMSK1 |= _BV(OCIE1A); +} + +void breathing_pulse(void) +{ + if (get_backlight_level() == 0) + { + breathing_index = 0; + } + else + { + // Set breathing_index to be at the midpoint + 1 (brightest point) + breathing_index = 0x21 << breath_speed; + } + + breathing_halt = BREATHING_HALT_ON; + + // Enable breathing interrupt + TIMSK1 |= _BV(OCIE1A); +} + +void breathing_disable(void) +{ + // Disable breathing interrupt + TIMSK1 &= ~_BV(OCIE1A); + backlight_set(get_backlight_level()); +} + +void breathing_self_disable(void) +{ + if (get_backlight_level() == 0) + { + breathing_halt = BREATHING_HALT_OFF; + } + else + { + breathing_halt = BREATHING_HALT_ON; + } + + //backlight_set(get_backlight_level()); +} + +void breathing_toggle(void) +{ + if (!is_breathing()) + { + if (get_backlight_level() == 0) + { + breathing_index = 0; + } + else + { + // Set breathing_index to be at the midpoint + 1 (brightest point) + breathing_index = 0x21 << breath_speed; + } + + breathing_halt = BREATHING_NO_HALT; + } + + // Toggle breathing interrupt + TIMSK1 ^= _BV(OCIE1A); + + // Restore backlight level + if (!is_breathing()) + { + backlight_set(get_backlight_level()); + } +} + +bool is_breathing(void) +{ + return (TIMSK1 && _BV(OCIE1A)); +} + +void breathing_intensity_default(void) +{ + //breath_intensity = (uint8_t)((uint16_t)100 * (uint16_t)get_backlight_level() / (uint16_t)BACKLIGHT_LEVELS); + breath_intensity = ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2)); +} + +void breathing_intensity_set(uint8_t value) +{ + breath_intensity = value; +} + +void breathing_speed_default(void) +{ + breath_speed = 4; +} + +void breathing_speed_set(uint8_t value) +{ + bool is_breathing_now = is_breathing(); + uint8_t old_breath_speed = breath_speed; + + if (is_breathing_now) + { + // Disable breathing interrupt + TIMSK1 &= ~_BV(OCIE1A); + } + + breath_speed = value; + + if (is_breathing_now) + { + // Adjust index to account for new speed + breathing_index = (( (uint8_t)( (breathing_index) >> old_breath_speed ) ) & 0x3F) << breath_speed; + + // Enable breathing interrupt + TIMSK1 |= _BV(OCIE1A); + } + +} + +void breathing_speed_inc(uint8_t value) +{ + if ((uint16_t)(breath_speed - value) > 10 ) + { + breathing_speed_set(0); + } + else + { + breathing_speed_set(breath_speed - value); + } +} + +void breathing_speed_dec(uint8_t value) +{ + if ((uint16_t)(breath_speed + value) > 10 ) + { + breathing_speed_set(10); + } + else + { + breathing_speed_set(breath_speed + value); + } +} + +void breathing_defaults(void) +{ + breathing_intensity_default(); + breathing_speed_default(); + breathing_halt = BREATHING_NO_HALT; +} + +/* Breathing Sleep LED brighness(PWM On period) table + * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle + * + * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 + * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i } + */ +static const uint8_t breathing_table[64] PROGMEM = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, + 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, +255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, + 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +ISR(TIMER1_COMPA_vect) +{ + // CHANNEL = (pgm_read_byte(&breathing_table[ ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F ] )) * breath_intensity; + + + uint8_t local_index = ( (uint8_t)( (breathing_index++) >> breath_speed ) ) & 0x3F; + + if (((breathing_halt == BREATHING_HALT_ON) && (local_index == 0x20)) || ((breathing_halt == BREATHING_HALT_OFF) && (local_index == 0x3F))) + { + // Disable breathing interrupt + TIMSK1 &= ~_BV(OCIE1A); + } + + CHANNEL = (uint16_t)(((uint16_t)pgm_read_byte(&breathing_table[local_index]) * 257)) >> breath_intensity; + } + + #endif
\ No newline at end of file diff --git a/keyboard/atomic/atomic.h b/keyboard/atomic/atomic.h index 0c7aeb1cc8..845a9043e2 100644 --- a/keyboard/atomic/atomic.h +++ b/keyboard/atomic/atomic.h @@ -33,4 +33,20 @@ void process_action_user(keyrecord_t *record); void led_set_user(uint8_t usb_led); void backlight_init_ports(void); +void breathing_enable(void); +void breathing_pulse(void); +void breathing_disable(void); +void breathing_self_disable(void); +void breathing_toggle(void); +bool is_breathing(void); + + +void breathing_defaults(void); +void breathing_intensity_default(void); +void breathing_speed_default(void); +void breathing_speed_set(uint8_t value); +void breathing_speed_inc(uint8_t value); +void breathing_speed_dec(uint8_t value); + + #endif
\ No newline at end of file diff --git a/keyboard/atomic/keymaps/pvc/config.h b/keyboard/atomic/keymaps/pvc/config.h index 034bc5dc5c..5e956286b5 100644 --- a/keyboard/atomic/keymaps/pvc/config.h +++ b/keyboard/atomic/keymaps/pvc/config.h @@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /* USB Device descriptor parameter */ #define VENDOR_ID 0xFEED -#define PRODUCT_ID 0x6060 +#define PRODUCT_ID 0x0419 #define DEVICE_VER 0x0001 #define MANUFACTURER Ortholinear Keyboards #define PRODUCT The Atomic Keyboard @@ -162,5 +162,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. //#define VIBRATO_ENABLE //#define VIBRATO_STRENGTH_ENABLE - #endif diff --git a/keyboard/atomic/keymaps/pvc/keymap.c b/keyboard/atomic/keymaps/pvc/keymap.c index 3d604a868e..ff7384268e 100644 --- a/keyboard/atomic/keymaps/pvc/keymap.c +++ b/keyboard/atomic/keymaps/pvc/keymap.c @@ -8,41 +8,44 @@ #include "song_list.h" #endif -#define LAYER_QWERTY 0 -#define LAYER_COLEMAK 1 -#define LAYER_DVORAK 2 -#define LAYER_RAISE 3 -#define LAYER_LOWER 4 -#define LAYER_FUNCTION 5 -#define LAYER_MOUSE 6 -#define LAYER_MUSIC 7 -#define LAYER_ADJUST 8 - -#define MACRO_QWERTY 0 -#define MACRO_COLEMAK 1 -#define MACRO_DVORAK 2 -#define MACRO_RAISE 3 -#define MACRO_LOWER 4 -#define MACRO_FUNCTION 5 -#define MACRO_MOUSE 6 -#define MACRO_TIMBRE_1 7 -#define MACRO_TIMBRE_2 8 -#define MACRO_TIMBRE_3 9 -#define MACRO_TIMBRE_4 10 -#define MACRO_TEMPO_U 11 -#define MACRO_TEMPO_D 12 -#define MACRO_TONE_DEFAULT 13 -#define MACRO_MUSIC_ON 14 -#define MACRO_MUSIC_OFF 15 -#define MACRO_AUDIO_ON 16 -#define MACRO_AUDIO_OFF 17 -#define MACRO_INC_VOICE 18 -#define MACRO_DEC_VOICE 19 +#define LAYER_QWERTY 0 +#define LAYER_COLEMAK 1 +#define LAYER_DVORAK 2 +#define LAYER_UPPER 3 +#define LAYER_LOWER 4 +#define LAYER_FUNCTION 5 +#define LAYER_MOUSE 6 +#define LAYER_MUSIC 7 +#define LAYER_ADJUST 8 + +#define MACRO_QWERTY 0 +#define MACRO_COLEMAK 1 +#define MACRO_DVORAK 2 +#define MACRO_UPPER 3 +#define MACRO_LOWER 4 +#define MACRO_FUNCTION 5 +#define MACRO_MOUSE 6 +#define MACRO_TIMBRE_1 7 +#define MACRO_TIMBRE_2 8 +#define MACRO_TIMBRE_3 9 +#define MACRO_TIMBRE_4 10 +#define MACRO_TEMPO_U 11 +#define MACRO_TEMPO_D 12 +#define MACRO_TONE_DEFAULT 13 +#define MACRO_MUSIC_TOGGLE 14 +#define MACRO_AUDIO_TOGGLE 16 +#define MACRO_INC_VOICE 18 +#define MACRO_DEC_VOICE 19 +#define MACRO_BACKLIGHT 20 +#define MACRO_BREATH_TOGGLE 21 +#define MACRO_BREATH_SPEED_INC 23 +#define MACRO_BREATH_SPEED_DEC 24 +#define MACRO_BREATH_DEFAULT 25 #define M_QWRTY M(MACRO_QWERTY) #define M_COLMK M(MACRO_COLEMAK) #define M_DVORK M(MACRO_DVORAK) -#define M_RAISE M(MACRO_RAISE) +#define M_UPPER M(MACRO_UPPER) #define M_LOWER M(MACRO_LOWER) #define M_FUNCT M(MACRO_FUNCTION) #define M_MOUSE M(MACRO_MOUSE) @@ -53,12 +56,15 @@ #define TMPO_UP M(MACRO_TEMPO_U) #define TMPO_DN M(MACRO_TEMPO_D) |