Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
OneWire_Masters/DS248x/ds248x.h@69:f915c4c59a69, 2016-05-09 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Mon May 09 08:29:49 2016 -0500
- Revision:
- 69:f915c4c59a69
- Parent:
- 32:bce180b544ed
- Child:
- 71:562f5c702094
Clean DS248x class to more closely resemble the DS2465 class. Write "OneWireConfig.cmake" to build directory.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 1:91e52f8ab8bf | 1 | /******************************************************************//** |
j3 | 1:91e52f8ab8bf | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 1:91e52f8ab8bf | 3 | * |
j3 | 1:91e52f8ab8bf | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 1:91e52f8ab8bf | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 1:91e52f8ab8bf | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 1:91e52f8ab8bf | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 1:91e52f8ab8bf | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 1:91e52f8ab8bf | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 1:91e52f8ab8bf | 10 | * |
j3 | 1:91e52f8ab8bf | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 1:91e52f8ab8bf | 12 | * in all copies or substantial portions of the Software. |
j3 | 1:91e52f8ab8bf | 13 | * |
j3 | 1:91e52f8ab8bf | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 1:91e52f8ab8bf | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 1:91e52f8ab8bf | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 1:91e52f8ab8bf | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 1:91e52f8ab8bf | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 1:91e52f8ab8bf | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 1:91e52f8ab8bf | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 1:91e52f8ab8bf | 21 | * |
j3 | 1:91e52f8ab8bf | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 1:91e52f8ab8bf | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 1:91e52f8ab8bf | 24 | * Products, Inc. Branding Policy. |
j3 | 1:91e52f8ab8bf | 25 | * |
j3 | 1:91e52f8ab8bf | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 1:91e52f8ab8bf | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 1:91e52f8ab8bf | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 1:91e52f8ab8bf | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 1:91e52f8ab8bf | 30 | * ownership rights. |
j3 | 1:91e52f8ab8bf | 31 | **********************************************************************/ |
j3 | 1:91e52f8ab8bf | 32 | |
j3 | 1:91e52f8ab8bf | 33 | |
j3 | 1:91e52f8ab8bf | 34 | #ifndef DS248X_H |
j3 | 1:91e52f8ab8bf | 35 | #define DS248X_H |
j3 | 1:91e52f8ab8bf | 36 | |
j3 | 1:91e52f8ab8bf | 37 | |
j3 | 1:91e52f8ab8bf | 38 | #include "mbed.h" |
IanBenzMaxim | 24:8942d8478d68 | 39 | #include "OneWire_Masters/OneWireMaster.h" |
j3 | 1:91e52f8ab8bf | 40 | |
j3 | 1:91e52f8ab8bf | 41 | |
j3 | 15:f6cb0d906fb6 | 42 | class Ds248x: public OneWireMaster |
j3 | 1:91e52f8ab8bf | 43 | { |
IanBenzMaxim | 69:f915c4c59a69 | 44 | public: |
j3 | 1:91e52f8ab8bf | 45 | |
j3 | 5:ce108eeb878d | 46 | enum DS248X_I2C_ADRS |
j3 | 1:91e52f8ab8bf | 47 | { |
j3 | 1:91e52f8ab8bf | 48 | DS248X_I2C_ADRS0 = 0x18, |
j3 | 1:91e52f8ab8bf | 49 | DS248X_I2C_ADRS1, |
j3 | 1:91e52f8ab8bf | 50 | DS248X_I2C_ADRS2, |
j3 | 1:91e52f8ab8bf | 51 | DS248X_I2C_ADRS3, |
j3 | 1:91e52f8ab8bf | 52 | DS248X_I2C_ADRS4, |
j3 | 1:91e52f8ab8bf | 53 | DS248X_I2C_ADRS5, |
j3 | 1:91e52f8ab8bf | 54 | DS248X_I2C_ADRS6, |
j3 | 5:ce108eeb878d | 55 | DS248X_I2C_ADRS7 |
j3 | 5:ce108eeb878d | 56 | }; |
j3 | 5:ce108eeb878d | 57 | |
IanBenzMaxim | 69:f915c4c59a69 | 58 | enum DS248X_REG |
j3 | 5:ce108eeb878d | 59 | { |
IanBenzMaxim | 69:f915c4c59a69 | 60 | REG_CONFIG = 0xC3, |
IanBenzMaxim | 69:f915c4c59a69 | 61 | REG_STATUS = 0xF0, |
IanBenzMaxim | 69:f915c4c59a69 | 62 | REG_READ_DATA = 0xE1, |
IanBenzMaxim | 69:f915c4c59a69 | 63 | REG_PORT_CONFIG = 0xB4, |
IanBenzMaxim | 69:f915c4c59a69 | 64 | REG_CHANNEL_SELECT = 0xD2 //DS2482-800 only |
j3 | 5:ce108eeb878d | 65 | }; |
j3 | 5:ce108eeb878d | 66 | |
j3 | 5:ce108eeb878d | 67 | enum DS2484_ADJST_PARAMS |
j3 | 5:ce108eeb878d | 68 | { |
j3 | 5:ce108eeb878d | 69 | TRSTL = 0, |
j3 | 5:ce108eeb878d | 70 | TRSTL_OD, |
j3 | 5:ce108eeb878d | 71 | TMSP, |
j3 | 5:ce108eeb878d | 72 | TMSP_OD, |
j3 | 5:ce108eeb878d | 73 | TW0L, |
j3 | 5:ce108eeb878d | 74 | TW0L_OD, |
j3 | 5:ce108eeb878d | 75 | TREC0, //OD NA |
j3 | 5:ce108eeb878d | 76 | RWPU = 8 //OD NA, see DS2484 datasheet page 13 |
j3 | 5:ce108eeb878d | 77 | }; |
IanBenzMaxim | 69:f915c4c59a69 | 78 | |
IanBenzMaxim | 69:f915c4c59a69 | 79 | /// Represents a DS2465 configuration. |
IanBenzMaxim | 69:f915c4c59a69 | 80 | class Config |
IanBenzMaxim | 69:f915c4c59a69 | 81 | { |
IanBenzMaxim | 69:f915c4c59a69 | 82 | public: |
IanBenzMaxim | 69:f915c4c59a69 | 83 | /// @{ |
IanBenzMaxim | 69:f915c4c59a69 | 84 | /// 1-Wire Speed |
IanBenzMaxim | 69:f915c4c59a69 | 85 | bool c1WS() const { return m_c1WS; } |
IanBenzMaxim | 69:f915c4c59a69 | 86 | void setC1WS(bool c1WS) { m_c1WS = c1WS; } |
IanBenzMaxim | 69:f915c4c59a69 | 87 | /// @} |
j3 | 5:ce108eeb878d | 88 | |
IanBenzMaxim | 69:f915c4c59a69 | 89 | /// @{ |
IanBenzMaxim | 69:f915c4c59a69 | 90 | /// Strong Pullup |
IanBenzMaxim | 69:f915c4c59a69 | 91 | bool cSPU() const { return m_cSPU; } |
IanBenzMaxim | 69:f915c4c59a69 | 92 | void setCSPU(bool cSPU) { m_cSPU = cSPU; } |
IanBenzMaxim | 69:f915c4c59a69 | 93 | /// @} |
IanBenzMaxim | 69:f915c4c59a69 | 94 | |
IanBenzMaxim | 69:f915c4c59a69 | 95 | /// @{ |
IanBenzMaxim | 69:f915c4c59a69 | 96 | /// 1-Wire Power Down |
IanBenzMaxim | 69:f915c4c59a69 | 97 | bool cPDN() const { return m_cPDN; } |
IanBenzMaxim | 69:f915c4c59a69 | 98 | void setCPDN(bool cPDN) { m_cPDN = cPDN; } |
IanBenzMaxim | 69:f915c4c59a69 | 99 | /// @} |
IanBenzMaxim | 69:f915c4c59a69 | 100 | |
IanBenzMaxim | 69:f915c4c59a69 | 101 | /// @{ |
IanBenzMaxim | 69:f915c4c59a69 | 102 | /// Active Pullup |
IanBenzMaxim | 69:f915c4c59a69 | 103 | bool cAPU() const { return m_cAPU; } |
IanBenzMaxim | 69:f915c4c59a69 | 104 | void setCAPU(bool cAPU) { m_cAPU = cAPU; } |
IanBenzMaxim | 69:f915c4c59a69 | 105 | /// @} |
IanBenzMaxim | 69:f915c4c59a69 | 106 | |
IanBenzMaxim | 69:f915c4c59a69 | 107 | /// Byte representation that is read from the DS2465. |
IanBenzMaxim | 69:f915c4c59a69 | 108 | std::uint8_t readByte() const; |
IanBenzMaxim | 69:f915c4c59a69 | 109 | /// Byte respresentation that is written to the DS2465. |
IanBenzMaxim | 69:f915c4c59a69 | 110 | std::uint8_t writeByte() const; |
IanBenzMaxim | 69:f915c4c59a69 | 111 | |
IanBenzMaxim | 69:f915c4c59a69 | 112 | /// Reset to the power-on default config. |
IanBenzMaxim | 69:f915c4c59a69 | 113 | void reset(); |
IanBenzMaxim | 69:f915c4c59a69 | 114 | Config() { reset(); } |
IanBenzMaxim | 69:f915c4c59a69 | 115 | |
IanBenzMaxim | 69:f915c4c59a69 | 116 | private: |
IanBenzMaxim | 69:f915c4c59a69 | 117 | bool m_c1WS, m_cSPU, m_cPDN, m_cAPU; |
IanBenzMaxim | 69:f915c4c59a69 | 118 | }; |
j3 | 3:644fc630f958 | 119 | |
j3 | 1:91e52f8ab8bf | 120 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 121 | * @brief Ds248x constructor |
j3 | 1:91e52f8ab8bf | 122 | * |
j3 | 1:91e52f8ab8bf | 123 | * @details allows user to use existing I2C object |
j3 | 1:91e52f8ab8bf | 124 | * |
j3 | 1:91e52f8ab8bf | 125 | * On Entry: |
j3 | 1:91e52f8ab8bf | 126 | * @param[in] p_i2c_bus - pointer to existing I2C object |
j3 | 1:91e52f8ab8bf | 127 | * |
j3 | 1:91e52f8ab8bf | 128 | * On Exit: |
j3 | 1:91e52f8ab8bf | 129 | * @return |
j3 | 1:91e52f8ab8bf | 130 | **************************************************************/ |
j3 | 5:ce108eeb878d | 131 | Ds248x(I2C &i2c_bus, DS248X_I2C_ADRS adrs); |
j3 | 1:91e52f8ab8bf | 132 | |
j3 | 1:91e52f8ab8bf | 133 | |
j3 | 1:91e52f8ab8bf | 134 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 135 | * @brief Ds248x constructor |
j3 | 1:91e52f8ab8bf | 136 | * |
j3 | 3:644fc630f958 | 137 | * @details Object instantiates a new I2C object with no |
j3 | 3:644fc630f958 | 138 | * public access |
j3 | 1:91e52f8ab8bf | 139 | * |
j3 | 1:91e52f8ab8bf | 140 | * On Entry: |
j3 | 1:91e52f8ab8bf | 141 | * @param[in] sda - sda pin of I2C bus |
j3 | 1:91e52f8ab8bf | 142 | * @param[in] scl - scl pin of I2C bus |
j3 | 1:91e52f8ab8bf | 143 | * |
j3 | 1:91e52f8ab8bf | 144 | * On Exit: |
j3 | 1:91e52f8ab8bf | 145 | * @return |
j3 | 1:91e52f8ab8bf | 146 | **************************************************************/ |
j3 | 5:ce108eeb878d | 147 | Ds248x(PinName sda, PinName scl, DS248X_I2C_ADRS adrs); |
j3 | 1:91e52f8ab8bf | 148 | |
j3 | 1:91e52f8ab8bf | 149 | |
j3 | 1:91e52f8ab8bf | 150 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 151 | * @brief Ds248x destructor |
j3 | 1:91e52f8ab8bf | 152 | * |
j3 | 1:91e52f8ab8bf | 153 | * @details deletes I2C object if owner |
j3 | 1:91e52f8ab8bf | 154 | * |
j3 | 1:91e52f8ab8bf | 155 | * On Entry: |
j3 | 1:91e52f8ab8bf | 156 | * |
j3 | 1:91e52f8ab8bf | 157 | * On Exit: |
j3 | 1:91e52f8ab8bf | 158 | * @return |
j3 | 1:91e52f8ab8bf | 159 | **************************************************************/ |
j3 | 5:ce108eeb878d | 160 | virtual ~Ds248x(); |
j3 | 1:91e52f8ab8bf | 161 | |
j3 | 1:91e52f8ab8bf | 162 | |
j3 | 1:91e52f8ab8bf | 163 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 164 | * @brief reset() |
j3 | 1:91e52f8ab8bf | 165 | * |
j3 | 1:91e52f8ab8bf | 166 | * @details Perform a device reset on the Ds248x |
j3 | 1:91e52f8ab8bf | 167 | * |
j3 | 1:91e52f8ab8bf | 168 | * On Entry: |
j3 | 1:91e52f8ab8bf | 169 | * |
j3 | 1:91e52f8ab8bf | 170 | * On Exit: |
j3 | 1:91e52f8ab8bf | 171 | * @return TRUE if device was reset |
j3 | 1:91e52f8ab8bf | 172 | * FALSE device not detected or failure to perform reset |
j3 | 1:91e52f8ab8bf | 173 | **************************************************************/ |
j3 | 23:e8e403d61359 | 174 | OneWireMaster::CmdResult reset(void); |
j3 | 1:91e52f8ab8bf | 175 | |
j3 | 1:91e52f8ab8bf | 176 | |
IanBenzMaxim | 69:f915c4c59a69 | 177 | /// Write a new configuration to the DS2465. |
IanBenzMaxim | 69:f915c4c59a69 | 178 | /// @param[in] config New configuration to write. |
IanBenzMaxim | 69:f915c4c59a69 | 179 | /// @param verify Verify that the configuration was written successfully. |
IanBenzMaxim | 69:f915c4c59a69 | 180 | OneWireMaster::CmdResult writeConfig(const Config & config, bool verify); |
IanBenzMaxim | 69:f915c4c59a69 | 181 | |
IanBenzMaxim | 69:f915c4c59a69 | 182 | /// Read the current DS2465 configuration. |
IanBenzMaxim | 69:f915c4c59a69 | 183 | /// @returns The cached current configuration. |
IanBenzMaxim | 69:f915c4c59a69 | 184 | Config currentConfig() const { return m_curConfig; } |
IanBenzMaxim | 69:f915c4c59a69 | 185 | |
IanBenzMaxim | 69:f915c4c59a69 | 186 | |
IanBenzMaxim | 69:f915c4c59a69 | 187 | |
IanBenzMaxim | 69:f915c4c59a69 | 188 | OneWireMaster::CmdResult readRegister(DS248X_REG reg, std::uint8_t & buf, bool skipSetPointer = false) const; |
j3 | 2:02d228c25fd4 | 189 | |
j3 | 2:02d228c25fd4 | 190 | |
j3 | 2:02d228c25fd4 | 191 | /**********************************************************//** |
j3 | 2:02d228c25fd4 | 192 | * @brief channel_select() |
j3 | 2:02d228c25fd4 | 193 | * |
j3 | 2:02d228c25fd4 | 194 | * @details Select the 1-Wire channel on a DS2482-800. |
j3 | 2:02d228c25fd4 | 195 | * Min channel = 1 |
j3 | 2:02d228c25fd4 | 196 | * |
j3 | 2:02d228c25fd4 | 197 | * On Entry: |
j3 | 2:02d228c25fd4 | 198 | * @param[in] channel - desired channel of the DS2482 |
j3 | 2:02d228c25fd4 | 199 | * |
j3 | 2:02d228c25fd4 | 200 | * On Exit: |
j3 | 2:02d228c25fd4 | 201 | * @return TRUE if channel selected |
j3 | 2:02d228c25fd4 | 202 | * FALSE device not detected or failure to perform select |
j3 | 2:02d228c25fd4 | 203 | **************************************************************/ |
IanBenzMaxim | 69:f915c4c59a69 | 204 | OneWireMaster::CmdResult channelSelect(uint8_t channel); |
j3 | 1:91e52f8ab8bf | 205 | |
j3 | 1:91e52f8ab8bf | 206 | |
j3 | 1:91e52f8ab8bf | 207 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 208 | * @brief adjust_timing() |
j3 | 1:91e52f8ab8bf | 209 | * |
j3 | 2:02d228c25fd4 | 210 | * @details adjustable timming available in DS2484 only |
j3 | 1:91e52f8ab8bf | 211 | * |
j3 | 1:91e52f8ab8bf | 212 | * On Entry: |
j3 | 1:91e52f8ab8bf | 213 | * @param[in] param - 1 of 8 adjustable parameters |
j3 | 1:91e52f8ab8bf | 214 | * @param[in] val - new value for parameter, see datasheet |
j3 | 1:91e52f8ab8bf | 215 | * for codes |
j3 | 1:91e52f8ab8bf | 216 | * |
j3 | 1:91e52f8ab8bf | 217 | * On Exit: |
j3 | 1:91e52f8ab8bf | 218 | * @return TRUE: parameter successfully adjusted |
j3 | 1:91e52f8ab8bf | 219 | * FALSE: failed to adjust parameter |
j3 | 1:91e52f8ab8bf | 220 | **************************************************************/ |
IanBenzMaxim | 69:f915c4c59a69 | 221 | OneWireMaster::CmdResult adjustTiming(DS2484_ADJST_PARAMS param, uint8_t val); |
j3 | 1:91e52f8ab8bf | 222 | |
j3 | 1:91e52f8ab8bf | 223 | |
j3 | 1:91e52f8ab8bf | 224 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 225 | * @brief search_triplet() |
j3 | 1:91e52f8ab8bf | 226 | * |
j3 | 1:91e52f8ab8bf | 227 | * @details Use the Ds248x help command '1-Wire triplet' to perform |
j3 | 1:91e52f8ab8bf | 228 | * one bit of a 1-Wire search. This command does two read |
j3 | 1:91e52f8ab8bf | 229 | * bits and one write bit. The write bit is either the |
j3 | 1:91e52f8ab8bf | 230 | * default direction (all device have same bit) or in case |
j3 | 1:91e52f8ab8bf | 231 | * of a discrepancy, the 'search_direction' parameter is |
j3 | 1:91e52f8ab8bf | 232 | * used. |
j3 | 1:91e52f8ab8bf | 233 | * |
j3 | 1:91e52f8ab8bf | 234 | * On Entry: |
j3 | 1:91e52f8ab8bf | 235 | * @param[in] search_direction |
j3 | 1:91e52f8ab8bf | 236 | * |
j3 | 1:91e52f8ab8bf | 237 | * On Exit: |
j3 | 1:91e52f8ab8bf | 238 | * @return The Ds248x status byte result from the triplet command |
j3 | 1:91e52f8ab8bf | 239 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 240 | virtual OneWireMaster::CmdResult OWTriplet(SearchDirection & search_direction, std::uint8_t & sbr, std::uint8_t & tsb); |
j3 | 1:91e52f8ab8bf | 241 | |
j3 | 5:ce108eeb878d | 242 | |
j3 | 23:e8e403d61359 | 243 | //Part of OneWireMaster that should be implemented for each master |
j3 | 23:e8e403d61359 | 244 | //See OneWireMaster.h for documentation |
j3 | 15:f6cb0d906fb6 | 245 | |
IanBenzMaxim | 69:f915c4c59a69 | 246 | /**********************************************************//** |
IanBenzMaxim | 69:f915c4c59a69 | 247 | * @brief |
IanBenzMaxim | 69:f915c4c59a69 | 248 | * |
IanBenzMaxim | 69:f915c4c59a69 | 249 | * @details Detect routine that performs a device reset |
IanBenzMaxim | 69:f915c4c59a69 | 250 | * followed by writing the configuration byte to default |
IanBenzMaxim | 69:f915c4c59a69 | 251 | * values: |
IanBenzMaxim | 69:f915c4c59a69 | 252 | * 1-Wire speed (c1WS) = standard (0) |
IanBenzMaxim | 69:f915c4c59a69 | 253 | * Strong pull-up (cSPU) = off (0) |
IanBenzMaxim | 69:f915c4c59a69 | 254 | * Presence pulse masking (cPPM) = off (0) |
IanBenzMaxim | 69:f915c4c59a69 | 255 | * Active pull-up (cAPU) = on (CONFIG_APU = 0x01) |
IanBenzMaxim | 69:f915c4c59a69 | 256 | * |
IanBenzMaxim | 69:f915c4c59a69 | 257 | * On Entry: |
IanBenzMaxim | 69:f915c4c59a69 | 258 | * |
IanBenzMaxim | 69:f915c4c59a69 | 259 | * On Exit: |
IanBenzMaxim | 69:f915c4c59a69 | 260 | * @return TRUE if device was detected and written |
IanBenzMaxim | 69:f915c4c59a69 | 261 | * FALSE device not detected or failure to write |
IanBenzMaxim | 69:f915c4c59a69 | 262 | * configuration byte |
IanBenzMaxim | 69:f915c4c59a69 | 263 | **************************************************************/ |
j3 | 23:e8e403d61359 | 264 | virtual OneWireMaster::CmdResult OWInitMaster(void); |
j3 | 14:7b2886a50321 | 265 | |
j3 | 23:e8e403d61359 | 266 | virtual OneWireMaster::CmdResult OWReset(void); |
j3 | 1:91e52f8ab8bf | 267 | |
IanBenzMaxim | 32:bce180b544ed | 268 | virtual OneWireMaster::CmdResult OWTouchBit(uint8_t & sendrecvbit, OWLevel after_level); |
IanBenzMaxim | 26:a361e3f42ba5 | 269 | |
IanBenzMaxim | 32:bce180b544ed | 270 | virtual OneWireMaster::CmdResult OWReadByte(uint8_t & recvbyte, OWLevel after_level); |
IanBenzMaxim | 26:a361e3f42ba5 | 271 | |
IanBenzMaxim | 32:bce180b544ed | 272 | virtual OneWireMaster::CmdResult OWWriteByte(uint8_t sendbyte, OWLevel after_level); |
j3 | 17:b646b1e3970b | 273 | |
j3 | 23:e8e403d61359 | 274 | virtual OneWireMaster::CmdResult OWWriteBlock(const uint8_t *tran_buf, uint8_t tran_len); |
j3 | 1:91e52f8ab8bf | 275 | |
j3 | 23:e8e403d61359 | 276 | virtual OneWireMaster::CmdResult OWReadBlock(uint8_t *rx_buf, uint8_t rx_len); |
j3 | 3:644fc630f958 | 277 | |
IanBenzMaxim | 32:bce180b544ed | 278 | virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed new_speed); |
j3 | 3:644fc630f958 | 279 | |
IanBenzMaxim | 32:bce180b544ed | 280 | virtual OneWireMaster::CmdResult OWSetLevel(OWLevel new_level); |
j3 | 2:02d228c25fd4 | 281 | |
IanBenzMaxim | 69:f915c4c59a69 | 282 | private: |
IanBenzMaxim | 69:f915c4c59a69 | 283 | |
IanBenzMaxim | 69:f915c4c59a69 | 284 | enum DS248X_CMDS |
IanBenzMaxim | 69:f915c4c59a69 | 285 | { |
IanBenzMaxim | 69:f915c4c59a69 | 286 | CMD_DRST = 0xF0, |
IanBenzMaxim | 69:f915c4c59a69 | 287 | CMD_WCFG = 0xD2, |
IanBenzMaxim | 69:f915c4c59a69 | 288 | CMD_A1WP = 0xC3, //DS2484 only |
IanBenzMaxim | 69:f915c4c59a69 | 289 | CMD_CHSL = 0xC3, //DS2482-800 only |
IanBenzMaxim | 69:f915c4c59a69 | 290 | CMD_SRP = 0xE1, |
IanBenzMaxim | 69:f915c4c59a69 | 291 | CMD_1WRS = 0xB4, |
IanBenzMaxim | 69:f915c4c59a69 | 292 | CMD_1WWB = 0xA5, |
IanBenzMaxim | 69:f915c4c59a69 | 293 | CMD_1WRB = 0x96, |
IanBenzMaxim | 69:f915c4c59a69 | 294 | CMD_1WSB = 0x87, |
IanBenzMaxim | 69:f915c4c59a69 | 295 | CMD_1WT = 0x78 |
IanBenzMaxim | 69:f915c4c59a69 | 296 | }; |
j3 | 1:91e52f8ab8bf | 297 | |
j3 | 6:1faafa0b3cd7 | 298 | //private fx for initializing _w_adrs and _r_adrs |
j3 | 6:1faafa0b3cd7 | 299 | void set_i2c_adrs(DS248X_I2C_ADRS adrs); |
j3 | 5:ce108eeb878d | 300 | |
j3 | 1:91e52f8ab8bf | 301 | I2C *_p_i2c_bus; |
j3 | 1:91e52f8ab8bf | 302 | uint8_t _w_adrs, _r_adrs; |
j3 | 5:ce108eeb878d | 303 | bool _i2c_owner; |
j3 | 2:02d228c25fd4 | 304 | |
j3 | 2:02d228c25fd4 | 305 | // ds248x state |
j3 | 2:02d228c25fd4 | 306 | uint8_t _short_detected; |
IanBenzMaxim | 69:f915c4c59a69 | 307 | |
IanBenzMaxim | 69:f915c4c59a69 | 308 | Config m_curConfig; |
IanBenzMaxim | 69:f915c4c59a69 | 309 | |
IanBenzMaxim | 69:f915c4c59a69 | 310 | /// Polls the DS2465 status waiting for the 1-Wire Busy bit (1WB) to be cleared. |
IanBenzMaxim | 69:f915c4c59a69 | 311 | /// @param[out] pStatus Optionally retrive the status byte when 1WB cleared. |
IanBenzMaxim | 69:f915c4c59a69 | 312 | /// @returns Success or TimeoutError if poll limit reached. |
IanBenzMaxim | 69:f915c4c59a69 | 313 | OneWireMaster::CmdResult pollBusy(std::uint8_t * pStatus = NULL); |
IanBenzMaxim | 69:f915c4c59a69 | 314 | |
IanBenzMaxim | 69:f915c4c59a69 | 315 | /// Ensure that the desired 1-Wire level is set in the configuration. |
IanBenzMaxim | 69:f915c4c59a69 | 316 | /// @param level Desired 1-Wire level. |
IanBenzMaxim | 69:f915c4c59a69 | 317 | OneWireMaster::CmdResult configureLevel(OWLevel level); |
IanBenzMaxim | 69:f915c4c59a69 | 318 | |
IanBenzMaxim | 69:f915c4c59a69 | 319 | /// @note Allow marking const since not public. |
IanBenzMaxim | 69:f915c4c59a69 | 320 | OneWireMaster::CmdResult sendCommand(DS248X_CMDS cmd) const; |
IanBenzMaxim | 69:f915c4c59a69 | 321 | |
IanBenzMaxim | 69:f915c4c59a69 | 322 | /// @note Allow marking const since not public. |
IanBenzMaxim | 69:f915c4c59a69 | 323 | OneWireMaster::CmdResult sendCommand(DS248X_CMDS cmd, std::uint8_t param) const; |
j3 | 1:91e52f8ab8bf | 324 | }; |
j3 | 1:91e52f8ab8bf | 325 | |
IanBenzMaxim | 69:f915c4c59a69 | 326 | #endif /*DS248X_H*/ |