Browse Source

Merge branch 'master' into led_matrix

led_matrix
Kai Ryu 10 years ago
parent
commit
9a6b1cc49d

+ 1
- 0
common/bootmagic.c View File

@@ -30,6 +30,7 @@ void bootmagic(void)

/* eeconfig clear */
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
eeconfig_disable();
eeconfig_init();
}


+ 7
- 0
common/eeconfig.c View File

@@ -2,6 +2,7 @@
#include <stdbool.h>
#include <avr/eeprom.h>
#include "eeconfig.h"
#include "keymap_ex.h"

void eeconfig_init(void)
{
@@ -13,6 +14,9 @@ void eeconfig_init(void)
#ifdef BACKLIGHT_ENABLE
eeprom_write_byte(EECONFIG_BACKLIGHT, 0);
#endif
#ifdef KEYMAP_EX_ENABLE
keymap_ex_init();
#endif
}

void eeconfig_enable(void)
@@ -22,6 +26,9 @@ void eeconfig_enable(void)

void eeconfig_disable(void)
{
#ifdef KEYMAP_EX_ENABLE
keymap_ex_disable();
#endif
eeprom_write_word(EECONFIG_MAGIC, 0xFFFF);
}


+ 7
- 3
common/keyboard.c View File

@@ -68,7 +68,9 @@ void keyboard_init(void)
#endif

#ifdef PS2_MOUSE_ENABLE
ps2_mouse_init();
if (ps2_enabled()) {
ps2_mouse_init();
}
#endif

#ifdef BOOTMAGIC_ENABLE
@@ -80,7 +82,7 @@ void keyboard_init(void)
#endif

#ifdef KEYMAP_EX_ENABLE
keymap_init();
keymap_ex_init();
#endif
}

@@ -133,7 +135,9 @@ MATRIX_LOOP_END:
#endif

#ifdef PS2_MOUSE_ENABLE
ps2_mouse_task();
if (ps2_enabled()) {
ps2_mouse_task();
}
#endif

// update LED

+ 5
- 1
common/keymap_ex.c View File

@@ -23,12 +23,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifdef KEYMAP_EX_ENABLE

void keymap_init(void) {
void keymap_ex_init(void) {
if (!check_keymap_in_eeprom()) {
write_keymap_to_eeprom();
}
}

void keymap_ex_disable(void) {
eeprom_write_word((void*)EECONFIG_KEYMAP_CHECKSUM, eeprom_read_word((void*)EECONFIG_KEYMAP_CHECKSUM) + 1);
}

bool check_keymap_in_eeprom(void) {
uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum);
uint16_t checksum = EECONFIG_MAGIC_NUMBER;

+ 2
- 1
common/keymap_ex.h View File

@@ -47,7 +47,8 @@ typedef struct {
#define FN_ACTION_OFFSET(index) (sizeof(uint16_t) * index)
#define KEY_OFFSET(layer, row, col) (sizeof(uint8_t) * (layer * MATRIX_ROWS * MATRIX_COLS + row * MATRIX_COLS + col))

void keymap_init(void);
void keymap_ex_init(void);
void keymap_ex_disable(void);
bool check_keymap_in_eeprom(void);
void write_keymap_to_eeprom(void);
uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col);

+ 2
- 1
keyboard/gh60/Makefile View File

@@ -134,12 +134,12 @@ COMMAND_ENABLE = yes # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
#PS2_USE_BUSYWAIT = yes
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
KEYMAP_EX_ENABLE = yes # External keymap in eeprom
KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
LED_MATRIX_ENABLE = yes


# Optimize size but this may cause error "relocation truncated to fit"
#EXTRALDFLAGS = -Wl,--relax

@@ -148,5 +148,6 @@ VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)

include $(TOP_DIR)/protocol/lufa.mk
include $(TOP_DIR)/protocol.mk
include $(TOP_DIR)/common.mk
include $(TOP_DIR)/rules.mk

+ 31
- 2
keyboard/gh60/backlight.c View File

@@ -72,14 +72,43 @@ void backlight_set(uint8_t level)
}
}
#else
static const uint8_t backlight_table[] PROGMEM = {
0, 16, 128, 255
};

void backlight_set(uint8_t level)
{
if (level > 0) {
DDRF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
PORTF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
DDRF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
PORTF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
cli();
TCCR1A |= (1<<WGM10);
TCCR1B |= ((1<<CS11) | (1<<CS10));
TIMSK1 |= ((1<<OCIE1A) | (1<<TOIE1));
TIFR1 |= (1<<TOV1);
sei();
OCR1A = pgm_read_byte(&backlight_table[level]);
}
else {
DDRF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
cli();
TCCR1A &= ~(1<<WGM10);
TCCR1B &= ~((1<<CS11) | (1<<CS10));
TIMSK1 |= ((1<<OCIE1A) | (1<<TOIE1));
TIFR1 |= (1<<TOV1);
sei();
OCR1A = 0;
}
}

