Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
j3
Date:
Sat Jan 30 23:00:57 2016 +0000
Revision:
1:91e52f8ab8bf
Child:
2:02d228c25fd4
init commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 1:91e52f8ab8bf 1 /******************************************************************//**
j3 1:91e52f8ab8bf 2 * @file ds248x.h
j3 1:91e52f8ab8bf 3 *
j3 1:91e52f8ab8bf 4 * @author Justin Jordan
j3 1:91e52f8ab8bf 5 *
j3 1:91e52f8ab8bf 6 * @version 0.0.0
j3 1:91e52f8ab8bf 7 *
j3 1:91e52f8ab8bf 8 * Started: 30JAN16
j3 1:91e52f8ab8bf 9 *
j3 1:91e52f8ab8bf 10 * Updated:
j3 1:91e52f8ab8bf 11 *
j3 1:91e52f8ab8bf 12 * @brief Header file for Ds248x I2C to 1-wire master
j3 1:91e52f8ab8bf 13 ***********************************************************************
j3 1:91e52f8ab8bf 14 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 1:91e52f8ab8bf 15 *
j3 1:91e52f8ab8bf 16 * Permission is hereby granted, free of charge, to any person obtaining a
j3 1:91e52f8ab8bf 17 * copy of this software and associated documentation files (the "Software"),
j3 1:91e52f8ab8bf 18 * to deal in the Software without restriction, including without limitation
j3 1:91e52f8ab8bf 19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 1:91e52f8ab8bf 20 * and/or sell copies of the Software, and to permit persons to whom the
j3 1:91e52f8ab8bf 21 * Software is furnished to do so, subject to the following conditions:
j3 1:91e52f8ab8bf 22 *
j3 1:91e52f8ab8bf 23 * The above copyright notice and this permission notice shall be included
j3 1:91e52f8ab8bf 24 * in all copies or substantial portions of the Software.
j3 1:91e52f8ab8bf 25 *
j3 1:91e52f8ab8bf 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 1:91e52f8ab8bf 27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 1:91e52f8ab8bf 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 1:91e52f8ab8bf 29 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 1:91e52f8ab8bf 30 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 1:91e52f8ab8bf 31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 1:91e52f8ab8bf 32 * OTHER DEALINGS IN THE SOFTWARE.
j3 1:91e52f8ab8bf 33 *
j3 1:91e52f8ab8bf 34 * Except as contained in this notice, the name of Maxim Integrated
j3 1:91e52f8ab8bf 35 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 1:91e52f8ab8bf 36 * Products, Inc. Branding Policy.
j3 1:91e52f8ab8bf 37 *
j3 1:91e52f8ab8bf 38 * The mere transfer of this software does not imply any licenses
j3 1:91e52f8ab8bf 39 * of trade secrets, proprietary technology, copyrights, patents,
j3 1:91e52f8ab8bf 40 * trademarks, maskwork rights, or any other form of intellectual
j3 1:91e52f8ab8bf 41 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 1:91e52f8ab8bf 42 * ownership rights.
j3 1:91e52f8ab8bf 43 **********************************************************************/
j3 1:91e52f8ab8bf 44
j3 1:91e52f8ab8bf 45
j3 1:91e52f8ab8bf 46 #ifndef DS248X_H
j3 1:91e52f8ab8bf 47 #define DS248X_H
j3 1:91e52f8ab8bf 48
j3 1:91e52f8ab8bf 49
j3 1:91e52f8ab8bf 50 #include "mbed.h"
j3 1:91e52f8ab8bf 51 #include "OneWireInterface.h"
j3 1:91e52f8ab8bf 52
j3 1:91e52f8ab8bf 53
j3 1:91e52f8ab8bf 54 class Ds248x: public OneWireInterface
j3 1:91e52f8ab8bf 55 {
j3 1:91e52f8ab8bf 56 public:
j3 1:91e52f8ab8bf 57
j3 1:91e52f8ab8bf 58 typedef enum
j3 1:91e52f8ab8bf 59 {
j3 1:91e52f8ab8bf 60 DS248X_I2C_ADRS0 = 0x18,
j3 1:91e52f8ab8bf 61 DS248X_I2C_ADRS1,
j3 1:91e52f8ab8bf 62 DS248X_I2C_ADRS2,
j3 1:91e52f8ab8bf 63 DS248X_I2C_ADRS3,
j3 1:91e52f8ab8bf 64 DS248X_I2C_ADRS4,
j3 1:91e52f8ab8bf 65 DS248X_I2C_ADRS5,
j3 1:91e52f8ab8bf 66 DS248X_I2C_ADRS6,
j3 1:91e52f8ab8bf 67 DS248X_I2C_ADRS7,
j3 1:91e52f8ab8bf 68 }
j3 1:91e52f8ab8bf 69 ds248x_i2c_adrs_t
j3 1:91e52f8ab8bf 70
j3 1:91e52f8ab8bf 71 /**********************************************************//**
j3 1:91e52f8ab8bf 72 * @brief Ds248x constructor
j3 1:91e52f8ab8bf 73 *
j3 1:91e52f8ab8bf 74 * @details allows user to use existing I2C object
j3 1:91e52f8ab8bf 75 *
j3 1:91e52f8ab8bf 76 * On Entry:
j3 1:91e52f8ab8bf 77 * @param[in] p_i2c_bus - pointer to existing I2C object
j3 1:91e52f8ab8bf 78 *
j3 1:91e52f8ab8bf 79 * On Exit:
j3 1:91e52f8ab8bf 80 * @return
j3 1:91e52f8ab8bf 81 **************************************************************/
j3 1:91e52f8ab8bf 82 Ds248x(I2C *p_i2c_bus, ds248x_i2c_adrs_t adrs);
j3 1:91e52f8ab8bf 83
j3 1:91e52f8ab8bf 84
j3 1:91e52f8ab8bf 85 /**********************************************************//**
j3 1:91e52f8ab8bf 86 * @brief Ds248x constructor
j3 1:91e52f8ab8bf 87 *
j3 1:91e52f8ab8bf 88 * @details allows user to use existing I2C object
j3 1:91e52f8ab8bf 89 *
j3 1:91e52f8ab8bf 90 * On Entry:
j3 1:91e52f8ab8bf 91 * @param[in] sda - sda pin of I2C bus
j3 1:91e52f8ab8bf 92 * @param[in] scl - scl pin of I2C bus
j3 1:91e52f8ab8bf 93 *
j3 1:91e52f8ab8bf 94 * On Exit:
j3 1:91e52f8ab8bf 95 * @return
j3 1:91e52f8ab8bf 96 **************************************************************/
j3 1:91e52f8ab8bf 97 Ds248x(PinName sda, PinName scl, ds248x_i2c_adrs_t adrs);
j3 1:91e52f8ab8bf 98
j3 1:91e52f8ab8bf 99
j3 1:91e52f8ab8bf 100 /**********************************************************//**
j3 1:91e52f8ab8bf 101 * @brief Ds248x destructor
j3 1:91e52f8ab8bf 102 *
j3 1:91e52f8ab8bf 103 * @details deletes I2C object if owner
j3 1:91e52f8ab8bf 104 *
j3 1:91e52f8ab8bf 105 * On Entry:
j3 1:91e52f8ab8bf 106 *
j3 1:91e52f8ab8bf 107 * On Exit:
j3 1:91e52f8ab8bf 108 * @return
j3 1:91e52f8ab8bf 109 **************************************************************/
j3 1:91e52f8ab8bf 110 ~Ds248x();
j3 1:91e52f8ab8bf 111
j3 1:91e52f8ab8bf 112
j3 1:91e52f8ab8bf 113 /**********************************************************//**
j3 1:91e52f8ab8bf 114 * @brief detect()
j3 1:91e52f8ab8bf 115 *
j3 1:91e52f8ab8bf 116 * @details Detect routine that performs a device reset
j3 1:91e52f8ab8bf 117 * followed by writing the configuration byte to default
j3 1:91e52f8ab8bf 118 * values:
j3 1:91e52f8ab8bf 119 * 1-Wire speed (c1WS) = standard (0)
j3 1:91e52f8ab8bf 120 * Strong pull-up (cSPU) = off (0)
j3 1:91e52f8ab8bf 121 * Presence pulse masking (cPPM) = off (0)
j3 1:91e52f8ab8bf 122 * Active pull-up (cAPU) = on (CONFIG_APU = 0x01)
j3 1:91e52f8ab8bf 123 *
j3 1:91e52f8ab8bf 124 * On Entry:
j3 1:91e52f8ab8bf 125 *
j3 1:91e52f8ab8bf 126 * On Exit:
j3 1:91e52f8ab8bf 127 * @return TRUE if device was detected and written
j3 1:91e52f8ab8bf 128 * FALSE device not detected or failure to write
j3 1:91e52f8ab8bf 129 * configuration byte
j3 1:91e52f8ab8bf 130 **************************************************************/
j3 1:91e52f8ab8bf 131 uint8_t detect(void);
j3 1:91e52f8ab8bf 132
j3 1:91e52f8ab8bf 133
j3 1:91e52f8ab8bf 134 /**********************************************************//**
j3 1:91e52f8ab8bf 135 * @brief reset()
j3 1:91e52f8ab8bf 136 *
j3 1:91e52f8ab8bf 137 * @details Perform a device reset on the Ds248x
j3 1:91e52f8ab8bf 138 *
j3 1:91e52f8ab8bf 139 * On Entry:
j3 1:91e52f8ab8bf 140 *
j3 1:91e52f8ab8bf 141 * On Exit:
j3 1:91e52f8ab8bf 142 * @return TRUE if device was reset
j3 1:91e52f8ab8bf 143 * FALSE device not detected or failure to perform reset
j3 1:91e52f8ab8bf 144 **************************************************************/
j3 1:91e52f8ab8bf 145 uint8_t reset(void);
j3 1:91e52f8ab8bf 146
j3 1:91e52f8ab8bf 147
j3 1:91e52f8ab8bf 148 /**********************************************************//**
j3 1:91e52f8ab8bf 149 * @brief write_config()
j3 1:91e52f8ab8bf 150 *
j3 1:91e52f8ab8bf 151 * @details Write the configuration register in the Ds248x. The
j3 1:91e52f8ab8bf 152 * configuration options are provided in the lower nibble
j3 1:91e52f8ab8bf 153 * of the provided config byte. The uppper nibble is
j3 1:91e52f8ab8bf 154 * bitwise inverted when written to the Ds248x.
j3 1:91e52f8ab8bf 155 *
j3 1:91e52f8ab8bf 156 * On Entry:
j3 1:91e52f8ab8bf 157 * @param[in] config - lower nib of configuration register
j3 1:91e52f8ab8bf 158 *
j3 1:91e52f8ab8bf 159 * On Exit:
j3 1:91e52f8ab8bf 160 * @return TRUE: config written and response correct
j3 1:91e52f8ab8bf 161 * FALSE: response incorrect
j3 1:91e52f8ab8bf 162 **************************************************************/
j3 1:91e52f8ab8bf 163 uint8_t write_config(uint8_t config);
j3 1:91e52f8ab8bf 164
j3 1:91e52f8ab8bf 165
j3 1:91e52f8ab8bf 166 /**********************************************************//**
j3 1:91e52f8ab8bf 167 * @brief adjust_timing()
j3 1:91e52f8ab8bf 168 *
j3 1:91e52f8ab8bf 169 * @details
j3 1:91e52f8ab8bf 170 *
j3 1:91e52f8ab8bf 171 * On Entry:
j3 1:91e52f8ab8bf 172 * @param[in] param - 1 of 8 adjustable parameters
j3 1:91e52f8ab8bf 173 * @param[in] val - new value for parameter, see datasheet
j3 1:91e52f8ab8bf 174 * for codes
j3 1:91e52f8ab8bf 175 *
j3 1:91e52f8ab8bf 176 * On Exit:
j3 1:91e52f8ab8bf 177 * @return TRUE: parameter successfully adjusted
j3 1:91e52f8ab8bf 178 * FALSE: failed to adjust parameter
j3 1:91e52f8ab8bf 179 **************************************************************/
j3 1:91e52f8ab8bf 180 uint8_t adjust_timing(uint8_t param, uint8_t val);
j3 1:91e52f8ab8bf 181
j3 1:91e52f8ab8bf 182
j3 1:91e52f8ab8bf 183 /**********************************************************//**
j3 1:91e52f8ab8bf 184 * @brief search_triplet()
j3 1:91e52f8ab8bf 185 *
j3 1:91e52f8ab8bf 186 * @details Use the Ds248x help command '1-Wire triplet' to perform
j3 1:91e52f8ab8bf 187 * one bit of a 1-Wire search. This command does two read
j3 1:91e52f8ab8bf 188 * bits and one write bit. The write bit is either the
j3 1:91e52f8ab8bf 189 * default direction (all device have same bit) or in case
j3 1:91e52f8ab8bf 190 * of a discrepancy, the 'search_direction' parameter is
j3 1:91e52f8ab8bf 191 * used.
j3 1:91e52f8ab8bf 192 *
j3 1:91e52f8ab8bf 193 * On Entry:
j3 1:91e52f8ab8bf 194 * @param[in] search_direction
j3 1:91e52f8ab8bf 195 *
j3 1:91e52f8ab8bf 196 * On Exit:
j3 1:91e52f8ab8bf 197 * @return The Ds248x status byte result from the triplet command
j3 1:91e52f8ab8bf 198 **************************************************************/
j3 1:91e52f8ab8bf 199 uint8_t search_triplet(uint8_t search_direction);
j3 1:91e52f8ab8bf 200
j3 1:91e52f8ab8bf 201
j3 1:91e52f8ab8bf 202 /**********************************************************//**
j3 1:91e52f8ab8bf 203 * @brief Reset all of the devices on the 1-Wire Net and return
j3 1:91e52f8ab8bf 204 * the result.
j3 1:91e52f8ab8bf 205 *
j3 1:91e52f8ab8bf 206 * @details
j3 1:91e52f8ab8bf 207 *
j3 1:91e52f8ab8bf 208 * On Entry:
j3 1:91e52f8ab8bf 209 *
j3 1:91e52f8ab8bf 210 * On Exit:
j3 1:91e52f8ab8bf 211 * @return TRUE(1): presence pulse(s) detected, device(s) reset
j3 1:91e52f8ab8bf 212 * FALSE(0): no presence pulses detected
j3 1:91e52f8ab8bf 213 **************************************************************/
j3 1:91e52f8ab8bf 214 virtual uint8_t OWReset();
j3 1:91e52f8ab8bf 215
j3 1:91e52f8ab8bf 216
j3 1:91e52f8ab8bf 217 /**********************************************************//**
j3 1:91e52f8ab8bf 218 * @brief Send 1 bit of communication to the 1-Wire Net.
j3 1:91e52f8ab8bf 219 * The parameter 'sendbit' least significant bit is used.
j3 1:91e52f8ab8bf 220 *
j3 1:91e52f8ab8bf 221 * @details
j3 1:91e52f8ab8bf 222 *
j3 1:91e52f8ab8bf 223 * On Entry:
j3 1:91e52f8ab8bf 224 * @param[in] 'sendbit' - 1 bit to send (least significant byte)
j3 1:91e52f8ab8bf 225 *
j3 1:91e52f8ab8bf 226 * On Exit:
j3 1:91e52f8ab8bf 227 * @return
j3 1:91e52f8ab8bf 228 **************************************************************/
j3 1:91e52f8ab8bf 229 virtual void OWWriteBit(uint8_t sendbit);
j3 1:91e52f8ab8bf 230
j3 1:91e52f8ab8bf 231
j3 1:91e52f8ab8bf 232 /**********************************************************//**
j3 1:91e52f8ab8bf 233 * @brief Reads 1 bit of communication from the 1-Wire Net and
j3 1:91e52f8ab8bf 234 * returns the result
j3 1:91e52f8ab8bf 235 *
j3 1:91e52f8ab8bf 236 * @details
j3 1:91e52f8ab8bf 237 *
j3 1:91e52f8ab8bf 238 * On Entry:
j3 1:91e52f8ab8bf 239 *
j3 1:91e52f8ab8bf 240 * On Exit:
j3 1:91e52f8ab8bf 241 * @return 1 bit read from 1-Wire Net
j3 1:91e52f8ab8bf 242 **************************************************************/
j3 1:91e52f8ab8bf 243 virtual uint8_t OWReadBit();
j3 1:91e52f8ab8bf 244
j3 1:91e52f8ab8bf 245
j3 1:91e52f8ab8bf 246 /**********************************************************//**
j3 1:91e52f8ab8bf 247 * @brief Send 1 bit of communication to the 1-Wire Net and return
j3 1:91e52f8ab8bf 248 * the result 1 bit read from the 1-Wire Net. The
j3 1:91e52f8ab8bf 249 * parameter 'sendbit' least significant bit is used and
j3 1:91e52f8ab8bf 250 * the least significant bit of the result is the return
j3 1:91e52f8ab8bf 251 * bit.
j3 1:91e52f8ab8bf 252 *
j3 1:91e52f8ab8bf 253 * @details
j3 1:91e52f8ab8bf 254 *
j3 1:91e52f8ab8bf 255 * On Entry:
j3 1:91e52f8ab8bf 256 * @param[in] 'sendbit' - the least significant bit is the bit to send
j3 1:91e52f8ab8bf 257 *
j3 1:91e52f8ab8bf 258 * On Exit:
j3 1:91e52f8ab8bf 259 * @return 0: 0 bit read from sendbit
j3 1:91e52f8ab8bf 260 * 1: 1 bit read from sendbit
j3 1:91e52f8ab8bf 261 **************************************************************/
j3 1:91e52f8ab8bf 262 virtual uint8_t OWTouchBit(uint8_t sendbit);
j3 1:91e52f8ab8bf 263
j3 1:91e52f8ab8bf 264
j3 1:91e52f8ab8bf 265 /**********************************************************//**
j3 1:91e52f8ab8bf 266 * @brief Send 8 bits of communication to the 1-Wire Net and
j3 1:91e52f8ab8bf 267 * verify that the 8 bits read from the 1-Wire Net is the
j3 1:91e52f8ab8bf 268 * same (write operation).The parameter 'sendbyte' least
j3 1:91e52f8ab8bf 269 * significant 8 bits are used.
j3 1:91e52f8ab8bf 270 *
j3 1:91e52f8ab8bf 271 * @details
j3 1:91e52f8ab8bf 272 *
j3 1:91e52f8ab8bf 273 * On Entry:
j3 1:91e52f8ab8bf 274 * @param[in] 'sendbyte' - 8 bits to send (least significant byte)
j3 1:91e52f8ab8bf 275 *
j3 1:91e52f8ab8bf 276 * On Exit:
j3 1:91e52f8ab8bf 277 * @return TRUE: bytes written and echo was the same
j3 1:91e52f8ab8bf 278 * FALSE: echo was not the same
j3 1:91e52f8ab8bf 279 **************************************************************/
j3 1:91e52f8ab8bf 280 virtual void OWWRiteByte(uint8_t sendbyte);
j3 1:91e52f8ab8bf 281
j3 1:91e52f8ab8bf 282
j3 1:91e52f8ab8bf 283 /**********************************************************//**
j3 1:91e52f8ab8bf 284 * @brief Send 8 bits of read communication to the 1-Wire Net and
j3 1:91e52f8ab8bf 285 * return the result 8 bits read from the 1-Wire Net.
j3 1:91e52f8ab8bf 286 *
j3 1:91e52f8ab8bf 287 * @details
j3 1:91e52f8ab8bf 288 *
j3 1:91e52f8ab8bf 289 * On Entry:
j3 1:91e52f8ab8bf 290 *
j3 1:91e52f8ab8bf 291 * On Exit:
j3 1:91e52f8ab8bf 292 * @return 8 bits read from 1-Wire Net
j3 1:91e52f8ab8bf 293 **************************************************************/
j3 1:91e52f8ab8bf 294 virtual uint8_t OWReadByte(void);
j3 1:91e52f8ab8bf 295
j3 1:91e52f8ab8bf 296
j3 1:91e52f8ab8bf 297 /**********************************************************//**
j3 1:91e52f8ab8bf 298 * @brief Send 8 bits of communication to the 1-Wire Net and
j3 1:91e52f8ab8bf 299 * return the result 8 bits read from the 1-Wire Net. The
j3 1:91e52f8ab8bf 300 * parameter 'sendbyte' least significant 8 bits are used
j3 1:91e52f8ab8bf 301 * and the least significant 8 bits of the result is the
j3 1:91e52f8ab8bf 302 * return byte.
j3 1:91e52f8ab8bf 303 *
j3 1:91e52f8ab8bf 304 * @details
j3 1:91e52f8ab8bf 305 *
j3 1:91e52f8ab8bf 306 * On Entry:
j3 1:91e52f8ab8bf 307 * @param[in] 'sendbyte' - 8 bits to send (least significant byte)
j3 1:91e52f8ab8bf 308 *
j3 1:91e52f8ab8bf 309 * On Exit:
j3 1:91e52f8ab8bf 310 * @return 8 bits read from sendbyte
j3 1:91e52f8ab8bf 311 **************************************************************/
j3 1:91e52f8ab8bf 312 virtual uint8_t OWTouchByte(uint8_t sendbyte);
j3 1:91e52f8ab8bf 313
j3 1:91e52f8ab8bf 314
j3 1:91e52f8ab8bf 315 /**********************************************************//**
j3 1:91e52f8ab8bf 316 * @brief The 'OWBlock' transfers a block of data to and from the
j3 1:91e52f8ab8bf 317 * 1-Wire Net. The result is returned in the same buffer.
j3 1:91e52f8ab8bf 318 *
j3 1:91e52f8ab8bf 319 * @details
j3 1:91e52f8ab8bf 320 *
j3 1:91e52f8ab8bf 321 * On Entry:
j3 1:91e52f8ab8bf 322 * @param[in] 'tran_buf' - pointer to a block of unsigned
j3 1:91e52f8ab8bf 323 * chars of length 'tran_len' that
j3 1:91e52f8ab8bf 324 * will be sent to the 1-Wire Net
j3 1:91e52f8ab8bf 325 * @param[in] 'tran_len' - length in bytes to transfer
j3 1:91e52f8ab8bf 326 *
j3 1:91e52f8ab8bf 327 * On Exit:
j3 1:91e52f8ab8bf 328 * @return
j3 1:91e52f8ab8bf 329 **************************************************************/
j3 1:91e52f8ab8bf 330 virtual void OWBlock(uint8_t *tran_buf, uint8_t tran_len);
j3 1:91e52f8ab8bf 331
j3 1:91e52f8ab8bf 332
j3 1:91e52f8ab8bf 333 /**********************************************************//**
j3 1:91e52f8ab8bf 334 * @brief Find the 'first' devices on the 1-Wire network
j3 1:91e52f8ab8bf 335 *
j3 1:91e52f8ab8bf 336 * @details
j3 1:91e52f8ab8bf 337 *
j3 1:91e52f8ab8bf 338 * On Entry:
j3 1:91e52f8ab8bf 339 *
j3 1:91e52f8ab8bf 340 * On Exit:
j3 1:91e52f8ab8bf 341 * @return TRUE : device found, ROM number in ROM_NO buffer
j3 1:91e52f8ab8bf 342 * FALSE : no device present
j3 1:91e52f8ab8bf 343 **************************************************************/
j3 1:91e52f8ab8bf 344 virtual void OWFirst(void);
j3 1:91e52f8ab8bf 345
j3 1:91e52f8ab8bf 346
j3 1:91e52f8ab8bf 347 /**********************************************************//**
j3 1:91e52f8ab8bf 348 * @brief Find the 'next' devices on the 1-Wire network
j3 1:91e52f8ab8bf 349 *
j3 1:91e52f8ab8bf 350 * @details
j3 1:91e52f8ab8bf 351 *
j3 1:91e52f8ab8bf 352 * On Entry:
j3 1:91e52f8ab8bf 353 *
j3 1:91e52f8ab8bf 354 * On Exit:
j3 1:91e52f8ab8bf 355 * @return TRUE : device found, ROM number in ROM_NO buffer
j3 1:91e52f8ab8bf 356 * FALSE : device not found, end of search
j3 1:91e52f8ab8bf 357 **************************************************************/
j3 1:91e52f8ab8bf 358 virtual uint8_t OWNext(void);
j3 1:91e52f8ab8bf 359
j3 1:91e52f8ab8bf 360
j3 1:91e52f8ab8bf 361 /**********************************************************//**
j3 1:91e52f8ab8bf 362 * @brief Verify the device with the ROM number in ROM_NO buffer
j3 1:91e52f8ab8bf 363 * is present.
j3 1:91e52f8ab8bf 364 *
j3 1:91e52f8ab8bf 365 * @details
j3 1:91e52f8ab8bf 366 *
j3 1:91e52f8ab8bf 367 * On Entry:
j3 1:91e52f8ab8bf 368 *
j3 1:91e52f8ab8bf 369 * On Exit:
j3 1:91e52f8ab8bf 370 * @return TRUE : device verified present
j3 1:91e52f8ab8bf 371 * FALSE : device not present
j3 1:91e52f8ab8bf 372 **************************************************************/
j3 1:91e52f8ab8bf 373 virtual uint8_t OWVerify(void);
j3 1:91e52f8ab8bf 374
j3 1:91e52f8ab8bf 375
j3 1:91e52f8ab8bf 376 /**********************************************************//**
j3 1:91e52f8ab8bf 377 * @brief Setup the search to find the device type 'family_code'
j3 1:91e52f8ab8bf 378 * on the next call to OWNext() if it is present.
j3 1:91e52f8ab8bf 379 *
j3 1:91e52f8ab8bf 380 * @details
j3 1:91e52f8ab8bf 381 *
j3 1:91e52f8ab8bf 382 * On Entry:
j3 1:91e52f8ab8bf 383 * @param[in] family_code - family code of device
j3 1:91e52f8ab8bf 384 *
j3 1:91e52f8ab8bf 385 * On Exit:
j3 1:91e52f8ab8bf 386 * @return
j3 1:91e52f8ab8bf 387 **************************************************************/
j3 1:91e52f8ab8bf 388 virtual void OWTargetSetup(uint8_t family_code);
j3 1:91e52f8ab8bf 389
j3 1:91e52f8ab8bf 390
j3 1:91e52f8ab8bf 391 /**********************************************************//**
j3 1:91e52f8ab8bf 392 * @brief Setup the search to skip the current device type on the
j3 1:91e52f8ab8bf 393 * next call to OWNext().
j3 1:91e52f8ab8bf 394 *
j3 1:91e52f8ab8bf 395 * @details
j3 1:91e52f8ab8bf 396 *
j3 1:91e52f8ab8bf 397 * On Entry:
j3 1:91e52f8ab8bf 398 *
j3 1:91e52f8ab8bf 399 * On Exit:
j3 1:91e52f8ab8bf 400 * @return
j3 1:91e52f8ab8bf 401 **************************************************************/
j3 1:91e52f8ab8bf 402 virtual void OWFamilySkipSetup(void);
j3 1:91e52f8ab8bf 403
j3 1:91e52f8ab8bf 404
j3 1:91e52f8ab8bf 405 /**********************************************************//**
j3 1:91e52f8ab8bf 406 * @brief The 'OWSearch' function does a general search. This
j3 1:91e52f8ab8bf 407 * function continues from the previous search state. The
j3 1:91e52f8ab8bf 408 * search state can be reset by using the 'OWFirst'
j3 1:91e52f8ab8bf 409 * function. This function contains one parameter
j3 1:91e52f8ab8bf 410 * 'alarm_only'. When 'alarm_only' is TRUE (1) the find
j3 1:91e52f8ab8bf 411 * alarm command 0xEC is sent instead of the normal search
j3 1:91e52f8ab8bf 412 * command 0xF0. Using the find alarm command 0xEC will
j3 1:91e52f8ab8bf 413 * limit the search to only 1-Wire devices that are in an
j3 1:91e52f8ab8bf 414 * 'alarm' state.
j3 1:91e52f8ab8bf 415 *
j3 1:91e52f8ab8bf 416 * @details
j3 1:91e52f8ab8bf 417 *
j3 1:91e52f8ab8bf 418 * On Entry:
j3 1:91e52f8ab8bf 419 *
j3 1:91e52f8ab8bf 420 * On Exit:
j3 1:91e52f8ab8bf 421 * @return TRUE (1) : when a 1-Wire device was found and its
j3 1:91e52f8ab8bf 422 * Serial Number placed in the global ROM
j3 1:91e52f8ab8bf 423 * FALSE (0): when no new device was found. Either the
j3 1:91e52f8ab8bf 424 * last search was the last device or there
j3 1:91e52f8ab8bf 425 * are no devices on the 1-Wire Net.
j3 1:91e52f8ab8bf 426 **************************************************************/
j3 1:91e52f8ab8bf 427 virtual uint8_t OWSearch(void);
j3 1:91e52f8ab8bf 428
j3 1:91e52f8ab8bf 429
j3 1:91e52f8ab8bf 430 /**********************************************************//**
j3 1:91e52f8ab8bf 431 * @brief Set the 1-Wire Net communication speed.
j3 1:91e52f8ab8bf 432 *
j3 1:91e52f8ab8bf 433 * @details
j3 1:91e52f8ab8bf 434 *
j3 1:91e52f8ab8bf 435 * On Entry:
j3 1:91e52f8ab8bf 436 * @param[in] 'new_speed' - new speed defined as
j3 1:91e52f8ab8bf 437 * MODE_STANDARD 0x00
j3 1:91e52f8ab8bf 438 * MODE_OVERDRIVE 0x01
j3 1:91e52f8ab8bf 439 *
j3 1:91e52f8ab8bf 440 * On Exit:
j3 1:91e52f8ab8bf 441 * @return current 1-Wire Net speed
j3 1:91e52f8ab8bf 442 **************************************************************/
j3 1:91e52f8ab8bf 443 virtual uint8_t OWSpeed(uint8_t new_speed);
j3 1:91e52f8ab8bf 444
j3 1:91e52f8ab8bf 445
j3 1:91e52f8ab8bf 446 /**********************************************************//**
j3 1:91e52f8ab8bf 447 * @brief Set the 1-Wire Net line level pull-up to normal. The
j3 1:91e52f8ab8bf 448 * Ds248x does only allows enabling strong pull-up on a
j3 1:91e52f8ab8bf 449 * bit or byte event. Consequently this function only
j3 1:91e52f8ab8bf 450 * allows the MODE_STANDARD argument. To enable strong
j3 1:91e52f8ab8bf 451 * pull-up use OWWriteBytePower or OWReadBitPower.
j3 1:91e52f8ab8bf 452 *
j3 1:91e52f8ab8bf 453 * @details
j3 1:91e52f8ab8bf 454 *
j3 1:91e52f8ab8bf 455 * On Entry:
j3 1:91e52f8ab8bf 456 * @param[in] 'new_level' - new level defined as
j3 1:91e52f8ab8bf 457 * MODE_STANDARD 0x00
j3 1:91e52f8ab8bf 458 *
j3 1:91e52f8ab8bf 459 * On Exit:
j3 1:91e52f8ab8bf 460 * @return current 1-Wire Net level
j3 1:91e52f8ab8bf 461 **************************************************************/
j3 1:91e52f8ab8bf 462 virtual uint8_t OWLevel(uint8_t new_level);
j3 1:91e52f8ab8bf 463
j3 1:91e52f8ab8bf 464
j3 1:91e52f8ab8bf 465 /**********************************************************//**
j3 1:91e52f8ab8bf 466 * @brief Send 8 bits of communication to the 1-Wire Net and
j3 1:91e52f8ab8bf 467 * verify that the 8 bits read from the 1-Wire Net is the
j3 1:91e52f8ab8bf 468 * same (write operation). The parameter 'sendbyte' least
j3 1:91e52f8ab8bf 469 * significant 8 bits are used. After the 8 bits are sent
j3 1:91e52f8ab8bf 470 * change the level of the 1-Wire net.
j3 1:91e52f8ab8bf 471 *
j3 1:91e52f8ab8bf 472 * @details
j3 1:91e52f8ab8bf 473 *
j3 1:91e52f8ab8bf 474 * On Entry:
j3 1:91e52f8ab8bf 475 * @param[in] 'sendbyte' - 8 bits to send (least significant bit)
j3 1:91e52f8ab8bf 476 *
j3 1:91e52f8ab8bf 477 * On Exit:
j3 1:91e52f8ab8bf 478 * @return TRUE: bytes written and echo was the same, strong pullup now on
j3 1:91e52f8ab8bf 479 * FALSE: echo was not the same
j3 1:91e52f8ab8bf 480 **************************************************************/
j3 1:91e52f8ab8bf 481 virtual uint8_t OWWriteBytePower(uint8_t sendbyte);
j3 1:91e52f8ab8bf 482
j3 1:91e52f8ab8bf 483
j3 1:91e52f8ab8bf 484 /**********************************************************//**
j3 1:91e52f8ab8bf 485 * @brief Send 1 bit of communication to the 1-Wire Net and verify
j3 1:91e52f8ab8bf 486 * that the response matches the 'applyPowerResponse' bit
j3 1:91e52f8ab8bf 487 * and apply power delivery to the 1-Wire net. Note that
j3 1:91e52f8ab8bf 488 * some implementations may apply the power first and then
j3 1:91e52f8ab8bf 489 * turn it off if the response is incorrect.
j3 1:91e52f8ab8bf 490 *
j3 1:91e52f8ab8bf 491 * @details
j3 1:91e52f8ab8bf 492 *
j3 1:91e52f8ab8bf 493 * On Entry:
j3 1:91e52f8ab8bf 494 * @param[in] 'applyPowerResponse' - 1 bit response to check,
j3 1:91e52f8ab8bf 495 * if correct
j3 1:91e52f8ab8bf 496 * then start power delivery
j3 1:91e52f8ab8bf 497 *
j3 1:91e52f8ab8bf 498 * On Exit:
j3 1:91e52f8ab8bf 499 * @return
j3 1:91e52f8ab8bf 500 **************************************************************/
j3 1:91e52f8ab8bf 501 virtual uint8_t OWReadBitPower(uint8_t applyPowerResponse);
j3 1:91e52f8ab8bf 502
j3 1:91e52f8ab8bf 503
j3 1:91e52f8ab8bf 504 /**********************************************************//**
j3 1:91e52f8ab8bf 505 * @brief Calculate the CRC8 of the byte value provided with the
j3 1:91e52f8ab8bf 506 * current global 'crc8' value.
j3 1:91e52f8ab8bf 507 *
j3 1:91e52f8ab8bf 508 * @details
j3 1:91e52f8ab8bf 509 *
j3 1:91e52f8ab8bf 510 * On Entry:
j3 1:91e52f8ab8bf 511 * @param[in] data
j3 1:91e52f8ab8bf 512 *
j3 1:91e52f8ab8bf 513 * On Exit:
j3 1:91e52f8ab8bf 514 * @return current global crc8 value
j3 1:91e52f8ab8bf 515 **************************************************************/
j3 1:91e52f8ab8bf 516 virtual uint8_t calc_crc8(uint8_t data);
j3 1:91e52f8ab8bf 517
j3 1:91e52f8ab8bf 518 private:
j3 1:91e52f8ab8bf 519
j3 1:91e52f8ab8bf 520 I2C *_p_i2c_bus;
j3 1:91e52f8ab8bf 521 bool i2c_owner;
j3 1:91e52f8ab8bf 522 uint8_t _w_adrs, _r_adrs;
j3 1:91e52f8ab8bf 523
j3 1:91e52f8ab8bf 524 };
j3 1:91e52f8ab8bf 525
j3 1:91e52f8ab8bf 526 #endif /*DS248X_H*/