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  5
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 /**
62  * @brief Options for I2C interface.
63  */
64 typedef struct
65 {
66   /**
67    * @brief The sensor's I2C address.
68    */
69   uint8_t address;
70 
71   /**
72    * @brief Enables receiving of multiple bytes in a single read operation.
73    */
74   uint8_t burstMode : 1;
75 
76   /**
77    * @brief Enables slave-transmitter mode (i.e. read-only, polling mode IO operation).
78    * In this mode, no register addresses are used.
79    * Data is polled from the sensor by sending the I2C address and read bit.
80    */
81   uint8_t slaveTransmitterMode : 1;
82 
83   /**
84    * @brief Enables usage of most significant bit of I2C register address to enable
85    * multi byte read (required e.g. by HIDS humidity sensor).
86    */
87   uint8_t useRegAddrMsbForMultiBytesRead : 1;
88 
89   /**
90    * @brief Currently unused.
91    */
92   uint8_t reserved : 5;
93 } WE_i2cOptions_t;
94 
95 
96 /**
97  * @brief Options for SPI interface.
98  */
99 typedef struct
100 {
101   /**
102    * @brief HAL port of chip select pin. The type of the port depends on the platform.
103    */
104   void *chipSelectPort;
105 
106   /**
107    * @brief Pin to use for chip select.
108    */
109   uint16_t chipSelectPin;
110 
111   /**
112    * @brief Enables receiving of multiple bytes in a single read operation.
113    */
114   uint8_t burstMode : 1;
115 
116   /**
117    * @brief Currently unused.
118    */
119   uint8_t reserved : 7;
120 } WE_spiOptions_t;
121 
122 
123 /**
124  * @brief Interface options.
125  */
126 typedef struct
127 {
128   /**
129    * @brief I2C interface options.
130    */
131   WE_i2cOptions_t i2c;
132 
133   /**
134      * @brief SPI interface options.
135      */
136   WE_spiOptions_t spi;
137 
138   /**
139    * @brief Timeout (ms) for read operations.
140    */
141   uint16_t readTimeout;
142 
143   /**
144    * @brief Timeout (ms) for write operations.
145    */
146   uint16_t writeTimeout;
147 } WE_sensorInterfaceOptions_t;
148 
149 
150 /**
151  * @brief Sensor interface configuration structure.
152  */
153 typedef struct
154 {
155   /**
156    * @brief Sensor type specifier.
157    */
158   WE_sensorType_t sensorType;
159 
160   /**
161    * @brief Specifies the interface to be used to communicate with the sensor.
162    */
163   WE_sensorInterfaceType_t interfaceType;
164 
165   /**
166    * @brief Options of sensor interface.
167    */
168   WE_sensorInterfaceOptions_t options;
169 
170   /**
171    * @brief HAL interface handle. The type of the handle depends on the interface used.
172    */
173   void *handle;
174 } WE_sensorInterface_t;
175 
176 #endif /* WE_SENSORS_SDK_H_INCLUDED */
177