- USB 6KRO - SoftPWM LED - Breathing LED - Fading LED - Typing LED - Ledmap - Ledmap in EEPROMledmap
SRC = keymap_common.c \ | SRC = keymap_common.c \ | ||||
matrix.c \ | matrix.c \ | ||||
led.c \ | led.c \ | ||||
backlight.c | |||||
backlight.c \ | |||||
ledmap.c | |||||
ifdef KEYMAP | ifdef KEYMAP | ||||
SRC := keymap_$(KEYMAP).c $(SRC) | SRC := keymap_$(KEYMAP).c $(SRC) | ||||
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 | NKRO_ENABLE = yes # USB Nkey Rollover | ||||
USB_6KRO_ENABLE = yes # USB 6key 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_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" | # Optimize size but this may cause error "relocation truncated to fit" |
# project specific files | # project specific files | ||||
SRC = keymap.c \ | SRC = keymap.c \ | ||||
matrix.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 | CONFIG_H = config.h | ||||
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(+500) | NKRO_ENABLE = yes # USB Nkey Rollover(+500) | ||||
USB_6KRO_ENABLE = yes # USB 6key 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 | |||||
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 | # Search Path |
#include <avr/interrupt.h> | #include <avr/interrupt.h> | ||||
#include <avr/pgmspace.h> | #include <avr/pgmspace.h> | ||||
#include "backlight.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 = { | static const uint8_t backlight_table[] PROGMEM = { | ||||
0, 16, 128, 255 | 0, 16, 128, 255 | ||||
}; | }; | ||||
uint8_t softpwm_ocr = 0; | |||||
/* Backlight pin configuration | /* Backlight pin configuration | ||||
* PWM: PB5 (RevRS) | |||||
* PWM: PB5 (RevRS) | |||||
* GPIO: PF7 PF6 PF5 | * GPIO: PF7 PF6 PF5 | ||||
*/ | */ | ||||
void backlight_set(uint8_t level) | 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 |
#define DEBOUNCE 5 | #define DEBOUNCE 5 | ||||
/* number of backlight levels */ | /* number of backlight levels */ | ||||
#define BACKLIGHT_LEVELS 3 | |||||
#define BACKLIGHT_LEVELS 8 | |||||
#define LED_COUNT 5 | |||||
/* number of backlight levels */ | /* number of backlight levels */ | ||||
//#define BACKLIGHT_LEVELS 3 | //#define BACKLIGHT_LEVELS 3 |
#endif | #endif | ||||
}; | }; | ||||
#ifdef KEYMAP_EX_ENABLE | |||||
#ifdef KEYMAP_IN_EEPROM_ENABLE | |||||
uint16_t keys_count(void) { | uint16_t keys_count(void) { | ||||
return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; | return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; | ||||
} | } |
[2] = ACTION_BACKLIGHT_INCREASE() | [2] = ACTION_BACKLIGHT_INCREASE() | ||||
}; | }; | ||||
#ifdef KEYMAP_EX_ENABLE | |||||
#ifdef KEYMAP_IN_EEPROM_ENABLE | |||||
uint16_t keys_count(void) { | uint16_t keys_count(void) { | ||||
return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; | return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; | ||||
} | } |
[2] = ACTION_BACKLIGHT_INCREASE() | [2] = ACTION_BACKLIGHT_INCREASE() | ||||
}; | }; | ||||
#ifdef KEYMAP_EX_ENABLE | |||||
#ifdef KEYMAP_IN_EEPROM_ENABLE | |||||
uint16_t keys_count(void) { | uint16_t keys_count(void) { | ||||
return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; | return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; | ||||
} | } |
/* translates key to keycode */ | /* translates key to keycode */ | ||||
uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) | 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)]); | return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); | ||||
#else | #else | ||||
return eeconfig_read_keymap_key(layer, key.row, key.col); | return eeconfig_read_keymap_key(layer, key.row, key.col); | ||||
action_t keymap_fn_to_action(uint8_t keycode) | action_t keymap_fn_to_action(uint8_t keycode) | ||||
{ | { | ||||
return (action_t) { | return (action_t) { | ||||
#ifndef KEYMAP_EX_ENABLE | |||||
#ifndef KEYMAP_IN_EEPROM_ENABLE | |||||
.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) | .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) | ||||
#else | #else | ||||
.code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)) | .code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)) | ||||
}; | }; | ||||
} | } | ||||
#ifdef KEYMAP_EX_ENABLE | |||||
#ifdef KEYMAP_IN_EEPROM_ENABLE | |||||
const uint8_t* keymaps_pointer(void) { | const uint8_t* keymaps_pointer(void) { | ||||
return (const uint8_t*)keymaps; | return (const uint8_t*)keymaps; | ||||
} | } |
#include "print.h" | #include "print.h" | ||||
#include "debug.h" | #include "debug.h" | ||||
#include "keymap.h" | #include "keymap.h" | ||||
#include "keymap_ex.h" | |||||
#include "keymap_in_eeprom.h" | |||||
extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; | extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; | ||||
extern const uint16_t fn_actions[]; | extern const uint16_t fn_actions[]; |
[0] = ACTION_BACKLIGHT_STEP(), | [0] = ACTION_BACKLIGHT_STEP(), | ||||
}; | }; | ||||
#ifdef KEYMAP_EX_ENABLE | |||||
#ifdef KEYMAP_IN_EEPROM_ENABLE | |||||
uint16_t keys_count(void) { | uint16_t keys_count(void) { | ||||
return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; | return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; | ||||
} | } |
#include "stdint.h" | #include "stdint.h" | ||||
#include "led.h" | #include "led.h" | ||||
#ifndef LEDMAP_ENABLE | |||||
void led_set(uint8_t usb_led) | void led_set(uint8_t usb_led) | ||||
{ | { | ||||
PORTB &= ~(1<<PB2); | PORTB &= ~(1<<PB2); | ||||
} | } | ||||
} | } | ||||
#endif |
#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 |