2018-06-13 19:08:26 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
*
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-06-13 19:08:26 -05:00
|
|
|
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
|
|
|
|
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
|
|
|
|
*
|
|
|
|
* 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-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-06-13 19:08:26 -05:00
|
|
|
*
|
|
|
|
*/
|
2018-11-04 02:25:55 -06:00
|
|
|
#pragma once
|
2017-07-11 15:59:27 -05:00
|
|
|
|
|
|
|
/**
|
2020-10-02 17:05:45 -05:00
|
|
|
* HAL for Teensy 3.5 (MK64FX512) and Teensy 3.6 (MK66FX1M0)
|
2017-07-11 15:59:27 -05:00
|
|
|
*/
|
|
|
|
|
2018-04-12 20:25:08 -05:00
|
|
|
#define CPU_32_BIT
|
|
|
|
|
2019-05-02 00:45:50 -05:00
|
|
|
#include "../shared/Marduino.h"
|
2018-08-14 03:28:52 -05:00
|
|
|
#include "../shared/math_32bit.h"
|
|
|
|
#include "../shared/HAL_SPI.h"
|
2018-04-12 20:25:08 -05:00
|
|
|
|
2019-09-02 19:49:58 -05:00
|
|
|
#include "fastio.h"
|
|
|
|
#include "watchdog.h"
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2017-09-06 06:28:32 -05:00
|
|
|
#include <stdint.h>
|
2019-03-29 12:23:09 -05:00
|
|
|
#include <util/atomic.h>
|
2017-09-06 06:28:32 -05:00
|
|
|
|
2018-05-27 03:36:57 -05:00
|
|
|
#define ST7920_DELAY_1 DELAY_NS(600)
|
|
|
|
#define ST7920_DELAY_2 DELAY_NS(750)
|
|
|
|
#define ST7920_DELAY_3 DELAY_NS(750)
|
|
|
|
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2017-07-11 15:59:27 -05:00
|
|
|
// Defines
|
2019-07-09 22:30:06 -05:00
|
|
|
// ------------------------
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2020-10-02 17:05:45 -05:00
|
|
|
#define IS_32BIT_TEENSY 1
|
|
|
|
#define IS_TEENSY_35_36 1
|
2020-09-08 22:14:59 -05:00
|
|
|
#ifdef __MK66FX1M0__
|
|
|
|
#define IS_TEENSY36 1
|
2020-10-02 17:05:45 -05:00
|
|
|
#else // __MK64FX512__
|
|
|
|
#define IS_TEENSY35 1
|
2020-09-08 22:14:59 -05:00
|
|
|
#endif
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2020-09-23 19:45:33 -05:00
|
|
|
#define _MSERIAL(X) Serial##X
|
|
|
|
#define MSERIAL(X) _MSERIAL(X)
|
|
|
|
#define Serial0 Serial
|
2017-11-05 08:49:38 -06:00
|
|
|
|
2017-07-11 15:59:27 -05:00
|
|
|
#if SERIAL_PORT == -1
|
2017-11-05 08:49:38 -06:00
|
|
|
#define MYSERIAL0 SerialUSB
|
2020-09-23 19:45:33 -05:00
|
|
|
#elif WITHIN(SERIAL_PORT, 0, 3)
|
|
|
|
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
|
2017-07-11 15:59:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define HAL_SERVO_LIB libServo
|
|
|
|
|
2017-10-26 13:37:26 -05:00
|
|
|
typedef int8_t pin_t;
|
|
|
|
|
2017-07-11 15:59:27 -05:00
|
|
|
#ifndef analogInputToDigitalPin
|
2020-10-09 16:50:17 -05:00
|
|
|
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
|
2017-07-11 15:59:27 -05:00
|
|
|
#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()
|
2019-03-29 12:23:09 -05:00
|
|
|
#define ISRS_ENABLED() (!__get_primask())
|
2018-06-01 19:02:22 -05:00
|
|
|
#define ENABLE_ISRS() __enable_irq()
|
|
|
|
#define DISABLE_ISRS() __disable_irq()
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2018-02-01 21:49:40 -06:00
|
|
|
#undef sq
|
|
|
|
#define sq(x) ((x)*(x))
|
2017-07-11 15:59:27 -05:00
|
|
|
|
|
|
|
#ifndef strncpy_P
|
|
|
|
#define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Fix bug in pgm_read_ptr
|
|
|
|
#undef pgm_read_ptr
|
2017-09-06 06:28:32 -05:00
|
|
|
#define pgm_read_ptr(addr) (*((void**)(addr)))
|
|
|
|
// Add type-checking to pgm_read_word
|
2017-07-11 15:59:27 -05:00
|
|
|
#undef pgm_read_word
|
2017-09-06 06:28:32 -05:00
|
|
|
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2019-09-30 21:44:07 -05:00
|
|
|
inline void HAL_init() {}
|
2019-06-27 16:29:17 -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();
|
2017-07-11 15:59:27 -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();
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2020-10-09 06:25:23 -05:00
|
|
|
inline void HAL_reboot() {} // reboot the board or restart the bootloader
|
|
|
|
|
2017-08-24 12:18:54 -05:00
|
|
|
FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2019-08-06 04:46:30 -05:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
2017-07-11 15:59:27 -05:00
|
|
|
extern "C" {
|
2019-09-16 20:31:08 -05:00
|
|
|
int freeMemory();
|
2017-07-11 15:59:27 -05:00
|
|
|
}
|
2019-08-06 04:46:30 -05:00
|
|
|
#pragma GCC diagnostic pop
|
2017-07-11 15:59:27 -05:00
|
|
|
|
|
|
|
// ADC
|
|
|
|
|
|
|
|
void HAL_adc_init();
|
|
|
|
|
2020-06-18 15:23:03 -05:00
|
|
|
#define HAL_ADC_VREF 3.3
|
2019-11-06 17:49:17 -06:00
|
|
|
#define HAL_ADC_RESOLUTION 10
|
2020-06-18 15:23:03 -05:00
|
|
|
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
2018-07-26 03:59:19 -05:00
|
|
|
#define HAL_READ_ADC() HAL_adc_get_result()
|
|
|
|
#define HAL_ADC_READY() true
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2019-05-21 18:28:12 -05:00
|
|
|
#define HAL_ANALOG_SELECT(pin)
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2017-09-27 03:52:29 -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();
|
2017-07-11 15:59:27 -05:00
|
|
|
|
2017-10-26 13:37:26 -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)
|