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:
- 75:8b627804927c
- Parent:
- 74:23be10c32fa3
- Child:
- 76:84e6c4994e29
--- a/Masters/DS248x/DS248x.h Fri May 13 07:48:35 2016 -0500 +++ b/Masters/DS248x/DS248x.h Fri May 13 14:52:50 2016 -0500 @@ -42,9 +42,11 @@ { namespace Masters { + /// 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, @@ -54,6 +56,7 @@ ChannelSelectReg = 0xD2 // DS2482-800 only }; + /// 1-Wire port adjustment parameters. /// @note DS2484 only enum OwAdjustParam { @@ -63,11 +66,11 @@ tMSP_OD, tW0L, tW0L_OD, - tREC0, //OD NA - RWPU = 8 //OD NA, see DS2484 datasheet page 13 + tREC0, // OD NA + RWPU = 8 // OD NA, see DS2484 datasheet page 13 }; - /// Represents a DS2465 configuration. + /// Represents a DS248x configuration. class Config { public: @@ -108,171 +111,83 @@ bool m_1WS, m_SPU, m_PDN, m_APU; }; - /**********************************************************//** - * @brief DS248x constructor - * - * @details allows user to use existing I2C object - * - * On Entry: - * @param[in] p_i2c_bus - pointer to existing I2C object - * - * On Exit: - * @return - **************************************************************/ + /// 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); - /**********************************************************//** - * @brief DS248x constructor - * - * @details Object instantiates a new I2C object with no - * public access - * - * On Entry: - * @param[in] sda - sda pin of I2C bus - * @param[in] scl - scl pin of I2C bus - * - * On Exit: - * @return - **************************************************************/ + /// 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); - /**********************************************************//** - * @brief DS248x destructor - * - * @details deletes I2C object if owner - * - * On Entry: - * - * On Exit: - * @return - **************************************************************/ + /// Destroys I2C interface if owner. virtual ~DS248x(); - /**********************************************************//** - * @brief reset() - * - * @details Perform a device reset on the DS248x - * - * On Entry: - * - * On Exit: - * @return TRUE if device was reset - * FALSE device not detected or failure to perform reset - **************************************************************/ + /// 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 DS2465. + /// 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 DS2465 configuration. + /// 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; - /**********************************************************//** - * @brief channel_select() - * - * @details Select the 1-Wire channel on a DS2482-800. - * Min channel = 1 - * - * On Entry: - * @param[in] channel - desired channel of the DS2482 - * - * On Exit: - * @return TRUE if channel selected - * FALSE device not detected or failure to perform select - **************************************************************/ + /// 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); - /**********************************************************//** - * @brief adjust_timing() - * - * @details adjustable timming available in DS2484 only - * - * On Entry: - * @param[in] param - 1 of 8 adjustable parameters - * @param[in] val - new value for parameter, see datasheet - * for codes - * - * On Exit: - * @return TRUE: parameter successfully adjusted - * FALSE: failed to adjust parameter - **************************************************************/ + /// 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); - /**********************************************************//** - * @brief search_triplet() - * - * @details Use the DS248x help command '1-Wire triplet' to perform - * one bit of a 1-Wire search. This command does two read - * bits and one write bit. The write bit is either the - * default direction (all device have same bit) or in case - * of a discrepancy, the 'search_direction' parameter is - * used. - * - * On Entry: - * @param[in] search_direction - * - * On Exit: - * @return The DS248x status byte result from the triplet command - **************************************************************/ - virtual OneWireMaster::CmdResult OWTriplet(SearchDirection & search_direction, uint8_t & sbr, uint8_t & tsb); - - /**********************************************************//** - * @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); - - virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendrecvbit, OWLevel after_level); - - virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvbyte, OWLevel after_level); - - virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendbyte, OWLevel after_level); - - virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed new_speed); - - virtual OneWireMaster::CmdResult OWSetLevel(OWLevel new_level); + /// @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); private: - enum DS248X_CMDS + enum Command { - 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 + 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 }; - mbed::I2C *_p_i2c_bus; - uint8_t _adrs; - bool _i2c_owner; - + 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. @@ -285,12 +200,12 @@ OneWireMaster::CmdResult configureLevel(OWLevel level); /// @note Allow marking const since not public. - OneWireMaster::CmdResult sendCommand(DS248X_CMDS cmd) const; + OneWireMaster::CmdResult sendCommand(Command cmd) const; /// @note Allow marking const since not public. - OneWireMaster::CmdResult sendCommand(DS248X_CMDS cmd, uint8_t param) const; + OneWireMaster::CmdResult sendCommand(Command cmd, uint8_t param) const; }; } } -#endif /*DS248X_H*/ +#endif