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.

Committer:
j3
Date:
Sun Jan 31 22:42:01 2016 +0000
Revision:
3:644fc630f958
Parent:
2:02d228c25fd4
Child:
5:ce108eeb878d
DS248X masters implemented, skeletons for the others, working on porting code for the DS28E17 1-wire to I2C bridge

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 2:02d228c25fd4 68 }ds248x_i2c_adrs_t;
j3 1:91e52f8ab8bf 69
j3 3:644fc630f958 70 /**
j3 3:644fc630f958 71 * Member functions that directly support DS248x I2C to 1-wire
j3 3:644fc630f958 72 * masters are documented in this file. Virtual function
j3 3:644fc630f958 73 * inerited from the interface class 'OneWireInterface'
j3 3:644fc630f958 74 * are documented in 'OneWireInterface.h', trying to follow
j3 3:644fc630f958 75 * a 'DRY' methodology, Don't Repeat Yourself.
j3 3:644fc630f958 76 */
j3 3:644fc630f958 77
j3 1:91e52f8ab8bf 78 /**********************************************************//**
j3 1:91e52f8ab8bf 79 * @brief Ds248x constructor
j3 1:91e52f8ab8bf 80 *
j3 1:91e52f8ab8bf 81 * @details allows user to use existing I2C object
j3 1:91e52f8ab8bf 82 *
j3 1:91e52f8ab8bf 83 * On Entry:
j3 1:91e52f8ab8bf 84 * @param[in] p_i2c_bus - pointer to existing I2C object
j3 1:91e52f8ab8bf 85 *
j3 1:91e52f8ab8bf 86 * On Exit:
j3 1:91e52f8ab8bf 87 * @return
j3 1:91e52f8ab8bf 88 **************************************************************/
j3 1:91e52f8ab8bf 89 Ds248x(I2C *p_i2c_bus, ds248x_i2c_adrs_t adrs);
j3 1:91e52f8ab8bf 90
j3 1:91e52f8ab8bf 91
j3 1:91e52f8ab8bf 92 /**********************************************************//**
j3 1:91e52f8ab8bf 93 * @brief Ds248x constructor
j3 1:91e52f8ab8bf 94 *
j3 3:644fc630f958 95 * @details Object instantiates a new I2C object with no
j3 3:644fc630f958 96 * public access
j3 1:91e52f8ab8bf 97 *
j3 1:91e52f8ab8bf 98 * On Entry:
j3 1:91e52f8ab8bf 99 * @param[in] sda - sda pin of I2C bus
j3 1:91e52f8ab8bf 100 * @param[in] scl - scl pin of I2C bus
j3 1:91e52f8ab8bf 101 *
j3 1:91e52f8ab8bf 102 * On Exit:
j3 1:91e52f8ab8bf 103 * @return
j3 1:91e52f8ab8bf 104 **************************************************************/
j3 1:91e52f8ab8bf 105 Ds248x(PinName sda, PinName scl, ds248x_i2c_adrs_t adrs);
j3 1:91e52f8ab8bf 106
j3 1:91e52f8ab8bf 107
j3 1:91e52f8ab8bf 108 /**********************************************************//**
j3 1:91e52f8ab8bf 109 * @brief Ds248x destructor
j3 1:91e52f8ab8bf 110 *
j3 1:91e52f8ab8bf 111 * @details deletes I2C object if owner
j3 1:91e52f8ab8bf 112 *
j3 1:91e52f8ab8bf 113 * On Entry:
j3 1:91e52f8ab8bf 114 *
j3 1:91e52f8ab8bf 115 * On Exit:
j3 1:91e52f8ab8bf 116 * @return
j3 1:91e52f8ab8bf 117 **************************************************************/
j3 1:91e52f8ab8bf 118 ~Ds248x();
j3 1:91e52f8ab8bf 119
j3 1:91e52f8ab8bf 120
j3 1:91e52f8ab8bf 121 /**********************************************************//**
j3 1:91e52f8ab8bf 122 * @brief detect()
j3 1:91e52f8ab8bf 123 *
j3 1:91e52f8ab8bf 124 * @details Detect routine that performs a device reset
j3 1:91e52f8ab8bf 125 * followed by writing the configuration byte to default
j3 1:91e52f8ab8bf 126 * values:
j3 1:91e52f8ab8bf 127 * 1-Wire speed (c1WS) = standard (0)
j3 1:91e52f8ab8bf 128 * Strong pull-up (cSPU) = off (0)
j3 1:91e52f8ab8bf 129 * Presence pulse masking (cPPM) = off (0)
j3 1:91e52f8ab8bf 130 * Active pull-up (cAPU) = on (CONFIG_APU = 0x01)
j3 1:91e52f8ab8bf 131 *
j3 1:91e52f8ab8bf 132 * On Entry:
j3 1:91e52f8ab8bf 133 *
j3 1:91e52f8ab8bf 134 * On Exit:
j3 1:91e52f8ab8bf 135 * @return TRUE if device was detected and written
j3 1:91e52f8ab8bf 136 * FALSE device not detected or failure to write
j3 1:91e52f8ab8bf 137 * configuration byte
j3 1:91e52f8ab8bf 138 **************************************************************/
j3 2:02d228c25fd4 139 bool detect(void);
j3 1:91e52f8ab8bf 140
j3 1:91e52f8ab8bf 141
j3 1:91e52f8ab8bf 142 /**********************************************************//**
j3 1:91e52f8ab8bf 143 * @brief reset()
j3 1:91e52f8ab8bf 144 *
j3 1:91e52f8ab8bf 145 * @details Perform a device reset on the Ds248x
j3 1:91e52f8ab8bf 146 *
j3 1:91e52f8ab8bf 147 * On Entry:
j3 1:91e52f8ab8bf 148 *
j3 1:91e52f8ab8bf 149 * On Exit:
j3 1:91e52f8ab8bf 150 * @return TRUE if device was reset
j3 1:91e52f8ab8bf 151 * FALSE device not detected or failure to perform reset
j3 1:91e52f8ab8bf 152 **************************************************************/
j3 2:02d228c25fd4 153 bool reset(void);
j3 1:91e52f8ab8bf 154
j3 1:91e52f8ab8bf 155
j3 1:91e52f8ab8bf 156 /**********************************************************//**
j3 1:91e52f8ab8bf 157 * @brief write_config()
j3 1:91e52f8ab8bf 158 *
j3 1:91e52f8ab8bf 159 * @details Write the configuration register in the Ds248x. The
j3 1:91e52f8ab8bf 160 * configuration options are provided in the lower nibble
j3 1:91e52f8ab8bf 161 * of the provided config byte. The uppper nibble is
j3 1:91e52f8ab8bf 162 * bitwise inverted when written to the Ds248x.
j3 1:91e52f8ab8bf 163 *
j3 1:91e52f8ab8bf 164 * On Entry:
j3 1:91e52f8ab8bf 165 * @param[in] config - lower nib of configuration register
j3 1:91e52f8ab8bf 166 *
j3 1:91e52f8ab8bf 167 * On Exit:
j3 1:91e52f8ab8bf 168 * @return TRUE: config written and response correct
j3 1:91e52f8ab8bf 169 * FALSE: response incorrect
j3 1:91e52f8ab8bf 170 **************************************************************/
j3 2:02d228c25fd4 171 bool write_config(uint8_t config);
j3 2:02d228c25fd4 172
j3 2:02d228c25fd4 173
j3 2:02d228c25fd4 174 /**********************************************************//**
j3 2:02d228c25fd4 175 * @brief channel_select()
j3 2:02d228c25fd4 176 *
j3 2:02d228c25fd4 177 * @details Select the 1-Wire channel on a DS2482-800.
j3 2:02d228c25fd4 178 * Min channel = 1
j3 2:02d228c25fd4 179 *
j3 2:02d228c25fd4 180 * On Entry:
j3 2:02d228c25fd4 181 * @param[in] channel - desired channel of the DS2482
j3 2:02d228c25fd4 182 *
j3 2:02d228c25fd4 183 * On Exit:
j3 2:02d228c25fd4 184 * @return TRUE if channel selected
j3 2:02d228c25fd4 185 * FALSE device not detected or failure to perform select
j3 2:02d228c25fd4 186 **************************************************************/
j3 2:02d228c25fd4 187 bool channel_select(uint8_t channel);
j3 1:91e52f8ab8bf 188
j3 1:91e52f8ab8bf 189
j3 1:91e52f8ab8bf 190 /**********************************************************//**
j3 1:91e52f8ab8bf 191 * @brief adjust_timing()
j3 1:91e52f8ab8bf 192 *
j3 2:02d228c25fd4 193 * @details adjustable timming available in DS2484 only
j3 1:91e52f8ab8bf 194 *
j3 1:91e52f8ab8bf 195 * On Entry:
j3 1:91e52f8ab8bf 196 * @param[in] param - 1 of 8 adjustable parameters
j3 1:91e52f8ab8bf 197 * @param[in] val - new value for parameter, see datasheet
j3 1:91e52f8ab8bf 198 * for codes
j3 1:91e52f8ab8bf 199 *
j3 1:91e52f8ab8bf 200 * On Exit:
j3 1:91e52f8ab8bf 201 * @return TRUE: parameter successfully adjusted
j3 1:91e52f8ab8bf 202 * FALSE: failed to adjust parameter
j3 1:91e52f8ab8bf 203 **************************************************************/
j3 2:02d228c25fd4 204 bool adjust_timing(uint8_t param, uint8_t val);
j3 1:91e52f8ab8bf 205
j3 1:91e52f8ab8bf 206
j3 1:91e52f8ab8bf 207 /**********************************************************//**
j3 1:91e52f8ab8bf 208 * @brief search_triplet()
j3 1:91e52f8ab8bf 209 *
j3 1:91e52f8ab8bf 210 * @details Use the Ds248x help command '1-Wire triplet' to perform
j3 1:91e52f8ab8bf 211 * one bit of a 1-Wire search. This command does two read
j3 1:91e52f8ab8bf 212 * bits and one write bit. The write bit is either the
j3 1:91e52f8ab8bf 213 * default direction (all device have same bit) or in case
j3 1:91e52f8ab8bf 214 * of a discrepancy, the 'search_direction' parameter is
j3 1:91e52f8ab8bf 215 * used.
j3 1:91e52f8ab8bf 216 *
j3 1:91e52f8ab8bf 217 * On Entry:
j3 1:91e52f8ab8bf 218 * @param[in] search_direction
j3 1:91e52f8ab8bf 219 *
j3 1:91e52f8ab8bf 220 * On Exit:
j3 1:91e52f8ab8bf 221 * @return The Ds248x status byte result from the triplet command
j3 1:91e52f8ab8bf 222 **************************************************************/
j3 1:91e52f8ab8bf 223 uint8_t search_triplet(uint8_t search_direction);
j3 1:91e52f8ab8bf 224
j3 3:644fc630f958 225 /***** OW API ****************************************************/
j3 2:02d228c25fd4 226 virtual bool OWReset();
j3 1:91e52f8ab8bf 227
j3 1:91e52f8ab8bf 228 virtual void OWWriteBit(uint8_t sendbit);
j3 1:91e52f8ab8bf 229
j3 1:91e52f8ab8bf 230 virtual uint8_t OWReadBit();
j3 1:91e52f8ab8bf 231
j3 1:91e52f8ab8bf 232 virtual uint8_t OWTouchBit(uint8_t sendbit);
j3 3:644fc630f958 233
j3 2:02d228c25fd4 234 virtual bool OWWriteByte(uint8_t sendbyte);
j3 3:644fc630f958 235
j3 1:91e52f8ab8bf 236 virtual uint8_t OWReadByte(void);
j3 3:644fc630f958 237
j3 1:91e52f8ab8bf 238 virtual uint8_t OWTouchByte(uint8_t sendbyte);
j3 3:644fc630f958 239
j3 1:91e52f8ab8bf 240 virtual void OWBlock(uint8_t *tran_buf, uint8_t tran_len);
j3 3:644fc630f958 241
j3 2:02d228c25fd4 242 virtual bool OWFirst(void);
j3 3:644fc630f958 243
j3 2:02d228c25fd4 244 virtual bool OWNext(void);
j3 3:644fc630f958 245
j3 2:02d228c25fd4 246 virtual bool OWVerify(void);
j3 3:644fc630f958 247
j3 1:91e52f8ab8bf 248 virtual void OWTargetSetup(uint8_t family_code);
j3 3:644fc630f958 249
j3 1:91e52f8ab8bf 250 virtual void OWFamilySkipSetup(void);
j3 1:91e52f8ab8bf 251
j3 2:02d228c25fd4 252 virtual bool OWSearch(void);
j3 3:644fc630f958 253
j3 1:91e52f8ab8bf 254 virtual uint8_t OWSpeed(uint8_t new_speed);
j3 3:644fc630f958 255
j3 1:91e52f8ab8bf 256 virtual uint8_t OWLevel(uint8_t new_level);
j3 3:644fc630f958 257
j3 2:02d228c25fd4 258 virtual bool OWWriteBytePower(uint8_t sendbyte);
j3 3:644fc630f958 259
j3 2:02d228c25fd4 260 virtual bool OWReadBitPower(uint8_t applyPowerResponse);
j3 3:644fc630f958 261
j3 3:644fc630f958 262 virtual uint8_t OWCalc_crc8(uint8_t data);
j3 3:644fc630f958 263
j3 3:644fc630f958 264 virtual void OWgetROMnumber(uint8_t *p_rom_buff);
j3 2:02d228c25fd4 265
j3 1:91e52f8ab8bf 266 private:
j3 1:91e52f8ab8bf 267
j3 1:91e52f8ab8bf 268 I2C *_p_i2c_bus;
j3 1:91e52f8ab8bf 269 bool i2c_owner;
j3 1:91e52f8ab8bf 270 uint8_t _w_adrs, _r_adrs;
j3 2:02d228c25fd4 271
j3 2:02d228c25fd4 272 // ds248x state
j3 2:02d228c25fd4 273 uint8_t _short_detected;
j3 2:02d228c25fd4 274 uint8_t _c1WS, _cSPU, _cPDN, _cAPU;
j3 2:02d228c25fd4 275
j3 2:02d228c25fd4 276 // Search state
j3 2:02d228c25fd4 277 uint8_t _rom_number[8];
j3 2:02d228c25fd4 278 uint8_t _last_discrepancy;
j3 2:02d228c25fd4 279 uint8_t _last_family_discrepancy;
j3 2:02d228c25fd4 280 uint8_t _last_device_flag;
j3 2:02d228c25fd4 281 uint8_t _crc8;
j3 1:91e52f8ab8bf 282 };
j3 1:91e52f8ab8bf 283
j3 1:91e52f8ab8bf 284 #endif /*DS248X_H*/