The code for T3.x was broken, especially for USB2... And the code was not setup for T4.x. So added it.main
| // Probably should be in a better spot. | // Probably should be in a better spot. | ||||
| extern uint8_t yield_active_check_flags; | extern uint8_t yield_active_check_flags; | ||||
| #define YIELD_CHECK_USB_SERIAL 0x1 // check the USB for Serial.available() | |||||
| #define YIELD_CHECK_USB_SERIAL 0x1 // check the USB for Serial.available() | |||||
| #define YIELD_CHECK_HARDWARE_SERIAL 0x2 // check Hardware Serial ports available | #define YIELD_CHECK_HARDWARE_SERIAL 0x2 // check Hardware Serial ports available | ||||
| #define YIELD_CHECK_EVENT_RESPONDER 0x4 // User has created eventResponders that use yield | #define YIELD_CHECK_EVENT_RESPONDER 0x4 // User has created eventResponders that use yield | ||||
| #define YIELD_CHECK_USB_SERIALUSB1 0x8 // Check for SerialUSB1 | |||||
| #define YIELD_CHECK_USB_SERIALUSB2 0x10 // Check for SerialUSB2 | |||||
| void yield(void); | void yield(void); | ||||
| #include <Arduino.h> | |||||
| void serialEventUSB1() __attribute__((weak)); | |||||
| void serialEventUSB1() {} | |||||
| uint8_t _serialEventUSB1_default PROGMEM = 1; |
| #include <Arduino.h> | |||||
| void serialEventUSB2() __attribute__((weak)); | |||||
| void serialEventUSB2() {} | |||||
| uint8_t _serialEventUSB2_default PROGMEM = 1; |
| #endif | #endif | ||||
| #endif // F_CPU | #endif // F_CPU | ||||
| //void serialEvent() __attribute__((weak)); | |||||
| //void serialEvent() {} | |||||
| void serialEventUSB1() __attribute__((weak)); | |||||
| void serialEventUSB1() {} | |||||
| void serialEventUSB2() __attribute__((weak)); | |||||
| void serialEventUSB2() {} |
| #ifdef USB_TRIPLE_SERIAL | #ifdef USB_TRIPLE_SERIAL | ||||
| uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL | YIELD_CHECK_USB_SERIALUSB1 | YIELD_CHECK_USB_SERIALUSB2; // default to check USB. | uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL | YIELD_CHECK_USB_SERIALUSB1 | YIELD_CHECK_USB_SERIALUSB2; // default to check USB. | ||||
| extern const uint8_t _serialEventUSB2_default; | |||||
| extern const uint8_t _serialEventUSB1_default; | |||||
| #elif defined(USB_DUAL_SERIAL) | #elif defined(USB_DUAL_SERIAL) | ||||
| uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL | YIELD_CHECK_USB_SERIALUSB1; // default to check USB. | uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL | YIELD_CHECK_USB_SERIALUSB1; // default to check USB. | ||||
| extern const uint8_t _serialEventUSB1_default; | |||||
| #else | #else | ||||
| uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL; // default to check USB. | uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL; // default to check USB. | ||||
| #endif | #endif | ||||
| extern const uint8_t _serialEvent_default; | extern const uint8_t _serialEvent_default; | ||||
| void yield(void) __attribute__ ((weak)); | void yield(void) __attribute__ ((weak)); | ||||
| #endif | #endif | ||||
| #ifdef USB_TRIPLE_SERIAL | #ifdef USB_TRIPLE_SERIAL | ||||
| if (yield_active_check_flags & YIELD_CHECK_USB_SERIALUSB2) { | if (yield_active_check_flags & YIELD_CHECK_USB_SERIALUSB2) { | ||||
| if (SerialUSB1.available()) serialEventUSB1(); | |||||
| if (SerialUSB2.available()) serialEventUSB2(); | |||||
| if (_serialEventUSB2_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIALUSB2; | if (_serialEventUSB2_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIALUSB2; | ||||
| } | } | ||||
| #endif | #endif |
| // TODO: interrupt disable/enable needed in many places!!! | // TODO: interrupt disable/enable needed in many places!!! | ||||
| // BUGBUG: See if file name order makes difference? | // BUGBUG: See if file name order makes difference? | ||||
| uint8_t _serialEvent_default __attribute__((weak)) PROGMEM = 0 ; | uint8_t _serialEvent_default __attribute__((weak)) PROGMEM = 0 ; | ||||
| uint8_t _serialEventUSB1_default __attribute__((weak)) PROGMEM = 0 ; | |||||
| uint8_t _serialEventUSB2_default __attribute__((weak)) PROGMEM = 0 ; | |||||
| void EventResponder::triggerEventNotImmediate() | void EventResponder::triggerEventNotImmediate() | ||||
| { | { |
| // Define a set of flags to know which things yield should check when called. | // Define a set of flags to know which things yield should check when called. | ||||
| extern uint8_t yield_active_check_flags; | extern uint8_t yield_active_check_flags; | ||||
| #define YIELD_CHECK_USB_SERIAL 0x1 // check the USB for Serial.available() | |||||
| #define YIELD_CHECK_USB_SERIAL 0x1 // check the USB for Serial.available() | |||||
| #define YIELD_CHECK_HARDWARE_SERIAL 0x2 // check Hardware Serial ports available | #define YIELD_CHECK_HARDWARE_SERIAL 0x2 // check Hardware Serial ports available | ||||
| #define YIELD_CHECK_EVENT_RESPONDER 0x4 // User has created eventResponders that use yield | #define YIELD_CHECK_EVENT_RESPONDER 0x4 // User has created eventResponders that use yield | ||||
| #define YIELD_CHECK_USB_SERIALUSB1 0x8 // Check for SerialUSB1 | |||||
| #define YIELD_CHECK_USB_SERIALUSB2 0x10 // Check for SerialUSB2 | |||||
| void yield(void); | void yield(void); | ||||
| void delay(uint32_t msec); | void delay(uint32_t msec); |
| #include <Arduino.h> | |||||
| void serialEventUSB1() __attribute__((weak)); | |||||
| void serialEventUSB1() {} | |||||
| uint8_t _serialEventUSB1_default PROGMEM = 1; |
| #include <Arduino.h> | |||||
| void serialEventUSB2() __attribute__((weak)); | |||||
| void serialEventUSB2() {} | |||||
| uint8_t _serialEventUSB2_default PROGMEM = 1; |
| #include <Arduino.h> | #include <Arduino.h> | ||||
| #include "EventResponder.h" | #include "EventResponder.h" | ||||
| #ifdef USB_TRIPLE_SERIAL | |||||
| uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL | YIELD_CHECK_USB_SERIALUSB1 | YIELD_CHECK_USB_SERIALUSB2; // default to check USB. | |||||
| extern const uint8_t _serialEventUSB2_default; | |||||
| extern const uint8_t _serialEventUSB1_default; | |||||
| #elif defined(USB_DUAL_SERIAL) | |||||
| uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL | YIELD_CHECK_USB_SERIALUSB1; // default to check USB. | |||||
| extern const uint8_t _serialEventUSB1_default; | |||||
| #else | |||||
| uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL; // default to check USB. | uint8_t yield_active_check_flags = YIELD_CHECK_USB_SERIAL; // default to check USB. | ||||
| #endif | |||||
| extern const uint8_t _serialEvent_default; | extern const uint8_t _serialEvent_default; | ||||
| void yield(void) __attribute__ ((weak)); | void yield(void) __attribute__ ((weak)); | ||||
| if (_serialEvent_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIAL; | if (_serialEvent_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIAL; | ||||
| } | } | ||||
| #if defined(USB_DUAL_SERIAL) || defined(USB_TRIPLE_SERIAL) | |||||
| if (yield_active_check_flags & YIELD_CHECK_USB_SERIALUSB1) { | |||||
| if (SerialUSB1.available()) serialEventUSB1(); | |||||
| if (_serialEventUSB1_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIALUSB1; | |||||
| } | |||||
| #endif | |||||
| #ifdef USB_TRIPLE_SERIAL | |||||
| if (yield_active_check_flags & YIELD_CHECK_USB_SERIALUSB2) { | |||||
| if (SerialUSB2.available()) serialEventUSB2(); | |||||
| if (_serialEventUSB2_default) yield_active_check_flags &= ~YIELD_CHECK_USB_SERIALUSB2; | |||||
| } | |||||
| #endif | |||||
| // Current workaround until integrate with EventResponder. | // Current workaround until integrate with EventResponder. | ||||
| if (yield_active_check_flags & YIELD_CHECK_HARDWARE_SERIAL) HardwareSerial::processSerialEventsList(); | if (yield_active_check_flags & YIELD_CHECK_HARDWARE_SERIAL) HardwareSerial::processSerialEventsList(); | ||||