# 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) | ||||
#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 | ||||
#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 | ||||
/* | /* | ||||
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)); | |||||
} | } |
#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 |
{ | { | ||||
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); | |||||
} | } | ||||
} | } |
/* | /* | ||||
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 |