|
| 1 | +/** |
| 2 | + * Marlin 3D Printer Firmware |
| 3 | + * |
| 4 | + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] |
| 5 | + * Copyright (c) 2016 Bob Cousins [email protected] |
| 6 | + * Copyright (c) 2015-2016 Nico Tonnhofer [email protected] |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | +#pragma once |
| 23 | + |
| 24 | +/** |
| 25 | + * Description: HAL for Teensy 4.0 and Teensy 4.1 |
| 26 | + */ |
| 27 | + |
| 28 | +#define CPU_32_BIT |
| 29 | + |
| 30 | +#include "../shared/Marduino.h" |
| 31 | +#include "../shared/math_32bit.h" |
| 32 | +#include "../shared/HAL_SPI.h" |
| 33 | + |
| 34 | +#include "fastio.h" |
| 35 | +#include "watchdog.h" |
| 36 | + |
| 37 | +#include <stdint.h> |
| 38 | +#include <util/atomic.h> |
| 39 | + |
| 40 | +//#define ST7920_DELAY_1 DELAY_NS(600) |
| 41 | +//#define ST7920_DELAY_2 DELAY_NS(750) |
| 42 | +//#define ST7920_DELAY_3 DELAY_NS(750) |
| 43 | + |
| 44 | +// ------------------------ |
| 45 | +// Defines |
| 46 | +// ------------------------ |
| 47 | + |
| 48 | +#ifdef __IMXRT1062__ |
| 49 | + #define IS_32BIT_TEENSY 1 |
| 50 | + #define IS_TEENSY41 1 |
| 51 | +#endif |
| 52 | + |
| 53 | +#if SERIAL_PORT == -1 |
| 54 | + #define MYSERIAL0 SerialUSB |
| 55 | +#elif SERIAL_PORT == 0 |
| 56 | + #define MYSERIAL0 Serial |
| 57 | +#elif SERIAL_PORT == 1 |
| 58 | + #define MYSERIAL0 Serial1 |
| 59 | +#elif SERIAL_PORT == 2 |
| 60 | + #define MYSERIAL0 Serial2 |
| 61 | +#elif SERIAL_PORT == 3 |
| 62 | + #define MYSERIAL0 Serial3 |
| 63 | +#elif SERIAL_PORT == 4 |
| 64 | + #define MYSERIAL0 Serial4 |
| 65 | +#elif SERIAL_PORT == 5 |
| 66 | + #define MYSERIAL0 Serial5 |
| 67 | +#elif SERIAL_PORT == 6 |
| 68 | + #define MYSERIAL0 Serial6 |
| 69 | +#elif SERIAL_PORT == 7 |
| 70 | + #define MYSERIAL0 Serial7 |
| 71 | +#elif SERIAL_PORT == 8 |
| 72 | + #define MYSERIAL0 Serial8 |
| 73 | +#else |
| 74 | + #error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration." |
| 75 | +#endif |
| 76 | + |
| 77 | +#ifdef SERIAL_PORT_2 |
| 78 | + #if SERIAL_PORT_2 == SERIAL_PORT |
| 79 | + #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." |
| 80 | + #elif SERIAL_PORT_2 == -1 |
| 81 | + #define MYSERIAL1 usbSerial |
| 82 | + #elif SERIAL_PORT_2 == 0 |
| 83 | + #define MYSERIAL1 Serial |
| 84 | + #elif SERIAL_PORT_2 == 1 |
| 85 | + #define MYSERIAL1 Serial1 |
| 86 | + #elif SERIAL_PORT_2 == 2 |
| 87 | + #define MYSERIAL1 Serial2 |
| 88 | + #elif SERIAL_PORT_2 == 3 |
| 89 | + #define MYSERIAL1 Serial3 |
| 90 | + #elif SERIAL_PORT_2 == 4 |
| 91 | + #define MYSERIAL1 Serial4 |
| 92 | + #elif SERIAL_PORT_2 == 5 |
| 93 | + #define MYSERIAL1 Serial5 |
| 94 | + #elif SERIAL_PORT_2 == 6 |
| 95 | + #define MYSERIAL1 Serial6 |
| 96 | + #elif SERIAL_PORT_2 == 7 |
| 97 | + #define MYSERIAL1 Serial7 |
| 98 | + #elif SERIAL_PORT_2 == 8 |
| 99 | + #define MYSERIAL1 Serial8 |
| 100 | + #else |
| 101 | + #error "SERIAL_PORT_2 must be from -1 to 8. Please update your configuration." |
| 102 | + #endif |
| 103 | + #define NUM_SERIAL 2 |
| 104 | +#else |
| 105 | + #define NUM_SERIAL 1 |
| 106 | +#endif |
| 107 | + |
| 108 | +#define HAL_SERVO_LIB libServo |
| 109 | + |
| 110 | +typedef int8_t pin_t; |
| 111 | + |
| 112 | +#ifndef analogInputToDigitalPin |
| 113 | + #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1) |
| 114 | +#endif |
| 115 | + |
| 116 | +#define CRITICAL_SECTION_START() uint32_t primask = __get_primask(); __disable_irq() |
| 117 | +#define CRITICAL_SECTION_END() if (!primask) __enable_irq() |
| 118 | +#define ISRS_ENABLED() (!__get_primask()) |
| 119 | +#define ENABLE_ISRS() __enable_irq() |
| 120 | +#define DISABLE_ISRS() __disable_irq() |
| 121 | + |
| 122 | +#undef sq |
| 123 | +#define sq(x) ((x)*(x)) |
| 124 | + |
| 125 | +#ifndef strncpy_P |
| 126 | + #define strncpy_P(dest, src, num) strncpy((dest), (src), (num)) |
| 127 | +#endif |
| 128 | + |
| 129 | +// Don't place string constants in PROGMEM |
| 130 | +#undef PSTR |
| 131 | +#define PSTR(str) ({static const char *data = (str); &data[0];}) |
| 132 | + |
| 133 | +// Fix bug in pgm_read_ptr |
| 134 | +#undef pgm_read_ptr |
| 135 | +#define pgm_read_ptr(addr) (*((void**)(addr))) |
| 136 | +// Add type-checking to pgm_read_word |
| 137 | +#undef pgm_read_word |
| 138 | +#define pgm_read_word(addr) (*((uint16_t*)(addr))) |
| 139 | + |
| 140 | +// Enable hooks into idle and setup for HAL |
| 141 | +#define HAL_IDLETASK 1 |
| 142 | +FORCE_INLINE void HAL_idletask() {} |
| 143 | +FORCE_INLINE void HAL_init() {} |
| 144 | + |
| 145 | +// Clear reset reason |
| 146 | +void HAL_clear_reset_source(); |
| 147 | + |
| 148 | +// Reset reason |
| 149 | +uint8_t HAL_get_reset_source(); |
| 150 | + |
| 151 | +FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); } |
| 152 | + |
| 153 | +#pragma GCC diagnostic push |
| 154 | +#pragma GCC diagnostic ignored "-Wunused-function" |
| 155 | +extern "C" { |
| 156 | + uint32_t freeMemory(); |
| 157 | +} |
| 158 | +#pragma GCC diagnostic pop |
| 159 | + |
| 160 | +// ADC |
| 161 | + |
| 162 | +void HAL_adc_init(); |
| 163 | + |
| 164 | +#define HAL_ADC_VREF 3.3 |
| 165 | +#define HAL_ADC_RESOLUTION 10 |
| 166 | +#define HAL_ADC_FILTERED // turn off ADC oversampling |
| 167 | +#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin) |
| 168 | +#define HAL_READ_ADC() HAL_adc_get_result() |
| 169 | +#define HAL_ADC_READY() true |
| 170 | + |
| 171 | +#define HAL_ANALOG_SELECT(pin) |
| 172 | + |
| 173 | +void HAL_adc_start_conversion(const uint8_t adc_pin); |
| 174 | +uint16_t HAL_adc_get_result(); |
| 175 | + |
| 176 | +#define GET_PIN_MAP_PIN(index) index |
| 177 | +#define GET_PIN_MAP_INDEX(pin) pin |
| 178 | +#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval) |
| 179 | + |
| 180 | +bool is_output(uint8_t pin); |
0 commit comments