* Virtual DIP Switch - Configurations stored EEPROM(Boot Magic) | * Virtual DIP Switch - Configurations stored EEPROM(Boot Magic) | ||||
* Locking CapsLock - Mechanical switch support for CapsLock | * Locking CapsLock - Mechanical switch support for CapsLock | ||||
* Breathing Sleep LED - Sleep indicator with charm during USB suspend | * Breathing Sleep LED - Sleep indicator with charm during USB suspend | ||||
* Backlight - Control backlight levels | |||||
Projects | Projects | ||||
* [phantom](keyboard/phantom/) - [Phantom] keyboard (by Tranquilite) | * [phantom](keyboard/phantom/) - [Phantom] keyboard (by Tranquilite) | ||||
* [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) | * [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) | ||||
* [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway] [retired] | * [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway] [retired] | ||||
* [KMAC](keyboard/kmac/) - Korean custom keyboard | |||||
[GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 | [GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 | ||||
[GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 | [GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 |
OPT_DEFS += -DNO_SUSPEND_POWER_DOWN | OPT_DEFS += -DNO_SUSPEND_POWER_DOWN | ||||
endif | endif | ||||
ifdef BACKLIGHT_ENABLE | |||||
SRC += $(COMMON_DIR)/backlight.c | |||||
OPT_DEFS += -DBACKLIGHT_ENABLE | |||||
endif | |||||
# Search Path | # Search Path | ||||
VPATH += $(TOP_DIR)/common | VPATH += $(TOP_DIR)/common |
#include "mousekey.h" | #include "mousekey.h" | ||||
#include "command.h" | #include "command.h" | ||||
#include "led.h" | #include "led.h" | ||||
#include "backlight.h" | |||||
#include "action_layer.h" | #include "action_layer.h" | ||||
#include "action_tapping.h" | #include "action_tapping.h" | ||||
#include "action_oneshot.h" | #include "action_oneshot.h" | ||||
case ACT_MACRO: | case ACT_MACRO: | ||||
action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); | action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); | ||||
break; | break; | ||||
#endif | |||||
#ifdef BACKLIGHT_ENABLE | |||||
case ACT_BACKLIGHT: | |||||
if (!event.pressed) { | |||||
switch (action.backlight.id) { | |||||
case BACKLIGHT_INCREASE: | |||||
backlight_increase(); | |||||
break; | |||||
case BACKLIGHT_DECREASE: | |||||
backlight_decrease(); | |||||
break; | |||||
case BACKLIGHT_TOGGLE: | |||||
backlight_toggle(); | |||||
break; | |||||
case BACKLIGHT_STEP: | |||||
backlight_step(); | |||||
break; | |||||
} | |||||
} | |||||
break; | |||||
#endif | #endif | ||||
case ACT_COMMAND: | case ACT_COMMAND: | ||||
break; | break; |
* 1100|opt | id(8) Macro play? | * 1100|opt | id(8) Macro play? | ||||
* 1100|1111| id(8) Macro record? | * 1100|1111| id(8) Macro record? | ||||
* | * | ||||
* ACT_BACKLIGHT(1101): | |||||
* 1101|xxxx| id(8) Backlight commands | |||||
* | |||||
* ACT_COMMAND(1110): | * ACT_COMMAND(1110): | ||||
* 1110|opt | id(8) Built-in Command exec | * 1110|opt | id(8) Built-in Command exec | ||||
* | * | ||||
ACT_LAYER_TAP1 = 0b1011, | ACT_LAYER_TAP1 = 0b1011, | ||||
/* Extensions */ | /* Extensions */ | ||||
ACT_MACRO = 0b1100, | ACT_MACRO = 0b1100, | ||||
ACT_BACKLIGHT = 0b1101, | |||||
ACT_COMMAND = 0b1110, | ACT_COMMAND = 0b1110, | ||||
ACT_FUNCTION = 0b1111 | ACT_FUNCTION = 0b1111 | ||||
}; | }; | ||||
uint8_t page :2; | uint8_t page :2; | ||||
uint8_t kind :4; | uint8_t kind :4; | ||||
} usage; | } usage; | ||||
struct action_backlight { | |||||
uint8_t id :8; | |||||
} backlight; | |||||
struct action_command { | struct action_command { | ||||
uint8_t id :8; | uint8_t id :8; | ||||
uint8_t opt :4; | uint8_t opt :4; | ||||
/* | /* | ||||
* Extensions | * Extensions | ||||
*/ | */ | ||||
enum backlight_id { | |||||
BACKLIGHT_INCREASE = 0, | |||||
BACKLIGHT_DECREASE = 1, | |||||
BACKLIGHT_TOGGLE = 2, | |||||
BACKLIGHT_STEP = 3, | |||||
}; | |||||
/* Macro */ | /* Macro */ | ||||
#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) | ||||
#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) | ||||
#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id)) | #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id)) | ||||
/* Backlight */ | |||||
#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE) | |||||
#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE) | |||||
#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE) | |||||
#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP) | |||||
/* Command */ | /* Command */ | ||||
#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) | ||||
/* Function */ | /* Function */ |
/* | |||||
Copyright 2013 Mathias Andersson <[email protected]> | |||||
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 | |||||
the Free Software Foundation, either version 2 of the License, or | |||||
(at your option) any later version. | |||||
This program is distributed in the hope that it will be useful, | |||||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
GNU General Public License for more details. | |||||
You should have received a copy of the GNU General Public License | |||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "backlight.h" | |||||
#include "eeconfig.h" | |||||
#include "debug.h" | |||||
backlight_config_t backlight_config; | |||||
void backlight_init(void) | |||||
{ | |||||
/* check signature */ | |||||
if (!eeconfig_is_enabled()) { | |||||
eeconfig_init(); | |||||
} | |||||
backlight_config.raw = eeconfig_read_backlight(); | |||||
backlight_set(backlight_config.enable ? backlight_config.level : 0); | |||||
} | |||||
void backlight_increase(void) | |||||
{ | |||||
if(backlight_config.level < BACKLIGHT_LEVELS) | |||||
{ | |||||
backlight_config.level++; | |||||
backlight_config.enable = 1; | |||||
eeconfig_write_backlight(backlight_config.raw); | |||||
} | |||||
dprintf("backlight increase: %u\n", backlight_config.level); | |||||
backlight_set(backlight_config.level); | |||||
} | |||||
void backlight_decrease(void) | |||||
{ | |||||
if(backlight_config.level > 0) | |||||
{ | |||||
backlight_config.level--; | |||||
backlight_config.enable = !!backlight_config.level; | |||||
eeconfig_write_backlight(backlight_config.raw); | |||||
} | |||||
dprintf("backlight decrease: %u\n", backlight_config.level); | |||||
backlight_set(backlight_config.level); | |||||
} | |||||
void backlight_toggle(void) | |||||
{ | |||||
backlight_config.enable ^= 1; | |||||
eeconfig_write_backlight(backlight_config.raw); | |||||
dprintf("backlight toggle: %u\n", backlight_config.enable); | |||||
backlight_set(backlight_config.enable ? backlight_config.level : 0); | |||||
} | |||||
void backlight_step(void) | |||||
{ | |||||
backlight_config.level++; | |||||
if(backlight_config.level > BACKLIGHT_LEVELS) | |||||
{ | |||||
backlight_config.level = 0; | |||||
} | |||||
backlight_config.enable = !!backlight_config.level; | |||||
eeconfig_write_backlight(backlight_config.raw); | |||||
dprintf("backlight step: %u\n", backlight_config.level); | |||||
backlight_set(backlight_config.level); | |||||
} |
/* | |||||
Copyright 2013 Mathias Andersson <[email protected]> | |||||
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 | |||||
the Free Software Foundation, either version 2 of the License, or | |||||
(at your option) any later version. | |||||
This program is distributed in the hope that it will be useful, | |||||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
GNU General Public License for more details. | |||||
You should have received a copy of the GNU General Public License | |||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef BACKLIGHT_H | |||||
#define BACKLIGHT_H | |||||
#include <stdint.h> | |||||
#include <stdbool.h> | |||||
typedef union { | |||||
uint8_t raw; | |||||
struct { | |||||
bool enable:1; | |||||
uint8_t level:7; | |||||
}; | |||||
} backlight_config_t; | |||||
void backlight_init(void); | |||||
void backlight_increase(void); | |||||
void backlight_decrease(void); | |||||
void backlight_toggle(void); | |||||
void backlight_step(void); | |||||
void backlight_set(uint8_t level); | |||||
#endif |
#include "sleep_led.h" | #include "sleep_led.h" | ||||
#include "led.h" | #include "led.h" | ||||
#include "command.h" | #include "command.h" | ||||
#include "backlight.h" | |||||
#ifdef MOUSEKEY_ENABLE | #ifdef MOUSEKEY_ENABLE | ||||
#include "mousekey.h" | #include "mousekey.h" | ||||
print(".no_gui: "); print_dec(kc.no_gui); print("\n"); | print(".no_gui: "); print_dec(kc.no_gui); print("\n"); | ||||
print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); | print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); | ||||
print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); | print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); | ||||
#ifdef BACKLIGHT_ENABLE | |||||
backlight_config_t bc; | |||||
bc.raw = eeconfig_read_backlight(); | |||||
print("backlight_config.raw: "); print_hex8(bc.raw); print("\n"); | |||||
print(".enable: "); print_dec(bc.enable); print("\n"); | |||||
print(".level: "); print_dec(bc.level); print("\n"); | |||||
#endif | |||||
} | } | ||||
#endif | #endif | ||||
eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); | eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); | ||||
eeprom_write_byte(EECONFIG_KEYMAP, 0); | eeprom_write_byte(EECONFIG_KEYMAP, 0); | ||||
eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); | eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); | ||||
#ifdef BACKLIGHT_ENABLE | |||||
eeprom_write_byte(EECONFIG_BACKLIGHT, 0); | |||||
#endif | |||||
} | } | ||||
void eeconfig_enable(void) | void eeconfig_enable(void) | ||||
uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); } | uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); } | ||||
void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); } | void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); } | ||||
#ifdef BACKLIGHT_ENABLE | |||||
uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } | |||||
void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } | |||||
#endif |
#define EECONFIG_H | #define EECONFIG_H | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdbool.h> | |||||
#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED | #define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED | ||||
#define EECONFIG_DEFAULT_LAYER (uint8_t *)3 | #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 | ||||
#define EECONFIG_KEYMAP (uint8_t *)4 | #define EECONFIG_KEYMAP (uint8_t *)4 | ||||
#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 | #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 | ||||
#define EECONFIG_BACKLIGHT (uint8_t *)6 | |||||
/* debug bit */ | /* debug bit */ | ||||
uint8_t eeconfig_read_keymap(void); | uint8_t eeconfig_read_keymap(void); | ||||
void eeconfig_write_keymap(uint8_t val); | void eeconfig_write_keymap(uint8_t val); | ||||
#ifdef BACKLIGHT_ENABLE | |||||
uint8_t eeconfig_read_backlight(void); | |||||
void eeconfig_write_backlight(uint8_t val); | |||||
#endif | |||||
#endif | #endif |
#include "bootmagic.h" | #include "bootmagic.h" | ||||
#include "eeconfig.h" | #include "eeconfig.h" | ||||
#include "mousekey.h" | #include "mousekey.h" | ||||
#include "backlight.h" | |||||
#ifdef MATRIX_HAS_GHOST | #ifdef MATRIX_HAS_GHOST | ||||
#ifdef BOOTMAGIC_ENABLE | #ifdef BOOTMAGIC_ENABLE | ||||
bootmagic(); | bootmagic(); | ||||
#endif | #endif | ||||
#ifdef BACKLIGHT_ENABLE | |||||
backlight_init(); | |||||
#endif | |||||
} | } | ||||
/* | /* |
#include "suspend.h" | #include "suspend.h" | ||||
#include "matrix.h" | #include "matrix.h" | ||||
#include "action.h" | #include "action.h" | ||||
#include "backlight.h" | |||||
void suspend_power_down(void) | void suspend_power_down(void) | ||||
{ | { | ||||
#ifdef BACKLIGHT_ENABLE | |||||
backlight_set(0); | |||||
#endif | |||||
#ifndef NO_SUSPEND_POWER_DOWN | #ifndef NO_SUSPEND_POWER_DOWN | ||||
// Enable watchdog to wake from MCU sleep | // Enable watchdog to wake from MCU sleep | ||||
cli(); | cli(); | ||||
// clear matrix and keyboard state | // clear matrix and keyboard state | ||||
matrix_init(); | matrix_init(); | ||||
clear_keyboard(); | clear_keyboard(); | ||||
#ifdef BACKLIGHT_ENABLE | |||||
backlight_init(); | |||||
#endif | |||||
} | } | ||||
#ifndef NO_SUSPEND_POWER_DOWN | #ifndef NO_SUSPEND_POWER_DOWN |
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 - not yet supported in LUFA | ||||
#BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | |||||
### 3. Programmer | ### 3. Programmer | ||||
Optional. Set proper command for your controller, bootloader and programmer. This command can be used with `make program`. Not needed if you use `FLIP`, `dfu-programmer` or `Teesy Loader`. | Optional. Set proper command for your controller, bootloader and programmer. This command can be used with `make program`. Not needed if you use `FLIP`, `dfu-programmer` or `Teesy Loader`. |
### 2.5 Backlight Action | |||||
These actions control the backlight. | |||||
#### 2.5.1 Change backlight level | |||||
Increase backlight level. | |||||
ACTION_BACKLIGHT_INCREASE() | |||||
Decrease backlight level. | |||||
ACTION_BACKLIGHT_DECREASE() | |||||
Step through backlight levels. | |||||
ACTION_BACKLIGHT_STEP() | |||||
#### 2.5.2 Turn on / off backlight | |||||
Turn the backlight on and off without changing level. | |||||
ACTION_BACKLIGHT_TOGGLE() | |||||
## 3. Layer switching Example | ## 3. Layer switching Example |