1-Wire and ENS210 driver stack
DS2485.h
Go to the documentation of this file.
1 /**
2  * @file DS2485.h
3  * @brief General library for the DS2485, supporting the higher-level one_wire.c/.h API.
4  *
5  * @par Return convention
6  * Most functions return an error code. A value of 0 indicates successful
7  * completion.
8  */
9 
10 /*******************************************************************************
11 * Copyright (C) Maxim Integrated Products, Inc., All rights Reserved.
12 *
13 * This software is protected by copyright laws of the United States and
14 * of foreign countries. This material may also be protected by patent laws
15 * and technology transfer regulations of the United States and of foreign
16 * countries. This software is furnished under a license agreement and/or a
17 * nondisclosure agreement and may only be used or reproduced in accordance
18 * with the terms of those agreements. Dissemination of this information to
19 * any party or parties not specified in the license agreement and/or
20 * nondisclosure agreement is expressly prohibited.
21 *
22 * The above copyright notice and this permission notice shall be included
23 * in all copies or substantial portions of the Software.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
29 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31 * OTHER DEALINGS IN THE SOFTWARE.
32 *
33 * Except as contained in this notice, the name of Maxim Integrated
34 * Products, Inc. shall not be used except as stated in the Maxim Integrated
35 * Products, Inc. Branding Policy.
36 *
37 * The mere transfer of this software does not imply any licenses
38 * of trade secrets, proprietary technology, copyrights, patents,
39 * trademarks, maskwork rights, or any other form of intellectual
40 * property whatsoever. Maxim Integrated Products, Inc. retains all
41 * ownership rights.
42 *******************************************************************************
43 */
44 
45  /* Define to prevent redundant inclusion */
46 #ifndef DS2485_H_INCLUDED
47 #define DS2485_H_INCLUDED
48 
49 /* **** Includes **** */
50 #include <stdint.h>
51 #include <stdbool.h>
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /* **** Definitions **** */
58 /* I2C Address */
59 #define DS2485_I2C_7BIT_ADDRESS 0x40U ///< will be shifted left one bit, then or'd with RW (R=1, W=0) bit on I2C
60 #define DS2485_I2C_CLOCKRATE 1000000U ///< 1MHz
61 
62 /* Device Function Commands */
63 #define DFC_WRITE_MEMORY 0x96;
64 #define DFC_READ_MEMORY 0x44;
65 #define DFC_READ_STATUS 0xAA;
66 #define DFC_SET_I2C_ADDRESS 0x75;
67 #define DFC_SET_PAGE_PROTECTION 0xC3;
68 #define DFC_READ_ONE_WIRE_PORT_CONFIG 0x52;
69 #define DFC_WRITE_ONE_WIRE_PORT_CONFIG 0x99;
70 #define DFC_MASTER_RESET 0x62;
71 #define DFC_ONE_WIRE_SCRIPT 0x88;
72 #define DFC_ONE_WIRE_BLOCK 0xAB;
73 #define DFC_ONE_WIRE_READ_BLOCK 0x50;
74 #define DFC_ONE_WIRE_WRITE_BLOCK 0x68;
75 #define DFC_ONE_WIRE_SEARCH 0x11;
76 #define DFC_FULL_COMMAND_SEQUENCE 0x57;
77 #define DFC_COMPUTE_CRC16 0xCC;
78 
79 /* Result Bytes */
80 #define RB_SUCCESS 0 // No Failure
81 #define RB_ALREADY_PROTECTED -100 // Command failed because the protection for the page has already been set
82 #define RB_INVALID_PARAMETER -101 // Invalid input or parameter
83 #define RB_SET_ADDRESS_FAIL -102 // Command failed because I2C address has already been set
84 #define RB_MASTER_RESET_FAIL -103 // Master reset fail
85 #define RB_COMMS_FAIL -104 // Communication failure
86 #define RB_NO_PRESENCE -105 // 1-Wire presence pulse not detected
87 #define RB_NO_MATCH_WRITES -106 // Non-matching 1-Wire writes
88 #define RB_NOT_DETECTED -107 // Device not detected in search
89 #define RB_INCORRECT_CRC -108 // CRC16 incorrect
90 #define RB_INVALID_LENGTH -109 // Invalid length of data (0)
91 #define RB_LENGTH_MISMATCH -110 // Length byte does not match actual length of data (Rx Length Byte will be 0)
92 #define RB_WRITE_PROTECTED -111 // The command failed because destination page is protected (WP)
93 #define RB_UNKNOWN -112 // Unknown error
94 
95 /* Operation Times */
96 #define tOP_USEC 40
97 #define tSEQ_USEC 20
98 #define tRM_MSEC 50
99 #define tWM_MSEC 100
100 #define tWS_MSEC 15
101 
102 /* Memory Pages*/
103 typedef enum {
104  PAGE_0,
105  PAGE_1,
106  PAGE_2,
107  PAGE_3,
108  PAGE_4,
109  PAGE_5,
110 } DS2485_memory_page_T;
111 
112 /* Device Status Outputs*/
113 typedef enum {
114  PAGE_PROTECTIONS,
115  MAN_ID,
116  DEVICE_VERSION,
117 } DS2485_status_outputs_T;
118 
119 /* Page Protections*/
120 typedef enum {
121  WRITE_PROTECTION = 0x02,
122  NONE_PROTECTION = 0x20,
123 } DS2485_page_protection_T;
124 
125 /* Write 1-Wire Port Configuration Registers */
126 typedef enum {
127  MASTER_CONFIGURATION,
128  STANDARD_SPEED_tRSTL,
129  STANDARD_SPEED_tMSI,
130  STANDARD_SPEED_tMSP,
131  STANDARD_SPEED_tRSTH,
132  STANDARD_SPEED_tW0L,
133  STANDARD_SPEED_tW1L,
134  STANDARD_SPEED_tMSR,
135  STANDARD_SPEED_tREC,
136  OVERDRIVE_SPEED_tRSTL,
137  OVERDRIVE_SPEED_tMSI,
138  OVERDRIVE_SPEED_tMSP,
139  OVERDRIVE_SPEED_tRSTH,
140  OVERDRIVE_SPEED_tW0L,
141  OVERDRIVE_SPEED_tW1L,
142  OVERDRIVE_SPEED_tMSR,
143  OVERDRIVE_SPEED_tREC,
144  RPUP_BUF,
145  PDSLEW,
146  RESERVED,
147  ALL,
148 } DS2485_configuration_register_address_T;
149 
150 /* 1-Wire Delays*/
151 typedef enum {
152  ms_0,
153  ms_2,
154  ms_4,
155  ms_6,
156  ms_8,
157  ms_10,
158  ms_12,
159  ms_14,
160  ms_16,
161  ms_18,
162  ms_20,
163  ms_22,
164  ms_24,
165  ms_26,
166  ms_28,
167  ms_30,
168  ms_32,
169  ms_34,
170  ms_36,
171  ms_38,
172  ms_40,
173  ms_42,
174  ms_44,
175  ms_46,
176  ms_48,
177  ms_50,
178  ms_52,
179  ms_54,
180  ms_56,
181  ms_58,
182  ms_60,
183  ms_62,
184  ms_64,
185  ms_66,
186  ms_68,
187  ms_70,
188  ms_72,
189  ms_74,
190  ms_76,
191  ms_78,
192  ms_80,
193  ms_82,
194  ms_84,
195  ms_86,
196  ms_88,
197  ms_90,
198  ms_92,
199  ms_94,
200  ms_96,
201  ms_98,
202  ms_100,
203  ms_102,
204  ms_104,
205  ms_106,
206  ms_108,
207  ms_110,
208  ms_112,
209  ms_114,
210  ms_116,
211  ms_118,
212  ms_120,
213  ms_122,
214  ms_124,
215  ms_126,
216  ms_128,
217  ms_130,
218  ms_132,
219  ms_134,
220  ms_136,
221  ms_138,
222  ms_140,
223  ms_142,
224  ms_144,
225  ms_146,
226  ms_148,
227  ms_150,
228  ms_152,
229  ms_154,
230  ms_156,
231  ms_158,
232  ms_160,
233  ms_162,
234  ms_164,
235  ms_166,
236  ms_168,
237  ms_170,
238  ms_172,
239  ms_174,
240  ms_176,
241  ms_178,
242  ms_180,
243  ms_182,
244  ms_184,
245  ms_186,
246  ms_188,
247  ms_190,
248  ms_192,
249  ms_194,
250  ms_196,
251  ms_198,
252  ms_200,
253  ms_202,
254  ms_204,
255  ms_206,
256  ms_208,
257  ms_210,
258  ms_212,
259  ms_214,
260  ms_216,
261  ms_218,
262  ms_220,
263  ms_222,
264  ms_224,
265  ms_226,
266  ms_228,
267  ms_230,
268  ms_232,
269  ms_234,
270  ms_236,
271  ms_238,
272  ms_240,
273  ms_242,
274  ms_244,
275  ms_246,
276  ms_248,
277  ms_250,
278  ms_252,
279  ms_254,
280  ms_256,
281  ms_258,
282  ms_260,
283  ms_262,
284  ms_264,
285  ms_266,
286  ms_268,
287  ms_270,
288  ms_272,
289  ms_274,
290  ms_276,
291  ms_278,
292  ms_280,
293  ms_282,
294  ms_284,
295  ms_286,
296  ms_288,
297  ms_290,
298  ms_292,
299  ms_294,
300  ms_296,
301  ms_298,
302  ms_300,
303  ms_302,
304  ms_304,
305  ms_306,
306  ms_308,
307  ms_310,
308  ms_312,
309  ms_314,
310  ms_316,
311  ms_318,
312  ms_320,
313  ms_322,
314  ms_324,
315  ms_326,
316  ms_328,
317  ms_330,
318  ms_332,
319  ms_334,
320  ms_336,
321  ms_338,
322  ms_340,
323  ms_342,
324  ms_344,
325  ms_346,
326  ms_348,
327  ms_350,
328  ms_352,
329  ms_354,
330  ms_356,
331  ms_358,
332  ms_360,
333  ms_362,
334  ms_364,
335  ms_366,
336  ms_368,
337  ms_370,
338  ms_372,
339  ms_374,
340  ms_376,
341  ms_378,
342  ms_380,
343  ms_382,
344  ms_384,
345  ms_386,
346  ms_388,
347  ms_390,
348  ms_392,
349  ms_394,
350  ms_396,
351  ms_398,
352  ms_400,
353  ms_402,
354  ms_404,
355  ms_406,
356  ms_408,
357  ms_410,
358  ms_412,
359  ms_414,
360  ms_416,
361  ms_418,
362  ms_420,
363  ms_422,
364  ms_424,
365  ms_426,
366  ms_428,
367  ms_430,
368  ms_432,
369  ms_434,
370  ms_436,
371  ms_438,
372  ms_440,
373  ms_442,
374  ms_444,
375  ms_446,
376  ms_448,
377  ms_450,
378  ms_452,
379  ms_454,
380  ms_456,
381  ms_458,
382  ms_460,
383  ms_462,
384  ms_464,
385  ms_466,
386  ms_468,
387  ms_470,
388  ms_472,
389  ms_474,
390  ms_476,
391  ms_478,
392  ms_480,
393  ms_482,
394  ms_484,
395  ms_486,
396  ms_488,
397  ms_490,
398  ms_492,
399  ms_494,
400  ms_496,
401  ms_498,
402  ms_500,
403  ms_502,
404  ms_504,
405  ms_506,
406  ms_508,
407  ms_510,
408 } DS2485_full_command_sequence_delays_msecs_T;
409 
410 /* Device Function Commands */
411 int DS2485_WriteMemory(DS2485_memory_page_T pgNumber, const uint8_t *pgData);
412 int DS2485_ReadMemory(DS2485_memory_page_T pgNumber, uint8_t *pgData);
413 int DS2485_ReadStatus(DS2485_status_outputs_T output, uint8_t *status);
414 int DS2485_SetI2cAddress(uint8_t newAddress);
415 int DS2485_SetPageProtection(DS2485_memory_page_T pgNumber, DS2485_page_protection_T protection);
416 int DS2485_ReadOneWirePortConfig(DS2485_configuration_register_address_T reg, uint8_t *regData);
417 int DS2485_WriteOneWirePortConfig(DS2485_configuration_register_address_T reg, const uint8_t *regData);
418 int DS2485_MasterReset(void);
419 int DS2485_OneWireScript(const uint8_t *script, uint8_t script_length, double accumulativeOneWireTime, uint8_t commandsCount, uint8_t *scriptResponse, uint8_t scriptResponse_length);
420 int DS2485_OneWireBlock(const uint8_t *blockData, int blockData_Length, uint8_t *ow_data, bool ow_reset, bool ignore, bool spu, bool pe); // blockData should include read bytes as FFh
421 int DS2485_OneWireWriteBlock(const uint8_t *writeData, int writeData_Length, bool ow_reset, bool ignore, bool spu);
422 int DS2485_OneWireReadBlock(uint8_t *readData, uint8_t bytes);
423 int DS2485_OneWireSearch(uint8_t *romId, uint8_t code, bool ow_reset, bool ignore, bool search_rst, bool *flag);
424 int DS2485_FullCommandSequence(const uint8_t *owData, int owData_Length, uint8_t *rom_id, DS2485_full_command_sequence_delays_msecs_T ow_delay_msecs, uint8_t *ow_rslt_data, uint8_t ow_rslt_len);
425 int DS2485_ComputeCrc16(const uint8_t *crcData, int crcData_Length, uint8_t *crc16);
426 
427 /// Platform-specific I2C command interface implemented in DS2485_port_xxxx.c Returns 'error' (0 if completed OK) */
428 int DS2485_ExecuteCommand(const uint8_t *packet, int packetSize, int delay_uSec, uint8_t *response, int responseSize);
429 
430 #ifdef __cplusplus
431 }
432 #endif
433 
434 #endif /* DS2485_H_INCLUDED */
int DS2485_ExecuteCommand(const uint8_t *packet, int packetSize, int delay_uSec, uint8_t *response, int responseSize)
Platform-specific I2C command interface implemented in DS2485_port_xxxx.c Returns &#39;error&#39; (0 if compl...