Browse Source

🎨 Minor HAL cleanup

FB4S_WIFI
Scott Lahteine 3 years ago
parent
commit
a0fe4f4895
  1. 4
      Marlin/src/HAL/AVR/HAL.cpp
  2. 2
      Marlin/src/HAL/AVR/HAL.h
  3. 15
      Marlin/src/HAL/DUE/HAL.cpp
  4. 2
      Marlin/src/HAL/DUE/HAL_SPI.cpp
  5. 1
      Marlin/src/HAL/HAL.h
  6. 2
      Marlin/src/HAL/LPC1768/HAL.h
  7. 2
      Marlin/src/HAL/NATIVE_SIM/HAL.h
  8. 5
      Marlin/src/HAL/STM32/HAL.cpp
  9. 9
      Marlin/src/HAL/STM32F1/HAL.cpp
  10. 40
      Marlin/src/HAL/TEENSY31_32/HAL.cpp
  11. 42
      Marlin/src/HAL/TEENSY35_36/HAL.cpp
  12. 2
      Marlin/src/HAL/TEENSY35_36/HAL.h
  13. 40
      Marlin/src/HAL/TEENSY40_41/HAL.cpp
  14. 2
      Marlin/src/HAL/TEENSY40_41/HAL.h
  15. 1
      Marlin/src/inc/MarlinConfig.h

4
Marlin/src/HAL/AVR/HAL.cpp

@ -88,6 +88,10 @@ void MarlinHAL::reboot() {
#endif #endif
} }
// ------------------------
// Free Memory Accessor
// ------------------------
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
#include "../../sd/SdFatUtil.h" #include "../../sd/SdFatUtil.h"

2
Marlin/src/HAL/AVR/HAL.h

@ -163,7 +163,7 @@ typedef Servo hal_servo_t;
#define strtof strtod #define strtof strtod
// ------------------------ // ------------------------
// Class Utilities // Free Memory Accessor
// ------------------------ // ------------------------
#pragma GCC diagnostic push #pragma GCC diagnostic push

15
Marlin/src/HAL/DUE/HAL.cpp

@ -40,14 +40,15 @@ uint16_t MarlinHAL::adc_result;
// Public functions // Public functions
// ------------------------ // ------------------------
TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial()); #if ENABLED(POSTMORTEM_DEBUGGING)
extern void install_min_serial();
#endif
void MarlinHAL::init() { void MarlinHAL::init() {
// Initialize the USB stack
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
#endif #endif
usb_task_init(); usb_task_init(); // Initialize the USB stack
TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler
} }
@ -72,6 +73,10 @@ uint8_t MarlinHAL::get_reset_source() {
void MarlinHAL::reboot() { rstc_start_software_reset(RSTC); } void MarlinHAL::reboot() { rstc_start_software_reset(RSTC); }
// ------------------------
// Free Memory Accessor
// ------------------------
extern "C" { extern "C" {
extern unsigned int _ebss; // end of bss section extern unsigned int _ebss; // end of bss section
} }
@ -82,6 +87,10 @@ int freeMemory() {
return (int)&free_memory - (heap_end ?: (int)&_ebss); return (int)&free_memory - (heap_end ?: (int)&_ebss);
} }
// ------------------------
// Serial Ports
// ------------------------
// Forward the default serial ports // Forward the default serial ports
#if USING_HW_SERIAL0 #if USING_HW_SERIAL0
DefaultSerial1 MSerial0(false, Serial); DefaultSerial1 MSerial0(false, Serial);

2
Marlin/src/HAL/DUE/HAL_SPI.cpp

@ -31,8 +31,6 @@
/** /**
* HAL for Arduino Due and compatible (SAM3X8E) * HAL for Arduino Due and compatible (SAM3X8E)
*
* For ARDUINO_ARCH_SAM
*/ */
#ifdef ARDUINO_ARCH_SAM #ifdef ARDUINO_ARCH_SAM

1
Marlin/src/HAL/HAL.h

