123

Dependencies:   Buffer

Dependents:   ATParser

Revision:
15:8bcd2a38302c
Parent:
11:779304f9c5d2
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;