diff options
author | Andrew Kannan <andrew.kannan@gmail.com> | 2019-05-19 13:03:06 -0400 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-05-19 10:03:06 -0700 |
commit | e8372692c58c3e731a7ccef58ddeaa45e2e71e9f (patch) | |
tree | 205959b182c1a2eb5ab996571099082993e84463 /keyboards/cannonkeys/stm32f072 | |
parent | b479eff94013c32b6f3f926a23b7e4a6cf7a3a6e (diff) | |
download | qmk_firmware-e8372692c58c3e731a7ccef58ddeaa45e2e71e9f.tar.gz |
[Keyboard] Instant60 VIA Support (#5909)
* VIA Support for Instant60
* Backlighting updates
* Update default keymap
* Add Standard layout default VIA supported layout
* Clean up some backslashes
* Add info.json
* Update info json metadata
* add info.json for practice65
* Update keyboards/cannonkeys/instant60/info.json
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/cannonkeys/practice65/info.json
Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>
* Update keyboards/cannonkeys/instant60/keymaps/via/keymap.c
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update keyboards/cannonkeys/instant60/keymaps/via_standard/keymap.c
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Remove unused enum
Diffstat (limited to 'keyboards/cannonkeys/stm32f072')
-rw-r--r-- | keyboards/cannonkeys/stm32f072/keyboard.c | 182 | ||||
-rw-r--r-- | keyboards/cannonkeys/stm32f072/led.c | 3 |
2 files changed, 181 insertions, 4 deletions
diff --git a/keyboards/cannonkeys/stm32f072/keyboard.c b/keyboards/cannonkeys/stm32f072/keyboard.c index f94ecb5fb..02c6dae18 100644 --- a/keyboards/cannonkeys/stm32f072/keyboard.c +++ b/keyboards/cannonkeys/stm32f072/keyboard.c @@ -5,9 +5,16 @@ #include "util.h" #include "quantum.h" +#include "ws2812.h" + +#include "raw_hid.h" +#include "dynamic_keymap.h" #include "tmk_core/common/eeprom.h" -#include "ws2812.h" +// HACK +#include "keyboards/zeal60/zeal60_api.h" // Temporary hack +#include "keyboards/zeal60/zeal60_keycodes.h" // Temporary hack + backlight_config_t kb_backlight_config = { .enable = true, @@ -41,6 +48,17 @@ void load_custom_config(){ kb_backlight_config.raw = eeprom_read_byte((uint8_t*)EEPROM_CUSTOM_BACKLIGHT); } +#ifdef DYNAMIC_KEYMAP_ENABLE +void dynamic_keymap_custom_reset(void){ + void *p = (void*)(EEPROM_CUSTOM_BACKLIGHT); + void *end = (void*)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR); + while ( p != end ) { + eeprom_update_byte(p, 0); + ++p; + } +} +#endif + void eeprom_init_kb(void) { // If the EEPROM has the magic, the data is good. @@ -48,9 +66,17 @@ void eeprom_init_kb(void) if (eeprom_is_valid()) { load_custom_config(); } 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(); +#endif // Save the magic number last, in case saving was interrupted + save_backlight_config_to_eeprom(); eeprom_set_valid(true); - save_backlight_config_to_eeprom(); } } @@ -120,6 +146,158 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { save_backlight_config_to_eeprom(); } return false; + default: + 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 true; } + + +// Start Dynamic Keymap code +#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: + { + 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; + } + default: + { + *command_id = id_unhandled; + break; + } + } + break; + } +#ifdef DYNAMIC_KEYMAP_ENABLE + + 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_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 + 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 ); + +} + +#endif diff --git a/keyboards/cannonkeys/stm32f072/led.c b/keyboards/cannonkeys/stm32f072/led.c index d69d94685..5c7df47da 100644 --- a/keyboards/cannonkeys/stm32f072/led.c +++ b/keyboards/cannonkeys/stm32f072/led.c @@ -77,10 +77,9 @@ void backlight_init_ports(void) { pwmStart(&PWMD3, &pwmCFG); // pwmEnableChannel(&PWMD3, 0, PWM_FRACTION_TO_WIDTH(&PWMD3, 0xFFFF,cie_lightness(0xFFFF))); if(kb_backlight_config.enable){ + backlight_set(kb_backlight_config.level); if(kb_backlight_config.breathing){ breathing_enable(); - } else{ - backlight_set(kb_backlight_config.level); } } else { backlight_set(0); |