From a4b01483650ce50e3916d4bc16553429825603ec Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 13 Aug 2018 23:55:12 -0500 Subject: [PATCH 1/2] Easier to find 'static inline' --- Marlin/src/feature/bedlevel/ubl/ubl.h | 6 +++--- Marlin/src/gcode/parser.h | 30 +++++++++++++-------------- Marlin/src/libs/buzzer.h | 2 +- Marlin/src/module/planner.h | 2 +- Marlin/src/module/planner_bezier.cpp | 19 ++++++++--------- Marlin/src/module/stepper.h | 4 ++-- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.h b/Marlin/src/feature/bedlevel/ubl/ubl.h index cbd5ed4bf..2db2b4dd7 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.h +++ b/Marlin/src/feature/bedlevel/ubl/ubl.h @@ -215,7 +215,7 @@ class unified_bed_leveling { * z_correction_for_x_on_horizontal_mesh_line is an optimization for * the case where the printer is making a vertical line that only crosses horizontal mesh lines. */ - inline static float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) { + static inline float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) { if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { @@ -249,7 +249,7 @@ class unified_bed_leveling { // // See comments above for z_correction_for_x_on_horizontal_mesh_line // - inline static float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) { + static inline float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) { if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { @@ -362,7 +362,7 @@ class unified_bed_leveling { static void line_to_destination_cartesian(const float &fr, const uint8_t e); #endif - inline static bool mesh_is_valid() { + static inline bool mesh_is_valid() { for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) if (isnan(z_values[x][y])) return false; diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 82843d622..1665304f7 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -175,10 +175,10 @@ public: FORCE_INLINE static bool has_value() { return value_ptr != NULL; } // Seen a parameter with a value - inline static bool seenval(const char c) { return seen(c) && has_value(); } + static inline bool seenval(const char c) { return seen(c) && has_value(); } // Float removes 'E' to prevent scientific notation interpretation - inline static float value_float() { + static inline float value_float() { if (value_ptr) { char *e = value_ptr; for (;;) { @@ -198,8 +198,8 @@ public: } // Code value as a long or ulong - inline static int32_t value_long() { return value_ptr ? strtol(value_ptr, NULL, 10) : 0L; } - inline static uint32_t value_ulong() { return value_ptr ? strtoul(value_ptr, NULL, 10) : 0UL; } + static inline int32_t value_long() { return value_ptr ? strtol(value_ptr, NULL, 10) : 0L; } + static inline uint32_t value_ulong() { return value_ptr ? strtoul(value_ptr, NULL, 10) : 0UL; } // Code value for use as time FORCE_INLINE static millis_t value_millis() { return value_ulong(); } @@ -208,10 +208,10 @@ public: // Reduce to fewer bits FORCE_INLINE static int16_t value_int() { return (int16_t)value_long(); } FORCE_INLINE static uint16_t value_ushort() { return (uint16_t)value_long(); } - inline static uint8_t value_byte() { return (uint8_t)constrain(value_long(), 0, 255); } + static inline uint8_t value_byte() { return (uint8_t)constrain(value_long(), 0, 255); } // Bool is true with no value or non-zero - inline static bool value_bool() { return !has_value() || !!value_byte(); } + static inline bool value_bool() { return !has_value() || !!value_byte(); } // Units modes: Inches, Fahrenheit, Kelvin @@ -220,7 +220,7 @@ public: // Init linear units by constructor GCodeParser() { set_input_linear_units(LINEARUNIT_MM); } - inline static void set_input_linear_units(const LinearUnit units) { + static inline void set_input_linear_units(const LinearUnit units) { switch (units) { case LINEARUNIT_INCH: linear_unit_factor = 25.4f; @@ -233,13 +233,13 @@ public: volumetric_unit_factor = POW(linear_unit_factor, 3); } - inline static float axis_unit_factor(const AxisEnum axis) { + static inline float axis_unit_factor(const AxisEnum axis) { return (axis >= E_AXIS && volumetric_enabled ? volumetric_unit_factor : linear_unit_factor); } - inline static float value_linear_units() { return value_float() * linear_unit_factor; } - inline static float value_axis_units(const AxisEnum axis) { return value_float() * axis_unit_factor(axis); } - inline static float value_per_axis_unit(const AxisEnum axis) { return value_float() / axis_unit_factor(axis); } + static inline float value_linear_units() { return value_float() * linear_unit_factor; } + static inline float value_axis_units(const AxisEnum axis) { return value_float() * axis_unit_factor(axis); } + static inline float value_per_axis_unit(const AxisEnum axis) { return value_float() / axis_unit_factor(axis); } #else @@ -251,7 +251,7 @@ public: #if ENABLED(TEMPERATURE_UNITS_SUPPORT) - inline static void set_input_temp_units(TempUnit units) { input_temp_units = units; } + static inline void set_input_temp_units(TempUnit units) { input_temp_units = units; } #if ENABLED(ULTIPANEL) && DISABLED(DISABLE_M503) @@ -261,7 +261,7 @@ public: FORCE_INLINE static const char* temp_units_name() { return input_temp_units == TEMPUNIT_K ? PSTR("Kelvin") : input_temp_units == TEMPUNIT_F ? PSTR("Fahrenheit") : PSTR("Celsius"); } - inline static float to_temp_units(const float &f) { + static inline float to_temp_units(const float &f) { switch (input_temp_units) { case TEMPUNIT_F: return f * 0.5555555556f + 32; @@ -275,7 +275,7 @@ public: #endif // ULTIPANEL && !DISABLE_M503 - inline static float value_celsius() { + static inline float value_celsius() { const float f = value_float(); switch (input_temp_units) { case TEMPUNIT_F: @@ -288,7 +288,7 @@ public: } } - inline static float value_celsius_diff() { + static inline float value_celsius_diff() { switch (input_temp_units) { case TEMPUNIT_F: return value_float() * 0.5555555556f; diff --git a/Marlin/src/libs/buzzer.h b/Marlin/src/libs/buzzer.h index 9cc23695c..2da9b8dee 100644 --- a/Marlin/src/libs/buzzer.h +++ b/Marlin/src/libs/buzzer.h @@ -82,7 +82,7 @@ class Buzzer { * @brief Resets the state of the class * @details Brings the class state to a known one. */ - inline static void reset() { + static inline void reset() { off(); state.endtime = 0; } diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index c362bf0f4..8a639a043 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -361,7 +361,7 @@ class Planner { * Returns 1.0 if planner.z_fade_height is 0.0. * Returns 0.0 if Z is past the specified 'Fade Height'. */ - inline static float fade_scaling_factor_for_z(const float &rz) { + static inline float fade_scaling_factor_for_z(const float &rz) { static float z_fade_factor = 1; if (z_fade_height) { if (rz >= z_fade_height) return 0; diff --git a/Marlin/src/module/planner_bezier.cpp b/Marlin/src/module/planner_bezier.cpp index 407d8a067..6ff6808a7 100644 --- a/Marlin/src/module/planner_bezier.cpp +++ b/Marlin/src/module/planner_bezier.cpp @@ -45,7 +45,7 @@ #define SIGMA 0.1f // Compute the linear interpolation between two real numbers. -inline static float interp(float a, float b, float t) { return (1 - t) * a + t * b; } +static inline float interp(const float &a, const float &b, const float &t) { return (1 - t) * a + t * b; } /** * Compute a Bézier curve using the De Casteljau's algorithm (see @@ -53,21 +53,20 @@ inline static float interp(float a, float b, float t) { return (1 - t) * a + t * * easy to code and has good numerical stability (very important, * since Arudino works with limited precision real numbers). */ -inline static float eval_bezier(float a, float b, float c, float d, float t) { - float iab = interp(a, b, t); - float ibc = interp(b, c, t); - float icd = interp(c, d, t); - float iabc = interp(iab, ibc, t); - float ibcd = interp(ibc, icd, t); - float iabcd = interp(iabc, ibcd, t); - return iabcd; +static inline float eval_bezier(const float &a, const float &b, const float &c, const float &d, const float &t) { + const float iab = interp(a, b, t), + ibc = interp(b, c, t), + icd = interp(c, d, t), + iabc = interp(iab, ibc, t), + ibcd = interp(ibc, icd, t); + return interp(iabc, ibcd, t); } /** * We approximate Euclidean distance with the sum of the coordinates * offset (so-called "norm 1"), which is quicker to compute. */ -inline static float dist1(float x1, float y1, float x2, float y2) { return ABS(x1 - x2) + ABS(y1 - y2); } +static inline float dist1(const float &x1, const float &y1, const float &x2, const float &y2) { return ABS(x1 - x2) + ABS(y1 - y2); } /** * The algorithm for computing the step is loosely based on the one in Kig diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 2280bb78b..7e9f9cbe1 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -435,7 +435,7 @@ class Stepper { #endif // Set the current position in steps - inline static void set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) { + static inline void set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) { planner.synchronize(); const bool was_enabled = STEPPER_ISR_ENABLED(); if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT(); @@ -443,7 +443,7 @@ class Stepper { if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT(); } - inline static void set_position(const AxisEnum a, const int32_t &v) { + static inline void set_position(const AxisEnum a, const int32_t &v) { planner.synchronize(); #ifdef __AVR__ From 865ee5985f8a9253897e74ca6ee707ee887b8181 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 13 Aug 2018 20:13:59 -0500 Subject: [PATCH 2/2] Followup persistent store with heading, const --- .../HAL/HAL_AVR/persistent_store_eeprom.cpp | 37 ++++++++----- .../HAL/HAL_DUE/persistent_store_eeprom.cpp | 38 ++++++++----- .../HAL_LPC1768/persistent_store_sdcard.cpp | 55 +++++++++---------- .../HAL_STM32F1/persistent_store_flash.cpp | 21 +------ .../HAL_STM32F1/persistent_store_sdcard.cpp | 20 +------ .../HAL_STM32F4/persistent_store_eeprom.cpp | 16 +----- .../HAL_STM32F7/persistent_store_eeprom.cpp | 17 +----- .../persistent_store_eeprom.cpp | 39 ++++++++----- Marlin/src/HAL/persistent_store_api.cpp | 7 ++- Marlin/src/HAL/persistent_store_api.h | 21 +++++-- 10 files changed, 122 insertions(+), 149 deletions(-) diff --git a/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp index f1489e70d..293955937 100644 --- a/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp @@ -1,3 +1,24 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * + * 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 3 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 . + * + */ #ifdef __AVR__ #include "../../inc/MarlinConfig.h" @@ -41,21 +62,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; // always assume success for AVR's } -bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return write_data(data_pos, value, size, &crc); -} - -bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return read_data(data_pos, value, size, &crc); -} - -const size_t PersistentStore::capacity() { - return E2END + 1; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // __AVR__ diff --git a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp index ad66b7b92..3bf0f443b 100644 --- a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp @@ -1,3 +1,25 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com + * + * 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 3 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 . + * + */ #ifdef ARDUINO_ARCH_SAM #include "../persistent_store_api.h" @@ -49,21 +71,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return write_data(data_pos, value, size, &crc); -} - -bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return read_data(data_pos, value, size, &crc); -} - -const size_t PersistentStore::capacity() { - return E2END + 1; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp index 630ab073e..42264e1cc 100644 --- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp @@ -1,9 +1,10 @@ /** * Marlin 3D Printer Firmware - * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * - * Based on Sprinter and grbl. - * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com * * 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 @@ -98,8 +99,8 @@ bool PersistentStore::access_finish() { // FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ // } FRESULT; -bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { - if(!eeprom_file_open) return true; +bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) { + if (!eeprom_file_open) return true; FRESULT s; UINT bytes_written = 0; @@ -113,7 +114,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui return s; } - s = f_write(&eeprom_file, (void *)value, size, &bytes_written); + s = f_write(&eeprom_file, (void*)value, size, &bytes_written); if (s) { SERIAL_PROTOCOLPAIR(" write_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 @@ -129,57 +130,51 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui return (bytes_written != size); // return true for any error } -bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { - if(!eeprom_file_open) return true; +bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) { + if (!eeprom_file_open) return true; UINT bytes_read = 0; FRESULT s; s = f_lseek(&eeprom_file, pos); + 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 + SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful + SERIAL_PROTOCOLCHAR(','); + SERIAL_PROTOCOL((int)value); // right now to see errors that are happening in the + SERIAL_PROTOCOLCHAR(','); + SERIAL_PROTOCOL(size); // read_data() and write_data() functions SERIAL_PROTOCOLLNPGM("...)"); SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s); return true; } + if (writing) { - s = f_read(&eeprom_file, (void *)value, size, &bytes_read); + s = f_read(&eeprom_file, (void*)value, size, &bytes_read); crc16(crc, value, size); } else { uint8_t temp[size]; - s = f_read(&eeprom_file, (void *)temp, size, &bytes_read); + s = f_read(&eeprom_file, (void*)temp, size, &bytes_read); crc16(crc, temp, size); } + 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 + SERIAL_PROTOCOLCHAR(','); + SERIAL_PROTOCOL((int)value); // right now to see errors that are happening in the + SERIAL_PROTOCOLCHAR(','); + SERIAL_PROTOCOL(size); // read_data() and write_data() functions SERIAL_PROTOCOLLNPGM("...)"); SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s); SERIAL_PROTOCOLPAIR(" size=", size); SERIAL_PROTOCOLLNPAIR("\n bytes_read=", bytes_read); return true; } + pos = pos + size; return bytes_read != size; // return true for any error } -bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return write_data(data_pos, value, size, &crc); -} - -bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return read_data(data_pos, value, size, &crc); -} - -const size_t PersistentStore::capacity() { - return 4096; //4KiB of Emulated EEPROM -} +const size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM #endif // EEPROM_SETTINGS #endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp index c6be9c179..779225d09 100644 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp @@ -55,7 +55,7 @@ bool PersistentStore::access_finish() { return true; } -bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { +bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) { FLASH_Status status; if (firstWrite) { @@ -90,7 +90,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui return false; } -bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { +bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) { for (uint16_t i = 0; i < size; i++) { byte* accessPoint = (byte*)(pageBase + pos + i); uint8_t c = *accessPoint; @@ -101,22 +101,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return write_data(data_pos, value, size, &crc); -} - -bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return read_data(data_pos, value, size, &crc); -} - -const size_t PersistentStore::capacity() { - return E2END + 1; -} - +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS && EEPROM FLASH #endif // __STM32F1__ diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp index b5b4d424a..26e011cf1 100644 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp @@ -60,7 +60,7 @@ bool PersistentStore::access_finish() { return (bytes_written == HAL_STM32F1_EEPROM_SIZE); } -bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { +bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) { for (int i = 0; i < size; i++) HAL_STM32F1_eeprom_content[pos + i] = value[i]; crc16(crc, value, size); @@ -68,7 +68,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui return false; } -bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { +bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) { for (int i = 0; i < size; i++) { uint8_t c = HAL_STM32F1_eeprom_content[pos + i]; if (writing) value[i] = c; @@ -78,21 +78,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return write_data(data_pos, value, size, &crc); -} - -bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return read_data(data_pos, value, size, &crc); -} - -const size_t PersistentStore::capacity() { - return HAL_STM32F1_EEPROM_SIZE; -} +const size_t PersistentStore::capacity() { return HAL_STM32F1_EEPROM_SIZE; } #endif // EEPROM_SETTINGS diff --git a/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp index 6d262ae38..33a92f99d 100644 --- a/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp @@ -64,21 +64,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return write_data(data_pos, value, size, &crc); -} - -bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return read_data(data_pos, value, size, &crc); -} - -const size_t PersistentStore::capacity() { - return E2END + 1; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // STM32F4 || STM32F4xx diff --git a/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp index 19f61153c..a765d2e68 100644 --- a/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp @@ -21,7 +21,6 @@ * */ - #ifdef STM32F7 #include "../../inc/MarlinConfig.h" @@ -65,21 +64,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return write_data(data_pos, value, size, &crc); -} - -bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return read_data(data_pos, value, size, &crc); -} - -const size_t PersistentStore::capacity() { - return E2END + 1; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // STM32F7 diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp index 453287797..871e58877 100644 --- a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp @@ -1,3 +1,26 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com + * + * 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 3 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 . + * + */ + #if defined(__MK64FX512__) || defined(__MK66FX1M0__) #include "../../inc/MarlinConfig.h" @@ -42,21 +65,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return write_data(data_pos, value, size, &crc); -} - -bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) { - int data_pos = pos; - uint16_t crc = 0; - return read_data(data_pos, value, size, &crc); -} - -const size_t PersistentStore::capacity() { - return E2END + 1; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // __MK64FX512__ || __MK66FX1M0__ diff --git a/Marlin/src/HAL/persistent_store_api.cpp b/Marlin/src/HAL/persistent_store_api.cpp index 303027b37..68afa6362 100644 --- a/Marlin/src/HAL/persistent_store_api.cpp +++ b/Marlin/src/HAL/persistent_store_api.cpp @@ -1,9 +1,10 @@ /** * Marlin 3D Printer Firmware - * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * - * Based on Sprinter and grbl. - * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com * * 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 diff --git a/Marlin/src/HAL/persistent_store_api.h b/Marlin/src/HAL/persistent_store_api.h index b8aea044a..278e49a8a 100644 --- a/Marlin/src/HAL/persistent_store_api.h +++ b/Marlin/src/HAL/persistent_store_api.h @@ -1,9 +1,10 @@ /** * Marlin 3D Printer Firmware - * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * - * Based on Sprinter and grbl. - * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com * * 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 @@ -30,9 +31,19 @@ public: static bool access_finish(); static bool write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc); static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true); - static bool write_data(const int pos, uint8_t* value, size_t size); - static bool read_data(const int pos, uint8_t* value, size_t size); static const size_t capacity(); + + static inline bool write_data(const int pos, uint8_t* value, const size_t size) { + int data_pos = pos; + uint16_t crc = 0; + return write_data(data_pos, value, size, &crc); + } + + static inline bool read_data(const int pos, uint8_t* value, const size_t size) { + int data_pos = pos; + uint16_t crc = 0; + return read_data(data_pos, value, size, &crc); + } }; extern PersistentStore persistentStore;