Bladeren bron

🎨 Minor HAL cleanup

Scott Lahteine 3 jaren geleden
bovenliggende
commit
12da2e9288

+ 4
- 0
Marlin/src/HAL/AVR/HAL.cpp Bestand weergeven

88
   #endif
88
   #endif
89
 }
89
 }
90
 
90
 
91
+// ------------------------
92
+// Free Memory Accessor
93
+// ------------------------
94
+
91
 #if ENABLED(SDSUPPORT)
95
 #if ENABLED(SDSUPPORT)
92
 
96
 
93
   #include "../../sd/SdFatUtil.h"
97
   #include "../../sd/SdFatUtil.h"

+ 1
- 1
Marlin/src/HAL/AVR/HAL.h Bestand weergeven

167
 #define strtof strtod
167
 #define strtof strtod
168
 
168
 
169
 // ------------------------
169
 // ------------------------
170
-// Class Utilities
170
+// Free Memory Accessor
171
 // ------------------------
171
 // ------------------------
172
 
172
 
173
 #pragma GCC diagnostic push
173
 #pragma GCC diagnostic push

+ 12
- 3
Marlin/src/HAL/DUE/HAL.cpp Bestand weergeven

40
 // Public functions
40
 // Public functions
41
 // ------------------------
41
 // ------------------------
42
 
42
 
43
-TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial());
43
+#if ENABLED(POSTMORTEM_DEBUGGING)
44
+  extern void install_min_serial();
45
+#endif
44
 
46
 
45
 void MarlinHAL::init() {
47
 void MarlinHAL::init() {
46
-  // Initialize the USB stack
47
   #if ENABLED(SDSUPPORT)
48
   #if ENABLED(SDSUPPORT)
48
     OUT_WRITE(SDSS, HIGH);  // Try to set SDSS inactive before any other SPI users start up
49
     OUT_WRITE(SDSS, HIGH);  // Try to set SDSS inactive before any other SPI users start up
49
   #endif
50
   #endif
50
-  usb_task_init();
51
+  usb_task_init();          // Initialize the USB stack
51
   TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler
52
   TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler
52
 }
53
 }
53
 
54
 
72
 
73
 
73
 void MarlinHAL::reboot() { rstc_start_software_reset(RSTC); }
74
 void MarlinHAL::reboot() { rstc_start_software_reset(RSTC); }
74
 
75
 
76
+// ------------------------
77
+// Free Memory Accessor
78
+// ------------------------
79
+
75
 extern "C" {
80
 extern "C" {
76
   extern unsigned int _ebss; // end of bss section
81
   extern unsigned int _ebss; // end of bss section
77
 }
82
 }
82
   return (int)&free_memory - (heap_end ?: (int)&_ebss);
87
   return (int)&free_memory - (heap_end ?: (int)&_ebss);
83
 }
88
 }
84
 
89
 
90
+// ------------------------
91
+// Serial Ports
92
+// ------------------------
93
+
85
 // Forward the default serial ports
94
 // Forward the default serial ports
86
 #if USING_HW_SERIAL0
95
 #if USING_HW_SERIAL0
87
   DefaultSerial1 MSerial0(false, Serial);
96
   DefaultSerial1 MSerial0(false, Serial);

+ 0
- 2
Marlin/src/HAL/DUE/HAL_SPI.cpp Bestand weergeven

31
 
31
 
32
 /**
32
 /**
33
  * HAL for Arduino Due and compatible (SAM3X8E)
33
  * HAL for Arduino Due and compatible (SAM3X8E)
34
- *
35
- * For ARDUINO_ARCH_SAM
36
  */
34
  */
37
 
35
 
38
 #ifdef ARDUINO_ARCH_SAM
36
 #ifdef ARDUINO_ARCH_SAM

+ 1
- 0
Marlin/src/HAL/HAL.h Bestand weergeven

28
 #endif
28
 #endif
29
 
29
 
30
 #include HAL_PATH(.,HAL.h)
