Browse Source

Merge pull request #477 from KurtE/serialEventUSB1_serialEventUSB2

Fix/Add seralEventUSB1 and serialEventUSB2
teensy4-core
Paul Stoffregen 4 years ago
parent
commit
cc025d05bd
No account linked to committer's email address
10 changed files with 62 additions and 10 deletions
  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 View File

// 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);



+ 5
- 0
teensy3/serialEventUSB1.cpp View File


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

+ 5
- 0
teensy3/serialEventUSB2.cpp View File


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

+ 0
- 7
teensy3/usb_inst.cpp View File

#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() {}

+ 7
- 1
teensy3/yield.cpp View File



#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

+ 2
- 0
teensy4/EventResponder.cpp View File

// 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()
{ {

+ 5
- 1
teensy4/core_pins.h View File



// 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);

+ 5
- 0
teensy4/serialEventUSB1.cpp View File


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

+ 5
- 0
teensy4/serialEventUSB2.cpp View File


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

+ 25
- 0
teensy4/yield.cpp View File

#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();



Loading…
Cancel
Save