Move crc16 function to libs

This commit is contained in:
Scott Lahteine 2019-06-11 07:41:54 -05:00
parent 2a96d4e23a
commit 356410dcfc
8 changed files with 69 additions and 38 deletions

View File

@ -25,6 +25,8 @@
#include <stddef.h>
#include <stdint.h>
#include "../../libs/crc16.h"
class PersistentStore {
public:
static bool access_start();

View File

@ -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"

View File

@ -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;

View File

@ -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

View File

@ -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
}

32
Marlin/src/libs/crc16.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#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));
}
}

26
Marlin/src/libs/crc16.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include <stdint.h>
void crc16(uint16_t *crc, const void * const data, uint16_t cnt);

View File

@ -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) {