Marlin_Firmware/Marlin/src/HAL/TEENSY35_36/HAL.h

131 lines
3.3 KiB
C
Raw Normal View History

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
*
*/
#pragma once
/**
2020-10-02 17:05:45 -05:00
* HAL for Teensy 3.5 (MK64FX512) and Teensy 3.6 (MK66FX1M0)
*/
#define CPU_32_BIT
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"
#include "watchdog.h"
2017-09-06 06:28:32 -05:00
#include <stdint.h>
#include <util/atomic.h>
2017-09-06 06:28:32 -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
// ------------------------
// Defines
2019-07-09 22:30:06 -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
#define _MSERIAL(X) Serial##X
#define MSERIAL(X) _MSERIAL(X)
#define Serial0 Serial
2017-11-05 08:49:38 -06:00
#if SERIAL_PORT == -1
2017-11-05 08:49:38 -06:00
#define MYSERIAL0 SerialUSB
#elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#endif
#define HAL_SERVO_LIB libServo
typedef int8_t pin_t;
#ifndef analogInputToDigitalPin
2020-10-09 16:50:17 -05:00
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
#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()
#define ISRS_ENABLED() (!__get_primask())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()
#undef sq
#define sq(x) ((x)*(x))
#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
#undef pgm_read_word
2017-09-06 06:28:32 -05:00
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
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();
2019-08-06 04:46:30 -05:00
// Reset reason
2019-09-16 20:31:08 -05:00
uint8_t HAL_get_reset_source();
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); }
2019-08-06 04:46:30 -05:00
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
extern "C" {
2019-09-16 20:31:08 -05:00
int freeMemory();
}
2019-08-06 04:46:30 -05:00
#pragma GCC diagnostic pop
// ADC
void HAL_adc_init();
2020-06-18 15:23:03 -05:00
#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10
2020-06-18 15:23:03 -05:00
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
2019-05-21 18:28:12 -05:00
#define HAL_ANALOG_SELECT(pin)
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();
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)