1 /*
2  * Copyright (c) 2023 Wuerth Elektronik eiSos GmbH & Co. KG
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief This is the main header file of the WE Sensors SDK.
10  */
11 
12 #ifndef WE_SENSORS_SDK_H_INCLUDED
13 #define WE_SENSORS_SDK_H_INCLUDED
14 
15 
16 /**
17  * @brief SDK major version number.
18  */
19 #define WE_SENSOR_SDK_MAJOR_VERSION  2
20 
21 /**
22  * @brief SDK minor version number.
23  */
24 #define WE_SENSOR_SDK_MINOR_VERSION  6
25 
26 /**
27  * @brief Return code for successful operations.
28  */
29 #define WE_SUCCESS   0
30 
31 /**
32  * @brief Return code for failed operations.
33  */
34 #define WE_FAIL     -1
35 
36 /**
37  * @brief Types of sensors supported by the WE Sensors SDK.
38  */
39 typedef enum
40 {
41   WE_HIDS,  /* Humidity sensor */
42   WE_ITDS,  /* Acceleration sensor */
43   WE_TIDS,  /* Temperature sensor */
44   WE_PADS,  /* Absolute pressure sensor */
45   WE_PDUS,  /* Differential pressure sensor */
46   WE_ISDS,  /* 3D accelerometer and 3D gyroscope */
47   WE_SENSOR_TYPE_MAX
48 } WE_sensorType_t;
49 
50 
51 /**
52  * @brief Supported digital interfaces of the sensors.
53  */
54 typedef enum
55 {
56   WE_i2c,
57   WE_spi
58 } WE_sensorInterfaceType_t;
59 
60 /**
61  * @brief Protocols for I2C interface.
62  */
63 typedef enum
64 {
65 	/**
66 	* @brief I2C protocol where you need to specify which register you are writing to or reading from.
67 	*/
68 	WE_i2cProtocol_RegisterBased = 0x0,
69 
70 	/**
71 	* @brief I2C protocol to deal with raw data.
72 	*/
73 	WE_i2cProtocol_Raw = 0x1
74 } WE_i2cProtocol_t;
75 
76 /**
77  * @brief Options for I2C interface.
78  */
79 typedef struct
80 {
81   /**
82    * @brief The sensor's I2C address.
83    */
84   uint8_t address;
85 
86   /**
87    * @brief Enables receiving of multiple bytes in a single read operation.
88    */
89   uint8_t burstMode : 1;
90 
91   /**
92    * @brief Selects the I2C protocol used for reading and writing.
93    */
94   WE_i2cProtocol_t protocol : 1;
95 
96   /**
97    * @brief Enables usage of most significant bit of I2C register address to enable
98    * multi byte read (required e.g. by HIDS humidity sensor).
99    */
100   uint8_t useRegAddrMsbForMultiBytesRead : 1;
101 
102   /**
103    * @brief Currently unused.
104    */
105   uint8_t reserved : 5;
106 } WE_i2cOptions_t;
107 
108 
109 /**
110  * @brief Options for SPI interface.
111  */
112 typedef struct
113 {
114   /**
115    * @brief HAL port of chip select pin. The type of the port depends on the platform.
116    */
117   void *chipSelectPort;
118 
119   /**
120    * @brief Pin to use for chip select.
121    */
122   uint16_t chipSelectPin;
123 
124   /**
125    * @brief Enables receiving of multiple bytes in a single read operation.
126    */
127   uint8_t burstMode : 1;
128 
129   /**
130    * @brief Currently unused.
131    */
132   uint8_t reserved : 7;
133 } WE_spiOptions_t;
134 
135 
136 /**
137  * @brief Interface options.
138  */
139 typedef struct
140 {
141   /**
142    * @brief I2C interface options.
143    */
144   WE_i2cOptions_t i2c;
145 
146   /**
147      * @brief SPI interface options.
148      */
149   WE_spiOptions_t spi;
150 
151   /**
152    * @brief Timeout (ms) for read operations.
153    */
154   uint16_t readTimeout;
155 
156   /**
157    * @brief Timeout (ms) for write operations.
158    */
159   uint16_t writeTimeout;
160 } WE_sensorInterfaceOptions_t;
161 
162 
163 /**
164  * @brief Sensor interface configuration structure.
165  */
166 typedef struct
167 {
168   /**
169    * @brief Sensor type specifier.
170    */
171   WE_sensorType_t sensorType;
172 
173   /**
174    * @brief Specifies the interface to be used to communicate with the sensor.
175    */
176   WE_sensorInterfaceType_t interfaceType;
177 
178   /**
179    * @brief Options of sensor interface.
180    */
181   WE_sensorInterfaceOptions_t options;
182 
183   /**
184    * @brief HAL interface handle. The type of the handle depends on the interface used.
185    */
186   void *handle;
187 } WE_sensorInterface_t;
188 
189 #endif /* WE_SENSORS_SDK_H_INCLUDED */
190