Fork of the original SoftSerial library with just a little modification in order to compile it with the current mbed version.

Dependents:   Adafruit_FONA_Library_FONAtest

Fork of SoftSerial by Erik -

Files at this revision

API Documentation at this revision

Comitter:
Sissors
Date:
Sun Apr 27 08:33:17 2014 +0000
Parent:
5:acfd0329f648
Child:
7:7de3e1019e23
Commit message:
Added custom ticker lib to allow for baudrate up to 57600

Changed in this revision

SoftSerial.cpp Show annotated file Show diff for this revision Revisions of this file
SoftSerial.h Show annotated file Show diff for this revision Revisions of this file
SoftSerial_Ticker.h Show annotated file Show diff for this revision Revisions of this file
SoftSerial_rx.cpp Show annotated file Show diff for this revision Revisions of this file
SoftSerial_tx.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SoftSerial.cpp	Sat Apr 26 20:55:02 2014 +0000
+++ b/SoftSerial.cpp	Sun Apr 27 08:33:17 2014 +0000
@@ -7,11 +7,13 @@
         tx_en = true;
         tx->write(1);
         tx_bit = -1;
+        txticker.attach(this, &SoftSerial::tx_handler);
     }
     if (RX != NC) {
         rx = new InterruptIn(RX);
         rx_en = true;
         out_valid = false;
+        rxticker.attach(this, &SoftSerial::rx_handler);
         rx->fall(this, &SoftSerial::rx_gpio_irq_handler);
     }
     
--- a/SoftSerial.h	Sat Apr 26 20:55:02 2014 +0000
+++ b/SoftSerial.h	Sun Apr 27 08:33:17 2014 +0000
@@ -2,7 +2,7 @@
 #define SOFTSERIAL_H
 
 #include "mbed.h"
-
+#include "SoftSerial_Ticker.h"
 /** A software serial implementation
  *
  */
@@ -103,13 +103,12 @@
     volatile int out_buffer;
     volatile bool out_valid;
     bool rx_error;
-    Timeout rxout;
-    Ticker rxticker;
+    FlexTicker rxticker;
     
     //tx
     void tx_handler(void);
     void prepare_tx(int c);
-    Timeout txout;
+    FlexTicker txticker;
     int _char;
     volatile int tx_bit;
     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoftSerial_Ticker.h	Sun Apr 27 08:33:17 2014 +0000
@@ -0,0 +1,38 @@
+//A modified version of the regular ticker/timeout libraries to allow us to do timeout without losing accuracy
+
+#ifndef FLEXTICKER_H
+#define FLEXTICKER_H
+
+#include "mbed.h"
+
+class FlexTicker: public TimerEvent {
+    public:
+    template<typename T>
+    void attach(T* tptr, void (T::*mptr)(void)) {
+        _function.attach(tptr, mptr);
+    }
+ 
+    /** Detach the function
+     */
+    void detach() {
+        remove();
+    }
+    
+    void setNext(int delay) {
+        insert(event.timestamp + delay);
+    }
+    
+    void prime(void) {
+        event.timestamp = us_ticker_read();
+    }
+ 
+protected:
+    virtual void handler() {
+        _function.call();
+    }
+ 
+    unsigned int _delay;
+    FunctionPointer _function;
+};
+
+#endif
\ No newline at end of file
--- a/SoftSerial_rx.cpp	Sat Apr 26 20:55:02 2014 +0000
+++ b/SoftSerial_rx.cpp	Sun Apr 27 08:33:17 2014 +0000
@@ -12,16 +12,15 @@
 
 //Start receiving byte
 void SoftSerial::rx_gpio_irq_handler(void) {
-    rxout.attach_us(this, &SoftSerial::rx_handler, bit_period + (bit_period >> 1));   //Start reading first data byte
+    rxticker.prime();
+    rxticker.setNext(bit_period + (bit_period >> 1));
     rx->fall(NULL);
     rx_bit = 0;
     rx_error = false;
 };    
 
 void SoftSerial::rx_handler(void) {
-    if (!rx_bit)
-        rxticker.attach_us(this, &SoftSerial::rx_handler, bit_period); 
-        
+    rxticker.setNext(bit_period);
     rx_bit++;
     
     //Receive data
--- a/SoftSerial_tx.cpp	Sat Apr 26 20:55:02 2014 +0000
+++ b/SoftSerial_tx.cpp	Sun Apr 27 08:33:17 2014 +0000
@@ -5,6 +5,7 @@
     while(!writeable());
     prepare_tx(c);
     tx_bit = 0;
+    txticker.prime();
     tx_handler();
     return 0;
 }
@@ -38,7 +39,7 @@
         tx_bit++;
     }
 
-    txout.attach_us(this, &SoftSerial::tx_handler, count);
+    txticker.setNext(count);
 }
 
 void SoftSerial::prepare_tx(int c)