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:
69:f915c4c59a69
Parent:
32:bce180b544ed
Child:
71:562f5c702094
--- a/OneWire_Masters/DS248x/ds248x.h	Fri Apr 22 10:36:53 2016 -0500
+++ b/OneWire_Masters/DS248x/ds248x.h	Mon May 09 08:29:49 2016 -0500
@@ -41,7 +41,7 @@
 
 class Ds248x: public OneWireMaster
 {
-    public:
+public:
     
     enum DS248X_I2C_ADRS
     {
@@ -55,38 +55,13 @@
         DS248X_I2C_ADRS7
     };
     
-    enum DS248X_CMDS
-    {
-        CMD_DRST = 0xF0,
-        CMD_WCFG = 0xD2,
-        CMD_A1WP = 0xC3, //DS2484 only
-        CMD_CHSL = 0xC3, //DS2482-800 only
-        CMD_SRP = 0xE1,
-        CMD_1WRS = 0xB4,
-        CMD_1WWB = 0xA5,
-        CMD_1WRB = 0x96,
-        CMD_1WSB = 0x87,
-        CMD_1WT = 0x78
-    };
-    
-    enum DS248X_CONFIG_BITS
+    enum DS248X_REG
     {
-        CONFIG_APU = 0x01,
-        CONFIG_PDN = 0x02,
-        CONFIG_SPU = 0x04,
-        CONFIG_1WS = 0x08
-    };
-
-    enum DS248X_STATUS_BITS
-    {
-        STATUS_1WB  = 0x01,
-        STATUS_PPD = 0x02,
-        STATUS_SD = 0x04,
-        STATUS_LL = 0x08,
-        STATUS_RST = 0x10,
-        STATUS_SBR = 0x20,
-        STATUS_TSB = 0x40,
-        STATUS_DIR = 0x80
+        REG_CONFIG = 0xC3,
+        REG_STATUS = 0xF0,
+        REG_READ_DATA = 0xE1,
+        REG_PORT_CONFIG = 0xB4,
+        REG_CHANNEL_SELECT = 0xD2 //DS2482-800 only
     };
     
     enum DS2484_ADJST_PARAMS
@@ -100,13 +75,47 @@
         TREC0, //OD NA
         RWPU = 8 //OD NA, see DS2484 datasheet page 13
     };
+    
+    /// Represents a DS2465 configuration.
+    class Config
+    {
+    public:
+    /// @{
+    /// 1-Wire Speed
+    bool c1WS() const { return m_c1WS; }
+    void setC1WS(bool c1WS) { m_c1WS = c1WS; }
+    /// @}
 
-    static const size_t POLL_LIMIT = 200;
-    
-    static const int I2C_WRITE_OK = 0;
-    
-    static const int I2C_READ_OK = 0;
-    
+    /// @{
+    /// Strong Pullup
+    bool cSPU() const { return m_cSPU; }
+    void setCSPU(bool cSPU) { m_cSPU = cSPU; }
+    /// @}
+
+    /// @{
+    /// 1-Wire Power Down
+    bool cPDN() const { return m_cPDN; }
+    void setCPDN(bool cPDN) { m_cPDN = cPDN; }
+    /// @}
+
+    /// @{
+    /// Active Pullup
+    bool cAPU() const { return m_cAPU; }
+    void setCAPU(bool cAPU) { m_cAPU = cAPU; }
+    /// @}
+
+    /// Byte representation that is read from the DS2465.
+    std::uint8_t readByte() const;
+    /// Byte respresentation that is written to the DS2465.
+    std::uint8_t writeByte() const;
+
+    /// Reset to the power-on default config.
+    void reset();
+    Config() { reset(); }
+
+    private:
+    bool m_c1WS, m_cSPU, m_cPDN, m_cAPU;
+    };
     
     /**********************************************************//**
     * @brief Ds248x constructor
@@ -152,27 +161,6 @@
     
     
     /**********************************************************//**
-    * @brief detect() 
-    * 
-    * @details Detect routine that performs a device reset 
-    *          followed by writing the configuration byte to default 
-    *          values:
-    *          1-Wire speed (c1WS) = standard (0)
-    *          Strong pull-up (cSPU) = off (0)
-    *          Presence pulse masking (cPPM) = off (0)
-    *          Active pull-up (cAPU) = on (CONFIG_APU = 0x01)
-    *
-    * On Entry:
-    *
-    * On Exit:
-    *    @return TRUE if device was detected and written
-    *            FALSE device not detected or failure to write 
-    *            configuration byte
-    **************************************************************/
-    OneWireMaster::CmdResult detect(void);
-    
-    
-    /**********************************************************//**
     * @brief reset()
     * 
     * @details Perform a device reset on the Ds248x
@@ -186,22 +174,18 @@
     OneWireMaster::CmdResult reset(void);
     
     
-    /**********************************************************//**
-    * @brief write_config()
-    * 
-    * @details Write the configuration register in the Ds248x. The 
-    *          configuration options are provided in the lower nibble 
-    *          of the provided config byte. The uppper nibble is 
-    *          bitwise inverted when written to the Ds248x.
-    *
-    * On Entry:
-    *     @param[in] config - lower nib of configuration register
-    *
-    * On Exit:
-    *    @return TRUE: config written and response correct
-    *            FALSE: response incorrect
-    **************************************************************/
-    OneWireMaster::CmdResult write_config(uint8_t config);
+    /// Write a new configuration to the DS2465.
+    /// @param[in] config New configuration to write.
+    /// @param verify Verify that the configuration was written successfully.
+    OneWireMaster::CmdResult writeConfig(const Config & config, bool verify);
+
+    /// Read the current DS2465 configuration.
+    /// @returns The cached current configuration.
+    Config currentConfig() const { return m_curConfig; }
+    
+
+
+    OneWireMaster::CmdResult readRegister(DS248X_REG reg, std::uint8_t & buf, bool skipSetPointer = false) const;
     
     
     /**********************************************************//**
@@ -217,7 +201,7 @@
     *    @return TRUE if channel selected
     *            FALSE device not detected or failure to perform select
     **************************************************************/