ISR(TIMER1_COMPA_vect)
{
// LED off
PORTF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
}
ISR(TIMER1_OVF_vect)
{
// LED on
PORTF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
}
#endif

+ 13
- 8
keyboard/gh60/config.h View File

@@ -42,13 +42,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEBOUNCE 5

/* number of backlight levels */
#if defined(GH60_REV_CHN)
# define BACKLIGHT_LEVELS 3
#elif defined(GH60_REV_CNY)
# define BACKLIGHT_LEVELS 3
#else
# define BACKLIGHT_LEVELS 1
#endif
#define BACKLIGHT_LEVELS 3

#ifdef GH60_REV_CNY
# define LED_MATRIX_ROWS 6
@@ -66,7 +60,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
)


/* PS2 mouse support */
#ifdef PS2_MOUSE_ENABLE
#define PS2_CLOCK_PORT PORTF
#define PS2_CLOCK_PIN PINF
#define PS2_CLOCK_DDR DDRF
#define PS2_CLOCK_BIT PF7

#define PS2_DATA_PORT PORTF
#define PS2_DATA_PIN PINF
#define PS2_DATA_DDR DDRF
#define PS2_DATA_BIT PF6
#endif

/*
* Feature disable options

+ 2
- 0
keyboard/gh60/led_matrix.c View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <avr/io.h>
#include "led_matrix.h"

#ifdef LED_MATRIX_ENABLE
#if defined(GH60_REV_CNY)

/* LED Column pin configuration
@@ -94,3 +95,4 @@ void led_matrix_select_row(uint8_t row)
}

#endif
#endif

+ 24
- 0
keyboard/gh60/matrix.c View File

@@ -26,6 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "debug.h"
#include "util.h"
#include "matrix.h"
#ifdef PS2_MOUSE_ENABLE
#include "ps2.h"
#endif


#ifndef DEBOUNCE
@@ -42,6 +45,14 @@ static void init_cols(void);
static void unselect_rows(void);
static void select_row(uint8_t row);

#ifdef PS2_MOUSE_ENABLE
static uint8_t ps2_mouse_detected;

uint8_t ps2_enabled(void)
{
return ps2_mouse_detected;
}
#endif

inline
uint8_t matrix_rows(void)
@@ -61,6 +72,19 @@ void matrix_init(void)
MCUCR = (1<<JTD);
MCUCR = (1<<JTD);

#ifdef PS2_MOUSE_ENABLE
// ps2 mouse detect
DDRF &= ~(1<<PF5 | 1<<PF4);
PORTF |= (1<<PF5 | 1<<PF4);
if (PINF & (1<<PF5 | 1 <<PF4)) {
ps2_mouse_detected = 0;
}
else {
ps2_mouse_detected = 1;
}
DDRF |= (1<<PF5 | 1<<PF4);
#endif

// initialize row and col
unselect_rows();
init_cols();

+ 9
- 3
keyboard/ghpad/Makefile View File

@@ -50,7 +50,8 @@ TARGET_DIR = .
# project specific files
SRC = keymap_common.c \
matrix.c \
led.c
led.c \
backlight.c

ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC)
@@ -111,6 +112,11 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
# USBaspLoader 2048
OPT_DEFS += -DBOOTLOADER_SIZE=4096

# Additional definitions from command line
ifdef DEFS
OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF))
endif


# Build Options
# comment out to disable the options.
@@ -121,9 +127,9 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = yes # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
NKRO_ENABLE = yes # USB Nkey Rollover
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
#BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
KEYMAP_EX_ENABLE = yes # External keymap in eeprom
KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor


+ 56
- 20
keyboard/ghpad/backlight.c View File

@@ -1,5 +1,5 @@
/*
Copyright 2013 Kai Ryu <[email protected]>
Copyright 2013,2014 Kai Ryu <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,30 +17,66 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "backlight.h"

static const uint8_t backlight_table[] PROGMEM = {
0, 16, 128, 255
};

uint8_t softpwm_ocr = 0;

/* Backlight pin configuration
* PF7 PF6 PF5
* PWM: PB5 (RevRS)
* GPIO: PF7 PF6 PF5
*/
void backlight_set(uint8_t level)
{
switch (level) {
case 0:
DDRF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5);
break;
case 1:
DDRF &= ~(1<<PF6 | 1<<PF5);
DDRF |= (1<<PF7);
PORTF &= ~(1<<PF7);
break;
case 2:
DDRF &= ~(1<<PF5);
DDRF |= (1<<PF7 | 1<<PF6);
PORTF &= ~(1<<PF7 | 1<<PF6);
break;
case 3:
DDRF |= (1<<PF7 | 1<<PF6 | 1<<PF5);
PORTF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5);
break;
if (level > 0) {
// Turn on PWM
cli();
// Hard PWM
DDRB |= (1<<PB5);
PORTB |= (1<<PB5);
TCCR1A |= ((1<<WGM10) | (1<<COM1A1));
TCCR1B |= ((1<<CS11) | (1<<CS10));
// Soft PWM
DDRF |= ((1<<PF7) | (1<<PF6) | (1<<PF5));
PORTF |= ((1<<PF7) | (1<<PF6) | (1<<PF5));
TIMSK1 |= ((1<<OCIE1A) | (1<<TOIE1));
TIFR1 |= (1<<TOV1);
sei();
// Set PWM
OCR1A = pgm_read_byte(&backlight_table[level]);
softpwm_ocr = pgm_read_byte(&backlight_table[level]);
}
else {
// Turn off PWM
cli();
// Hard PWM
DDRB |= (1<<PB5);
PORTB &= ~(1<<PB5);
TCCR1A &= ~((1<<WGM10) | (1<<COM1A1));
TCCR1B &= ~((1<<CS11) | (1<<CS10));
// Soft PWM
DDRF |= ((1<<PF7) | (1<<PF6) | (1<<PF5));
PORTF |= ((1<<PF7) | (1<<PF6) | (1<<PF5));
TIMSK1 |= ((1<<OCIE1A) | (1<<TOIE1));
TIFR1 |= (1<<TOV1);
sei();
// Set PWM
OCR1A = 0;
softpwm_ocr = 0;
}
}

