• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdbool.h>
17 #include "lz_hardware.h"
18 #include "stdint.h"
19 #include "rtdText.h"
20 #include "rtdUri.h"
21 #include "ndef.h"
22 
23 /* 记录是否已经初始化 */
24 #define NFC_NOT_INIT        0
25 #define NFC_IS_INIT         1
26 static unsigned char m_nfc_is_init = NFC_NOT_INIT;
27 
28 /***************************************************************
29  * 函数名称: nfc_store_uri_http
30  * 说    明: 向NFC写入URI信息
31  * 参    数:
32  *      @position:信息标识
33  *      @http:需要写入的网络地址
34  * 返 回 值: 返回ture为成功,false为失败
35  ***************************************************************/
nfc_store_uri_http(RecordPosEnu position,uint8_t * http)36 bool nfc_store_uri_http(RecordPosEnu position, uint8_t *http)
37 {
38     NDEFDataStr data;
39 
40     if (m_nfc_is_init == NFC_NOT_INIT) {
41         printf("%s, %s, %d: NFC is not init!\n", __FILE__, __func__, __LINE__);
42         return 0;
43     }
44 
45     prepareUrihttp(&data, position, http);
46     return NT3HwriteRecord(&data);
47 }
48 
49 
50 /***************************************************************
51  * 函数名称: nfc_store_text
52  * 说    明: 向NFC写入txt信息
53  * 参    数:
54  *      @position:信息标识
55  *      @http:需要写入的文本信息
56  * 返 回 值: 返回ture为成功,false为失败
57  ***************************************************************/
nfc_store_text(RecordPosEnu position,uint8_t * text)58 bool nfc_store_text(RecordPosEnu position, uint8_t *text)
59 {
60     NDEFDataStr data;
61 
62     if (m_nfc_is_init == NFC_NOT_INIT) {
63         printf("%s, %s, %d: NFC is not init!\n", __FILE__, __func__, __LINE__);
64         return 0;
65     }
66 
67     prepareText(&data, position, text);
68     return NT3HwriteRecord(&data);
69 }
70 
71 /***************************************************************
72  * 函数名称: nfc_init
73  * 说    明: NFC初始化
74  * 参    数: 无
75  * 返 回 值: 返回0为成功,反之为失败
76  ***************************************************************/
nfc_init(void)77 unsigned int nfc_init(void)
78 {
79     unsigned int ret = 0;
80 
81     if (m_nfc_is_init == NFC_IS_INIT) {
82         printf("%s, %s, %d: Nfc readly init!\n", __FILE__, __func__, __LINE__);
83         return __LINE__;
84     }
85 
86     ret = NT3HI2cInit();
87     if (ret != 0) {
88         printf("%s, %s, %d: NT3HI2cInit failed!\n", __FILE__, __func__, __LINE__);
89         return __LINE__;
90     }
91 
92     m_nfc_is_init = 1;
93     return 0;
94 }
95 
96 
97 /***************************************************************
98  * 函数名称: nfc_deinit
99  * 说    明: NFC销毁
100  * 参    数: 无
101  * 返 回 值: 返回0为成功,反之为失败
102  ***************************************************************/
nfc_deinit(void)103 unsigned int nfc_deinit(void)
104 {
105     m_nfc_is_init = NFC_NOT_INIT;
106     NT3HI2cDeInit();
107     return 0;
108 }
109