30
 #include HAL_PATH(.,HAL.h)
31
+extern MarlinHAL hal;
31
 
32
 
32
 #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
33
 #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
33
 
34
 

+ 1
- 1
Marlin/src/HAL/LPC1768/HAL.h Bestand weergeven

177
 #define CPU_ST7920_DELAY_3 750
177
 #define CPU_ST7920_DELAY_3 750
178
 
178
 
179
 // ------------------------
179
 // ------------------------
180
-// Class Utilities
180
+// Free Memory Accessor
181
 // ------------------------
181
 // ------------------------
182
 
182
 
183
 #pragma GCC diagnostic push
183
 #pragma GCC diagnostic push

+ 1
- 1
Marlin/src/HAL/NATIVE_SIM/HAL.h Bestand weergeven

186
 }
186
 }
187
 
187
 
188
 // ------------------------
188
 // ------------------------
189
-// Class Utilities
189
+// Free Memory Accessor
190
 // ------------------------
190
 // ------------------------
191
 
191
 
192
 #pragma GCC diagnostic push
192
 #pragma GCC diagnostic push

+ 2
- 3
Marlin/src/HAL/STM32/HAL.cpp Bestand weergeven

24
 
24
 
25
 #ifdef HAL_STM32
25
 #ifdef HAL_STM32
26
 
26
 
27
-#include "HAL.h"
28
-#include "usb_serial.h"
29
-
30
 #include "../../inc/MarlinConfig.h"
27
 #include "../../inc/MarlinConfig.h"
31
 #include "../shared/Delay.h"
28
 #include "../shared/Delay.h"
32
 
29
 
30
+#include "usb_serial.h"
31
+
33
 #ifdef USBCON
32
 #ifdef USBCON
34
   DefaultSerial1 MSerialUSB(false, SerialUSB);
33
   DefaultSerial1 MSerialUSB(false, SerialUSB);
35
 #endif
34
 #endif

+ 7
- 2
Marlin/src/HAL/STM32F1/HAL.cpp Bestand weergeven

83
 // ------------------------
83
 // ------------------------
84
 
84
 
85
 #if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE
85
 #if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE
86
+
86
   USBSerial SerialUSB;
87
   USBSerial SerialUSB;
87
   DefaultSerial1 MSerial0(true, SerialUSB);
88
   DefaultSerial1 MSerial0(true, SerialUSB);
88
 
89
 
211
 
212
 
212
 void MarlinHAL::reboot() { nvic_sys_reset(); }
213
 void MarlinHAL::reboot() { nvic_sys_reset(); }
213
 
214
 
215
+// ------------------------
216
+// Free Memory Accessor
217
+// ------------------------
218
+
214
 extern "C" {
219
 extern "C" {
215
   extern unsigned int _ebss; // end of bss section
220
   extern unsigned int _ebss; // end of bss section
216
 }
221
 }
243
 }
248
 }
244
 */
249
 */
245
 
250
 
246
-//
251
+// ------------------------
247
 // ADC
252
 // ADC
248
-//
253
+// ------------------------
249
 
254
 
250
 enum ADCIndex : uint8_t {
255
 enum ADCIndex : uint8_t {
251
   OPTITEM(HAS_TEMP_ADC_0, TEMP_0)
256
   OPTITEM(HAS_TEMP_ADC_0, TEMP_0)

+ 21
- 19
Marlin/src/HAL/TEENSY31_32/HAL.cpp Bestand weergeven

45
 USBSerialType USBSerial(false, SerialUSB);
45
 USBSerialType USBSerial(false, SerialUSB);
46
 
46
 
47
 // ------------------------
47
 // ------------------------
48
-// Class Utilities
49
-// ------------------------
50
-
51
-extern "C" {
52
-  extern char __bss_end;
53
-  extern char __heap_start;
54
-  extern void* __brkval;
55
-
56
-  int freeMemory() {
57
-    int free_memory;
58
-    if ((int)__brkval == 0)
59
-      free_memory = ((int)&free_memory) - ((int)&__bss_end);
60
-    else
61
-      free_memory = ((int)&free_memory) - ((int)__brkval);
62
-    return free_memory;
63
-  }
64
-}
65
-
66
-// ------------------------
67
 // MarlinHAL Class
48
 // MarlinHAL Class
68
 // ------------------------
49
 // ------------------------
69
 
50
 
81
   return 0;
62
   return 0;
82
 }
63
 }
