2018-10-03 03:26:07 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
*
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-10-03 03:26:07 -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
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-10-03 03:26:07 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#define CPU_32_BIT
|
|
|
|
|
2019-06-21 07:46:23 +02:00
|
|
|
#include "../../core/macros.h"
|
2019-05-02 00:45:50 -05:00
|
|
|
#include "../shared/Marduino.h"
|
|
|
|
#include "../shared/math_32bit.h"
|
|
|
|
#include "../shared/HAL_SPI.h"
|
2019-09-02 19:49:58 -05:00
|
|
|
#include "fastio.h"
|
2020-12-04 22:02:58 -08:00
|
|
|
#include "Servo.h"
|
2019-09-02 19:49:58 -05:00
|
|
|
#include "watchdog.h"
|
2020-05-26 06:43:29 +01:00
|
|
|
#include "MarlinSerial.h"
|
2019-05-02 00:45:50 -05:00
|
|
|
|
|
|
|
#include "../../inc/MarlinConfigPre.h"
|
2018-10-03 03:26:07 -05:00
|
|
|
|
2019-05-02 00:45:50 -05:00
|
|
|
#include <stdint.h>
|
2018-10-03 03:26:07 -05:00
|
|
|
|
|
|
|
#ifdef USBCON
|
|
|
|
#include <USBSerial.h>
|
2021-02-01 01:18:39 +01:00
|
|
|
#include "../../core/serial_hook.h"
|
2021-01-28 09:02:06 +01:00
|
|
|
typedef ForwardSerial0Type< decltype(SerialUSB) > DefaultSerial;
|
|
|
|
extern DefaultSerial MSerial;
|
2018-10-03 03:26:07 -05:00
|
|
|
#endif
|
|
|
|
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2018-10-03 03:26:07 -05:00
|
|
|
// Defines
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2020-09-23 19:45:33 -05:00
|
|
|
#define _MSERIAL(X) MSerial##X
|
|
|
|
#define MSERIAL(X) _MSERIAL(X)
|
2018-10-03 03:26:07 -05:00
|
|
|
|
2020-09-23 19:45:33 -05:00
|
|
|
#if SERIAL_PORT == -1
|
2021-01-28 09:02:06 +01:00
|
|
|
#define MYSERIAL0 MSerial
|
2020-09-23 19:45:33 -05:00
|
|
|
#elif WITHIN(SERIAL_PORT, 1, 6)
|
|
|
|
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
|
2020-01-02 17:59:06 -06:00
|
|
|
#else
|
2020-09-23 19:45:33 -05:00
|
|
|
#error "SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
|
2018-10-03 03:26:07 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SERIAL_PORT_2
|
2020-09-23 19:45:33 -05:00
|
|
|
#if SERIAL_PORT_2 == -1
|
2021-01-28 09:02:06 +01:00
|
|
|
#define MYSERIAL1 MSerial
|
2020-09-23 19:45:33 -05:00
|
|
|
#elif WITHIN(SERIAL_PORT_2, 1, 6)
|
|
|
|
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
|
2020-01-02 17:59:06 -06:00
|
|
|
#else
|
2020-09-23 19:45:33 -05:00
|
|
|
#error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration."
|
2018-10-03 03:26:07 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2021-01-16 03:38:34 +01:00
|
|
|
#ifdef MMU2_SERIAL_PORT
|
|
|
|
#if MMU2_SERIAL_PORT == -1
|
2021-01-28 09:02:06 +01:00
|
|
|
#define MMU2_SERIAL MSerial
|
2021-01-16 03:38:34 +01:00
|
|
|
#elif WITHIN(MMU2_SERIAL_PORT, 1, 6)
|
|
|
|
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
|
|
|
|
#else
|
|
|
|
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-09-24 18:28:48 -07:00
|
|
|
#ifdef LCD_SERIAL_PORT
|
2020-09-23 19:45:33 -05:00
|
|
|
#if LCD_SERIAL_PORT == -1
|
2021-01-28 09:02:06 +01:00
|
|
|
#define LCD_SERIAL MSerial
|
2020-09-23 19:45:33 -05:00
|
|
|
#elif WITHIN(LCD_SERIAL_PORT, 1, 6)
|
|
|
|
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
|
|
|
|
#else
|
|
|
|
#error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
|
|
|
|
#endif
|
2020-09-24 18:28:48 -07:00
|
|
|
#if HAS_DGUS_LCD
|
|
|
|
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
|
|
|
|
#endif
|
2020-09-23 19:45:33 -05:00
|
|
|
#endif
|
2019-02-23 23:56:09 +01:00
|
|
|
|
2018-10-03 03:26:07 -05:00
|
|
|
/**
|
|
|
|
* TODO: review this to return 1 for pins that are not analog input
|
|
|
|
*/
|
|
|
|
#ifndef analogInputToDigitalPin
|
|
|
|
#define analogInputToDigitalPin(p) (p)
|
|
|
|
#endif
|
|
|
|
|
2020-02-11 01:13:02 -06:00
|
|
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
|
|
|
|
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
2018-10-03 03:26:07 -05:00
|
|
|
#define ISRS_ENABLED() (!__get_PRIMASK())
|
|
|
|
#define ENABLE_ISRS() __enable_irq()
|
|
|
|
#define DISABLE_ISRS() __disable_irq()
|
|
|
|
#define cli() __disable_irq()
|
|
|
|
#define sei() __enable_irq()
|
|
|
|
|
|
|
|
// On AVR this is in math.h?
|
|
|
|
#define square(x) ((x)*(x))
|
|
|
|
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2018-10-03 03:26:07 -05:00
|
|
|
// Types
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2018-10-03 03:26:07 -05:00
|
|
|
|
2019-07-07 10:52:17 +08:00
|
|
|
typedef int16_t pin_t;
|
2018-10-03 03:26:07 -05:00
|
|
|
|
|
|
|
#define HAL_SERVO_LIB libServo
|
2020-12-04 22:02:58 -08:00
|
|
|
#define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos()
|
|
|
|
#define RESUME_SERVO_OUTPUT() libServo::resume_all_servos()
|
2018-10-03 03:26:07 -05:00
|
|
|
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2018-10-03 03:26:07 -05:00
|
|
|
// Public Variables
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2018-10-03 03:26:07 -05:00
|
|
|
|
2019-08-06 04:46:30 -05:00
|
|
|
// result of last ADC conversion
|
2018-10-03 03:26:07 -05:00
|
|
|
extern uint16_t HAL_adc_result;
|
|
|
|
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2018-10-03 03:26:07 -05:00
|
|
|
// Public functions
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2018-10-03 03:26:07 -05:00
|
|
|
|
|
|
|
// Memory related
|
|
|
|
#define __bss_end __bss_end__
|
|
|
|
|
|
|
|
// Enable hooks into setup for HAL
|
2019-09-16 20:31:08 -05:00
|
|
|
void HAL_init();
|
2021-02-02 17:55:11 -03:00
|
|
|
#define HAL_IDLETASK 1
|
|
|
|
void HAL_idletask();
|
2018-10-03 03:26:07 -05:00
|
|
|
|
2019-08-06 04:46:30 -05:00
|
|
|
// Clear reset reason
|
2019-09-16 20:31:08 -05:00
|
|
|
void HAL_clear_reset_source();
|
2018-10-03 03:26:07 -05:00
|
|
|
|
2019-08-06 04:46:30 -05:00
|
|
|
// Reset reason
|
2019-09-16 20:31:08 -05:00
|
|
|
uint8_t HAL_get_reset_source();
|
2018-10-03 03:26:07 -05:00
|
|
|
|
2020-10-09 08:25:23 -03:00
|
|
|
inline void HAL_reboot() {} // reboot the board or restart the bootloader
|
|
|
|
|
2018-10-03 03:26:07 -05:00
|
|
|
void _delay_ms(const int delay);
|
|
|
|
|
|
|
|
extern "C" char* _sbrk(int incr);
|
|
|
|
|
2020-12-15 00:53:53 -06:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
2019-08-06 04:46:30 -05:00
|
|
|
|
2019-01-11 02:01:31 +01:00
|
|
|
static inline int freeMemory() {
|
2018-10-03 03:26:07 -05:00
|
|
|
volatile char top;
|
|
|
|
return &top - reinterpret_cast<char*>(_sbrk(0));
|
|
|
|
}
|
|
|
|
|
2020-12-15 00:53:53 -06:00
|
|
|
#pragma GCC diagnostic pop
|
2019-08-06 04:46:30 -05:00
|
|
|
|
2019-02-20 06:13:07 -06:00
|
|
|
//
|
2018-10-03 03:26:07 -05:00
|
|
|
// ADC
|
2019-02-20 06:13:07 -06:00
|
|
|
//
|
2018-10-03 03:26:07 -05:00
|
|
|
|
|
|
|
#define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
|
|
|
|
|
2020-06-18 15:23:03 -05:00
|
|
|
#define HAL_ADC_VREF 3.3
|
2020-12-22 03:30:03 +03:00
|
|
|
#define HAL_ADC_RESOLUTION ADC_RESOLUTION // 12
|
2020-06-18 15:23:03 -05:00
|
|
|
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
2018-10-03 03:26:07 -05:00
|
|
|
#define HAL_READ_ADC() HAL_adc_result
|
|
|
|
#define HAL_ADC_READY() true
|
|
|
|
|
2020-12-22 03:30:03 +03:00
|
|
|
inline void HAL_adc_init() { analogReadResolution(HAL_ADC_RESOLUTION); }
|
|
|
|
|
2018-10-03 03:26:07 -05:00
|
|
|
void HAL_adc_start_conversion(const uint8_t adc_pin);
|
|
|
|
|
2019-09-16 20:31:08 -05:00
|
|
|
uint16_t HAL_adc_get_result();
|
2018-10-03 03:26:07 -05:00
|
|
|
|
|
|
|
#define GET_PIN_MAP_PIN(index) index
|
|
|
|
#define GET_PIN_MAP_INDEX(pin) pin
|
|
|
|
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
|
2019-09-28 08:54:30 +03:00
|
|
|
|
2020-07-30 09:43:19 +03:00
|
|
|
#ifdef STM32F1xx
|
|
|
|
#define JTAG_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_JTAGDISABLE)
|
|
|
|
#define JTAGSWD_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_DISABLE)
|
|
|
|
#endif
|
|
|
|
|
2019-09-28 08:54:30 +03:00
|
|
|
#define PLATFORM_M997_SUPPORT
|
2020-03-23 17:11:00 -05:00
|
|
|
void flashFirmware(const int16_t);
|
2020-10-01 22:52:42 -03:00
|
|
|
|
|
|
|
// Maple Compatibility
|
|
|
|
typedef void (*systickCallback_t)(void);
|
|
|
|
void systick_attach_callback(systickCallback_t cb);
|
|
|
|
void HAL_SYSTICK_Callback();
|
2020-11-01 23:38:10 -03:00
|
|
|
extern volatile uint32_t systick_uptime_millis;
|
2020-11-04 23:15:19 +02:00
|
|
|
|
|
|
|
#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set_pwm_frequency
|
|
|
|
* Set the frequency of the timer corresponding to the provided pin
|
|
|
|
* All Timer PWM pins run at the same frequency
|
|
|
|
*/
|
|
|
|
void set_pwm_frequency(const pin_t pin, int f_desired);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set_pwm_duty
|
|
|
|
* Set the PWM duty cycle of the provided pin to the provided value
|
|
|
|
* Optionally allows inverting the duty cycle [default = false]
|
|
|
|
* Optionally allows changing the maximum size of the provided value to enable finer PWM duty control [default = 255]
|
|
|
|
*/
|
|
|
|
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);
|