qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

nvm_eeprom_eeconfig_internal.h (2581B)


      1 // Copyright 2024 Nick Brassel (@tzarc)
      2 // SPDX-License-Identifier: GPL-2.0-or-later
      3 #pragma once
      4 
      5 #include <stdint.h>
      6 #include <stddef.h> // offsetof
      7 
      8 #include "compiler_support.h"
      9 #include "eeconfig.h"
     10 #include "util.h"
     11 
     12 // Dummy struct only used to calculate offsets
     13 typedef struct PACKED {
     14     uint16_t magic;
     15     uint8_t  debug;
     16     uint8_t  default_layer;
     17     uint16_t keymap;
     18     uint8_t  backlight;
     19     uint8_t  audio;
     20     uint32_t rgblight;
     21     uint8_t  unicode;
     22     uint8_t  steno;
     23     uint8_t  handedness;
     24     uint32_t keyboard;
     25     uint32_t user;
     26     union { // Mutually exclusive
     27         uint32_t led_matrix;
     28         uint64_t rgb_matrix;
     29     };
     30     uint32_t haptic;
     31     uint8_t  rgblight_ext;
     32     uint8_t  connection;
     33 } eeprom_core_t;
     34 
     35 /* EEPROM parameter address */
     36 #define EECONFIG_MAGIC (uint16_t *)(offsetof(eeprom_core_t, magic))
     37 #define EECONFIG_DEBUG (uint8_t *)(offsetof(eeprom_core_t, debug))
     38 #define EECONFIG_DEFAULT_LAYER (uint8_t *)(offsetof(eeprom_core_t, default_layer))
     39 #define EECONFIG_KEYMAP (uint16_t *)(offsetof(eeprom_core_t, keymap))
     40 #define EECONFIG_BACKLIGHT (uint8_t *)(offsetof(eeprom_core_t, backlight))
     41 #define EECONFIG_AUDIO (uint8_t *)(offsetof(eeprom_core_t, audio))
     42 #define EECONFIG_RGBLIGHT (uint32_t *)(offsetof(eeprom_core_t, rgblight))
     43 #define EECONFIG_UNICODEMODE (uint8_t *)(offsetof(eeprom_core_t, unicode))
     44 #define EECONFIG_STENOMODE (uint8_t *)(offsetof(eeprom_core_t, steno))
     45 #define EECONFIG_HANDEDNESS (uint8_t *)(offsetof(eeprom_core_t, handedness))
     46 #define EECONFIG_KEYBOARD (uint32_t *)(offsetof(eeprom_core_t, keyboard))
     47 #define EECONFIG_USER (uint32_t *)(offsetof(eeprom_core_t, user))
     48 #define EECONFIG_LED_MATRIX (uint32_t *)(offsetof(eeprom_core_t, led_matrix))
     49 #define EECONFIG_RGB_MATRIX (uint64_t *)(offsetof(eeprom_core_t, rgb_matrix))
     50 #define EECONFIG_HAPTIC (uint32_t *)(offsetof(eeprom_core_t, haptic))
     51 #define EECONFIG_RGBLIGHT_EXTENDED (uint8_t *)(offsetof(eeprom_core_t, rgblight_ext))
     52 #define EECONFIG_CONNECTION (uint8_t *)(offsetof(eeprom_core_t, connection))
     53 
     54 // Size of EEPROM being used for core data storage
     55 #define EECONFIG_BASE_SIZE ((uint8_t)sizeof(eeprom_core_t))
     56 
     57 #define EECONFIG_KB_DATABLOCK ((uint8_t *)(EECONFIG_BASE_SIZE))
     58 #define EECONFIG_USER_DATABLOCK ((uint8_t *)((EECONFIG_BASE_SIZE) + (EECONFIG_KB_DATA_SIZE)))
     59 
     60 // Size of EEPROM being used, other code can refer to this for available EEPROM
     61 #define EECONFIG_SIZE ((EECONFIG_BASE_SIZE) + (EECONFIG_KB_DATA_SIZE) + (EECONFIG_USER_DATA_SIZE))
     62 
     63 STATIC_ASSERT((intptr_t)EECONFIG_HANDEDNESS == 14, "EEPROM handedness offset is incorrect");