当前位置:首页|资讯

【外设移植】安信可Ai-WB2+FPM383C指纹

作者:安信可科技发布时间:2024-10-29

以下作品由安信可社区用户

WT_0213制作


关于 FPM383C 指纹模块 在之前的帖子介绍的已经比较详细了可以看下这个帖子。

【外设移植】FPM383C 指纹模块 +Ai-M61-32S

bbs.ai-thinker.com/foru

这里主要说一下移植 FPM383C 指纹到 Ai-WB2 模块时遇到的一些问题和移植完成示例。

首先是环境搭建

【Ai-WB2 入门篇】搭建 windows+eclipse 环境
bbs.ai-thinker.com/foru

跟着园长的教程完成环境搭建基本不会出现什么意外情况,都可以正常跑起来。

这里有个小坑需要注意:

尽量使用克隆命令克隆项目,不要直接下载 zip
git clone --recursive
gitee.com/Ai-Thinker-Op

如果对配置文件不熟悉的话尽量按照现有的一些目录接口创建自己的项目这样可以尽可能少的去修改配置文件。

如果在其他目录下创建项目,需要注意的是 BL60X_SDK_PATH 这个值要能找到 sdkpath。



编译过程有一些警告,如果不是自己代码中的可以忽略。

如果编译通过的话最终会生成 bin 文件。



Ai-WB2 烧录软件
docs.ai-thinker.com/_me
烧录过程参考
【Ai-WB2 入门篇】新建工程和烧录指导
bbs.ai-thinker.com/foru

这里有小坑需要注意一下:



1、如果出现 COM 口拒绝访问,检查下时候开启的串口调试工具。

2、如果提示 BFLB IMG LOAD SHAKEHAND FAIL 应该是没有进入烧录模式,点击 Create & Download 然后按住开发板右侧的按钮,再点按左侧 EN 按钮松手就可以了。

这里有大坑需要注意一下:



烧录编译的 bin 的时候需要使用这种烧录方式进项烧录,否则烧录后程序不能正常运行。

序号 1、3、4 选择的都是烧录工具目录下的文件
序号 2 选择编译的 bin 即可
烧录完成后,开启串口调试工具
波特率设置为 115200



这里日志通过 printf 方法打印出来的,不知道为啥 blog_info 不生效没有深入去看

然后是代码部分

#include <stdio.h>
#include <FreeRTOS.h>
#include <task.h>
#include <bl_gpio.h>
#include "fpm383c.h"
#include <blog.h>
int is_register = 1;
int main(void) {
printf("\r\n");
// 初始化FPM383C指纹模块
fpm383c_init();
printf("clear \r\n");
// 清空指纹库
fpm383c_empty(2000);
printf("random id\r\n");
// 指纹id
int fpm383cPageId = 10;
while (1) {
if (is_register) {
// 开启注册指纹,指纹ID:0—59, 超时时间尽量在 10秒左右,需要录入四次
fpm383c_enroll(fpm383cPageId, 10000);
// 休息600毫秒进行下次注册
vTaskDelay(pdMS_TO_TICKS(600));
// 模块休眠一下
fpm383c_sleep();
is_register = 0;
printf("register OK\r\n");
} else {
// printf("identify\r\n");
// 开启自动识别
fpm383c_identify();
}
vTaskDelay(pdMS_TO_TICKS(10));
}
return 0;
}

这里值得注意的是 int main(void)函数是有返回值的,返回值类型为 int

这个函数会在会执行在 FreeRTOS 任务中可以看下这篇分析的帖子

wb2 项目启动流程分析
bbs.ai-thinker.com/foru

fpm383c.h

#ifndef __FPM383C_H
#define __FPM383C_H
#include "stdint.h"
void fpm383c_init(void);
void fpm383c_senddata(int length, uint8_t buffer[]);
void fpm383c_sleep(void);
uint8_t fpm383c_getimage(uint32_t timeout);
uint8_t fpm383c_genchar(uint32_t timeout);
uint8_t fpm383c_search(uint32_t timeout);
uint8_t fpm383c_empty(uint32_t timeout);
uint8_t fpm383c_delete(uint16_t pageID,uint32_t timeout);
uint8_t fpm383c_controlled(uint8_t PS_ControlLEDBuf[],uint32_t timeout);
void fpm383c_identify(void);
void fpm383c_enroll(uint16_t pageID,uint16_t timeout);
#endif