ISR(TIMER1_COMPA_vect)
{
// LED off
PORTF |= ((1<<PF7) | (1<<PF6) | (1<<PF5));
}
ISR(TIMER1_OVF_vect)
{
// LED on
PORTF &= ~((1<<PF7) | (1<<PF6) | (1<<PF5));
}

+ 6
- 2
keyboard/ghpad/config.h View File

@@ -54,11 +54,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define LOCKING_RESYNC_ENABLE

/* key combination for command */
#ifndef __ASSEMBLER__
#include "matrix.h"
#define IS_COMMAND() ( \
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
matrix_is_on(0, 0) && matrix_is_on(0, MATRIX_COLS - 1) \
)
#endif


/* boot magic key */
#define BOOTMAGIC_KEY_SALT KC_FN0

/*
* Feature disable options

+ 54
- 0
keyboard/ghpad/keymap_4x6_backlight.c View File

@@ -0,0 +1,54 @@
#include "keymap_common.h"

// 4x6 Keypad
#ifdef KEYMAP_SECTION_ENABLE
const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
#else
const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
#endif
/* Keymap 0: Default Layer
* ,---------------.
* |Esc|Fn0|Fn1|Fn2|
* |---+---+---+---|
* |Num|/ |* |- |
* |---+---+---+---|
* |7 |8 |9 |+ |
* |---+---+---| |
* |4 |5 |6 | |
* |---+---+---+---|
* |1 |2 |3 |Ent|
* |---+---+---| |
* |0 |. | |
* `---------------'
*/
[0] = KEYMAP(
ESC, FN0, FN1, FN2, \
NLCK,PSLS,PAST,PMNS, \
P7, P8, P9, PPLS, \
P4, P5, P6, PENT, \
P1, P2, P3, PENT, \
P0, NO, PDOT,NO)
};

/*
* Fn action definition
*/
#ifdef KEYMAP_SECTION_ENABLE
const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = {
#else
const uint16_t fn_actions[] PROGMEM = {
#endif
[0] = ACTION_BACKLIGHT_TOGGLE(),
[1] = ACTION_BACKLIGHT_DECREASE(),
[2] = ACTION_BACKLIGHT_INCREASE()
};

#ifdef KEYMAP_EX_ENABLE
uint16_t keys_count(void) {
return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS;
}

uint16_t fn_actions_count(void) {
return sizeof(fn_actions) / sizeof(fn_actions[0]);
}
#endif

+ 4
- 4
keyboard/ghpad/led.c View File

@@ -24,11 +24,11 @@ void led_set(uint8_t usb_led)
{
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
// output low
DDRB |= (1<<2);
PORTB &= ~(1<<2);
DDRB |= (1<<PB2);
PORTB &= ~(1<<PB2);
} else {
// Hi-Z
DDRB &= ~(1<<2);
PORTB &= ~(1<<2);
DDRB &= ~(1<<PB2);
PORTB &= ~(1<<PB2);
}
}

+ 1
- 1
keyboard/ghpad/matrix.c View File

@@ -1,5 +1,5 @@
/*
Copyright 2013 Kai Ryu <[email protected]>
Copyright 2013,2014 Kai Ryu <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

+ 1
- 0
protocol/ps2.h View File

@@ -90,6 +90,7 @@ uint8_t ps2_host_send(uint8_t data);
uint8_t ps2_host_recv_response(void);
uint8_t ps2_host_recv(void);
void ps2_host_set_led(uint8_t usb_led);
uint8_t ps2_enabled(void);


/* Check port settings for clock and data line */