83
 
64
 
65
+// ------------------------
84
 // ADC
66
 // ADC
67
+// ------------------------
85
 
68
 
86
 void MarlinHAL::adc_init() {
69
 void MarlinHAL::adc_init() {
87
   analog_init();
70
   analog_init();
102
 
85
 
103
 uint16_t MarlinHAL::adc_value() { return ADC0_RA; }
86
 uint16_t MarlinHAL::adc_value() { return ADC0_RA; }
104
 
87
 
88
+// ------------------------
89
+// Free Memory Accessor
90
+// ------------------------
91
+
92
+extern "C" {
93
+  extern char __bss_end;
94
+  extern char __heap_start;
95
+  extern void* __brkval;
96
+
97
+  int freeMemory() {
98
+    int free_memory;
99
+    if ((int)__brkval == 0)
100
+      free_memory = ((int)&free_memory) - ((int)&__bss_end);
101
+    else
102
+      free_memory = ((int)&free_memory) - ((int)__brkval);
103
+    return free_memory;
104
+  }
105
+}
106
+
105
 #endif // __MK20DX256__
107
 #endif // __MK20DX256__

+ 21
- 21
Marlin/src/HAL/TEENSY35_36/HAL.cpp Bestand weergeven

44
 USBSerialType USBSerial(false, SerialUSB);
44
 USBSerialType USBSerial(false, SerialUSB);
45
 
45
 
46
 // ------------------------
46
 // ------------------------
47
-// Class Utilities
48
-// ------------------------
49
-
50
-extern "C" {
51
-  extern char __bss_end;
52
-  extern char __heap_start;
53
-  extern void* __brkval;
54
-
55
-  int freeMemory() {
56
-    int free_memory;
57
-    if ((int)__brkval == 0)
58
-      free_memory = ((int)&free_memory) - ((int)&__bss_end);
59
-    else
60
-      free_memory = ((int)&free_memory) - ((int)__brkval);
61
-    return free_memory;
62
-  }
63
-}
64
-
65
-// ------------------------
66
 // MarlinHAL Class
47
 // MarlinHAL Class
67
 // ------------------------
48
 // ------------------------
68
 
49
 
69
 void MarlinHAL::reboot() { _reboot_Teensyduino_(); }
50
 void MarlinHAL::reboot() { _reboot_Teensyduino_(); }
70
 
51
 
71
-// Reset
72
-
73
 uint8_t MarlinHAL::get_reset_source() {
52
 uint8_t MarlinHAL::get_reset_source() {
74
   switch (RCM_SRS0) {
53
   switch (RCM_SRS0) {
75
     case 128: return RST_POWER_ON; break;
54
     case 128: return RST_POWER_ON; break;
82
   return 0;
61
   return 0;
83
 }
62
 }
84
 
63
 
64
+// ------------------------
85
 // ADC
65
 // ADC
66
+// ------------------------
86
 
67
 
87
 int8_t MarlinHAL::adc_select;
68
 int8_t MarlinHAL::adc_select;
88
 
69
 
131
   return 0;
112
   return 0;
132
 }
113
 }
133
 
114
 
115
+// ------------------------
116
+// Free Memory Accessor
117
+// ------------------------
118
+
119
+extern "C" {
120
+  extern char __bss_end;
121
+  extern char __heap_start;
122
+  extern void* __brkval;
123
+
124
+  int freeMemory() {
125
+    int free_memory;
126
+    if ((int)__brkval == 0)
127
+      free_memory = ((int)&free_memory) - ((int)&__bss_end);
128
+    else
129
+      free_memory = ((int)&free_memory) - ((int)__brkval);
130
+    return free_memory;
131
+  }
132
+}
133
+
134
 #endif // __MK64FX512__ || __MK66FX1M0__
134
 #endif // __MK64FX512__ || __MK66FX1M0__

+ 1
- 1
Marlin/src/HAL/TEENSY35_36/HAL.h Bestand weergeven

118
 #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
118
 #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
119
 
119
 
120
 // ------------------------
120
 // ------------------------
121
-// Class Utilities
121
+// Free Memory Accessor
122
 // ------------------------
122
 // ------------------------
123
 
123
 
124
 #pragma GCC diagnostic push
124
 #pragma GCC diagnostic push

+ 21
- 19
Marlin/src/HAL/TEENSY40_41/HAL.cpp Bestand weergeven

45
 USBSerialType USBSerial(false, SerialUSB);
45
 USBSerialType USBSerial(false, SerialUSB);
46
 
46
 
47
 // ------------------------
47
 // ------------------------
48
-// Class Utilities
49
-// ------------------------
50
-
51
-#define __bss_end _ebss
52
-
53
-extern "C" {
54
-  extern char __bss_end;
55
-  extern char __heap_start;
56
-  extern void* __brkval;
57
-
58
-  // Doesn't work on Teensy 4.x
59
-  uint32_t freeMemory() {
60
-    uint32_t free_memory;
61
-    free_memory = ((uint32_t)&free_memory) - (((uint32_t)__brkval) ?: ((uint32_t)&__bss_end));
62
-    return free_memory;
63
-  }
64
-}
65
-
66
-// ------------------------
67
 // FastIO
48
 // FastIO
68
 // ------------------------
49
 // ------------------------
69
 
50
 
97
   SRC_SRSR = reset_source;
78
   SRC_SRSR = reset_source;
98
 }
79
 }
