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.
OneWire_Masters/DS248x/ds248x.h@2:02d228c25fd4, 2016-01-31 (annotated)
- Committer:
- j3
- Date:
- Sun Jan 31 06:15:24 2016 +0000
- Revision:
- 2:02d228c25fd4
- Parent:
- 1:91e52f8ab8bf
- Child:
- 3:644fc630f958
Finished porting DS248X code
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:91e52f8ab8bf | 70 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 71 | * @brief Ds248x constructor |
j3 | 1:91e52f8ab8bf | 72 | * |
j3 | 1:91e52f8ab8bf | 73 | * @details allows user to use existing I2C object |
j3 | 1:91e52f8ab8bf | 74 | * |
j3 | 1:91e52f8ab8bf | 75 | * On Entry: |
j3 | 1:91e52f8ab8bf | 76 | * @param[in] p_i2c_bus - pointer to existing I2C object |
j3 | 1:91e52f8ab8bf | 77 | * |
j3 | 1:91e52f8ab8bf | 78 | * On Exit: |
j3 | 1:91e52f8ab8bf | 79 | * @return |
j3 | 1:91e52f8ab8bf | 80 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 81 | Ds248x(I2C *p_i2c_bus, ds248x_i2c_adrs_t adrs); |
j3 | 1:91e52f8ab8bf | 82 | |
j3 | 1:91e52f8ab8bf | 83 | |
j3 | 1:91e52f8ab8bf | 84 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 85 | * @brief Ds248x constructor |
j3 | 1:91e52f8ab8bf | 86 | * |
j3 | 1:91e52f8ab8bf | 87 | * @details allows user to use existing I2C object |
j3 | 1:91e52f8ab8bf | 88 | * |
j3 | 1:91e52f8ab8bf | 89 | * On Entry: |
j3 | 1:91e52f8ab8bf | 90 | * @param[in] sda - sda pin of I2C bus |
j3 | 1:91e52f8ab8bf | 91 | * @param[in] scl - scl pin of I2C bus |
j3 | 1:91e52f8ab8bf | 92 | * |
j3 | 1:91e52f8ab8bf | 93 | * On Exit: |
j3 | 1:91e52f8ab8bf | 94 | * @return |
j3 | 1:91e52f8ab8bf | 95 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 96 | Ds248x(PinName sda, PinName scl, ds248x_i2c_adrs_t adrs); |
j3 | 1:91e52f8ab8bf | 97 | |
j3 | 1:91e52f8ab8bf | 98 | |
j3 | 1:91e52f8ab8bf | 99 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 100 | * @brief Ds248x destructor |
j3 | 1:91e52f8ab8bf | 101 | * |
j3 | 1:91e52f8ab8bf | 102 | * @details deletes I2C object if owner |
j3 | 1:91e52f8ab8bf | 103 | * |
j3 | 1:91e52f8ab8bf | 104 | * On Entry: |
j3 | 1:91e52f8ab8bf | 105 | * |
j3 | 1:91e52f8ab8bf | 106 | * On Exit: |
j3 | 1:91e52f8ab8bf | 107 | * @return |
j3 | 1:91e52f8ab8bf | 108 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 109 | ~Ds248x(); |
j3 | 1:91e52f8ab8bf | 110 | |
j3 | 1:91e52f8ab8bf | 111 | |
j3 | 1:91e52f8ab8bf | 112 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 113 | * @brief detect() |
j3 | 1:91e52f8ab8bf | 114 | * |
j3 | 1:91e52f8ab8bf | 115 | * @details Detect routine that performs a device reset |
j3 | 1:91e52f8ab8bf | 116 | * followed by writing the configuration byte to default |
j3 | 1:91e52f8ab8bf | 117 | * values: |
j3 | 1:91e52f8ab8bf | 118 | * 1-Wire speed (c1WS) = standard (0) |
j3 | 1:91e52f8ab8bf | 119 | * Strong pull-up (cSPU) = off (0) |
j3 | 1:91e52f8ab8bf | 120 | * Presence pulse masking (cPPM) = off (0) |
j3 | 1:91e52f8ab8bf | 121 | * Active pull-up (cAPU) = on (CONFIG_APU = 0x01) |
j3 | 1:91e52f8ab8bf | 122 | * |
j3 | 1:91e52f8ab8bf | 123 | * On Entry: |
j3 | 1:91e52f8ab8bf | 124 | * |
j3 | 1:91e52f8ab8bf | 125 | * On Exit: |
j3 | 1:91e52f8ab8bf | 126 | * @return TRUE if device was detected and written |
j3 | 1:91e52f8ab8bf | 127 | * FALSE device not detected or failure to write |
j3 | 1:91e52f8ab8bf | 128 | * configuration byte |
j3 | 1:91e52f8ab8bf | 129 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 130 | bool detect(void); |
j3 | 1:91e52f8ab8bf | 131 | |
j3 | 1:91e52f8ab8bf | 132 | |
j3 | 1:91e52f8ab8bf | 133 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 134 | * @brief reset() |
j3 | 1:91e52f8ab8bf | 135 | * |
j3 | 1:91e52f8ab8bf | 136 | * @details Perform a device reset on the Ds248x |
j3 | 1:91e52f8ab8bf | 137 | * |
j3 | 1:91e52f8ab8bf | 138 | * On Entry: |
j3 | 1:91e52f8ab8bf | 139 | * |
j3 | 1:91e52f8ab8bf | 140 | * On Exit: |
j3 | 1:91e52f8ab8bf | 141 | * @return TRUE if device was reset |
j3 | 1:91e52f8ab8bf | 142 | * FALSE device not detected or failure to perform reset |
j3 | 1:91e52f8ab8bf | 143 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 144 | bool reset(void); |
j3 | 1:91e52f8ab8bf | 145 | |
j3 | 1:91e52f8ab8bf | 146 | |
j3 | 1:91e52f8ab8bf | 147 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 148 | * @brief write_config() |
j3 | 1:91e52f8ab8bf | 149 | * |
j3 | 1:91e52f8ab8bf | 150 | * @details Write the configuration register in the Ds248x. The |
j3 | 1:91e52f8ab8bf | 151 | * configuration options are provided in the lower nibble |
j3 | 1:91e52f8ab8bf | 152 | * of the provided config byte. The uppper nibble is |
j3 | 1:91e52f8ab8bf | 153 | * bitwise inverted when written to the Ds248x. |
j3 | 1:91e52f8ab8bf | 154 | * |
j3 | 1:91e52f8ab8bf | 155 | * On Entry: |
j3 | 1:91e52f8ab8bf | 156 | * @param[in] config - lower nib of configuration register |
j3 | 1:91e52f8ab8bf | 157 | * |
j3 | 1:91e52f8ab8bf | 158 | * On Exit: |
j3 | 1:91e52f8ab8bf | 159 | * @return TRUE: config written and response correct |
j3 | 1:91e52f8ab8bf | 160 | * FALSE: response incorrect |
j3 | 1:91e52f8ab8bf | 161 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 162 | bool write_config(uint8_t config); |
j3 | 2:02d228c25fd4 | 163 | |
j3 | 2:02d228c25fd4 | 164 | |
j3 | 2:02d228c25fd4 | 165 | /**********************************************************//** |
j3 | 2:02d228c25fd4 | 166 | * @brief channel_select() |
j3 | 2:02d228c25fd4 | 167 | * |
j3 | 2:02d228c25fd4 | 168 | * @details Select the 1-Wire channel on a DS2482-800. |
j3 | 2:02d228c25fd4 | 169 | * Min channel = 1 |
j3 | 2:02d228c25fd4 | 170 | * |
j3 | 2:02d228c25fd4 | 171 | * On Entry: |
j3 | 2:02d228c25fd4 | 172 | * @param[in] channel - desired channel of the DS2482 |
j3 | 2:02d228c25fd4 | 173 | * |
j3 | 2:02d228c25fd4 | 174 | * On Exit: |
j3 | 2:02d228c25fd4 | 175 | * @return TRUE if channel selected |
j3 | 2:02d228c25fd4 | 176 | * FALSE device not detected or failure to perform select |
j3 | 2:02d228c25fd4 | 177 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 178 | bool channel_select(uint8_t channel); |
j3 | 1:91e52f8ab8bf | 179 | |
j3 | 1:91e52f8ab8bf | 180 | |
j3 | 1:91e52f8ab8bf | 181 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 182 | * @brief adjust_timing() |
j3 | 1:91e52f8ab8bf | 183 | * |
j3 | 2:02d228c25fd4 | 184 | * @details adjustable timming available in DS2484 only |
j3 | 1:91e52f8ab8bf | 185 | * |
j3 | 1:91e52f8ab8bf | 186 | * On Entry: |
j3 | 1:91e52f8ab8bf | 187 | * @param[in] param - 1 of 8 adjustable parameters |
j3 | 1:91e52f8ab8bf | 188 | * @param[in] val - new value for parameter, see datasheet |
j3 | 1:91e52f8ab8bf | 189 | * for codes |
j3 | 1:91e52f8ab8bf | 190 | * |
j3 | 1:91e52f8ab8bf | 191 | * On Exit: |
j3 | 1:91e52f8ab8bf | 192 | * @return TRUE: parameter successfully adjusted |
j3 | 1:91e52f8ab8bf | 193 | * FALSE: failed to adjust parameter |
j3 | 1:91e52f8ab8bf | 194 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 195 | bool adjust_timing(uint8_t param, uint8_t val); |
j3 | 1:91e52f8ab8bf | 196 | |
j3 | 1:91e52f8ab8bf | 197 | |
j3 | 1:91e52f8ab8bf | 198 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 199 | * @brief search_triplet() |
j3 | 1:91e52f8ab8bf | 200 | * |
j3 | 1:91e52f8ab8bf | 201 | * @details Use the Ds248x help command '1-Wire triplet' to perform |
j3 | 1:91e52f8ab8bf | 202 | * one bit of a 1-Wire search. This command does two read |
j3 | 1:91e52f8ab8bf | 203 | * bits and one write bit. The write bit is either the |
j3 | 1:91e52f8ab8bf | 204 | * default direction (all device have same bit) or in case |
j3 | 1:91e52f8ab8bf | 205 | * of a discrepancy, the 'search_direction' parameter is |
j3 | 1:91e52f8ab8bf | 206 | * used. |
j3 | 1:91e52f8ab8bf | 207 | * |
j3 | 1:91e52f8ab8bf | 208 | * On Entry: |
j3 | 1:91e52f8ab8bf | 209 | * @param[in] search_direction |
j3 | 1:91e52f8ab8bf | 210 | * |
j3 | 1:91e52f8ab8bf | 211 | * On Exit: |
j3 | 1:91e52f8ab8bf | 212 | * @return The Ds248x status byte result from the triplet command |
j3 | 1:91e52f8ab8bf | 213 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 214 | uint8_t search_triplet(uint8_t search_direction); |
j3 | 1:91e52f8ab8bf | 215 | |
j3 | 1:91e52f8ab8bf | 216 | |
j3 | 1:91e52f8ab8bf | 217 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 218 | * @brief Reset all of the devices on the 1-Wire Net and return |
j3 | 1:91e52f8ab8bf | 219 | * the result. |
j3 | 1:91e52f8ab8bf | 220 | * |
j3 | 1:91e52f8ab8bf | 221 | * @details |
j3 | 1:91e52f8ab8bf | 222 | * |
j3 | 1:91e52f8ab8bf | 223 | * On Entry: |
j3 | 1:91e52f8ab8bf | 224 | * |
j3 | 1:91e52f8ab8bf | 225 | * On Exit: |
j3 | 1:91e52f8ab8bf | 226 | * @return TRUE(1): presence pulse(s) detected, device(s) reset |
j3 | 1:91e52f8ab8bf | 227 | * FALSE(0): no presence pulses detected |
j3 | 1:91e52f8ab8bf | 228 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 229 | virtual bool OWReset(); |
j3 | 1:91e52f8ab8bf | 230 | |
j3 | 1:91e52f8ab8bf | 231 | |
j3 | 1:91e52f8ab8bf | 232 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 233 | * @brief Send 1 bit of communication to the 1-Wire Net. |
j3 | 1:91e52f8ab8bf | 234 | * The parameter 'sendbit' least significant bit is used. |
j3 | 1:91e52f8ab8bf | 235 | * |
j3 | 1:91e52f8ab8bf | 236 | * @details |
j3 | 1:91e52f8ab8bf | 237 | * |
j3 | 1:91e52f8ab8bf | 238 | * On Entry: |
j3 | 1:91e52f8ab8bf | 239 | * @param[in] 'sendbit' - 1 bit to send (least significant byte) |
j3 | 1:91e52f8ab8bf | 240 | * |
j3 | 1:91e52f8ab8bf | 241 | * On Exit: |
j3 | 1:91e52f8ab8bf | 242 | * @return |
j3 | 1:91e52f8ab8bf | 243 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 244 | virtual void OWWriteBit(uint8_t sendbit); |
j3 | 1:91e52f8ab8bf | 245 | |
j3 | 1:91e52f8ab8bf | 246 | |
j3 | 1:91e52f8ab8bf | 247 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 248 | * @brief Reads 1 bit of communication from the 1-Wire Net and |
j3 | 1:91e52f8ab8bf | 249 | * returns the result |
j3 | 1:91e52f8ab8bf | 250 | * |
j3 | 1:91e52f8ab8bf | 251 | * @details |
j3 | 1:91e52f8ab8bf | 252 | * |
j3 | 1:91e52f8ab8bf | 253 | * On Entry: |
j3 | 1:91e52f8ab8bf | 254 | * |
j3 | 1:91e52f8ab8bf | 255 | * On Exit: |
j3 | 1:91e52f8ab8bf | 256 | * @return 1 bit read from 1-Wire Net |
j3 | 1:91e52f8ab8bf | 257 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 258 | virtual uint8_t OWReadBit(); |
j3 | 1:91e52f8ab8bf | 259 | |
j3 | 1:91e52f8ab8bf | 260 | |
j3 | 1:91e52f8ab8bf | 261 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 262 | * @brief Send 1 bit of communication to the 1-Wire Net and return |
j3 | 1:91e52f8ab8bf | 263 | * the result 1 bit read from the 1-Wire Net. The |
j3 | 1:91e52f8ab8bf | 264 | * parameter 'sendbit' least significant bit is used and |
j3 | 1:91e52f8ab8bf | 265 | * the least significant bit of the result is the return |
j3 | 1:91e52f8ab8bf | 266 | * bit. |
j3 | 1:91e52f8ab8bf | 267 | * |
j3 | 1:91e52f8ab8bf | 268 | * @details |
j3 | 1:91e52f8ab8bf | 269 | * |
j3 | 1:91e52f8ab8bf | 270 | * On Entry: |
j3 | 1:91e52f8ab8bf | 271 | * @param[in] 'sendbit' - the least significant bit is the bit to send |
j3 | 1:91e52f8ab8bf | 272 | * |
j3 | 1:91e52f8ab8bf | 273 | * On Exit: |
j3 | 1:91e52f8ab8bf | 274 | * @return 0: 0 bit read from sendbit |
j3 | 1:91e52f8ab8bf | 275 | * 1: 1 bit read from sendbit |
j3 | 1:91e52f8ab8bf | 276 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 277 | virtual uint8_t OWTouchBit(uint8_t sendbit); |
j3 | 1:91e52f8ab8bf | 278 | |
j3 | 1:91e52f8ab8bf | 279 | |
j3 | 1:91e52f8ab8bf | 280 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 281 | * @brief Send 8 bits of communication to the 1-Wire Net and |
j3 | 1:91e52f8ab8bf | 282 | * verify that the 8 bits read from the 1-Wire Net is the |
j3 | 1:91e52f8ab8bf | 283 | * same (write operation).The parameter 'sendbyte' least |
j3 | 1:91e52f8ab8bf | 284 | * significant 8 bits are used. |
j3 | 1:91e52f8ab8bf | 285 | * |
j3 | 1:91e52f8ab8bf | 286 | * @details |
j3 | 1:91e52f8ab8bf | 287 | * |
j3 | 1:91e52f8ab8bf | 288 | * On Entry: |
j3 | 1:91e52f8ab8bf | 289 | * @param[in] 'sendbyte' - 8 bits to send (least significant byte) |
j3 | 1:91e52f8ab8bf | 290 | * |
j3 | 1:91e52f8ab8bf | 291 | * On Exit: |
j3 | 1:91e52f8ab8bf | 292 | * @return TRUE: bytes written and echo was the same |
j3 | 1:91e52f8ab8bf | 293 | * FALSE: echo was not the same |
j3 | 1:91e52f8ab8bf | 294 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 295 | virtual bool OWWriteByte(uint8_t sendbyte); |
j3 | 1:91e52f8ab8bf | 296 | |
j3 | 1:91e52f8ab8bf | 297 | |
j3 | 1:91e52f8ab8bf | 298 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 299 | * @brief Send 8 bits of read communication to the 1-Wire Net and |
j3 | 1:91e52f8ab8bf | 300 | * return the result 8 bits read from the 1-Wire Net. |
j3 | 1:91e52f8ab8bf | 301 | * |
j3 | 1:91e52f8ab8bf | 302 | * @details |
j3 | 1:91e52f8ab8bf | 303 | * |
j3 | 1:91e52f8ab8bf | 304 | * On Entry: |
j3 | 1:91e52f8ab8bf | 305 | * |
j3 | 1:91e52f8ab8bf | 306 | * On Exit: |
j3 | 1:91e52f8ab8bf | 307 | * @return 8 bits read from 1-Wire Net |
j3 | 1:91e52f8ab8bf | 308 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 309 | virtual uint8_t OWReadByte(void); |
j3 | 1:91e52f8ab8bf | 310 | |
j3 | 1:91e52f8ab8bf | 311 | |
j3 | 1:91e52f8ab8bf | 312 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 313 | * @brief Send 8 bits of communication to the 1-Wire Net and |
j3 | 1:91e52f8ab8bf | 314 | * return the result 8 bits read from the 1-Wire Net. The |
j3 | 1:91e52f8ab8bf | 315 | * parameter 'sendbyte' least significant 8 bits are used |
j3 | 1:91e52f8ab8bf | 316 | * and the least significant 8 bits of the result is the |
j3 | 1:91e52f8ab8bf | 317 | * return byte. |
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] 'sendbyte' - 8 bits to send (least significant byte) |
j3 | 1:91e52f8ab8bf | 323 | * |
j3 | 1:91e52f8ab8bf | 324 | * On Exit: |
j3 | 1:91e52f8ab8bf | 325 | * @return 8 bits read from sendbyte |
j3 | 1:91e52f8ab8bf | 326 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 327 | virtual uint8_t OWTouchByte(uint8_t sendbyte); |
j3 | 1:91e52f8ab8bf | 328 | |
j3 | 1:91e52f8ab8bf | 329 | |
j3 | 1:91e52f8ab8bf | 330 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 331 | * @brief The 'OWBlock' transfers a block of data to and from the |
j3 | 1:91e52f8ab8bf | 332 | * 1-Wire Net. The result is returned in the same buffer. |
j3 | 1:91e52f8ab8bf | 333 | * |
j3 | 1:91e52f8ab8bf | 334 | * @details |
j3 | 1:91e52f8ab8bf | 335 | * |
j3 | 1:91e52f8ab8bf | 336 | * On Entry: |
j3 | 1:91e52f8ab8bf | 337 | * @param[in] 'tran_buf' - pointer to a block of unsigned |
j3 | 1:91e52f8ab8bf | 338 | * chars of length 'tran_len' that |
j3 | 1:91e52f8ab8bf | 339 | * will be sent to the 1-Wire Net |
j3 | 1:91e52f8ab8bf | 340 | * @param[in] 'tran_len' - length in bytes to transfer |
j3 | 1:91e52f8ab8bf | 341 | * |
j3 | 1:91e52f8ab8bf | 342 | * On Exit: |
j3 | 1:91e52f8ab8bf | 343 | * @return |
j3 | 1:91e52f8ab8bf | 344 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 345 | virtual void OWBlock(uint8_t *tran_buf, uint8_t tran_len); |
j3 | 1:91e52f8ab8bf | 346 | |
j3 | 1:91e52f8ab8bf | 347 | |
j3 | 1:91e52f8ab8bf | 348 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 349 | * @brief Find the 'first' devices on the 1-Wire network |
j3 | 1:91e52f8ab8bf | 350 | * |
j3 | 1:91e52f8ab8bf | 351 | * @details |
j3 | 1:91e52f8ab8bf | 352 | * |
j3 | 1:91e52f8ab8bf | 353 | * On Entry: |
j3 | 1:91e52f8ab8bf | 354 | * |
j3 | 1:91e52f8ab8bf | 355 | * On Exit: |
j3 | 1:91e52f8ab8bf | 356 | * @return TRUE : device found, ROM number in ROM_NO buffer |
j3 | 1:91e52f8ab8bf | 357 | * FALSE : no device present |
j3 | 1:91e52f8ab8bf | 358 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 359 | virtual bool OWFirst(void); |
j3 | 1:91e52f8ab8bf | 360 | |
j3 | 1:91e52f8ab8bf | 361 | |
j3 | 1:91e52f8ab8bf | 362 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 363 | * @brief Find the 'next' devices on the 1-Wire network |
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 found, ROM number in ROM_NO buffer |
j3 | 1:91e52f8ab8bf | 371 | * FALSE : device not found, end of search |
j3 | 1:91e52f8ab8bf | 372 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 373 | virtual bool OWNext(void); |
j3 | 1:91e52f8ab8bf | 374 | |
j3 | 1:91e52f8ab8bf | 375 | |
j3 | 1:91e52f8ab8bf | 376 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 377 | * @brief Verify the device with the ROM number in ROM_NO buffer |
j3 | 1:91e52f8ab8bf | 378 | * 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 | * |
j3 | 1:91e52f8ab8bf | 384 | * On Exit: |
j3 | 1:91e52f8ab8bf | 385 | * @return TRUE : device verified present |
j3 | 1:91e52f8ab8bf | 386 | * FALSE : device not present |
j3 | 1:91e52f8ab8bf | 387 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 388 | virtual bool OWVerify(void); |
j3 | 1:91e52f8ab8bf | 389 | |
j3 | 1:91e52f8ab8bf | 390 | |
j3 | 1:91e52f8ab8bf | 391 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 392 | * @brief Setup the search to find the device type 'family_code' |
j3 | 1:91e52f8ab8bf | 393 | * on the next call to OWNext() if it is present. |
j3 | 1:91e52f8ab8bf | 394 | * |
j3 | 1:91e52f8ab8bf | 395 | * @details |
j3 | 1:91e52f8ab8bf | 396 | * |
j3 | 1:91e52f8ab8bf | 397 | * On Entry: |
j3 | 1:91e52f8ab8bf | 398 | * @param[in] family_code - family code of device |
j3 | 1:91e52f8ab8bf | 399 | * |
j3 | 1:91e52f8ab8bf | 400 | * On Exit: |
j3 | 1:91e52f8ab8bf | 401 | * @return |
j3 | 1:91e52f8ab8bf | 402 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 403 | virtual void OWTargetSetup(uint8_t family_code); |
j3 | 1:91e52f8ab8bf | 404 | |
j3 | 1:91e52f8ab8bf | 405 | |
j3 | 1:91e52f8ab8bf | 406 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 407 | * @brief Setup the search to skip the current device type on the |
j3 | 1:91e52f8ab8bf | 408 | * next call to OWNext(). |
j3 | 1:91e52f8ab8bf | 409 | * |
j3 | 1:91e52f8ab8bf | 410 | * @details |
j3 | 1:91e52f8ab8bf | 411 | * |
j3 | 1:91e52f8ab8bf | 412 | * On Entry: |
j3 | 1:91e52f8ab8bf | 413 | * |
j3 | 1:91e52f8ab8bf | 414 | * On Exit: |
j3 | 1:91e52f8ab8bf | 415 | * @return |
j3 | 1:91e52f8ab8bf | 416 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 417 | virtual void OWFamilySkipSetup(void); |
j3 | 1:91e52f8ab8bf | 418 | |
j3 | 1:91e52f8ab8bf | 419 | |
j3 | 1:91e52f8ab8bf | 420 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 421 | * @brief The 'OWSearch' function does a general search. This |
j3 | 1:91e52f8ab8bf | 422 | * function continues from the previous search state. The |
j3 | 1:91e52f8ab8bf | 423 | * search state can be reset by using the 'OWFirst' |
j3 | 1:91e52f8ab8bf | 424 | * function. This function contains one parameter |
j3 | 1:91e52f8ab8bf | 425 | * 'alarm_only'. When 'alarm_only' is TRUE (1) the find |
j3 | 1:91e52f8ab8bf | 426 | * alarm command 0xEC is sent instead of the normal search |
j3 | 1:91e52f8ab8bf | 427 | * command 0xF0. Using the find alarm command 0xEC will |
j3 | 1:91e52f8ab8bf | 428 | * limit the search to only 1-Wire devices that are in an |
j3 | 1:91e52f8ab8bf | 429 | * 'alarm' state. |
j3 | 1:91e52f8ab8bf | 430 | * |
j3 | 1:91e52f8ab8bf | 431 | * @details |
j3 | 1:91e52f8ab8bf | 432 | * |
j3 | 1:91e52f8ab8bf | 433 | * On Entry: |
j3 | 1:91e52f8ab8bf | 434 | * |
j3 | 1:91e52f8ab8bf | 435 | * On Exit: |
j3 | 1:91e52f8ab8bf | 436 | * @return TRUE (1) : when a 1-Wire device was found and its |
j3 | 1:91e52f8ab8bf | 437 | * Serial Number placed in the global ROM |
j3 | 1:91e52f8ab8bf | 438 | * FALSE (0): when no new device was found. Either the |
j3 | 1:91e52f8ab8bf | 439 | * last search was the last device or there |
j3 | 1:91e52f8ab8bf | 440 | * are no devices on the 1-Wire Net. |
j3 | 1:91e52f8ab8bf | 441 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 442 | virtual bool OWSearch(void); |
j3 | 1:91e52f8ab8bf | 443 | |
j3 | 1:91e52f8ab8bf | 444 | |
j3 | 1:91e52f8ab8bf | 445 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 446 | * @brief Set the 1-Wire Net communication speed. |
j3 | 1:91e52f8ab8bf | 447 | * |
j3 | 1:91e52f8ab8bf | 448 | * @details |
j3 | 1:91e52f8ab8bf | 449 | * |
j3 | 1:91e52f8ab8bf | 450 | * On Entry: |
j3 | 1:91e52f8ab8bf | 451 | * @param[in] 'new_speed' - new speed defined as |
j3 | 1:91e52f8ab8bf | 452 | * MODE_STANDARD 0x00 |
j3 | 1:91e52f8ab8bf | 453 | * MODE_OVERDRIVE 0x01 |
j3 | 1:91e52f8ab8bf | 454 | * |
j3 | 1:91e52f8ab8bf | 455 | * On Exit: |
j3 | 1:91e52f8ab8bf | 456 | * @return current 1-Wire Net speed |
j3 | 1:91e52f8ab8bf | 457 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 458 | virtual uint8_t OWSpeed(uint8_t new_speed); |
j3 | 1:91e52f8ab8bf | 459 | |
j3 | 1:91e52f8ab8bf | 460 | |
j3 | 1:91e52f8ab8bf | 461 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 462 | * @brief Set the 1-Wire Net line level pull-up to normal. The |
j3 | 1:91e52f8ab8bf | 463 | * Ds248x does only allows enabling strong pull-up on a |
j3 | 1:91e52f8ab8bf | 464 | * bit or byte event. Consequently this function only |
j3 | 1:91e52f8ab8bf | 465 | * allows the MODE_STANDARD argument. To enable strong |
j3 | 1:91e52f8ab8bf | 466 | * pull-up use OWWriteBytePower or OWReadBitPower. |
j3 | 1:91e52f8ab8bf | 467 | * |
j3 | 1:91e52f8ab8bf | 468 | * @details |
j3 | 1:91e52f8ab8bf | 469 | * |
j3 | 1:91e52f8ab8bf | 470 | * On Entry: |
j3 | 1:91e52f8ab8bf | 471 | * @param[in] 'new_level' - new level defined as |
j3 | 1:91e52f8ab8bf | 472 | * MODE_STANDARD 0x00 |
j3 | 1:91e52f8ab8bf | 473 | * |
j3 | 1:91e52f8ab8bf | 474 | * On Exit: |
j3 | 1:91e52f8ab8bf | 475 | * @return current 1-Wire Net level |
j3 | 1:91e52f8ab8bf | 476 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 477 | virtual uint8_t OWLevel(uint8_t new_level); |
j3 | 1:91e52f8ab8bf | 478 | |
j3 | 1:91e52f8ab8bf | 479 | |
j3 | 1:91e52f8ab8bf | 480 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 481 | * @brief Send 8 bits of communication to the 1-Wire Net and |
j3 | 1:91e52f8ab8bf | 482 | * verify that the 8 bits read from the 1-Wire Net is the |
j3 | 1:91e52f8ab8bf | 483 | * same (write operation). The parameter 'sendbyte' least |
j3 | 1:91e52f8ab8bf | 484 | * significant 8 bits are used. After the 8 bits are sent |
j3 | 1:91e52f8ab8bf | 485 | * change the level of the 1-Wire net. |
j3 | 1:91e52f8ab8bf | 486 | * |
j3 | 1:91e52f8ab8bf | 487 | * @details |
j3 | 1:91e52f8ab8bf | 488 | * |
j3 | 1:91e52f8ab8bf | 489 | * On Entry: |
j3 | 1:91e52f8ab8bf | 490 | * @param[in] 'sendbyte' - 8 bits to send (least significant bit) |
j3 | 1:91e52f8ab8bf | 491 | * |
j3 | 1:91e52f8ab8bf | 492 | * On Exit: |
j3 | 1:91e52f8ab8bf | 493 | * @return TRUE: bytes written and echo was the same, strong pullup now on |
j3 | 1:91e52f8ab8bf | 494 | * FALSE: echo was not the same |
j3 | 1:91e52f8ab8bf | 495 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 496 | virtual bool OWWriteBytePower(uint8_t sendbyte); |
j3 | 1:91e52f8ab8bf | 497 | |
j3 | 1:91e52f8ab8bf | 498 | |
j3 | 1:91e52f8ab8bf | 499 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 500 | * @brief Send 1 bit of communication to the 1-Wire Net and verify |
j3 | 1:91e52f8ab8bf | 501 | * that the response matches the 'applyPowerResponse' bit |
j3 | 1:91e52f8ab8bf | 502 | * and apply power delivery to the 1-Wire net. Note that |
j3 | 1:91e52f8ab8bf | 503 | * some implementations may apply the power first and then |
j3 | 1:91e52f8ab8bf | 504 | * turn it off if the response is incorrect. |
j3 | 1:91e52f8ab8bf | 505 | * |
j3 | 1:91e52f8ab8bf | 506 | * @details |
j3 | 1:91e52f8ab8bf | 507 | * |
j3 | 1:91e52f8ab8bf | 508 | * On Entry: |
j3 | 1:91e52f8ab8bf | 509 | * @param[in] 'applyPowerResponse' - 1 bit response to check, |
j3 | 1:91e52f8ab8bf | 510 | * if correct |
j3 | 1:91e52f8ab8bf | 511 | * then start power delivery |
j3 | 1:91e52f8ab8bf | 512 | * |
j3 | 1:91e52f8ab8bf | 513 | * On Exit: |
j3 | 2:02d228c25fd4 | 514 | * @return TRUE: bit written and response correct, strong pullup now on |
j3 | 2:02d228c25fd4 | 515 | * FALSE: response incorrect |
j3 | 1:91e52f8ab8bf | 516 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 517 | virtual bool OWReadBitPower(uint8_t applyPowerResponse); |
j3 | 1:91e52f8ab8bf | 518 | |
j3 | 1:91e52f8ab8bf | 519 | |
j3 | 1:91e52f8ab8bf | 520 | /**********************************************************//** |
j3 | 1:91e52f8ab8bf | 521 | * @brief Calculate the CRC8 of the byte value provided with the |
j3 | 1:91e52f8ab8bf | 522 | * current global 'crc8' value. |
j3 | 1:91e52f8ab8bf | 523 | * |
j3 | 1:91e52f8ab8bf | 524 | * @details |
j3 | 1:91e52f8ab8bf | 525 | * |
j3 | 1:91e52f8ab8bf | 526 | * On Entry: |
j3 | 1:91e52f8ab8bf | 527 | * @param[in] data |
j3 | 1:91e52f8ab8bf | 528 | * |
j3 | 1:91e52f8ab8bf | 529 | * On Exit: |
j3 | 1:91e52f8ab8bf | 530 | * @return current global crc8 value |
j3 | 1:91e52f8ab8bf | 531 | **************************************************************/ |
j3 | 1:91e52f8ab8bf | 532 | virtual uint8_t calc_crc8(uint8_t data); |
j3 | 1:91e52f8ab8bf | 533 | |
j3 | 2:02d228c25fd4 | 534 | |
j3 | 2:02d228c25fd4 | 535 | /**********************************************************//** |
j3 | 2:02d228c25fd4 | 536 | * @brief get_rom_number() |
j3 | 2:02d228c25fd4 | 537 | * |
j3 | 2:02d228c25fd4 | 538 | * @details Get the ROM ID currently held in the private buffer |
j3 | 2:02d228c25fd4 | 539 | * |
j3 | 2:02d228c25fd4 | 540 | * On Entry: |
j3 | 2:02d228c25fd4 | 541 | * @param[in] p_rom_buff - pointer to buffer for storing |
j3 | 2:02d228c25fd4 | 542 | * rom number |
j3 | 2:02d228c25fd4 | 543 | * |
j3 | 2:02d228c25fd4 | 544 | * On Exit: |
j3 | 2:02d228c25fd4 | 545 | * @return none |
j3 | 2:02d228c25fd4 | 546 | **************************************************************/ |
j3 | 2:02d228c25fd4 | 547 | virtual void get_rom_number(uint8_t *p_rom_buff); |
j3 | 2:02d228c25fd4 | 548 | |
j3 | 1:91e52f8ab8bf | 549 | private: |
j3 | 1:91e52f8ab8bf | 550 | |
j3 | 1:91e52f8ab8bf | 551 | I2C *_p_i2c_bus; |
j3 | 1:91e52f8ab8bf | 552 | bool i2c_owner; |
j3 | 1:91e52f8ab8bf | 553 | uint8_t _w_adrs, _r_adrs; |
j3 | 2:02d228c25fd4 | 554 | |
j3 | 2:02d228c25fd4 | 555 | // ds248x state |
j3 | 2:02d228c25fd4 | 556 | uint8_t _short_detected; |
j3 | 2:02d228c25fd4 | 557 | uint8_t _c1WS, _cSPU, _cPDN, _cAPU; |
j3 | 2:02d228c25fd4 | 558 | |
j3 | 2:02d228c25fd4 | 559 | // Search state |
j3 | 2:02d228c25fd4 | 560 | uint8_t _rom_number[8]; |
j3 | 2:02d228c25fd4 | 561 | uint8_t _last_discrepancy; |
j3 | 2:02d228c25fd4 | 562 | uint8_t _last_family_discrepancy; |
j3 | 2:02d228c25fd4 | 563 | uint8_t _last_device_flag; |
j3 | 2:02d228c25fd4 | 564 | uint8_t _crc8; |
j3 | 1:91e52f8ab8bf | 565 | }; |
j3 | 1:91e52f8ab8bf | 566 | |
j3 | 1:91e52f8ab8bf | 567 | #endif /*DS248X_H*/ |