fpm383c.c

#include "stdlib.h"
#include "string.h"
#include "bl_sys.h"
#include <stdio.h>
#include <cli.h>
#include <hosal_uart.h>
#include <blog.h>
#include <hosal_uart.h>
#include <stdint.h>
#include <FreeRTOS.h>
#include <bl_gpio.h>
#include <blog.h>
#include "fpm383c.h"
#define GPIO_LED_PIN 14

uint8_t ps_blueledbuf[16] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x07,0x3C,0x03,0x01,0x01,0x00,0x00,0x49};
uint8_t ps_redledbuf[16] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x07,0x3C,0x02,0x04,0x04,0x02,0x00,0x50};
uint8_t ps_greenledbuf[16] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x07,0x3C,0x02,0x02,0x02,0x02,0x00,0x4C};

uint8_t ps_sleepbuf[12] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x33,0x00,0x37};

uint8_t ps_emptybuf[12] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x0D,0x00,0x11};

uint8_t ps_cancelbuf[12] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x30,0x00,0x34};

uint8_t ps_autoenrollbuf[17] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x08,0x31,'\0','\0',0x04,0x00,0x16,'\0','\0'};

uint8_t ps_getimagebuf[12] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x01,0x00,0x05};

uint8_t ps_getcharbuf[13] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x04,0x02,0x01,0x00,0x08};

uint8_t ps_searchbuf[17] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x08,0x04,0x01,0x00,0x00,0xFF,0xFF,0x02,0x0C};

uint8_t ps_deletebuf[16] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x07,0x0C,'\0','\0',0x00,0x01,'\0','\0'};

hosal_uart_dev_t fpm383c_uart = {
.config = {
.uart_id = 1,
.tx_pin = 4, // TXD GPIO
.rx_pin = 3, // RXD GPIO
.baud_rate = 57600,
.data_width = HOSAL_DATA_WIDTH_8BIT,
.parity = HOSAL_NO_PARITY,
.stop_bits = HOSAL_STOP_BITS_1,
.mode = HOSAL_UART_MODE_POLL,
},
};

uint16_t pageID,score;

uint8_t uart_receivebuf[20];

uint8_t scanstatus = 0;

void fpm383c_receivedata(uint16_t timeout, uint8_t lenght)
{
// 轮询fpm383c_uart接收到的字符
int ret;
uint8_t uart_receive_len = 0;
uint8_t receivebuf_cache[20];
memset(uart_receivebuf, 0xFF, sizeof(uart_receivebuf));
while(true){
ret = hosal_uart_receive(&fpm383c_uart, receivebuf_cache, sizeof(receivebuf_cache));
if (ret > 0) {
memcpy(uart_receivebuf + uart_receive_len, receivebuf_cache, ret);
uart_receive_len += ret;

if(uart_receive_len >= lenght){
uart_receive_len=0;
break;
}
}
vTaskDelay(1);
}
}

void fpm383c_init(){

hosal_uart_init(&fpm383c_uart);
printf("fpm383c_init\r\n");
}

void fpm383c_senddata(int length, uint8_t fpm383c_databuf[])
{
hosal_uart_send(&fpm383c_uart, fpm383c_databuf, length);
}

void fpm383c_sleep(void)
{
fpm383c_senddata(12, ps_sleepbuf);
}

uint8_t fpm383c_getimage(uint32_t timeout)
{
uint8_t tmp;
fpm383c_senddata(12,ps_getimagebuf);
fpm383c_receivedata(timeout, 12);
tmp = (uart_receivebuf[6] == 0x07 ? uart_receivebuf[9] : 0xFF);
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
return tmp;
}

uint8_t fpm383c_genchar(uint32_t timeout)
{
uint8_t tmp;
fpm383c_senddata(13,ps_getcharbuf);
fpm383c_receivedata(timeout, 12);
tmp = (uart_receivebuf[6] == 0x07 ? uart_receivebuf[9] : 0xFF);
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
return tmp;
}

