123
Revision 15:8bcd2a38302c, committed 2020-03-23
- Comitter:
- ohlaaa
- Date:
- Mon Mar 23 07:47:10 2020 +0000
- Parent:
- 12:a0d37088b405
- Commit message:
- demo
Changed in this revision
BufferedSerial.cpp | Show annotated file Show diff for this revision Revisions of this file |
BufferedSerial.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r a0d37088b405 -r 8bcd2a38302c BufferedSerial.cpp --- a/BufferedSerial.cpp Mon Mar 07 21:10:27 2016 +0000 +++ b/BufferedSerial.cpp Mon Mar 23 07:47:10 2020 +0000 @@ -26,12 +26,19 @@ BufferedSerial::BufferedSerial(PinName tx, PinName rx, uint32_t buf_size, uint32_t tx_multiple, const char* name) : RawSerial(tx, rx) , _rxbuf(buf_size), _txbuf((uint32_t)(tx_multiple*buf_size)) { - RawSerial::attach(this, &BufferedSerial::rxIrq, Serial::RxIrq); + RawSerial::attach(callback(this, &BufferedSerial::rxIrq), Serial::RxIrq); this->_buf_size = buf_size; this->_tx_multiple = tx_multiple; return; } +void BufferedSerial::attach(Callback<void()> func) +{ + if(func) { + this->_rx.attach(func); + } +} + BufferedSerial::~BufferedSerial(void) { RawSerial::attach(NULL, RawSerial::RxIrq); @@ -122,6 +129,7 @@ // read from the peripheral and make sure something is available if(serial_readable(&_serial)) { _rxbuf = serial_getc(&_serial); // if so load them into a buffer + _rx.call(); } return; @@ -149,7 +157,7 @@ if(serial_writable(&_serial)) { RawSerial::attach(NULL, RawSerial::TxIrq); // make sure not to cause contention in the irq BufferedSerial::txIrq(); // only write to hardware in one place - RawSerial::attach(this, &BufferedSerial::txIrq, RawSerial::TxIrq); + RawSerial::attach(callback(this, &BufferedSerial::txIrq), RawSerial::TxIrq); } return;
diff -r a0d37088b405 -r 8bcd2a38302c BufferedSerial.h --- a/BufferedSerial.h Mon Mar 07 21:10:27 2016 +0000 +++ b/BufferedSerial.h Mon Mar 23 07:47:10 2020 +0000 @@ -75,6 +75,7 @@ MyBuffer <char> _txbuf; uint32_t _buf_size; uint32_t _tx_multiple; + FunctionPointer _rx; void rxIrq(void); void txIrq(void); @@ -135,6 +136,8 @@ * @return The number of bytes written to the Serial Port Buffer */ virtual ssize_t write(const void *s, std::size_t length); + + void attach(Callback<void()> func); }; #endif