Skip to content

Commit

Permalink
Merge pull request qmk#8 from Drugantibus/eeprom
Browse files Browse the repository at this point in the history
Implement emulated EEPROM
  • Loading branch information
Drugantibus authored Jul 24, 2021
2 parents bd30a37 + b15cbcf commit 72966bc
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 6 deletions.
2 changes: 1 addition & 1 deletion keyboards/massdrop/alt/keymaps/drugo/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

#define SERIAL_NUM "FRT001"

#define UNICODE_SELECTED_MODES UC_LNX, UC_WINC
#define UNICODE_SELECTED_MODES UC_LNX, UC_WINC, UC_MAC
#define UCIS_MAX_CODE_POINTS 32
6 changes: 6 additions & 0 deletions keyboards/massdrop/alt/keymaps/drugo/config_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#define DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
#define DISABLE_RGB_MATRIX_DUAL_BEACON
#define DISABLE_RGB_MATRIX_BREATHING
#define DISABLE_RGB_MATRIX_HUE_BREATHING
#define DISABLE_RGB_MATRIX_HUE_PENDULUM
#define DISABLE_RGB_MATRIX_HUE_WAVE

#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
#define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY 50

// Set default RGB effect
#define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_ALPHAS_MODS
Expand Down
56 changes: 54 additions & 2 deletions keyboards/massdrop/alt/keymaps/drugo/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ enum {
TD_LOCK, //ESC/GUI+L
};

enum alt_rgb_mode {
RGB_MODE_ALL,
RGB_MODE_KEYLIGHT,
RGB_MODE_UNDERGLOW,
RGB_MODE_NONE,
};

typedef union {
uint32_t raw;
struct {
uint8_t rgb_mode :8;
};
} alt_config_t;

alt_config_t alt_config;

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// DEFAULT
[0] = LAYOUT_65_ansi_blocker(
Expand All @@ -38,8 +54,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[1] = LAYOUT_65_ansi_blocker(
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_MUTE, \
_______, RGB_SPD, RGB_VAI, RGB_SPI, RGB_HUI, RGB_SAI, _______,U_T_AUTO,U_T_AGCR, _______, KC_PSCR, KC_SLCK, KC_PAUS, _______, KC_HOME, \
_______,RGB_RMOD, RGB_VAD, RGB_MOD, RGB_HUD, RGB_SAD, _______, _______, _______, _______, _______, _______, _______, KC_BRIU, \
_______, RGB_TOG, RGB_FRZ, _______, _______, MD_BOOT, NK_TOGG, DBG_TOG, DBG_KBD,DBG_MTRX, _______, _______, KC_VOLU, KC_BRID, \
UC_M_MA,RGB_RMOD, RGB_VAD, RGB_MOD, RGB_HUD, RGB_SAD, _______, _______, _______, _______, _______, _______, _______, KC_BRIU, \
_______, RGB_TOG, RGB_FRZ, _______, EEP_RST, MD_BOOT, NK_TOGG, DBG_TOG, DBG_KBD,DBG_MTRX, _______, _______, KC_VOLU, KC_BRID, \
UNI_ON , UC_M_WC, UC_M_LN, KC_MPLY, MO(2) , _______, KC_MPRV, KC_VOLD, KC_MNXT \
),
// MACRO
Expand Down Expand Up @@ -110,6 +126,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
}
return false;
case EEP_RST:
if (record->event.pressed) {
key_timer = timer_read32();
} else {
if (timer_elapsed32(key_timer) >= 500) {
eeconfig_init();
}
}
return false;
#ifdef UCIS_ENABLE
case UNI_ON:
if (record->event.pressed) {
Expand Down Expand Up @@ -196,24 +221,29 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case LED_FLAG_ALL: {
rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
rgb_matrix_set_color_all(0, 0, 0);
alt_config.rgb_mode = RGB_MODE_KEYLIGHT;
}
break;
case (LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR): {
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
rgb_matrix_set_color_all(0, 0, 0);
alt_config.rgb_mode = RGB_MODE_UNDERGLOW;
}
break;
case LED_FLAG_UNDERGLOW: {
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_disable_noeeprom();
alt_config.rgb_mode = RGB_MODE_NONE;
}
break;
default: {
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_enable_noeeprom();
alt_config.rgb_mode = RGB_MODE_ALL;
}
break;
}
eeconfig_update_user(alt_config.raw);
}
return false;
case RGB_FRZ:
Expand All @@ -235,6 +265,28 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
}

void keyboard_post_init_kb(void) {
alt_config.raw = eeconfig_read_user();
switch (alt_config.rgb_mode) {
case RGB_MODE_ALL:
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_enable_noeeprom();
break;
case RGB_MODE_KEYLIGHT:
rgb_matrix_set_flags(LED_FLAG_KEYLIGHT);
rgb_matrix_set_color_all(0, 0, 0);
break;
case RGB_MODE_UNDERGLOW:
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
rgb_matrix_set_color_all(0, 0, 0);
break;
case RGB_MODE_NONE:
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_disable_noeeprom();
break;
}
}

#ifdef TAP_DANCE_ENABLE
void lock_esc(qk_tap_dance_state_t *state, void *user_data){
if (state->count == 1) {
Expand Down
33 changes: 30 additions & 3 deletions tmk_core/common/arm_atsam/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,51 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "samd51j18a.h"
#include "eeprom.h"
#include "core_cm4.h"
#include "component/nvmctrl.h"

#ifndef EEPROM_SIZE
# include "eeconfig.h"
# define EEPROM_SIZE (((EECONFIG_SIZE + 3) / 4) * 4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO
#endif

__attribute__((aligned(4))) static uint8_t buffer[EEPROM_SIZE];
volatile uint8_t *SmartEEPROM8 = (uint8_t *) SEEPROM_ADDR;

uint8_t eeprom_read_byte(const uint8_t *addr) {
uintptr_t offset = (uintptr_t)addr;
return buffer[offset];
if (offset >= EEPROM_SIZE)
return 0x0;

if (NVMCTRL->SEESTAT.bit.PSZ == 0 || NVMCTRL->SEESTAT.bit.SBLK == 0)
return buffer[offset];

int timeout = 10000;
while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0)
;
if (!NVMCTRL->SEESTAT.bit.BUSY)
return SmartEEPROM8[offset];

return 0;
}

void eeprom_write_byte(uint8_t *addr, uint8_t value) {
uintptr_t offset = (uintptr_t)addr;
buffer[offset] = value;
if (offset >= EEPROM_SIZE)
return;

if (NVMCTRL->SEESTAT.bit.PSZ == 0 || NVMCTRL->SEESTAT.bit.SBLK == 0) {
buffer[offset] = value;
return;
}

int timeout = 10000;
while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0)
;
if (!NVMCTRL->SEESTAT.bit.BUSY)
SmartEEPROM8[offset] = value;
}

uint16_t eeprom_read_word(const uint16_t *addr) {
Expand Down
File renamed without changes.
Binary file added util/mdloader
Binary file not shown.
File renamed without changes.
Binary file added util/old_mdloder/mdloader_mac
Binary file not shown.

0 comments on commit 72966bc

Please sign in to comment.