1
0

Add support for full-led revision of ghpad

This commit is contained in:
Kai Ryu 2014-04-04 12:22:22 +09:00
parent 91d22894b0
commit 5bc8b5dcb6
5 changed files with 118 additions and 27 deletions

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)
@ -123,7 +124,7 @@ 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
#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

View File

@ -1,5 +1,5 @@
/*
Copyright 2013 Kai Ryu <kai1103@gmail.com>
Copyright 2013,2014 Kai Ryu <kai1103@gmail.com>
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));
}

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

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);
}
}

View File

@ -1,5 +1,5 @@
/*
Copyright 2013 Kai Ryu <kai1103@gmail.com>
Copyright 2013,2014 Kai Ryu <kai1103@gmail.com>
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