Added macros to Dynamic Keymaps, Zeal60 RGB backlight improvements (#4520)

* Refactored M6-B to use Zeal60 RGB backlight code

* Fixed M6-B LED co-ordinates

* Minor changes to RGB config for Zeal65

* Added dynamic keymaps to WT80-A, WT60-A, WT-80A, U80-A

* Macro implementation

* Implemented macros, API protocol version 8, RGB backlight fixes

* Improved radial effects for M6-B

* Fixed undefined references when building an RGB keyboard after M6-A
master
Wilba 2018-12-01 03:43:34 +11:00 committed by Drashna Jaelre
parent b10aad45b6
commit d7f1e072a8
22 changed files with 569 additions and 114 deletions

View File

@ -31,7 +31,7 @@
#define MATRIX_ROWS 5 #define MATRIX_ROWS 5
#define MATRIX_COLS 14 #define MATRIX_COLS 14
// Zeal60 PCB default pin-out // M60-A PCB default pin-out
#define MATRIX_ROW_PINS { F0, F1, F4, F6, F7 } #define MATRIX_ROW_PINS { F0, F1, F4, F6, F7 }
#define MATRIX_COL_PINS { F5, D5, B1, B2, B3, D3, D2, C7, C6, B6, B5, B4, D7, D6 } #define MATRIX_COL_PINS { F5, D5, B1, B2, B3, D3, D2, C7, C6, B6, B5, B4, D7, D6 }
#define UNUSED_PINS #define UNUSED_PINS
@ -118,11 +118,14 @@
// Bump this every time we change what we store // Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults // This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM // and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x08
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version // Backlight config starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic keymap starts after backlight config (35+31)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_EEPROM_ADDR 66
// Dynamic macro starts after dynamic keymaps (66+(4*5*14*2)) = (66+560)
#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 626
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 398
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -1,8 +1,8 @@
# project specific files # project specific files
SRC = ../zeal60/zeal60.c \ SRC = keyboards/zeal60/zeal60.c \
../zeal60/rgb_backlight.c \ keyboards/zeal60/rgb_backlight.c \
quantum/color.c \ quantum/color.c \
drivers/issi/is31fl3731.c \ drivers/issi/is31fl3731.c \
drivers/avr/i2c_master.c drivers/avr/i2c_master.c

View File

@ -119,11 +119,17 @@
// Bump this every time we change what we store // Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults // This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM // and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x08
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// NOTE: M6-A doesn't use RGB backlight, but we keep this
// consistent with M6-B which does.
// Backlight config starts after EEPROM version // Backlight config starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic keymap starts after backlight config (35+43)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_EEPROM_ADDR 78
// Dynamic macro starts after dynamic keymaps (78+(4*6*2)) = (78+48)
#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 126
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 898
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -1,5 +1,5 @@
# project specific files # project specific files
SRC = ../zeal60/zeal60.c SRC = keyboards/zeal60/zeal60.c
# MCU name # MCU name
MCU = atmega32u4 MCU = atmega32u4

View File

@ -150,11 +150,14 @@
// Bump this every time we change what we store // Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults // This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM // and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x08
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version // Backlight config starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic keymap starts after backlight config (35+43)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_EEPROM_ADDR 78
// Dynamic macro starts after dynamic keymaps (78+(4*6*2)) = (78+48)
#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 126
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 898
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -1,6 +1,6 @@
# project specific files # project specific files
SRC = ../zeal60/zeal60.c \ SRC = keyboards/zeal60/zeal60.c \
../zeal60/rgb_backlight.c \ keyboards/zeal60/rgb_backlight.c \
quantum/color.c \ quantum/color.c \
drivers/issi/is31fl3218.c \ drivers/issi/is31fl3218.c \
drivers/avr/i2c_master.c drivers/avr/i2c_master.c

View File

@ -198,7 +198,9 @@
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x07
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version // Dynamic keymap starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define DYNAMIC_KEYMAP_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic macro starts after dynamic keymaps (35+(4*6*17*2)) = (35+816)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 851
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 173
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -195,10 +195,12 @@
// Bump this every time we change what we store // Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults // This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM // and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x08
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version // Dynamic keymap starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define DYNAMIC_KEYMAP_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic macro starts after dynamic keymaps (35+(4*5*14*2)) = (35+560)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 595
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 429
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -195,10 +195,12 @@
// Bump this every time we change what we store // Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults // This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM // and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x08
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version // Dynamic keymap starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define DYNAMIC_KEYMAP_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic macro starts after dynamic keymaps (35+(4*5*15*2)) = (35+600)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 635
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 389
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -195,10 +195,12 @@
// Bump this every time we change what we store // Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults // This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM // and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x08
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version // Dynamic keymap starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define DYNAMIC_KEYMAP_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic macro starts after dynamic keymaps (35+(4*6*17*2)) = (35+816)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 851
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 173
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -17,6 +17,7 @@
#include "quantum.h" #include "quantum.h"
#include "keyboards/wilba_tech/wt_mono_backlight.h" #include "keyboards/wilba_tech/wt_mono_backlight.h"
#include "keyboards/zeal60/zeal60_api.h" // Temporary hack #include "keyboards/zeal60/zeal60_api.h" // Temporary hack
#include "keyboards/zeal60/zeal60_keycodes.h" // Temporary hack
#include "raw_hid.h" #include "raw_hid.h"
#include "dynamic_keymap.h" #include "dynamic_keymap.h"
@ -91,22 +92,57 @@ void raw_hid_receive( uint8_t *data, uint8_t length )
dynamic_keymap_reset(); dynamic_keymap_reset();
break; break;
} }
case id_dynamic_keymap_macro_get_count:
{
command_data[0] = dynamic_keymap_macro_get_count();
break;
}
case id_dynamic_keymap_macro_get_buffer_size:
{
uint16_t size = dynamic_keymap_macro_get_buffer_size();
command_data[0] = size >> 8;
command_data[1] = size & 0xFF;
break;
}
case id_dynamic_keymap_macro_get_buffer:
{
uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
uint16_t size = command_data[2]; // size <= 28
dynamic_keymap_macro_get_buffer( offset, size, &command_data[3] );
break;
}
case id_dynamic_keymap_macro_set_buffer:
{
uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
uint16_t size = command_data[2]; // size <= 28
dynamic_keymap_macro_set_buffer( offset, size, &command_data[3] );
break;
}
case id_dynamic_keymap_macro_reset:
{
dynamic_keymap_macro_reset();
break;
}
case id_dynamic_keymap_get_layer_count:
{
command_data[0] = dynamic_keymap_get_layer_count();
break;
}
case id_dynamic_keymap_get_buffer:
{
uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
uint16_t size = command_data[2]; // size <= 28
dynamic_keymap_get_buffer( offset, size, &command_data[3] );
break;
}
case id_dynamic_keymap_set_buffer:
{
uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
uint16_t size = command_data[2]; // size <= 28
dynamic_keymap_set_buffer( offset, size, &command_data[3] );
break;
}
#endif // DYNAMIC_KEYMAP_ENABLE #endif // DYNAMIC_KEYMAP_ENABLE
case id_backlight_config_set_value:
{
//backlight_config_set_value(command_data);
break;
}
case id_backlight_config_get_value:
{
//backlight_config_get_value(command_data);
break;
}
case id_backlight_config_save:
{
//backlight_config_save();
break;
}
case id_eeprom_reset: case id_eeprom_reset:
{ {
eeprom_reset(); eeprom_reset();
@ -151,6 +187,8 @@ void main_init(void)
#ifdef DYNAMIC_KEYMAP_ENABLE #ifdef DYNAMIC_KEYMAP_ENABLE
// This resets the keymaps in EEPROM to what is in flash. // This resets the keymaps in EEPROM to what is in flash.
dynamic_keymap_reset(); dynamic_keymap_reset();
// This resets the macros in EEPROM to nothing.
dynamic_keymap_macro_reset();
#endif #endif
// Save the magic number last, in case saving was interrupted // Save the magic number last, in case saving was interrupted
eeprom_set_valid(true); eeprom_set_valid(true);
@ -196,3 +234,43 @@ void matrix_scan_kb(void)
backlight_update_pwm_buffers(); backlight_update_pwm_buffers();
matrix_scan_user(); matrix_scan_user();
} }
bool process_record_kb(uint16_t keycode, keyrecord_t *record)
{
switch(keycode) {
case FN_MO13:
if (record->event.pressed) {
layer_on(1);
update_tri_layer(1, 2, 3);
} else {
layer_off(1);
update_tri_layer(1, 2, 3);
}
return false;
break;
case FN_MO23:
if (record->event.pressed) {
layer_on(2);
update_tri_layer(1, 2, 3);
} else {
layer_off(2);
update_tri_layer(1, 2, 3);
}
return false;
break;
}
#ifdef DYNAMIC_KEYMAP_ENABLE
// Handle macros
if (record->event.pressed) {
if ( keycode >= MACRO00 && keycode <= MACRO15 )
{
uint8_t id = keycode - MACRO00;
dynamic_keymap_macro_send(id);
return false;
}
}
#endif //DYNAMIC_KEYMAP_ENABLE
return process_record_user(keycode, record);
}

