backlight stuff

This commit is contained in:
Jack Humbert 2015-05-07 15:34:46 -04:00
parent 1e0ae2936b
commit cb3e499cc7
8 changed files with 67 additions and 17 deletions

View File

@ -53,7 +53,7 @@ TARGET_DIR = .
ifdef COMMON ifdef COMMON
SRC = keymap_common.c \ SRC = keymap_common.c \
matrix_handwire.c \ matrix.c \
led.c \ led.c \
backlight.c backlight.c
@ -66,7 +66,7 @@ endif
else else
SRC = extended_keymap_common.c \ SRC = extended_keymap_common.c \
matrix_handwire.c \ matrix.c \
led.c \ led.c \
backlight.c backlight.c

View File

@ -2,9 +2,11 @@
#include <avr/io.h> #include <avr/io.h>
#include "backlight.h" #include "backlight.h"
#define CHANNEL OCR1C
void backlight_init_ports() void backlight_init_ports(uint8_t level)
{ {
// Setup PB7 as output and output low. // Setup PB7 as output and output low.
DDRB |= (1<<7); DDRB |= (1<<7);
PORTB &= ~(1<<7); PORTB &= ~(1<<7);
@ -24,9 +26,8 @@ void backlight_init_ports()
TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010;
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
// Default to zero duty cycle. backlight_init();
OCR1C = 0x0000;
} }
void backlight_set(uint8_t level) 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. // Turn off PWM control on PB7, revert to output low.
TCCR1A &= ~(_BV(COM1C1)); TCCR1A &= ~(_BV(COM1C1));
// CHANNEL = level << OFFSET | 0x0FFF;
CHANNEL = ((1 << level) - 1);
} }
else else
{ {
// Turn on PWM control of PB7 // Turn on PWM control of PB7
TCCR1A |= _BV(COM1C1); TCCR1A |= _BV(COM1C1);
OCR1C = level << 12 | 0x0FFF; // CHANNEL = level << OFFSET | 0x0FFF;
CHANNEL = ((1 << level) - 1);
} }
} }

View File

@ -1,2 +0,0 @@
void backlight_init_ports(void);

View File

@ -23,9 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define VENDOR_ID 0xFEED #define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x6060 #define PRODUCT_ID 0x6060
#define DEVICE_VER 0x0001 #define DEVICE_VER 0x0001
#define MANUFACTURER jackhumbert #define MANUFACTURER Ortholinear Keyboards
#define PRODUCT Planck #define PRODUCT Planck
#define DESCRIPTION t.m.k. keyboard firmware for the Planck #define DESCRIPTION A compact ortholinear keyboard
/* key matrix size */ /* key matrix size */
#define MATRIX_ROWS 4 #define MATRIX_ROWS 4

View File

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "action.h" #include "action.h"
#include "action_macro.h" #include "action_macro.h"
#include "debug.h" #include "debug.h"
#include "backlight.h"
static action_t keycode_to_action(uint16_t keycode); 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_t action;
action.code = ACTION_MACRO(keycode & 0xFF); action.code = ACTION_MACRO(keycode & 0xFF);
return action; 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) { switch (keycode) {
case KC_FN0 ... KC_FN31: case KC_FN0 ... KC_FN31:

View File

@ -149,4 +149,29 @@ extern const uint16_t fn_actions[];
#define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) #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 #endif

View File

@ -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_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_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}, {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 */ [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}, {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},

View File

@ -62,8 +62,8 @@ void matrix_init(void)
MCUCR |= (1<<JTD); MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD); MCUCR |= (1<<JTD);
// TODO fix this dependency // Pass default level here
backlight_init_ports(); backlight_init_ports(15);
// initialize row and col // initialize row and col
unselect_rows(); unselect_rows();