From 356410dcfce70972f9cfbafd9c32a71701781640 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 11 Jun 2019 07:41:54 -0500 Subject: [PATCH] Move crc16 function to libs --- Marlin/src/HAL/shared/persistent_store_api.h | 2 ++ Marlin/src/core/utility.cpp | 13 -------- Marlin/src/core/utility.h | 20 +++--------- Marlin/src/feature/backlash.h | 2 ++ .../src/gcode/feature/digipot/M907-M910.cpp | 10 ++---- Marlin/src/libs/crc16.cpp | 32 +++++++++++++++++++ Marlin/src/libs/crc16.h | 26 +++++++++++++++ Marlin/src/sd/usb_flashdrive/lib/Usb.cpp | 2 +- 8 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 Marlin/src/libs/crc16.cpp create mode 100644 Marlin/src/libs/crc16.h diff --git a/Marlin/src/HAL/shared/persistent_store_api.h b/Marlin/src/HAL/shared/persistent_store_api.h index de9f1c109..1e1bc983b 100644 --- a/Marlin/src/HAL/shared/persistent_store_api.h +++ b/Marlin/src/HAL/shared/persistent_store_api.h @@ -25,6 +25,8 @@ #include #include +#include "../../libs/crc16.h" + class PersistentStore { public: static bool access_start(); diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index f8415637e..4f2cb8107 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -35,19 +35,6 @@ void safe_delay(millis_t ms) { thermalManager.manage_heater(); // This keeps us safe if too many small safe_delay() calls are made } -#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE) - - void crc16(uint16_t *crc, const void * const data, uint16_t cnt) { - uint8_t *ptr = (uint8_t *)data; - while (cnt--) { - *crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8)); - for (uint8_t i = 0; i < 8; i++) - *crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1)); - } - } - -#endif // EEPROM_SETTINGS || SD_FIRMWARE_UPDATE - #if ENABLED(DEBUG_LEVELING_FEATURE) #include "../module/probe.h" diff --git a/Marlin/src/core/utility.h b/Marlin/src/core/utility.h index d27e742c9..2e226e2ba 100644 --- a/Marlin/src/core/utility.h +++ b/Marlin/src/core/utility.h @@ -37,21 +37,10 @@ inline void serial_delay(const millis_t ms) { #endif } -#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE) - void crc16(uint16_t *crc, const void * const data, uint16_t cnt); -#endif - -#if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION) - /** - * These support functions allow the use of large bit arrays of flags that take very - * little RAM. Currently they are limited to being 16x16 in size. Changing the declaration - * to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed - * in the future. - */ - FORCE_INLINE void bitmap_clear(uint16_t bits[16], const uint8_t x, const uint8_t y) { CBI(bits[y], x); } - FORCE_INLINE void bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { SBI(bits[y], x); } - FORCE_INLINE bool is_bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); } -#endif +// 16x16 bit arrays +FORCE_INLINE void bitmap_clear(uint16_t bits[16], const uint8_t x, const uint8_t y) { CBI(bits[y], x); } +FORCE_INLINE void bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { SBI(bits[y], x); } +FORCE_INLINE bool is_bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); } #if ENABLED(DEBUG_LEVELING_FEATURE) void log_machine_info(); @@ -76,4 +65,3 @@ public: // Converts from an uint8_t in the range of 0-255 to an uint8_t // in the range 0-100 while avoiding rounding artifacts constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; } -constexpr uint8_t all_on = 0xFF, all_off = 0x00; diff --git a/Marlin/src/feature/backlash.h b/Marlin/src/feature/backlash.h index f2dffe131..623a5fa0f 100644 --- a/Marlin/src/feature/backlash.h +++ b/Marlin/src/feature/backlash.h @@ -24,6 +24,8 @@ #include "../inc/MarlinConfigPre.h" #include "../module/planner.h" +constexpr uint8_t all_on = 0xFF, all_off = 0x00; + class Backlash { public: #ifdef BACKLASH_DISTANCE_MM diff --git a/Marlin/src/gcode/feature/digipot/M907-M910.cpp b/Marlin/src/gcode/feature/digipot/M907-M910.cpp index 107c77f41..541c32d05 100644 --- a/Marlin/src/gcode/feature/digipot/M907-M910.cpp +++ b/Marlin/src/gcode/feature/digipot/M907-M910.cpp @@ -85,16 +85,10 @@ void GcodeSuite::M907() { */ void GcodeSuite::M908() { #if HAS_DIGIPOTSS - stepper.digitalPotWrite( - parser.intval('P'), - parser.intval('S') - ); + stepper.digitalPotWrite(parser.intval('P'), parser.intval('S')); #endif #if ENABLED(DAC_STEPPER_CURRENT) - dac_current_raw( - parser.byteval('P', -1), - parser.ushortval('S', 0) - ); + dac_current_raw(parser.byteval('P', -1), parser.ushortval('S', 0)); #endif } diff --git a/Marlin/src/libs/crc16.cpp b/Marlin/src/libs/crc16.cpp new file mode 100644 index 000000000..a5a8a2809 --- /dev/null +++ b/Marlin/src/libs/crc16.cpp @@ -0,0 +1,32 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2019 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 "crc16.h" + +void crc16(uint16_t *crc, const void * const data, uint16_t cnt) { + uint8_t *ptr = (uint8_t *)data; + while (cnt--) { + *crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8)); + for (uint8_t i = 0; i < 8; i++) + *crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1)); + } +} diff --git a/Marlin/src/libs/crc16.h b/Marlin/src/libs/crc16.h new file mode 100644 index 000000000..507ad48ef --- /dev/null +++ b/Marlin/src/libs/crc16.h @@ -0,0 +1,26 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2019 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 . + * + */ +#pragma once + +#include + +void crc16(uint16_t *crc, const void * const data, uint16_t cnt); diff --git a/Marlin/src/sd/usb_flashdrive/lib/Usb.cpp b/Marlin/src/sd/usb_flashdrive/lib/Usb.cpp index 4ca0b2dde..b0a6d2943 100644 --- a/Marlin/src/sd/usb_flashdrive/lib/Usb.cpp +++ b/Marlin/src/sd/usb_flashdrive/lib/Usb.cpp @@ -46,7 +46,7 @@ void USB::init() { } uint8_t USB::getUsbTaskState(void) { - return ( usb_task_state); + return usb_task_state; } void USB::setUsbTaskState(uint8_t state) {