From cb3e499cc7dbff2607bc43cb05fc8c29a2eb9d30 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 7 May 2015 15:34:46 -0400 Subject: [PATCH] backlight stuff --- keyboard/planck/Makefile | 4 +-- keyboard/planck/backlight.c | 17 +++++++----- keyboard/planck/backlight.h | 2 -- keyboard/planck/config.h | 4 +-- keyboard/planck/extended_keymap_common.c | 26 ++++++++++++++++++- keyboard/planck/extended_keymap_common.h | 25 ++++++++++++++++++ .../extended_keymaps/extended_keymap_jack.c | 2 +- keyboard/planck/matrix.c | 4 +-- 8 files changed, 67 insertions(+), 17 deletions(-) delete mode 100644 keyboard/planck/backlight.h diff --git a/keyboard/planck/Makefile b/keyboard/planck/Makefile index e021e9e9..773783ad 100644 --- a/keyboard/planck/Makefile +++ b/keyboard/planck/Makefile @@ -53,7 +53,7 @@ TARGET_DIR = . ifdef COMMON SRC = keymap_common.c \ - matrix_handwire.c \ + matrix.c \ led.c \ backlight.c @@ -66,7 +66,7 @@ endif else SRC = extended_keymap_common.c \ - matrix_handwire.c \ + matrix.c \ led.c \ backlight.c diff --git a/keyboard/planck/backlight.c b/keyboard/planck/backlight.c index ee7e31ee..a560687e 100644 --- a/keyboard/planck/backlight.c +++ b/keyboard/planck/backlight.c @@ -2,9 +2,11 @@ #include #include "backlight.h" +#define CHANNEL OCR1C -void backlight_init_ports() +void backlight_init_ports(uint8_t level) { + // Setup PB7 as output and output low. DDRB |= (1<<7); PORTB &= ~(1<<7); @@ -24,9 +26,8 @@ void backlight_init_ports() TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; - - // Default to zero duty cycle. - OCR1C = 0x0000; + + backlight_init(); } void backlight_set(uint8_t level) @@ -35,12 +36,14 @@ void backlight_set(uint8_t level) { // 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); - OCR1C = level << 12 | 0x0FFF; + // CHANNEL = level << OFFSET | 0x0FFF; + CHANNEL = ((1 << level) - 1); } -} - +} \ No newline at end of file diff --git a/keyboard/planck/backlight.h b/keyboard/planck/backlight.h deleted file mode 100644 index 0fe1f4a7..00000000 --- a/keyboard/planck/backlight.h +++ /dev/null @@ -1,2 +0,0 @@ - -void backlight_init_ports(void); diff --git a/keyboard/planck/config.h b/keyboard/planck/config.h index 0b0c1524..4e49a2b8 100644 --- a/keyboard/planck/config.h +++ b/keyboard/planck/config.h @@ -23,9 +23,9 @@ along with this program. If not, see . #define VENDOR_ID 0xFEED #define PRODUCT_ID 0x6060 #define DEVICE_VER 0x0001 -#define MANUFACTURER jackhumbert +#define MANUFACTURER Ortholinear Keyboards #define PRODUCT Planck -#define DESCRIPTION t.m.k. keyboard firmware for the Planck +#define DESCRIPTION A compact ortholinear keyboard /* key matrix size */ #define MATRIX_ROWS 4 diff --git a/keyboard/planck/extended_keymap_common.c b/keyboard/planck/extended_keymap_common.c index f8fc3209..841b2494 100644 --- a/keyboard/planck/extended_keymap_common.c +++ b/keyboard/planck/extended_keymap_common.c @@ -22,6 +22,7 @@ along with this program. If not, see . #include "action.h" #include "action_macro.h" #include "debug.h" +#include "backlight.h" static action_t keycode_to_action(uint16_t keycode); @@ -46,7 +47,30 @@ action_t action_for_key(uint8_t layer, keypos_t key) action_t action; action.code = ACTION_MACRO(keycode & 0xFF); return action; - } + } 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; + } else if (keycode == RESET) { + bootloader_jump(); + return; + } switch (keycode) { case KC_FN0 ... KC_FN31: diff --git a/keyboard/planck/extended_keymap_common.h b/keyboard/planck/extended_keymap_common.h index 66712459..21d8978b 100644 --- a/keyboard/planck/extended_keymap_common.h +++ b/keyboard/planck/extended_keymap_common.h @@ -149,4 +149,29 @@ extern const uint16_t fn_actions[]; #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) +#define BL_ON 0x4009 +#define BL_OFF 0x4000 +#define BL_0 0x4000 +#define BL_1 0x4001 +#define BL_2 0x4002 +#define BL_3 0x4003 +#define BL_4 0x4004 +#define BL_5 0x4005 +#define BL_6 0x4006 +#define BL_7 0x4007 +#define BL_8 0x4008 +#define BL_9 0x4009 +#define BL_10 0x400A +#define BL_11 0x400B +#define BL_12 0x400C +#define BL_13 0x400D +#define BL_14 0x400E +#define BL_15 0x400F +#define BL_DEC 0x4010 +#define BL_INC 0x4011 +#define BL_TOGG 0x4012 +#define BL_STEP 0x4013 + +#define RESET 0x5000 + #endif diff --git a/keyboard/planck/extended_keymaps/extended_keymap_jack.c b/keyboard/planck/extended_keymaps/extended_keymap_jack.c index 416ae834..de966ca9 100644 --- a/keyboard/planck/extended_keymaps/extended_keymap_jack.c +++ b/keyboard/planck/extended_keymaps/extended_keymap_jack.c @@ -5,7 +5,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { {KC_TAB, CM_Q, CM_W, CM_F, CM_P, CM_G, CM_J, CM_L, CM_U, CM_Y, CM_SCLN, KC_BSPC}, {KC_ESC, CM_A, CM_R, CM_S, CM_T, CM_D, CM_H, CM_N, CM_E, CM_I, CM_O, KC_QUOT}, {KC_LSFT, CM_Z, CM_X, CM_C, CM_V, CM_B, CM_K, CM_M, CM_COMM, CM_DOT, CM_SLSH, KC_ENT}, - {M(0), KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_NO, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + {BL_STEP, KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_NO, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} }, [1] = { /* Jack hard-coded 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}, diff --git a/keyboard/planck/matrix.c b/keyboard/planck/matrix.c index e3926cae..156e081d 100644 --- a/keyboard/planck/matrix.c +++ b/keyboard/planck/matrix.c @@ -62,8 +62,8 @@ void matrix_init(void) MCUCR |= (1<