🎨 Minor HAL cleanup

This commit is contained in:
Scott Lahteine 2022-05-14 15:31:51 -05:00
parent 4d65d7f142
commit a0fe4f4895
15 changed files with 94 additions and 75 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -44,25 +44,6 @@
#endif
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
// ------------------------
@ -81,7 +62,9 @@ uint8_t MarlinHAL::get_reset_source() {
return 0;
}
// ------------------------
// ADC
// ------------------------
void MarlinHAL::adc_init() {
analog_init();
@ -102,4 +85,23 @@ void MarlinHAL::adc_start(const pin_t pin) {
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__

View File

@ -43,33 +43,12 @@
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
// ------------------------
void MarlinHAL::reboot() { _reboot_Teensyduino_(); }
// Reset
uint8_t MarlinHAL::get_reset_source() {
switch (RCM_SRS0) {
case 128: return RST_POWER_ON; break;
@ -82,7 +61,9 @@ uint8_t MarlinHAL::get_reset_source() {
return 0;
}
// ------------------------
// ADC
// ------------------------
int8_t MarlinHAL::adc_select;
@ -131,4 +112,23 @@ uint16_t MarlinHAL::adc_value() {
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__

View File

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

View File

@ -44,25 +44,6 @@
#endif
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
// ------------------------
@ -97,7 +78,9 @@ void MarlinHAL::clear_reset_source() {
SRC_SRSR = reset_source;
}
// ------------------------
// ADC
// ------------------------
int8_t MarlinHAL::adc_select;
@ -180,4 +163,23 @@ uint16_t MarlinHAL::adc_value() {
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__

View File

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

View File

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