Browse Source

Update features for GHPad

- USB 6KRO
- SoftPWM LED
- Breathing LED
- Fading LED
- Typing LED
- Ledmap
- Ledmap in EEPROM
ledmap
Kai Ryu 9 years ago
parent
commit
9414e34f5b

+ 10
- 3
keyboard/ghpad/Makefile View File

@@ -51,7 +51,8 @@ TARGET_DIR = .
SRC = keymap_common.c \
matrix.c \
led.c \
backlight.c
backlight.c \
ledmap.c

ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC)
@@ -128,10 +129,16 @@ 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
USB_6KRO_ENABLE = yes # USB 6key Rollover
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
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
KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom
#KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight
FADING_LED_ENABLE = yes # Enable fading backlight
BREATHING_LED_ENABLE = yes # Enable breathing backlight
LEDMAP_ENABLE = yes # Enable LED mapping
LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom


# Optimize size but this may cause error "relocation truncated to fit"

+ 19
- 1
keyboard/ghpad/Makefile.pjrc View File

@@ -50,7 +50,16 @@ TARGET_DIR = .
# project specific files
SRC = keymap.c \
matrix.c \
led.c
led.c \
backlight.c \
ledmap.c

ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC)
else
SRC := keymap_4x6.c $(SRC)
endif


CONFIG_H = config.h

@@ -86,7 +95,16 @@ CONSOLE_ENABLE = yes # Console for debug
COMMAND_ENABLE = yes # Commands for debug and configuration
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
NKRO_ENABLE = yes # USB Nkey Rollover(+500)
USB_6KRO_ENABLE = yes # USB 6key Rollover
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom
#KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight
FADING_LED_ENABLE = yes # Enable fading backlight
BREATHING_LED_ENABLE = yes # Enable breathing backlight
LEDMAP_ENABLE = yes # Enable LED mapping
LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom


# Search Path

+ 76
- 44
keyboard/ghpad/backlight.c View File

@@ -19,64 +19,96 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "backlight.h"
#include "softpwm_led.h"
#include "action.h"

#ifdef BACKLIGHT_ENABLE

static uint8_t backlight_mode;

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

uint8_t softpwm_ocr = 0;

/* Backlight pin configuration
* PWM: PB5 (RevRS)
* PWM: PB5 (RevRS)
* GPIO: PF7 PF6 PF5
*/
void backlight_set(uint8_t level)
{
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;
backlight_mode = level;
switch (level) {
case 1:
case 2:
case 3:
softpwm_led_enable();
fading_led_disable_all();
breathing_led_disable_all();
softpwm_led_set_all(pgm_read_byte(&backlight_table[level]));
break;
case 4:
case 5:
case 6:
softpwm_led_enable();
breathing_led_enable_all();
fading_led_disable_all();
breathing_led_set_duration(6 - level);
break;
case 7:
softpwm_led_enable();
fading_led_enable_all();
breathing_led_disable_all();
fading_led_set_direction(FADING_LED_FADE_IN);
fading_led_set_duration(4);
break;
case 8:
softpwm_led_enable();
fading_led_enable_all();
breathing_led_disable_all();
fading_led_set_direction(FADING_LED_FADE_OUT);
fading_led_set_duration(2);
break;
case 0:
default:
fading_led_disable_all();
breathing_led_disable_all();
softpwm_led_enable();
break;
}
}

ISR(TIMER1_COMPA_vect)
#ifndef LEDMAP_ENABLE
void softpwm_led_init(void)
{
DDRB |= (1<<PB5);
DDRF |= (1<<PF7 | 1<<PF6 | 1<<PF5);
}

void softpwm_led_on(uint8_t index)
{
// LED off
PORTF |= ((1<<PF7) | (1<<PF6) | (1<<PF5));
PORTB |= (1<<PB5);
PORTF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5);
}
ISR(TIMER1_OVF_vect)

void softpwm_led_off(uint8_t index)
{
// LED on
PORTF &= ~((1<<PF7) | (1<<PF6) | (1<<PF5));
PORTB &= ~(1<<PB5);
PORTF |= (1<<PF7 | 1<<PF6 | 1<<PF5);
}
#endif

void action_keyevent(keyevent_t event)
{
if (backlight_mode == 7) {
if (event.pressed) {
softpwm_led_decrease_all(32);
}
}
if (backlight_mode == 8) {
if (event.pressed) {
softpwm_led_increase_all(32);
}
}
}

#endif

