diff --git a/Makefile b/Makefile index c851e01e73..1e55e7fdf9 100644 --- a/Makefile +++ b/Makefile @@ -641,6 +641,7 @@ $(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(ROOT_DIR)/quantum/versio $(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(ROOT_DIR)/quantum/version.h) $(shell echo '#define CHIBIOS_VERSION "$(CHIBIOS_VERSION)"' >> $(ROOT_DIR)/quantum/version.h) $(shell echo '#define CHIBIOS_CONTRIB_VERSION "$(CHIBIOS_CONTRIB_VERSION)"' >> $(ROOT_DIR)/quantum/version.h) +$(shell python3 util/build_id.py >> $(ROOT_DIR)/quantum/version.h) else BUILD_DATE := NA endif diff --git a/quantum/via.c b/quantum/via.c index 263c0f4958..253cecae67 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -65,10 +65,16 @@ void via_qmk_rgblight_get_value(uint8_t *data); // Can be called in an overriding via_init_kb() to test if keyboard level code usage of // EEPROM is invalid and use/save defaults. bool via_eeprom_is_valid(void) { +#ifdef VIAL_ENABLE + uint8_t magic0 = BUILD_ID & 0xFF; + uint8_t magic1 = (BUILD_ID >> 8) & 0xFF; + uint8_t magic2 = (BUILD_ID >> 16) & 0xFF; +#else char * p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" uint8_t magic0 = ((p[2] & 0x0F) << 4) | (p[3] & 0x0F); uint8_t magic1 = ((p[5] & 0x0F) << 4) | (p[6] & 0x0F); uint8_t magic2 = ((p[8] & 0x0F) << 4) | (p[9] & 0x0F); +#endif return (eeprom_read_byte((void *)VIA_EEPROM_MAGIC_ADDR + 0) == magic0 && eeprom_read_byte((void *)VIA_EEPROM_MAGIC_ADDR + 1) == magic1 && eeprom_read_byte((void *)VIA_EEPROM_MAGIC_ADDR + 2) == magic2); } @@ -76,10 +82,16 @@ bool via_eeprom_is_valid(void) { // Sets VIA/keyboard level usage of EEPROM to valid/invalid // Keyboard level code (eg. via_init_kb()) should not call this void via_eeprom_set_valid(bool valid) { +#ifdef VIAL_ENABLE + uint8_t magic0 = BUILD_ID & 0xFF; + uint8_t magic1 = (BUILD_ID >> 8) & 0xFF; + uint8_t magic2 = (BUILD_ID >> 16) & 0xFF; +#else char * p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" uint8_t magic0 = ((p[2] & 0x0F) << 4) | (p[3] & 0x0F); uint8_t magic1 = ((p[5] & 0x0F) << 4) | (p[6] & 0x0F); uint8_t magic2 = ((p[8] & 0x0F) << 4) | (p[9] & 0x0F); +#endif eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 0, valid ? magic0 : 0xFF); eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 1, valid ? magic1 : 0xFF); diff --git a/util/build_id.py b/util/build_id.py new file mode 100644 index 0000000000..77e56b5938 --- /dev/null +++ b/util/build_id.py @@ -0,0 +1,9 @@ +import random + + +def main(): + print("#define BUILD_ID ((uint32_t)0x{:08X})".format(random.randrange(0, 2 ** 24 - 1))) + + +if __name__ == "__main__": + main()