View File

@ -115,11 +115,15 @@
// Bump this every time we change what we store // Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults // This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM // and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x08
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version // Backlight config starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic keymap starts after backlight config (35+31)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_EEPROM_ADDR 66
// Dynamic macro starts after dynamic keymaps (66+(4*5*14*2)) = (66+560)
#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 626
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 398
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -15,9 +15,9 @@
*/ */
#if RGB_BACKLIGHT_ENABLED #if RGB_BACKLIGHT_ENABLED
#if defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_ZEAL65) || defined (RGB_BACKLIGHT_M60_A) || defined(RGB_BACKLIGHT_M6_B) #if defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_ZEAL65) || defined (RGB_BACKLIGHT_M60_A) || defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_KOYU)
#else #else
#error None of the following was defined: RGB_BACKLIGHT_ZEAL60, RGB_BACKLIGHT_ZEAL65, RGB_BACKLIGHT_M60_A, RGB_BACKLIGHT_M6_B #error None of the following was defined: RGB_BACKLIGHT_ZEAL60, RGB_BACKLIGHT_ZEAL65, RGB_BACKLIGHT_M60_A, RGB_BACKLIGHT_M6_B, RGB_BACKLIGHT_KOYU
#endif #endif
#include "quantum.h" #include "quantum.h"
@ -55,18 +55,21 @@ backlight_config g_config = {
.brightness = 255, .brightness = 255,
.effect = RGB_BACKLIGHT_EFFECT, .effect = RGB_BACKLIGHT_EFFECT,
.effect_speed = 0, .effect_speed = 0,
.color_1 = { .h = 0, .s = 255, .v = 255 }, .color_1 = { .h = 0, .s = 255 },
.color_2 = { .h = 127, .s = 255, .v = 255 }, .color_2 = { .h = 127, .s = 255 },
.caps_lock_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, .caps_lock_indicator = { .color = { .h = 0, .s = 0 }, .index = 255 },
.layer_1_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, .layer_1_indicator = { .color = { .h = 0, .s = 0 }, .index = 255 },
.layer_2_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, .layer_2_indicator = { .color = { .h = 0, .s = 0 }, .index = 255 },
.layer_3_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, .layer_3_indicator = { .color = { .h = 0, .s = 0 }, .index = 255 },
.alphas_mods = { .alphas_mods = {
RGB_BACKLIGHT_ALPHAS_MODS_ROW_0, RGB_BACKLIGHT_ALPHAS_MODS_ROW_0,
RGB_BACKLIGHT_ALPHAS_MODS_ROW_1, RGB_BACKLIGHT_ALPHAS_MODS_ROW_1,
RGB_BACKLIGHT_ALPHAS_MODS_ROW_2, RGB_BACKLIGHT_ALPHAS_MODS_ROW_2,
RGB_BACKLIGHT_ALPHAS_MODS_ROW_3, RGB_BACKLIGHT_ALPHAS_MODS_ROW_3,
RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 } RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 },
#if defined(RGB_BACKLIGHT_M6_B)
.custom_color = { { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 }, { 171, 255 }, { 213, 255 } }
#endif
}; };
bool g_suspend_state = false; bool g_suspend_state = false;
@ -199,7 +202,7 @@ const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
}; };
const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
// LA0..LA17 // LA0..LA17
{64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,247}, {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
{61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255}, {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
// LB0..LB17 // LB0..LB17
{56,255}, {51,255}, {46,255}, {42,255}, {37,255}, {35,255}, {32,255}, {19,255}, {0,255}, {56,255}, {51,255}, {46,255}, {42,255}, {37,255}, {35,255}, {32,255}, {19,255}, {0,255},
@ -208,8 +211,37 @@ const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
{184,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {255,255}, {167,255}, {165,255}, {184,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {255,255}, {167,255}, {165,255},
{128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {145,233}, {148,255}, {161,255}, {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {145,233}, {148,255}, {161,255},
// LD0..LD17 // LD0..LD17
{0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {255,201}, {224,181}, {230,217}, {235,255}, {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
{189,128}, {200,131}, {210,141}, {218,159}, {201,228}, {201,228}, {206,255}, {213,255}, {218,255} {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {201,228}, {206,255}, {213,255}, {218,255}
};
#elif defined (RGB_BACKLIGHT_KOYU)
const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
// LA0..LA17
{120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
{128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
// LB0..LB17
{144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {240,0}, {240,16}, {240,32},
{136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64},
// LC0..LC17
{112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,60}, {24,64},
{108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64},
// LD0..LD17
{124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
{116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {208,64}, {255,255}
};
const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
// LA0..LA17
{64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
{61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
// LB0..LB17
{56,255}, {51,255}, {46,255}, {42,255}, {38,255}, {35,255}, {32,255}, {19,255}, {0,255},
{53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255},
// LC0..LC17
{189,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {172,252}, {169,255}, {165,255},
{128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {255,255}, {148,255}, {161,255},
// LD0..LD17
{0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
{189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {207,238}, {211,255}, {218,255}, {255,255}
}; };
#elif defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_M60_A) #elif defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_M60_A)
const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
@ -248,7 +280,7 @@ const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
{0,0}, {0,16}, {16,16}, {16,0}, {32,16}, {32,0} {0,0}, {0,16}, {16,16}, {16,0}, {32,16}, {32,0}
}; };
const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
{0,0}, {0,16}, {16,16}, {16,0}, {32,16}, {32,0} {160,255}, {96,255}, {77,255}, {179,255}, {51,255}, {205,255}
}; };
#endif #endif
@ -318,7 +350,7 @@ void map_led_to_point_polar( uint8_t index, Point *point )
#if defined (RGB_BACKLIGHT_ZEAL65) #if defined (RGB_BACKLIGHT_ZEAL65)
// Note: Left spacebar stab is at 4,3 (LC7) // Note: Left spacebar stab is at 4,2 (LC7)
// Right spacebar stab is at 4,9 (D14) // Right spacebar stab is at 4,9 (D14)
// //
// A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6 // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6
@ -333,6 +365,22 @@ const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
{ 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8, 18+15 }, { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8, 18+15 },
{ 36+17, 36+8, 36+7, 255, 255, 255, 255, 36+0, 255, 54+14, 54+15, 54+16, 54+17, 18+17, 18+16 } { 36+17, 36+8, 36+7, 255, 255, 255, 255, 36+0, 255, 54+14, 54+15, 54+16, 54+17, 18+17, 18+16 }
}; };
#elif defined(RGB_BACKLIGHT_KOYU)
// Note: Left spacebar stab is at 4,4 (LC6)
// Right spacebar stab is at 4,10 (D14)
//
// A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6
// A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7
// A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8
// C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15
// C17, C8, C7, C6, ---, ---, ---, C0, ---, ---, D14, D15, D16, B17, B16
const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
{ 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4, 18+6 },
{ 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14, 18+7 },
{ 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5, 18+8 },
{ 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8, 18+15 },
{ 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 255, 54+14, 54+15, 54+16, 18+17, 18+16 }
};
#elif defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_M60_A) #elif defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_M60_A)
// Note: Left spacebar stab is at 4,3 (LC6) // Note: Left spacebar stab is at 4,3 (LC6)
// Right spacebar stab is at 4,9 (LD13) or 4,10 (LD14) // Right spacebar stab is at 4,9 (LD13) or 4,10 (LD14)
@ -781,8 +829,24 @@ void backlight_effect_cycle_radial2(void)
} }
} }
void backlight_effect_indicators_set_colors( uint8_t index, HSV hsv ) #if defined(RGB_BACKLIGHT_M6_B)
void backlight_effect_custom_colors(void)
{ {
RGB rgb;
for ( uint8_t i = 0; i < 6; i++ )
{
HSV hsv = { .h = g_config.custom_color[i].h, .s = g_config.custom_color[i].s, .v = g_config.brightness };
rgb = hsv_to_rgb( hsv );
uint8_t led;
map_row_column_to_led( 0, i, &led );
backlight_set_color( led, rgb.r, rgb.g, rgb.b );
}
}
#endif
void backlight_effect_indicators_set_colors( uint8_t index, HS color )
{
HSV hsv = { .h = color.h, .s = color.s, .v = g_config.brightness };
RGB rgb = hsv_to_rgb( hsv ); RGB rgb = hsv_to_rgb( hsv );
if ( index == 254 ) if ( index == 254 )
{ {
@ -799,6 +863,9 @@ void backlight_effect_indicators_set_colors( uint8_t index, HSV hsv )
#if defined (RGB_BACKLIGHT_ZEAL65) #if defined (RGB_BACKLIGHT_ZEAL65)
backlight_set_color( 36+7, rgb.r, rgb.g, rgb.b ); // LC7 backlight_set_color( 36+7, rgb.r, rgb.g, rgb.b ); // LC7
backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14 backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
#elif defined (RGB_BACKLIGHT_KOYU)
backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6
backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
#elif defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_M60_A) #elif defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_M60_A)
backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6 backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6
backlight_set_color( 54+13, rgb.r, rgb.g, rgb.b ); // LD13 backlight_set_color( 54+13, rgb.r, rgb.g, rgb.b ); // LD13
@ -911,7 +978,11 @@ ISR(TIMER3_COMPA_vect)
backlight_effect_solid_color(); backlight_effect_solid_color();
break; break;
case 2: case 2:
#if defined(RGB_BACKLIGHT_M6_B)
backlight_effect_custom_colors();
#else
backlight_effect_alphas_mods(); backlight_effect_alphas_mods();
#endif
break; break;
case 3: case 3:
backlight_effect_gradient_up_down(); backlight_effect_gradient_up_down();
@ -989,18 +1060,16 @@ void backlight_get_indicator_row_col( uint8_t index, uint8_t *row, uint8_t *colu
} }
// Some helpers for setting/getting HSV // Some helpers for setting/getting HSV
void _set_color( HSV *color, uint8_t *data ) void _set_color( HS *color, uint8_t *data )
{ {
color->h = data[0]; color->h = data[0];
color->s = data[1]; color->s = data[1];
color->v = data[2];
} }
void _get_color( HSV *color, uint8_t *data ) void _get_color( HS *color, uint8_t *data )
{ {
data[0] = color->h; data[0] = color->h;
data[1] = color->s; data[1] = color->s;
data[2] = color->v;
} }
void backlight_config_set_value( uint8_t *data ) void backlight_config_set_value( uint8_t *data )
@ -1132,6 +1201,16 @@ void backlight_config_set_value( uint8_t *data )
g_config.alphas_mods[i] = ( *(value_data+i*2) << 8 ) | ( *(value_data+i*2+1) ); g_config.alphas_mods[i] = ( *(value_data+i*2) << 8 ) | ( *(value_data+i*2+1) );
} }
} }
#if defined(RGB_BACKLIGHT_M6_B)
case id_custom_color:
{
uint8_t index = value_data[0];
if ( index >= 0 && index <= 6 )
{
_set_color( &(g_config.custom_color[index]), &(value_data[1]) );
}
}
#endif
} }
if ( reinitialize ) if ( reinitialize )
@ -1259,6 +1338,16 @@ void backlight_config_get_value( uint8_t *data )
*(value_data+i*2+1) = g_config.alphas_mods[i] & 0xFF; *(value_data+i*2+1) = g_config.alphas_mods[i] & 0xFF;
} }
} }
#if defined(RGB_BACKLIGHT_M6_B)
case id_custom_color:
{
uint8_t index = value_data[0];
if ( index >= 0 && index <= 6 )
{
_get_color( &(g_config.custom_color[index]), &(value_data[1]) );
}
}
#endif
} }
} }
@ -1301,6 +1390,10 @@ void backlight_init_drivers(void)
bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5 bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5
( index == 36+6 ) || // LC6 ( index == 36+6 ) || // LC6
( index == 54+13 ) ); // LD13 ( index == 54+13 ) ); // LD13
#elif defined (RGB_BACKLIGHT_KOYU)
bool enabled = !( ( index == 36+15 ) || // LC15
( index == 54+13 ) || // LD13
( index == 54+17 ) ); // LD17
#elif defined (RGB_BACKLIGHT_M60_A) #elif defined (RGB_BACKLIGHT_M60_A)
bool enabled = !( bool enabled = !(
// LB6 LB7 LB8 LB15 LB16 LB17 not present on M60-A // LB6 LB7 LB8 LB15 LB16 LB17 not present on M60-A

View File

@ -25,9 +25,15 @@
#include "quantum/color.h" #include "quantum/color.h"
typedef struct PACKED
{
uint8_t h;
uint8_t s;
} HS;
typedef struct typedef struct
{ {
HSV color; HS color;
uint8_t index; uint8_t index;
} backlight_config_indicator; } backlight_config_indicator;
@ -45,14 +51,17 @@ typedef struct
uint8_t brightness; // 1 byte uint8_t brightness; // 1 byte
uint8_t effect; // 1 byte uint8_t effect; // 1 byte
uint8_t effect_speed; // 1 byte uint8_t effect_speed; // 1 byte
HSV color_1; // 3 bytes HS color_1; // 2 bytes
HSV color_2; // 3 bytes HS color_2; // 2 bytes
backlight_config_indicator caps_lock_indicator; // 4 bytes backlight_config_indicator caps_lock_indicator; // 3 bytes
backlight_config_indicator layer_1_indicator; // 4 bytes backlight_config_indicator layer_1_indicator; // 3 bytes
backlight_config_indicator layer_2_indicator; // 4 bytes backlight_config_indicator layer_2_indicator; // 3 bytes
backlight_config_indicator layer_3_indicator; // 4 bytes backlight_config_indicator layer_3_indicator; // 3 bytes
uint16_t alphas_mods[5]; // 10 bytes uint16_t alphas_mods[5]; // 10 bytes
} backlight_config; // = 37 bytes #if defined(RGB_BACKLIGHT_M6_B)
HS custom_color[6]; // 12 bytes
#endif
} backlight_config; // = 31 bytes (M6-B = 43 bytes)
void backlight_config_load(void); void backlight_config_load(void);
void backlight_config_save(void); void backlight_config_save(void);

