2017-07-18 23:29:06 +00:00
|
|
|
/* **************************************************************************
|
2017-09-27 09:57:33 +00:00
|
|
|
|
2017-07-18 23:29:06 +00:00
|
|
|
Marlin 3D Printer Firmware
|
|
|
|
Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
|
2017-09-27 09:57:33 +00:00
|
|
|
|
2017-07-18 23:29:06 +00:00
|
|
|
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/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Description: HAL for Arduino Due and compatible (SAM3X8E)
|
|
|
|
*
|
|
|
|
* For ARDUINO_ARCH_SAM
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef ARDUINO_ARCH_SAM
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Includes
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "../HAL.h"
|
|
|
|
|
|
|
|
#include <Wire.h>
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Externals
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Local defines
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Types
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Variables
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Public Variables
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
uint16_t HAL_adc_result;
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Private Variables
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Function prototypes
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Private functions
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Public functions
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// disable interrupts
|
|
|
|
void cli(void) { noInterrupts(); }
|
|
|
|
|
|
|
|
// enable interrupts
|
|
|
|
void sei(void) { interrupts(); }
|
|
|
|
|
|
|
|
void HAL_clear_reset_source(void) { }
|
|
|
|
|
|
|
|
uint8_t HAL_get_reset_source (void) {
|
|
|
|
switch ((RSTC->RSTC_SR >> 8) & 7) {
|
|
|
|
case 0: return RST_POWER_ON; break;
|
|
|
|
case 1: return RST_BACKUP; break;
|
|
|
|
case 2: return RST_WATCHDOG; break;
|
|
|
|
case 3: return RST_SOFTWARE; break;
|
|
|
|
case 4: return RST_EXTERNAL; break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 09:57:33 +00:00
|
|
|
void _delay_ms(const int delay_ms) {
|
2017-08-31 22:30:43 +00:00
|
|
|
// todo: port for Due?
|
|
|
|
delay(delay_ms);
|
2017-07-18 23:29:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
extern unsigned int _ebss; // end of bss section
|
|
|
|
}
|
|
|
|
|
|
|
|
// return free memory between end of heap (or end bss) and whatever is current
|
|
|
|
int freeMemory() {
|
|
|
|
int free_memory, heap_end = (int)_sbrk(0);
|
|
|
|
return (int)&free_memory - (heap_end ? heap_end : (int)&_ebss);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// ADC
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2017-09-27 08:52:29 +00:00
|
|
|
void HAL_adc_start_conversion(const uint8_t adc_pin) {
|
2017-07-18 23:29:06 +00:00
|
|
|
HAL_adc_result = analogRead(adc_pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t HAL_adc_get_result(void) {
|
|
|
|
// nop
|
|
|
|
return HAL_adc_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ARDUINO_ARCH_SAM
|