Infer eeconfig identifiers (#22135)

Co-authored-by: Nick Brassel <nick@tzarc.org>
This commit is contained in:
Joel Challis 2024-03-14 10:45:03 +00:00 committed by GitHub
parent 6720e9c58c
commit 4bbfecae90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 25 deletions

View File

@ -22,6 +22,10 @@ void eeprom_update_dword(uint32_t *__p, uint32_t __value);
void eeprom_update_block(const void *__src, void *__dst, size_t __n); void eeprom_update_block(const void *__src, void *__dst, size_t __n);
#endif #endif
static inline void eeprom_write_qword(uint64_t *__p, uint64_t __value) {
eeprom_update_block(&__value, __p, sizeof(uint64_t));
}
#if defined(EEPROM_CUSTOM) #if defined(EEPROM_CUSTOM)
# ifndef EEPROM_SIZE # ifndef EEPROM_SIZE
# error EEPROM_SIZE has not been defined for custom driver. # error EEPROM_SIZE has not been defined for custom driver.

View File

@ -19,6 +19,8 @@ void via_eeprom_set_valid(bool valid);
void eeconfig_init_via(void); void eeconfig_init_via(void);
#endif #endif
_Static_assert((intptr_t)EECONFIG_HANDEDNESS == 14, "EEPROM handedness offset is incorrect");
/** \brief eeconfig enable /** \brief eeconfig enable
* *
* FIXME: needs doc * FIXME: needs doc
@ -57,11 +59,9 @@ void eeconfig_init_quantum(void) {
eeprom_update_byte(EECONFIG_AUDIO, 0); eeprom_update_byte(EECONFIG_AUDIO, 0);
eeprom_update_dword(EECONFIG_RGBLIGHT, 0); eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, 0); eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, 0);
eeprom_update_byte(EECONFIG_UNUSED, 0);
eeprom_update_byte(EECONFIG_UNICODEMODE, 0); eeprom_update_byte(EECONFIG_UNICODEMODE, 0);
eeprom_update_byte(EECONFIG_STENOMODE, 0); eeprom_update_byte(EECONFIG_STENOMODE, 0);
uint64_t dummy = 0; eeprom_write_qword(EECONFIG_RGB_MATRIX, 0);
eeprom_update_block(&dummy, EECONFIG_RGB_MATRIX, sizeof(uint64_t));
eeprom_update_dword(EECONFIG_HAPTIC, 0); eeprom_update_dword(EECONFIG_HAPTIC, 0);
#if defined(HAPTIC_ENABLE) #if defined(HAPTIC_ENABLE)
haptic_reset(); haptic_reset();

View File

@ -19,37 +19,57 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> // offsetof
#include "eeprom.h" #include "eeprom.h"
#include "util.h"
#ifndef EECONFIG_MAGIC_NUMBER #ifndef EECONFIG_MAGIC_NUMBER
# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE6 // When changing, decrement this value to avoid future re-init issues # define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE5 // When changing, decrement this value to avoid future re-init issues
#endif #endif
#define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF
/* EEPROM parameter address */ // Dummy struct only used to calculate offsets
#define EECONFIG_MAGIC (uint16_t *)0 typedef struct PACKED {
#define EECONFIG_DEBUG (uint8_t *)2 uint16_t magic;
#define EECONFIG_DEFAULT_LAYER (uint8_t *)3 uint8_t debug;
#define EECONFIG_KEYMAP (uint16_t *)4 uint8_t default_layer;
#define EECONFIG_BACKLIGHT (uint8_t *)6 uint16_t keymap;
#define EECONFIG_AUDIO (uint8_t *)7 uint8_t backlight;
#define EECONFIG_RGBLIGHT (uint32_t *)8 uint8_t audio;
#define EECONFIG_UNICODEMODE (uint8_t *)12 uint32_t rgblight;
#define EECONFIG_STENOMODE (uint8_t *)13 uint8_t unicode;
// EEHANDS for two handed boards uint8_t steno;
#define EECONFIG_HANDEDNESS (uint8_t *)14 uint8_t handedness;
#define EECONFIG_KEYBOARD (uint32_t *)15 uint32_t keyboard;
#define EECONFIG_USER (uint32_t *)19 uint32_t user;
#define EECONFIG_UNUSED (uint8_t *)23 union { // Mutually exclusive
// Mutually exclusive uint32_t led_matrix;
#define EECONFIG_LED_MATRIX (uint32_t *)24 uint64_t rgb_matrix;
#define EECONFIG_RGB_MATRIX (uint64_t *)24 };
uint32_t haptic;
uint8_t rgblight_ext;
} eeprom_core_t;
#define EECONFIG_HAPTIC (uint32_t *)32 /* EEPROM parameter address */
#define EECONFIG_RGBLIGHT_EXTENDED (uint8_t *)36 #define EECONFIG_MAGIC (uint16_t *)(offsetof(eeprom_core_t, magic))
#define EECONFIG_DEBUG (uint8_t *)(offsetof(eeprom_core_t, debug))
#define EECONFIG_DEFAULT_LAYER (uint8_t *)(offsetof(eeprom_core_t, default_layer))
#define EECONFIG_KEYMAP (uint16_t *)(offsetof(eeprom_core_t, keymap))
#define EECONFIG_BACKLIGHT (uint8_t *)(offsetof(eeprom_core_t, backlight))
#define EECONFIG_AUDIO (uint8_t *)(offsetof(eeprom_core_t, audio))
#define EECONFIG_RGBLIGHT (uint32_t *)(offsetof(eeprom_core_t, rgblight))
#define EECONFIG_UNICODEMODE (uint8_t *)(offsetof(eeprom_core_t, unicode))
#define EECONFIG_STENOMODE (uint8_t *)(offsetof(eeprom_core_t, steno))
#define EECONFIG_HANDEDNESS (uint8_t *)(offsetof(eeprom_core_t, handedness))
#define EECONFIG_KEYBOARD (uint32_t *)(offsetof(eeprom_core_t, keyboard))
#define EECONFIG_USER (uint32_t *)(offsetof(eeprom_core_t, user))
#define EECONFIG_LED_MATRIX (uint32_t *)(offsetof(eeprom_core_t, led_matrix))
#define EECONFIG_RGB_MATRIX (uint64_t *)(offsetof(eeprom_core_t, rgb_matrix))
#define EECONFIG_HAPTIC (uint32_t *)(offsetof(eeprom_core_t, haptic))
#define EECONFIG_RGBLIGHT_EXTENDED (uint8_t *)(offsetof(eeprom_core_t, rgblight_ext))
// Size of EEPROM being used for core data storage // Size of EEPROM being used for core data storage
#define EECONFIG_BASE_SIZE 37 #define EECONFIG_BASE_SIZE ((uint8_t)sizeof(eeprom_core_t))
// Size of EEPROM dedicated to keyboard- and user-specific data // Size of EEPROM dedicated to keyboard- and user-specific data
#ifndef EECONFIG_KB_DATA_SIZE #ifndef EECONFIG_KB_DATA_SIZE