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:
32:bce180b544ed
Parent:
27:d5aaefa252f1
Child:
43:23017dcd2ec3
diff -r 7c684e49fa8f -r bce180b544ed OneWire_Masters/OneWireMaster.h
--- a/OneWire_Masters/OneWireMaster.h	Tue Mar 29 16:36:12 2016 -0500
+++ b/OneWire_Masters/OneWireMaster.h	Wed Mar 30 16:50:29 2016 -0500
@@ -37,24 +37,30 @@
 #include <cstdint>
 #include <cstddef>
 
-class RomId;
+#include "RomId.hpp"
 
 class OneWireMaster
 {   
 public:
     
-    enum OW_SPEED
+    enum OWSpeed
     {
         SPEED_STANDARD = 0x00,
         SPEED_OVERDRIVE = 0x01
     };
     
-    enum OW_LEVEL
+    enum OWLevel
     {
         LEVEL_NORMAL = 0x00,
         LEVEL_STRONG = 0x02
     };
     
+    enum SearchDirection
+    {
+        DIRECTION_WRITE_ZERO = 0,
+        DIRECTION_WRITE_ONE = 1
+    };
+    
     enum CmdResult
     {
         Success,
@@ -64,6 +70,24 @@
         OperationFailure
     };
     
+    struct SearchState
+    {
+        RomId romId;
+        std::uint8_t last_discrepancy;
+        std::uint8_t last_family_discrepancy;
+        bool last_device_flag;
+        
+        void reset()
+        {
+            last_discrepancy = 0;
+            last_device_flag = false;
+            last_family_discrepancy = 0;
+            romId.reset();
+        }
+        
+        SearchState() { reset(); }
+    };
+    
     static std::uint16_t calculateCRC16(std::uint16_t CRC16, std::uint16_t data);
     
     static std::uint16_t calculateCRC16(const std::uint8_t * data, std::size_t data_offset, std::size_t data_len, std::uint16_t crc = 0);
@@ -118,7 +142,7 @@
     *
     * @return CmdResult - zero on success, non-zero on failure
     **************************************************************/
-    virtual CmdResult OWTouchBit(std::uint8_t & sendrecvbit, OW_LEVEL after_level) = 0;
+    virtual CmdResult OWTouchBit(std::uint8_t & sendrecvbit, OWLevel after_level) = 0;
     
     
     /**********************************************************//**
@@ -136,7 +160,7 @@
     *
     * @return CmdResult - zero on success, non-zero on failure
     **************************************************************/
-    virtual CmdResult OWWriteByte(std::uint8_t sendbyte, OW_LEVEL after_level) = 0;
+    virtual CmdResult OWWriteByte(std::uint8_t sendbyte, OWLevel after_level) = 0;
     
     
     /**********************************************************//**
@@ -151,7 +175,7 @@
     *
     * @return CmdResult - zero on success, non-zero on failure
     **************************************************************/
-    virtual CmdResult OWReadByte(std::uint8_t & recvbyte, OW_LEVEL after_level) = 0;
+    virtual CmdResult OWReadByte(std::uint8_t & recvbyte, OWLevel after_level) = 0;
     
     
     /**********************************************************//**
@@ -189,29 +213,7 @@
     
     
     /**********************************************************//**
-    * @brief OWSearch()
-    * 
-    * @details The 'OWSearch' function does a general search.  This 
-    *        function continues from the previous search state. The 
-    *        search state can be reset by using the 'OWFirst' 
-    *        function. This function contains one parameter 
-    *        'alarm_only'. When 'alarm_only' is TRUE (1) the find 
-    *        alarm command 0xEC is sent instead of the normal search 
-    *        command 0xF0. Using the find alarm command 0xEC will 
-    *        limit the search to only 1-Wire devices that are in an 
-    *        'alarm' state.
-    *
-    * On Entry:
-    *
-    * On Exit:
-    *
-    * @return CmdResult - zero on success, non-zero on failure
-    **************************************************************/
-    virtual CmdResult OWSearch(RomId & romId) = 0;
-    
-    
-    /**********************************************************//**
-    * @brief OWSpeed()
+    * @brief OWSetSpeed()
     * 
     * @details Set the 1-Wire Net communication speed.
     *
@@ -224,10 +226,11 @@
     *
     * @return CmdResult - zero on success, non-zero on failure
     **************************************************************/
-    virtual CmdResult OWSpeed(OW_SPEED new_speed) = 0;
+    virtual CmdResult OWSetSpeed(OWSpeed new_speed) = 0;
+    
     
     /**********************************************************//**
-    * @brief OWLevel()
+    * @brief OWSetLevel()
     *
     * @details Set the 1-Wire Net line level pull-up to normal. The 
     *          ds2484 does only allows enabling strong pull-up on a 
@@ -243,10 +246,16 @@
     *
     * @return CmdResult - zero on success, non-zero on failure
     **************************************************************/
-    virtual CmdResult OWLevel(OW_LEVEL new_level) = 0;
+    virtual CmdResult OWSetLevel(OWLevel new_level) = 0;
+    
+    
+    
     
-    CmdResult OWWriteBit(std::uint8_t sendbit, OW_LEVEL after_level) { return OWTouchBit(sendbit, after_level); }
-    CmdResult OWReadBit(std::uint8_t & recvbit, OW_LEVEL after_level) { recvbit = 0x01; return OWTouchBit(recvbit, after_level); }
+    virtual CmdResult OWTriplet(SearchDirection & search_direction, std::uint8_t & sbr, std::uint8_t & tsb);
+    
+    
+    CmdResult OWWriteBit(std::uint8_t sendbit, OWLevel after_level) { return OWTouchBit(sendbit, after_level); }
+    CmdResult OWReadBit(std::uint8_t & recvbit, OWLevel after_level) { recvbit = 0x01; return OWTouchBit(recvbit, after_level); }
     
     CmdResult OWWriteBit(std::uint8_t sendbit) { return OWWriteBit(sendbit, LEVEL_NORMAL); }
     CmdResult OWReadBit(std::uint8_t & recvbit) { return OWReadBit(recvbit, LEVEL_NORMAL); }
@@ -269,7 +278,7 @@
     *
     * @return CmdResult - zero on success, non-zero on failure
     **************************************************************/
-    CmdResult OWFirst(RomId & romId);
+    CmdResult OWFirst(SearchState & searchState);
     
     
     /**********************************************************//**
@@ -283,7 +292,7 @@
     *
     * @return CmdResult - zero on success, non-zero on failure
     **************************************************************/
-    CmdResult OWNext(RomId & romId);
+    CmdResult OWNext(SearchState & searchState);
     
     
     /**********************************************************//**
@@ -314,7 +323,7 @@
     *
     * @return 
     **************************************************************/
-    void OWTargetSetup(RomId & romId);
+    void OWTargetSetup(SearchState & searchState);
     
     
     /**********************************************************//**
@@ -329,7 +338,7 @@
     *
     * @return 
     **************************************************************/
-    void OWFamilySkipSetup(void);
+    void OWFamilySkipSetup(SearchState & searchState);
     
     
     /**********************************************************//**
@@ -424,7 +433,30 @@
     **************************************************************/
     CmdResult OWResume(void);
     
-protected:
+    
+    /**********************************************************//**
+    * @brief OWSearch()
+    * 
+    * @details The 'OWSearch' function does a general search.  This 
+    *        function continues from the previous search state. The 
+    *        search state can be reset by using the 'OWFirst' 
+    *        function. This function contains one parameter 
+    *        'alarm_only'. When 'alarm_only' is TRUE (1) the find 
+    *        alarm command 0xEC is sent instead of the normal search 
+    *        command 0xF0. Using the find alarm command 0xEC will 
+    *        limit the search to only 1-Wire devices that are in an 
+    *        'alarm' state.
+    *
+    * On Entry:
+    *
+    * On Exit:
+    *
+    * @return CmdResult - zero on success, non-zero on failure
+    **************************************************************/
+    CmdResult OWSearch(SearchState & searchState);
+    
+    
+private:
 
     enum OW_ROM_CMD
     {
@@ -437,13 +469,6 @@
         OVERDRIVE_MATCH_ROM = 0x69
     };
     
-    // Search state
-    std::uint8_t _last_discrepancy;
-    std::uint8_t _last_family_discrepancy;
-    bool _last_device_flag;
-
-private:
-    
     static const std::uint16_t _oddparity[16];
 };