1-Wire and ENS210 driver stack
DS28E18.h
Go to the documentation of this file.
1 // DS28E18.h - Driver for DS2818E slave one 1-Wire bus
2 // Cleaned up by Dave Nadler 30-October-2023
3 
4 /*******************************************************************************
5 * Copyright (C) Maxim Integrated Products, Inc., All rights Reserved.
6 *
7 * This software is protected by copyright laws of the United States and
8 * of foreign countries. This material may also be protected by patent laws
9 * and technology transfer regulations of the United States and of foreign
10 * countries. This software is furnished under a license agreement and/or a
11 * nondisclosure agreement and may only be used or reproduced in accordance
12 * with the terms of those agreements. Dissemination of this information to
13 * any party or parties not specified in the license agreement and/or
14 * nondisclosure agreement is expressly prohibited.
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
23 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 *
27 * Except as contained in this notice, the name of Maxim Integrated
28 * Products, Inc. shall not be used except as stated in the Maxim Integrated
29 * Products, Inc. Branding Policy.
30 *
31 * The mere transfer of this software does not imply any licenses
32 * of trade secrets, proprietary technology, copyrights, patents,
33 * trademarks, maskwork rights, or any other form of intellectual
34 * property whatsoever. Maxim Integrated Products, Inc. retains all
35 * ownership rights.
36 *******************************************************************************
37 */
38 
39 /**
40  * @file ds28e18.h
41  * @brief General library for the DS28E18.
42  */
43 
44  /* Define to prevent redundant inclusion */
45 #ifndef _DS28E18_H_
46 #define _DS28E18_H_
47 
48 /* **** Includes **** */
49 #include <stdint.h>
50 #include <stdbool.h>
51 #include "one_wire.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 typedef enum { // DS28E18_device_function_commands_T
58  COMMAND_START = 0x66,
59  WRITE_SEQUENCER = 0x11,
60  READ_SEQUENCER = 0x22,
61  RUN_SEQUENCER = 0x33,
62  WRITE_CONFIGURATION = 0x55,
63  READ_CONFIGURATION = 0x6A,
64  WRITE_GPIO_CONFIGURATION = 0x83,
65  READ_GPIO_CONFIGURATION = 0x7C,
66  DEVICE_STATUS = 0x7A,
67 } DS28E18_device_function_commands_T;
68 
69 typedef enum { // DS28E18_one_wire_rom_commands_T
70  READ_ROM = 0x33, ///< can only be used if there is a single slave on the bus
71  MATCH_ROM = 0x55, ///< address a specific slave by ROM ID
72  SEARCH_ROM = 0xF0, ///< enumeration of all slaves on bus
73  SKIP_ROM = 0xCC, ///< don't use ROM ID (applicable only when there is only 1 slave on the bus)
74  RESUME = 0xA5, ///
75  OVERDRIVE_SKIP = 0x3C,
76  OVERDRIVE_MATCH = 0x69, ///< selected (matched ROM ID) slave goes into overdrive
78 
79 typedef enum { // DS28E18_sequencer_commands_T
80  //I2C
81  I2C_START = 0x02,
82  I2C_STOP = 0x03,
83  I2C_WRITE_DATA = 0xE3,
84  I2C_READ_DATA = 0xD4,
85  I2C_READ_DATA_W_NACK_END = 0xD3,
86 
87  // SPI
88  SPI_WRITE_READ_BYTE = 0xC0,
89  SPI_WRITE_READ_BIT = 0xB0,
90  SPI_SS_HIGH = 0x01,
91  SPI_SS_LOW = 0x80,
92 
93  // Utility
94  UTILITY_DELAY = 0xDD,
95  UTILITY_SENS_VDD_ON = 0xCC,
96  UTILITY_SENS_VDD_OFF = 0xBB,
97  UTILITY_GPIO_BUF_WRITE = 0xD1,
98  UTILITY_GPIO_BUF_READ = 0x1D,
99  UTILITY_GPIO_CNTL_WRITE = 0xE2,
100  UTILITY_GPIO_CNTL_READ = 0x2E,
101 } DS28E18_sequencer_commands_T;
102 
103 typedef enum { // DS28E18_result_byte_T
104  POR_OCCURRED = 0x44,
105  EXECUTION_ERROR = 0x55,
106  INVALID_PARAMETER = 0x77,
107  NACK_OCCURED = 0x88,
108  SUCCESS = 0xAA,
109 } DS28E18_result_byte_T;
110 
111 typedef enum { // DS28E18_protocol_speed_T
112  KHZ_100,
113  KHZ_400,
114  KHZ_1000,
115  KHZ_2300,
116 } DS28E18_protocol_speed_T;
117 
118 typedef enum { // DS28E18_ignore_nack_T
119  DONT_IGNORE,
120  IGNORE,
121 } DS28E18_ignore_nack_T;
122 
123 typedef enum { // DS28E18_protocol_T
124  I2C,
125  SPI,
126 } DS28E18_protocol_T;
127 
128 typedef enum { // DS28E18_spi_mode_T
129  MODE_0 = 0x00,
130  MODE_3 = 0x03,
131 } DS28E18_spi_mode_T;
132 
133 typedef enum { // DS28E18_target_configuration_register_T
134  CONTROL = 0x0B,
135  BUFFER = 0x0C,
136 } DS28E18_target_configuration_register_T;
137 
138 /// DS28E18 delay command argument is an exponent: Delay is 2^arg in msec.
139 /// The actual delay time is from 1ms to 32s respectively
140 /// Code relies on enum defined as the exponent as below.
141 typedef enum { // DS28E18_utility_delay_T
142  DELAY_1msec = 0,
143  DELAY_2msec = 1,
144  DELAY_4msec = 2,
145  DELAY_8msec = 3,
146  DELAY_16msec = 4,
147  DELAY_32msec = 5,
148  DELAY_64msec = 6,
149  DELAY_128msec = 7,
150  DELAY_256msec = 8,
151  DELAY_512msec = 9,
152  DELAY_1024msec = 10,
153  DELAY_2048msec = 11,
154  DELAY_4096msec = 12,
155  DELAY_8192msec = 13,
156  DELAY_16384msec = 14,
157  DELAY_32768msec = 15,
159 
160 typedef struct { // DS28E18_sequence_T
161  uint8_t sequenceData[512];
162  int sequenceIdx;
163  unsigned int totalSequencerDelayTime; // milliseconds
165 
166 
167 /***** Globals *****/
168 
169 /// DS28E18 device addressed for current operations (may be one of many on 1-Wire bus)
171 
172 
173 /***** API *****/
174 
175 // High Level Functions
176 int DS28E18_Init(void);
177 int DS28E18_SetOnewireSpeed(one_wire_speeds spd);
180 
181 // Device Function Commands
182 bool DS28E18_WriteSequencer(unsigned short nineBitStartingAddress, const uint8_t *txData, int txDataSize);
183 bool DS28E18_ReadSequencer(unsigned short nineBitStartingAddress, uint8_t *rxData, unsigned short readLength);
184 bool DS28E18_RunSequencer(unsigned short nineBitStartingAddress, unsigned short runLength);
185 bool DS28E18_WriteConfiguration(DS28E18_protocol_speed_T SPD, DS28E18_ignore_nack_T INACK, DS28E18_protocol_T PROT, DS28E18_spi_mode_T SPI_MODE);
186 bool DS28E18_ReadConfiguration(uint8_t *rxData);
187 bool DS28E18_WriteGpioConfiguration(DS28E18_target_configuration_register_T CFG_REG_TARGET, uint8_t GPIO_HI, uint8_t GPIO_LO);
188 bool DS28E18_ReadGpioConfiguration(uint8_t CFG_REG_TARGET, uint8_t *rxData);
189 bool DS28E18_DeviceStatus(uint8_t *rxData);
190 
191 // Utilities to build and use a packet of Sequencer Commands
197 void DS28E18_BuildPacket_I2C_WriteData(const uint8_t *i2cData, uint8_t i2cDataSize);
198 unsigned short DS28E18_BuildPacket_I2C_ReadData(int readBytes);
199 unsigned short DS28E18_BuildPacket_I2C_ReadDataWithNackEnd(int readBytes);
200 unsigned short DS28E18_BuildPacket_SPI_WriteReadByte(const uint8_t *spiWriteData, uint8_t spiWriteDataSize, int readBytes, bool fullDuplex);
201 unsigned short DS28E18_BuildPacket_SPI_WriteReadBit(const uint8_t *spiWriteData, uint8_t spiWriteDataSize, int writeBits, int readBits);
207 void DS28E18_BuildPacket_Utility_GpioBufferWrite(uint8_t GPIO_BUF);
208 unsigned short DS28E18_BuildPacket_Utility_GpioBufferRead(void);
209 void DS28E18_BuildPacket_Utility_GpioControlWrite(uint8_t GPIO_CRTL_HI, uint8_t GPIO_CRTL_LO);
211 void DS28E18_BuildPacket_Append(const uint8_t* sequencerCmds, size_t length);
213 
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif /* _DS28E18_H_ */
220 
void DS28E18_BuildPacket_I2C_WriteData(const uint8_t *i2cData, uint8_t i2cDataSize)
Definition: DS28E18.c:729
bool DS28E18_WriteConfiguration(DS28E18_protocol_speed_T SPD, DS28E18_ignore_nack_T INACK, DS28E18_protocol_T PROT, DS28E18_spi_mode_T SPI_MODE)
Definition: DS28E18.c:550
void DS28E18_BuildPacket_SPI_SlaveSelectLow(void)
Definition: DS28E18.c:1039
void DS28E18_BuildPacket_Utility_GpioBufferWrite(uint8_t GPIO_BUF)
Definition: DS28E18.c:1083
unsigned short DS28E18_BuildPacket_SPI_WriteReadBit(const uint8_t *spiWriteData, uint8_t spiWriteDataSize, int writeBits, int readBits)
Definition: DS28E18.c:906
void DS28E18_BuildPacket_Append(const uint8_t *sequencerCmds, size_t length)
Append commands to locally constructed command sequencer packet.
Definition: DS28E18.c:687
DS28E18_utility_delay_T
Definition: DS28E18.h:141
unsigned short DS28E18_BuildPacket_SPI_WriteReadByte(const uint8_t *spiWriteData, uint8_t spiWriteDataSize, int readBytes, bool fullDuplex)
Definition: DS28E18.c:802
bool DS28E18_WriteGpioConfiguration(DS28E18_target_configuration_register_T CFG_REG_TARGET, uint8_t GPIO_HI, uint8_t GPIO_LO)
Definition: DS28E18.c:599
DS28E18_one_wire_rom_commands_T DS28E18_GetRomCommand(void)
Return the value of &#39;current_ROM_command&#39;.
Definition: DS28E18.c:217
void DS28E18_BuildPacket_Utility_Delay(DS28E18_utility_delay_T delayTimeInMsExponent)
Definition: DS28E18.c:1049
unsigned short DS28E18_BuildPacket_I2C_ReadData(int readBytes)
Definition: DS28E18.c:746
void DS28E18_BuildPacket_I2C_Start(void)
Definition: DS28E18.c:706
void DS28E18_BuildPacket_Utility_SensVddOff(void)
Definition: DS28E18.c:1071
unsigned short DS28E18_BuildPacket_I2C_ReadDataWithNackEnd(int readBytes)
Definition: DS28E18.c:773
can only be used if there is a single slave on the bus
Definition: DS28E18.h:70
unsigned short DS28E18_BuildPacket_Utility_GpioControlRead(void)
Definition: DS28E18.c:1122
bool DS28E18_BuildPacket_WriteAndRun(void)
Definition: DS28E18.c:694
unsigned short DS28E18_BuildPacket_Utility_GpioBufferRead(void)
Definition: DS28E18.c:1095
OneWire_ROM_ID_T type stores a 1-Wire address.
Definition: one_wire_address.h:15
void DS28E18_SetRomCommand(DS28E18_one_wire_rom_commands_T rom_cmd)
Definition: DS28E18.c:211
bool DS28E18_ReadGpioConfiguration(uint8_t CFG_REG_TARGET, uint8_t *rxData)
Definition: DS28E18.c:624
bool DS28E18_ReadConfiguration(uint8_t *rxData)
Definition: DS28E18.c:572
void DS28E18_BuildPacket_I2C_Stop(void)
Definition: DS28E18.c:716
Definition: DS28E18.h:160
OneWire_ROM_ID_T current_DS28E18_ROM_ID
DS28E18 device addressed for current operations (may be one of many on 1-Wire bus) ...
Definition: DS28E18.c:72
uint8_t * DS28E18_BuildPacket_GetSequencerPacket(void)
Get address of locally constructed command sequencer packet&#39;s data.
Definition: DS28E18.c:677
selected (matched ROM ID) slave goes into overdrive
Definition: DS28E18.h:76
void DS28E18_BuildPacket_ClearSequencerPacket(void)
Reset local command sequencer packet under construction.
Definition: DS28E18.c:670
int DS28E18_SetOnewireSpeed(one_wire_speeds spd)
Definition: DS28E18.c:180
don&#39;t use ROM ID (applicable only when there is only 1 slave on the bus)
Definition: DS28E18.h:73
void DS28E18_BuildPacket_SPI_SlaveSelectHigh(void)
Definition: DS28E18.c:1029
void DS28E18_BuildPacket_Utility_GpioControlWrite(uint8_t GPIO_CRTL_HI, uint8_t GPIO_CRTL_LO)
Definition: DS28E18.c:1110
bool DS28E18_DeviceStatus(uint8_t *rxData)
Definition: DS28E18.c:649
DS28E18_one_wire_rom_commands_T
Definition: DS28E18.h:69
bool DS28E18_RunSequencer(unsigned short nineBitStartingAddress, unsigned short runLength)
Definition: DS28E18.c:465
enumeration of all slaves on bus
Definition: DS28E18.h:72
int DS28E18_BuildPacket_GetSequencerPacketSize(void)
Get length of locally constructed command sequencer packet.
Definition: DS28E18.c:682
bool DS28E18_WriteSequencer(unsigned short nineBitStartingAddress, const uint8_t *txData, int txDataSize)
Definition: DS28E18.c:387
int DS28E18_Init(void)
Definition: DS28E18.c:110
void DS28E18_BuildPacket_Utility_SensVddOn(void)
Definition: DS28E18.c:1061
address a specific slave by ROM ID
Definition: DS28E18.h:71
General 1-Wire API using the DS2485 1-Wire master.
bool DS28E18_ReadSequencer(unsigned short nineBitStartingAddress, uint8_t *rxData, unsigned short readLength)
Definition: DS28E18.c:413