@ -28,6 +28,7 @@
#endif #endif
#include HAL_PATH(.,HAL.h) #include HAL_PATH(.,HAL.h)
extern MarlinHAL hal;
#define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION) #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)

2
Marlin/src/HAL/LPC1768/HAL.h

@ -177,7 +177,7 @@ void flashFirmware(const int16_t);
#define CPU_ST7920_DELAY_3 750 #define CPU_ST7920_DELAY_3 750
// ------------------------ // ------------------------
// Class Utilities // Free Memory Accessor
// ------------------------ // ------------------------
#pragma GCC diagnostic push #pragma GCC diagnostic push

2
Marlin/src/HAL/NATIVE_SIM/HAL.h

@ -186,7 +186,7 @@ constexpr inline char* strstr_constexpr(char* str, const char* target) {
} }
// ------------------------ // ------------------------
// Class Utilities // Free Memory Accessor
// ------------------------ // ------------------------
#pragma GCC diagnostic push #pragma GCC diagnostic push

5
Marlin/src/HAL/STM32/HAL.cpp

@ -24,12 +24,11 @@
#ifdef HAL_STM32 #ifdef HAL_STM32
#include "HAL.h"
#include "usb_serial.h"
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#include "../shared/Delay.h" #include "../shared/Delay.h"
#include "usb_serial.h"
#ifdef USBCON #ifdef USBCON
DefaultSerial1 MSerialUSB(false, SerialUSB); DefaultSerial1 MSerialUSB(false, SerialUSB);
#endif #endif

9
Marlin/src/HAL/STM32F1/HAL.cpp

