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



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



+ 7
- 0
common/eeconfig.c View File

#include <stdbool.h> #include <stdbool.h>
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include "eeconfig.h" #include "eeconfig.h"
#include "keymap_ex.h"


void eeconfig_init(void) void eeconfig_init(void)
{ {
#ifdef BACKLIGHT_ENABLE #ifdef BACKLIGHT_ENABLE
eeprom_write_byte(EECONFIG_BACKLIGHT, 0); eeprom_write_byte(EECONFIG_BACKLIGHT, 0);
#endif #endif
#ifdef KEYMAP_EX_ENABLE
keymap_ex_init();
#endif
} }


void eeconfig_enable(void) void eeconfig_enable(void)


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



+ 7
- 3
common/keyboard.c View File

#endif #endif


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


#ifdef BOOTMAGIC_ENABLE #ifdef BOOTMAGIC_ENABLE
#endif #endif


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


#endif #endif


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


// update LED // update LED

+ 5
- 1
common/keymap_ex.c View File



#ifdef KEYMAP_EX_ENABLE #ifdef KEYMAP_EX_ENABLE


void keymap_init(void) {
void keymap_ex_init(void) {
if (!check_keymap_in_eeprom()) { if (!check_keymap_in_eeprom()) {
write_keymap_to_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) { bool check_keymap_in_eeprom(void) {
uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum); uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum);
uint16_t checksum = EECONFIG_MAGIC_NUMBER; uint16_t checksum = EECONFIG_MAGIC_NUMBER;

+ 2
- 1
common/keymap_ex.h View File

#define FN_ACTION_OFFSET(index) (sizeof(uint16_t) * index) #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)) #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); bool check_keymap_in_eeprom(void);
void write_keymap_to_eeprom(void); void write_keymap_to_eeprom(void);
uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col); uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col);

+ 2
- 1
keyboard/gh60/Makefile View File

#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend #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 - not yet supported in LUFA
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
#PS2_USE_BUSYWAIT = yes
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
KEYMAP_EX_ENABLE = yes # External keymap in eeprom KEYMAP_EX_ENABLE = yes # External keymap in eeprom
KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
LED_MATRIX_ENABLE = yes LED_MATRIX_ENABLE = yes



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


VPATH += $(TOP_DIR) VPATH += $(TOP_DIR)


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

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

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

void backlight_set(uint8_t level) void backlight_set(uint8_t level)
{ {
if (level > 0) { 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 { else {
DDRF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4); 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 #endif

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

#define DEBOUNCE 5 #define DEBOUNCE 5


/* number of backlight levels */ /* 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 #ifdef GH60_REV_CNY
# define LED_MATRIX_ROWS 6 # define LED_MATRIX_ROWS 6
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ 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 * Feature disable options

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

#include <avr/io.h> #include <avr/io.h>
#include "led_matrix.h" #include "led_matrix.h"


#ifdef LED_MATRIX_ENABLE
#if defined(GH60_REV_CNY) #if defined(GH60_REV_CNY)


/* LED Column pin configuration /* LED Column pin configuration
} }


#endif #endif
#endif

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

#include "debug.h" #include "debug.h"
#include "util.h" #include "util.h"
#include "matrix.h" #include "matrix.h"
#ifdef PS2_MOUSE_ENABLE
#include "ps2.h"
#endif




#ifndef DEBOUNCE #ifndef DEBOUNCE
static void unselect_rows(void); static void unselect_rows(void);
static void select_row(uint8_t row); 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 inline
uint8_t matrix_rows(void) uint8_t matrix_rows(void)
MCUCR = (1<<JTD); MCUCR = (1<<JTD);
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 // initialize row and col
unselect_rows(); unselect_rows();
init_cols(); init_cols();

+ 9
- 3
keyboard/ghpad/Makefile View File

# project specific files # project specific files
SRC = keymap_common.c \ SRC = keymap_common.c \
matrix.c \ matrix.c \
led.c
led.c \
backlight.c


ifdef KEYMAP ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC) SRC := keymap_$(KEYMAP).c $(SRC)
# USBaspLoader 2048 # USBaspLoader 2048
OPT_DEFS += -DBOOTLOADER_SIZE=4096 OPT_DEFS += -DBOOTLOADER_SIZE=4096


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



# Build Options # Build Options
# comment out to disable the options. # comment out to disable the options.
CONSOLE_ENABLE = yes # Console for debug(+400) CONSOLE_ENABLE = yes # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration COMMAND_ENABLE = yes # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend #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 #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_EX_ENABLE = yes # External keymap in eeprom
KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor



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

/* /*
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 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 it under the terms of the GNU General Public License as published by


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


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

uint8_t softpwm_ocr = 0;

/* Backlight pin configuration /* Backlight pin configuration
* PF7 PF6 PF5
* PWM: PB5 (RevRS)
* GPIO: PF7 PF6 PF5
*/ */
void backlight_set(uint8_t level) 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

#define LOCKING_RESYNC_ENABLE #define LOCKING_RESYNC_ENABLE


/* key combination for command */ /* key combination for command */
#ifndef __ASSEMBLER__
#include "matrix.h"
#define IS_COMMAND() ( \ #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 * Feature disable options

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

#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

{ {
if (usb_led & (1<<USB_LED_NUM_LOCK)) { if (usb_led & (1<<USB_LED_NUM_LOCK)) {
// output low // output low
DDRB |= (1<<2);
PORTB &= ~(1<<2);
DDRB |= (1<<PB2);
PORTB &= ~(1<<PB2);
} else { } else {
// Hi-Z // Hi-Z
DDRB &= ~(1<<2);
PORTB &= ~(1<<2);
DDRB &= ~(1<<PB2);
PORTB &= ~(1<<PB2);
} }
} }

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

/* /*
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 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 it under the terms of the GNU General Public License as published by

+ 1
- 0
protocol/ps2.h View File

uint8_t ps2_host_recv_response(void); uint8_t ps2_host_recv_response(void);
uint8_t ps2_host_recv(void); uint8_t ps2_host_recv(void);
void ps2_host_set_led(uint8_t usb_led); void ps2_host_set_led(uint8_t usb_led);
uint8_t ps2_enabled(void);




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