1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.

Dependents:   MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more

Superseded by MaximInterface.

Revision:
109:5c9180b4be25
Parent:
92:aa40c49b8563
diff -r 01aa7b13a5f9 -r 5c9180b4be25 Masters/DS2480B/DS2480B.h
--- a/Masters/DS2480B/DS2480B.h	Thu Aug 04 20:20:32 2016 +0000
+++ b/Masters/DS2480B/DS2480B.h	Fri Aug 05 15:06:47 2016 -0500
@@ -33,55 +33,25 @@
 #ifndef OneWire_Masters_DS2480B
 #define OneWire_Masters_DS2480B
 
-#include "PinNames.h"
+#include "Serial.h"
 #include "Masters/OneWireMaster.h"
 
-namespace mbed { class Serial; }
-
 namespace OneWire
 {
-    ///UART to 1-wire master interface
+    /// Serial to 1-Wire Line Driver
     class DS2480B : public OneWireMaster
     {
     public:
-    
-        ///Valid baud rates for DS2480B
-        enum Baud
+        /// Baud rates for DS2480B
+        enum BaudRate
         {
-            Bps9600 = 0,
-            Bps19200 = 2,
-            Bps57600 = 4,
-            Bps115200 = 6
+            Baud9600bps = 0, ///< 9600 bps
+            Baud19200bps = 2, ///< 19200 bps
+            Baud57600bps = 4, ///< 57600 bps
+            Baud115200bps = 6 ///< 115200 bps
         };
 
-        /**********************************************************//**
-        * @brief DS2480B constructor
-        *
-        * @details allows user to use existing Serial object
-        *
-        * On Entry:
-        *     @param[in] p_serial - pointer to existing serial object
-        *
-        * On Exit:
-        *    @return
-        **************************************************************/
-        DS2480B(mbed::Serial &p_serial);
-
-
-        /**********************************************************//**
-        * @brief DS2480B destructor
-        *
-        * @details deletes serial object if owner
-        *
-        * On Entry:
-        *
-        * On Exit:
-        *    @return
-        **************************************************************/
-        virtual ~DS2480B();
-
-
-        OneWireMaster::CmdResult DS2480B_ChangeBaud(Baud newBaud);
+        DS2480B(PinName tx, PinName rx);
 
         virtual OneWireMaster::CmdResult OWInitMaster();
         virtual OneWireMaster::CmdResult OWReset();
@@ -90,36 +60,25 @@
         virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel);
         virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed);
         virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel);
+        
+        OneWireMaster::CmdResult detect();
+        OneWireMaster::CmdResult changeBaud(BaudRate newBaud);
 
     private:
-        void rx_callback(void);
+        OneWireMaster::CmdResult writeCom(size_t outlen, uint8_t *outbuf);
+        OneWireMaster::CmdResult readCom(size_t inlen, uint8_t *inbuf);
+        void breakCom();
+        void flushCom();
+        void setComBaud(BaudRate new_baud);
 
-        OneWireMaster::CmdResult DS2480B_Detect(void);
-        OneWireMaster::CmdResult WriteCOM(uint32_t outlen, uint8_t *outbuf);
-        OneWireMaster::CmdResult ReadCOM(uint32_t inlen, uint8_t *inbuf);
-        void BreakCOM(void);
-        void FlushCOM(void);
-        void SetBaudCOM(uint8_t new_baud);
-        int32_t bitacc(uint32_t op, uint32_t state, uint32_t loc, uint8_t *buf);
-
-        mbed::Serial *_p_serial;
-        bool _serial_owner;
+        // COM interface
+        mbed::Serial serial;
 
         // DS2480B state
-        OWLevel _ULevel; // 1-Wire level
-        Baud _UBaud;  // baud rate
-        uint8_t _UMode;  // command or data mode state
-        uint8_t _USpeed; // 1-Wire communication speed
-
-        static const size_t MAX_RX_BUFFER_LEN = 256;
-        volatile struct ds2480b_circular_buff_s
-        {
-            uint8_t w_idx;
-            uint8_t r_idx;
-            uint8_t rx_bytes_available;
-            bool wrap_error;
-            uint8_t buff[MAX_RX_BUFFER_LEN];
-        }rx_buffer;
+        OWLevel level; // 1-Wire level
+        BaudRate baud;  // baud rate
+        uint8_t mode;  // command or data mode state
+        uint8_t speed; // 1-Wire communication speed
     };
 }