View File

@ -38,5 +38,6 @@ enum backlight_config_value
id_layer_2_indicator_row_col = 0x13, id_layer_2_indicator_row_col = 0x13,
id_layer_3_indicator_color = 0x14, id_layer_3_indicator_color = 0x14,
id_layer_3_indicator_row_col = 0x15, id_layer_3_indicator_row_col = 0x15,
id_alphas_mods = 0x16 id_alphas_mods = 0x16,
id_custom_color = 0x17
}; };

View File

@ -94,6 +94,56 @@ void raw_hid_receive( uint8_t *data, uint8_t length )
dynamic_keymap_reset(); dynamic_keymap_reset();
break; break;
} }
case id_dynamic_keymap_macro_get_count:
{
command_data[0] = dynamic_keymap_macro_get_count();
break;
}
case id_dynamic_keymap_macro_get_buffer_size:
{
uint16_t size = dynamic_keymap_macro_get_buffer_size();
command_data[0] = size >> 8;
command_data[1] = size & 0xFF;
break;
}
case id_dynamic_keymap_macro_get_buffer:
{
uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
uint16_t size = command_data[2]; // size <= 28
dynamic_keymap_macro_get_buffer( offset, size, &command_data[3] );
break;
}
case id_dynamic_keymap_macro_set_buffer:
{
uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
uint16_t size = command_data[2]; // size <= 28
dynamic_keymap_macro_set_buffer( offset, size, &command_data[3] );
break;
}
case id_dynamic_keymap_macro_reset:
{
dynamic_keymap_macro_reset();
break;
}
case id_dynamic_keymap_get_layer_count:
{
command_data[0] = dynamic_keymap_get_layer_count();
break;
}
case id_dynamic_keymap_get_buffer:
{
uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
uint16_t size = command_data[2]; // size <= 28
dynamic_keymap_get_buffer( offset, size, &command_data[3] );
break;
}
case id_dynamic_keymap_set_buffer:
{
uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
uint16_t size = command_data[2]; // size <= 28
dynamic_keymap_set_buffer( offset, size, &command_data[3] );
break;
}
#endif // DYNAMIC_KEYMAP_ENABLE #endif // DYNAMIC_KEYMAP_ENABLE
#if RGB_BACKLIGHT_ENABLED #if RGB_BACKLIGHT_ENABLED
case id_backlight_config_set_value: case id_backlight_config_set_value:
@ -160,6 +210,8 @@ void main_init(void)
#ifdef DYNAMIC_KEYMAP_ENABLE #ifdef DYNAMIC_KEYMAP_ENABLE
// This resets the keymaps in EEPROM to what is in flash. // This resets the keymaps in EEPROM to what is in flash.
dynamic_keymap_reset(); dynamic_keymap_reset();
// This resets the macros in EEPROM to nothing.
dynamic_keymap_macro_reset();
#endif #endif
// Save the magic number last, in case saving was interrupted // Save the magic number last, in case saving was interrupted
eeprom_set_valid(true); eeprom_set_valid(true);
@ -238,7 +290,19 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record)
return false; return false;
break; break;
} }
#ifdef DYNAMIC_KEYMAP_ENABLE
// Handle macros
if (record->event.pressed) {
if ( keycode >= MACRO00 && keycode <= MACRO15 )
{
uint8_t id = keycode - MACRO00;
dynamic_keymap_macro_send(id);
return false;
}
}
#endif //DYNAMIC_KEYMAP_ENABLE
return process_record_user(keycode, record); return process_record_user(keycode, record);
} }
@ -263,28 +327,6 @@ uint16_t keymap_function_id_to_action( uint16_t function_id )
} }
} }
#if USE_KEYMAPS_IN_EEPROM
#if 0
// This is how to implement actions stored in EEPROM.
// Not yet implemented. Not sure if it's worth the trouble
// before we have a nice GUI for keymap editing.
if ( eeprom_is_valid() &&
function_id < 32 ) // TODO: replace magic number
{
uint16_t action = keymap_action_load(function_id);
// If action is not "empty", return it, otherwise
// drop down to return the one in flash
if ( action != 0x0000 ) // TODO: replace magic number
{
return action;
}
}
#endif
#endif // USE_KEYMAPS_IN_EEPROM
return pgm_read_word(&fn_actions[function_id]); return pgm_read_word(&fn_actions[function_id]);
} }