-    OneWireMaster::CmdResult channel_select(uint8_t channel);
+    OneWireMaster::CmdResult channelSelect(uint8_t channel);
     
     
     /**********************************************************//**
@@ -234,7 +218,7 @@
     *    @return TRUE: parameter successfully adjusted
     *            FALSE: failed to adjust parameter
     **************************************************************/
-    OneWireMaster::CmdResult adjust_timing(uint8_t param, uint8_t val);
+    OneWireMaster::CmdResult adjustTiming(DS2484_ADJST_PARAMS param, uint8_t val);
     
     
     /**********************************************************//**
@@ -259,6 +243,24 @@
     //Part of OneWireMaster that should be implemented for each master
     //See OneWireMaster.h for documentation
     
+    /**********************************************************//**
+    * @brief
+    * 
+    * @details Detect routine that performs a device reset 
+    *          followed by writing the configuration byte to default 
+    *          values:
+    *          1-Wire speed (c1WS) = standard (0)
+    *          Strong pull-up (cSPU) = off (0)
+    *          Presence pulse masking (cPPM) = off (0)
+    *          Active pull-up (cAPU) = on (CONFIG_APU = 0x01)
+    *
+    * On Entry:
+    *
+    * On Exit:
+    *    @return TRUE if device was detected and written
+    *            FALSE device not detected or failure to write 
+    *            configuration byte
+    **************************************************************/
     virtual OneWireMaster::CmdResult OWInitMaster(void);
     
     virtual OneWireMaster::CmdResult OWReset(void);
@@ -277,9 +279,21 @@
 
     virtual OneWireMaster::CmdResult OWSetLevel(OWLevel new_level);
     
-    OneWireMaster::CmdResult ConfigureSPU(bool spu_enable);
-    
-    private:
+private:
+
+    enum DS248X_CMDS
+    {
+        CMD_DRST = 0xF0,
+        CMD_WCFG = 0xD2,
+        CMD_A1WP = 0xC3, //DS2484 only
+        CMD_CHSL = 0xC3, //DS2482-800 only
+        CMD_SRP = 0xE1,
+        CMD_1WRS = 0xB4,
+        CMD_1WWB = 0xA5,
+        CMD_1WRB = 0x96,
+        CMD_1WSB = 0x87,
+        CMD_1WT = 0x78
+    };
     
     //private fx for initializing _w_adrs and _r_adrs
     void set_i2c_adrs(DS248X_I2C_ADRS adrs);
@@ -290,7 +304,23 @@
     
     // ds248x state
     uint8_t _short_detected;
-    uint8_t _c1WS, _cSPU, _cPDN, _cAPU;   
+    
+    Config m_curConfig;
+
+    /// Polls the DS2465 status waiting for the 1-Wire Busy bit (1WB) to be cleared.
+    /// @param[out] pStatus Optionally retrive the status byte when 1WB cleared.
+    /// @returns Success or TimeoutError if poll limit reached.
+    OneWireMaster::CmdResult pollBusy(std::uint8_t * pStatus = NULL);
+
+    /// Ensure that the desired 1-Wire level is set in the configuration.
+    /// @param level Desired 1-Wire level.
+    OneWireMaster::CmdResult configureLevel(OWLevel level);
+
+    /// @note Allow marking const since not public.
+    OneWireMaster::CmdResult sendCommand(DS248X_CMDS cmd) const;
+    
+    /// @note Allow marking const since not public.
+    OneWireMaster::CmdResult sendCommand(DS248X_CMDS cmd, std::uint8_t param) const;
 };
 
-#endif /*DS248X_H*/
\ No newline at end of file
+#endif /*DS248X_H*/