|
@@ -19,6 +19,7 @@
|
19
|
19
|
|
20
|
20
|
#include "msc_sd.h"
|
21
|
21
|
#include "SPI.h"
|
|
22
|
+#include "usb_reg_map.h"
|
22
|
23
|
|
23
|
24
|
#define PRODUCT_ID 0x29
|
24
|
25
|
|
|
@@ -41,14 +42,27 @@ Serial0Type<USBCompositeSerial> MarlinCompositeSerial(true);
|
41
|
42
|
#endif
|
42
|
43
|
|
43
|
44
|
#if ENABLED(EMERGENCY_PARSER)
|
44
|
|
- void (*real_rx_callback)(void);
|
45
|
45
|
|
46
|
|
- void my_rx_callback(void) {
|
47
|
|
- real_rx_callback();
|
48
|
|
- int len = MarlinCompositeSerial.available();
|
49
|
|
- while (len-- > 0) // >0 because available() may return a negative value
|
50
|
|
- emergency_parser.update(MarlinCompositeSerial.emergency_state, MarlinCompositeSerial.peek());
|
51
|
|
- }
|
|
46
|
+// The original callback is not called (no way to retrieve address).
|
|
47
|
+// That callback detects a special STM32 reset sequence: this functionality is not essential
|
|
48
|
+// as M997 achieves the same.
|
|
49
|
+void my_rx_callback(unsigned int, void*) {
|
|
50
|
+ // max length of 16 is enough to contain all emergency commands
|
|
51
|
+ uint8 buf[16];
|
|
52
|
+
|
|
53
|
+ //rx is usbSerialPart.endpoints[2]
|
|
54
|
+ uint16 len = usb_get_ep_rx_count(usbSerialPart.endpoints[2].address);
|
|
55
|
+ uint32 total = composite_cdcacm_data_available();
|
|
56
|
+
|
|
57
|
+ if (len == 0 || total == 0 || !WITHIN(total, len, COUNT(buf)))
|
|
58
|
+ return;
|
|
59
|
+
|
|
60
|
+ // cannot get character by character due to bug in composite_cdcacm_peek_ex
|
|
61
|
+ len = composite_cdcacm_peek(buf, total);
|
|
62
|
+
|
|
63
|
+ for (uint32 i = 0; i < len; i++)
|
|
64
|
+ emergency_parser.update(MarlinCompositeSerial.emergency_state, buf[i+total-len]);
|
|
65
|
+}
|
52
|
66
|
#endif
|
53
|
67
|
|
54
|
68
|
void MSC_SD_init() {
|
|
@@ -73,9 +87,7 @@ void MSC_SD_init() {
|
73
|
87
|
MarlinCompositeSerial.registerComponent();
|
74
|
88
|
USBComposite.begin();
|
75
|
89
|
#if ENABLED(EMERGENCY_PARSER)
|
76
|
|
- //rx is usbSerialPart.endpoints[2]
|
77
|
|
- real_rx_callback = usbSerialPart.endpoints[2].callback;
|
78
|
|
- usbSerialPart.endpoints[2].callback = my_rx_callback;
|
|
90
|
+ composite_cdcacm_set_hooks(USBHID_CDCACM_HOOK_RX, my_rx_callback);
|
79
|
91
|
#endif
|
80
|
92
|
}
|
81
|
93
|
|