View File

@ -15,7 +15,7 @@
*/ */
#pragma once #pragma once
#define PROTOCOL_VERSION 0x0007 #define PROTOCOL_VERSION 0x0008
enum zeal60_command_id enum zeal60_command_id
{ {
@ -30,6 +30,14 @@ enum zeal60_command_id
id_backlight_config_save, id_backlight_config_save,
id_eeprom_reset, id_eeprom_reset,
id_bootloader_jump, id_bootloader_jump,
id_dynamic_keymap_macro_get_count,
id_dynamic_keymap_macro_get_buffer_size,
id_dynamic_keymap_macro_get_buffer,
id_dynamic_keymap_macro_set_buffer,
id_dynamic_keymap_macro_reset,
id_dynamic_keymap_get_layer_count,
id_dynamic_keymap_get_buffer,
id_dynamic_keymap_set_buffer,
id_unhandled = 0xFF, id_unhandled = 0xFF,
}; };

View File

@ -22,7 +22,23 @@
// Backlight keycodes are in range 0x5F00-0x5F0F // Backlight keycodes are in range 0x5F00-0x5F0F
enum zeal60_keycodes { enum zeal60_keycodes {
FN_MO13 = 0x5F10, FN_MO13 = 0x5F10,
FN_MO23 FN_MO23,
MACRO00,
MACRO01,
MACRO02,
MACRO03,
MACRO04,
MACRO05,
MACRO06,
MACRO07,
MACRO08,
MACRO09,
MACRO10,
MACRO11,
MACRO12,
MACRO13,
MACRO14,
MACRO15,
}; };
// Zeal60 specific "action functions" // Zeal60 specific "action functions"

