README_zh.md
1# 小凌派-RK2206开发板基础外设开发——NFC
2
3本示例将演示如何在小凌派-RK2206开发板控制NFC
4
5
6
7## 程序设计
8
9### 头文件
10
11```
12/vendor/lockzhiner/lingpi/samples/b0_nfc/include/nfc.h
13```
14
15### API分析
16
17#### nfc_init()
18
19```c
20unsigned int nfc_init(void);
21```
22
23**描述:**
24
25NFC模块初始化。
26
27**参数:**
28
29无
30
31**返回值:**
32
330为成功,反之则失败。
34
35#### nfc_deinit()
36
37```c
38unsigned int nfc_deinit(void);
39```
40
41**描述:**
42
43NFC模块注销。
44
45**参数:**
46
47无
48
49**返回值:**
50
510为成功,反之则失败。
52
53#### nfc_store_uri_http()
54
55```c
56bool nfc_store_uri_http(RecordPosEnu position, uint8_t *http);
57```
58
59**描述:**
60
61向NFC写入URI信息。
62
63**参数:**
64
65| 名字 | 描述 |
66| :------- | :----------------------- |
67| position | 信息标识 |
68| http | 需要写入的网络地址字符串 |
69
70**返回值:**
71
72true为成功,false则失败。
73
74#### nfc_store_text()
75
76```c
77bool nfc_store_text(RecordPosEnu position, uint8_t *text);
78```
79
80**描述:**
81
82向NFC写入txt信息。
83
84**参数:**
85
86| 名字 | 描述 |
87| :------- | :------------------- |
88| position | 信息标识 |
89| text | 需要写入的内容字符串 |
90
91**返回值:**
92
93true为成功,false则失败。
94
95### 主要代码分析
96
97**初始化代码分析**
98
99这部分代码为i2c初始化的代码。首先用 `I2cIoInit()` 函数将GPIO0_PC1复用为I2C1_SDA_M1,GPIO0_PC2复用为I2C1_SCL_M1。最后调用 `LzI2cInit()`函数初始化I2C1端口。
100
101```c
102if (I2cIoInit(m_i2c2m0) != LZ_HARDWARE_SUCCESS)
103{
104 printf("%s, %s, %d: I2cIoInit failed!\n", __FILE__, __func__, __LINE__);
105 return __LINE__;
106}
107if (LzI2cInit(NFC_I2C_PORT, m_i2c2_freq) != LZ_HARDWARE_SUCCESS)
108{
109 printf("%s, %s, %d: LzI2cInit failed!\n", __FILE__, __func__, __LINE__);
110 return __LINE__;
111}
112```
113
114## 编译调试
115
116### 修改 BUILD.gn 文件
117
118修改 `vendor/lockzhiner/lingpi/sample` 路径下 BUILD.gn 文件,指定 `nfc` 参与编译。
119
120```r
121"b2_nfc",
122```
123
124在主目录下输入编译命令。
125
126```shell
127hb build -f
128```
129
130### 运行结果
131
132示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,并请使用带有LCD屏幕显示如下:
133
134```c
135==============NFC Example==============
136Please use the mobile phone with NFC function close to the development board!
137```
138
139