# project specific files | # project specific files | ||||
SRC = keymap_common.c \ | SRC = keymap_common.c \ | ||||
tentapad.c \ | |||||
matrix.c \ | matrix.c \ | ||||
led.c \ | led.c \ | ||||
backlight.c \ | backlight.c \ |
#include <avr/pgmspace.h> | #include <avr/pgmspace.h> | ||||
#include "backlight.h" | #include "backlight.h" | ||||
#include "softpwm_led.h" | #include "softpwm_led.h" | ||||
#include "action.h" | |||||
#include "keymap_common.h" | #include "keymap_common.h" | ||||
#include "tentapad.h" | |||||
#ifdef BACKLIGHT_ENABLE | #ifdef BACKLIGHT_ENABLE | ||||
static uint8_t backlight_mode; | |||||
static const uint8_t backlight_brightness = 0xFF; | |||||
enum { | |||||
LED_KEY_1 = 0, | |||||
LED_KEY_2, | |||||
LED_KEY_SIDE, | |||||
LED_BOARD_SIDE | |||||
}; | |||||
uint8_t backlight_mode; | |||||
const uint8_t backlight_brightness = 0xFF; | |||||
void backlight_set(uint8_t level) | void backlight_set(uint8_t level) | ||||
{ | { | ||||
} | } | ||||
#endif | #endif | ||||
extern uint8_t config_mode; | |||||
void action_keyevent(keyevent_t event) | |||||
{ | |||||
if (config_mode) return; | |||||
if (event.key.col < 2) { | |||||
if (event.pressed) { | |||||
switch (backlight_mode) { | |||||
case 0: case 6: | |||||
softpwm_led_on(event.key.col); | |||||
break; | |||||
case 1 ... 5: | |||||
softpwm_led_set(event.key.col, backlight_brightness); | |||||
break; | |||||
} | |||||
} | |||||
else { | |||||
switch (backlight_mode) { | |||||
case 0: case 6: | |||||
softpwm_led_off(event.key.col); | |||||
break; | |||||
case 1 ... 5: | |||||
softpwm_led_set(event.key.col, 0); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
switch (backlight_mode) { | |||||
case 1: | |||||
if (event.pressed) { | |||||
softpwm_led_increase(LED_KEY_SIDE, 32); | |||||
} | |||||
break; | |||||
case 2: | |||||
if (event.pressed) { | |||||
softpwm_led_increase(LED_BOARD_SIDE, 32); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
#endif | #endif |
/* keymap in eeprom */ | /* keymap in eeprom */ | ||||
#define FN_ACTIONS_COUNT 32 | #define FN_ACTIONS_COUNT 32 | ||||
#define KEYMAPS_COUNT 9 | |||||
#define KEYMAPS_COUNT 8 | |||||
/* define if matrix has ghost */ | /* define if matrix has ghost */ | ||||
//#define MATRIX_HAS_GHOST | //#define MATRIX_HAS_GHOST |
#include "keymap_in_eeprom.h" | #include "keymap_in_eeprom.h" | ||||
#include "keymap_common.h" | #include "keymap_common.h" | ||||
static uint8_t keymaps_cache[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS]; | |||||
static uint8_t keymaps_cache[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] = {0}; | |||||
static uint8_t last_layer_number = 1; | static uint8_t last_layer_number = 1; | ||||
void keymaps_cache_init(void) | void keymaps_cache_init(void) | ||||
uint8_t non_empty_key = 0; | uint8_t non_empty_key = 0; | ||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) { | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||||
if (col == 3) { | |||||
keymaps_cache[layer][row][col] = KC_FN28; | |||||
} | |||||
else if (col == 4) { | |||||
keymaps_cache[layer][row][col] = KC_FN29; | |||||
} | |||||
else { | |||||
if (layer < CONFIG_LAYER) { | |||||
#ifndef KEYMAP_IN_EEPROM_ENABLE | #ifndef KEYMAP_IN_EEPROM_ENABLE | ||||
keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]); | |||||
keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]); | |||||
#else | #else | ||||
keymaps_cache[layer][row][col] = eeconfig_read_keymap_key(layer, row, col); | |||||
keymaps_cache[layer][row][col] = eeconfig_read_keymap_key(layer, row, col); | |||||
#endif | #endif | ||||
if (keymaps_cache[layer][row][col] > KC_TRANSPARENT) { | |||||
non_empty_key++; | |||||
} | |||||
} | |||||
else { | |||||
keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]); | |||||
} | |||||
if (keymaps_cache[layer][row][col] > KC_TRANSPARENT) { | |||||
non_empty_key++; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) | .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) | ||||
}; | }; | ||||
#else | #else | ||||
uint8_t index = FN_INDEX(keycode); | |||||
if (index < RESERVED_FN) { | |||||
return (action_t) { | |||||
.code = eeconfig_read_keymap_fn_action(index) | |||||
}; | |||||
} | |||||
else { | |||||
return (action_t) { | |||||
.code = pgm_read_word(&fn_actions[index]) | |||||
}; | |||||
} | |||||
return (action_t) { | |||||
.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) | |||||
}; | |||||
#endif | #endif | ||||
} | } | ||||
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[]; | ||||
#define CONFIG_LAYER (KEYMAPS_COUNT - 1) | |||||
#define RESERVED_FN (FN_ACTIONS_COUNT - 4) | |||||
void keymaps_cache_init(void); | void keymaps_cache_init(void); | ||||
uint8_t last_layer(void); | uint8_t last_layer(void); | ||||
#include <avr/pgmspace.h> | #include <avr/pgmspace.h> | ||||
#include "keycode.h" | #include "keycode.h" | ||||
#include "action_layer.h" | |||||
#include "eeconfig.h" | |||||
#include "backlight.h" | |||||
#include "keymap_common.h" | #include "keymap_common.h" | ||||
enum function_id { | |||||
TOUCH_PROXIMITY = 0, | |||||
CONFIG_MODE, | |||||
SWITCH_LAYOUT, | |||||
SWITCH_BACKLIGHT | |||||
}; | |||||
// Default | // Default | ||||
#ifdef KEYMAP_SECTION_ENABLE | #ifdef KEYMAP_SECTION_ENABLE | ||||
const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { | const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { | ||||
[3] = KEYMAP( UP, DOWN,ESC ), | [3] = KEYMAP( UP, DOWN,ESC ), | ||||
[4] = KEYMAP( PGUP,PGDN,ESC ), | [4] = KEYMAP( PGUP,PGDN,ESC ), | ||||
[5] = KEYMAP( SPC, ESC, ESC ), | [5] = KEYMAP( SPC, ESC, ESC ), | ||||
[CONFIG_LAYER] = KEYMAP( FN30, FN31, NO ) | |||||
}; | }; | ||||
/* | /* | ||||
#else | #else | ||||
const uint16_t fn_actions[] PROGMEM = { | const uint16_t fn_actions[] PROGMEM = { | ||||
#endif | #endif | ||||
[28] = ACTION_FUNCTION(TOUCH_PROXIMITY), | |||||
[29] = ACTION_FUNCTION(CONFIG_MODE), | |||||
[30] = ACTION_FUNCTION(SWITCH_LAYOUT), | |||||
[31] = ACTION_FUNCTION(SWITCH_BACKLIGHT) | |||||
}; | }; | ||||
#ifdef KEYMAP_IN_EEPROM_ENABLE | #ifdef KEYMAP_IN_EEPROM_ENABLE | ||||
return sizeof(fn_actions) / sizeof(fn_actions[0]); | return sizeof(fn_actions) / sizeof(fn_actions[0]); | ||||
} | } | ||||
#endif | #endif | ||||
uint8_t config_mode = 0; | |||||
static uint8_t layer = 0; | |||||
static uint8_t backlight = 0; | |||||
static uint8_t layer_modified = 0; | |||||
static uint8_t backlight_modified = 0; | |||||
extern backlight_config_t backlight_config; | |||||
void enter_config_mode(void); | |||||
void exit_config_mode(void); | |||||
void switch_layout(void); | |||||
void switch_backlight(void); | |||||
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) | |||||
{ | |||||
switch (id) { | |||||
case CONFIG_MODE: | |||||
if (record->event.pressed) { | |||||
if (config_mode) { | |||||
exit_config_mode(); | |||||
} | |||||
else { | |||||
enter_config_mode(); | |||||
} | |||||
} | |||||
break; | |||||
case SWITCH_LAYOUT: | |||||
if (record->event.pressed) { | |||||
if (config_mode) { | |||||
switch_layout(); | |||||
} | |||||
} | |||||
break; | |||||
case SWITCH_BACKLIGHT: | |||||
if (record->event.pressed) { | |||||
if (config_mode) { | |||||
switch_backlight(); | |||||
} | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
void enter_config_mode(void) | |||||
{ | |||||
config_mode = 1; | |||||
layer_modified = 0; | |||||
backlight_modified = 0; | |||||
backlight = backlight_config.level; | |||||
backlight_level(8); | |||||
layer_on(CONFIG_LAYER); | |||||
} | |||||
void exit_config_mode(void) | |||||
{ | |||||
config_mode = 0; | |||||
backlight_level(backlight); | |||||
layer_off(CONFIG_LAYER); | |||||
if (layer_modified) { | |||||
default_layer_set(1UL<<layer); | |||||
eeconfig_write_default_layer(1UL<<layer); | |||||
} | |||||
} | |||||
void switch_layout(void) | |||||
{ | |||||
if (!layer_modified) { | |||||
layer = 0; | |||||
layer_modified = 1; | |||||
} | |||||
else { | |||||
layer = (layer + 1) % (last_layer() + 1); | |||||
} | |||||
softpwm_led_set(0, 32 * (layer + 1)); | |||||
} | |||||
void switch_backlight(void) | |||||
{ | |||||
if (!backlight_modified) { | |||||
backlight = 0; | |||||
backlight_modified = 1; | |||||
} | |||||
else { | |||||
backlight = (backlight + 1) % (BACKLIGHT_LEVELS); | |||||
} | |||||
softpwm_led_set(1, 32 * (backlight + 1)); | |||||
} |
/* | |||||
Copyright 2014 Kai Ryu <[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 <stdint.h> | |||||
#include "action.h" | |||||
#include "action_layer.h" | |||||
#include "backlight.h" | |||||
#include "softpwm_led.h" | |||||
#include "eeconfig.h" | |||||
#include "keymap_common.h" | |||||
#include "tentapad.h" | |||||
#include "debug.h" | |||||
uint8_t config_mode = 0; | |||||
static uint8_t layer = 0; | |||||
static uint8_t backlight = 0; | |||||
static uint8_t layer_modified = 0; | |||||
static uint8_t backlight_modified = 0; | |||||
extern uint8_t backlight_mode; | |||||
extern const uint8_t backlight_brightness; | |||||
void action_keyevent(keyevent_t event) | |||||
{ | |||||
uint8_t key = event.key.col; | |||||
if (config_mode) { | |||||
/* config mode */ | |||||
switch (key) { | |||||
case KEY_K1: | |||||
if (event.pressed) { | |||||
switch_layout(); | |||||
} | |||||
break; | |||||
case KEY_K2: | |||||
if (event.pressed) { | |||||
switch_backlight(); | |||||
} | |||||
break; | |||||
case KEY_CFG: | |||||
if (event.pressed) { | |||||
exit_config_mode(); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
else { | |||||
/* normal mode */ | |||||
switch (key) { | |||||
case KEY_K1: case KEY_K2: | |||||
if (event.pressed) { | |||||
/* press */ | |||||
switch (backlight_mode) { | |||||
case 0: case 6: | |||||
softpwm_led_on(key); | |||||
break; | |||||
case 1: case 2: | |||||
softpwm_led_increase(LED_KEY_SIDE - 1 + backlight_mode, 32); | |||||
case 3 ... 5: | |||||
softpwm_led_set(key, backlight_brightness); | |||||
break; | |||||
} | |||||
} | |||||
else { | |||||
/* release */ | |||||
switch (backlight_mode) { | |||||
case 0: case 6: | |||||
softpwm_led_off(key); | |||||
break; | |||||
case 1 ... 5: | |||||
softpwm_led_set(key, 0); | |||||
break; | |||||
} | |||||
} | |||||
break; | |||||
case KEY_TT: | |||||
if (event.pressed) { | |||||
switch (backlight_mode) { | |||||
case 1: case 2: | |||||
softpwm_led_increase(LED_KEY_SIDE - 1 + backlight_mode, 32); | |||||
break; | |||||
} | |||||
} | |||||
break; | |||||
case KEY_CFG: | |||||
if (event.pressed) { | |||||
enter_config_mode(); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
void enter_config_mode(void) | |||||
{ | |||||
config_mode = 1; | |||||
layer_modified = 0; | |||||
backlight_modified = 0; | |||||
backlight = backlight_mode; | |||||
backlight_level(8); | |||||
layer_on(CONFIG_LAYER); | |||||
} | |||||
void exit_config_mode(void) | |||||
{ | |||||
config_mode = 0; | |||||
backlight_level(backlight); | |||||
layer_off(CONFIG_LAYER); | |||||
if (layer_modified) { | |||||
default_layer_set(1UL<<layer); | |||||
eeconfig_write_default_layer(1UL<<layer); | |||||
} | |||||
} | |||||
void switch_layout(void) | |||||
{ | |||||
if (!layer_modified) { | |||||
layer = 0; | |||||
layer_modified = 1; | |||||
} | |||||
else { | |||||
layer = (layer + 1) % (last_layer() + 1); | |||||
} | |||||
xprintf("layer: %d\n", layer); | |||||
xprintf("last layer: %d\n", last_layer()); | |||||
softpwm_led_set(0, 32 * (layer + 1)); | |||||
} | |||||
void switch_backlight(void) | |||||
{ | |||||
if (!backlight_modified) { | |||||
backlight = 0; | |||||
backlight_modified = 1; | |||||
} | |||||
else { | |||||
backlight = (backlight + 1) % (BACKLIGHT_LEVELS); | |||||
} | |||||
xprintf("backlight: %d\n", backlight); | |||||
softpwm_led_set(1, 32 * (backlight + 1)); | |||||
} |
/* | |||||
Copyright 2014 Kai Ryu <[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 TENTAPAD_H | |||||
#define TENTAPAD_H | |||||
enum { | |||||
KEY_K1 = 0, | |||||
KEY_K2, | |||||
KEY_TT, | |||||
KEY_TP, | |||||
KEY_CFG | |||||
}; | |||||
enum { | |||||
LED_KEY_1 = 0, | |||||
LED_KEY_2, | |||||
LED_KEY_SIDE, | |||||
LED_BOARD_SIDE | |||||
}; | |||||
#define CONFIG_LAYER 31 | |||||
void enter_config_mode(void); | |||||
void exit_config_mode(void); | |||||
void switch_layout(void); | |||||
void switch_backlight(void); | |||||
#endif | |||||