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.

usb_serial.cpp 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
  20. #include "../../inc/MarlinConfigPre.h"
  21. #if ENABLED(EMERGENCY_PARSER)
  22. #include "usb_serial.h"
  23. #include "../../feature/e_parser.h"
  24. EmergencyParser::State emergency_state = EmergencyParser::State::EP_RESET;
  25. int8_t (*USBD_CDC_Receive_original) (uint8_t *Buf, uint32_t *Len) = nullptr;
  26. static int8_t USBD_CDC_Receive_hook(uint8_t *Buf, uint32_t *Len) {
  27. for (uint32_t i = 0; i < *Len; i++)
  28. emergency_parser.update(emergency_state, Buf[i]);
  29. return USBD_CDC_Receive_original(Buf, Len);
  30. }
  31. typedef struct _USBD_CDC_Itf {
  32. int8_t (* Init)(void);
  33. int8_t (* DeInit)(void);
  34. int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
  35. int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
  36. int8_t (* Transferred)(void);
  37. } USBD_CDC_ItfTypeDef;
  38. extern USBD_CDC_ItfTypeDef USBD_CDC_fops;
  39. void USB_Hook_init() {
  40. USBD_CDC_Receive_original = USBD_CDC_fops.Receive;
  41. USBD_CDC_fops.Receive = USBD_CDC_Receive_hook;
  42. }
  43. #endif // EMERGENCY_PARSER
  44. #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC