LibDriver HDC1080
Loading...
Searching...
No Matches
driver_hdc1080_register_test.c
Go to the documentation of this file.
1
36
38
39static hdc1080_handle_t gs_handle;
40
49{
50 uint8_t res;
51 uint8_t id[6];
52 hdc1080_info_t info;
53 hdc1080_bool_t enable;
55 hdc1080_mode_t mode;
58
59 /* link interface function */
68
69 /* get information */
70 res = hdc1080_info(&info);
71 if (res != 0)
72 {
73 hdc1080_interface_debug_print("hdc1080: get info failed.\n");
74
75 return 1;
76 }
77 else
78 {
79 /* print chip info */
80 hdc1080_interface_debug_print("hdc1080: chip is %s.\n", info.chip_name);
81 hdc1080_interface_debug_print("hdc1080: manufacturer is %s.\n", info.manufacturer_name);
82 hdc1080_interface_debug_print("hdc1080: interface is %s.\n", info.interface);
83 hdc1080_interface_debug_print("hdc1080: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
84 hdc1080_interface_debug_print("hdc1080: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
85 hdc1080_interface_debug_print("hdc1080: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
86 hdc1080_interface_debug_print("hdc1080: max current is %0.2fmA.\n", info.max_current_ma);
87 hdc1080_interface_debug_print("hdc1080: max temperature is %0.1fC.\n", info.temperature_max);
88 hdc1080_interface_debug_print("hdc1080: min temperature is %0.1fC.\n", info.temperature_min);
89 }
90
91 /* start register test */
92 hdc1080_interface_debug_print("hdc1080: start register test.\n");
93
94 /* init */
95 res = hdc1080_init(&gs_handle);
96 if (res != 0)
97 {
98 hdc1080_interface_debug_print("hdc1080: init failed.\n");
99
100 return 1;
101 }
102
103 /* hdc1080_get_serial_id test */
104 hdc1080_interface_debug_print("hdc1080: hdc1080_get_serial_id test.\n");
105
106 /* get serial id */
107 res = hdc1080_get_serial_id(&gs_handle, id);
108 if (res != 0)
109 {
110 hdc1080_interface_debug_print("hdc1080: get serial id failed.\n");
111 (void)hdc1080_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* output */
117 hdc1080_interface_debug_print("hdc1080: serial id is 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\n",
118 id[0], id[1], id[2], id[3], id[4], id[5]);
119
120 /* hdc1080_get_battery_status test */
121 hdc1080_interface_debug_print("hdc1080: hdc1080_get_battery_status test.\n");
122
123 /* get battery status */
124 res = hdc1080_get_battery_status(&gs_handle, &status);
125 if (res != 0)
126 {
127 hdc1080_interface_debug_print("hdc1080: get battery status failed.\n");
128 (void)hdc1080_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* output */
134 hdc1080_interface_debug_print("hdc1080: battery status is %s.\n",
135 status == HDC1080_BATTERY_STATUS_OVER_2P8_V ? "over 2.8V" : "less 2.8V");
136
137 /* hdc1080_set_heater/hdc1080_get_heater test test */
138 hdc1080_interface_debug_print("hdc1080: hdc1080_set_heater/hdc1080_get_heater test.\n");
139
140 /* disable heater */
141 res = hdc1080_set_heater(&gs_handle, HDC1080_BOOL_FALSE);
142 if (res != 0)
143 {
144 hdc1080_interface_debug_print("hdc1080: set heater failed.\n");
145 (void)hdc1080_deinit(&gs_handle);
146
147 return 1;
148 }
149
150 /* disable heater */
151 hdc1080_interface_debug_print("hdc1080: disable heater.\n");
152
153 /* get heater */
154 res = hdc1080_get_heater(&gs_handle, &enable);
155 if (res != 0)
156 {
157 hdc1080_interface_debug_print("hdc1080: get heater failed.\n");
158 (void)hdc1080_deinit(&gs_handle);
159
160 return 1;
161 }
162
163 /* output */
164 hdc1080_interface_debug_print("hdc1080: check heater %s.\n", enable == HDC1080_BOOL_FALSE ? "ok" : "error");
165
166 /* enable heater */
167 res = hdc1080_set_heater(&gs_handle, HDC1080_BOOL_TRUE);
168 if (res != 0)
169 {
170 hdc1080_interface_debug_print("hdc1080: set heater failed.\n");
171 (void)hdc1080_deinit(&gs_handle);
172
173 return 1;
174 }
175
176 /* enable heater */
177 hdc1080_interface_debug_print("hdc1080: enable heater.\n");
178
179 /* get heater */
180 res = hdc1080_get_heater(&gs_handle, &enable);
181 if (res != 0)
182 {
183 hdc1080_interface_debug_print("hdc1080: get heater failed.\n");
184 (void)hdc1080_deinit(&gs_handle);
185
186 return 1;
187 }
188
189 /* output */
190 hdc1080_interface_debug_print("hdc1080: check heater %s.\n", enable == HDC1080_BOOL_TRUE ? "ok" : "error");
191
192 /* hdc1080_set_mode/hdc1080_get_mode test */
193 hdc1080_interface_debug_print("hdc1080: hdc1080_set_mode/hdc1080_get_mode test.\n");
194
195 /* temperature or humidity is acquired mode */
196 res = hdc1080_set_mode(&gs_handle, HDC1080_MODE_OR);
197 if (res != 0)
198 {
199 hdc1080_interface_debug_print("hdc1080: set mode failed.\n");
200 (void)hdc1080_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* temperature or humidity is acquired mode */
206 hdc1080_interface_debug_print("hdc1080: temperature or humidity is acquired mode.\n");
207
208 /* get mode */
209 res = hdc1080_get_mode(&gs_handle, &mode);
210 if (res != 0)
211 {
212 hdc1080_interface_debug_print("hdc1080: get mode failed.\n");
213 (void)hdc1080_deinit(&gs_handle);
214
215 return 1;
216 }
217
218 /* output */
219 hdc1080_interface_debug_print("hdc1080: check mode %s.\n", mode == HDC1080_MODE_OR ? "ok" : "error");
220
221 /* temperature and humidity are acquired in sequence */
222 res = hdc1080_set_mode(&gs_handle, HDC1080_MODE_SEQUENCE);
223 if (res != 0)
224 {
225 hdc1080_interface_debug_print("hdc1080: set mode failed.\n");
226 (void)hdc1080_deinit(&gs_handle);
227
228 return 1;
229 }
230
231 /* temperature and humidity are acquired in sequence mode */
232 hdc1080_interface_debug_print("hdc1080: temperature and humidity are acquired in sequence mode.\n");
233
234 /* get mode */
235 res = hdc1080_get_mode(&gs_handle, &mode);
236 if (res != 0)
237 {
238 hdc1080_interface_debug_print("hdc1080: get mode failed.\n");
239 (void)hdc1080_deinit(&gs_handle);
240
241 return 1;
242 }
243
244 /* output */
245 hdc1080_interface_debug_print("hdc1080: check mode %s.\n", mode == HDC1080_MODE_SEQUENCE ? "ok" : "error");
246
247 /* hdc1080_set_temperature_resolution/hdc1080_get_temperature_resolution test */
248 hdc1080_interface_debug_print("hdc1080: hdc1080_set_temperature_resolution/hdc1080_get_temperature_resolution test.\n");
249
250 /* 11 bit */
252 if (res != 0)
253 {
254 hdc1080_interface_debug_print("hdc1080: set temperature resolution failed.\n");
255 (void)hdc1080_deinit(&gs_handle);
256
257 return 1;
258 }
259
260 /* 11 bit */
261 hdc1080_interface_debug_print("hdc1080: set temperature resolution 11 bit.\n");
262
263 /* get temperature resolution */
264 res = hdc1080_get_temperature_resolution(&gs_handle, &t_resolution);
265 if (res != 0)
266 {
267 hdc1080_interface_debug_print("hdc1080: get temperature resolution failed.\n");
268 (void)hdc1080_deinit(&gs_handle);
269
270 return 1;
271 }
272
273 /* output */
274 hdc1080_interface_debug_print("hdc1080: check temperature resolution %s.\n", t_resolution == HDC1080_TEMPERATURE_RESOLUTION_11_BIT ? "ok" : "error");
275
276 /* 14 bit */
278 if (res != 0)
279 {
280 hdc1080_interface_debug_print("hdc1080: set temperature resolution failed.\n");
281 (void)hdc1080_deinit(&gs_handle);
282
283 return 1;
284 }
285
286 /* 14 bit */
287 hdc1080_interface_debug_print("hdc1080: set temperature resolution 14 bit.\n");
288
289 /* get temperature resolution */
290 res = hdc1080_get_temperature_resolution(&gs_handle, &t_resolution);
291 if (res != 0)
292 {
293 hdc1080_interface_debug_print("hdc1080: get temperature resolution failed.\n");
294 (void)hdc1080_deinit(&gs_handle);
295
296 return 1;
297 }
298
299 /* output */
300 hdc1080_interface_debug_print("hdc1080: check temperature resolution %s.\n", t_resolution == HDC1080_TEMPERATURE_RESOLUTION_14_BIT ? "ok" : "error");
301
302 /* hdc1080_set_humidity_resolution/hdc1080_get_humidity_resolution test */
303 hdc1080_interface_debug_print("hdc1080: hdc1080_set_humidity_resolution/hdc1080_get_humidity_resolution test.\n");
304
305 /* 8 bit */
307 if (res != 0)
308 {
309 hdc1080_interface_debug_print("hdc1080: set humidity resolution failed.\n");
310 (void)hdc1080_deinit(&gs_handle);
311
312 return 1;
313 }
314
315 /* set humidity resolution 8 bit */
316 hdc1080_interface_debug_print("hdc1080: set humidity resolution 8 bit.\n");
317
318 /* get humidity resolution */
319 res = hdc1080_get_humidity_resolution(&gs_handle, &h_resolution);
320 if (res != 0)
321 {
322 hdc1080_interface_debug_print("hdc1080: get humidity resolution failed.\n");
323 (void)hdc1080_deinit(&gs_handle);
324
325 return 1;
326 }
327
328 /* output */
329 hdc1080_interface_debug_print("hdc1080: check humidity resolution %s.\n", h_resolution == HDC1080_HUMIDITY_RESOLUTION_8_BIT ? "ok" : "error");
330
331 /* 11 bit */
333 if (res != 0)
334 {
335 hdc1080_interface_debug_print("hdc1080: set humidity resolution failed.\n");
336 (void)hdc1080_deinit(&gs_handle);
337
338 return 1;
339 }
340
341 /* set humidity resolution 11 bit */
342 hdc1080_interface_debug_print("hdc1080: set humidity resolution 11 bit.\n");
343
344 /* get humidity resolution */
345 res = hdc1080_get_humidity_resolution(&gs_handle, &h_resolution);
346 if (res != 0)
347 {
348 hdc1080_interface_debug_print("hdc1080: get humidity resolution failed.\n");
349 (void)hdc1080_deinit(&gs_handle);
350
351 return 1;
352 }
353
354 /* output */
355 hdc1080_interface_debug_print("hdc1080: check humidity resolution %s.\n", h_resolution == HDC1080_HUMIDITY_RESOLUTION_11_BIT ? "ok" : "error");
356
357 /* 14 bit */
359 if (res != 0)
360 {
361 hdc1080_interface_debug_print("hdc1080: set humidity resolution failed.\n");
362 (void)hdc1080_deinit(&gs_handle);
363
364 return 1;
365 }
366
367 /* set humidity resolution 14 bit */
368 hdc1080_interface_debug_print("hdc1080: set humidity resolution 14 bit.\n");
369
370 /* get humidity resolution */
371 res = hdc1080_get_humidity_resolution(&gs_handle, &h_resolution);
372 if (res != 0)
373 {
374 hdc1080_interface_debug_print("hdc1080: get humidity resolution failed.\n");
375 (void)hdc1080_deinit(&gs_handle);
376
377 return 1;
378 }
379
380 /* output */
381 hdc1080_interface_debug_print("hdc1080: check humidity resolution %s.\n", h_resolution == HDC1080_HUMIDITY_RESOLUTION_14_BIT ? "ok" : "error");
382
383 /* hdc1080_software_reset test */
384 hdc1080_interface_debug_print("hdc1080: hdc1080_software_reset test.\n");
385
386 /* software reset */
387 res = hdc1080_software_reset(&gs_handle);
388 if (res != 0)
389 {
390 hdc1080_interface_debug_print("hdc1080: software reset failed.\n");
391 (void)hdc1080_deinit(&gs_handle);
392
393 return 1;
394 }
395
396 /* finish register */
397 hdc1080_interface_debug_print("hdc1080: finish register test.\n");
398 (void)hdc1080_deinit(&gs_handle);
399
400 return 0;
401}
driver hdc1080 register test header file
uint8_t hdc1080_get_serial_id(hdc1080_handle_t *handle, uint8_t id[6])
get serial id
uint8_t hdc1080_info(hdc1080_info_t *info)
get chip's information
struct hdc1080_info_s hdc1080_info_t
hdc1080 information structure definition
uint8_t hdc1080_get_temperature_resolution(hdc1080_handle_t *handle, hdc1080_temperature_resolution_t *resolution)
get temperature resolution
uint8_t hdc1080_get_battery_status(hdc1080_handle_t *handle, hdc1080_battery_status_t *status)
get battery status
struct hdc1080_handle_s hdc1080_handle_t
hdc1080 handle structure definition
hdc1080_humidity_resolution_t
hdc1080 humidity resolution enumeration definition
hdc1080_mode_t
hdc1080 mode enumeration definition
hdc1080_temperature_resolution_t
hdc1080 temperature resolution enumeration definition
uint8_t hdc1080_deinit(hdc1080_handle_t *handle)
close the chip
uint8_t hdc1080_set_heater(hdc1080_handle_t *handle, hdc1080_bool_t enable)
enable or disable heater
uint8_t hdc1080_set_mode(hdc1080_handle_t *handle, hdc1080_mode_t mode)
set the chip mode
uint8_t hdc1080_get_humidity_resolution(hdc1080_handle_t *handle, hdc1080_humidity_resolution_t *resolution)
get humidity resolution
uint8_t hdc1080_set_humidity_resolution(hdc1080_handle_t *handle, hdc1080_humidity_resolution_t resolution)
set humidity resolution
uint8_t hdc1080_init(hdc1080_handle_t *handle)
initialize the chip
hdc1080_battery_status_t
hdc1080 battery status enumeration definition
uint8_t hdc1080_get_heater(hdc1080_handle_t *handle, hdc1080_bool_t *enable)
get the heater status
uint8_t hdc1080_software_reset(hdc1080_handle_t *handle)
software reset
uint8_t hdc1080_get_mode(hdc1080_handle_t *handle, hdc1080_mode_t *mode)
get the chip mode
uint8_t hdc1080_set_temperature_resolution(hdc1080_handle_t *handle, hdc1080_temperature_resolution_t resolution)
set temperature resolution
hdc1080_bool_t
hdc1080 bool enumeration definition
@ HDC1080_HUMIDITY_RESOLUTION_8_BIT
@ HDC1080_HUMIDITY_RESOLUTION_11_BIT
@ HDC1080_HUMIDITY_RESOLUTION_14_BIT
@ HDC1080_MODE_OR
@ HDC1080_MODE_SEQUENCE
@ HDC1080_TEMPERATURE_RESOLUTION_14_BIT
@ HDC1080_TEMPERATURE_RESOLUTION_11_BIT
@ HDC1080_BATTERY_STATUS_OVER_2P8_V
@ HDC1080_BOOL_FALSE
@ HDC1080_BOOL_TRUE
uint8_t hdc1080_interface_iic_read_with_wait(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with wait
void hdc1080_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t hdc1080_interface_iic_deinit(void)
interface iic bus deinit
void hdc1080_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hdc1080_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t hdc1080_interface_iic_init(void)
interface iic bus init
uint8_t hdc1080_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t hdc1080_register_test(void)
register test
uint32_t driver_version
char manufacturer_name[32]