diff options
Diffstat (limited to 'keyboards/cannonkeys/satisfaction75')
8 files changed, 138 insertions, 238 deletions
diff --git a/keyboards/cannonkeys/satisfaction75/config.h b/keyboards/cannonkeys/satisfaction75/config.h index 8387289d8..7a4354c8a 100644 --- a/keyboards/cannonkeys/satisfaction75/config.h +++ b/keyboards/cannonkeys/satisfaction75/config.h @@ -64,41 +64,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #endif - -#define DYNAMIC_KEYMAP_LAYER_COUNT 4 - -// EEPROM usage - -// TODO: refactor with new user EEPROM code (coming soon) -#define EEPROM_MAGIC 0x451F -#define EEPROM_MAGIC_ADDR 40 -// Bump this every time we change what we store -// This will automatically reset the EEPROM with defaults -// and avoid loading invalid data from the EEPROM -#define EEPROM_VERSION 0x01 -#define EEPROM_VERSION_ADDR 42 - -// Dynamic keymap starts after EEPROM version -#define DYNAMIC_KEYMAP_EEPROM_ADDR 43 - -// Dynamic macro starts after dynamic keymaps (35+(4*6*16*2)) = (35+768) = 803 - -// I'm also putting my custom stuff after that -// 1 for enabled encoder modes -// 1 for custom backlighting controls -// 1 for OLED default mode -// 6 for 3x custom encoder settings, left, right, and press (18 total) - -#define DYNAMIC_KEYMAP_ENABLED_ENCODER_MODES 811 -#define DYNAMIC_KEYMAP_CUSTOM_BACKLIGHT 812 -#define DYNAMIC_KEYMAP_DEFAULT_OLED 813 -#define DYNAMIC_KEYMAP_CUSTOM_ENCODER 814 - -#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 832 -#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 192 -#define DYNAMIC_KEYMAP_MACRO_COUNT 16 - - +// Custom config starts after VIA's EEPROM usage, +// dynamic keymaps start after this. +// Custom config Usage: +// 1 for enabled encoder modes (1 byte) +// 1 for custom backlighting controls (1 byte) +// 1 for OLED default mode (1 byte) +// 6 for 3x custom encoder settings, left, right, and press (18 bytes) +#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 21 /* * Feature disable options diff --git a/keyboards/cannonkeys/satisfaction75/keymaps/boy_314/rules.mk b/keyboards/cannonkeys/satisfaction75/keymaps/boy_314/rules.mk index 0dcaa7318..6f45dc73e 100644 --- a/keyboards/cannonkeys/satisfaction75/keymaps/boy_314/rules.mk +++ b/keyboards/cannonkeys/satisfaction75/keymaps/boy_314/rules.mk @@ -1,4 +1,3 @@ # rules.mk overrides to enable VIA -RAW_ENABLE = yes -DYNAMIC_KEYMAP_ENABLE = yes +VIA_ENABLE = yes
\ No newline at end of file diff --git a/keyboards/cannonkeys/satisfaction75/keymaps/via/rules.mk b/keyboards/cannonkeys/satisfaction75/keymaps/via/rules.mk index d12497792..1e5b99807 100644 --- a/keyboards/cannonkeys/satisfaction75/keymaps/via/rules.mk +++ b/keyboards/cannonkeys/satisfaction75/keymaps/via/rules.mk @@ -1,5 +1 @@ -# rules.mk overrides to enable VIA - -RAW_ENABLE = yes -DYNAMIC_KEYMAP_ENABLE = yes - +VIA_ENABLE = yes diff --git a/keyboards/cannonkeys/satisfaction75/prototype/prototype.h b/keyboards/cannonkeys/satisfaction75/prototype/prototype.h index 42e574f3e..ed4c7d793 100644 --- a/keyboards/cannonkeys/satisfaction75/prototype/prototype.h +++ b/keyboards/cannonkeys/satisfaction75/prototype/prototype.h @@ -17,3 +17,20 @@ { K400, K401, K402, K403, K404, K405, K406, K407, K408, K409, K410, K411, KC_NO, K413, KC_NO, K415 }, \ { K500, K501, K502, KC_NO, KC_NO, K505, KC_NO, KC_NO, KC_NO, K509, K510, K511, K512, K513, KC_NO, K515 } \ } + +// Expose All Keys - Split backspace - ISO Extra keys - Split space bottom row +#define LAYOUT_all( \ + K000, K002, K003, K004, K005, K006, K007, K008, K009, K010, K011, K012, K013, \ + K100, K101, K102, K103, K104, K105, K106, K107, K108, K109, K110, K111, K112, K113, K114, K115, \ + K200, K201, K202, K203, K204, K205, K206, K207, K208, K209, K210, K211, K212, K213, K215, \ + K300, K301, K302, K303, K304, K305, K306, K307, K308, K309, K310, K311, K312, K313, K315, \ + K400, K401, K402, K403, K404, K405, K406, K407, K408, K409, K410, K411, K412, K413, K415, \ + K500, K501, K502, K503, K505, K507, K509, K510, K511, K512, K513, K515 \ +) { \ + { K000, KC_NO, K002, K003, K004, K005, K006, K007, K008, K009, K010, K011, K012, K013, KC_NO, KC_NO }, \ + { K100, K101, K102, K103, K104, K105, K106, K107, K108, K109, K110, K111, K112, K113, K114, K115 }, \ + { K200, K201, K202, K203, K204, K205, K206, K207, K208, K209, K210, K211, K212, K213, KC_NO, K215 }, \ + { K300, K301, K302, K303, K304, K305, K306, K307, K308, K309, K310, K311, K312, K313, KC_NO, K315 }, \ + { K400, K401, K402, K403, K404, K405, K406, K407, K408, K409, K410, K411, K412, K413, KC_NO, K415 }, \ + { K500, K501, K502, K503, KC_NO, K505, KC_NO, K507, KC_NO, K509, K510, K511, K512, K513, KC_NO, K515 } \ +} diff --git a/keyboards/cannonkeys/satisfaction75/rules.mk b/keyboards/cannonkeys/satisfaction75/rules.mk index 3e2877200..e81448d62 100644 --- a/keyboards/cannonkeys/satisfaction75/rules.mk +++ b/keyboards/cannonkeys/satisfaction75/rules.mk @@ -51,7 +51,4 @@ ENCODER_ENABLE = yes QWIIC_ENABLE += MICRO_OLED #BACKLIGHT_ENABLE = yes -# RAW_ENABLE = yes -# DYNAMIC_KEYMAP_ENABLE = yes - DEFAULT_FOLDER = cannonkeys/satisfaction75/rev1 diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.c b/keyboards/cannonkeys/satisfaction75/satisfaction75.c index 12d3660da..0fe09c384 100644 --- a/keyboards/cannonkeys/satisfaction75/satisfaction75.c +++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.c @@ -15,11 +15,7 @@ #include "raw_hid.h" #include "dynamic_keymap.h" #include "tmk_core/common/eeprom.h" - -// HACK -#include "keyboards/wilba_tech/via_api.h" // Temporary hack -#include "keyboards/wilba_tech/via_keycodes.h" // Temporary hack - +#include "version.h" // for QMK_BUILDDATE used in EEPROM magic /* Artificial delay added to get media keys to work in the encoder*/ #define MEDIA_KEY_DELAY 10 @@ -58,56 +54,20 @@ backlight_config_t kb_backlight_config = { .level = BACKLIGHT_LEVELS }; -bool eeprom_is_valid(void) -{ - return (eeprom_read_word(((void*)EEPROM_MAGIC_ADDR)) == EEPROM_MAGIC && - eeprom_read_byte(((void*)EEPROM_VERSION_ADDR)) == EEPROM_VERSION); -} - -void eeprom_set_valid(bool valid) +#ifdef VIA_ENABLE +void raw_hid_receive_kb( uint8_t *data, uint8_t length ) { - eeprom_update_word(((void*)EEPROM_MAGIC_ADDR), valid ? EEPROM_MAGIC : 0xFFFF); - eeprom_update_byte(((void*)EEPROM_VERSION_ADDR), valid ? EEPROM_VERSION : 0xFF); -} - -void eeprom_reset(void) -{ - // Set the VIA specific EEPROM state as invalid. - eeprom_set_valid(false); - // Set the TMK/QMK EEPROM state as invalid. - eeconfig_disable(); -} - -#ifdef RAW_ENABLE - -void raw_hid_receive( uint8_t *data, uint8_t length ) -{ - uint8_t *command_id = &(data[0]); - uint8_t *command_data = &(data[1]); - switch ( *command_id ) - { - case id_get_protocol_version: - { - command_data[0] = PROTOCOL_VERSION >> 8; - command_data[1] = PROTOCOL_VERSION & 0xFF; - break; - } - case id_get_keyboard_value: - { + uint8_t *command_id = &(data[0]); + uint8_t *command_data = &(data[1]); + switch ( *command_id ) + { + case id_get_keyboard_value: + { switch( command_data[0]) { - case id_uptime: - { - uint32_t value = timer_read32(); - command_data[1] = (value >> 24 ) & 0xFF; - command_data[2] = (value >> 16 ) & 0xFF; - command_data[3] = (value >> 8 ) & 0xFF; - command_data[4] = value & 0xFF; - break; - } case id_oled_default_mode: { - uint8_t default_oled = eeprom_read_byte((uint8_t*)DYNAMIC_KEYMAP_DEFAULT_OLED); + uint8_t default_oled = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED); command_data[1] = default_oled; break; } @@ -141,15 +101,14 @@ void raw_hid_receive( uint8_t *data, uint8_t length ) break; } } - break; + break; } -#ifdef DYNAMIC_KEYMAP_ENABLE case id_set_keyboard_value: { switch(command_data[0]){ case id_oled_default_mode: { - eeprom_update_byte((uint8_t*)DYNAMIC_KEYMAP_DEFAULT_OLED, command_data[1]); + eeprom_update_byte((uint8_t*)EEPROM_DEFAULT_OLED, command_data[1]); break; } case id_oled_mode: @@ -161,7 +120,7 @@ void raw_hid_receive( uint8_t *data, uint8_t length ) case id_encoder_modes: { enabled_encoder_modes = command_data[1]; - eeprom_update_byte((uint8_t*)DYNAMIC_KEYMAP_ENABLED_ENCODER_MODES, enabled_encoder_modes); + eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, enabled_encoder_modes); break; } case id_encoder_custom: @@ -180,95 +139,15 @@ void raw_hid_receive( uint8_t *data, uint8_t length ) } break; } - case id_dynamic_keymap_get_keycode: - { - uint16_t keycode = dynamic_keymap_get_keycode( command_data[0], command_data[1], command_data[2] ); - command_data[3] = keycode >> 8; - command_data[4] = keycode & 0xFF; - break; - } - case id_dynamic_keymap_set_keycode: - { - dynamic_keymap_set_keycode( command_data[0], command_data[1], command_data[2], ( command_data[3] << 8 ) | command_data[4] ); - break; - } - case id_dynamic_keymap_reset: - { - dynamic_keymap_reset(); - 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_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 - case id_eeprom_reset: - { - eeprom_reset(); - break; - } - case id_bootloader_jump: - { - // Need to send data back before the jump - // Informs host that the command is handled - raw_hid_send( data, length ); - // Give host time to read it - wait_ms(100); - bootloader_jump(); - break; - } - default: - { - // Unhandled message. - *command_id = id_unhandled; - break; - } - } - - // Return same buffer with values changed - raw_hid_send( data, length ); - + default: + { + // Unhandled message. + *command_id = id_unhandled; + break; + } + } + // DO NOT call raw_hid_send(data,length) here, let caller do this } - #endif @@ -349,18 +228,6 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { 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); } @@ -392,59 +259,56 @@ void encoder_update_kb(uint8_t index, bool clockwise) { } } -void dynamic_keymap_custom_reset(void){ - void *p = (void*)(DYNAMIC_KEYMAP_CUSTOM_BACKLIGHT); - void *end = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR); - while ( p != end ) { - eeprom_update_byte(p, 0); - ++p; - } - eeprom_update_byte((uint8_t*)DYNAMIC_KEYMAP_ENABLED_ENCODER_MODES, 0x1F); +void custom_config_reset(void){ + void *p = (void*)(VIA_EEPROM_CUSTOM_CONFIG_ADDR); + void *end = (void*)(VIA_EEPROM_CUSTOM_CONFIG_ADDR+VIA_EEPROM_CUSTOM_CONFIG_SIZE); + while ( p != end ) { + eeprom_update_byte(p, 0); + ++p; + } + eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, 0x1F); } -void save_backlight_config_to_eeprom(){ - eeprom_update_byte((uint8_t*)DYNAMIC_KEYMAP_CUSTOM_BACKLIGHT, kb_backlight_config.raw); +void backlight_config_save(){ + eeprom_update_byte((uint8_t*)EEPROM_CUSTOM_BACKLIGHT, kb_backlight_config.raw); } -void load_custom_config(){ - kb_backlight_config.raw = eeprom_read_byte((uint8_t*)DYNAMIC_KEYMAP_CUSTOM_BACKLIGHT); +void custom_config_load(){ + kb_backlight_config.raw = eeprom_read_byte((uint8_t*)EEPROM_CUSTOM_BACKLIGHT); #ifdef DYNAMIC_KEYMAP_ENABLE - oled_mode = eeprom_read_byte((uint8_t*)DYNAMIC_KEYMAP_DEFAULT_OLED); - enabled_encoder_modes = eeprom_read_byte((uint8_t*)DYNAMIC_KEYMAP_ENABLED_ENCODER_MODES); + oled_mode = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED); + enabled_encoder_modes = eeprom_read_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES); #endif } -void eeprom_init_kb(void) +// Called from via_init() if VIA_ENABLE +// Called from matrix_init_kb() if not VIA_ENABLE +void via_init_kb(void) { - // If the EEPROM has the magic, the data is good. - // OK to load from EEPROM. - if (eeprom_is_valid()) { - load_custom_config(); - } else { - // If the EEPROM has not been saved before, or is out of date, - // save the default values to the EEPROM. Default values - // come from construction of the zeal_backlight_config instance. - //backlight_config_save(); + // If the EEPROM has the magic, the data is good. + // OK to load from EEPROM. + if (via_eeprom_is_valid()) { + custom_config_load(); + } else { #ifdef DYNAMIC_KEYMAP_ENABLE - // This resets the keymaps in EEPROM to what is in flash. - dynamic_keymap_reset(); - // This resets the macros in EEPROM to nothing. - dynamic_keymap_macro_reset(); // Reset the custom stuff - dynamic_keymap_custom_reset(); + custom_config_reset(); #endif - // Save the magic number last, in case saving was interrupted - eeprom_set_valid(true); - } + // DO NOT set EEPROM valid here, let caller do this + } } void matrix_init_kb(void) { - eeprom_init_kb(); +#ifndef VIA_ENABLE + via_init_kb(); + via_eeprom_set_valid(true); +#endif // VIA_ENABLE + rtcGetTime(&RTCD1, &last_timespec); queue_for_send = true; backlight_init_ports(); - matrix_init_user(); + matrix_init_user(); } @@ -472,3 +336,51 @@ void matrix_scan_kb(void) { #endif } +// +// In the case of VIA being disabled, we still need to check if +// keyboard level EEPROM memory is valid before loading. +// Thus these are copies of the same functions in VIA, since +// the backlight settings reuse VIA's EEPROM magic/version, +// and the ones in via.c won't be compiled in. +// +// Yes, this is sub-optimal, and is only here for completeness +// (i.e. catering to the 1% of people that want wilba.tech LED bling +// AND want persistent settings BUT DON'T want to use dynamic keymaps/VIA). +// +#ifndef VIA_ENABLE + +bool via_eeprom_is_valid(void) +{ + char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" + uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F ); + uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F ); + uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F ); + + return (eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0 ) == magic0 && + eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1 ) == magic1 && + eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2 ) == magic2 ); +} + +// Sets VIA/keyboard level usage of EEPROM to valid/invalid +// Keyboard level code (eg. via_init_kb()) should not call this +void via_eeprom_set_valid(bool valid) +{ + char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" + uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F ); + uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F ); + uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F ); + + eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0, valid ? magic0 : 0xFF); + eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1, valid ? magic1 : 0xFF); + eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2, valid ? magic2 : 0xFF); +} + +void via_eeprom_reset(void) +{ + // Set the VIA specific EEPROM state as invalid. + via_eeprom_set_valid(false); + // Set the TMK/QMK EEPROM state as invalid. + eeconfig_disable(); +} + +#endif // VIA_ENABLE
\ No newline at end of file diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.h b/keyboards/cannonkeys/satisfaction75/satisfaction75.h index 188a1d497..13aaf6888 100644 --- a/keyboards/cannonkeys/satisfaction75/satisfaction75.h +++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.h @@ -8,6 +8,12 @@ #include "rev1.h" #endif +#include "via.h" // only for EEPROM address +#define EEPROM_ENABLED_ENCODER_MODES (VIA_EEPROM_CUSTOM_CONFIG_ADDR) +#define EEPROM_CUSTOM_BACKLIGHT (VIA_EEPROM_CUSTOM_CONFIG_ADDR+1) +#define EEPROM_DEFAULT_OLED (VIA_EEPROM_CUSTOM_CONFIG_ADDR+2) +#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+3) + /* screen off after this many milliseconds */ #define ScreenOffInterval 60000 /* milliseconds */ @@ -117,5 +123,5 @@ void backlight_set(uint8_t level); bool is_breathing(void); void breathing_enable(void); void breathing_disable(void); -void load_custom_config(void); -void save_backlight_config_to_eeprom(void); +void custom_config_load(void); +void backlight_config_save(void); diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c b/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c index e866d897c..8fcd720e2 100644 --- a/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c +++ b/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c @@ -12,7 +12,7 @@ void pre_encoder_mode_change(){ timespec.millisecond = (hour_config * 60 + minute_config) * 60 * 1000; rtcSetTime(&RTCD1, ×pec); } else if (encoder_mode == ENC_MODE_BACKLIGHT){ - save_backlight_config_to_eeprom(); + backlight_config_save(); } } @@ -221,7 +221,7 @@ uint16_t handle_encoder_press(){ uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior){ #ifdef DYNAMIC_KEYMAP_ENABLE - void* addr = (void*)(DYNAMIC_KEYMAP_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2)); + void* addr = (void*)(EEPROM_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2)); //big endian uint16_t keycode = eeprom_read_byte(addr) << 8; keycode |= eeprom_read_byte(addr + 1); @@ -233,7 +233,7 @@ uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior){ void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t new_code){ #ifdef DYNAMIC_KEYMAP_ENABLE - void* addr = (void*)(DYNAMIC_KEYMAP_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2)); + void* addr = (void*)(EEPROM_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2)); eeprom_update_byte(addr, (uint8_t)(new_code >> 8)); eeprom_update_byte(addr + 1, (uint8_t)(new_code & 0xFF)); #endif |