+ 3
- 1
keyboard/ghpad/config.h View File

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

/* number of backlight levels */
#define BACKLIGHT_LEVELS 3
#define BACKLIGHT_LEVELS 8

#define LED_COUNT 5

/* number of backlight levels */
//#define BACKLIGHT_LEVELS 3

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

@@ -40,7 +40,7 @@ const uint16_t fn_actions[] PROGMEM = {
#endif
};

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

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

@@ -43,7 +43,7 @@ const uint16_t fn_actions[] PROGMEM = {
[2] = ACTION_BACKLIGHT_INCREASE()
};

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

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

@@ -51,7 +51,7 @@ const uint16_t fn_actions[] PROGMEM = {
[2] = ACTION_BACKLIGHT_INCREASE()
};

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

+ 3
- 3
keyboard/ghpad/keymap_common.c View File

@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* translates key to keycode */
uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
{
#ifndef KEYMAP_EX_ENABLE
#ifndef KEYMAP_IN_EEPROM_ENABLE
return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
#else
return eeconfig_read_keymap_key(layer, key.row, key.col);
@@ -30,7 +30,7 @@ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
action_t keymap_fn_to_action(uint8_t keycode)
{
return (action_t) {
#ifndef KEYMAP_EX_ENABLE
#ifndef KEYMAP_IN_EEPROM_ENABLE
.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)])
#else
.code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode))
@@ -38,7 +38,7 @@ action_t keymap_fn_to_action(uint8_t keycode)
};
}

#ifdef KEYMAP_EX_ENABLE
#ifdef KEYMAP_IN_EEPROM_ENABLE
const uint8_t* keymaps_pointer(void) {
return (const uint8_t*)keymaps;
}

+ 1
- 1
keyboard/ghpad/keymap_common.h View File

@@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "print.h"
#include "debug.h"
#include "keymap.h"
#include "keymap_ex.h"
#include "keymap_in_eeprom.h"

extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
extern const uint16_t fn_actions[];

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

@@ -41,7 +41,7 @@ const uint16_t fn_actions[] PROGMEM = {
[0] = ACTION_BACKLIGHT_STEP(),
};

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

+ 3
- 0
keyboard/ghpad/led.c View File

@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdint.h"
#include "led.h"

#ifndef LEDMAP_ENABLE

void led_set(uint8_t usb_led)
{
@@ -32,3 +33,5 @@ void led_set(uint8_t usb_led)
PORTB &= ~(1<<PB2);
}
}

#endif

+ 73
- 0
keyboard/ghpad/ledmap.c View File

@@ -0,0 +1,73 @@
#include <avr/pgmspace.h>
#include "ledmap.h"
#include "debug.h"


#ifdef LEDMAP_ENABLE

static const uint8_t ledmaps[LED_COUNT] PROGMEM = {
[0] = LEDMAP_NUM_LOCK | LEDMAP_BACKLIGHT, // LEDS1 - PB2
[1] = LEDMAP_BACKLIGHT, // LEDS6 - PF7
[2] = LEDMAP_BACKLIGHT, // LEDS11 - PF6
[3] = LEDMAP_BACKLIGHT, // LEDS16 - PF5
[4] = LEDMAP_BACKLIGHT, // PWM - PB5
};

uint8_t ledmap_get_code(uint8_t index)
{
return pgm_read_byte(&ledmaps[index]);
}

void ledmap_led_init(void)
{
DDRB |= (1<<PB2);
PORTB |= (1<<PB2);
DDRF |= (1<<PF7 | 1<<PF6 | 1<<PF5);
PORTF |= (1<<PF7 | 1<<PF6 | 1<<PF5);
DDRB |= (1<<PB5);
PORTB &= ~(1<<PB5);
}

void ledmap_led_on(uint8_t index)
{
switch (index) {
case 0:
PORTB &= ~(1<<PB2);
break;
case 1:
PORTF &= ~(1<<PF7);
break;
case 2:
PORTF &= ~(1<<PF6);
break;
case 3:
PORTF &= ~(1<<PF5);
break;
case 4:
PORTB |= (1<<PB5);
break;
}
}

void ledmap_led_off(uint8_t index)
{
switch (index) {
case 0:
PORTB |= (1<<PB2);
break;
case 1:
PORTF |= (1<<PF7);
break;
case 2:
PORTF |= (1<<PF6);
break;
case 3:
PORTF |= (1<<PF5);
break;
case 4:
PORTB &= ~(1<<PB5);
break;
}
}

#endif