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.
Diff: Masters/DS248x/DS248x.h
- Revision:
- 76:84e6c4994e29
- Parent:
- 75:8b627804927c
- Child:
- 78:0cbbac7f2016
--- a/Masters/DS248x/DS248x.h Fri May 13 14:52:50 2016 -0500 +++ b/Masters/DS248x/DS248x.h Sat May 14 14:27:56 2016 -0500 @@ -40,172 +40,169 @@ namespace OneWire { - namespace Masters + /// Interface to the DS2484, DS2482-100, DS2482-101, DS2482-800 1-Wire masters. + class DS248x : public OneWireMaster { - /// Interface to the DS2484, DS2482-100, DS2482-101, DS2482-800 1-Wire masters. - class DS248x : public OneWireMaster + public: + /// Device register pointers. + enum Register + { + ConfigReg = 0xC3, + StatusReg = 0xF0, + ReadDataReg = 0xE1, + PortConfigReg = 0xB4, + ChannelSelectReg = 0xD2 // DS2482-800 only + }; + + /// 1-Wire port adjustment parameters. + /// @note DS2484 only + enum OwAdjustParam + { + tRSTL = 0, + tRSTL_OD, + tMSP, + tMSP_OD, + tW0L, + tW0L_OD, + tREC0, // OD NA + RWPU = 8 // OD NA, see DS2484 datasheet page 13 + }; + + /// Represents a DS248x configuration. + class Config { public: - /// Device register pointers. - enum Register - { - ConfigReg = 0xC3, - StatusReg = 0xF0, - ReadDataReg = 0xE1, - PortConfigReg = 0xB4, - ChannelSelectReg = 0xD2 // DS2482-800 only - }; - - /// 1-Wire port adjustment parameters. - /// @note DS2484 only - enum OwAdjustParam - { - tRSTL = 0, - tRSTL_OD, - tMSP, - tMSP_OD, - tW0L, - tW0L_OD, - tREC0, // OD NA - RWPU = 8 // OD NA, see DS2484 datasheet page 13 - }; + /// @{ + /// 1-Wire Speed + bool get1WS() const { return m_1WS; } + void set1WS(bool new1WS) { m_1WS = new1WS; } + /// @} - /// Represents a DS248x configuration. - class Config - { - public: - /// @{ - /// 1-Wire Speed - bool get1WS() const { return m_1WS; } - void set1WS(bool new1WS) { m_1WS = new1WS; } - /// @} - - /// @{ - /// Strong Pullup - bool getSPU() const { return m_SPU; } - void setSPU(bool newSPU) { m_SPU = newSPU; } - /// @} - - /// @{ - /// 1-Wire Power Down - bool getPDN() const { return m_PDN; } - void setPDN(bool newPDN) { m_PDN = newPDN; } - /// @} - - /// @{ - /// Active Pullup - bool getAPU() const { return m_APU; } - void setAPU(bool newAPU) { m_APU = newAPU; } - /// @} - - /// Byte representation that is read from the DS2465. - uint8_t readByte() const; - /// Byte respresentation that is written to the DS2465. - uint8_t writeByte() const; - - /// Reset to the power-on default config. - void reset(); - Config() { reset(); } + /// @{ + /// Strong Pullup + bool getSPU() const { return m_SPU; } + void setSPU(bool newSPU) { m_SPU = newSPU; } + /// @} - private: - bool m_1WS, m_SPU, m_PDN, m_APU; - }; - - /// Construct to use an existing I2C interface. - /// @param i2c_bus Configured I2C communication interface for DS248x. - /// @param adrs I2C bus address of the DS248x in mbed format. - DS248x(mbed::I2C & i2c_bus, uint8_t adrs); - - /// Construct with a new I2C interface. - /// @param sda SDA pin of the I2C bus. - /// @param scl SCL pin of the I2C bus. - /// @param adrs I2C bus address of the DS248x in mbed format. - DS248x(PinName sda, PinName scl, uint8_t adrs); - - /// Destroys I2C interface if owner. - virtual ~DS248x(); - - /// Performs a soft reset on the DS248x. - /// @note This is note a 1-Wire Reset. - OneWireMaster::CmdResult reset(void); - - /// Write a new configuration to the DS248x. - /// @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 DS248x configuration. - /// @returns The cached current configuration. - Config currentConfig() const { return m_curConfig; } + /// @{ + /// 1-Wire Power Down + bool getPDN() const { return m_PDN; } + void setPDN(bool newPDN) { m_PDN = newPDN; } + /// @} - /// Reads a register from the DS248x. - /// @param reg Register to read from. - /// @param[out] buf Buffer to hold read data. - /// @param skipSetPointer Assume that the read pointer is already set to the correct register. - OneWireMaster::CmdResult readRegister(Register reg, uint8_t & buf, bool skipSetPointer = false) const; - - /// Select the 1-Wire channel on a DS2482-800. - /// @note DS2482-800 only - /// @param channel Channel number to select beginning at 1. - OneWireMaster::CmdResult selectChannel(uint8_t channel); + /// @{ + /// Active Pullup + bool getAPU() const { return m_APU; } + void setAPU(bool newAPU) { m_APU = newAPU; } + /// @} - /// Adjust 1-Wire port paramaters. - /// @note DS2484 only - /// @param param Parameter to adjust. - /// @param val New parameter value to set. Consult datasheet for value mappings. - OneWireMaster::CmdResult adjustOwPort(OwAdjustParam param, uint8_t val); + /// Byte representation that is read from the DS2465. + uint8_t readByte() const; + /// Byte respresentation that is written to the DS2465. + uint8_t writeByte() const; - /// @details Performs a device reset followed by writing the configuration byte to default values: - /// 1-Wire Speed Standard - /// Strong Pullup Off - /// 1-Wire Powerdown Off - /// Active Pullup On - virtual OneWireMaster::CmdResult OWInitMaster(); - /// @note Perform a 1-Wire triplet using the DS248x command. - virtual OneWireMaster::CmdResult OWTriplet(SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb); - virtual OneWireMaster::CmdResult OWReset(); - virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel); - virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel); - virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel); - virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed); - virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel); + /// Reset to the power-on default config. + void reset(); + Config() { reset(); } private: - enum Command - { - DeviceResetCmd = 0xF0, - WriteDeviceConfigCmd = 0xD2, - AdjustOwPortCmd = 0xC3, // DS2484 only - ChannelSelectCmd = 0xC3, // DS2482-800 only - SetReadPointerCmd = 0xE1, - OwResetCmd = 0xB4, - OwWriteByteCmd = 0xA5, - OwReadByteCmd = 0x96, - OwSingleBitCmd = 0x87, - OwTripletCmd = 0x78 - }; + bool m_1WS, m_SPU, m_PDN, m_APU; + }; + + /// Construct to use an existing I2C interface. + /// @param i2c_bus Configured I2C communication interface for DS248x. + /// @param adrs I2C bus address of the DS248x in mbed format. + DS248x(mbed::I2C & i2c_bus, uint8_t adrs); + + /// Construct with a new I2C interface. + /// @param sda SDA pin of the I2C bus. + /// @param scl SCL pin of the I2C bus. + /// @param adrs I2C bus address of the DS248x in mbed format. + DS248x(PinName sda, PinName scl, uint8_t adrs); + + /// Destroys I2C interface if owner. + virtual ~DS248x(); + + /// Performs a soft reset on the DS248x. + /// @note This is note a 1-Wire Reset. + OneWireMaster::CmdResult reset(void); + + /// Write a new configuration to the DS248x. + /// @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 DS248x configuration. + /// @returns The cached current configuration. + Config currentConfig() const { return m_curConfig; } + + /// Reads a register from the DS248x. + /// @param reg Register to read from. + /// @param[out] buf Buffer to hold read data. + /// @param skipSetPointer Assume that the read pointer is already set to the correct register. + OneWireMaster::CmdResult readRegister(Register reg, uint8_t & buf, bool skipSetPointer = false) const; + + /// Select the 1-Wire channel on a DS2482-800. + /// @note DS2482-800 only + /// @param channel Channel number to select beginning at 1. + OneWireMaster::CmdResult selectChannel(uint8_t channel); + + /// Adjust 1-Wire port paramaters. + /// @note DS2484 only + /// @param param Parameter to adjust. + /// @param val New parameter value to set. Consult datasheet for value mappings. + OneWireMaster::CmdResult adjustOwPort(OwAdjustParam param, uint8_t val); - mbed::I2C *m_p_i2c_bus; - uint8_t m_adrs; - bool m_i2c_owner; - 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(uint8_t * pStatus = NULL); + /// @details Performs a device reset followed by writing the configuration byte to default values: + /// 1-Wire Speed Standard + /// Strong Pullup Off + /// 1-Wire Powerdown Off + /// Active Pullup On + virtual OneWireMaster::CmdResult OWInitMaster(); + /// @note Perform a 1-Wire triplet using the DS248x command. + virtual OneWireMaster::CmdResult OWTriplet(SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb); + virtual OneWireMaster::CmdResult OWReset(); + virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel); + virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel); + virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel); + virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed); + virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel); - /// Ensure that the desired 1-Wire level is set in the configuration. - /// @param level Desired 1-Wire level. - OneWireMaster::CmdResult configureLevel(OWLevel level); + private: + enum Command + { + DeviceResetCmd = 0xF0, + WriteDeviceConfigCmd = 0xD2, + AdjustOwPortCmd = 0xC3, // DS2484 only + ChannelSelectCmd = 0xC3, // DS2482-800 only + SetReadPointerCmd = 0xE1, + OwResetCmd = 0xB4, + OwWriteByteCmd = 0xA5, + OwReadByteCmd = 0x96, + OwSingleBitCmd = 0x87, + OwTripletCmd = 0x78 + }; - /// @note Allow marking const since not public. - OneWireMaster::CmdResult sendCommand(Command cmd) const; + mbed::I2C *m_p_i2c_bus; + uint8_t m_adrs; + bool m_i2c_owner; + 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(uint8_t * pStatus = NULL); - /// @note Allow marking const since not public. - OneWireMaster::CmdResult sendCommand(Command cmd, uint8_t param) const; - }; - } + /// 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(Command cmd) const; + + /// @note Allow marking const since not public. + OneWireMaster::CmdResult sendCommand(Command cmd, uint8_t param) const; + }; } #endif