The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
Diff: Serial.h
- Revision:
- 21:3944f1e2fa4f
- Parent:
- 20:029aa53d7323
- Child:
- 27:7110ebee3484
diff -r 029aa53d7323 -r 3944f1e2fa4f Serial.h --- a/Serial.h Thu Jun 03 11:17:50 2010 +0000 +++ b/Serial.h Thu Jun 17 16:23:14 2010 +0000 @@ -59,6 +59,11 @@ , Forced0 }; + enum IrqType { + RxIrq = 0 + , TxIrq + }; + /* Function: format * Set the transmission format used by the Serial port * @@ -128,8 +133,9 @@ * * Variables: * fptr - A pointer to a void function, or 0 to set as none + * type - Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) */ - void attach(void (*fptr)(void)); + void attach(void (*fptr)(void), IrqType type = RxIrq); /* Function: attach * Attach a member function to call whenever a serial interrupt is generated @@ -137,11 +143,14 @@ * Variables: * tptr - pointer to the object to call the member function on * mptr - pointer to the member function to be called + * type - Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) */ template<typename T> - void attach(T* tptr, void (T::*mptr)(void)) { - _irq.attach(tptr, mptr); - setup_interrupt(); + void attach(T* tptr, void (T::*mptr)(void), IrqType type = RxIrq) { + if((mptr != NULL) && (tptr != NULL)) { + _irq[type].attach(tptr, mptr); + setup_interrupt(type); + } } #ifdef MBED_RPC @@ -151,14 +160,15 @@ protected: - void setup_interrupt(); - void remove_interrupt(); + void setup_interrupt(IrqType type); + void remove_interrupt(IrqType type); virtual int _getc(); virtual int _putc(int c); UARTName _uart; - FunctionPointer _irq; + FunctionPointer _irq[2]; + int _uidx; };