程序设计
头文件
/vendor/lockzhiner/lingpi/samples/b0_nfc/include/nfc.h
API分析
nfc_init()
unsigned int nfc_init(void);
描述:
NFC模块初始化。
参数:
无
返回值:
0为成功,反之则失败。
nfc_deinit()
unsigned int nfc_deinit(void);
描述:
NFC模块注销。
参数:
无
返回值:
0为成功,反之则失败。
nfc_store_uri_http()
bool nfc_store_uri_http(RecordPosEnu position, uint8_t *http);
描述:
向NFC写入URI信息。
参数:
返回值:
true为成功,false则失败。
nfc_store_text()
bool nfc_store_text(RecordPosEnu position, uint8_t *text);
描述:
向NFC写入txt信息。
参数:
返回值:
true为成功,false则失败。
主要代码分析
初始化代码分析
这部分代码为i2c初始化的代码。首先用 I2cIoInit() 函数将GPIO0_PC1复用为I2C1_SDA_M1,GPIO0_PC2复用为I2C1_SCL_M1。最后调用 LzI2cInit()函数初始化I2C1端口。
if (I2cIoInit(m_i2c2m0) != LZ_HARDWARE_SUCCESS)
{
printf("%s, %s, %d: I2cIoInit failed!\n", __FILE__, __func__, __LINE__);
return __LINE__;
}
if (LzI2cInit(NFC_I2C_PORT, m_i2c2_freq) != LZ_HARDWARE_SUCCESS)
{
printf("%s, %s, %d: LzI2cInit failed!\n", __FILE__, __func__, __LINE__);
return __LINE__;
}
编译调试
修改 BUILD.gn 文件
修改 vendor/lockzhiner/lingpi/sample 路径下 BUILD.gn 文件,指定 nfc 参与编译。
"b2_nfc",
在主目录下输入编译命令。
hb build -f
运行结果
示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,并请使用带有LCD屏幕显示如下:
==============NFC Example==============
Please use the mobile phone with NFC function close to the development board!
原作者:王小彬 Gitee
|