Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
OneWire_Masters/OneWireMaster.h@72:6892702709ee, 2016-05-09 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Mon May 09 16:20:56 2016 -0500
- Revision:
- 72:6892702709ee
- Parent:
- 71:562f5c702094
Use distinct names to prevent hiding of overloads in derived classes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 5:ce108eeb878d | 1 | /******************************************************************//** |
j3 | 5:ce108eeb878d | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 5:ce108eeb878d | 3 | * |
j3 | 5:ce108eeb878d | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 5:ce108eeb878d | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 5:ce108eeb878d | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 5:ce108eeb878d | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 5:ce108eeb878d | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 5:ce108eeb878d | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 5:ce108eeb878d | 10 | * |
j3 | 5:ce108eeb878d | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 5:ce108eeb878d | 12 | * in all copies or substantial portions of the Software. |
j3 | 5:ce108eeb878d | 13 | * |
j3 | 5:ce108eeb878d | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 5:ce108eeb878d | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 5:ce108eeb878d | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 5:ce108eeb878d | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 5:ce108eeb878d | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 5:ce108eeb878d | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 5:ce108eeb878d | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 5:ce108eeb878d | 21 | * |
j3 | 5:ce108eeb878d | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 5:ce108eeb878d | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 5:ce108eeb878d | 24 | * Products, Inc. Branding Policy. |
j3 | 5:ce108eeb878d | 25 | * |
j3 | 5:ce108eeb878d | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 5:ce108eeb878d | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 5:ce108eeb878d | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 5:ce108eeb878d | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 5:ce108eeb878d | 30 | * ownership rights. |
j3 | 5:ce108eeb878d | 31 | **********************************************************************/ |
j3 | 5:ce108eeb878d | 32 | |
j3 | 5:ce108eeb878d | 33 | |
j3 | 15:f6cb0d906fb6 | 34 | #ifndef ONEWIREMASTER_H |
j3 | 15:f6cb0d906fb6 | 35 | #define ONEWIREMASTER_H |
j3 | 5:ce108eeb878d | 36 | |
IanBenzMaxim | 27:d5aaefa252f1 | 37 | #include <cstdint> |
IanBenzMaxim | 27:d5aaefa252f1 | 38 | #include <cstddef> |
j3 | 5:ce108eeb878d | 39 | |
IanBenzMaxim | 32:bce180b544ed | 40 | #include "RomId.hpp" |
j3 | 5:ce108eeb878d | 41 | |
IanBenzMaxim | 48:6f9208ae280e | 42 | /// Base class for all 1-Wire Masters. |
j3 | 23:e8e403d61359 | 43 | class OneWireMaster |
IanBenzMaxim | 27:d5aaefa252f1 | 44 | { |
IanBenzMaxim | 24:8942d8478d68 | 45 | public: |
j3 | 23:e8e403d61359 | 46 | |
IanBenzMaxim | 48:6f9208ae280e | 47 | /// Speed of the 1-Wire bus |
IanBenzMaxim | 32:bce180b544ed | 48 | enum OWSpeed |
j3 | 23:e8e403d61359 | 49 | { |
j3 | 23:e8e403d61359 | 50 | SPEED_STANDARD = 0x00, |
j3 | 23:e8e403d61359 | 51 | SPEED_OVERDRIVE = 0x01 |
j3 | 23:e8e403d61359 | 52 | }; |
j3 | 23:e8e403d61359 | 53 | |
IanBenzMaxim | 48:6f9208ae280e | 54 | /// Level of the 1-Wire bus |
IanBenzMaxim | 32:bce180b544ed | 55 | enum OWLevel |
j3 | 23:e8e403d61359 | 56 | { |
j3 | 23:e8e403d61359 | 57 | LEVEL_NORMAL = 0x00, |
j3 | 63:422be898443a | 58 | LEVEL_STRONG = 0x02, |
j3 | 63:422be898443a | 59 | LEVEL_PROGRAM = 0x04, |
j3 | 23:e8e403d61359 | 60 | }; |
j3 | 23:e8e403d61359 | 61 | |
IanBenzMaxim | 48:6f9208ae280e | 62 | /// Search direction for the Triplet |
IanBenzMaxim | 32:bce180b544ed | 63 | enum SearchDirection |
IanBenzMaxim | 32:bce180b544ed | 64 | { |
IanBenzMaxim | 32:bce180b544ed | 65 | DIRECTION_WRITE_ZERO = 0, |
IanBenzMaxim | 32:bce180b544ed | 66 | DIRECTION_WRITE_ONE = 1 |
IanBenzMaxim | 32:bce180b544ed | 67 | }; |
IanBenzMaxim | 32:bce180b544ed | 68 | |
IanBenzMaxim | 48:6f9208ae280e | 69 | /// Result of all 1-Wire commands |
j3 | 23:e8e403d61359 | 70 | enum CmdResult |
j3 | 23:e8e403d61359 | 71 | { |
j3 | 23:e8e403d61359 | 72 | Success, |
j3 | 23:e8e403d61359 | 73 | CommunicationWriteError, |
j3 | 23:e8e403d61359 | 74 | CommunicationReadError, |
j3 | 23:e8e403d61359 | 75 | TimeoutError, |
j3 | 23:e8e403d61359 | 76 | OperationFailure |
j3 | 23:e8e403d61359 | 77 | }; |
j3 | 23:e8e403d61359 | 78 | |
IanBenzMaxim | 48:6f9208ae280e | 79 | /// State used by all ROM ID search functions. |
IanBenzMaxim | 32:bce180b544ed | 80 | struct SearchState |
IanBenzMaxim | 32:bce180b544ed | 81 | { |
IanBenzMaxim | 32:bce180b544ed | 82 | RomId romId; |
IanBenzMaxim | 32:bce180b544ed | 83 | std::uint8_t last_discrepancy; |
IanBenzMaxim | 32:bce180b544ed | 84 | std::uint8_t last_family_discrepancy; |
IanBenzMaxim | 32:bce180b544ed | 85 | bool last_device_flag; |
IanBenzMaxim | 32:bce180b544ed | 86 | |
IanBenzMaxim | 48:6f9208ae280e | 87 | /// Reset to the search state to start at the beginning. |
IanBenzMaxim | 32:bce180b544ed | 88 | void reset() |
IanBenzMaxim | 32:bce180b544ed | 89 | { |
IanBenzMaxim | 32:bce180b544ed | 90 | last_discrepancy = 0; |
IanBenzMaxim | 32:bce180b544ed | 91 | last_device_flag = false; |
IanBenzMaxim | 32:bce180b544ed | 92 | last_family_discrepancy = 0; |
IanBenzMaxim | 32:bce180b544ed | 93 | romId.reset(); |
IanBenzMaxim | 32:bce180b544ed | 94 | } |
IanBenzMaxim | 32:bce180b544ed | 95 | |
IanBenzMaxim | 32:bce180b544ed | 96 | SearchState() { reset(); } |
IanBenzMaxim | 32:bce180b544ed | 97 | }; |
IanBenzMaxim | 32:bce180b544ed | 98 | |
IanBenzMaxim | 48:6f9208ae280e | 99 | /// Perform a CRC16 calculation. |
IanBenzMaxim | 48:6f9208ae280e | 100 | /// @param CRC16 Beginning state of the CRC generator. |
IanBenzMaxim | 48:6f9208ae280e | 101 | /// @param data Data to pass though the CRC generator. |
IanBenzMaxim | 48:6f9208ae280e | 102 | /// @returns The calculated CRC16. |
IanBenzMaxim | 27:d5aaefa252f1 | 103 | static std::uint16_t calculateCRC16(std::uint16_t CRC16, std::uint16_t data); |
j3 | 17:b646b1e3970b | 104 | |
IanBenzMaxim | 49:36954b62f503 | 105 | /// Perform a CRC16 calculation with variable length data. |
IanBenzMaxim | 48:6f9208ae280e | 106 | /// @param[in] data Data array to pass through the CRC generator. |
IanBenzMaxim | 48:6f9208ae280e | 107 | /// @param data_offset Offset of the data array to begin processing. |
IanBenzMaxim | 48:6f9208ae280e | 108 | /// @param data_len Length of the data array to process. |
IanBenzMaxim | 48:6f9208ae280e | 109 | /// @param crc Beginning state of the CRC generator. |
IanBenzMaxim | 48:6f9208ae280e | 110 | /// @returns The calculated CRC16. |
IanBenzMaxim | 27:d5aaefa252f1 | 111 | static std::uint16_t calculateCRC16(const std::uint8_t * data, std::size_t data_offset, std::size_t data_len, std::uint16_t crc = 0); |
j3 | 17:b646b1e3970b | 112 | |
IanBenzMaxim | 48:6f9208ae280e | 113 | /// Allow freeing through a base class pointer. |
IanBenzMaxim | 26:a361e3f42ba5 | 114 | virtual ~OneWireMaster() { } |
IanBenzMaxim | 26:a361e3f42ba5 | 115 | |
j3 | 23:e8e403d61359 | 116 | |
j3 | 23:e8e403d61359 | 117 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 118 | * @brief OWInitMaster() |
j3 | 23:e8e403d61359 | 119 | * |
j3 | 23:e8e403d61359 | 120 | * @details Initiializes particular master being instaniated. |
j3 | 23:e8e403d61359 | 121 | * Added to interface to provide a common 'init' function between |
j3 | 23:e8e403d61359 | 122 | * all masters |
j3 | 23:e8e403d61359 | 123 | * |
j3 | 23:e8e403d61359 | 124 | * On Entry: |
j3 | 23:e8e403d61359 | 125 | * |
j3 | 23:e8e403d61359 | 126 | * On Exit: |
j3 | 23:e8e403d61359 | 127 | * |
j3 | 23:e8e403d61359 | 128 | **************************************************************/ |
j3 | 23:e8e403d61359 | 129 | virtual CmdResult OWInitMaster(void) = 0; |
j3 | 23:e8e403d61359 | 130 | |
j3 | 23:e8e403d61359 | 131 | |
j3 | 23:e8e403d61359 | 132 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 133 | * @brief OWReset() |
j3 | 23:e8e403d61359 | 134 | * |
j3 | 23:e8e403d61359 | 135 | * @details Reset all of the devices on the 1-Wire Net and return |
j3 | 23:e8e403d61359 | 136 | * the result. |
j3 | 23:e8e403d61359 | 137 | * |
j3 | 23:e8e403d61359 | 138 | * On Entry: |
j3 | 23:e8e403d61359 | 139 | * |
j3 | 23:e8e403d61359 | 140 | * On Exit: |
j3 | 23:e8e403d61359 | 141 | * |
IanBenzMaxim | 47:307dc45952db | 142 | * @returns OperationFailure if reset was performed but no |
IanBenzMaxim | 47:307dc45952db | 143 | * presence pulse was detected. |
j3 | 23:e8e403d61359 | 144 | **************************************************************/ |
j3 | 23:e8e403d61359 | 145 | virtual CmdResult OWReset(void) = 0; |
j3 | 23:e8e403d61359 | 146 | |
j3 | 23:e8e403d61359 | 147 | |
j3 | 23:e8e403d61359 | 148 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 149 | * @brief OWTouchBit() |
j3 | 23:e8e403d61359 | 150 | * |
j3 | 23:e8e403d61359 | 151 | * @details Send 1 bit of communication to the 1-Wire Net and return |
j3 | 23:e8e403d61359 | 152 | * the result 1 bit read from the 1-Wire Net. The |
j3 | 23:e8e403d61359 | 153 | * parameter 'sendbit' least significant bit is used and |
j3 | 23:e8e403d61359 | 154 | * the least significant bit of the result is the return |
j3 | 23:e8e403d61359 | 155 | * bit. |
j3 | 23:e8e403d61359 | 156 | * |
j3 | 23:e8e403d61359 | 157 | * On Entry: |
j3 | 23:e8e403d61359 | 158 | * @param[in] 'sendbit' - the least significant bit is the bit to send |
j3 | 23:e8e403d61359 | 159 | * |
j3 | 23:e8e403d61359 | 160 | * On Exit: |
j3 | 23:e8e403d61359 | 161 | * |
j3 | 23:e8e403d61359 | 162 | **************************************************************/ |
IanBenzMaxim | 72:6892702709ee | 163 | virtual CmdResult OWTouchBitSetLevel(std::uint8_t & sendrecvbit, OWLevel after_level) = 0; |
j3 | 23:e8e403d61359 | 164 | |
j3 | 23:e8e403d61359 | 165 | |
j3 | 23:e8e403d61359 | 166 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 167 | * @brief OWWRiteByte() |
j3 | 23:e8e403d61359 | 168 | * |
j3 | 23:e8e403d61359 | 169 | * @details Send 8 bits of communication to the 1-Wire Net and |
j3 | 23:e8e403d61359 | 170 | * verify that the 8 bits read from the 1-Wire Net is the |
j3 | 23:e8e403d61359 | 171 | * same (write operation).The parameter 'sendbyte' least |
j3 | 23:e8e403d61359 | 172 | * significant 8 bits are used. |
j3 | 23:e8e403d61359 | 173 | * |
j3 | 23:e8e403d61359 | 174 | * On Entry: |
j3 | 23:e8e403d61359 | 175 | * @param[in] 'sendbyte' - 8 bits to send (least significant byte) |
j3 | 23:e8e403d61359 | 176 | * |
j3 | 23:e8e403d61359 | 177 | * On Exit: |
j3 | 23:e8e403d61359 | 178 | * |
j3 | 23:e8e403d61359 | 179 | **************************************************************/ |
IanBenzMaxim | 72:6892702709ee | 180 | virtual CmdResult OWWriteByteSetLevel(std::uint8_t sendbyte, OWLevel after_level) = 0; |
j3 | 23:e8e403d61359 | 181 | |
j3 | 23:e8e403d61359 | 182 | |
j3 | 23:e8e403d61359 | 183 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 184 | * @brief OWReadByte() |
j3 | 23:e8e403d61359 | 185 | * |
j3 | 23:e8e403d61359 | 186 | * @details Send 8 bits of read communication to the 1-Wire Net |
j3 | 23:e8e403d61359 | 187 | * and return the result 8 bits read from the 1-Wire Net. |
j3 | 23:e8e403d61359 | 188 | * |
j3 | 23:e8e403d61359 | 189 | * On Entry: |
j3 | 23:e8e403d61359 | 190 | * |
j3 | 23:e8e403d61359 | 191 | * On Exit: |
j3 | 23:e8e403d61359 | 192 | * |
j3 | 23:e8e403d61359 | 193 | **************************************************************/ |
IanBenzMaxim | 72:6892702709ee | 194 | virtual CmdResult OWReadByteSetLevel(std::uint8_t & recvbyte, OWLevel after_level) = 0; |
j3 | 23:e8e403d61359 | 195 | |
j3 | 23:e8e403d61359 | 196 | |
j3 | 23:e8e403d61359 | 197 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 198 | * @brief OWWriteBlock() |
j3 | 23:e8e403d61359 | 199 | * |
j3 | 23:e8e403d61359 | 200 | * @details complements OWBlock, writes 'tran_len' bytes from |
j3 | 23:e8e403d61359 | 201 | * 'tran_buf' to 1-wire Net. |
j3 | 23:e8e403d61359 | 202 | * |
j3 | 23:e8e403d61359 | 203 | * On Entry: |
j3 | 23:e8e403d61359 | 204 | * @param[in] tran_buf - pointer to data to write |
j3 | 23:e8e403d61359 | 205 | * @param[in] tran_len - number of bytes to write |
j3 | 23:e8e403d61359 | 206 | * |
j3 | 23:e8e403d61359 | 207 | * On Exit: |
j3 | 23:e8e403d61359 | 208 | * |
j3 | 23:e8e403d61359 | 209 | **************************************************************/ |
IanBenzMaxim | 71:562f5c702094 | 210 | virtual CmdResult OWWriteBlock(const std::uint8_t *tran_buf, std::uint8_t tran_len); |
j3 | 23:e8e403d61359 | 211 | |
j3 | 15:f6cb0d906fb6 | 212 | |
j3 | 23:e8e403d61359 | 213 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 214 | * @brief OWReadBlock() |
j3 | 23:e8e403d61359 | 215 | * |
j3 | 23:e8e403d61359 | 216 | * @details complements OWBlock, reads 'recv_len' bytes from |
j3 | 23:e8e403d61359 | 217 | * 1-wire Net and puts them in 'recv_buf'. |
j3 | 23:e8e403d61359 | 218 | * |
j3 | 23:e8e403d61359 | 219 | * On Entry: |
j3 | 23:e8e403d61359 | 220 | * @param[in] recv_buf - pointer to receive buffer |
j3 | 23:e8e403d61359 | 221 | * @param[in] recv_len - number of bytes to read |
j3 | 23:e8e403d61359 | 222 | * |
j3 | 23:e8e403d61359 | 223 | * On Exit: |
IanBenzMaxim | 47:307dc45952db | 224 | * |
j3 | 23:e8e403d61359 | 225 | **************************************************************/ |
IanBenzMaxim | 71:562f5c702094 | 226 | virtual CmdResult OWReadBlock(std::uint8_t *rx_buf, std::uint8_t rx_len); |
j3 | 23:e8e403d61359 | 227 | |
j3 | 23:e8e403d61359 | 228 | |
j3 | 23:e8e403d61359 | 229 | /**********************************************************//** |
IanBenzMaxim | 32:bce180b544ed | 230 | * @brief OWSetSpeed() |
j3 | 23:e8e403d61359 | 231 | * |
j3 | 23:e8e403d61359 | 232 | * @details Set the 1-Wire Net communication speed. |
j3 | 23:e8e403d61359 | 233 | * |
j3 | 23:e8e403d61359 | 234 | * On Entry: |
j3 | 23:e8e403d61359 | 235 | * @param[in] 'new_speed' - new speed defined as |
j3 | 23:e8e403d61359 | 236 | * MODE_STANDARD 0x00 |
j3 | 23:e8e403d61359 | 237 | * MODE_OVERDRIVE 0x01 |
j3 | 23:e8e403d61359 | 238 | * |
j3 | 23:e8e403d61359 | 239 | * On Exit: |
j3 | 23:e8e403d61359 | 240 | * |
j3 | 23:e8e403d61359 | 241 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 242 | virtual CmdResult OWSetSpeed(OWSpeed new_speed) = 0; |
IanBenzMaxim | 32:bce180b544ed | 243 | |
j3 | 15:f6cb0d906fb6 | 244 | |
j3 | 23:e8e403d61359 | 245 | /**********************************************************//** |
IanBenzMaxim | 32:bce180b544ed | 246 | * @brief OWSetLevel() |
j3 | 23:e8e403d61359 | 247 | * |
j3 | 23:e8e403d61359 | 248 | * @details Set the 1-Wire Net line level pull-up to normal. The |
j3 | 23:e8e403d61359 | 249 | * ds2484 does only allows enabling strong pull-up on a |
j3 | 23:e8e403d61359 | 250 | * bit or byte event. Consequently this function only |
j3 | 23:e8e403d61359 | 251 | * allows the MODE_STANDARD argument. To enable strong |
j3 | 23:e8e403d61359 | 252 | * pull-up use OWWriteBytePower or OWReadBitPower. |
j3 | 23:e8e403d61359 | 253 | * |
j3 | 23:e8e403d61359 | 254 | * On Entry: |
j3 | 23:e8e403d61359 | 255 | * @param[in] 'new_level' - new level defined as |
j3 | 23:e8e403d61359 | 256 | * MODE_STANDARD 0x00 |
j3 | 23:e8e403d61359 | 257 | * |
j3 | 23:e8e403d61359 | 258 | * On Exit: |
j3 | 23:e8e403d61359 | 259 | * |
j3 | 23:e8e403d61359 | 260 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 261 | virtual CmdResult OWSetLevel(OWLevel new_level) = 0; |
IanBenzMaxim | 32:bce180b544ed | 262 | |
IanBenzMaxim | 32:bce180b544ed | 263 | |
IanBenzMaxim | 47:307dc45952db | 264 | /**********************************************************//** |
IanBenzMaxim | 47:307dc45952db | 265 | * @brief OWTriplet() |
IanBenzMaxim | 47:307dc45952db | 266 | * |
IanBenzMaxim | 47:307dc45952db | 267 | * @details Perform one bit of a 1-Wire search. This command |
IanBenzMaxim | 47:307dc45952db | 268 | * does two read bits and one write bit. The write bit is either |
IanBenzMaxim | 47:307dc45952db | 269 | * the default direction (all device have same bit) or in case |
IanBenzMaxim | 47:307dc45952db | 270 | * of a discrepancy, the 'search_direction' parameter is used. |
IanBenzMaxim | 47:307dc45952db | 271 | * |
IanBenzMaxim | 47:307dc45952db | 272 | * @param[in,out] search_direction |
IanBenzMaxim | 47:307dc45952db | 273 | * Input with desired direction in case both read bits are zero. |
IanBenzMaxim | 47:307dc45952db | 274 | * Output with direction taken based on read bits. |
IanBenzMaxim | 47:307dc45952db | 275 | * |
IanBenzMaxim | 47:307dc45952db | 276 | * @param[out] sbr Bit result of first read operation. |
IanBenzMaxim | 47:307dc45952db | 277 | * @param[out] tsb Bit result of second read operation. |
IanBenzMaxim | 47:307dc45952db | 278 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 279 | virtual CmdResult OWTriplet(SearchDirection & search_direction, std::uint8_t & sbr, std::uint8_t & tsb); |
IanBenzMaxim | 32:bce180b544ed | 280 | |
IanBenzMaxim | 48:6f9208ae280e | 281 | /// OWWriteBit() |
IanBenzMaxim | 72:6892702709ee | 282 | CmdResult OWWriteBitSetLevel(std::uint8_t sendbit, OWLevel after_level) { return OWTouchBitSetLevel(sendbit, after_level); } |
IanBenzMaxim | 32:bce180b544ed | 283 | |
IanBenzMaxim | 48:6f9208ae280e | 284 | /// OWReadBit() |
IanBenzMaxim | 72:6892702709ee | 285 | CmdResult OWReadBitSetLevel(std::uint8_t & recvbit, OWLevel after_level) { recvbit = 0x01; return OWTouchBitSetLevel(recvbit, after_level); } |
j3 | 23:e8e403d61359 | 286 | |
IanBenzMaxim | 48:6f9208ae280e | 287 | // Alternate forms of read and write functions |
IanBenzMaxim | 72:6892702709ee | 288 | CmdResult OWWriteBit(std::uint8_t sendbit) { return OWWriteBitSetLevel(sendbit, LEVEL_NORMAL); } |
IanBenzMaxim | 72:6892702709ee | 289 | CmdResult OWReadBit(std::uint8_t & recvbit) { return OWReadBitSetLevel(recvbit, LEVEL_NORMAL); } |
IanBenzMaxim | 72:6892702709ee | 290 | CmdResult OWWriteBitPower(std::uint8_t sendbit) { return OWWriteBitSetLevel(sendbit, LEVEL_STRONG); } |
IanBenzMaxim | 72:6892702709ee | 291 | CmdResult OWReadBitPower(std::uint8_t & recvbit) { return OWReadBitSetLevel(recvbit, LEVEL_STRONG); } |
IanBenzMaxim | 72:6892702709ee | 292 | CmdResult OWWriteByte(std::uint8_t sendbyte) { return OWWriteByteSetLevel(sendbyte, LEVEL_NORMAL); } |
IanBenzMaxim | 72:6892702709ee | 293 | CmdResult OWReadByte(std::uint8_t & recvbyte) { return OWReadByteSetLevel(recvbyte, LEVEL_NORMAL); } |
IanBenzMaxim | 72:6892702709ee | 294 | CmdResult OWWriteBytePower(std::uint8_t sendbyte) { return OWWriteByteSetLevel(sendbyte, LEVEL_STRONG); } |
IanBenzMaxim | 72:6892702709ee | 295 | CmdResult OWReadBytePower(std::uint8_t & recvbyte) { return OWReadByteSetLevel(recvbyte, LEVEL_STRONG); } |
j3 | 23:e8e403d61359 | 296 | |
j3 | 23:e8e403d61359 | 297 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 298 | * @brief OWFirst() |
j3 | 23:e8e403d61359 | 299 | * |
j3 | 23:e8e403d61359 | 300 | * @details Find the 'first' devices on the 1-Wire network |
j3 | 23:e8e403d61359 | 301 | * |
j3 | 23:e8e403d61359 | 302 | * On Entry: |
j3 | 23:e8e403d61359 | 303 | * |
j3 | 23:e8e403d61359 | 304 | * On Exit: |
j3 | 23:e8e403d61359 | 305 | * |
j3 | 23:e8e403d61359 | 306 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 307 | CmdResult OWFirst(SearchState & searchState); |
j3 | 23:e8e403d61359 | 308 | |
j3 | 23:e8e403d61359 | 309 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 310 | * @brief OWNext() |
j3 | 23:e8e403d61359 | 311 | * |
j3 | 23:e8e403d61359 | 312 | * @details Find the 'next' devices on the 1-Wire network |
j3 | 23:e8e403d61359 | 313 | * |
j3 | 23:e8e403d61359 | 314 | * On Entry: |
j3 | 23:e8e403d61359 | 315 | * |
j3 | 23:e8e403d61359 | 316 | * On Exit: |
j3 | 23:e8e403d61359 | 317 | * |
j3 | 23:e8e403d61359 | 318 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 319 | CmdResult OWNext(SearchState & searchState); |
j3 | 23:e8e403d61359 | 320 | |
j3 | 23:e8e403d61359 | 321 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 322 | * @brief OWVerify() |
j3 | 23:e8e403d61359 | 323 | * |
j3 | 23:e8e403d61359 | 324 | * @details Verify the device with the ROM number in ROM_NO buffer |
j3 | 23:e8e403d61359 | 325 | * is present. |
j3 | 23:e8e403d61359 | 326 | * |
j3 | 23:e8e403d61359 | 327 | * On Entry: |
j3 | 23:e8e403d61359 | 328 | * |
j3 | 23:e8e403d61359 | 329 | * On Exit: |
j3 | 23:e8e403d61359 | 330 | * |
j3 | 23:e8e403d61359 | 331 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 332 | CmdResult OWVerify(const RomId & romId); |
j3 | 23:e8e403d61359 | 333 | |
j3 | 23:e8e403d61359 | 334 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 335 | * @brief OWTargetSetup() |
j3 | 23:e8e403d61359 | 336 | * |
j3 | 23:e8e403d61359 | 337 | * @details Setup the search to find the device type 'family_code' |
j3 | 23:e8e403d61359 | 338 | * on the next call to OWNext() if it is present. |
j3 | 23:e8e403d61359 | 339 | * |
j3 | 23:e8e403d61359 | 340 | * On Entry: |
j3 | 23:e8e403d61359 | 341 | * @param[in] family_code - family code of device |
j3 | 23:e8e403d61359 | 342 | * |
j3 | 23:e8e403d61359 | 343 | * On Exit: |
j3 | 23:e8e403d61359 | 344 | * |
j3 | 23:e8e403d61359 | 345 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 346 | void OWTargetSetup(SearchState & searchState); |
j3 | 23:e8e403d61359 | 347 | |
j3 | 23:e8e403d61359 | 348 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 349 | * @brief OWFamilySkipSetup() |
j3 | 23:e8e403d61359 | 350 | * |
j3 | 23:e8e403d61359 | 351 | * @details Setup the search to skip the current device type on the |
j3 | 23:e8e403d61359 | 352 | * next call to OWNext(). |
j3 | 23:e8e403d61359 | 353 | * |
j3 | 23:e8e403d61359 | 354 | * On Entry: |
j3 | 23:e8e403d61359 | 355 | * |
j3 | 23:e8e403d61359 | 356 | * On Exit: |
j3 | 23:e8e403d61359 | 357 | * |
j3 | 23:e8e403d61359 | 358 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 359 | void OWFamilySkipSetup(SearchState & searchState); |
j3 | 15:f6cb0d906fb6 | 360 | |
j3 | 23:e8e403d61359 | 361 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 362 | * @brief OWReadROM() |
j3 | 23:e8e403d61359 | 363 | * |
j3 | 23:e8e403d61359 | 364 | * @details Only use this command with a single drop bus, data |
j3 | 23:e8e403d61359 | 365 | * collisions will occur if more than 1 device on bus. |
j3 | 23:e8e403d61359 | 366 | * Issues READ_ROM command, slave device will respond with ROM ID. |
j3 | 23:e8e403d61359 | 367 | * |
j3 | 23:e8e403d61359 | 368 | * On Entry: |
j3 | 23:e8e403d61359 | 369 | * |
j3 | 23:e8e403d61359 | 370 | * On Exit: |
j3 | 23:e8e403d61359 | 371 | * |
j3 | 23:e8e403d61359 | 372 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 373 | CmdResult OWReadROM(RomId & romId); |
j3 | 23:e8e403d61359 | 374 | |
j3 | 23:e8e403d61359 | 375 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 376 | * @brief OWSkipROM() |
j3 | 23:e8e403d61359 | 377 | * |
j3 | 23:e8e403d61359 | 378 | * @details Issue SKIP_ROM command on 1-wire bus |
j3 | 23:e8e403d61359 | 379 | * |
j3 | 23:e8e403d61359 | 380 | * On Entry: |
j3 | 23:e8e403d61359 | 381 | * |
j3 | 23:e8e403d61359 | 382 | * On Exit: |
j3 | 23:e8e403d61359 | 383 | * |
j3 | 23:e8e403d61359 | 384 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 385 | CmdResult OWSkipROM(void); |
j3 | 23:e8e403d61359 | 386 | |
j3 | 23:e8e403d61359 | 387 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 388 | * @brief OWMatchROM() |
j3 | 23:e8e403d61359 | 389 | * |
j3 | 23:e8e403d61359 | 390 | * @details Issues MATCH_ROM command on 1-wire bus and then sends |
j3 | 23:e8e403d61359 | 391 | * the rom id in _rom_number |
j3 | 23:e8e403d61359 | 392 | * |
j3 | 23:e8e403d61359 | 393 | * On Entry: |
j3 | 23:e8e403d61359 | 394 | * |
j3 | 23:e8e403d61359 | 395 | * On Exit: |
j3 | 23:e8e403d61359 | 396 | * |
j3 | 23:e8e403d61359 | 397 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 398 | CmdResult OWMatchROM(const RomId & romId); |
j3 | 23:e8e403d61359 | 399 | |
j3 | 23:e8e403d61359 | 400 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 401 | * @brief OWOverdriveSkipROM() |
j3 | 23:e8e403d61359 | 402 | * |
j3 | 23:e8e403d61359 | 403 | * @details Issues OVERDRIVE_SKIP rom command. DS248X OW speed |
j3 | 23:e8e403d61359 | 404 | * is set to SPEED_OVERDRIVE |
j3 | 23:e8e403d61359 | 405 | * |
j3 | 23:e8e403d61359 | 406 | * On Entry: |
j3 | 23:e8e403d61359 | 407 | * |
j3 | 23:e8e403d61359 | 408 | * On Exit: |
j3 | 23:e8e403d61359 | 409 | * |
j3 | 23:e8e403d61359 | 410 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 411 | CmdResult OWOverdriveSkipROM(void); |
j3 | 15:f6cb0d906fb6 | 412 | |
j3 | 23:e8e403d61359 | 413 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 414 | * @brief OWOverdriveMatchROM() |
j3 | 23:e8e403d61359 | 415 | * |
j3 | 23:e8e403d61359 | 416 | * @details Issues OVERDRIVE_MATCH rom command. DS248X OW speed |
j3 | 23:e8e403d61359 | 417 | * is set to SPEED_OVERDRIVE |
j3 | 23:e8e403d61359 | 418 | * |
j3 | 23:e8e403d61359 | 419 | * On Entry: |
j3 | 23:e8e403d61359 | 420 | * |
j3 | 23:e8e403d61359 | 421 | * On Exit: |
j3 | 23:e8e403d61359 | 422 | * |
j3 | 23:e8e403d61359 | 423 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 424 | CmdResult OWOverdriveMatchROM(const RomId & romId); |
j3 | 23:e8e403d61359 | 425 | |
j3 | 23:e8e403d61359 | 426 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 427 | * @brief OWResume() |
j3 | 23:e8e403d61359 | 428 | * |
j3 | 23:e8e403d61359 | 429 | * @details Issues RESUME command, very usefull. Is like skip |
j3 | 23:e8e403d61359 | 430 | * on a multidrop bus, however you must first select the device |
j3 | 23:e8e403d61359 | 431 | * you want to interface with using a MATCH, or SEARCH. The |
j3 | 23:e8e403d61359 | 432 | * device stays selected until another device is selected, |
j3 | 23:e8e403d61359 | 433 | * see slave datasheet for detailed explanation. |
j3 | 23:e8e403d61359 | 434 | * |
j3 | 23:e8e403d61359 | 435 | * On Entry: |
j3 | 23:e8e403d61359 | 436 | * |
j3 | 23:e8e403d61359 | 437 | * On Exit: |
j3 | 23:e8e403d61359 | 438 | * |
j3 | 23:e8e403d61359 | 439 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 440 | CmdResult OWResume(void); |
IanBenzMaxim | 21:00c94aeb533e | 441 | |
IanBenzMaxim | 32:bce180b544ed | 442 | /**********************************************************//** |
IanBenzMaxim | 32:bce180b544ed | 443 | * @brief OWSearch() |
IanBenzMaxim | 32:bce180b544ed | 444 | * |
IanBenzMaxim | 32:bce180b544ed | 445 | * @details The 'OWSearch' function does a general search. This |
IanBenzMaxim | 32:bce180b544ed | 446 | * function continues from the previous search state. The |
IanBenzMaxim | 32:bce180b544ed | 447 | * search state can be reset by using the 'OWFirst' |
IanBenzMaxim | 32:bce180b544ed | 448 | * function. This function contains one parameter |
IanBenzMaxim | 32:bce180b544ed | 449 | * 'alarm_only'. When 'alarm_only' is TRUE (1) the find |
IanBenzMaxim | 32:bce180b544ed | 450 | * alarm command 0xEC is sent instead of the normal search |
IanBenzMaxim | 32:bce180b544ed | 451 | * command 0xF0. Using the find alarm command 0xEC will |
IanBenzMaxim | 32:bce180b544ed | 452 | * limit the search to only 1-Wire devices that are in an |
IanBenzMaxim | 32:bce180b544ed | 453 | * 'alarm' state. |
IanBenzMaxim | 32:bce180b544ed | 454 | * |
IanBenzMaxim | 32:bce180b544ed | 455 | * On Entry: |
IanBenzMaxim | 32:bce180b544ed | 456 | * |
IanBenzMaxim | 32:bce180b544ed | 457 | * On Exit: |
IanBenzMaxim | 32:bce180b544ed | 458 | * |
IanBenzMaxim | 32:bce180b544ed | 459 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 460 | CmdResult OWSearch(SearchState & searchState); |
j3 | 15:f6cb0d906fb6 | 461 | }; |
j3 | 15:f6cb0d906fb6 | 462 | |
IanBenzMaxim | 47:307dc45952db | 463 | #endif /*ONEWIREMASTER_H*/ |