@ -83,6 +83,7 @@
// ------------------------ // ------------------------
#if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE #if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE
USBSerial SerialUSB; USBSerial SerialUSB;
DefaultSerial1 MSerial0(true, SerialUSB); DefaultSerial1 MSerial0(true, SerialUSB);
@ -211,6 +212,10 @@ void MarlinHAL::idletask() {
void MarlinHAL::reboot() { nvic_sys_reset(); } void MarlinHAL::reboot() { nvic_sys_reset(); }
// ------------------------
// Free Memory Accessor
// ------------------------
extern "C" { extern "C" {
extern unsigned int _ebss; // end of bss section extern unsigned int _ebss; // end of bss section
} }
@ -243,9 +248,9 @@ extern "C" {
} }
*/ */
// // ------------------------
// ADC // ADC
// // ------------------------
enum ADCIndex : uint8_t { enum ADCIndex : uint8_t {
OPTITEM(HAS_TEMP_ADC_0, TEMP_0) OPTITEM(HAS_TEMP_ADC_0, TEMP_0)

40
Marlin/src/HAL/TEENSY31_32/HAL.cpp

@ -44,25 +44,6 @@
#endif #endif
USBSerialType USBSerial(false, SerialUSB); USBSerialType USBSerial(false, SerialUSB);
// ------------------------
// Class Utilities
// ------------------------
extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;
int freeMemory() {
int free_memory;
if ((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
}
// ------------------------ // ------------------------
// MarlinHAL Class // MarlinHAL Class
// ------------------------ // ------------------------
@ -81,7 +62,9 @@ uint8_t MarlinHAL::get_reset_source() {
return 0; return 0;
} }
// ------------------------
// ADC // ADC
// ------------------------
void MarlinHAL::adc_init() { void MarlinHAL::adc_init() {
analog_init(); analog_init();
@ -102,4 +85,23 @@ void MarlinHAL::adc_start(const pin_t pin) {
uint16_t MarlinHAL::adc_value() { return ADC0_RA; } uint16_t MarlinHAL::adc_value() { return ADC0_RA; }
// ------------------------
// Free Memory Accessor
// ------------------------
extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;
int freeMemory() {
int free_memory;
if ((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
}
#endif // __MK20DX256__ #endif // __MK20DX256__

42
Marlin/src/HAL/TEENSY35_36/HAL.cpp

@ -43,33 +43,12 @@
USBSerialType USBSerial(false, SerialUSB); USBSerialType USBSerial(false, SerialUSB);
// ------------------------
// Class Utilities
// ------------------------
extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;
int freeMemory() {
int free_memory;
if ((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
}
// ------------------------ // ------------------------
// MarlinHAL Class // MarlinHAL Class
// ------------------------ // ------------------------
void MarlinHAL::reboot() { _reboot_Teensyduino_(); } void MarlinHAL::reboot() { _reboot_Teensyduino_(); }
// Reset
uint8_t MarlinHAL::get_reset_source() { uint8_t MarlinHAL::get_reset_source() {
switch (RCM_SRS0) { switch (RCM_SRS0) {
case 128: return RST_POWER_ON; break; case 128: return RST_POWER_ON; break;
@ -82,7 +61,9 @@ uint8_t MarlinHAL::get_reset_source() {
return 0; return 0;
} }
// ------------------------
// ADC // ADC
// ------------------------
int8_t MarlinHAL::adc_select; int8_t MarlinHAL::adc_select;
@ -131,4 +112,23 @@ uint16_t MarlinHAL::adc_value() {
return 0; return 0;
} }
// ------------------------
// Free Memory Accessor
// ------------------------
extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;
int freeMemory() {
int free_memory;
if ((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
}
#endif // __MK64FX512__ || __MK66FX1M0__ #endif // __MK64FX512__ || __MK66FX1M0__

2
Marlin/src/HAL/TEENSY35_36/HAL.h

@ -118,7 +118,7 @@ typedef int8_t pin_t;
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval) #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
// ------------------------ // ------------------------
// Class Utilities // Free Memory Accessor
// ------------------------ // ------------------------
#pragma GCC diagnostic push #pragma GCC diagnostic push

40
Marlin/src/HAL/TEENSY40_41/HAL.cpp

@ -44,25 +44,6 @@
#endif #endif
USBSerialType USBSerial(false, SerialUSB); USBSerialType USBSerial(false, SerialUSB);
// ------------------------
// Class Utilities
// ------------------------
#define __bss_end _ebss
extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;
// Doesn't work on Teensy 4.x
uint32_t freeMemory() {
uint32_t free_memory;
free_memory = ((uint32_t)&free_memory) - (((uint32_t)__brkval) ?: ((uint32_t)&__bss_end));
return free_memory;
}
}
// ------------------------ // ------------------------
// FastIO // FastIO
// ------------------------ // ------------------------
@ -97,7 +78,9 @@ void MarlinHAL::clear_reset_source() {
SRC_SRSR = reset_source; SRC_SRSR = reset_source;
} }
// ------------------------
// ADC // ADC
// ------------------------
int8_t MarlinHAL::adc_select; int8_t MarlinHAL::adc_select;
@ -180,4 +163,23 @@ uint16_t MarlinHAL::adc_value() {
return 0; return 0;
} }
// ------------------------
// Free Memory Accessor
// ------------------------
#define __bss_end _ebss
extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;
// Doesn't work on Teensy 4.x
uint32_t freeMemory() {
uint32_t free_memory;
free_memory = ((uint32_t)&free_memory) - (((uint32_t)__brkval) ?: ((uint32_t)&__bss_end));
return free_memory;
}
}
#endif // __IMXRT1062__ #endif // __IMXRT1062__

2
Marlin/src/HAL/TEENSY40_41/HAL.h

@ -140,7 +140,7 @@ typedef int8_t pin_t;
bool is_output(pin_t pin); bool is_output(pin_t pin);
// ------------------------ // ------------------------
// Class Utilities // Free Memory Accessor
// ------------------------ // ------------------------
#pragma GCC diagnostic push #pragma GCC diagnostic push

1
Marlin/src/inc/MarlinConfig.h

@ -29,7 +29,6 @@
#ifndef __MARLIN_DEPS__ #ifndef __MARLIN_DEPS__
#include "../HAL/HAL.h" #include "../HAL/HAL.h"
extern MarlinHAL hal;
#endif #endif
#include "../pins/pins.h" #include "../pins/pins.h"

Loading…
Cancel
Save