Browse Source

Add serialEvent (USB) and serialEvent1-3 (serial)

teensy4-core
PaulStoffregen 10 years ago
parent
commit
4c047eea2b
8 changed files with 34 additions and 2 deletions
  1. +3
    -0
      teensy3/HardwareSerial.h
  2. +2
    -0
      teensy3/HardwareSerial1.cpp
  3. +2
    -0
      teensy3/HardwareSerial2.cpp
  4. +2
    -0
      teensy3/HardwareSerial3.cpp
  5. +3
    -0
      teensy3/usb_inst.cpp
  6. +2
    -0
      teensy3/usb_seremu.h
  7. +2
    -0
      teensy3/usb_serial.h
  8. +18
    -2
      teensy3/yield.cpp

+ 3
- 0
teensy3/HardwareSerial.h View File

@@ -168,6 +168,7 @@ public:
virtual size_t write9bit(uint32_t c) { serial_putchar(c); return 1; }
};
extern HardwareSerial Serial1;
extern void serialEvent1(void);

class HardwareSerial2 : public HardwareSerial
{
@@ -195,6 +196,7 @@ public:
virtual size_t write9bit(uint32_t c) { serial2_putchar(c); return 1; }
};
extern HardwareSerial2 Serial2;
extern void serialEvent2(void);

class HardwareSerial3 : public HardwareSerial
{
@@ -222,6 +224,7 @@ public:
virtual size_t write9bit(uint32_t c) { serial3_putchar(c); return 1; }
};
extern HardwareSerial3 Serial3;
extern void serialEvent3(void);

#endif
#endif

+ 2
- 0
teensy3/HardwareSerial1.cpp View File

@@ -2,3 +2,5 @@

HardwareSerial Serial1;

void serialEvent1() __attribute__((weak));
void serialEvent1() {}

+ 2
- 0
teensy3/HardwareSerial2.cpp View File

@@ -2,3 +2,5 @@

HardwareSerial2 Serial2;

void serialEvent2() __attribute__((weak));
void serialEvent2() {}

+ 2
- 0
teensy3/HardwareSerial3.cpp View File

@@ -2,3 +2,5 @@

HardwareSerial3 Serial3;

void serialEvent3() __attribute__((weak));
void serialEvent3() {}

+ 3
- 0
teensy3/usb_inst.cpp View File

@@ -77,3 +77,6 @@ usb_seremu_class Serial;
#endif

#endif // F_CPU

void serialEvent() __attribute__((weak));
void serialEvent() {}

+ 2
- 0
teensy3/usb_seremu.h View File

@@ -84,6 +84,7 @@ public:
operator bool() { return usb_configuration; }
};
extern usb_seremu_class Serial;
extern void serialEvent(void);
#endif // __cplusplus


@@ -120,6 +121,7 @@ public:
};

extern usb_seremu_class Serial;
extern void serialEvent(void);
#endif // __cplusplus



+ 2
- 0
teensy3/usb_serial.h View File

@@ -100,6 +100,7 @@ public:

};
extern usb_serial_class Serial;
extern void serialEvent(void);
#endif // __cplusplus


@@ -135,6 +136,7 @@ public:
};

extern usb_serial_class Serial;
extern void serialEvent(void);
#endif // __cplusplus

#endif // F_CPU

teensy3/yield.c → teensy3/yield.cpp View File

@@ -1,6 +1,6 @@
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
* Copyright (c) 2014 PJRC.COM, LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -28,5 +28,21 @@
* SOFTWARE.
*/

#include "core_pins.h"
#include "HardwareSerial.h"
#include "usb_serial.h"
#include "usb_seremu.h"

void yield(void) __attribute__ ((weak));
void yield(void) {};
void yield(void)
{
static uint8_t running=0;

if (running) return; // TODO: does this need to be atomic?
running = 1;
if (Serial.available()) serialEvent();
if (Serial1.available()) serialEvent1();
if (Serial2.available()) serialEvent2();
if (Serial3.available()) serialEvent3();
running = 0;
};

Loading…
Cancel
Save