99
 
80
 
81
+// ------------------------
100
 // ADC
82
 // ADC
83
+// ------------------------
101
 
84
 
102
 int8_t MarlinHAL::adc_select;
85
 int8_t MarlinHAL::adc_select;
103
 
86
 
180
   return 0;
163
   return 0;
181
 }
164
 }
182
 
165
 
166
+// ------------------------
167
+// Free Memory Accessor
168
+// ------------------------
169
+
170
+#define __bss_end _ebss
171
+
172
+extern "C" {
173
+  extern char __bss_end;
174
+  extern char __heap_start;
175
+  extern void* __brkval;
176
+
177
+  // Doesn't work on Teensy 4.x
178
+  uint32_t freeMemory() {
179
+    uint32_t free_memory;
180
+    free_memory = ((uint32_t)&free_memory) - (((uint32_t)__brkval) ?: ((uint32_t)&__bss_end));
181
+    return free_memory;
182
+  }
183
+}
184
+
183
 #endif // __IMXRT1062__
185
 #endif // __IMXRT1062__

+ 1
- 1
Marlin/src/HAL/TEENSY40_41/HAL.h Bestand weergeven

140
 bool is_output(pin_t pin);
140
 bool is_output(pin_t pin);
141
 
141
 
142
 // ------------------------
142
 // ------------------------
143
-// Class Utilities
143
+// Free Memory Accessor
144
 // ------------------------
144
 // ------------------------
145
 
145
 
146
 #pragma GCC diagnostic push
146
 #pragma GCC diagnostic push

+ 0
- 1
Marlin/src/inc/MarlinConfig.h Bestand weergeven

29
 
29
 
30
 #ifndef __MARLIN_DEPS__
30
 #ifndef __MARLIN_DEPS__
31
   #include "../HAL/HAL.h"
31
   #include "../HAL/HAL.h"
32
-  extern MarlinHAL hal;
33
 #endif
32
 #endif
34
 
33
 
35
 #include "../pins/pins.h"
34
 #include "../pins/pins.h"

Laden…
Annuleren
Opslaan