LibDriver CS1237
Loading...
Searching...
No Matches
driver_cs1237_register_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static cs1237_handle_t gs_handle;
41
50{
51 uint8_t res;
52 cs1237_bool_t enable;
54 cs1237_pga_t pga;
55 cs1237_channel_t channel;
56 cs1237_info_t info;
57
58 /* link interface function */
70
71 /* get information */
72 res = cs1237_info(&info);
73 if (res != 0)
74 {
75 cs1237_interface_debug_print("cs1237: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip info */
82 cs1237_interface_debug_print("cs1237: chip is %s.\n", info.chip_name);
83 cs1237_interface_debug_print("cs1237: manufacturer is %s.\n", info.manufacturer_name);
84 cs1237_interface_debug_print("cs1237: interface is %s.\n", info.interface);
85 cs1237_interface_debug_print("cs1237: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 cs1237_interface_debug_print("cs1237: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 cs1237_interface_debug_print("cs1237: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 cs1237_interface_debug_print("cs1237: max current is %0.2fmA.\n", info.max_current_ma);
89 cs1237_interface_debug_print("cs1237: max temperature is %0.1fC.\n", info.temperature_max);
90 cs1237_interface_debug_print("cs1237: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start register test */
94 cs1237_interface_debug_print("cs1237: start register test.\n");
95
96 /* init */
97 res = cs1237_init(&gs_handle);
98 if (res != 0)
99 {
100 cs1237_interface_debug_print("cs1237: init failed.\n");
101
102 return 1;
103 }
104
105 /* wake up */
106 res = cs1237_wake_up(&gs_handle);
107 if (res != 0)
108 {
109 cs1237_interface_debug_print("cs1237: wake up failed.\n");
110 (void)cs1237_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* cs1237_set_reference_voltage_output/cs1237_get_reference_voltage_output test */
116 cs1237_interface_debug_print("cs1237: cs1237_set_reference_voltage_output/cs1237_get_reference_voltage_output test.\n");
117
118 /* enable reference voltage output */
120 if (res != 0)
121 {
122 cs1237_interface_debug_print("cs1237: set reference voltage output failed.\n");
123 (void)cs1237_deinit(&gs_handle);
124
125 return 1;
126 }
127 cs1237_interface_debug_print("cs1237: enable reference voltage output.\n");
128 res = cs1237_get_reference_voltage_output(&gs_handle, &enable);
129 if (res != 0)
130 {
131 cs1237_interface_debug_print("cs1237: get reference voltage output failed.\n");
132 (void)cs1237_deinit(&gs_handle);
133
134 return 1;
135 }
136
137 /* output */
138 cs1237_interface_debug_print("cs1237: check reference voltage output %s.\n", (enable == CS1237_BOOL_TRUE) ? "ok" : "error");
139
140 /* disable reference voltage output */
142 if (res != 0)
143 {
144 cs1237_interface_debug_print("cs1237: set reference voltage output failed.\n");
145 (void)cs1237_deinit(&gs_handle);
146
147 return 1;
148 }
149 cs1237_interface_debug_print("cs1237: disable reference voltage output.\n");
150 res = cs1237_get_reference_voltage_output(&gs_handle, &enable);
151 if (res != 0)
152 {
153 cs1237_interface_debug_print("cs1237: get reference voltage output failed.\n");
154 (void)cs1237_deinit(&gs_handle);
155
156 return 1;
157 }
158
159 /* output */
160 cs1237_interface_debug_print("cs1237: check reference voltage output %s.\n", (enable == CS1237_BOOL_FALSE) ? "ok" : "error");
161
162 /* cs1237_set_adc_rate/cs1237_get_adc_rate test */
163 cs1237_interface_debug_print("cs1237: cs1237_set_adc_rate/cs1237_get_adc_rate test.\n");
164
165 /* set adc rate 10hz */
166 res = cs1237_set_adc_rate(&gs_handle, CS1237_ADC_RATE_10HZ);
167 if (res != 0)
168 {
169 cs1237_interface_debug_print("cs1237: set adc rate failed.\n");
170 (void)cs1237_deinit(&gs_handle);
171
172 return 1;
173 }
174 cs1237_interface_debug_print("cs1237: set adc rate 10hz.\n");
175 res = cs1237_get_adc_rate(&gs_handle, &rate);
176 if (res != 0)
177 {
178 cs1237_interface_debug_print("cs1237: get adc rate failed.\n");
179 (void)cs1237_deinit(&gs_handle);
180
181 return 1;
182 }
183
184 /* output */
185 cs1237_interface_debug_print("cs1237: check adc rate %s.\n", (rate == CS1237_ADC_RATE_10HZ) ? "ok" : "error");
186
187 /* set adc rate 40hz */
188 res = cs1237_set_adc_rate(&gs_handle, CS1237_ADC_RATE_40HZ);
189 if (res != 0)
190 {
191 cs1237_interface_debug_print("cs1237: set adc rate failed.\n");
192 (void)cs1237_deinit(&gs_handle);
193
194 return 1;
195 }
196 cs1237_interface_debug_print("cs1237: set adc rate 40hz.\n");
197 res = cs1237_get_adc_rate(&gs_handle, &rate);
198 if (res != 0)
199 {
200 cs1237_interface_debug_print("cs1237: get adc rate failed.\n");
201 (void)cs1237_deinit(&gs_handle);
202
203 return 1;
204 }
205
206 /* output */
207 cs1237_interface_debug_print("cs1237: check adc rate %s.\n", (rate == CS1237_ADC_RATE_40HZ) ? "ok" : "error");
208
209 /* set adc rate 640hz */
211 if (res != 0)
212 {
213 cs1237_interface_debug_print("cs1237: set adc rate failed.\n");
214 (void)cs1237_deinit(&gs_handle);
215
216 return 1;
217 }
218 cs1237_interface_debug_print("cs1237: set adc rate 640hz.\n");
219 res = cs1237_get_adc_rate(&gs_handle, &rate);
220 if (res != 0)
221 {
222 cs1237_interface_debug_print("cs1237: get adc rate failed.\n");
223 (void)cs1237_deinit(&gs_handle);
224
225 return 1;
226 }
227
228 /* output */
229 cs1237_interface_debug_print("cs1237: check adc rate %s.\n", (rate == CS1237_ADC_RATE_640HZ) ? "ok" : "error");
230
231 /* set adc rate 1280hz */
233 if (res != 0)
234 {
235 cs1237_interface_debug_print("cs1237: set adc rate failed.\n");
236 (void)cs1237_deinit(&gs_handle);
237
238 return 1;
239 }
240 cs1237_interface_debug_print("cs1237: set adc rate 1280hz.\n");
241 res = cs1237_get_adc_rate(&gs_handle, &rate);
242 if (res != 0)
243 {
244 cs1237_interface_debug_print("cs1237: get adc rate failed.\n");
245 (void)cs1237_deinit(&gs_handle);
246
247 return 1;
248 }
249
250 /* output */
251 cs1237_interface_debug_print("cs1237: check adc rate %s.\n", (rate == CS1237_ADC_RATE_1280HZ) ? "ok" : "error");
252
253 /* cs1237_set_pga/cs1237_get_pga test */
254 cs1237_interface_debug_print("cs1237: cs1237_set_pga/cs1237_get_pga test.\n");
255
256 /* set pga 1 */
257 res = cs1237_set_pga(&gs_handle, CS1237_PGA_1);
258 if (res != 0)
259 {
260 cs1237_interface_debug_print("cs1237: set pga failed.\n");
261 (void)cs1237_deinit(&gs_handle);
262
263 return 1;
264 }
265 cs1237_interface_debug_print("cs1237: set pga 1.\n");
266 res = cs1237_get_pga(&gs_handle, &pga);
267 if (res != 0)
268 {
269 cs1237_interface_debug_print("cs1237: get pga failed.\n");
270 (void)cs1237_deinit(&gs_handle);
271
272 return 1;
273 }
274
275 /* output */
276 cs1237_interface_debug_print("cs1237: check pga %s.\n", (pga == CS1237_PGA_1) ? "ok" : "error");
277
278 /* set pga 2 */
279 res = cs1237_set_pga(&gs_handle, CS1237_PGA_2);
280 if (res != 0)
281 {
282 cs1237_interface_debug_print("cs1237: set pga failed.\n");
283 (void)cs1237_deinit(&gs_handle);
284
285 return 1;
286 }
287 cs1237_interface_debug_print("cs1237: set pga 2.\n");
288 res = cs1237_get_pga(&gs_handle, &pga);
289 if (res != 0)
290 {
291 cs1237_interface_debug_print("cs1237: get pga failed.\n");
292 (void)cs1237_deinit(&gs_handle);
293
294 return 1;
295 }
296
297 /* output */
298 cs1237_interface_debug_print("cs1237: check pga %s.\n", (pga == CS1237_PGA_2) ? "ok" : "error");
299
300 /* set pga 64 */
301 res = cs1237_set_pga(&gs_handle, CS1237_PGA_64);
302 if (res != 0)
303 {
304 cs1237_interface_debug_print("cs1237: set pga failed.\n");
305 (void)cs1237_deinit(&gs_handle);
306
307 return 1;
308 }
309 cs1237_interface_debug_print("cs1237: set pga 64.\n");
310 res = cs1237_get_pga(&gs_handle, &pga);
311 if (res != 0)
312 {
313 cs1237_interface_debug_print("cs1237: get pga failed.\n");
314 (void)cs1237_deinit(&gs_handle);
315
316 return 1;
317 }
318
319 /* output */
320 cs1237_interface_debug_print("cs1237: check pga %s.\n", (pga == CS1237_PGA_64) ? "ok" : "error");
321
322 /* set pga 128 */
323 res = cs1237_set_pga(&gs_handle, CS1237_PGA_128);
324 if (res != 0)
325 {
326 cs1237_interface_debug_print("cs1237: set pga failed.\n");
327 (void)cs1237_deinit(&gs_handle);
328
329 return 1;
330 }
331 cs1237_interface_debug_print("cs1237: set pga 128.\n");
332 res = cs1237_get_pga(&gs_handle, &pga);
333 if (res != 0)
334 {
335 cs1237_interface_debug_print("cs1237: get pga failed.\n");
336 (void)cs1237_deinit(&gs_handle);
337
338 return 1;
339 }
340
341 /* output */
342 cs1237_interface_debug_print("cs1237: check pga %s.\n", (pga == CS1237_PGA_128) ? "ok" : "error");
343
344 /* cs1237_set_channel/cs1237_get_channel test */
345 cs1237_interface_debug_print("cs1237: cs1237_set_channel/cs1237_get_channel test.\n");
346
347 /* set channel short circuit */
349 if (res != 0)
350 {
351 cs1237_interface_debug_print("cs1237: set channel failed.\n");
352 (void)cs1237_deinit(&gs_handle);
353
354 return 1;
355 }
356 cs1237_interface_debug_print("cs1237: set channel short circuit.\n");
357 res = cs1237_get_channel(&gs_handle, &channel);
358 if (res != 0)
359 {
360 cs1237_interface_debug_print("cs1237: get channel failed.\n");
361 (void)cs1237_deinit(&gs_handle);
362
363 return 1;
364 }
365
366 /* output */
367 cs1237_interface_debug_print("cs1237: check channel %s.\n", (channel == CS1237_CHANNEL_SHORT_CIRCUIT) ? "ok" : "error");
368
369 /* set channel temperature */
371 if (res != 0)
372 {
373 cs1237_interface_debug_print("cs1237: set channel failed.\n");
374 (void)cs1237_deinit(&gs_handle);
375
376 return 1;
377 }
378 cs1237_interface_debug_print("cs1237: set channel temperature.\n");
379 res = cs1237_get_channel(&gs_handle, &channel);
380 if (res != 0)
381 {
382 cs1237_interface_debug_print("cs1237: get channel failed.\n");
383 (void)cs1237_deinit(&gs_handle);
384
385 return 1;
386 }
387
388 /* output */
389 cs1237_interface_debug_print("cs1237: check channel %s.\n", (channel == CS1237_CHANNEL_TEMPERATURE) ? "ok" : "error");
390
391 /* set channel a */
392 res = cs1237_set_channel(&gs_handle, CS1237_CHANNEL_A);
393 if (res != 0)
394 {
395 cs1237_interface_debug_print("cs1237: set channel failed.\n");
396 (void)cs1237_deinit(&gs_handle);
397
398 return 1;
399 }
400 cs1237_interface_debug_print("cs1237: set channel a.\n");
401 res = cs1237_get_channel(&gs_handle, &channel);
402 if (res != 0)
403 {
404 cs1237_interface_debug_print("cs1237: get channel failed.\n");
405 (void)cs1237_deinit(&gs_handle);
406
407 return 1;
408 }
409
410 /* output */
411 cs1237_interface_debug_print("cs1237: check channel %s.\n", (channel == CS1237_CHANNEL_A) ? "ok" : "error");
412
413 /* cs1237_wake_up test */
414 cs1237_interface_debug_print("cs1237: cs1237_wake_up test.\n");
415
416 /* wake up */
417 res = cs1237_wake_up(&gs_handle);
418 if (res != 0)
419 {
420 cs1237_interface_debug_print("cs1237: wake up failed.\n");
421 (void)cs1237_deinit(&gs_handle);
422
423 return 1;
424 }
425
426 /* output */
427 cs1237_interface_debug_print("cs1237: check wake up %s.\n", (res == 0) ? "ok" : "error");
428
429 /* cs1237_power_down test */
430 cs1237_interface_debug_print("cs1237: cs1237_wake_up test.\n");
431
432 /* power down */
433 res = cs1237_power_down(&gs_handle);
434 if (res != 0)
435 {
436 cs1237_interface_debug_print("cs1237: power down failed.\n");
437 (void)cs1237_deinit(&gs_handle);
438
439 return 1;
440 }
441
442 /* output */
443 cs1237_interface_debug_print("cs1237: check power down %s.\n", (res == 0) ? "ok" : "error");
444
445 /* finish register test */
446 cs1237_interface_debug_print("cs1237: finish register test.\n");
447 (void)cs1237_deinit(&gs_handle);
448
449 return 0;
450}
driver cs1237 register test header file
uint8_t cs1237_set_adc_rate(cs1237_handle_t *handle, cs1237_adc_rate_t rate)
set adc rate
uint8_t cs1237_set_reference_voltage_output(cs1237_handle_t *handle, cs1237_bool_t enable)
enable or disable reference voltage output
uint8_t cs1237_get_channel(cs1237_handle_t *handle, cs1237_channel_t *channel)
get adc channel
struct cs1237_handle_s cs1237_handle_t
cs1237 handle structure definition
uint8_t cs1237_deinit(cs1237_handle_t *handle)
close the chip
uint8_t cs1237_info(cs1237_info_t *info)
get chip's information
cs1237_bool_t
cs1237 bool enumeration definition
uint8_t cs1237_wake_up(cs1237_handle_t *handle)
wake up
uint8_t cs1237_get_pga(cs1237_handle_t *handle, cs1237_pga_t *pga)
get adc pga
uint8_t cs1237_get_adc_rate(cs1237_handle_t *handle, cs1237_adc_rate_t *rate)
get adc rate
uint8_t cs1237_set_pga(cs1237_handle_t *handle, cs1237_pga_t pga)
set adc pga
uint8_t cs1237_get_reference_voltage_output(cs1237_handle_t *handle, cs1237_bool_t *enable)
get reference voltage output status
uint8_t cs1237_power_down(cs1237_handle_t *handle)
power down
cs1237_pga_t
cs1237 pga enumeration definition
cs1237_adc_rate_t
cs1237 adc rate enumeration definition
struct cs1237_info_s cs1237_info_t
cs1237 information structure definition
uint8_t cs1237_set_channel(cs1237_handle_t *handle, cs1237_channel_t channel)
set adc channel
uint8_t cs1237_init(cs1237_handle_t *handle)
initialize the chip
cs1237_channel_t
cs1237 channel enumeration definition
@ CS1237_BOOL_TRUE
@ CS1237_BOOL_FALSE
@ CS1237_PGA_2
@ CS1237_PGA_1
@ CS1237_PGA_128
@ CS1237_PGA_64
@ CS1237_ADC_RATE_1280HZ
@ CS1237_ADC_RATE_640HZ
@ CS1237_ADC_RATE_10HZ
@ CS1237_ADC_RATE_40HZ
@ CS1237_CHANNEL_SHORT_CIRCUIT
@ CS1237_CHANNEL_TEMPERATURE
@ CS1237_CHANNEL_A
void cs1237_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t cs1237_interface_dout_gpio_deinit(void)
interface dout gpio deinit
uint8_t cs1237_interface_sclk_gpio_write(uint8_t level)
interface sclk gpio write
uint8_t cs1237_interface_sclk_gpio_deinit(void)
interface sclk gpio deinit
uint8_t cs1237_interface_dout_gpio_init(void)
interface dout gpio init
uint8_t cs1237_interface_sclk_gpio_init(void)
interface sclk gpio init
void cs1237_interface_delay_ms(uint32_t ms)
interface delay ms
void cs1237_interface_delay_us(uint32_t us)
interface delay us
uint8_t cs1237_interface_dout_gpio_read(uint8_t *level)
interface dout gpio read
uint8_t cs1237_interface_dout_gpio_write(uint8_t level)
interface dout gpio write
uint8_t cs1237_register_test(void)
register test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]