View File

@ -115,11 +115,15 @@
// Bump this every time we change what we store // Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults // This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM // and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07 #define EEPROM_VERSION 0x08
#define EEPROM_VERSION_ADDR 34 #define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version // Backlight config starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37) // Dynamic keymap starts after backlight config (35+31)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 #define DYNAMIC_KEYMAP_EEPROM_ADDR 66
// Dynamic macro starts after dynamic keymaps (66+(4*5*15*2)) = (66+600)
#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 666
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 358
#define DYNAMIC_KEYMAP_MACRO_COUNT 16

View File

@ -1,8 +1,8 @@
# project specific files # project specific files
SRC = ../zeal60/zeal60.c \ SRC = keyboards/zeal60/zeal60.c \
../zeal60/rgb_backlight.c \ keyboards/zeal60/rgb_backlight.c \
quantum/color.c \ quantum/color.c \
drivers/issi/is31fl3731.c \ drivers/issi/is31fl3731.c \
drivers/avr/i2c_master.c drivers/avr/i2c_master.c

View File

@ -18,7 +18,7 @@
#include "keymap.h" // to get keymaps[][][] #include "keymap.h" // to get keymaps[][][]
#include "tmk_core/common/eeprom.h" #include "tmk_core/common/eeprom.h"
#include "progmem.h" // to read default from flash #include "progmem.h" // to read default from flash
#include "quantum.h" // for send_string()
#include "dynamic_keymap.h" #include "dynamic_keymap.h"
#ifdef DYNAMIC_KEYMAP_ENABLE #ifdef DYNAMIC_KEYMAP_ENABLE
@ -31,6 +31,23 @@
#error DYNAMIC_KEYMAP_LAYER_COUNT not defined #error DYNAMIC_KEYMAP_LAYER_COUNT not defined
#endif #endif
#ifndef DYNAMIC_KEYMAP_MACRO_COUNT
#error DYNAMIC_KEYMAP_MACRO_COUNT not defined
#endif
#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
#error DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR not defined
#endif
#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE
#error DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE not defined
#endif
uint8_t dynamic_keymap_get_layer_count(void)
{
return DYNAMIC_KEYMAP_LAYER_COUNT;
}
void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column) void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column)
{ {
// TODO: optimize this with some left shifts // TODO: optimize this with some left shifts
@ -69,6 +86,36 @@ void dynamic_keymap_reset(void)
} }
} }
void dynamic_keymap_get_buffer( uint16_t offset, uint16_t size, uint8_t *data )
{
uint16_t dynamic_keymap_eeprom_size = DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2;
void *source = (void*)(DYNAMIC_KEYMAP_EEPROM_ADDR+offset);
uint8_t *target = data;
for ( uint16_t i = 0; i < size; i++ ) {
if ( offset + i < dynamic_keymap_eeprom_size ) {
*target = eeprom_read_byte(source);
} else {
*target = 0x00;
}
source++;
target++;
}
}
void dynamic_keymap_set_buffer( uint16_t offset, uint16_t size, uint8_t *data )
{
uint16_t dynamic_keymap_eeprom_size = DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2;
void *target = (void*)(DYNAMIC_KEYMAP_EEPROM_ADDR+offset);
uint8_t *source = data;
for ( uint16_t i = 0; i < size; i++ ) {
if ( offset + i < dynamic_keymap_eeprom_size ) {
eeprom_update_byte(target, *source);
}
source++;
target++;
}
}
// This overrides the one in quantum/keymap_common.c // This overrides the one in quantum/keymap_common.c
uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
{ {
@ -81,5 +128,103 @@ uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
} }
} }
uint8_t dynamic_keymap_macro_get_count(void)
{
return DYNAMIC_KEYMAP_MACRO_COUNT;
}
uint16_t dynamic_keymap_macro_get_buffer_size(void)
{
return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE;
}
void dynamic_keymap_macro_get_buffer( uint16_t offset, uint16_t size, uint8_t *data )
{
void *source = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+offset);
uint8_t *target = data;
for ( uint16_t i = 0; i < size; i++ ) {
if ( offset + i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE ) {
*target = eeprom_read_byte(source);
} else {
*target = 0x00;
}
source++;
target++;
}
}
void dynamic_keymap_macro_set_buffer( uint16_t offset, uint16_t size, uint8_t *data )
{
void *target = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+offset);
uint8_t *source = data;
for ( uint16_t i = 0; i < size; i++ ) {
if ( offset + i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE ) {
eeprom_update_byte(target, *source);
}
source++;
target++;
}
}
void dynamic_keymap_macro_reset(void)
{
void *p = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
void *end = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
while ( p != end ) {
eeprom_update_byte(p, 0);
++p;
}
}
void dynamic_keymap_macro_send( uint8_t id )
{
if ( id >= DYNAMIC_KEYMAP_MACRO_COUNT ) {
return;
}
// Check the last byte of the buffer.
// If it's not zero, then we are in the middle
// of buffer writing, possibly an aborted buffer
// write. So do nothing.
void *p = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE-1);
if ( eeprom_read_byte(p) != 0 ) {
return;
}
// Skip N null characters
// p will then point to the Nth macro
p = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
void *end = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR+DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
while ( id > 0 ) {
// If we are past the end of the buffer, then the buffer
// contents are garbage, i.e. there were not DYNAMIC_KEYMAP_MACRO_COUNT
// nulls in the buffer.
if ( p == end ) {
return;
}
if ( eeprom_read_byte(p) == 0 ) {
--id;
}
++p;
}
// Send the macro string one char at a time
// by making temporary 1 char strings
char data[2] = { 0, 0 };
// We already checked there was a null at the end of
// the buffer, so this cannot go past the end
while ( 1 ) {
data[0] = eeprom_read_byte(p);
// Stop at the null terminator of this macro string
if ( data[0] == 0 ) {
break;
}
send_string(data);
++p;
}
}
#endif // DYNAMIC_KEYMAP_ENABLE #endif // DYNAMIC_KEYMAP_ENABLE

