Fix E2END and add EEPROM to Smart RAMPS

Reference #9983
This commit is contained in:
Scott Lahteine 2018-03-10 03:02:53 -06:00
parent ddce486360
commit 239902f861
8 changed files with 19 additions and 10 deletions

View File

@ -132,7 +132,7 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
UINT bytes_read = 0; UINT bytes_read = 0;
FRESULT s; FRESULT s;
s = f_lseek(&eeprom_file, pos); 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(" 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(",", (int)value); // right now to see errors that are happening in the
SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions

View File

@ -53,7 +53,6 @@ uint8_t eeprom_read_byte(uint8_t* pos) {
return v; return v;
} }
void eeprom_read_block(void* dest, const void* eeprom_address, size_t n) { void eeprom_read_block(void* dest, const void* eeprom_address, size_t n) {
uint8_t eeprom_temp[3]; uint8_t eeprom_temp[3];

View File

@ -1167,13 +1167,13 @@
SERIAL_ECHO_START(); SERIAL_ECHO_START();
SERIAL_ECHOLNPGM("EEPROM Dump:"); 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(); if (!(i & 0x3)) idle();
print_hex_word(i); print_hex_word(i);
SERIAL_ECHOPGM(": "); SERIAL_ECHOPGM(": ");
for (uint16_t j = 0; j < 16; j++) { for (uint16_t j = 0; j < 16; j++) {
kkkk = i + 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); print_hex_byte(cccc);
SERIAL_ECHO(' '); SERIAL_ECHO(' ');
} }

View File

@ -1494,6 +1494,10 @@ void MarlinSettings::postprocess() {
return (meshes_end - meshes_start_index()) / sizeof(ubl.z_values); 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) { void MarlinSettings::store_mesh(const int8_t slot) {
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
@ -1509,8 +1513,8 @@ void MarlinSettings::postprocess() {
return; return;
} }
int pos = mesh_slot_offset(slot);
uint16_t crc = 0; uint16_t crc = 0;
int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values);
HAL::PersistentStore::access_start(); HAL::PersistentStore::access_start();
const bool status = HAL::PersistentStore::write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc); 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; return;
} }
int pos = mesh_slot_offset(slot);
uint16_t crc = 0; 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; uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
HAL::PersistentStore::access_start(); HAL::PersistentStore::access_start();

View File

@ -73,6 +73,7 @@ class MarlinSettings {
static int16_t meshes_start_index(); static int16_t meshes_start_index();
FORCE_INLINE static int16_t meshes_end_index() { return meshes_end; } FORCE_INLINE static int16_t meshes_end_index() { return meshes_end; }
static uint16_t calc_num_meshes(); 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 store_mesh(const int8_t slot);
static void load_mesh(const int8_t slot, void * const into=NULL); 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 #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
// That can store is enabled // 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 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 // live at the very end of the eeprom
#endif #endif

View File

@ -151,8 +151,9 @@
#define SDSS 4 #define SDSS 4
#define PS_ON_PIN 40 #define PS_ON_PIN 40
// I2C EEPROM with 8K of space
#define I2C_EEPROM #define I2C_EEPROM
#define E2END 0x2000 #define E2END 0x1FFF
// //
// LCD / Controller // LCD / Controller

View File

@ -60,6 +60,10 @@
#define IS_RAMPS_SMART #define IS_RAMPS_SMART
#include "pins_RAMPS.h" #include "pins_RAMPS.h"
// I2C EEPROM with 4K of space
#define I2C_EEPROM
#define E2END 0xFFF
// //
// Temperature Sensors // Temperature Sensors
// //

View File

@ -175,7 +175,7 @@
// //
// EEPROM // EEPROM
// //
#define E2END 0x8000 // 32Kb (24lc256) #define E2END 0x7FFF // 32Kb (24lc256)
#define I2C_EEPROM // EEPROM on I2C-0 #define I2C_EEPROM // EEPROM on I2C-0
//#define EEPROM_SD // EEPROM on SDCARD //#define EEPROM_SD // EEPROM on SDCARD
//#define SPI_EEPROM // EEPROM on SPI-0 //#define SPI_EEPROM // EEPROM on SPI-0