From d7ee81202fab12f6d344f8ff7a8796bd49d32593 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 6 Sep 2017 06:28:32 -0500 Subject: [PATCH] Libs updates --- Marlin/src/libs/hex_print_routines.cpp | 79 ++++++++++++++++---------- Marlin/src/libs/hex_print_routines.h | 14 +++-- Marlin/src/libs/least_squares_fit.cpp | 7 +-- Marlin/src/libs/least_squares_fit.h | 13 ++--- Marlin/src/libs/nozzle.cpp | 24 +++++++- Marlin/src/libs/nozzle.h | 4 +- Marlin/src/libs/point_t.h | 5 +- Marlin/src/libs/private_spi.h | 2 +- Marlin/src/libs/softspi.h | 2 - Marlin/src/libs/stopwatch.cpp | 2 +- Marlin/src/libs/stopwatch.h | 4 +- Marlin/src/libs/vector_3.cpp | 7 ++- Marlin/src/libs/vector_3.h | 4 +- 13 files changed, 102 insertions(+), 65 deletions(-) diff --git a/Marlin/src/libs/hex_print_routines.cpp b/Marlin/src/libs/hex_print_routines.cpp index 4c6d3b5881..9e8a2b702a 100644 --- a/Marlin/src/libs/hex_print_routines.cpp +++ b/Marlin/src/libs/hex_print_routines.cpp @@ -19,37 +19,58 @@ * along with this program. If not, see . * */ -#include "Marlin.h" -#include "gcode.h" + +#include "../inc/MarlinConfig.h" #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(M100_FREE_MEMORY_WATCHER) || ENABLED(DEBUG_GCODE_PARSER) -#include "hex_print_routines.h" - -static char _hex[7] = "0x0000"; - -char* hex_byte(const uint8_t b) { - _hex[4] = hex_nybble(b >> 4); - _hex[5] = hex_nybble(b); - return &_hex[4]; -} - -char* hex_word(const uint16_t w) { - _hex[2] = hex_nybble(w >> 12); - _hex[3] = hex_nybble(w >> 8); - _hex[4] = hex_nybble(w >> 4); - _hex[5] = hex_nybble(w); - return &_hex[2]; -} - -char* hex_address(const void * const w) { - (void)hex_word((int)w); - return _hex; -} - -void print_hex_nybble(const uint8_t n) { SERIAL_CHAR(hex_nybble(n)); } -void print_hex_byte(const uint8_t b) { SERIAL_ECHO(hex_byte(b)); } -void print_hex_word(const uint16_t w) { SERIAL_ECHO(hex_word(w)); } -void print_hex_address(const void * const w) { SERIAL_ECHO(hex_address(w)); } + #include "hex_print_routines.h" + + #ifdef CPU_32_BIT + constexpr int byte_start = 0; + static char _hex[] = "0x0000"; + #else + constexpr int byte_start = 4; + static char _hex[] = "0x00000000"; + #endif + + char* hex_byte(const uint8_t b) { + _hex[byte_start + 4] = hex_nybble(b >> 4); + _hex[byte_start + 5] = hex_nybble(b); + return &_hex[byte_start]; + } + + char* hex_word(const uint16_t w) { + _hex[byte_start + 2] = hex_nybble(w >> 12); + _hex[byte_start + 3] = hex_nybble(w >> 8); + _hex[byte_start + 4] = hex_nybble(w >> 4); + _hex[byte_start + 5] = hex_nybble(w); + return &_hex[byte_start - 2]; + } + + #ifdef CPU_32_BIT + char* hex_long(const uint32_t w) { + _hex[byte_start - 2] = hex_nybble(w >> 28); + _hex[byte_start - 1] = hex_nybble(w >> 24); + _hex[byte_start + 0] = hex_nybble(w >> 20); + _hex[byte_start + 1] = hex_nybble(w >> 16); + (void)hex_word((uint16_t)(w & 0xFFFF)); + return &_hex[byte_start - 6]; + } + #endif + + char* hex_address(const void * const w) { + #ifdef CPU_32_BIT + (void)hex_long((ptr_int_t)w); + #else + (void)hex_word((ptr_int_t)w); + #endif + return _hex; + } + + void print_hex_nybble(const uint8_t n) { SERIAL_CHAR(hex_nybble(n)); } + void print_hex_byte(const uint8_t b) { SERIAL_ECHO(hex_byte(b)); } + void print_hex_word(const uint16_t w) { SERIAL_ECHO(hex_word(w)); } + void print_hex_address(const void * const w) { SERIAL_ECHO(hex_address(w)); } #endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER || DEBUG_GCODE_PARSER diff --git a/Marlin/src/libs/hex_print_routines.h b/Marlin/src/libs/hex_print_routines.h index 1ca61e311e..859b79fe31 100644 --- a/Marlin/src/libs/hex_print_routines.h +++ b/Marlin/src/libs/hex_print_routines.h @@ -23,16 +23,13 @@ #ifndef HEX_PRINT_ROUTINES_H #define HEX_PRINT_ROUTINES_H -#include "MarlinConfig.h" -#include "gcode.h" - -#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(M100_FREE_MEMORY_WATCHER) || ENABLED(DEBUG_GCODE_PARSER) +#include // // Utility functions to create and print hex strings as nybble, byte, and word. // -inline char hex_nybble(const uint8_t n) { +FORCE_INLINE char hex_nybble(const uint8_t n) { return (n & 0xF) + ((n & 0xF) < 10 ? '0' : 'A' - 10); } char* hex_byte(const uint8_t b); @@ -44,5 +41,10 @@ void print_hex_byte(const uint8_t b); void print_hex_word(const uint16_t w); void print_hex_address(const void * const w); -#endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER || DEBUG_GCODE_PARSER +#ifdef CPU_32_BIT + typedef uint32_t ptr_int_t; +#else + typedef uint16_t ptr_int_t; +#endif + #endif // HEX_PRINT_ROUTINES_H diff --git a/Marlin/src/libs/least_squares_fit.cpp b/Marlin/src/libs/least_squares_fit.cpp index 66821ce58f..94588a0df5 100644 --- a/Marlin/src/libs/least_squares_fit.cpp +++ b/Marlin/src/libs/least_squares_fit.cpp @@ -32,15 +32,14 @@ * */ -#include "MarlinConfig.h" +#include "../inc/MarlinConfig.h" #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_LINEAR) -#include "macros.h" -#include - #include "least_squares_fit.h" +#include + int finish_incremental_LSF(struct linear_fit_data *lsf) { const float N = lsf->N; diff --git a/Marlin/src/libs/least_squares_fit.h b/Marlin/src/libs/least_squares_fit.h index 9ed923ab49..b45bc23f3d 100644 --- a/Marlin/src/libs/least_squares_fit.h +++ b/Marlin/src/libs/least_squares_fit.h @@ -32,12 +32,10 @@ * */ -#include "MarlinConfig.h" +#ifndef _LEAST_SQUARES_FIT_H_ +#define _LEAST_SQUARES_FIT_H_ -#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_LINEAR) - -#include "Marlin.h" -#include "macros.h" +#include "../inc/MarlinConfig.h" #include struct linear_fit_data { @@ -54,7 +52,7 @@ void inline incremental_LSF_reset(struct linear_fit_data *lsf) { void inline incremental_WLSF(struct linear_fit_data *lsf, const float &x, const float &y, const float &z, const float &w) { // weight each accumulator by factor w, including the "number" of samples - // (analagous to calling inc_LSF twice with same values to weight it by 2X) + // (analogous to calling inc_LSF twice with same values to weight it by 2X) lsf->xbar += w * x; lsf->ybar += w * y; lsf->zbar += w * z; @@ -86,5 +84,4 @@ void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const f int finish_incremental_LSF(struct linear_fit_data *); -#endif - +#endif // _LEAST_SQUARES_FIT_H_ diff --git a/Marlin/src/libs/nozzle.cpp b/Marlin/src/libs/nozzle.cpp index eec8bfa39a..c8c4732f9e 100644 --- a/Marlin/src/libs/nozzle.cpp +++ b/Marlin/src/libs/nozzle.cpp @@ -1,6 +1,28 @@ +/** + * 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 + * + * 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 . + * + */ + #include "nozzle.h" -#include "Marlin.h" +#include "../Marlin.h" #include "point_t.h" /** diff --git a/Marlin/src/libs/nozzle.h b/Marlin/src/libs/nozzle.h index 2fbe98fb06..308efd1c96 100644 --- a/Marlin/src/libs/nozzle.h +++ b/Marlin/src/libs/nozzle.h @@ -23,7 +23,7 @@ #ifndef __NOZZLE_H__ #define __NOZZLE_H__ -#include "Marlin.h" +#include "../inc/MarlinConfig.h" #include "point_t.h" #if ENABLED(NOZZLE_CLEAN_FEATURE) @@ -106,4 +106,4 @@ class Nozzle { ) _Os; }; -#endif +#endif // __NOZZLE_H__ diff --git a/Marlin/src/libs/point_t.h b/Marlin/src/libs/point_t.h index 360abce649..367ee55fe1 100644 --- a/Marlin/src/libs/point_t.h +++ b/Marlin/src/libs/point_t.h @@ -34,10 +34,7 @@ * @param e The e-coordinate of the point. */ struct point_t { - float x; - float y; - float z; - float e; + float x, y, z, e; /** * @brief Two dimensional point constructor diff --git a/Marlin/src/libs/private_spi.h b/Marlin/src/libs/private_spi.h index 45cab24435..d124124fd7 100644 --- a/Marlin/src/libs/private_spi.h +++ b/Marlin/src/libs/private_spi.h @@ -23,8 +23,8 @@ #ifndef __PRIVATE_SPI_H__ #define __PRIVATE_SPI_H__ -#include #include "softspi.h" +#include template class SPI { diff --git a/Marlin/src/libs/softspi.h b/Marlin/src/libs/softspi.h index 3b77e443b3..9f81722d0c 100644 --- a/Marlin/src/libs/softspi.h +++ b/Marlin/src/libs/softspi.h @@ -766,5 +766,3 @@ class SoftSPI { } //---------------------------------------------------------------------------- }; - - diff --git a/Marlin/src/libs/stopwatch.cpp b/Marlin/src/libs/stopwatch.cpp index 5958000f72..29f84099a6 100644 --- a/Marlin/src/libs/stopwatch.cpp +++ b/Marlin/src/libs/stopwatch.cpp @@ -20,7 +20,7 @@ * */ -#include "Marlin.h" +#include "../Marlin.h" #include "stopwatch.h" Stopwatch::Stopwatch() { diff --git a/Marlin/src/libs/stopwatch.h b/Marlin/src/libs/stopwatch.h index ae3c998fb1..c092ee53c8 100644 --- a/Marlin/src/libs/stopwatch.h +++ b/Marlin/src/libs/stopwatch.h @@ -23,7 +23,7 @@ #ifndef STOPWATCH_H #define STOPWATCH_H -#include "macros.h" +#include "../core/types.h" // Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM) //#define DEBUG_STOPWATCH @@ -103,7 +103,7 @@ class Stopwatch { */ millis_t duration(); - #if ENABLED(DEBUG_STOPWATCH) + #ifdef DEBUG_STOPWATCH /** * @brief Prints a debug message diff --git a/Marlin/src/libs/vector_3.cpp b/Marlin/src/libs/vector_3.cpp index f9615bcf08..796085bb23 100644 --- a/Marlin/src/libs/vector_3.cpp +++ b/Marlin/src/libs/vector_3.cpp @@ -38,12 +38,15 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include "Marlin.h" + +#include "../inc/MarlinConfig.h" #if HAS_ABL + #include "vector_3.h" +#include + vector_3::vector_3() : x(0), y(0), z(0) { } vector_3::vector_3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) { } diff --git a/Marlin/src/libs/vector_3.h b/Marlin/src/libs/vector_3.h index 19f6e3a3a7..14fb5b9168 100644 --- a/Marlin/src/libs/vector_3.h +++ b/Marlin/src/libs/vector_3.h @@ -38,11 +38,10 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + #ifndef VECTOR_3_H #define VECTOR_3_H -#if HAS_ABL - class matrix_3x3; struct vector_3 { @@ -79,5 +78,4 @@ struct matrix_3x3 { void apply_rotation_xyz(matrix_3x3 rotationMatrix, float &x, float &y, float &z); -#endif // HAS_ABL #endif // VECTOR_3_H