My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MinSerial.h 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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. #pragma once
  23. #include "../../core/serial.h"
  24. #include <stdint.h>
  25. // Serial stuff here
  26. // Inside an exception handler, the CPU state is not safe, we can't expect the handler to resume
  27. // and the software to continue. UART communication can't rely on later callback/interrupt as it might never happen.
  28. // So, you need to provide some method to send one byte to the usual UART with the interrupts disabled
  29. // By default, the method uses SERIAL_CHAR but it's 100% guaranteed to break (couldn't be worse than nothing...)7
  30. extern void (*HAL_min_serial_init)();
  31. extern void (*HAL_min_serial_out)(char ch);
  32. struct MinSerial {
  33. static bool force_using_default_output;
  34. // Serial output
  35. static void TX(char ch) {
  36. if (force_using_default_output)
  37. SERIAL_CHAR(ch);
  38. else
  39. HAL_min_serial_out(ch);
  40. }
  41. // Send String through UART
  42. static void TX(const char *s) { while (*s) TX(*s++); }
  43. // Send a digit through UART
  44. static void TXDigit(uint32_t d) {
  45. if (d < 10) TX((char)(d+'0'));
  46. else if (d < 16) TX((char)(d+'A'-10));
  47. else TX('?');
  48. }
  49. // Send Hex number through UART
  50. static void TXHex(uint32_t v) {
  51. TX("0x");
  52. for (uint8_t i = 0; i < 8; i++, v <<= 4)
  53. TXDigit((v >> 28) & 0xF);
  54. }
  55. // Send Decimal number through UART
  56. static void TXDec(uint32_t v) {
  57. if (!v) {
  58. TX('0');
  59. return;
  60. }
  61. char nbrs[14];
  62. char *p = &nbrs[0];
  63. while (v != 0) {
  64. *p++ = '0' + (v % 10);
  65. v /= 10;
  66. }
  67. do {
  68. p--;
  69. TX(*p);
  70. } while (p != &nbrs[0]);
  71. }
  72. static void init() { if (!force_using_default_output) HAL_min_serial_init(); }
  73. };