Marlin_Firmware/Marlin/src/HAL/HAL_STM32F4/HAL.cpp

102 lines
2.6 KiB
C++
Raw Normal View History

2018-04-17 17:33:29 -05:00
/**
* Marlin 3D Printer Firmware
*
2019-06-27 23:57:50 -05:00
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2018-04-17 17:33:29 -05:00
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
* Copyright (c) 2017 Victor Perez
*
* 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/>.
*
*/
#if defined(STM32GENERIC) && defined(STM32F4)
2018-04-17 17:33:29 -05:00
#include "HAL.h"
//#include <Wire.h>
2019-07-09 22:30:06 -05:00
// ------------------------
2018-04-17 17:33:29 -05:00
// Public Variables
2019-07-09 22:30:06 -05:00
// ------------------------
2018-04-17 17:33:29 -05:00
uint16_t HAL_adc_result;
2019-07-09 22:30:06 -05:00
// ------------------------
2018-04-17 17:33:29 -05:00
// Public functions
2019-07-09 22:30:06 -05:00
// ------------------------
2018-04-17 17:33:29 -05:00
/* VGPV Done with defines
// disable interrupts
void cli(void) { noInterrupts(); }
// enable interrupts
void sei(void) { interrupts(); }
*/
void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
2019-04-12 13:35:30 -05:00
uint8_t HAL_get_reset_source(void) {
if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) return RST_WATCHDOG;
2018-04-17 17:33:29 -05:00
if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET) return RST_SOFTWARE;
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET) return RST_EXTERNAL;
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET) return RST_POWER_ON;
2018-04-17 17:33:29 -05:00
return 0;
}
void _delay_ms(const int delay_ms) { delay(delay_ms); }
extern "C" {
extern unsigned int _ebss; // end of bss section
}
// return free memory between end of heap (or end bss) and whatever is current
/*
#include "wirish/syscalls.c"
//extern caddr_t _sbrk(int incr);
#ifndef CONFIG_HEAP_END
extern char _lm_heap_end;
#define CONFIG_HEAP_END ((caddr_t)&_lm_heap_end)
#endif
extern "C" {
static int freeMemory() {
char top = 't';
return &top - reinterpret_cast<char*>(sbrk(0));
}
int freeMemory() {
int free_memory;
int heap_end = (int)_sbrk(0);
free_memory = ((int)&free_memory) - ((int)heap_end);
return free_memory;
}
}
*/
2019-07-09 22:30:06 -05:00
// ------------------------
2018-04-17 17:33:29 -05:00
// ADC
2019-07-09 22:30:06 -05:00
// ------------------------
2018-04-17 17:33:29 -05:00
void HAL_adc_start_conversion(const uint8_t adc_pin) {
HAL_adc_result = analogRead(adc_pin);
}
uint16_t HAL_adc_get_result(void) {
return HAL_adc_result;
}
#endif // // STM32GENERIC && STM32F4