uint8_t fpm383c_search(uint32_t timeout)
{
fpm383c_senddata(17,ps_searchbuf);
fpm383c_receivedata(timeout, 16);
return (uart_receivebuf[6] == 0x07 ? uart_receivebuf[9] : 0xFF);
}

uint8_t fpm383c_delete(uint16_t pageID,uint32_t timeout)
{
uint8_t tmp;
ps_deletebuf[10] = (pageID>>8);
ps_deletebuf[11] = (pageID);
ps_deletebuf[14] = (0x15+ps_deletebuf[10]+ps_deletebuf[11])>>8;
ps_deletebuf[15] = (0x15+ps_deletebuf[10]+ps_deletebuf[11]);
fpm383c_senddata(16,ps_deletebuf);
fpm383c_receivedata(timeout, 12);
tmp = (uart_receivebuf[6] == 0x07 ? uart_receivebuf[9] : 0xFF);
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
return tmp;
}

uint8_t fpm383c_empty(uint32_t timeout)
{
uint8_t tmp;
fpm383c_senddata(12,ps_emptybuf);
fpm383c_receivedata(timeout, 12);
tmp = (uart_receivebuf[6] == 0x07 ? uart_receivebuf[9] : 0xFF);
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
return tmp;
}

uint8_t fpm383c_controlled(uint8_t ps_controlledbuf[],uint32_t timeout)
{
uint8_t tmp;
fpm383c_senddata(16,ps_controlledbuf);
fpm383c_receivedata(timeout, 12);
tmp = (uart_receivebuf[6] == 0x07 ? uart_receivebuf[9] : 0xFF);
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
return tmp;
}

void fpm383c_identify(void)
{
if(fpm383c_getimage(2000) == 0x00)
{
if(fpm383c_genchar(2000) == 0x00)
{
bl_gpio_enable_output(GPIO_LED_PIN, 0, 0);
bl_gpio_output_set(GPIO_LED_PIN, 0);
if(fpm383c_search(2000) == 0x00)
{
score = (int)((uart_receivebuf[10] << 8) + uart_receivebuf[11]);
printf("success ID: %d \r\n",(int)score);
fpm383c_controlled(ps_greenledbuf,1000);
bl_gpio_output_set(GPIO_LED_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(1000));
bl_gpio_output_set(GPIO_LED_PIN, 0);
// 重置接收数据缓存
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
return;
}else{
printf("fail \r\n");
bl_gpio_output_set(GPIO_LED_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(1000));
bl_gpio_output_set(GPIO_LED_PIN, 0);
// 重置接收数据缓存
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
return;
}
}
}
}

void fpm383c_enroll(uint16_t pageID,uint16_t timeout)
{
blog_info("注册指纹ID: %d\r\n", pageID);
ps_autoenrollbuf[10] = (pageID>>8);
ps_autoenrollbuf[11] = (pageID);
ps_autoenrollbuf[15] = (0x54+ps_autoenrollbuf[10]+ps_autoenrollbuf[11])>>8;
ps_autoenrollbuf[16] = (0x54+ps_autoenrollbuf[10]+ps_autoenrollbuf[11]);
fpm383c_senddata(17,ps_autoenrollbuf);
fpm383c_receivedata(timeout, 14);
if(uart_receivebuf[9] == 0x00)
{
blog_info("指纹注册完成\r\n");
// 亮绿灯2秒
fpm383c_controlled(ps_greenledbuf,2000);
// 重置接收数据缓存
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
return;
}
else if(timeout == 0)
{
// 超时取消注册
fpm383c_senddata(12,ps_cancelbuf);
vTaskDelay(pdMS_TO_TICKS(50));
// 重置接收数据缓存
memset(uart_receivebuf,0xFF,sizeof(uart_receivebuf));
}
// 亮红灯2秒
fpm383c_controlled(ps_redledbuf,2000);
}

以上就是主要逻辑代码



接线方式





由于复用的 IO3 所以蓝灯会亮

其他 Ai-WB2 相关知识可以看看社区整理的这篇文章

【Ai-WB2 教程合集】看这一篇就够了!!

bbs.ai-thinker.com/foru



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1