mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-28 14:10:13 +00:00
satisfaction75
This commit is contained in:
parent
357494852a
commit
1bd68df217
@ -53,6 +53,22 @@ void board_init(void) {
|
||||
SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_SPI2_DMA_RMP);
|
||||
}
|
||||
|
||||
uint32_t read_custom_config(void *data, uint32_t offset, uint32_t length) {
|
||||
#ifdef VIA_ENABLE
|
||||
return via_read_custom_config(data, offset, length);
|
||||
#else
|
||||
return eeconfig_read_kb_datablock(data, offset, length);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t write_custom_config(const void *data, uint32_t offset, uint32_t length) {
|
||||
#ifdef VIA_ENABLE
|
||||
return via_update_custom_config(data, offset, length);
|
||||
#else
|
||||
return eeconfig_update_kb_datablock(data, offset, length);
|
||||
#endif
|
||||
}
|
||||
|
||||
void keyboard_post_init_kb(void) {
|
||||
/*
|
||||
This is a workaround to some really weird behavior
|
||||
@ -78,7 +94,7 @@ void custom_set_value(uint8_t *data) {
|
||||
switch ( *value_id ) {
|
||||
case id_oled_default_mode:
|
||||
{
|
||||
eeprom_update_byte((uint8_t*)EEPROM_DEFAULT_OLED, value_data[0]);
|
||||
write_custom_config(&value_data[0], EEPROM_DEFAULT_OLED_OFFSET, 1);
|
||||
break;
|
||||
}
|
||||
case id_oled_mode:
|
||||
@ -92,7 +108,7 @@ void custom_set_value(uint8_t *data) {
|
||||
uint8_t index = value_data[0];
|
||||
uint8_t enable = value_data[1];
|
||||
enabled_encoder_modes = (enabled_encoder_modes & ~(1<<index)) | (enable<<index);
|
||||
eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, enabled_encoder_modes);
|
||||
write_custom_config(&enabled_encoder_modes, EEPROM_ENABLED_ENCODER_MODES_OFFSET, 1);
|
||||
break;
|
||||
}
|
||||
case id_encoder_custom:
|
||||
@ -113,7 +129,8 @@ void custom_get_value(uint8_t *data) {
|
||||
switch ( *value_id ) {
|
||||
case id_oled_default_mode:
|
||||
{
|
||||
uint8_t default_oled = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED);
|
||||
uint8_t default_oled;
|
||||
read_custom_config(&default_oled, EEPROM_DEFAULT_OLED_OFFSET, 1);
|
||||
value_data[0] = default_oled;
|
||||
break;
|
||||
}
|
||||
@ -179,7 +196,6 @@ void via_custom_value_command_kb(uint8_t *data, uint8_t length) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void read_host_led_state(void) {
|
||||
led_t led_state = host_keyboard_led_state();
|
||||
if (led_state.num_lock) {
|
||||
@ -290,25 +306,25 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
|
||||
}
|
||||
|
||||
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;
|
||||
for(int i = 0; i < VIA_EEPROM_CUSTOM_CONFIG_SIZE; ++i) {
|
||||
uint8_t dummy = 0;
|
||||
write_custom_config(&dummy, i, 1);
|
||||
}
|
||||
eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, 0x1F);
|
||||
|
||||
uint8_t encoder_modes = 0x1F;
|
||||
write_custom_config(&encoder_modes, EEPROM_ENABLED_ENCODER_MODES_OFFSET, 1);
|
||||
}
|
||||
|
||||
void custom_config_load(void){
|
||||
#ifdef DYNAMIC_KEYMAP_ENABLE
|
||||
oled_mode = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED);
|
||||
enabled_encoder_modes = eeprom_read_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES);
|
||||
read_custom_config(&oled_mode, EEPROM_DEFAULT_OLED_OFFSET, 1);
|
||||
read_custom_config(&enabled_encoder_modes, EEPROM_ENABLED_ENCODER_MODES_OFFSET, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Called from via_init() if VIA_ENABLE
|
||||
// Called from matrix_init_kb() if not VIA_ENABLE
|
||||
void via_init_kb(void)
|
||||
void satisfaction_core_init(void)
|
||||
{
|
||||
// This checks both an EEPROM reset (from bootmagic lite, keycodes)
|
||||
// and also firmware build date (from via_eeprom_is_valid())
|
||||
@ -326,8 +342,7 @@ void via_init_kb(void)
|
||||
void matrix_init_kb(void)
|
||||
{
|
||||
#ifndef VIA_ENABLE
|
||||
via_init_kb();
|
||||
via_eeprom_set_valid(true);
|
||||
satisfaction_core_init();
|
||||
#endif // VIA_ENABLE
|
||||
|
||||
rtcGetTime(&RTCD1, &last_timespec);
|
||||
@ -335,6 +350,11 @@ void matrix_init_kb(void)
|
||||
oled_request_wakeup();
|
||||
}
|
||||
|
||||
#ifdef VIA_ENABLE
|
||||
void via_init_kb(void) {
|
||||
satisfaction_core_init();
|
||||
}
|
||||
#endif // VIA_ENABLE
|
||||
|
||||
void housekeeping_task_kb(void) {
|
||||
rtcGetTime(&RTCD1, &last_timespec);
|
||||
@ -345,52 +365,3 @@ void housekeeping_task_kb(void) {
|
||||
oled_request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
|
@ -6,12 +6,14 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <hal.h>
|
||||
|
||||
#include "via.h" // only for EEPROM address
|
||||
#include "satisfaction_keycodes.h"
|
||||
|
||||
#define EEPROM_ENABLED_ENCODER_MODES (VIA_EEPROM_CUSTOM_CONFIG_ADDR)
|
||||
#define EEPROM_DEFAULT_OLED (VIA_EEPROM_CUSTOM_CONFIG_ADDR+1)
|
||||
#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+2)
|
||||
#define EEPROM_ENABLED_ENCODER_MODES_OFFSET 0
|
||||
#define EEPROM_DEFAULT_OLED_OFFSET 1
|
||||
#define EEPROM_CUSTOM_ENCODER_OFFSET 2
|
||||
|
||||
enum s75_keyboard_value_id {
|
||||
id_encoder_modes = 1,
|
||||
@ -94,3 +96,6 @@ void oled_request_repaint(void);
|
||||
bool oled_task_needs_to_repaint(void);
|
||||
|
||||
void custom_config_load(void);
|
||||
|
||||
uint32_t read_custom_config(void *data, uint32_t offset, uint32_t length);
|
||||
uint32_t write_custom_config(const void *data, uint32_t offset, uint32_t length);
|
||||
|
@ -215,10 +215,13 @@ uint16_t handle_encoder_press(void){
|
||||
|
||||
uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior){
|
||||
#ifdef DYNAMIC_KEYMAP_ENABLE
|
||||
void* addr = (void*)(EEPROM_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2));
|
||||
uint32_t offset = EEPROM_CUSTOM_ENCODER_OFFSET + (encoder_idx * 6) + (behavior * 2);
|
||||
//big endian
|
||||
uint16_t keycode = eeprom_read_byte(addr) << 8;
|
||||
keycode |= eeprom_read_byte(addr + 1);
|
||||
uint8_t hi, lo;
|
||||
read_custom_config(&hi, offset+0, 1);
|
||||
read_custom_config(&lo, offset+1, 1);
|
||||
uint16_t keycode = hi << 8;
|
||||
keycode |= lo;
|
||||
return keycode;
|
||||
#else
|
||||
return 0;
|
||||
@ -227,8 +230,10 @@ 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*)(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));
|
||||
uint32_t offset = EEPROM_CUSTOM_ENCODER_OFFSET + (encoder_idx * 6) + (behavior * 2);
|
||||
uint8_t hi = new_code >> 8;
|
||||
uint8_t lo = new_code & 0xFF;
|
||||
write_custom_config(&hi, offset+0, 1);
|
||||
write_custom_config(&lo, offset+1, 1);
|
||||
#endif
|
||||
}
|
||||
|
@ -42,4 +42,7 @@
|
||||
// 6 for 3x custom encoder settings, left, right, and press (18 bytes)
|
||||
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 20
|
||||
|
||||
|
||||
// And if VIA isn't enabled, fall back to using standard QMK for configuration
|
||||
#ifndef VIA_ENABLE
|
||||
#define EECONFIG_KB_DATA_SIZE VIA_EEPROM_CUSTOM_CONFIG_SIZE
|
||||
#endif
|
@ -25,8 +25,8 @@
|
||||
#include "progmem.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
#include "nvm_eeprom_eeconfig_internal.h"
|
||||
#include "nvm_eeprom_via_internal.h"
|
||||
#include "nvm_eeprom_eeconfig_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
|
||||
#include "nvm_eeprom_via_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
|
||||
#include "via.h" // uses EEPROM address, lighting value IDs
|
||||
#define MONO_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR)
|
||||
|
||||
|
@ -67,8 +67,8 @@ rgb_led_t g_ws2812_leds[WS2812_LED_TOTAL];
|
||||
#include "quantum/color.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
#include "nvm_eeprom_eeconfig_internal.h"
|
||||
#include "nvm_eeprom_via_internal.h"
|
||||
#include "nvm_eeprom_eeconfig_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
|
||||
#include "nvm_eeprom_via_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
|
||||
#include "via.h" // uses EEPROM address, lighting value IDs
|
||||
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR)
|
||||
|
||||
|
@ -180,4 +180,3 @@ void nvm_dynamic_keymap_macro_reset(void) {
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "eeprom.h"
|
||||
#include "util.h"
|
||||
#include "via.h"
|
||||
#include "nvm_via.h"
|
||||
#include "nvm_eeprom_eeconfig_internal.h"
|
||||
@ -54,7 +55,7 @@ uint32_t nvm_via_read_custom_config(void *buf, uint32_t offset, uint32_t length)
|
||||
void *ee_start = (void *)(uintptr_t)(VIA_EEPROM_CUSTOM_CONFIG_ADDR + offset);
|
||||
void *ee_end = (void *)(uintptr_t)(VIA_EEPROM_CUSTOM_CONFIG_ADDR + MIN(VIA_EEPROM_CUSTOM_CONFIG_SIZE, offset + length));
|
||||
eeprom_read_block(buf, ee_start, ee_end - ee_start);
|
||||
return ee_end - ee - start;
|
||||
return ee_end - ee_start;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user