View File

@ -18,11 +18,46 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
uint8_t dynamic_keymap_get_layer_count(void);
void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column); void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column);
uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column); uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column);
void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode); void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode);
void dynamic_keymap_reset(void); void dynamic_keymap_reset(void);
// These get/set the keycodes as stored in the EEPROM buffer
// Data is big-endian 16-bit values (the keycodes)
// Order is by layer/row/column
// Thus offset 0 = 0,0,0, offset MATRIX_COLS*2 = 0,1,0, offset MATRIX_ROWS*MATRIX_COLS*2 = 1,0,0
// Note the *2, because offset is in bytes and keycodes are two bytes
// This is only really useful for host applications that want to get a whole keymap fast,
// by reading 14 keycodes (28 bytes) at a time, reducing the number of raw HID transfers by
// a factor of 14.
void dynamic_keymap_get_buffer( uint16_t offset, uint16_t size, uint8_t *data );
void dynamic_keymap_set_buffer( uint16_t offset, uint16_t size, uint8_t *data );
// This overrides the one in quantum/keymap_common.c // This overrides the one in quantum/keymap_common.c
// uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); // uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
// Note regarding dynamic_keymap_macro_set_buffer():
// The last byte of the buffer is used as a valid flag,
// so macro sending is disabled during writing a new buffer,
// should it happen during, or after an interrupted transfer.
//
// Users writing to the buffer must first set the last byte of the buffer
// to non-zero (i.e. 0xFF). After (or during) the final write, set the
// last byte of the buffer to zero.
//
// Since the contents of the buffer must be a list of null terminated
// strings, the last byte must be a null when at maximum capacity,
// and it not being null means the buffer can be considered in an
// invalid state.
uint8_t dynamic_keymap_macro_get_count(void);
uint16_t dynamic_keymap_macro_get_buffer_size(void);
void dynamic_keymap_macro_get_buffer( uint16_t offset, uint16_t size, uint8_t *data );
void dynamic_keymap_macro_set_buffer( uint16_t offset, uint16_t size, uint8_t *data );
void dynamic_keymap_macro_reset(void);
void dynamic_keymap_macro_send( uint8_t id );