Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more
DS248x.h
00001 /******************************************************************//** 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 **********************************************************************/ 00032 00033 #ifndef OneWire_Masters_DS248x 00034 #define OneWire_Masters_DS248x 00035 00036 #include "Masters/OneWireMaster.h" 00037 00038 namespace mbed { class I2C; } 00039 00040 namespace OneWire 00041 { 00042 /// Interface to the DS2484, DS2482-100, DS2482-101, DS2482-800 1-Wire masters. 00043 class DS248x : public OneWireMaster 00044 { 00045 public: 00046 /// Device register pointers. 00047 enum Register 00048 { 00049 ConfigReg = 0xC3, 00050 StatusReg = 0xF0, 00051 ReadDataReg = 0xE1, 00052 PortConfigReg = 0xB4, 00053 ChannelSelectReg = 0xD2 // DS2482-800 only 00054 }; 00055 00056 /// Represents a DS248x configuration. 00057 class Config 00058 { 00059 public: 00060 /// @{ 00061 /// 1-Wire Speed 00062 bool get1WS () const { return m_1WS; } 00063 void set1WS(bool new1WS) { m_1WS = new1WS; } 00064 /// @} 00065 00066 /// @{ 00067 /// Strong Pullup 00068 bool getSPU () const { return m_SPU; } 00069 void setSPU(bool newSPU) { m_SPU = newSPU; } 00070 /// @} 00071 00072 /// @{ 00073 /// 1-Wire Power Down 00074 bool getPDN () const { return m_PDN; } 00075 void setPDN(bool newPDN) { m_PDN = newPDN; } 00076 /// @} 00077 00078 /// @{ 00079 /// Active Pullup 00080 bool getAPU () const { return m_APU; } 00081 void setAPU(bool newAPU) { m_APU = newAPU; } 00082 /// @} 00083 00084 /// Byte representation that is read from the DS248x. 00085 uint8_t readByte() const; 00086 /// Byte respresentation that is written to the DS248x. 00087 uint8_t writeByte() const; 00088 00089 /// Reset to the power-on default config. 00090 void reset(); 00091 Config() { reset(); } 00092 00093 private: 00094 bool m_1WS, m_SPU, m_PDN, m_APU; 00095 }; 00096 00097 /// Performs a soft reset on the DS248x. 00098 /// @note This is note a 1-Wire Reset. 00099 OneWireMaster::CmdResult reset(void); 00100 00101 /// Write a new configuration to the DS248x. 00102 /// @param[in] config New configuration to write. 00103 /// @param verify Verify that the configuration was written successfully. 00104 OneWireMaster::CmdResult writeConfig(const Config & config, bool verify); 00105 00106 /// Read the current DS248x configuration. 00107 /// @returns The cached current configuration. 00108 Config currentConfig() const { return m_curConfig; } 00109 00110 /// Reads a register from the DS248x. 00111 /// @param reg Register to read from. 00112 /// @param[out] buf Buffer to hold read data. 00113 /// @param skipSetPointer Assume that the read pointer is already set to the correct register. 00114 OneWireMaster::CmdResult readRegister(Register reg, uint8_t & buf, bool skipSetPointer = false) const; 00115 00116 /// @details Performs a device reset followed by writing the configuration byte to default values: 00117 /// 1-Wire Speed Standard 00118 /// Strong Pullup Off 00119 /// 1-Wire Powerdown Off 00120 /// Active Pullup On 00121 virtual OneWireMaster::CmdResult OWInitMaster (); 00122 00123 /// @note Perform a 1-Wire triplet using the DS248x command. 00124 virtual OneWireMaster::CmdResult OWTriplet (SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb); 00125 00126 virtual OneWireMaster::CmdResult OWReset(); 00127 virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel); 00128 virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel); 00129 virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel); 00130 virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed); 00131 virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel); 00132 00133 protected: 00134 enum Command 00135 { 00136 DeviceResetCmd = 0xF0, 00137 WriteDeviceConfigCmd = 0xD2, 00138 AdjustOwPortCmd = 0xC3, // DS2484 only 00139 ChannelSelectCmd = 0xC3, // DS2482-800 only 00140 SetReadPointerCmd = 0xE1, 00141 OwResetCmd = 0xB4, 00142 OwWriteByteCmd = 0xA5, 00143 OwReadByteCmd = 0x96, 00144 OwSingleBitCmd = 0x87, 00145 OwTripletCmd = 0x78 00146 }; 00147 00148 /// Construct to use an existing I2C interface. 00149 /// @param i2c_bus Configured I2C communication interface for DS248x. 00150 /// @param adrs I2C bus address of the DS248x in mbed format. 00151 DS248x(mbed::I2C & i2c_bus, uint8_t adrs); 00152 00153 /// @note Allow marking const since not public. 00154 OneWireMaster::CmdResult sendCommand (Command cmd) const; 00155 00156 /// @note Allow marking const since not public. 00157 OneWireMaster::CmdResult sendCommand (Command cmd, uint8_t param) const; 00158 00159 private: 00160 /// Polls the DS248x status waiting for the 1-Wire Busy bit (1WB) to be cleared. 00161 /// @param[out] pStatus Optionally retrieve the status byte when 1WB cleared. 00162 /// @returns Success or TimeoutError if poll limit reached. 00163 OneWireMaster::CmdResult pollBusy(uint8_t * pStatus = NULL); 00164 00165 /// Ensure that the desired 1-Wire level is set in the configuration. 00166 /// @param level Desired 1-Wire level. 00167 OneWireMaster::CmdResult configureLevel(OWLevel level); 00168 00169 mbed::I2C & m_i2c_bus; 00170 uint8_t m_adrs; 00171 Config m_curConfig; 00172 }; 00173 } 00174 00175 #endif
Generated on Tue Jul 12 2022 15:46:21 by
