|
| 1 | +/** |
| 2 | + * Marlin 3D Printer Firmware |
| 3 | + * Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] |
| 4 | + * |
| 5 | + * Based on Sprinter and grbl. |
| 6 | + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm |
| 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 | + |
| 23 | +/** |
| 24 | + * HAL for HC32F460 based boards |
| 25 | + * |
| 26 | + * Note: MarlinHAL class is in MarlinHAL.h/cpp |
| 27 | + */ |
| 28 | + |
| 29 | +#define CPU_32_BIT |
| 30 | + |
| 31 | +#include "../../inc/MarlinConfig.h" |
| 32 | + |
| 33 | +#include "../../core/macros.h" |
| 34 | +#include "../shared/Marduino.h" |
| 35 | +#include "../shared/math_32bit.h" |
| 36 | +#include "../shared/HAL_SPI.h" |
| 37 | + |
| 38 | +#include "fastio.h" |
| 39 | +#include "timers.h" |
| 40 | +#include "MarlinSerial.h" |
| 41 | + |
| 42 | +#include <stdint.h> |
| 43 | + |
| 44 | +// |
| 45 | +// Serial Ports |
| 46 | +// |
| 47 | +#define _MSERIAL(X) MSerial##X |
| 48 | +#define MSERIAL(X) _MSERIAL(X) |
| 49 | +#define NUM_UARTS 4 |
| 50 | + |
| 51 | +#if SERIAL_PORT == -1 |
| 52 | + #error "USB Serial is not supported on HC32F460" |
| 53 | +#elif WITHIN(SERIAL_PORT, 1, NUM_UARTS) |
| 54 | + #define MYSERIAL1 MSERIAL(SERIAL_PORT) |
| 55 | +#else |
| 56 | + #define MYSERIAL1 MSERIAL(1) // Dummy port |
| 57 | + static_assert(false, "SERIAL_PORT must be from 1 to " STRINGIFY(NUM_UARTS) ".") |
| 58 | +#endif |
| 59 | + |
| 60 | +#ifdef SERIAL_PORT_2 |
| 61 | + #if SERIAL_PORT_2 == -1 |
| 62 | + #error "USB Serial is not supported on HC32F460" |
| 63 | + #elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS) |
| 64 | + #define MYSERIAL2 MSERIAL(SERIAL_PORT_2) |
| 65 | + #else |
| 66 | + #define MYSERIAL2 MSERIAL(1) // Dummy port |
| 67 | + static_assert(false, "SERIAL_PORT_2 must be from 1 to " STRINGIFY(NUM_UARTS) ".") |
| 68 | + #endif |
| 69 | +#endif |
| 70 | + |
| 71 | +#ifdef SERIAL_PORT_3 |
| 72 | + #if SERIAL_PORT_3 == -1 |
| 73 | + #error "USB Serial is not supported on HC32F460" |
| 74 | + #elif WITHIN(SERIAL_PORT_3, 1, NUM_UARTS) |
| 75 | + #define MYSERIAL3 MSERIAL(SERIAL_PORT_3) |
| 76 | + #else |
| 77 | + #define MYSERIAL3 MSERIAL(1) // Dummy port |
| 78 | + static_assert(false, "SERIAL_PORT_3 must be from 1 to " STRINGIFY(NUM_UARTS) ".") |
| 79 | + #endif |
| 80 | +#endif |
| 81 | + |
| 82 | +#ifdef LCD_SERIAL_PORT |
| 83 | + #if LCD_SERIAL_PORT == -1 |
| 84 | + #error "USB Serial is not supported on HC32F460" |
| 85 | + #elif WITHIN(LCD_SERIAL_PORT, 1, NUM_UARTS) |
| 86 | + #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) |
| 87 | + #else |
| 88 | + #define LCD_SERIAL MSERIAL(1) // Dummy port |
| 89 | + static_assert(false, "LCD_SERIAL_PORT must be from 1 to " STRINGIFY(NUM_UARTS) ".") |
| 90 | + #endif |
| 91 | + |
| 92 | + #if HAS_DGUS_LCD |
| 93 | + #define LCD_SERIAL_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() |
| 94 | + #endif |
| 95 | +#endif |
| 96 | + |
| 97 | +// |
| 98 | +// Emergency Parser |
| 99 | +// |
| 100 | +#if ENABLED(EMERGENCY_PARSER) |
| 101 | + extern "C" void usart_rx_irq_hook(uint8_t ch, uint8_t usart); |
| 102 | +#endif |
| 103 | + |
| 104 | +// |
| 105 | +// Misc. Defines |
| 106 | +// |
| 107 | +#define square(x) ((x) * (x)) |
| 108 | + |
| 109 | +#ifndef strncpy_P |
| 110 | + #define strncpy_P(dest, src, num) strncpy((dest), (src), (num)) |
| 111 | +#endif |
| 112 | + |
| 113 | +// |
| 114 | +// Misc. Functions |
| 115 | +// |
| 116 | +#ifndef analogInputToDigitalPin |
| 117 | +#define analogInputToDigitalPin(p) (p) |
| 118 | +#endif |
| 119 | + |
| 120 | +#define CRITICAL_SECTION_START \ |
| 121 | + uint32_t primask = __get_PRIMASK(); \ |
| 122 | + (void)__iCliRetVal() |
| 123 | + |
| 124 | +#define CRITICAL_SECTION_END \ |
| 125 | + if (!primask) \ |
| 126 | + (void)__iSeiRetVal() |
| 127 | + |
| 128 | +// Disable interrupts |
| 129 | +#define cli() noInterrupts() |
| 130 | + |
| 131 | +// Enable interrupts |
| 132 | +#define sei() interrupts() |
| 133 | + |
| 134 | +// bss_end alias |
| 135 | +#define __bss_end __bss_end__ |
| 136 | + |
| 137 | +// Fix bug in pgm_read_ptr |
| 138 | +#undef pgm_read_ptr |
| 139 | +#define pgm_read_ptr(addr) (*(addr)) |
| 140 | + |
| 141 | +// |
| 142 | +// ADC |
| 143 | +// |
| 144 | +#define HAL_ADC_VREF_MV 3300 |
| 145 | +#define HAL_ADC_RESOLUTION 10 |
| 146 | + |
| 147 | +#define GET_PIN_MAP_PIN(index) index |
| 148 | +#define GET_PIN_MAP_INDEX(pin) pin |
| 149 | +#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval) |
| 150 | + |
| 151 | +// |
| 152 | +// MarlinHAL implementation |
| 153 | +// |
| 154 | +#include "MarlinHAL.h" |
0 commit comments