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