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