浏览代码

Fix/Add seralEventUSB1 and serialEventUSB2

The code for T3.x was broken, especially for USB2...

And the code was not setup for T4.x.  So added it.
main
Kurt Eckhardt 4 年前
父节点
当前提交
9a54ab1fde
共有 10 个文件被更改,包括 62 次插入10 次删除
  1. +3
    -1
      teensy3/core_pins.h
  2. +5
    -0
      teensy3/serialEventUSB1.cpp
  3. +5
    -0
      teensy3/serialEventUSB2.cpp
  4. +0
    -7
      teensy3/usb_inst.cpp
  5. +7
    -1
      teensy3/yield.cpp
  6. +2
    -0
      teensy4/EventResponder.cpp
  7. +5
    -1
      teensy4/core_pins.h
  8. +5
    -0
      teensy4/serialEventUSB1.cpp
  9. +5
    -0
      teensy4/serialEventUSB2.cpp
  10. +25
    -0
      teensy4/yield.cpp

+ 3
- 1
teensy3/core_pins.h 查看文件

@@ -2000,9 +2000,11 @@ void _restart_Teensyduino_(void) __attribute__((noreturn));
// Probably should be in a better spot.
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_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);


+ 5
- 0
teensy3/serialEventUSB1.cpp 查看文件

@@ -0,0 +1,5 @@

#include <Arduino.h>
void serialEventUSB1() __attribute__((weak));
void serialEventUSB1() {}
uint8_t _serialEventUSB1_default PROGMEM = 1;

+ 5
- 0
teensy3/serialEventUSB2.cpp 查看文件

@@ -0,0 +1,5 @@

#include <Arduino.h>
void serialEventUSB2() __attribute__((weak));
void serialEventUSB2() {}
uint8_t _serialEventUSB2_default PROGMEM = 1;

+ 0
- 7
teensy3/usb_inst.cpp 查看文件

@@ -97,10 +97,3 @@ usb_seremu_class Serial;
#endif

#endif // F_CPU

//void serialEvent() __attribute__((weak));
//void serialEvent() {}
void serialEventUSB1() __attribute__((weak));
void serialEventUSB1() {}
void serialEventUSB2() __attribute__((weak));
void serialEventUSB2() {}

+ 7
- 1
teensy3/yield.cpp 查看文件

@@ -33,11 +33,17 @@

#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.
#endif

extern const uint8_t _serialEvent_default;

void yield(void) __attribute__ ((weak));
@@ -64,7 +70,7 @@ void yield(void)
#endif
#ifdef USB_TRIPLE_SERIAL
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;
}
#endif

+ 2
- 0
teensy4/EventResponder.cpp 查看文件

@@ -43,6 +43,8 @@ bool EventResponder::runningFromYield = false;
// TODO: interrupt disable/enable needed in many places!!!
// BUGBUG: See if file name order makes difference?
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()
{

+ 5
- 1
teensy4/core_pins.h 查看文件

@@ -1548,9 +1548,13 @@ void _restart_Teensyduino_(void) __attribute__((noreturn));

// Define a set of flags to know which things yield should check when called.
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_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 delay(uint32_t msec);

+ 5
- 0
teensy4/serialEventUSB1.cpp 查看文件

@@ -0,0 +1,5 @@

#include <Arduino.h>
void serialEventUSB1() __attribute__((weak));
void serialEventUSB1() {}
uint8_t _serialEventUSB1_default PROGMEM = 1;

+ 5
- 0
teensy4/serialEventUSB2.cpp 查看文件

@@ -0,0 +1,5 @@

#include <Arduino.h>
void serialEventUSB2() __attribute__((weak));
void serialEventUSB2() {}
uint8_t _serialEventUSB2_default PROGMEM = 1;

+ 25
- 0
teensy4/yield.cpp 查看文件

@@ -31,7 +31,19 @@
#include <Arduino.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.
#endif

extern const uint8_t _serialEvent_default;

void yield(void) __attribute__ ((weak));
@@ -49,6 +61,19 @@ void yield(void)
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.
if (yield_active_check_flags & YIELD_CHECK_HARDWARE_SERIAL) HardwareSerial::processSerialEventsList();


正在加载...
取消
保存