eeprom_update_byte(((void*)EEPROM_VERSION_ADDR), valid ? EEPROM_VERSION : 0xFF);
}
+void eeprom_reset(void)
+{
+ // Set the Zeal60 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 )
}
case id_get_keyboard_value:
{
- if ( command_data[0] == 0x01 )
+ if ( command_data[0] == id_uptime )
{
uint32_t value = timer_read32();
command_data[1] = (value >> 24 ) & 0xFF;
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_clear_all:
+ 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:
{
- dynamic_keymap_clear_all();
+ 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
break;
}
#endif // RGB_BACKLIGHT_ENABLED
+ 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.
#endif
-void bootmagic_lite(void)
-{
- // The lite version of TMK's bootmagic.
- // 100% less potential for accidentally making the
- // keyboard do stupid things.
-
- // We need multiple scans because debouncing can't be turned off.
- matrix_scan();
- wait_ms(DEBOUNCING_DELAY);
- wait_ms(DEBOUNCING_DELAY);
- matrix_scan();
-
- // If the Esc and space bar are held down on power up,
- // reset the EEPROM valid state and jump to bootloader.
- // Assumes Esc is at [0,0] and spacebar is at [4,7].
- // This isn't very generalized, but we need something that doesn't
- // rely on user's keymaps in firmware or EEPROM.
- if ( ( matrix_get_row(0) & (1<<0) ) &&
- ( matrix_get_row(4) & (1<<7) ) )
- {
- // Set the Zeal60 specific EEPROM state as invalid.
- eeprom_set_valid(false);
- // Set the TMK/QMK EEPROM state as invalid.
- eeconfig_disable();
- // Jump to bootloader.
- bootloader_jump();
- }
-}
-
-void matrix_init_kb(void)
+void main_init(void)
{
- bootmagic_lite();
-
// If the EEPROM has the magic, the data is good.
// OK to load from EEPROM.
- if (eeprom_is_valid())
- {
+ if (eeprom_is_valid()) {
#if RGB_BACKLIGHT_ENABLED
backlight_config_load();
#endif // RGB_BACKLIGHT_ENABLED
- // TODO: do something to "turn on" keymaps in EEPROM?
- }
- else
- {
+ } else {
#if RGB_BACKLIGHT_ENABLED
// 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();
#endif // RGB_BACKLIGHT_ENABLED
-
#ifdef DYNAMIC_KEYMAP_ENABLE
- // This saves "empty" keymaps so it falls back to the keymaps
- // in the firmware (aka. progmem/flash)
- dynamic_keymap_clear_all();
+ // 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();
#endif
-
// Save the magic number last, in case saving was interrupted
eeprom_set_valid(true);
}
#if RGB_BACKLIGHT_ENABLED
// Initialize LED drivers for backlight.
backlight_init_drivers();
-
+
backlight_timer_init();
backlight_timer_enable();
#endif // RGB_BACKLIGHT_ENABLED
+}
+
+void bootmagic_lite(void)
+{
+ // The lite version of TMK's bootmagic.
+ // 100% less potential for accidentally making the
+ // keyboard do stupid things.
+
+ // We need multiple scans because debouncing can't be turned off.
+ matrix_scan();
+ wait_ms(DEBOUNCE);
+ wait_ms(DEBOUNCE);
+ matrix_scan();
+
+ // If the Esc (matrix 0,0) is held down on power up,
+ // reset the EEPROM valid state and jump to bootloader.
+ if ( matrix_get_row(0) & (1<<0) ) {
+ eeprom_reset();
+ bootloader_jump();
+ }
+}
+void matrix_init_kb(void)
+{
+ bootmagic_lite();
+ main_init();
matrix_init_user();
}
process_record_backlight(keycode, record);
#endif // BACKLIGHT_ENABLED
- switch(keycode)
- {
+ switch(keycode) {
case FN_MO13:
- if (record->event.pressed)
- {
+ if (record->event.pressed) {
layer_on(1);
update_tri_layer(1, 2, 3);
- }
- else
- {
+ } else {
layer_off(1);
update_tri_layer(1, 2, 3);
}
return false;
break;
case FN_MO23:
- if (record->event.pressed)
- {
+ if (record->event.pressed) {
layer_on(2);
update_tri_layer(1, 2, 3);
- }
- else
- {
+ } 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);
}
if ( function_id >= 0x0F00 && function_id <= 0x0FFF )
{
uint8_t id = function_id & 0xFF;
- switch ( id )
- {
+ switch ( id ) {
case TRIPLE_TAP_1_3:
case TRIPLE_TAP_2_3:
{
}
}
-#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]);
}
{
case TRIPLE_TAP_1_3:
case TRIPLE_TAP_2_3:
- if (record->event.pressed)
- {
+ if (record->event.pressed) {
layer_on( id == TRIPLE_TAP_1_3 ? 1 : 2 );
-
- if (record->tap.count && !record->tap.interrupted)
- {
- if (record->tap.count >= 3)
- {
+ if (record->tap.count && !record->tap.interrupted) {
+ if (record->tap.count >= 3) {
layer_invert(3);
}
- }
- else
- {
+ } else {
record->tap.count = 0;
}
- }
- else
- {
+ } else {
layer_off( id == TRIPLE_TAP_1_3 ? 1 : 2 );
}
break;
backlight_set_suspend_state(false);
#endif // RGB_BACKLIGHT_ENABLED
}
-