LibDriver AS608
Loading...
Searching...
No Matches
driver_as608.c
Go to the documentation of this file.
1
36
37#include "driver_as608.h"
38#include <math.h>
39
43#define CHIP_NAME "Synochip AS608"
44#define MANUFACTURER_NAME "Synochip"
45#define SUPPLY_VOLTAGE_MIN 3.0f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 60.0f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 1000
51
55#define AS608_COMMAND_GET_IMAGE 0x01
56#define AS608_COMMAND_GEN_CHAR 0x02
57#define AS608_COMMAND_MATCH 0x03
58#define AS608_COMMAND_SEARCH 0x04
59#define AS608_COMMAND_REG_MODEL 0x05
60#define AS608_COMMAND_STORE_CHAR 0x06
61#define AS608_COMMAND_LOAD_CHAR 0x07
62#define AS608_COMMAND_UP_CHAR 0x08
63#define AS608_COMMAND_DOWN_CHAR 0x09
64#define AS608_COMMAND_UP_IMAGE 0x0A
65#define AS608_COMMAND_DOWN_IMAGE 0x0B
66#define AS608_COMMAND_DELETE_CHAR 0x0C
67#define AS608_COMMAND_EMPTY 0x0D
68#define AS608_COMMAND_WRITE_REG 0x0E
69#define AS608_COMMAND_READ_SYS_PARA 0x0F
70#define AS608_COMMAND_ENROLL 0x10
71#define AS608_COMMAND_IDENTIFY 0x11
72#define AS608_COMMAND_SET_PWD 0x12
73#define AS608_COMMAND_VFY_PWD 0x13
74#define AS608_COMMAND_GET_RANDOM_CODE 0x14
75#define AS608_COMMAND_SET_CHIP_ADDR 0x15
76#define AS608_COMMAND_READ_INFO_PAGE 0x16
77#define AS608_COMMAND_PORT_CONTROL 0x17
78#define AS608_COMMAND_WRITE_NOTEPAD 0x18
79#define AS608_COMMAND_READ_NOTEPAD 0x19
80#define AS608_COMMAND_BURN_CODE 0x1A
81#define AS608_COMMAND_HIGH_SPEED_SEARCH 0x1B
82#define AS608_COMMAND_GEN_BIN_IMAGE 0x1C
83#define AS608_COMMAND_VALID_TEMPLATE_NUM 0x1D
84#define AS608_COMMAND_USER_GPIO 0x1E
85#define AS608_COMMAND_READ_INDEX_TABLE 0x1F
86
90#define AS608_TYPE_COMMAND 0x01
91#define AS608_TYPE_DATA 0x02
92#define AS608_TYPE_RESPONSE 0x07
93#define AS608_TYPE_END 0x08
94
108static uint8_t a_as608_uart_write(as608_handle_t *handle, uint32_t addr, uint8_t type,
109 uint8_t *buf, uint16_t len)
110{
111 uint16_t i;
112 uint16_t sum;
113 uint16_t l;
114
115 if ((len + 11) > 384) /* check length */
116 {
117 return 2; /* return error */
118 }
119 handle->buf[0] = 0xEF; /* header 0 */
120 handle->buf[1] = 0x01; /* header 1 */
121 handle->buf[2] = (addr >> 24) & 0xFF; /* set addr 3 */
122 handle->buf[3] = (addr >> 16) & 0xFF; /* set addr 2 */
123 handle->buf[4] = (addr >> 8) & 0xFF; /* set addr 1 */
124 handle->buf[5] = (addr >> 0) & 0xFF; /* set addr 0 */
125 handle->buf[6] = type; /* set type */
126 l = len + 2; /* add check crc */
127 handle->buf[7] = (l >> 8) & 0xFF; /* set l msb */
128 handle->buf[8] = (l >> 0) & 0xFF; /* set l lsb */
129 memcpy(handle->buf + 9, buf, len); /* copy data */
130 l = len + 9; /* add 9 */
131 sum = 0; /* init 0 */
132 for(i = 6; i < l; i++) /* loop */
133 {
134 sum += handle->buf[i]; /* sum all */
135 }
136 handle->buf[l] = (sum >> 8) & 0xFF; /* set sum msb */
137 handle->buf[l + 1] = (sum >> 0) & 0xFF; /* set sum lsb */
138
139 if (handle->uart_flush() != 0) /* uart flush */
140 {
141 return 1; /* return error */
142 }
143 if (handle->uart_write(handle->buf, l + 2) != 0) /* write data */
144 {
145 return 1; /* return error */
146 }
147
148 return 0; /* success return 0 */
149}
150
168static uint8_t a_as608_uart_decode(as608_handle_t *handle, uint32_t ms, uint32_t *addr,
169 uint8_t *buf, uint16_t *len)
170{
171 uint16_t i;
172 uint16_t l;
173 uint16_t ll;
174 uint16_t sum;
175 uint16_t sum_check;
176 uint16_t read_len;
177
178 handle->delay_ms(ms); /* delay */
179 l = handle->uart_read(handle->buf, 384); /* read data */
180 if (l != 0) /* check length */
181 {
182 if (l < 12) /* check min length */
183 {
184 handle->debug_print("as608: decode failed.\n"); /* decode failed */
185
186 return 2; /* return error */
187 }
188 ll = l - 2; /* no check sum */
189 sum = 0; /* init 0 */
190 for(i = 6; i < ll; i++) /* loop */
191 {
192 sum += handle->buf[i]; /* sum all */
193 }
194 sum_check = (uint16_t)((uint16_t)handle->buf[l - 2] << 8) | handle->buf[l - 1]; /* sum check */
195 if (sum != sum_check) /* check sum */
196 {
197 handle->debug_print("as608: sum check error.\n"); /* sum check error */
198
199 return 3; /* return error */
200 }
201 ll = (uint16_t)((uint16_t)handle->buf[7] << 8) | handle->buf[8]; /* get length */
202 if (ll + 9 != l) /* check length */
203 {
204 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
205
206 return 4; /* return error */
207 }
208 if ((handle->buf[0] != 0xEF) && (handle->buf[1] != 0x01)) /* check header */
209 {
210 handle->debug_print("as608: header is invalid.\n"); /* header is invalid */
211
212 return 5; /* return error */
213 }
214 *addr = (uint32_t)((uint32_t)handle->buf[2] << 24) |
215 (uint32_t)((uint32_t)handle->buf[3] << 16) |
216 (uint32_t)((uint32_t)handle->buf[4] << 8) |
217 (uint32_t)((uint32_t)handle->buf[5] << 0); /* set address */
218 if (handle->buf[6] != AS608_TYPE_RESPONSE) /* check type */
219 {
220 handle->debug_print("as608: type is invalid.\n"); /* type is invalid */
221
222 return 6; /* return error */
223 }
224 read_len = ((*len) < (ll - 2)) ? (*len) : (ll - 2); /* set length */
225 memcpy(buf, &handle->buf[9], read_len); /* copy data */
226 *len = read_len; /* set addr */
227
228 return 0; /* success return 0 */
229 }
230 else
231 {
232 handle->debug_print("as608: no response.\n"); /* no response */
233
234 return 2; /* return error */
235 }
236}
237
256static uint8_t a_as608_uart_decode_with_length(as608_handle_t *handle, uint16_t input_len,
257 uint32_t ms, uint32_t *addr,
258 uint8_t *buf, uint16_t *len)
259{
260 uint16_t i;
261 uint16_t l;
262 uint16_t ll;
263 uint16_t sum;
264 uint16_t sum_check;
265 uint16_t read_len;
266
267 handle->delay_ms(ms); /* delay */
268 l = handle->uart_read(handle->buf, input_len); /* read data */
269 if (l != 0) /* check length */
270 {
271 if (l < 12) /* check min length */
272 {
273 handle->debug_print("as608: decode failed.\n"); /* decode failed */
274
275 return 2; /* return error */
276 }
277 if (l != input_len) /* check min length */
278 {
279 handle->debug_print("as608: decode failed.\n"); /* decode failed */
280
281 return 2; /* return error */
282 }
283 ll = l - 2; /* no check sum */
284 sum = 0; /* init 0 */
285 for(i = 6; i < ll; i++) /* loop */
286 {
287 sum += handle->buf[i]; /* sum all */
288 }
289 sum_check = (uint16_t)((uint16_t)handle->buf[l - 2] << 8) | handle->buf[l - 1]; /* sum check */
290 if (sum != sum_check) /* check sum */
291 {
292 handle->debug_print("as608: sum check error.\n"); /* sum check error */
293
294 return 3; /* return error */
295 }
296 ll = (uint16_t)((uint16_t)handle->buf[7] << 8) | handle->buf[8]; /* get length */
297 if (ll + 9 != l) /* check length */
298 {
299 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
300
301 return 4; /* return error */
302 }
303 if ((handle->buf[0] != 0xEF) && (handle->buf[1] != 0x01)) /* check header */
304 {
305 handle->debug_print("as608: header is invalid.\n"); /* header is invalid */
306
307 return 5; /* return error */
308 }
309 *addr = (uint32_t)((uint32_t)handle->buf[2] << 24) |
310 (uint32_t)((uint32_t)handle->buf[3] << 16) |
311 (uint32_t)((uint32_t)handle->buf[4] << 8) |
312 (uint32_t)((uint32_t)handle->buf[5] << 0); /* set address */
313 if (handle->buf[6] != AS608_TYPE_RESPONSE) /* check type */
314 {
315 handle->debug_print("as608: type is invalid.\n"); /* type is invalid */
316
317 return 6; /* return error */
318 }
319 read_len = ((*len) < (ll - 2)) ? (*len) : (ll - 2); /* set length */
320 memcpy(buf, &handle->buf[9], read_len); /* copy data */
321 *len = read_len; /* set addr */
322
323 return 0; /* success return 0 */
324 }
325 else
326 {
327 handle->debug_print("as608: no response.\n"); /* no response */
328
329 return 2; /* return error */
330 }
331}
332
352static uint8_t a_as608_uart_parse_data(as608_handle_t *handle, uint32_t ms,uint32_t *addr, uint8_t *buf,
353 uint16_t *len, as608_bool_t *end_enable, as608_bool_t *full_enable)
354{
355 uint16_t i;
356 uint16_t l;
357 uint16_t ll;
358 uint16_t sum;
359 uint16_t sum_check;
360 uint16_t read_len;
361
362 handle->delay_ms(ms); /* delay */
363 l = handle->uart_read(handle->buf, 9); /* read data */
364 if (l != 0) /* check length */
365 {
366 if (l != 9) /* check min length */
367 {
368 handle->debug_print("as608: parse failed.\n"); /* parse failed */
369
370 return 2; /* return error */
371 }
372 l = (uint16_t)(((uint16_t)handle->buf[7]) << 8) | handle->buf[8]; /* get length */
373 if (l > 256)
374 {
375 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
376
377 return 4; /* return error */
378 }
379 ll = handle->uart_read(&handle->buf[9], l); /* read data */
380 if (ll != l) /* check the read length */
381 {
382 handle->debug_print("as608: parse failed.\n"); /* parse failed */
383
384 return 2; /* return error */
385 }
386 l += 9; /* add header length */
387 ll = l - 2; /* no check sum */
388 sum = 0; /* init 0 */
389 for(i = 6; i < ll; i++) /* loop */
390 {
391 sum += handle->buf[i]; /* sum all */
392 }
393 sum_check = (uint16_t)((uint16_t)handle->buf[l - 2] << 8) | handle->buf[l - 1]; /* sum check */
394 if (sum != sum_check) /* check sum */
395 {
396 handle->debug_print("as608: sum check error.\n"); /* sum check error */
397
398 return 3; /* return error */
399 }
400 ll = (uint16_t)((uint16_t)handle->buf[7] << 8) | handle->buf[8]; /* get length */
401 if (ll + 9 != l) /* check length */
402 {
403 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
404
405 return 4; /* return error */
406 }
407 if ((handle->buf[0] != 0xEF) && (handle->buf[1] != 0x01)) /* check header */
408 {
409 handle->debug_print("as608: header is invalid.\n"); /* header is invalid */
410
411 return 5; /* return error */
412 }
413 *addr = (uint32_t)((uint32_t)handle->buf[2] << 24) |
414 (uint32_t)((uint32_t)handle->buf[3] << 16) |
415 (uint32_t)((uint32_t)handle->buf[4] << 8) |
416 (uint32_t)((uint32_t)handle->buf[5] << 0); /* set address */
417 if (handle->buf[6] == AS608_TYPE_DATA) /* if data type */
418 {
419 *end_enable = AS608_BOOL_FALSE; /* disable end */
420 }
421 else if (handle->buf[6] == AS608_TYPE_END) /* if end */
422 {
423 *end_enable = AS608_BOOL_TRUE; /* enable end */
424 }
425 else
426 {
427 handle->debug_print("as608: type is invalid.\n"); /* type is invalid */
428
429 return 6; /* return error */
430 }
431 read_len = ((*len) < (ll - 2)) ? (*len) : (ll - 2); /* set length */
432 memcpy(buf, &handle->buf[9], read_len); /* copy data */
433 *len = read_len; /* set addr */
434 if ((ll - 2) > (*len)) /* check buffer full */
435 {
436 *full_enable = AS608_BOOL_TRUE; /* full */
437 }
438 else
439 {
440 *full_enable = AS608_BOOL_FALSE; /* not full */
441 }
442
443 return 0; /* success return 0 */
444 }
445 else
446 {
447 handle->debug_print("as608: no response.\n"); /* no response */
448
449 return 2; /* return error */
450 }
451}
452
465uint8_t as608_init(as608_handle_t *handle, uint32_t addr)
466{
467 uint8_t res;
468 uint8_t buf[17];
469 uint16_t len;
470 uint32_t addr_check;
471
472 if (handle == NULL) /* check handle */
473 {
474 return 2; /* return error */
475 }
476 if (handle->debug_print == NULL) /* check debug_print */
477 {
478 return 3; /* return error */
479 }
480 if (handle->uart_init == NULL) /* check uart_init */
481 {
482 handle->debug_print("as608: uart_init is null.\n"); /* uart_init is null */
483
484 return 3; /* return error */
485 }
486 if (handle->uart_deinit == NULL) /* check uart_deinit */
487 {
488 handle->debug_print("as608: uart_deinit is null.\n"); /* uart_deinit is null */
489
490 return 3; /* return error */
491 }
492 if (handle->uart_read == NULL) /* check uart_read */
493 {
494 handle->debug_print("as608: uart_read is null.\n"); /* uart_read is null */
495
496 return 3; /* return error */
497 }
498 if (handle->uart_write == NULL) /* check uart_write */
499 {
500 handle->debug_print("as608: uart_write is null.\n"); /* uart_write is null */
501
502 return 3; /* return error */
503 }
504 if (handle->uart_flush == NULL) /* check uart_flush */
505 {
506 handle->debug_print("as608: uart_flush is null.\n"); /* uart_flush is null */
507
508 return 3; /* return error */
509 }
510 if (handle->delay_ms == NULL) /* check delay_ms */
511 {
512 handle->debug_print("as608: delay_ms is null.\n"); /* delay_ms is null */
513
514 return 3; /* return error */
515 }
516
517 if (handle->uart_init() != 0) /* uart init */
518 {
519 handle->debug_print("as608: uart init failed.\n"); /* uart init failed */
520
521 return 1; /* return error */
522 }
523 handle->delay_ms(100); /* delay 100ms */
524
525 buf[0] = AS608_COMMAND_READ_SYS_PARA; /* read sys para */
526 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
527 if (res != 0) /* check result */
528 {
529 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
530 (void)handle->uart_deinit(); /* uart deinit */
531
532 return 4; /* return error */
533 }
534 len = 17; /* len 17 */
535 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
536 if (res != 0) /* check result */
537 {
538 (void)handle->uart_deinit(); /* uart deinit */
539
540 return 4; /* return error */
541 }
542 if (addr_check != addr) /* check addr */
543 {
544 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
545 (void)handle->uart_deinit(); /* uart deinit */
546
547 return 4; /* return error */
548 }
549 if (len != 17) /* check length */
550 {
551 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
552 (void)handle->uart_deinit(); /* uart deinit */
553
554 return 4; /* return error */
555 }
556 handle->status = buf[0]; /* save status */
557 handle->packet_size = (uint16_t)(32.0f * powf(2.0f, (float)((uint16_t)
558 ((uint16_t)buf[13] << 8) | buf[14]))); /* packet size */
559
560 handle->inited = 1; /* flag finish initialization */
561
562 return 0; /* success return 0 */
563}
564
576{
577 if (handle == NULL) /* check handle */
578 {
579 return 2; /* return error */
580 }
581 if (handle->inited != 1) /* check handle initialization */
582 {
583 return 3; /* return error */
584 }
585
586 if (handle->uart_deinit() != 0) /* uart deinit */
587 {
588 handle->debug_print("as608: uart deinit failed.\n"); /* uart deinit failed */
589
590 return 1; /* return error */
591 }
592 handle->inited = 0; /* flag close */
593
594 return 0; /* success return 0 */
595}
596
608{
609 if (handle == NULL) /* check handle */
610 {
611 return 2; /* return error */
612 }
613 if (handle->inited != 1) /* check handle initialization */
614 {
615 return 3; /* return error */
616 }
617
618 *status = (as608_status_t)handle->status; /* get status */
619
620 return 0; /* success return 0 */
621}
622
638uint8_t as608_get_image(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
639{
640 uint8_t res;
641 uint8_t buf[1];
642 uint16_t len;
643 uint32_t addr_check;
644
645 if (handle == NULL) /* check handle */
646 {
647 return 2; /* return error */
648 }
649 if (handle->inited != 1) /* check handle initialization */
650 {
651 return 3; /* return error */
652 }
653
654 buf[0] = AS608_COMMAND_GET_IMAGE; /* get image */
655 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
656 if (res != 0) /* check result */
657 {
658 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
659
660 return 1; /* return error */
661 }
662 len = 1; /* len 1 */
663 res = a_as608_uart_decode(handle, 500, &addr_check, buf, &len); /* decode */
664 if (res != 0) /* check result */
665 {
666 return 4; /* return error */
667 }
668 if (addr_check != addr) /* check addr */
669 {
670 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
671
672 return 5; /* return error */
673 }
674 if (len != 1) /* check length */
675 {
676 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
677
678 return 6; /* return error */
679 }
680 handle->status = buf[0]; /* save status */
681 *status = (as608_status_t)handle->status; /* set status */
682
683 return 0; /* success return 0 */
684}
685
703{
704 uint8_t res;
705 uint8_t buf[2];
706 uint16_t len;
707 uint32_t addr_check;
708
709 if (handle == NULL) /* check handle */
710 {
711 return 2; /* return error */
712 }
713 if (handle->inited != 1) /* check handle initialization */
714 {
715 return 3; /* return error */
716 }
717
718 buf[0] = AS608_COMMAND_GEN_CHAR; /* generate char */
719 buf[1] = num; /* set buffer number */
720 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 2); /* write data */
721 if (res != 0) /* check result */
722 {
723 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
724
725 return 1; /* return error */
726 }
727 len = 1; /* len 1 */
728 res = a_as608_uart_decode(handle, 400, &addr_check, buf, &len); /* decode */
729 if (res != 0) /* check result */
730 {
731 return 4; /* return error */
732 }
733 if (addr_check != addr) /* check addr */
734 {
735 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
736
737 return 5; /* return error */
738 }
739 if (len != 1) /* check length */
740 {
741 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
742
743 return 6; /* return error */
744 }
745 handle->status = buf[0]; /* save status */
746 *status = (as608_status_t)handle->status; /* set status */
747
748 return 0; /* success return 0 */
749}
750
767uint8_t as608_match_feature(as608_handle_t *handle, uint32_t addr, uint16_t *score, as608_status_t *status)
768{
769 uint8_t res;
770 uint8_t buf[3];
771 uint16_t len;
772 uint32_t addr_check;
773
774 if (handle == NULL) /* check handle */
775 {
776 return 2; /* return error */
777 }
778 if (handle->inited != 1) /* check handle initialization */
779 {
780 return 3; /* return error */
781 }
782
783 buf[0] = AS608_COMMAND_MATCH; /* match feature */
784 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
785 if (res != 0) /* check result */
786 {
787 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
788
789 return 1; /* return error */
790 }
791 len = 3; /* len 3 */
792 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
793 if (res != 0) /* check result */
794 {
795 return 4; /* return error */
796 }
797 if (addr_check != addr) /* check addr */
798 {
799 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
800
801 return 5; /* return error */
802 }
803 if (len != 3) /* check length */
804 {
805 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
806
807 return 6; /* return error */
808 }
809 handle->status = buf[0]; /* save status */
810 *status = (as608_status_t)handle->status; /* set status */
811 *score = (uint16_t)((uint16_t)buf[1] << 8) | buf[2]; /* set the score */
812
813 return 0; /* success return 0 */
814}
815
836uint8_t as608_search_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num,
837 uint16_t start_page, uint16_t page_number, uint16_t *found_page,
838 uint16_t *score, as608_status_t *status)
839{
840 uint8_t res;
841 uint8_t buf[6];
842 uint16_t len;
843 uint32_t addr_check;
844
845 if (handle == NULL) /* check handle */
846 {
847 return 2; /* return error */
848 }
849 if (handle->inited != 1) /* check handle initialization */
850 {
851 return 3; /* return error */
852 }
853
854 buf[0] = AS608_COMMAND_SEARCH; /* search char */
855 buf[1] = num; /* set buffer number */
856 buf[2] = (start_page >> 8) & 0xFF; /* start page msb */
857 buf[3] = (start_page >> 0) & 0xFF; /* start page lsb */
858 buf[4] = (page_number >> 8) & 0xFF; /* page number msb */
859 buf[5] = (page_number >> 0) & 0xFF; /* page number lsb */
860 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 6); /* write data */
861 if (res != 0) /* check result */
862 {
863 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
864
865 return 1; /* return error */
866 }
867 len = 5; /* len 5 */
868 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
869 if (res != 0) /* check result */
870 {
871 return 4; /* return error */
872 }
873 if (addr_check != addr) /* check addr */
874 {
875 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
876
877 return 5; /* return error */
878 }
879 if (len != 5) /* check length */
880 {
881 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
882
883 return 6; /* return error */
884 }
885 handle->status = buf[0]; /* save status */
886 *status = (as608_status_t)handle->status; /* set status */
887 *found_page = (uint16_t)((uint16_t)buf[1] << 8) | buf[2]; /* set the found page */
888 *score = (uint16_t)((uint16_t)buf[3] << 8) | buf[4]; /* set the score */
889
890 return 0; /* success return 0 */
891}
892
908uint8_t as608_combine_feature(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
909{
910 uint8_t res;
911 uint8_t buf[1];
912 uint16_t len;
913 uint32_t addr_check;
914
915 if (handle == NULL) /* check handle */
916 {
917 return 2; /* return error */
918 }
919 if (handle->inited != 1) /* check handle initialization */
920 {
921 return 3; /* return error */
922 }
923
924 buf[0] = AS608_COMMAND_REG_MODEL; /* reg model */
925 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
926 if (res != 0) /* check result */
927 {
928 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
929
930 return 1; /* return error */
931 }
932 len = 1; /* len 1 */
933 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
934 if (res != 0) /* check result */
935 {
936 return 4; /* return error */
937 }
938 if (addr_check != addr) /* check addr */
939 {
940 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
941
942 return 5; /* return error */
943 }
944 if (len != 1) /* check length */
945 {
946 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
947
948 return 6; /* return error */
949 }
950 handle->status = buf[0]; /* save status */
951 *status = (as608_status_t)handle->status; /* set status */
952
953 return 0; /* success return 0 */
954}
955
973uint8_t as608_store_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num,
974 uint16_t page_number, as608_status_t *status)
975{
976 uint8_t res;
977 uint8_t buf[4];
978 uint16_t len;
979 uint32_t addr_check;
980
981 if (handle == NULL) /* check handle */
982 {
983 return 2; /* return error */
984 }
985 if (handle->inited != 1) /* check handle initialization */
986 {
987 return 3; /* return error */
988 }
989
990 buf[0] = AS608_COMMAND_STORE_CHAR; /* store char */
991 buf[1] = num; /* set buffer number */
992 buf[2] = (page_number >> 8) & 0xFF; /* page number msb */
993 buf[3] = (page_number >> 0) & 0xFF; /* page number lsb */
994 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 4); /* write data */
995 if (res != 0) /* check result */
996 {
997 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
998
999 return 1; /* return error */
1000 }
1001 len = 1; /* len 1 */
1002 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
1003 if (res != 0) /* check result */
1004 {
1005 return 4; /* return error */
1006 }
1007 if (addr_check != addr) /* check addr */
1008 {
1009 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1010
1011 return 5; /* return error */
1012 }
1013 if (len != 1) /* check length */
1014 {
1015 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1016
1017 return 6; /* return error */
1018 }
1019 handle->status = buf[0]; /* save status */
1020 *status = (as608_status_t)handle->status; /* set status */
1021
1022 return 0; /* success return 0 */
1023}
1024
1042uint8_t as608_load_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num,
1043 uint16_t page_number, as608_status_t *status)
1044{
1045 uint8_t res;
1046 uint8_t buf[4];
1047 uint16_t len;
1048 uint32_t addr_check;
1049
1050 if (handle == NULL) /* check handle */
1051 {
1052 return 2; /* return error */
1053 }
1054 if (handle->inited != 1) /* check handle initialization */
1055 {
1056 return 3; /* return error */
1057 }
1058
1059 buf[0] = AS608_COMMAND_LOAD_CHAR; /* load char */
1060 buf[1] = num; /* set buffer number */
1061 buf[2] = (page_number >> 8) & 0xFF; /* page number msb */
1062 buf[3] = (page_number >> 0) & 0xFF; /* page number lsb */
1063 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 4); /* write data */
1064 if (res != 0) /* check result */
1065 {
1066 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1067
1068 return 1; /* return error */
1069 }
1070 len = 1; /* len 1 */
1071 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
1072 if (res != 0) /* check result */
1073 {
1074 return 4; /* return error */
1075 }
1076 if (addr_check != addr) /* check addr */
1077 {
1078 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1079
1080 return 5; /* return error */
1081 }
1082 if (len != 1) /* check length */
1083 {
1084 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1085
1086 return 6; /* return error */
1087 }
1088 handle->status = buf[0]; /* save status */
1089 *status = (as608_status_t)handle->status; /* set status */
1090
1091 return 0; /* success return 0 */
1092}
1093
1113uint8_t as608_upload_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num,
1114 uint8_t *output_buffer, uint16_t *output_len, as608_status_t *status)
1115{
1116 uint8_t res;
1117 uint8_t buf[2];
1118 uint16_t l;
1119 uint16_t point;
1120 uint16_t len;
1121 uint32_t addr_check;
1122
1123 if (handle == NULL) /* check handle */
1124 {
1125 return 2; /* return error */
1126 }
1127 if (handle->inited != 1) /* check handle initialization */
1128 {
1129 return 3; /* return error */
1130 }
1131
1132 buf[0] = AS608_COMMAND_UP_CHAR; /* upload char */
1133 buf[1] = num; /* set buffer number */
1134 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 2); /* write data */
1135 if (res != 0) /* check result */
1136 {
1137 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1138
1139 return 1; /* return error */
1140 }
1141 len = 1; /* len 1 */
1142 res = a_as608_uart_decode_with_length(handle, 12, 100, &addr_check,
1143 buf, &len); /* decode */
1144 if (res != 0) /* check result */
1145 {
1146 return 4; /* return error */
1147 }
1148 if (addr_check != addr) /* check addr */
1149 {
1150 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1151
1152 return 5; /* return error */
1153 }
1154 if (len != 1) /* check length */
1155 {
1156 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1157
1158 return 6; /* return error */
1159 }
1160 handle->status = buf[0]; /* save status */
1161 *status = (as608_status_t)handle->status; /* set status */
1162 point = 0; /* init 0 */
1163 len = *output_len; /* get the length */
1164 l = *output_len; /* get the length */
1165 while (1) /* loop */
1166 {
1167 as608_bool_t end_enable;
1168 as608_bool_t full_enable;
1169
1170 l = len; /* set the remain max buffer size */
1171 res = a_as608_uart_parse_data(handle, 100, &addr_check,
1172 output_buffer + point,
1173 &l, &end_enable, &full_enable); /* parse the data */
1174 if (res != 0)
1175 {
1176 return 4; /* return error */
1177 }
1178 if (addr_check != addr) /* check addr */
1179 {
1180 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1181
1182 return 5; /* return error */
1183 }
1184 len -= l; /* remain length - read length */
1185 point += l; /* current point adds read length */
1186 if (full_enable == AS608_BOOL_TRUE) /* if buffer is full */
1187 {
1188 handle->debug_print("as608: buffer is full.\n"); /* buffer is full */
1189
1190 return 7; /* return error */
1191 }
1192 if (end_enable == AS608_BOOL_TRUE) /* if the last packet */
1193 {
1194 break; /* break */
1195 }
1196 }
1197 *output_len = point; /* save the length */
1198
1199 return 0; /* success return 0 */
1200}
1201
1221 uint8_t *input_buffer, uint16_t input_len, as608_status_t *status)
1222{
1223 uint8_t res;
1224 uint8_t buf[2];
1225 uint16_t i;
1226 uint16_t m;
1227 uint16_t n;
1228 uint16_t len;
1229 uint32_t addr_check;
1230
1231 if (handle == NULL) /* check handle */
1232 {
1233 return 2; /* return error */
1234 }
1235 if (handle->inited != 1) /* check handle initialization */
1236 {
1237 return 3; /* return error */
1238 }
1239
1240 buf[0] = AS608_COMMAND_DOWN_CHAR; /* download char */
1241 buf[1] = num; /* set buffer number */
1242 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 2); /* write data */
1243 if (res != 0) /* check result */
1244 {
1245 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1246
1247 return 1; /* return error */
1248 }
1249 len = 1; /* len 1 */
1250 res = a_as608_uart_decode_with_length(handle, 12, 100, &addr_check, buf, &len); /* decode */
1251 if (res != 0) /* check result */
1252 {
1253 return 4; /* return error */
1254 }
1255 if (addr_check != addr) /* check addr */
1256 {
1257 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1258
1259 return 5; /* return error */
1260 }
1261 if (len != 1) /* check length */
1262 {
1263 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1264
1265 return 6; /* return error */
1266 }
1267 handle->status = buf[0]; /* save status */
1268 *status = (as608_status_t)handle->status; /* set status */
1269
1270 m = input_len / handle->packet_size; /* set m */
1271 n = input_len % handle->packet_size; /* set n */
1272 if (n != 0) /* check n */
1273 {
1274 for (i = 0; i < m; i++) /* m times */
1275 {
1276 res = a_as608_uart_write(handle, addr, AS608_TYPE_DATA,
1277 input_buffer + i * handle->packet_size,
1278 handle->packet_size); /* write data */
1279 if (res != 0) /* check result */
1280 {
1281 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1282
1283 return 1; /* return error */
1284 }
1285 handle->delay_ms(100); /* delay 100ms */
1286 }
1287 res = a_as608_uart_write(handle, addr, AS608_TYPE_END,
1288 input_buffer + m * handle->packet_size, n); /* write data */
1289 if (res != 0) /* check result */
1290 {
1291 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1292
1293 return 1; /* return error */
1294 }
1295 handle->delay_ms(100); /* delay 100ms */
1296 }
1297 else
1298 {
1299 for (i = 0; i < (m - 1); i++) /* m - 1 times */
1300 {
1301 res = a_as608_uart_write(handle, addr, AS608_TYPE_DATA,
1302 input_buffer + i * handle->packet_size,
1303 handle->packet_size); /* write data */
1304 if (res != 0) /* check result */
1305 {
1306 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1307
1308 return 1; /* return error */
1309 }
1310 handle->delay_ms(100); /* delay 100ms */
1311 }
1312 res = a_as608_uart_write(handle, addr, AS608_TYPE_END,
1313 input_buffer + (m - 1) * handle->packet_size,
1314 handle->packet_size); /* write data */
1315 if (res != 0) /* check result */
1316 {
1317 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1318
1319 return 1; /* return error */
1320 }
1321 handle->delay_ms(100); /* delay 100ms */
1322 }
1323
1324 return 0; /* success return 0 */
1325}
1326
1345uint8_t as608_upload_image(as608_handle_t *handle, uint32_t addr, uint8_t *output_buffer,
1346 uint16_t *output_len, as608_status_t *status)
1347{
1348 uint8_t res;
1349 uint8_t buf[1];
1350 uint16_t l;
1351 uint16_t point;
1352 uint16_t len;
1353 uint32_t addr_check;
1354
1355 if (handle == NULL) /* check handle */
1356 {
1357 return 2; /* return error */
1358 }
1359 if (handle->inited != 1) /* check handle initialization */
1360 {
1361 return 3; /* return error */
1362 }
1363
1364 buf[0] = AS608_COMMAND_UP_IMAGE; /* upload image */
1365 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
1366 if (res != 0) /* check result */
1367 {
1368 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1369
1370 return 1; /* return error */
1371 }
1372 len = 1; /* len 1 */
1373 res = a_as608_uart_decode_with_length(handle, 12, 100,
1374 &addr_check, buf, &len); /* decode */
1375 if (res != 0) /* check result */
1376 {
1377 return 4; /* return error */
1378 }
1379 if (addr_check != addr) /* check addr */
1380 {
1381 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1382
1383 return 5; /* return error */
1384 }
1385 if (len != 1) /* check length */
1386 {
1387 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1388
1389 return 6; /* return error */
1390 }
1391 handle->status = buf[0]; /* save status */
1392 *status = (as608_status_t)handle->status; /* set status */
1393 point = 0; /* init 0 */
1394 len = *output_len; /* get the length */
1395 l = *output_len; /* get the length */
1396 while (1) /* loop */
1397 {
1398 as608_bool_t end_enable;
1399 as608_bool_t full_enable;
1400
1401 l = len; /* set the remain max buffer size */
1402 res = a_as608_uart_parse_data(handle, 100, &addr_check,
1403 output_buffer + point,
1404 &l, &end_enable, &full_enable); /* parse the data */
1405 if (res != 0)
1406 {
1407 return 4; /* return error */
1408 }
1409 if (addr_check != addr) /* check addr */
1410 {
1411 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1412
1413 return 5; /* return error */
1414 }
1415 len -= l; /* remain length - read length */
1416 point += l; /* current point adds read length */
1417 if (full_enable == AS608_BOOL_TRUE) /* if buffer is full */
1418 {
1419 handle->debug_print("as608: buffer is full.\n"); /* buffer is full */
1420
1421 return 7; /* return error */
1422 }
1423 if (end_enable == AS608_BOOL_TRUE) /* if the last packet */
1424 {
1425 break; /* break */
1426 }
1427 }
1428 *output_len = point; /* save the length */
1429
1430 return 0; /* success return 0 */
1431}
1432
1450uint8_t as608_download_image(as608_handle_t *handle, uint32_t addr, uint8_t *input_buffer,
1451 uint16_t input_len, as608_status_t *status)
1452{
1453 uint8_t res;
1454 uint8_t buf[1];
1455 uint16_t i;
1456 uint16_t m;
1457 uint16_t n;
1458 uint16_t len;
1459 uint32_t addr_check;
1460
1461 if (handle == NULL) /* check handle */
1462 {
1463 return 2; /* return error */
1464 }
1465 if (handle->inited != 1) /* check handle initialization */
1466 {
1467 return 3; /* return error */
1468 }
1469
1470 buf[0] = AS608_COMMAND_DOWN_IMAGE; /* download char */
1471 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
1472 if (res != 0) /* check result */
1473 {
1474 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1475
1476 return 1; /* return error */
1477 }
1478 len = 1; /* len 1 */
1479 res = a_as608_uart_decode_with_length(handle, 12, 100, &addr_check, buf, &len); /* decode */
1480 if (res != 0) /* check result */
1481 {
1482 return 4; /* return error */
1483 }
1484 if (addr_check != addr) /* check addr */
1485 {
1486 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1487
1488 return 5; /* return error */
1489 }
1490 if (len != 1) /* check length */
1491 {
1492 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1493
1494 return 6; /* return error */
1495 }
1496 handle->status = buf[0]; /* save status */
1497 *status = (as608_status_t)handle->status; /* set status */
1498
1499 m = input_len / handle->packet_size; /* set m */
1500 n = input_len % handle->packet_size; /* set n */
1501 if (n != 0) /* check n */
1502 {
1503 for (i = 0; i < m; i++) /* m times */
1504 {
1505 res = a_as608_uart_write(handle, addr, AS608_TYPE_DATA,
1506 input_buffer + i * handle->packet_size,
1507 handle->packet_size); /* write data */
1508 if (res != 0) /* check result */
1509 {
1510 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1511
1512 return 1; /* return error */
1513 }
1514 handle->delay_ms(100); /* delay 100ms */
1515 }
1516 res = a_as608_uart_write(handle, addr, AS608_TYPE_END,
1517 input_buffer + m * handle->packet_size, n); /* write data */
1518 if (res != 0) /* check result */
1519 {
1520 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1521
1522 return 1; /* return error */
1523 }
1524 handle->delay_ms(100); /* delay 100ms */
1525 }
1526 else
1527 {
1528 for (i = 0; i < (m - 1); i++) /* m - 1 times */
1529 {
1530 res = a_as608_uart_write(handle, addr, AS608_TYPE_DATA,
1531 input_buffer + i * handle->packet_size,
1532 handle->packet_size); /* write data */
1533 if (res != 0) /* check result */
1534 {
1535 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1536
1537 return 1; /* return error */
1538 }
1539 handle->delay_ms(100); /* delay 100ms */
1540 }
1541 res = a_as608_uart_write(handle, addr, AS608_TYPE_END,
1542 input_buffer + (m - 1) * handle->packet_size,
1543 handle->packet_size); /* write data */
1544 if (res != 0) /* check result */
1545 {
1546 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1547
1548 return 1; /* return error */
1549 }
1550 handle->delay_ms(100); /* delay 100ms */
1551 }
1552
1553 return 0; /* success return 0 */
1554}
1555
1573uint8_t as608_delete_feature(as608_handle_t *handle, uint32_t addr, uint16_t page_number, uint16_t number, as608_status_t *status)
1574{
1575 uint8_t res;
1576 uint8_t buf[5];
1577 uint16_t len;
1578 uint32_t addr_check;
1579
1580 if (handle == NULL) /* check handle */
1581 {
1582 return 2; /* return error */
1583 }
1584 if (handle->inited != 1) /* check handle initialization */
1585 {
1586 return 3; /* return error */
1587 }
1588
1589 buf[0] = AS608_COMMAND_DELETE_CHAR; /* delete char feature */
1590 buf[1] = (page_number >> 8) & 0xFF; /* page number msb */
1591 buf[2] = (page_number >> 0) & 0xFF; /* page number lsb */
1592 buf[3] = (number >> 8) & 0xFF; /* number msb */
1593 buf[4] = (number >> 0) & 0xFF; /* number lsb */
1594 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 5); /* write data */
1595 if (res != 0) /* check result */
1596 {
1597 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1598
1599 return 1; /* return error */
1600 }
1601 len = 1; /* len 1 */
1602 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
1603 if (res != 0) /* check result */
1604 {
1605 return 4; /* return error */
1606 }
1607 if (addr_check != addr) /* check addr */
1608 {
1609 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1610
1611 return 5; /* return error */
1612 }
1613 if (len != 1) /* check length */
1614 {
1615 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1616
1617 return 6; /* return error */
1618 }
1619 handle->status = buf[0]; /* save status */
1620 *status = (as608_status_t)handle->status; /* set status */
1621
1622 return 0; /* success return 0 */
1623}
1624
1640uint8_t as608_empty_all_feature(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
1641{
1642 uint8_t res;
1643 uint8_t buf[1];
1644 uint16_t len;
1645 uint32_t addr_check;
1646
1647 if (handle == NULL) /* check handle */
1648 {
1649 return 2; /* return error */
1650 }
1651 if (handle->inited != 1) /* check handle initialization */
1652 {
1653 return 3; /* return error */
1654 }
1655
1656 buf[0] = AS608_COMMAND_EMPTY; /* empty all char feature */
1657 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
1658 if (res != 0) /* check result */
1659 {
1660 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1661
1662 return 1; /* return error */
1663 }
1664 len = 1; /* len 1 */
1665 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
1666 if (res != 0) /* check result */
1667 {
1668 return 4; /* return error */
1669 }
1670 if (addr_check != addr) /* check addr */
1671 {
1672 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1673
1674 return 5; /* return error */
1675 }
1676 if (len != 1) /* check length */
1677 {
1678 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1679
1680 return 6; /* return error */
1681 }
1682 handle->status = buf[0]; /* save status */
1683 *status = (as608_status_t)handle->status; /* set status */
1684
1685 return 0; /* success return 0 */
1686}
1687
1704uint8_t as608_set_baud_rate(as608_handle_t *handle, uint32_t addr, uint8_t n_9600, as608_status_t *status)
1705{
1706 uint8_t res;
1707 uint8_t buf[3];
1708 uint16_t len;
1709 uint32_t addr_check;
1710
1711 if (handle == NULL) /* check handle */
1712 {
1713 return 2; /* return error */
1714 }
1715 if (handle->inited != 1) /* check handle initialization */
1716 {
1717 return 3; /* return error */
1718 }
1719
1720 buf[0] = AS608_COMMAND_WRITE_REG; /* write reg */
1721 buf[1] = 0x04; /* baud rate */
1722 buf[2] = n_9600; /* n x 9600 */
1723 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 3); /* write data */
1724 if (res != 0) /* check result */
1725 {
1726 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1727
1728 return 1; /* return error */
1729 }
1730 len = 1; /* len 1 */
1731 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
1732 if (res != 0) /* check result */
1733 {
1734 return 4; /* return error */
1735 }
1736 if (addr_check != addr) /* check addr */
1737 {
1738 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1739
1740 return 5; /* return error */
1741 }
1742 if (len != 1) /* check length */
1743 {
1744 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1745
1746 return 6; /* return error */
1747 }
1748 handle->status = buf[0]; /* save status */
1749 *status = (as608_status_t)handle->status; /* set status */
1750
1751 return 0; /* success return 0 */
1752}
1753
1770uint8_t as608_set_level(as608_handle_t *handle, uint32_t addr, as608_level_t level, as608_status_t *status)
1771{
1772 uint8_t res;
1773 uint8_t buf[3];
1774 uint16_t len;
1775 uint32_t addr_check;
1776
1777 if (handle == NULL) /* check handle */
1778 {
1779 return 2; /* return error */
1780 }
1781 if (handle->inited != 1) /* check handle initialization */
1782 {
1783 return 3; /* return error */
1784 }
1785
1786 buf[0] = AS608_COMMAND_WRITE_REG; /* write reg */
1787 buf[1] = 0x05; /* level settings */
1788 buf[2] = level; /* set level */
1789 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 3); /* write data */
1790 if (res != 0) /* check result */
1791 {
1792 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1793
1794 return 1; /* return error */
1795 }
1796 len = 1; /* len 1 */
1797 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
1798 if (res != 0) /* check result */
1799 {
1800 return 4; /* return error */
1801 }
1802 if (addr_check != addr) /* check addr */
1803 {
1804 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1805
1806 return 5; /* return error */
1807 }
1808 if (len != 1) /* check length */
1809 {
1810 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1811
1812 return 6; /* return error */
1813 }
1814 handle->status = buf[0]; /* save status */
1815 *status = (as608_status_t)handle->status; /* set status */
1816
1817 return 0; /* success return 0 */
1818}
1819
1836uint8_t as608_set_packet_size(as608_handle_t *handle, uint32_t addr, as608_packet_size_t size, as608_status_t *status)
1837{
1838 uint8_t res;
1839 uint8_t buf[3];
1840 uint16_t len;
1841 uint32_t addr_check;
1842
1843 if (handle == NULL) /* check handle */
1844 {
1845 return 2; /* return error */
1846 }
1847 if (handle->inited != 1) /* check handle initialization */
1848 {
1849 return 3; /* return error */
1850 }
1851
1852 buf[0] = AS608_COMMAND_WRITE_REG; /* write reg */
1853 buf[1] = 0x06; /* size settings */
1854 buf[2] = size; /* set size */
1855 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 3); /* write data */
1856 if (res != 0) /* check result */
1857 {
1858 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1859
1860 return 1; /* return error */
1861 }
1862 len = 1; /* len 1 */
1863 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
1864 if (res != 0) /* check result */
1865 {
1866 return 4; /* return error */
1867 }
1868 if (addr_check != addr) /* check addr */
1869 {
1870 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1871
1872 return 5; /* return error */
1873 }
1874 if (len != 1) /* check length */
1875 {
1876 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1877
1878 return 6; /* return error */
1879 }
1880 handle->status = buf[0]; /* save status */
1881 *status = (as608_status_t)handle->status; /* set status */
1882 handle->packet_size = (uint16_t)(32.0f * powf(2.0f,
1883 (float)((uint16_t)size))); /* packet size */
1884
1885 return 0; /* success return 0 */
1886}
1887
1904uint8_t as608_get_params(as608_handle_t *handle, uint32_t addr, as608_params_t *param, as608_status_t *status)
1905{
1906 uint8_t res;
1907 uint8_t buf[17];
1908 uint16_t len;
1909 uint32_t addr_check;
1910
1911 if (handle == NULL) /* check handle */
1912 {
1913 return 2; /* return error */
1914 }
1915 if (handle->inited != 1) /* check handle initialization */
1916 {
1917 return 3; /* return error */
1918 }
1919
1920 buf[0] = AS608_COMMAND_READ_SYS_PARA; /* read sys para */
1921 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
1922 if (res != 0) /* check result */
1923 {
1924 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
1925
1926 return 1; /* return error */
1927 }
1928 len = 17; /* len 17 */
1929 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
1930 if (res != 0) /* check result */
1931 {
1932 return 4; /* return error */
1933 }
1934 if (addr_check != addr) /* check addr */
1935 {
1936 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
1937
1938 return 5; /* return error */
1939 }
1940 if (len != 17) /* check length */
1941 {
1942 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
1943
1944 return 6; /* return error */
1945 }
1946 handle->status = buf[0]; /* save status */
1947 *status = (as608_status_t)handle->status; /* set status */
1948 param->status = (uint16_t)((uint16_t)buf[1] << 8) | buf[2]; /* set current status */
1950 ((uint16_t)((uint16_t)buf[3] << 8) | buf[4]); /* set sensor type */
1951 param->fingerprint_size = (uint16_t)((uint16_t)buf[5] << 8) | buf[6]; /* set fingerprint size */
1952 param->level = (as608_level_t)
1953 ((uint16_t)((uint16_t)buf[7] << 8) | buf[8]); /* set level */
1954 param->address = (uint32_t)((uint32_t)buf[9] << 24) |
1955 (uint32_t)((uint32_t)buf[10] << 16) |
1956 (uint32_t)((uint32_t)buf[11] << 8) |
1957 (uint32_t)((uint32_t)buf[12] << 0); /* set address */
1959 ((uint16_t)((uint16_t)buf[13] << 8) | buf[14]); /* set packet size */
1960 param->n_9600 = (uint16_t)((uint16_t)buf[15] << 8) | buf[16]; /* set n_9600 */
1961
1962 return 0; /* success return 0 */
1963}
1964
1981uint8_t as608_enroll(as608_handle_t *handle, uint32_t addr, uint16_t *page_number, as608_status_t *status)
1982{
1983 uint8_t res;
1984 uint8_t buf[3];
1985 uint16_t len;
1986 uint32_t addr_check;
1987
1988 if (handle == NULL) /* check handle */
1989 {
1990 return 2; /* return error */
1991 }
1992 if (handle->inited != 1) /* check handle initialization */
1993 {
1994 return 3; /* return error */
1995 }
1996
1997 buf[0] = AS608_COMMAND_ENROLL; /* enroll */
1998 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
1999 if (res != 0) /* check result */
2000 {
2001 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2002
2003 return 1; /* return error */
2004 }
2005 len = 3; /* len 3 */
2006 res = a_as608_uart_decode(handle, 1000, &addr_check, buf, &len); /* decode */
2007 if (res != 0) /* check result */
2008 {
2009 return 4; /* return error */
2010 }
2011 if (addr_check != addr) /* check addr */
2012 {
2013 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2014
2015 return 5; /* return error */
2016 }
2017 if (len != 3) /* check length */
2018 {
2019 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2020
2021 return 6; /* return error */
2022 }
2023 handle->status = buf[0]; /* save status */
2024 *status = (as608_status_t)handle->status; /* set status */
2025 *page_number = (uint16_t)((uint16_t)buf[1]) | buf[2]; /* set page number */
2026
2027 return 0; /* success return 0 */
2028}
2029
2047uint8_t as608_identify(as608_handle_t *handle, uint32_t addr, uint16_t *page_number, uint16_t *score, as608_status_t *status)
2048{
2049 uint8_t res;
2050 uint8_t buf[5];
2051 uint16_t len;
2052 uint32_t addr_check;
2053
2054 if (handle == NULL) /* check handle */
2055 {
2056 return 2; /* return error */
2057 }
2058 if (handle->inited != 1) /* check handle initialization */
2059 {
2060 return 3; /* return error */
2061 }
2062
2063 buf[0] = AS608_COMMAND_IDENTIFY; /* identify */
2064 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
2065 if (res != 0) /* check result */
2066 {
2067 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2068
2069 return 1; /* return error */
2070 }
2071 len = 5; /* len 5 */
2072 res = a_as608_uart_decode(handle, 1000, &addr_check, buf, &len); /* decode */
2073 if (res != 0) /* check result */
2074 {
2075 return 4; /* return error */
2076 }
2077 if (addr_check != addr) /* check addr */
2078 {
2079 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2080
2081 return 5; /* return error */
2082 }
2083 if (len != 5) /* check length */
2084 {
2085 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2086
2087 return 6; /* return error */
2088 }
2089 handle->status = buf[0]; /* save status */
2090 *status = (as608_status_t)handle->status; /* set status */
2091 *page_number = (uint16_t)((uint16_t)buf[1]) | buf[2]; /* set page number */
2092 *score = (uint16_t)((uint16_t)buf[3]) | buf[4]; /* set score */
2093
2094 return 0; /* success return 0 */
2095}
2096
2113uint8_t as608_set_password(as608_handle_t *handle, uint32_t addr, uint32_t password, as608_status_t *status)
2114{
2115 uint8_t res;
2116 uint8_t buf[5];
2117 uint16_t len;
2118 uint32_t addr_check;
2119
2120 if (handle == NULL) /* check handle */
2121 {
2122 return 2; /* return error */
2123 }
2124 if (handle->inited != 1) /* check handle initialization */
2125 {
2126 return 3; /* return error */
2127 }
2128
2129 buf[0] = AS608_COMMAND_SET_PWD; /* set password */
2130 buf[1] = (password >> 24) & 0xFF; /* set password */
2131 buf[2] = (password >> 16) & 0xFF; /* set password */
2132 buf[3] = (password >> 8) & 0xFF; /* set password */
2133 buf[4] = (password >> 0) & 0xFF; /* set password */
2134 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 5); /* write data */
2135 if (res != 0) /* check result */
2136 {
2137 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2138
2139 return 1; /* return error */
2140 }
2141 len = 1; /* len 1 */
2142 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2143 if (res != 0) /* check result */
2144 {
2145 return 4; /* return error */
2146 }
2147 if (addr_check != addr) /* check addr */
2148 {
2149 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2150
2151 return 5; /* return error */
2152 }
2153 if (len != 1) /* check length */
2154 {
2155 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2156
2157 return 6; /* return error */
2158 }
2159 handle->status = buf[0]; /* save status */
2160 *status = (as608_status_t)handle->status; /* set status */
2161
2162 return 0; /* success return 0 */
2163}
2164
2181uint8_t as608_verify_password(as608_handle_t *handle, uint32_t addr, uint32_t password, as608_status_t *status)
2182{
2183 uint8_t res;
2184 uint8_t buf[5];
2185 uint16_t len;
2186 uint32_t addr_check;
2187
2188 if (handle == NULL) /* check handle */
2189 {
2190 return 2; /* return error */
2191 }
2192 if (handle->inited != 1) /* check handle initialization */
2193 {
2194 return 3; /* return error */
2195 }
2196
2197 buf[0] = AS608_COMMAND_VFY_PWD; /* verify password */
2198 buf[1] = (password >> 24) & 0xFF; /* set password */
2199 buf[2] = (password >> 16) & 0xFF; /* set password */
2200 buf[3] = (password >> 8) & 0xFF; /* set password */
2201 buf[4] = (password >> 0) & 0xFF; /* set password */
2202 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 5); /* write data */
2203 if (res != 0) /* check result */
2204 {
2205 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2206
2207 return 1; /* return error */
2208 }
2209 len = 1; /* len 1 */
2210 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2211 if (res != 0) /* check result */
2212 {
2213 return 4; /* return error */
2214 }
2215 if (addr_check != addr) /* check addr */
2216 {
2217 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2218
2219 return 5; /* return error */
2220 }
2221 if (len != 1) /* check length */
2222 {
2223 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2224
2225 return 6; /* return error */
2226 }
2227 handle->status = buf[0]; /* save status */
2228 *status = (as608_status_t)handle->status; /* set status */
2229
2230 return 0; /* success return 0 */
2231}
2232
2249uint8_t as608_get_random(as608_handle_t *handle, uint32_t addr, uint32_t *randn, as608_status_t *status)
2250{
2251 uint8_t res;
2252 uint8_t buf[5];
2253 uint16_t len;
2254 uint32_t addr_check;
2255
2256 if (handle == NULL) /* check handle */
2257 {
2258 return 2; /* return error */
2259 }
2260 if (handle->inited != 1) /* check handle initialization */
2261 {
2262 return 3; /* return error */
2263 }
2264
2265 buf[0] = AS608_COMMAND_GET_RANDOM_CODE; /* get random code */
2266 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
2267 if (res != 0) /* check result */
2268 {
2269 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2270
2271 return 1; /* return error */
2272 }
2273 len = 5; /* len 5 */
2274 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2275 if (res != 0) /* check result */
2276 {
2277 return 4; /* return error */
2278 }
2279 if (addr_check != addr) /* check addr */
2280 {
2281 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2282
2283 return 5; /* return error */
2284 }
2285 if (len != 5) /* check length */
2286 {
2287 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2288
2289 return 6; /* return error */
2290 }
2291 handle->status = buf[0]; /* save status */
2292 *status = (as608_status_t)handle->status; /* set status */
2293 *randn = (uint32_t)((uint32_t)buf[1] << 24) |
2294 (uint32_t)((uint32_t)buf[2] << 16) |
2295 (uint32_t)((uint32_t)buf[3] << 8) |
2296 (uint32_t)((uint32_t)buf[4] << 0); /* get the random */
2297
2298 return 0; /* success return 0 */
2299}
2300
2317uint8_t as608_set_chip_address(as608_handle_t *handle, uint32_t addr, uint32_t new_addr, as608_status_t *status)
2318{
2319 uint8_t res;
2320 uint8_t buf[5];
2321 uint16_t len;
2322 uint32_t addr_check;
2323
2324 if (handle == NULL) /* check handle */
2325 {
2326 return 2; /* return error */
2327 }
2328 if (handle->inited != 1) /* check handle initialization */
2329 {
2330 return 3; /* return error */
2331 }
2332
2333 buf[0] = AS608_COMMAND_SET_CHIP_ADDR; /* set chip addr */
2334 buf[1] = (new_addr >> 24) & 0xFF; /* set chip addr */
2335 buf[2] = (new_addr >> 16) & 0xFF; /* set chip addr*/
2336 buf[3] = (new_addr >> 8) & 0xFF; /* set chip addr */
2337 buf[4] = (new_addr >> 0) & 0xFF; /* set chip addr */
2338 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 5); /* write data */
2339 if (res != 0) /* check result */
2340 {
2341 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2342
2343 return 1; /* return error */
2344 }
2345 len = 1; /* len 1 */
2346 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2347 if (res != 0) /* check result */
2348 {
2349 return 4; /* return error */
2350 }
2351 if (addr_check != new_addr) /* check addr */
2352 {
2353 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2354
2355 return 5; /* return error */
2356 }
2357 if (len != 1) /* check length */
2358 {
2359 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2360
2361 return 6; /* return error */
2362 }
2363 handle->status = buf[0]; /* save status */
2364 *status = (as608_status_t)handle->status; /* set status */
2365
2366 return 0; /* success return 0 */
2367}
2368
2387uint8_t as608_get_flash_information(as608_handle_t *handle, uint32_t addr,
2388 uint8_t *output_buffer, uint16_t *output_len, as608_status_t *status)
2389{
2390 uint8_t res;
2391 uint8_t buf[1];
2392 uint16_t l;
2393 uint16_t point;
2394 uint16_t len;
2395 uint32_t addr_check;
2396
2397 if (handle == NULL) /* check handle */
2398 {
2399 return 2; /* return error */
2400 }
2401 if (handle->inited != 1) /* check handle initialization */
2402 {
2403 return 3; /* return error */
2404 }
2405
2406 buf[0] = AS608_COMMAND_READ_INFO_PAGE; /* read info page */
2407 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
2408 if (res != 0) /* check result */
2409 {
2410 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2411
2412 return 1; /* return error */
2413 }
2414 len = 1; /* len 1 */
2415 res = a_as608_uart_decode_with_length(handle, 12, 100, &addr_check,
2416 buf, &len); /* decode */
2417 if (res != 0) /* check result */
2418 {
2419 return 4; /* return error */
2420 }
2421 if (addr_check != addr) /* check addr */
2422 {
2423 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2424
2425 return 5; /* return error */
2426 }
2427 if (len != 1) /* check length */
2428 {
2429 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2430
2431 return 6; /* return error */
2432 }
2433 handle->status = buf[0]; /* save status */
2434 *status = (as608_status_t)handle->status; /* set status */
2435 point = 0; /* init 0 */
2436 len = *output_len; /* get the length */
2437 l = *output_len; /* get the length */
2438 while (1) /* loop */
2439 {
2440 as608_bool_t end_enable;
2441 as608_bool_t full_enable;
2442
2443 l = len; /* set the remain max buffer size */
2444 res = a_as608_uart_parse_data(handle, 100, &addr_check,
2445 output_buffer + point,
2446 &l, &end_enable, &full_enable); /* parse the data */
2447 if (res != 0)
2448 {
2449 return 4; /* return error */
2450 }
2451 if (addr_check != addr) /* check addr */
2452 {
2453 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2454
2455 return 5; /* return error */
2456 }
2457 len -= l; /* remain length - read length */
2458 point += l; /* current point adds read length */
2459 if (full_enable == AS608_BOOL_TRUE) /* if buffer is full */
2460 {
2461 handle->debug_print("as608: buffer is full.\n"); /* buffer is full */
2462
2463 return 7; /* return error */
2464 }
2465 if (end_enable == AS608_BOOL_TRUE) /* if the last packet */
2466 {
2467 break; /* break */
2468 }
2469 }
2470 *output_len = point; /* save the length */
2471
2472 return 0; /* success return 0 */
2473}
2474
2491uint8_t as608_set_port(as608_handle_t *handle, uint32_t addr, as608_bool_t enable, as608_status_t *status)
2492{
2493 uint8_t res;
2494 uint8_t buf[2];
2495 uint16_t len;
2496 uint32_t addr_check;
2497
2498 if (handle == NULL) /* check handle */
2499 {
2500 return 2; /* return error */
2501 }
2502 if (handle->inited != 1) /* check handle initialization */
2503 {
2504 return 3; /* return error */
2505 }
2506
2507 buf[0] = AS608_COMMAND_PORT_CONTROL; /* port control */
2508 buf[1] = enable; /* set chip addr */
2509 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 2); /* write data */
2510 if (res != 0) /* check result */
2511 {
2512 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2513
2514 return 1; /* return error */
2515 }
2516 len = 1; /* len 1 */
2517 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2518 if (res != 0) /* check result */
2519 {
2520 return 4; /* return error */
2521 }
2522 if (addr_check != addr) /* check addr */
2523 {
2524 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2525
2526 return 5; /* return error */
2527 }
2528 if (len != 1) /* check length */
2529 {
2530 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2531
2532 return 6; /* return error */
2533 }
2534 handle->status = buf[0]; /* save status */
2535 *status = (as608_status_t)handle->status; /* set status */
2536
2537 return 0; /* success return 0 */
2538}
2539
2558uint8_t as608_write_notepad(as608_handle_t *handle, uint32_t addr, uint8_t page_number, uint8_t data[32], as608_status_t *status)
2559{
2560 uint8_t res;
2561 uint8_t buf[34];
2562 uint16_t len;
2563 uint32_t addr_check;
2564
2565 if (handle == NULL) /* check handle */
2566 {
2567 return 2; /* return error */
2568 }
2569 if (handle->inited != 1) /* check handle initialization */
2570 {
2571 return 3; /* return error */
2572 }
2573 if (page_number > 16) /* check page number */
2574 {
2575 handle->debug_print("as608: page_number > 16.\n"); /* page_number > 16 */
2576
2577 return 7; /* return error */
2578 }
2579
2580 buf[0] = AS608_COMMAND_WRITE_NOTEPAD; /* write notepad */
2581 buf[1] = page_number; /* set page number */
2582 memcpy(&buf[2], data, 32); /* copy data */
2583 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 34); /* write data */
2584 if (res != 0) /* check result */
2585 {
2586 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2587
2588 return 1; /* return error */
2589 }
2590 len = 1; /* len 1 */
2591 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2592 if (res != 0) /* check result */
2593 {
2594 return 4; /* return error */
2595 }
2596 if (addr_check != addr) /* check addr */
2597 {
2598 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2599
2600 return 5; /* return error */
2601 }
2602 if (len != 1) /* check length */
2603 {
2604 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2605
2606 return 6; /* return error */
2607 }
2608 handle->status = buf[0]; /* save status */
2609 *status = (as608_status_t)handle->status; /* set status */
2610
2611 return 0; /* success return 0 */
2612}
2613
2632uint8_t as608_read_notepad(as608_handle_t *handle, uint32_t addr, uint8_t page_number, uint8_t data[32], as608_status_t *status)
2633{
2634 uint8_t res;
2635 uint8_t buf[33];
2636 uint16_t len;
2637 uint32_t addr_check;
2638
2639 if (handle == NULL) /* check handle */
2640 {
2641 return 2; /* return error */
2642 }
2643 if (handle->inited != 1) /* check handle initialization */
2644 {
2645 return 3; /* return error */
2646 }
2647 if (page_number > 16) /* check page number */
2648 {
2649 handle->debug_print("as608: page_number > 16.\n"); /* page_number > 16 */
2650
2651 return 7; /* return error */
2652 }
2653
2654 buf[0] = AS608_COMMAND_READ_NOTEPAD; /* read notepad */
2655 buf[1] = page_number; /* set page number */
2656 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 2); /* write data */
2657 if (res != 0) /* check result */
2658 {
2659 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2660
2661 return 1; /* return error */
2662 }
2663 len = 33; /* len 33 */
2664 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2665 if (res != 0) /* check result */
2666 {
2667 return 4; /* return error */
2668 }
2669 if (addr_check != addr) /* check addr */
2670 {
2671 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2672
2673 return 5; /* return error */
2674 }
2675 if (len != 33) /* check length */
2676 {
2677 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2678
2679 return 6; /* return error */
2680 }
2681 handle->status = buf[0]; /* save status */
2682 *status = (as608_status_t)handle->status; /* set status */
2683 memcpy(data, &buf[1], 32); /* copy data */
2684
2685 return 0; /* success return 0 */
2686}
2687
2706uint8_t as608_burn_code(as608_handle_t *handle, uint32_t addr, as608_burn_code_mode_t mode,
2707 uint8_t *input_buffer, uint16_t input_len, as608_status_t *status)
2708{
2709 uint8_t res;
2710 uint8_t buf[2];
2711 uint16_t i;
2712 uint16_t m;
2713 uint16_t n;
2714 uint16_t len;
2715 uint32_t addr_check;
2716
2717 if (handle == NULL) /* check handle */
2718 {
2719 return 2; /* return error */
2720 }
2721 if (handle->inited != 1) /* check handle initialization */
2722 {
2723 return 3; /* return error */
2724 }
2725
2726 buf[0] = AS608_COMMAND_BURN_CODE; /* burn code */
2727 buf[1] = mode; /* set burn code */
2728 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 2); /* write data */
2729 if (res != 0) /* check result */
2730 {
2731 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2732
2733 return 1; /* return error */
2734 }
2735 len = 1; /* len 1 */
2736 res = a_as608_uart_decode_with_length(handle, 12, 100, &addr_check, buf, &len); /* decode */
2737 if (res != 0) /* check result */
2738 {
2739 return 4; /* return error */
2740 }
2741 if (addr_check != addr) /* check addr */
2742 {
2743 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2744
2745 return 5; /* return error */
2746 }
2747 if (len != 1) /* check length */
2748 {
2749 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2750
2751 return 6; /* return error */
2752 }
2753 handle->status = buf[0]; /* save status */
2754 *status = (as608_status_t)handle->status; /* set status */
2755
2756 m = input_len / handle->packet_size; /* set m */
2757 n = input_len % handle->packet_size; /* set n */
2758 if (n != 0) /* check n */
2759 {
2760 for (i = 0; i < m; i++) /* m times */
2761 {
2762 res = a_as608_uart_write(handle, addr, AS608_TYPE_DATA,
2763 input_buffer + i * handle->packet_size,
2764 handle->packet_size); /* write data */
2765 if (res != 0) /* check result */
2766 {
2767 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2768
2769 return 1; /* return error */
2770 }
2771 handle->delay_ms(100); /* delay 100ms */
2772 }
2773 res = a_as608_uart_write(handle, addr, AS608_TYPE_END,
2774 input_buffer + m * handle->packet_size, n); /* write data */
2775 if (res != 0) /* check result */
2776 {
2777 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2778
2779 return 1; /* return error */
2780 }
2781 handle->delay_ms(100); /* delay 100ms */
2782 }
2783 else
2784 {
2785 for (i = 0; i < (m - 1); i++) /* m - 1 times */
2786 {
2787 res = a_as608_uart_write(handle, addr, AS608_TYPE_DATA,
2788 input_buffer + i * handle->packet_size,
2789 handle->packet_size); /* write data */
2790 if (res != 0) /* check result */
2791 {
2792 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2793
2794 return 1; /* return error */
2795 }
2796 handle->delay_ms(100); /* delay 100ms */
2797 }
2798 res = a_as608_uart_write(handle, addr, AS608_TYPE_END,
2799 input_buffer + (m - 1) * handle->packet_size,
2800 handle->packet_size); /* write data */
2801 if (res != 0) /* check result */
2802 {
2803 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2804
2805 return 1; /* return error */
2806 }
2807 handle->delay_ms(100); /* delay 100ms */
2808 }
2809
2810 return 0; /* success return 0 */
2811}
2812
2833uint8_t as608_high_speed_search(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t buffer_number,
2834 uint16_t start_page, uint16_t page_number,
2835 uint16_t *found_page, uint16_t *score,
2836 as608_status_t *status)
2837{
2838 uint8_t res;
2839 uint8_t buf[6];
2840 uint16_t len;
2841 uint32_t addr_check;
2842
2843 if (handle == NULL) /* check handle */
2844 {
2845 return 2; /* return error */
2846 }
2847 if (handle->inited != 1) /* check handle initialization */
2848 {
2849 return 3; /* return error */
2850 }
2851
2852 buf[0] = AS608_COMMAND_HIGH_SPEED_SEARCH; /* high speed search */
2853 buf[1] = buffer_number; /* set buffer number */
2854 buf[2] = (start_page >> 8) & 0xFF; /* start page msb */
2855 buf[3] = (start_page >> 0) & 0xFF; /* start page lsb */
2856 buf[4] = (page_number >> 8) & 0xFF; /* page number msb */
2857 buf[5] = (page_number >> 0) & 0xFF; /* page number lsb */
2858 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 6); /* write data */
2859 if (res != 0) /* check result */
2860 {
2861 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2862
2863 return 1; /* return error */
2864 }
2865 len = 5; /* len 5 */
2866 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2867 if (res != 0) /* check result */
2868 {
2869 return 4; /* return error */
2870 }
2871 if (addr_check != addr) /* check addr */
2872 {
2873 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2874
2875 return 5; /* return error */
2876 }
2877 if (len != 5) /* check length */
2878 {
2879 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2880
2881 return 6; /* return error */
2882 }
2883 handle->status = buf[0]; /* save status */
2884 *status = (as608_status_t)handle->status; /* set status */
2885 *found_page = (uint16_t)((uint16_t)buf[1] << 8) | buf[2]; /* set found page */
2886 *score = (uint16_t)((uint16_t)buf[3] << 8) | buf[4]; /* set score */
2887
2888 return 0; /* success return 0 */
2889}
2890
2907uint8_t as608_generate_bin_image(as608_handle_t *handle, uint32_t addr, as608_image_t image, as608_status_t *status)
2908{
2909 uint8_t res;
2910 uint8_t buf[2];
2911 uint16_t len;
2912 uint32_t addr_check;
2913
2914 if (handle == NULL) /* check handle */
2915 {
2916 return 2; /* return error */
2917 }
2918 if (handle->inited != 1) /* check handle initialization */
2919 {
2920 return 3; /* return error */
2921 }
2922
2923 buf[0] = AS608_COMMAND_GEN_BIN_IMAGE; /* generate bin image */
2924 buf[1] = image; /* set image */
2925 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 2); /* write data */
2926 if (res != 0) /* check result */
2927 {
2928 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2929
2930 return 1; /* return error */
2931 }
2932 len = 1; /* len 1 */
2933 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2934 if (res != 0) /* check result */
2935 {
2936 return 4; /* return error */
2937 }
2938 if (addr_check != addr) /* check addr */
2939 {
2940 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
2941
2942 return 5; /* return error */
2943 }
2944 if (len != 1) /* check length */
2945 {
2946 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
2947
2948 return 6; /* return error */
2949 }
2950 handle->status = buf[0]; /* save status */
2951 *status = (as608_status_t)handle->status; /* set status */
2952
2953 return 0; /* success return 0 */
2954}
2955
2972uint8_t as608_get_valid_template_number(as608_handle_t *handle, uint32_t addr, uint16_t *num, as608_status_t *status)
2973{
2974 uint8_t res;
2975 uint8_t buf[3];
2976 uint16_t len;
2977 uint32_t addr_check;
2978
2979 if (handle == NULL) /* check handle */
2980 {
2981 return 2; /* return error */
2982 }
2983 if (handle->inited != 1) /* check handle initialization */
2984 {
2985 return 3; /* return error */
2986 }
2987
2988 buf[0] = AS608_COMMAND_VALID_TEMPLATE_NUM; /* valid template num */
2989 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 1); /* write data */
2990 if (res != 0) /* check result */
2991 {
2992 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
2993
2994 return 1; /* return error */
2995 }
2996 len = 3; /* len 3 */
2997 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
2998 if (res != 0) /* check result */
2999 {
3000 return 4; /* return error */
3001 }
3002 if (addr_check != addr) /* check addr */
3003 {
3004 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
3005
3006 return 5; /* return error */
3007 }
3008 if (len != 3) /* check length */
3009 {
3010 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
3011
3012 return 6; /* return error */
3013 }
3014 handle->status = buf[0]; /* save status */
3015 *status = (as608_status_t)handle->status; /* set status */
3016 *num = (uint16_t)((uint16_t)buf[1] << 8) | buf[2]; /* get the number */
3017
3018 return 0; /* success return 0 */
3019}
3020
3039uint8_t as608_set_gpio_level(as608_handle_t *handle, uint32_t addr, as608_gpio_number_t gpio,
3040 as608_gpio_level_t input_level, as608_gpio_level_t *output_level, as608_status_t *status)
3041{
3042 uint8_t res;
3043 uint8_t buf[3];
3044 uint16_t len;
3045 uint32_t addr_check;
3046
3047 if (handle == NULL) /* check handle */
3048 {
3049 return 2; /* return error */
3050 }
3051 if (handle->inited != 1) /* check handle initialization */
3052 {
3053 return 3; /* return error */
3054 }
3055
3056 buf[0] = AS608_COMMAND_USER_GPIO; /* user gpio */
3057 buf[1] = gpio; /* set gpio number */
3058 buf[2] = input_level; /* set gpio input level */
3059 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 3); /* write data */
3060 if (res != 0) /* check result */
3061 {
3062 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
3063
3064 return 1; /* return error */
3065 }
3066 len = 2; /* len 2 */
3067 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
3068 if (res != 0) /* check result */
3069 {
3070 return 4; /* return error */
3071 }
3072 if (addr_check != addr) /* check addr */
3073 {
3074 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
3075
3076 return 5; /* return error */
3077 }
3078 if (len != 2) /* check length */
3079 {
3080 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
3081
3082 return 6; /* return error */
3083 }
3084 handle->status = buf[0]; /* save status */
3085 *status = (as608_status_t)handle->status; /* set status */
3086 *output_level = (as608_gpio_level_t)(buf[1]); /* get gpio level */
3087
3088 return 0; /* success return 0 */
3089}
3090
3109uint8_t as608_get_index_table(as608_handle_t *handle, uint32_t addr, uint8_t num,
3110 uint8_t table[32], as608_status_t *status)
3111{
3112 uint8_t res;
3113 uint8_t buf[33];
3114 uint16_t len;
3115 uint32_t addr_check;
3116
3117 if (handle == NULL) /* check handle */
3118 {
3119 return 2; /* return error */
3120 }
3121 if (handle->inited != 1) /* check handle initialization */
3122 {
3123 return 3; /* return error */
3124 }
3125 if (num > 3) /* check num */
3126 {
3127 handle->debug_print("as608: num > 3.\n"); /* num > 3 */
3128
3129 return 7; /* return error */
3130 }
3131
3132 buf[0] = AS608_COMMAND_READ_INDEX_TABLE; /* read index table */
3133 buf[1] = num; /* set index table number */
3134 res = a_as608_uart_write(handle, addr, AS608_TYPE_COMMAND, buf, 2); /* write data */
3135 if (res != 0) /* check result */
3136 {
3137 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
3138
3139 return 1; /* return error */
3140 }
3141 len = 33; /* len 33 */
3142 res = a_as608_uart_decode(handle, 300, &addr_check, buf, &len); /* decode */
3143 if (res != 0) /* check result */
3144 {
3145 return 4; /* return error */
3146 }
3147 if (addr_check != addr) /* check addr */
3148 {
3149 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
3150
3151 return 5; /* return error */
3152 }
3153 if (len != 33) /* check length */
3154 {
3155 handle->debug_print("as608: len is invalid.\n"); /* len is invalid */
3156
3157 return 6; /* return error */
3158 }
3159 handle->status = buf[0]; /* save status */
3160 *status = (as608_status_t)handle->status; /* set status */
3161 memcpy(table, &buf[1], 32); /* copy data */
3162
3163 return 0; /* success return 0 */
3164}
3165
3177{
3178 if (handle == NULL) /* check handle */
3179 {
3180 return 2; /* return error */
3181 }
3182 if (handle->inited != 1) /* check handle initialization */
3183 {
3184 return 3; /* return error */
3185 }
3186
3187 switch (status) /* switch status */
3188 {
3189 case AS608_STATUS_OK : /* status case */
3190 {
3191 handle->debug_print("as608: ok.\n"); /* print message */
3192
3193 break; /* break */
3194 }
3195 case AS608_STATUS_FRAME_ERROR : /* status case */
3196 {
3197 handle->debug_print("as608: frame error.\n"); /* print message */
3198
3199 break; /* break */
3200 }
3201 case AS608_STATUS_NO_FINGERPRINT : /* status case */
3202 {
3203 handle->debug_print("as608: no fingerprint.\n"); /* print message */
3204
3205 break; /* break */
3206 }
3207 case AS608_STATUS_INPUT_ERROR : /* status case */
3208 {
3209 handle->debug_print("as608: fingerprint image error.\n"); /* print message */
3210
3211 break; /* break */
3212 }
3213 case AS608_STATUS_IMAGE_TOO_DRY : /* status case */
3214 {
3215 handle->debug_print("as608: fingerprint image too dry.\n"); /* print message */
3216
3217 break; /* break */
3218 }
3219 case AS608_STATUS_IMAGE_TOO_WET : /* status case */
3220 {
3221 handle->debug_print("as608: fingerprint image too wet.\n"); /* print message */
3222
3223 break; /* break */
3224 }
3225 case AS608_STATUS_IMAGE_TOO_CLUTTER : /* status case */
3226 {
3227 handle->debug_print("as608: fingerprint too clutter.\n"); /* print message */
3228
3229 break; /* break */
3230 }
3231 case AS608_STATUS_IMAGE_TOO_FEW_FEATURE : /* status case */
3232 {
3233 handle->debug_print("as608: fingerprint feature too few.\n"); /* print message */
3234
3235 break; /* break */
3236 }
3237 case AS608_STATUS_NOT_MATCH : /* status case */
3238 {
3239 handle->debug_print("as608: not match.\n"); /* print message */
3240
3241 break; /* break */
3242 }
3243 case AS608_STATUS_NOT_FOUND : /* status case */
3244 {
3245 handle->debug_print("as608: not found.\n"); /* print message */
3246
3247 break; /* break */
3248 }
3249 case AS608_STATUS_FEATURE_COMBINE_ERROR : /* status case */
3250 {
3251 handle->debug_print("as608: feature combine error.\n"); /* print message */
3252
3253 break; /* break */
3254 }
3255 case AS608_STATUS_LIB_ADDR_OVER : /* status case */
3256 {
3257 handle->debug_print("as608: fingerprint lib addr is over.\n"); /* print message */
3258
3259 break; /* break */
3260 }
3261 case AS608_STATUS_LIB_READ_ERROR : /* status case */
3262 {
3263 handle->debug_print("as608: fingerprint lib read error.\n"); /* print message */
3264
3265 break; /* break */
3266 }
3267 case AS608_STATUS_UPLOAD_FEATURE_ERROR : /* status case */
3268 {
3269 handle->debug_print("as608: upload feature error.\n"); /* print message */
3270
3271 break; /* break */
3272 }
3273 case AS608_STATUS_NO_FRAME : /* status case */
3274 {
3275 handle->debug_print("as608: no frame.\n"); /* print message */
3276
3277 break; /* break */
3278 }
3279 case AS608_STATUS_UPLOAD_IMAGE_ERROR : /* status case */
3280 {
3281 handle->debug_print("as608: upload image error.\n"); /* print message */
3282
3283 break; /* break */
3284 }
3285 case AS608_STATUS_LIB_DELETE_ERROR : /* status case */
3286 {
3287 handle->debug_print("as608: delete lib error.\n"); /* print message */
3288
3289 break; /* break */
3290 }
3291 case AS608_STATUS_LIB_CLEAR_ERROR : /* status case */
3292 {
3293 handle->debug_print("as608: clear lib error.\n"); /* print message */
3294
3295 break; /* break */
3296 }
3297 case AS608_STATUS_ENTER_LOW_POWER_ERROR : /* status case */
3298 {
3299 handle->debug_print("as608: enter low power error.\n"); /* print message */
3300
3301 break; /* break */
3302 }
3303 case AS608_STATUS_COMMAND_INVALID : /* status case */
3304 {
3305 handle->debug_print("as608: command invalid.\n"); /* print message */
3306
3307 break; /* break */
3308 }
3309 case AS608_STATUS_RESET_ERROR : /* status case */
3310 {
3311 handle->debug_print("as608: reset error.\n"); /* print message */
3312
3313 break; /* break */
3314 }
3315 case AS608_STATUS_BUFFER_INVALID : /* status case */
3316 {
3317 handle->debug_print("as608: buffer invalid.\n"); /* print message */
3318
3319 break; /* break */
3320 }
3321 case AS608_STATUS_UPDATE_ERROR : /* status case */
3322 {
3323 handle->debug_print("as608: update error.\n"); /* print message */
3324
3325 break; /* break */
3326 }
3327 case AS608_STATUS_NO_MOVE : /* status case */
3328 {
3329 handle->debug_print("as608: no move.\n"); /* print message */
3330
3331 break; /* break */
3332 }
3333 case AS608_STATUS_FLASH_ERROR : /* status case */
3334 {
3335 handle->debug_print("as608: flash error.\n"); /* print message */
3336
3337 break; /* break */
3338 }
3339 case AS608_STATUS_F0_RESPONSE : /* status case */
3340 {
3341 handle->debug_print("as608: f0 response.\n"); /* print message */
3342
3343 break; /* break */
3344 }
3345 case AS608_STATUS_F1_RESPONSE : /* status case */
3346 {
3347 handle->debug_print("as608: f1 response.\n"); /* print message */
3348
3349 break; /* break */
3350 }
3351 case AS608_STATUS_FLASH_WRITE_SUM_ERROR : /* status case */
3352 {
3353 handle->debug_print("as608: flash sum error.\n"); /* print message */
3354
3355 break; /* break */
3356 }
3357 case AS608_STATUS_FLASH_WRITE_HEADER_ERROR : /* status case */
3358 {
3359 handle->debug_print("as608: flash header error.\n"); /* print message */
3360
3361 break; /* break */
3362 }
3363 case AS608_STATUS_FLASH_WRITE_LENGTH_ERROR : /* status case */
3364 {
3365 handle->debug_print("as608: flash length error.\n"); /* print message */
3366
3367 break; /* break */
3368 }
3369 case AS608_STATUS_FLASH_WRITE_LENGTH_TOO_LONG : /* status case */
3370 {
3371 handle->debug_print("as608: flash length too long.\n"); /* print message */
3372
3373 break; /* break */
3374 }
3375 case AS608_STATUS_FLASH_WRITE_ERROR : /* status case */
3376 {
3377 handle->debug_print("as608: flash write error.\n"); /* print message */
3378
3379 break; /* break */
3380 }
3381 case AS608_STATUS_UNKNOWN : /* status case */
3382 {
3383 handle->debug_print("as608: unknown.\n"); /* print message */
3384
3385 break; /* break */
3386 }
3387 case AS608_STATUS_REG_INVALID : /* status case */
3388 {
3389 handle->debug_print("as608: reg invalid.\n"); /* print message */
3390
3391 break; /* break */
3392 }
3393 case AS608_STATUS_DATA_INVALID : /* status case */
3394 {
3395 handle->debug_print("as608: data invalid.\n"); /* print message */
3396
3397 break; /* break */
3398 }
3399 case AS608_STATUS_NOTE_PAGE_INVALID : /* status case */
3400 {
3401 handle->debug_print("as608: note page invalid.\n"); /* print message */
3402
3403 break; /* break */
3404 }
3405 case AS608_STATUS_PORT_INVALID : /* status case */
3406 {
3407 handle->debug_print("as608: port invalid.\n"); /* print message */
3408
3409 break; /* break */
3410 }
3411 case AS608_STATUS_ENROOL_ERROR : /* status case */
3412 {
3413 handle->debug_print("as608: enrool error.\n"); /* print message */
3414
3415 break; /* break */
3416 }
3417 case AS608_STATUS_LIB_FULL : /* status case */
3418 {
3419 handle->debug_print("as608: lib full.\n"); /* print message */
3420
3421 break; /* break */
3422 }
3423 default : /* default */
3424 {
3425 handle->debug_print("as608: invalid type.\n"); /* print message */
3426
3427 break; /* break */
3428 }
3429 }
3430
3431 return 0; /* success return 0 */
3432}
3433
3453uint8_t as608_command_write_read(as608_handle_t *handle, uint32_t addr, uint8_t type,
3454 uint8_t *input_buffer, uint16_t input_len,
3455 uint16_t ms, uint8_t *output_buffer, uint16_t *output_len)
3456{
3457 uint8_t res;
3458 uint32_t addr_check;
3459
3460 if (handle == NULL) /* check handle */
3461 {
3462 return 2; /* return error */
3463 }
3464 if (handle->inited != 1) /* check handle initialization */
3465 {
3466 return 3; /* return error */
3467 }
3468
3469 res = a_as608_uart_write(handle, addr, type, input_buffer, input_len); /* write data */
3470 if (res != 0) /* check result */
3471 {
3472 handle->debug_print("as608: uart write failed.\n"); /* uart write failed */
3473
3474 return 1; /* return error */
3475 }
3476 res = a_as608_uart_decode(handle, ms, &addr_check, output_buffer, output_len); /* decode*/
3477 if (res != 0) /* check result */
3478 {
3479 return 4; /* return error */
3480 }
3481 if (addr_check != addr) /* check addr */
3482 {
3483 handle->debug_print("as608: addr is invalid.\n"); /* addr is invalid */
3484
3485 return 5; /* return error */
3486 }
3487
3488 return 0; /* success return 0 */
3489}
3490
3500{
3501 if (info == NULL) /* check handle */
3502 {
3503 return 2; /* return error */
3504 }
3505
3506 memset(info, 0, sizeof(as608_info_t)); /* initialize as608 info structure */
3507 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
3508 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
3509 strncpy(info->interface, "UART", 8); /* copy interface name */
3510 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
3511 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
3512 info->max_current_ma = MAX_CURRENT; /* set maximum current */
3513 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
3514 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
3515 info->driver_version = DRIVER_VERSION; /* set driver version */
3516
3517 return 0; /* success return 0 */
3518}
#define AS608_COMMAND_BURN_CODE
#define AS608_COMMAND_REG_MODEL
#define AS608_COMMAND_DELETE_CHAR
#define AS608_COMMAND_DOWN_IMAGE
#define AS608_COMMAND_READ_SYS_PARA
#define AS608_COMMAND_PORT_CONTROL
#define MAX_CURRENT
#define AS608_COMMAND_GET_RANDOM_CODE
#define AS608_COMMAND_MATCH
#define AS608_TYPE_RESPONSE
#define AS608_TYPE_END
#define AS608_COMMAND_DOWN_CHAR
#define AS608_COMMAND_HIGH_SPEED_SEARCH
#define AS608_TYPE_COMMAND
chip type definition
#define SUPPLY_VOLTAGE_MAX
#define AS608_COMMAND_SEARCH
#define TEMPERATURE_MAX
#define AS608_COMMAND_WRITE_NOTEPAD
#define AS608_COMMAND_IDENTIFY
#define AS608_COMMAND_SET_PWD
#define AS608_COMMAND_GEN_CHAR
#define AS608_COMMAND_USER_GPIO
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define AS608_COMMAND_VFY_PWD
#define AS608_COMMAND_LOAD_CHAR
#define AS608_COMMAND_ENROLL
#define AS608_TYPE_DATA
#define AS608_COMMAND_READ_INDEX_TABLE
#define AS608_COMMAND_VALID_TEMPLATE_NUM
#define AS608_COMMAND_READ_INFO_PAGE
#define AS608_COMMAND_EMPTY
#define AS608_COMMAND_READ_NOTEPAD
#define CHIP_NAME
chip information definition
#define AS608_COMMAND_SET_CHIP_ADDR
#define AS608_COMMAND_UP_CHAR
#define AS608_COMMAND_UP_IMAGE
#define DRIVER_VERSION
#define AS608_COMMAND_GEN_BIN_IMAGE
#define AS608_COMMAND_STORE_CHAR
#define AS608_COMMAND_GET_IMAGE
chip command definition
#define AS608_COMMAND_WRITE_REG
driver as608 header file
uint8_t as608_download_image(as608_handle_t *handle, uint32_t addr, uint8_t *input_buffer, uint16_t input_len, as608_status_t *status)
download image
as608_sensor_type_t
as608 sensor type enumeration definition
uint8_t as608_set_port(as608_handle_t *handle, uint32_t addr, as608_bool_t enable, as608_status_t *status)
enable or disable port
uint8_t as608_set_packet_size(as608_handle_t *handle, uint32_t addr, as608_packet_size_t size, as608_status_t *status)
set packet size
uint8_t as608_get_random(as608_handle_t *handle, uint32_t addr, uint32_t *randn, as608_status_t *status)
get random
struct as608_handle_s as608_handle_t
as608 handle structure definition
uint8_t as608_init(as608_handle_t *handle, uint32_t addr)
initialize the chip
uint8_t as608_load_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint16_t page_number, as608_status_t *status)
load feature
uint8_t as608_generate_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, as608_status_t *status)
generate feature
uint8_t as608_get_index_table(as608_handle_t *handle, uint32_t addr, uint8_t num, uint8_t table[32], as608_status_t *status)
get index table
uint8_t as608_store_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint16_t page_number, as608_status_t *status)
store feature
as608_status_t
as608 status enumeration definition
uint8_t as608_info(as608_info_t *info)
get chip's information
uint8_t as608_set_password(as608_handle_t *handle, uint32_t addr, uint32_t password, as608_status_t *status)
set password
uint8_t as608_upload_image(as608_handle_t *handle, uint32_t addr, uint8_t *output_buffer, uint16_t *output_len, as608_status_t *status)
upload image
uint8_t as608_write_notepad(as608_handle_t *handle, uint32_t addr, uint8_t page_number, uint8_t data[32], as608_status_t *status)
write notepad
as608_bool_t
as608 bool enumeration definition
uint8_t as608_get_valid_template_number(as608_handle_t *handle, uint32_t addr, uint16_t *num, as608_status_t *status)
get valid template number
struct as608_params_s as608_params_t
as608 params structure definition
uint8_t as608_search_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint16_t start_page, uint16_t page_number, uint16_t *found_page, uint16_t *score, as608_status_t *status)
search feature
uint8_t as608_get_image(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
get image
uint8_t as608_download_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint8_t *input_buffer, uint16_t input_len, as608_status_t *status)
download feature
uint8_t as608_get_last_status(as608_handle_t *handle, as608_status_t *status)
get the last status
as608_gpio_level_t
as608 gpio level enumeration definition
uint8_t as608_combine_feature(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
combine feature
uint8_t as608_print_status(as608_handle_t *handle, as608_status_t status)
print status
as608_buffer_number_t
as608 buffer number enumeration definition
as608_gpio_number_t
as608 gpio number enumeration definition
uint8_t as608_match_feature(as608_handle_t *handle, uint32_t addr, uint16_t *score, as608_status_t *status)
match feature
uint8_t as608_get_params(as608_handle_t *handle, uint32_t addr, as608_params_t *param, as608_status_t *status)
get params
uint8_t as608_set_level(as608_handle_t *handle, uint32_t addr, as608_level_t level, as608_status_t *status)
set level
uint8_t as608_delete_feature(as608_handle_t *handle, uint32_t addr, uint16_t page_number, uint16_t number, as608_status_t *status)
delete feature
uint8_t as608_set_baud_rate(as608_handle_t *handle, uint32_t addr, uint8_t n_9600, as608_status_t *status)
set baud rate
uint8_t as608_upload_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint8_t *output_buffer, uint16_t *output_len, as608_status_t *status)
upload feature
uint8_t as608_deinit(as608_handle_t *handle)
close the chip
uint8_t as608_identify(as608_handle_t *handle, uint32_t addr, uint16_t *page_number, uint16_t *score, as608_status_t *status)
identify
struct as608_info_s as608_info_t
as608 information structure definition
as608_burn_code_mode_t
as608 burn code mode enumeration definition
uint8_t as608_set_chip_address(as608_handle_t *handle, uint32_t addr, uint32_t new_addr, as608_status_t *status)
set the chip address
uint8_t as608_burn_code(as608_handle_t *handle, uint32_t addr, as608_burn_code_mode_t mode, uint8_t *input_buffer, uint16_t input_len, as608_status_t *status)
burn code
uint8_t as608_read_notepad(as608_handle_t *handle, uint32_t addr, uint8_t page_number, uint8_t data[32], as608_status_t *status)
read notepad
as608_packet_size_t
as608 packet size enumeration definition
uint8_t as608_empty_all_feature(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
empty all feature
as608_image_t
as608 image enumeration definition
as608_level_t
as608 level enumeration definition
uint8_t as608_set_gpio_level(as608_handle_t *handle, uint32_t addr, as608_gpio_number_t gpio, as608_gpio_level_t input_level, as608_gpio_level_t *output_level, as608_status_t *status)
set gpio level
uint8_t as608_generate_bin_image(as608_handle_t *handle, uint32_t addr, as608_image_t image, as608_status_t *status)
generate bin image
uint8_t as608_verify_password(as608_handle_t *handle, uint32_t addr, uint32_t password, as608_status_t *status)
verify password
uint8_t as608_enroll(as608_handle_t *handle, uint32_t addr, uint16_t *page_number, as608_status_t *status)
enroll
uint8_t as608_high_speed_search(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t buffer_number, uint16_t start_page, uint16_t page_number, uint16_t *found_page, uint16_t *score, as608_status_t *status)
high speed search
uint8_t as608_get_flash_information(as608_handle_t *handle, uint32_t addr, uint8_t *output_buffer, uint16_t *output_len, as608_status_t *status)
get flash information
@ AS608_STATUS_FEATURE_COMBINE_ERROR
@ AS608_STATUS_OK
@ AS608_STATUS_UPDATE_ERROR
@ AS608_STATUS_DATA_INVALID
@ AS608_STATUS_BUFFER_INVALID
@ AS608_STATUS_NOT_FOUND
@ AS608_STATUS_F0_RESPONSE
@ AS608_STATUS_FRAME_ERROR
@ AS608_STATUS_NOT_MATCH
@ AS608_STATUS_F1_RESPONSE
@ AS608_STATUS_LIB_CLEAR_ERROR
@ AS608_STATUS_NO_FRAME
@ AS608_STATUS_INPUT_ERROR
@ AS608_STATUS_FLASH_WRITE_SUM_ERROR
@ AS608_STATUS_PORT_INVALID
@ AS608_STATUS_IMAGE_TOO_CLUTTER
@ AS608_STATUS_IMAGE_TOO_WET
@ AS608_STATUS_IMAGE_TOO_FEW_FEATURE
@ AS608_STATUS_REG_INVALID
@ AS608_STATUS_FLASH_WRITE_ERROR
@ AS608_STATUS_NO_FINGERPRINT
@ AS608_STATUS_UNKNOWN
@ AS608_STATUS_FLASH_ERROR
@ AS608_STATUS_LIB_DELETE_ERROR
@ AS608_STATUS_ENROOL_ERROR
@ AS608_STATUS_FLASH_WRITE_LENGTH_TOO_LONG
@ AS608_STATUS_COMMAND_INVALID
@ AS608_STATUS_LIB_ADDR_OVER
@ AS608_STATUS_NO_MOVE
@ AS608_STATUS_ENTER_LOW_POWER_ERROR
@ AS608_STATUS_RESET_ERROR
@ AS608_STATUS_NOTE_PAGE_INVALID
@ AS608_STATUS_UPLOAD_FEATURE_ERROR
@ AS608_STATUS_FLASH_WRITE_HEADER_ERROR
@ AS608_STATUS_FLASH_WRITE_LENGTH_ERROR
@ AS608_STATUS_UPLOAD_IMAGE_ERROR
@ AS608_STATUS_LIB_READ_ERROR
@ AS608_STATUS_IMAGE_TOO_DRY
@ AS608_STATUS_LIB_FULL
@ AS608_BOOL_FALSE
@ AS608_BOOL_TRUE
uint8_t as608_command_write_read(as608_handle_t *handle, uint32_t addr, uint8_t type, uint8_t *input_buffer, uint16_t input_len, uint16_t ms, uint8_t *output_buffer, uint16_t *output_len)
write read data to chip
uint8_t(* uart_flush)(void)
uint8_t(* uart_write)(uint8_t *buf, uint16_t len)
void(* delay_ms)(uint32_t ms)
uint8_t(* uart_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint16_t packet_size
uint8_t(* uart_init)(void)
uint8_t buf[384]
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]
as608_level_t level
as608_sensor_type_t sensor_type
uint16_t fingerprint_size
as608_packet_size_t packet_size