|
@ -19,6 +19,7 @@ |
|
|
|
|
|
|
|
|
#include "msc_sd.h" |
|
|
#include "msc_sd.h" |
|
|
#include "SPI.h" |
|
|
#include "SPI.h" |
|
|
|
|
|
#include "usb_reg_map.h" |
|
|
|
|
|
|
|
|
#define PRODUCT_ID 0x29 |
|
|
#define PRODUCT_ID 0x29 |
|
|
|
|
|
|
|
@ -41,13 +42,26 @@ Serial0Type<USBCompositeSerial> MarlinCompositeSerial(true); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if ENABLED(EMERGENCY_PARSER) |
|
|
#if ENABLED(EMERGENCY_PARSER) |
|
|
void (*real_rx_callback)(void); |
|
|
|
|
|
|
|
|
|
|
|
void my_rx_callback(void) { |
|
|
// The original callback is not called (no way to retrieve address).
|
|
|
real_rx_callback(); |
|
|
// That callback detects a special STM32 reset sequence: this functionality is not essential
|
|
|
int len = MarlinCompositeSerial.available(); |
|
|
// as M997 achieves the same.
|
|
|
while (len-- > 0) // >0 because available() may return a negative value
|
|
|
void my_rx_callback(unsigned int, void*) { |
|
|
emergency_parser.update(MarlinCompositeSerial.emergency_state, MarlinCompositeSerial.peek()); |
|
|
// max length of 16 is enough to contain all emergency commands
|
|
|
|
|
|
uint8 buf[16]; |
|
|
|
|
|
|
|
|
|
|
|
//rx is usbSerialPart.endpoints[2]
|
|
|
|
|
|
uint16 len = usb_get_ep_rx_count(usbSerialPart.endpoints[2].address); |
|
|
|
|
|
uint32 total = composite_cdcacm_data_available(); |
|
|
|
|
|
|
|
|
|
|
|
if (len == 0 || total == 0 || !WITHIN(total, len, COUNT(buf))) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
// cannot get character by character due to bug in composite_cdcacm_peek_ex
|
|
|
|
|
|
len = composite_cdcacm_peek(buf, total); |
|
|
|
|
|
|
|
|
|
|
|
for (uint32 i = 0; i < len; i++) |
|
|
|
|
|
emergency_parser.update(MarlinCompositeSerial.emergency_state, buf[i+total-len]); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
@ -73,9 +87,7 @@ void MSC_SD_init() { |
|
|
MarlinCompositeSerial.registerComponent(); |
|
|
MarlinCompositeSerial.registerComponent(); |
|
|
USBComposite.begin(); |
|
|
USBComposite.begin(); |
|
|
#if ENABLED(EMERGENCY_PARSER) |
|
|
#if ENABLED(EMERGENCY_PARSER) |
|
|
//rx is usbSerialPart.endpoints[2]
|
|
|
composite_cdcacm_set_hooks(USBHID_CDCACM_HOOK_RX, my_rx_callback); |
|
|
real_rx_callback = usbSerialPart.endpoints[2].callback; |
|
|
|
|
|
usbSerialPart.endpoints[2].callback = my_rx_callback; |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|