From 239902f8615d37a95a8296195fe37c1b35c2e383 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 10 Mar 2018 03:02:53 -0600 Subject: [PATCH] Fix E2END and add EEPROM to Smart RAMPS Reference #9983 --- Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp | 2 +- Marlin/src/HAL/SpiEeprom.cpp | 1 - Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp | 4 ++-- Marlin/src/module/configuration_store.cpp | 8 ++++++-- Marlin/src/module/configuration_store.h | 5 +++-- Marlin/src/pins/pins_RADDS.h | 3 ++- Marlin/src/pins/pins_RAMPS_SMART.h | 4 ++++ Marlin/src/pins/pins_RURAMPS4D.h | 2 +- 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp index ef8e1aa29f..c03dceeec6 100644 --- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp @@ -132,7 +132,7 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo UINT bytes_read = 0; FRESULT s; s = f_lseek(&eeprom_file, pos); - if ( s ) { + if (s) { SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions diff --git a/Marlin/src/HAL/SpiEeprom.cpp b/Marlin/src/HAL/SpiEeprom.cpp index 9e74b4f6f4..f15978b686 100644 --- a/Marlin/src/HAL/SpiEeprom.cpp +++ b/Marlin/src/HAL/SpiEeprom.cpp @@ -53,7 +53,6 @@ uint8_t eeprom_read_byte(uint8_t* pos) { return v; } - void eeprom_read_block(void* dest, const void* eeprom_address, size_t n) { uint8_t eeprom_temp[3]; diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index af99ac08dc..0c7f640869 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -1167,13 +1167,13 @@ SERIAL_ECHO_START(); SERIAL_ECHOLNPGM("EEPROM Dump:"); - for (uint16_t i = 0; i < E2END + 1; i += 16) { + for (uint16_t i = 0; i <= E2END; i += 16) { if (!(i & 0x3)) idle(); print_hex_word(i); SERIAL_ECHOPGM(": "); for (uint16_t j = 0; j < 16; j++) { kkkk = i + j; - eeprom_read_block(&cccc, (const void *) kkkk, sizeof(unsigned char)); + eeprom_read_block(&cccc, (const void *)kkkk, sizeof(unsigned char)); print_hex_byte(cccc); SERIAL_ECHO(' '); } diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index 197d9ad141..50c9d18b55 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -1494,6 +1494,10 @@ void MarlinSettings::postprocess() { return (meshes_end - meshes_start_index()) / sizeof(ubl.z_values); } + int MarlinSettings::mesh_slot_offset(const int8_t slot) { + return meshes_end - (slot + 1) * sizeof(ubl.z_values); + } + void MarlinSettings::store_mesh(const int8_t slot) { #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -1509,8 +1513,8 @@ void MarlinSettings::postprocess() { return; } + int pos = mesh_slot_offset(slot); uint16_t crc = 0; - int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values); HAL::PersistentStore::access_start(); const bool status = HAL::PersistentStore::write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc); @@ -1546,8 +1550,8 @@ void MarlinSettings::postprocess() { return; } + int pos = mesh_slot_offset(slot); uint16_t crc = 0; - int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values); uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values; HAL::PersistentStore::access_start(); diff --git a/Marlin/src/module/configuration_store.h b/Marlin/src/module/configuration_store.h index 3352ce726f..83840ade07 100644 --- a/Marlin/src/module/configuration_store.h +++ b/Marlin/src/module/configuration_store.h @@ -73,6 +73,7 @@ class MarlinSettings { static int16_t meshes_start_index(); FORCE_INLINE static int16_t meshes_end_index() { return meshes_end; } static uint16_t calc_num_meshes(); + static int mesh_slot_offset(const int8_t slot); static void store_mesh(const int8_t slot); static void load_mesh(const int8_t slot, void * const into=NULL); @@ -104,8 +105,8 @@ class MarlinSettings { #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system // That can store is enabled - const static int16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always - // live at the very end of the eeprom + static constexpr int16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always + // live at the very end of the eeprom #endif diff --git a/Marlin/src/pins/pins_RADDS.h b/Marlin/src/pins/pins_RADDS.h index 4a41bb1693..78ff1f7e28 100644 --- a/Marlin/src/pins/pins_RADDS.h +++ b/Marlin/src/pins/pins_RADDS.h @@ -151,8 +151,9 @@ #define SDSS 4 #define PS_ON_PIN 40 +// I2C EEPROM with 8K of space #define I2C_EEPROM -#define E2END 0x2000 +#define E2END 0x1FFF // // LCD / Controller diff --git a/Marlin/src/pins/pins_RAMPS_SMART.h b/Marlin/src/pins/pins_RAMPS_SMART.h index 8f1b3ebafc..48c8dab234 100644 --- a/Marlin/src/pins/pins_RAMPS_SMART.h +++ b/Marlin/src/pins/pins_RAMPS_SMART.h @@ -60,6 +60,10 @@ #define IS_RAMPS_SMART #include "pins_RAMPS.h" +// I2C EEPROM with 4K of space +#define I2C_EEPROM +#define E2END 0xFFF + // // Temperature Sensors // diff --git a/Marlin/src/pins/pins_RURAMPS4D.h b/Marlin/src/pins/pins_RURAMPS4D.h index 5aa8ede239..d92b3b05ec 100644 --- a/Marlin/src/pins/pins_RURAMPS4D.h +++ b/Marlin/src/pins/pins_RURAMPS4D.h @@ -175,7 +175,7 @@ // // EEPROM // -#define E2END 0x8000 // 32Kb (24lc256) +#define E2END 0x7FFF // 32Kb (24lc256) #define I2C_EEPROM // EEPROM on I2C-0 //#define EEPROM_SD // EEPROM on SDCARD //#define SPI_EEPROM // EEPROM on SPI-0