From c23225040fecf166f3a263c6b47904faee78d2e9 Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 7 Dec 2023 13:49:58 +0900 Subject: [PATCH] Add eeprom_tool project --- keyboard/eeprom_tool/Makefile | 47 +++++++++++++++++ keyboard/eeprom_tool/Makefile.show_atmega32u2 | 6 +++ keyboard/eeprom_tool/Makefile.show_atmega32u4 | 6 +++ keyboard/eeprom_tool/Makefile.wipe_atmega32u2 | 6 +++ keyboard/eeprom_tool/Makefile.wipe_atmega32u4 | 6 +++ keyboard/eeprom_tool/README.md | 18 +++++++ keyboard/eeprom_tool/config.h | 50 +++++++++++++++++++ keyboard/eeprom_tool/eeprom_show.c | 28 +++++++++++ keyboard/eeprom_tool/eeprom_tool.c | 42 ++++++++++++++++ keyboard/eeprom_tool/eeprom_wipe.c | 41 +++++++++++++++ 10 files changed, 250 insertions(+) create mode 100644 keyboard/eeprom_tool/Makefile create mode 100644 keyboard/eeprom_tool/Makefile.show_atmega32u2 create mode 100644 keyboard/eeprom_tool/Makefile.show_atmega32u4 create mode 100644 keyboard/eeprom_tool/Makefile.wipe_atmega32u2 create mode 100644 keyboard/eeprom_tool/Makefile.wipe_atmega32u4 create mode 100644 keyboard/eeprom_tool/README.md create mode 100644 keyboard/eeprom_tool/config.h create mode 100644 keyboard/eeprom_tool/eeprom_show.c create mode 100644 keyboard/eeprom_tool/eeprom_tool.c create mode 100644 keyboard/eeprom_tool/eeprom_wipe.c diff --git a/keyboard/eeprom_tool/Makefile b/keyboard/eeprom_tool/Makefile new file mode 100644 index 00000000..65a348aa --- /dev/null +++ b/keyboard/eeprom_tool/Makefile @@ -0,0 +1,47 @@ +TARGET ?= eeprom_tool +TMK_DIR ?= ../../tmk_core +TARGET_DIR ?= . + +SRC ?= $(TARGET).c +CONFIG_H ?= config.h + +# MCU name +MCU ?= atmega32u4 +#MCU ?= atmega32u2 + +# Processor frequency. +F_CPU ?= 16000000 + +# +# LUFA specific +# +ARCH ?= AVR8 +F_USB ?= $(F_CPU) + +# Interrupt driven control endpoint task +OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT + +# +# Build Options +# +MOUSEKEY_ENABLE ?= no # Mouse keys +EXTRAKEY_ENABLE ?= no # Media control and System control +CONSOLE_ENABLE ?= yes # Console for debug +COMMAND_ENABLE ?= no # Commands for debug and configuration +NKRO_ENABLE ?= no # USB Nkey Rollover +NO_KEYBOARD ?= yes # No keyboard interface +NO_DEBUG ?= yes + +# Boot Section Size in bytes +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + +#OPT_DEFS += -DNO_DEBUG + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TMK_DIR) + +include $(TMK_DIR)/protocol/lufa.mk +include $(TMK_DIR)/common.mk +include $(TMK_DIR)/rules.mk diff --git a/keyboard/eeprom_tool/Makefile.show_atmega32u2 b/keyboard/eeprom_tool/Makefile.show_atmega32u2 new file mode 100644 index 00000000..dd7a093d --- /dev/null +++ b/keyboard/eeprom_tool/Makefile.show_atmega32u2 @@ -0,0 +1,6 @@ +NAME = eeprom_show +MCU = atmega32u2 +TARGET = $(NAME)_$(MCU) +SRC = $(NAME).c + +include Makefile diff --git a/keyboard/eeprom_tool/Makefile.show_atmega32u4 b/keyboard/eeprom_tool/Makefile.show_atmega32u4 new file mode 100644 index 00000000..ea9a5f24 --- /dev/null +++ b/keyboard/eeprom_tool/Makefile.show_atmega32u4 @@ -0,0 +1,6 @@ +NAME = eeprom_show +MCU = atmega32u4 +TARGET = $(NAME)_$(MCU) +SRC = $(NAME).c + +include Makefile diff --git a/keyboard/eeprom_tool/Makefile.wipe_atmega32u2 b/keyboard/eeprom_tool/Makefile.wipe_atmega32u2 new file mode 100644 index 00000000..da6e6ead --- /dev/null +++ b/keyboard/eeprom_tool/Makefile.wipe_atmega32u2 @@ -0,0 +1,6 @@ +NAME = eeprom_wipe +MCU = atmega32u2 +TARGET = $(NAME)_$(MCU) +SRC = $(NAME).c + +include Makefile diff --git a/keyboard/eeprom_tool/Makefile.wipe_atmega32u4 b/keyboard/eeprom_tool/Makefile.wipe_atmega32u4 new file mode 100644 index 00000000..eceb82ba --- /dev/null +++ b/keyboard/eeprom_tool/Makefile.wipe_atmega32u4 @@ -0,0 +1,6 @@ +NAME = eeprom_wipe +MCU = atmega32u4 +TARGET = $(NAME)_$(MCU) +SRC = $(NAME).c + +include Makefile diff --git a/keyboard/eeprom_tool/README.md b/keyboard/eeprom_tool/README.md new file mode 100644 index 00000000..6cc68237 --- /dev/null +++ b/keyboard/eeprom_tool/README.md @@ -0,0 +1,18 @@ +EEPROM tool +=========== +This can show and erase EEPROM content and would be useful when you have a trouble with EEPROM. + + +Prebuilt firmware +----------------- +`eeprom_show` just shows content of EEPROM and `eeprom_wipe` overwrites all bytes of EEPROM with 0xFF. + +You can see the contents using `hid_listen`. + +#### For ATmega32u2: +- eeprom_show_32u2.hex +- eeprom_wipe_32u2.hex + +#### For ATmega32u4: +- eeprom_show_32u4.hex +- eeprom_wipe_32u4.hex diff --git a/keyboard/eeprom_tool/config.h b/keyboard/eeprom_tool/config.h new file mode 100644 index 00000000..caf50803 --- /dev/null +++ b/keyboard/eeprom_tool/config.h @@ -0,0 +1,50 @@ +/* +Copyright 2012 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + + +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0xEEEE +#define DEVICE_VER 0x0001 +#define MANUFACTURER TMK +#define PRODUCT EEPROM Tool +#define DESCRIPTION Product from TMK keyboard firmware project + + +/* matrix size */ +#define MATRIX_ROWS 0 +#define MATRIX_COLS 0 + +/* key combination for command */ +#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) + + +// Disable power saving in USB suspend loop but remote wakeup is still valid. +// This allows keep USB::Task() going during suspend without power down time delay. +//#define NO_SUSPEND_POWER_DOWN + + +// Disable USB startup wait, which can delays starting UHS2 Task() for 350-600ms. +//#define NO_USB_STARTUP_WAIT_LOOP + +// Disable USB suspend loop, which blocks UHS2 Task() while power saving. +// Note that this also disables power saving and remote wakeup from keyboard completely. +//#define NO_USB_SUSPEND_LOOP + +#endif diff --git a/keyboard/eeprom_tool/eeprom_show.c b/keyboard/eeprom_tool/eeprom_show.c new file mode 100644 index 00000000..f399d060 --- /dev/null +++ b/keyboard/eeprom_tool/eeprom_show.c @@ -0,0 +1,28 @@ +#include "hook.h" +#include "print.h" +#include "timer.h" +#include + +static void eeprom_show(void) +{ + xprintf("eeprom:"); + for (int i = 0; i < E2END + 1; i++) { + if ((i % 16) == 0) { xprintf("\n%04X: ", i); } + xprintf("%02X ", eeprom_read_byte((uint8_t *)i)); + } + xprintf("\n"); +} + +void hook_late_init(void) +{ + eeprom_show(); +} + +void hook_main_loop(void) +{ + static uint16_t last_time = 0; + uint16_t t = timer_read(); + if (t != last_time && (t % 1000) == 0) xprintf("."); + last_time = t; +} + diff --git a/keyboard/eeprom_tool/eeprom_tool.c b/keyboard/eeprom_tool/eeprom_tool.c new file mode 100644 index 00000000..0d81b657 --- /dev/null +++ b/keyboard/eeprom_tool/eeprom_tool.c @@ -0,0 +1,42 @@ +#include "hook.h" +#include "print.h" +#include "timer.h" +#include + +static void eeprom_show(void) +{ + xprintf("eeprom:"); + for (int i = 0; i < E2END + 1; i++) { + if ((i % 16) == 0) { xprintf("\n%04X: ", i); } + xprintf("%02X ", eeprom_read_byte((uint8_t *)i)); + } + xprintf("\n"); +} + +static void eeprom_wipe(void) +{ + xprintf("eeprom wipe: "); + for (int i = 0; i < E2END + 1; i++) { + if ((i % 16) == 0) { xprintf("%04X: ", i); } + eeprom_write_byte((uint8_t *)i, 0xFF); + } + xprintf("\n"); +} + +void hook_late_init(void) +{ + //eeprom_show(); + //xprintf("\n"); + //eeprom_wipe(); + //xprintf("\n"); + eeprom_show(); +} + +void hook_main_loop(void) +{ + static uint16_t last_time = 0; + uint16_t t = timer_read(); + if (t != last_time && (t % 1000) == 0) xprintf("."); + last_time = t; +} + diff --git a/keyboard/eeprom_tool/eeprom_wipe.c b/keyboard/eeprom_tool/eeprom_wipe.c new file mode 100644 index 00000000..de21f702 --- /dev/null +++ b/keyboard/eeprom_tool/eeprom_wipe.c @@ -0,0 +1,41 @@ +#include "hook.h" +#include "print.h" +#include "timer.h" +#include + +static void eeprom_show(void) +{ + xprintf("eeprom:"); + for (int i = 0; i < E2END + 1; i++) { + if ((i % 16) == 0) { xprintf("\n%04X: ", i); } + xprintf("%02X ", eeprom_read_byte((uint8_t *)i)); + } + xprintf("\n"); +} + +static void eeprom_wipe(void) +{ + xprintf("eeprom wipe: "); + for (int i = 0; i < E2END + 1; i++) { + if ((i % 16) == 0) { xprintf("%04X: ", i); } + eeprom_write_byte((uint8_t *)i, 0xFF); + } + xprintf("\n"); +} + +void hook_late_init(void) +{ + eeprom_show(); + xprintf("\n"); + eeprom_wipe(); + xprintf("\n"); + eeprom_show(); +} + +void hook_main_loop(void) +{ + static uint16_t last_time = 0; + uint16_t t = timer_read(); + if (t != last_time && (t % 1000) == 0) xprintf("."); + last_time = t; +}