diff options
author | Jack Humbert <jack.humb@gmail.com> | 2015-08-16 17:51:53 -0400 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2015-08-16 17:51:53 -0400 |
commit | b3f638f491601d4a849995fb4fa1181c9ff4341a (patch) | |
tree | 2faf8bda68233a28abba86429c948d6fd841ef03 /keyboard/planck | |
parent | 07d090db8ba5a3be15ec6c8ecf9e30815a48b0c0 (diff) |
ok
Diffstat (limited to 'keyboard/planck')
-rw-r--r-- | keyboard/planck/Makefile | 21 | ||||
-rw-r--r-- | keyboard/planck/backlight.c | 56 | ||||
-rw-r--r-- | keyboard/planck/config.h | 4 | ||||
-rw-r--r-- | keyboard/planck/extended_keymap_common.c | 4 | ||||
-rw-r--r-- | keyboard/planck/extended_keymap_common.h | 4 | ||||
-rw-r--r-- | keyboard/planck/extended_keymaps/extended_keymap_default.c | 24 | ||||
-rw-r--r-- | keyboard/planck/keymap_common.h | 2 | ||||
-rw-r--r-- | keyboard/planck/matrix.c | 2 | ||||
-rw-r--r-- | keyboard/planck/matrix_center.c | 71 | ||||
-rw-r--r-- | keyboard/planck/matrix_pcb.c | 5 |
10 files changed, 140 insertions, 53 deletions
diff --git a/keyboard/planck/Makefile b/keyboard/planck/Makefile index 964e6832ea..0da2a86c95 100644 --- a/keyboard/planck/Makefile +++ b/keyboard/planck/Makefile @@ -53,9 +53,9 @@ TARGET_DIR = . ifdef COMMON SRC = keymap_common.c \ - matrix_pcb.c \ led.c \ - backlight.c + backlight.c \ + beeps.c ifdef KEYMAP SRC := common_keymaps/keymap_$(KEYMAP).c $(SRC) @@ -63,12 +63,19 @@ else SRC := common_keymaps/keymap_jack.c $(SRC) endif +ifdef MATRIX + SRC := matrix_$(MATRIX).c $(SRC) +else + SRC := matrix_pcb.c $(SRC) +endif + else SRC = extended_keymap_common.c \ - matrix_pcb.c \ + analog.c \ led.c \ - backlight.c + backlight.c \ + beeps.c ifdef KEYMAP SRC := extended_keymaps/extended_keymap_$(KEYMAP).c $(SRC) @@ -76,6 +83,12 @@ else SRC := extended_keymaps/extended_keymap_default.c $(SRC) endif +ifdef MATRIX + SRC := matrix_$(MATRIX).c $(SRC) +else + SRC := matrix_pcb.c $(SRC) +endif + endif CONFIG_H = config.h diff --git a/keyboard/planck/backlight.c b/keyboard/planck/backlight.c index 06f103b4ac..90b1db874f 100644 --- a/keyboard/planck/backlight.c +++ b/keyboard/planck/backlight.c @@ -8,42 +8,42 @@ void backlight_init_ports() { // Setup PB7 as output and output low. - DDRB |= (1<<7); - PORTB &= ~(1<<7); + // DDRB |= (1<<7); + // PORTB &= ~(1<<7); - // Use full 16-bit resolution. - ICR1 = 0xFFFF; + // // 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 + // // 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 + // // 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; + // TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; + // TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; backlight_init(); } void backlight_set(uint8_t level) { - if ( level == 0 ) - { - // Turn off PWM control on PB7, revert to output low. - TCCR1A &= ~(_BV(COM1C1)); - // CHANNEL = level << OFFSET | 0x0FFF; - CHANNEL = ((1 << level) - 1); - } - else - { - // Turn on PWM control of PB7 - TCCR1A |= _BV(COM1C1); - // CHANNEL = level << OFFSET | 0x0FFF; - CHANNEL = ((1 << level) - 1); - } + // if ( level == 0 ) + // { + // // Turn off PWM control on PB7, revert to output low. + // TCCR1A &= ~(_BV(COM1C1)); + // // CHANNEL = level << OFFSET | 0x0FFF; + // CHANNEL = ((1 << level) - 1); + // } + // else + // { + // // Turn on PWM control of PB7 + // TCCR1A |= _BV(COM1C1); + // // CHANNEL = level << OFFSET | 0x0FFF; + // CHANNEL = ((1 << level) - 1); + // } }
\ No newline at end of file diff --git a/keyboard/planck/config.h b/keyboard/planck/config.h index 4e49a2b897..f621ac5ecc 100644 --- a/keyboard/planck/config.h +++ b/keyboard/planck/config.h @@ -59,10 +59,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* disable debug print */ -//#define NO_DEBUG +#define NO_DEBUG /* disable print */ -//#define NO_PRINT +#define NO_PRINT /* disable action features */ //#define NO_ACTION_LAYER diff --git a/keyboard/planck/extended_keymap_common.c b/keyboard/planck/extended_keymap_common.c index 841b249431..ade8508444 100644 --- a/keyboard/planck/extended_keymap_common.c +++ b/keyboard/planck/extended_keymap_common.c @@ -24,7 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "debug.h" #include "backlight.h" - static action_t keycode_to_action(uint16_t keycode); @@ -70,6 +69,9 @@ action_t action_for_key(uint8_t layer, keypos_t key) } else if (keycode == RESET) { bootloader_jump(); return; + } else if (keycode > RESET) { + // MIDI + return; } switch (keycode) { diff --git a/keyboard/planck/extended_keymap_common.h b/keyboard/planck/extended_keymap_common.h index 21d8978b7b..2dce4a2fac 100644 --- a/keyboard/planck/extended_keymap_common.h +++ b/keyboard/planck/extended_keymap_common.h @@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "action_macro.h" #include "report.h" #include "host.h" -#include "print.h" +// #include "print.h" #include "debug.h" #ifdef BOOTMAGIC_ENABLE @@ -174,4 +174,6 @@ extern const uint16_t fn_actions[]; #define RESET 0x5000 +#define MIDI(n) n | 0x6000 + #endif diff --git a/keyboard/planck/extended_keymaps/extended_keymap_default.c b/keyboard/planck/extended_keymaps/extended_keymap_default.c index c35b283675..8bf1a0c87b 100644 --- a/keyboard/planck/extended_keymaps/extended_keymap_default.c +++ b/keyboard/planck/extended_keymaps/extended_keymap_default.c @@ -5,7 +5,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}, - {BL_STEP, KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + {M(0), KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} // Space is repeated to accommadate for both spacebar wiring positions }, [1] = { /* Colemak */ @@ -16,19 +16,18 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }, [2] = { /* 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, FUNC(3), FUNC(4), LSFT(RSFT(KC_PAUSE)), KC_TRNS, KC_TRNS, KC_TRNS, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, - {KC_TRNS, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, KC_TRNS}, + {KC_TRNS, FUNC(3), FUNC(4), RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, + {KC_TRNS, KC_F11, KC_F12, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS}, {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FUNC(1), KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} }, [3] = { /* LOWER */ {S(KC_GRV), S(KC_1), S(KC_2), S(KC_3), S(KC_4), S(KC_5), S(KC_6), S(KC_7), S(KC_8), S(KC_9), S(KC_0), KC_BSPC}, - {KC_TRNS, FUNC(3), FUNC(4), LSFT(RSFT(KC_PAUSE)), KC_TRNS, KC_TRNS, KC_TRNS, S(KC_MINS), S(KC_EQL), S(KC_LBRC), S(KC_RBRC), S(KC_BSLS)}, + {KC_TRNS, FUNC(3), FUNC(4), RESET, KC_TRNS, KC_TRNS, KC_TRNS, S(KC_MINS), S(KC_EQL), S(KC_LBRC), S(KC_RBRC), S(KC_BSLS)}, {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_TRNS}, {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FUNC(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} } }; - const uint16_t PROGMEM fn_actions[] = { [1] = ACTION_LAYER_MOMENTARY(2), // to RAISE [2] = ACTION_LAYER_MOMENTARY(3), // to LOWER @@ -41,10 +40,15 @@ 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: - return MACRODOWN(T(CM_T), END); - break; - } + switch(id) { + case 0: + if (record->event.pressed) { + register_code(KC_RSFT); + ACTION_BACKLIGHT_STEP(); + } else { + unregister_code(KC_RSFT); + } + break; + } return MACRO_NONE; }; diff --git a/keyboard/planck/keymap_common.h b/keyboard/planck/keymap_common.h index 4a0bcfbb08..d46df92876 100644 --- a/keyboard/planck/keymap_common.h +++ b/keyboard/planck/keymap_common.h @@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "action_macro.h" #include "report.h" #include "host.h" -#include "print.h" +// #include "print.h" #include "debug.h" #include "keymap.h" diff --git a/keyboard/planck/matrix.c b/keyboard/planck/matrix.c index 2f2dbdb108..2ae69c3c80 100644 --- a/keyboard/planck/matrix.c +++ b/keyboard/planck/matrix.c @@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdbool.h> #include <avr/io.h> #include <util/delay.h> -#include "print.h" +// #include "print.h" #include "debug.h" #include "util.h" #include "matrix.h" diff --git a/keyboard/planck/matrix_center.c b/keyboard/planck/matrix_center.c index 8e34130d6f..2a603f334b 100644 --- a/keyboard/planck/matrix_center.c +++ b/keyboard/planck/matrix_center.c @@ -23,10 +23,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <avr/io.h> #include <util/delay.h> #include "action_layer.h" -#include "print.h" +// #include "print.h" #include "debug.h" #include "util.h" #include "matrix.h" +#include "analog.h" #ifndef DEBOUNCE @@ -40,9 +41,14 @@ static matrix_row_t matrix_debouncing[MATRIX_ROWS]; static matrix_row_t read_cols(void); static void init_cols(void); +static void init_encoder(void); +static void init_pot(void); static void unselect_rows(void); static void select_row(uint8_t row); - +int16_t analogRead(uint8_t pin); +uint8_t state; +int32_t position; +int16_t value; inline uint8_t matrix_rows(void) @@ -61,6 +67,8 @@ void matrix_init(void) // initialize row and col unselect_rows(); init_cols(); + init_encoder(); + init_pot(); // initialize matrix state: all keys off for (uint8_t i=0; i < MATRIX_ROWS; i++) { @@ -69,6 +77,50 @@ void matrix_init(void) } } +static void init_encoder(void) +{ + DDRC &= ~(1<<6 | 1<<7); + PORTC |= (1<<6 | 1<<7); + + uint8_t s = 0; + _delay_ms(1); + if (PINC&(1<<6)) s |= 1; + if (PINC&(1<<7)) s |= 2; + state = s; + position = 0; +} + +void read_encoder(void) +{ + uint8_t s = state & 3; + if (PINC&(1<<6)) s |= 4; + if (PINC&(1<<7)) s |= 8; + state = (s >> 2); + switch (s) { + case 1: case 7: case 8: case 14: + position++; + break; + case 2: case 4: case 11: case 13: + position--; + break; + case 3: case 12: + position += 2; + break; + case 6: case 9: + position -= 2; + break; + } +} + +#define HEX(n) (((n) < 10) ? ((n) + '0') : ((n) + 'A' - 10)) + +static void init_pot(void) +{ + // DDRD &= ~(1<<4); + // PORTD |= (1<<4); + // DIDR2 = (1<<0); +} + uint8_t matrix_scan(void) { for (uint8_t i = 0; i < MATRIX_ROWS; i++) { @@ -95,6 +147,21 @@ uint8_t matrix_scan(void) } } + read_encoder(); + if (position >= 2) { + register_code(KC_AUDIO_VOL_UP); + unregister_code(KC_AUDIO_VOL_UP); + position = 0; + } else if (position <= -2) { + register_code(KC_AUDIO_VOL_DOWN); + unregister_code(KC_AUDIO_VOL_DOWN); + position = 0; + } + + // uint16_t val = analogRead(11); + + // debug("analogRead: "); debug_hex(val); debug("\n"); + return 1; } diff --git a/keyboard/planck/matrix_pcb.c b/keyboard/planck/matrix_pcb.c index 7d46baf3de..48510cd833 100644 --- a/keyboard/planck/matrix_pcb.c +++ b/keyboard/planck/matrix_pcb.c @@ -23,13 +23,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdbool.h> #include <avr/io.h> #include <util/delay.h> -#include "print.h" +// #include "print.h" #include "debug.h" #include "util.h" #include "matrix.h" #include "backlight.h" // TODO fix this dependency - #ifndef DEBOUNCE # define DEBOUNCE 10 #endif @@ -67,7 +66,7 @@ void matrix_init(void) // Turn status LED on DDRE |= (1<<6); PORTE |= (1<<6); - + // initialize row and col unselect_rows(); init_cols(); |