Skip to content

Commit

Permalink
start planning eeprom stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhumbert committed Aug 1, 2017
1 parent bd0a888 commit 4e7ee5b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 6 deletions.
48 changes: 44 additions & 4 deletions tmk_core/common/eeconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

void eeconfig_init(void)
{
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
eeprom_update_word(EEPROM_SIGNATURE_ADDR, EEPROM_SIGNATURE);
eeprom_update_byte(EECONFIG_DEBUG, 0);
eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
eeprom_update_byte(EECONFIG_KEYMAP, 0);
Expand All @@ -24,19 +24,59 @@ void eeconfig_init(void)
#endif
}

uint8_t eeprom_feature_location(eeprom_feature_t feature) {
uint8_t location = EEPROM_HEADER_SIZE;
if (feature == eeprom_debug)
return location;
location += sizeof(typeof(eeprom_debug));
if (feature == eeprom_default_layer)
return location;
location += sizeof(typeof(eeprom_default_layer));
if (feature == eeprom_keymap)
return location;
location += sizeof(typeof(eeprom_keymap));
if (feature == eeprom_mousekey_accel)
return location;
location += sizeof(typeof(eeprom_mousekey_accel));
#ifdef BACKLIGHT_ENABLE
if (feature == eeprom_backlight)
return location;
location += sizeof(typeof(eeprom_backlight));
#endif
#ifdef AUDIO_ENABLE
if (feature == eeprom_audio)
return location;
location += sizeof(typeof(eeprom_audio));
#endif
#ifdef RGBLIGHT_ENABLE
if (feature == eeprom_rgblight)
return location;
location += sizeof(typeof(eeprom_rgblight));
#endif
if (feature == eeprom_unicodemode)
return location;
location += sizeof(typeof(eeprom_unicodemode));
#ifdef STENO_ENABLE
if (feature == eeprom_stenomode)
return location;
location += sizeof(typeof(eeprom_stenomode));
#endif
return location;
}

void eeconfig_enable(void)
{
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
eeprom_update_word(EEPROM_SIGNATURE_ADDR, EEPROM_SIGNATURE);
}

void eeconfig_disable(void)
{
eeprom_update_word(EECONFIG_MAGIC, 0xFFFF);
eeprom_update_word(EEPROM_SIGNATURE_ADDR, 0xFFFF);
}

bool eeconfig_is_enabled(void)
{
return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
return (eeprom_read_word(EEPROM_SIGNATURE_ADDR) == EEPROM_SIGNATURE);
}

uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
Expand Down
58 changes: 56 additions & 2 deletions tmk_core/common/eeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,62 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <stdbool.h>


#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED
#define EEPROM_CONFIG_VERSION 1
#define EEPROM_HEADER_SIZE 4

#define EEPROM_SIGNATURE (0xFEED - EEPROM_CONFIG_VERSION)
#define EEPROM_SIGNATURE_ADDR (uint16_t *)0

#define EEPROM_ENABLED_FEATURES eeprom_enabled_features
#define EEPROM_ENABLED_FEATURES_ADDR (uint16_t *)2

enum eeprom_optional_features {
eeprom_backlight_option,
eeprom_audio_option,
eeprom_rgblight_option,
eeprom_stenomode_option,
eeprom_free_range_option
};

static const uint16_t eeprom_enabled_features =
#ifdef BACKLIGHT_ENABLE
(1 << eeprom_backlight_option) |
#endif
#ifdef AUDIO_ENABLE
(1 << eeprom_audio_option) |
#endif
#ifdef RGBLIGHT_ENABLE
(1 << eeprom_rgblight_option) |
#endif
#ifdef STENO_ENABLE
(1 << eeprom_stenomode_option) |
#endif
0;

typedef enum eeprom_features {
eeprom_debug,
eeprom_default_layer,
eeprom_keymap,
eeprom_mousekey_accel,
eeprom_backlight,
eeprom_audio,
eeprom_rgblight,
eeprom_unicodemode,
eeprom_stenomode,
eeprom_free_range
} eeprom_feature_t;

typedef uint8_t eeprom_debug_t;
typedef uint8_t eeprom_default_layer_t;
typedef uint8_t eeprom_keymap_t;
typedef uint8_t eeprom_mousekey_accel_t;
typedef uint8_t eeprom_backlight_t;
typedef uint8_t eeprom_audio_t;
typedef uint32_t eeprom_rgblight_t;
typedef uint8_t eeprom_unicodemode_t;
typedef uint8_t eeprom_stenomode_t;

#define typeof(n) n ## _t

/* eeprom parameteter address */
#define EECONFIG_MAGIC (uint16_t *)0
Expand Down

0 comments on commit 4e7ee5b

Please sign in to comment.