Browse Source

Move crc16 function to libs

Scott Lahteine 6 years ago
parent
commit
356410dcfc

+ 2
- 0
Marlin/src/HAL/shared/persistent_store_api.h View File

25
 #include <stddef.h>
25
 #include <stddef.h>
26
 #include <stdint.h>
26
 #include <stdint.h>
27
 
27
 
28
+#include "../../libs/crc16.h"
29
+
28
 class PersistentStore {
30
 class PersistentStore {
29
 public:
31
 public:
30
   static bool access_start();
32
   static bool access_start();

+ 0
- 13
Marlin/src/core/utility.cpp View File

35
   thermalManager.manage_heater(); // This keeps us safe if too many small safe_delay() calls are made
35
   thermalManager.manage_heater(); // This keeps us safe if too many small safe_delay() calls are made
36
 }
36
 }
37
 
37
 
38
-#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
39
-
40
-  void crc16(uint16_t *crc, const void * const data, uint16_t cnt) {
41
-    uint8_t *ptr = (uint8_t *)data;
42
-    while (cnt--) {
43
-      *crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8));
44
-      for (uint8_t i = 0; i < 8; i++)
45
-        *crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1));
46
-    }
47
-  }
48
-
49
-#endif // EEPROM_SETTINGS || SD_FIRMWARE_UPDATE
50
-
51
 #if ENABLED(DEBUG_LEVELING_FEATURE)
38
 #if ENABLED(DEBUG_LEVELING_FEATURE)
52
 
39
 
53
   #include "../module/probe.h"
40
   #include "../module/probe.h"

+ 4
- 16
Marlin/src/core/utility.h View File

37
   #endif
37
   #endif
38
 }
38
 }
39
 
39
 
40
-#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
41
-  void crc16(uint16_t *crc, const void * const data, uint16_t cnt);
42
-#endif
43
-
44
-#if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
45
-  /**
46
-   * These support functions allow the use of large bit arrays of flags that take very
47
-   * little RAM. Currently they are limited to being 16x16 in size. Changing the declaration
48
-   * to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed
49
-   * in the future.
50
-   */
51
-  FORCE_INLINE void bitmap_clear(uint16_t bits[16], const uint8_t x, const uint8_t y)  { CBI(bits[y], x); }
52
-  FORCE_INLINE void bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y)    { SBI(bits[y], x); }
53
-  FORCE_INLINE bool is_bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
54
-#endif
40
+// 16x16 bit arrays
41
+FORCE_INLINE void bitmap_clear(uint16_t bits[16], const uint8_t x, const uint8_t y)  { CBI(bits[y], x); }
42
+FORCE_INLINE void bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y)    { SBI(bits[y], x); }
43
+FORCE_INLINE bool is_bitmap_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
55
 
44
 
56
 #if ENABLED(DEBUG_LEVELING_FEATURE)
45
 #if ENABLED(DEBUG_LEVELING_FEATURE)
57
   void log_machine_info();
46
   void log_machine_info();
76
 // Converts from an uint8_t in the range of 0-255 to an uint8_t
65
 // Converts from an uint8_t in the range of 0-255 to an uint8_t
77
 // in the range 0-100 while avoiding rounding artifacts
66
 // in the range 0-100 while avoiding rounding artifacts
78
 constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; }
67
 constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; }
79
-constexpr uint8_t all_on = 0xFF, all_off = 0x00;

+ 2
- 0
Marlin/src/feature/backlash.h View File

24
 #include "../inc/MarlinConfigPre.h"
24
 #include "../inc/MarlinConfigPre.h"
25
 #include "../module/planner.h"
25
 #include "../module/planner.h"
26
 
26
 
27
+constexpr uint8_t all_on = 0xFF, all_off = 0x00;
28
+
27
 class Backlash {
29
 class Backlash {
28
 public:
30
 public:
29
   #ifdef BACKLASH_DISTANCE_MM
31
   #ifdef BACKLASH_DISTANCE_MM

+ 2
- 8
Marlin/src/gcode/feature/digipot/M907-M910.cpp View File

85
    */
85
    */
86
   void GcodeSuite::M908() {
86
   void GcodeSuite::M908() {
87
     #if HAS_DIGIPOTSS
87
     #if HAS_DIGIPOTSS
88
-      stepper.digitalPotWrite(
89
-        parser.intval('P'),
90
-        parser.intval('S')
91
-      );
88
+      stepper.digitalPotWrite(parser.intval('P'), parser.intval('S'));
92
     #endif
89
     #endif
93
     #if ENABLED(DAC_STEPPER_CURRENT)
90
     #if ENABLED(DAC_STEPPER_CURRENT)
94
-      dac_current_raw(
95
-        parser.byteval('P', -1),
96
-        parser.ushortval('S', 0)
97
-      );
91
+      dac_current_raw(parser.byteval('P', -1), parser.ushortval('S', 0));
98
     #endif
92
     #endif
99
   }
93
   }
100
 
94
 

+ 32
- 0
Marlin/src/libs/crc16.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "crc16.h"
24
+
25
+void crc16(uint16_t *crc, const void * const data, uint16_t cnt) {
26
+  uint8_t *ptr = (uint8_t *)data;
27
+  while (cnt--) {
28
+    *crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8));
29
+    for (uint8_t i = 0; i < 8; i++)
30
+      *crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1));
31
+  }
32
+}

+ 26
- 0
Marlin/src/libs/crc16.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <stdint.h>
25
+
26
+void crc16(uint16_t *crc, const void * const data, uint16_t cnt);

+ 1
- 1
Marlin/src/sd/usb_flashdrive/lib/Usb.cpp View File

46
 }
46
 }
47
 
47
 
48
 uint8_t USB::getUsbTaskState(void) {
48
 uint8_t USB::getUsbTaskState(void) {
49
-  return ( usb_task_state);
49
+  return usb_task_state;
50
 }
50
 }
51
 
51
 
52
 void USB::setUsbTaskState(uint8_t state) {
52
 void USB::setUsbTaskState(uint8_t state) {

Loading…
Cancel
Save