Skip to content

Commit 809da46

Browse files
authored
Merge pull request #1 from ABOSTM/ST25DV
ST25DV sensor driver implementation
2 parents 198ff22 + e56dd0f commit 809da46

38 files changed

Lines changed: 10965 additions & 1 deletion

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
11
# ST25DV
2-
Arduino library to support ST25DV components
2+
Arduino library to support the NFC ST25DV components:
3+
* ST25DV04K
4+
* ST25DV64K
5+
6+
## API
7+
8+
This NFC sensor uses I2C to communicate.
9+
It creates the instance st25dv.
10+
11+
It is then required to call begin API with the 2 pins to be used before accessing to the sensors, and optionally wire instance:
12+
```cpp
13+
st25dv->begin(gpo_pin, lpd_pin);
14+
```
15+
or
16+
```cpp
17+
TwoWire MyWire(SDA_PIN, SCL_PIN);
18+
st25dv->begin(gpo_pin, lpd_pin, MyWire);
19+
```
20+
21+
22+
It is then possible to read/write NFC URI:
23+
24+
```cpp
25+
int writeURI(String protocol, String uri, String info);
26+
String readURI();
27+
```
28+
29+
30+
## Documentation
31+
32+
You can find the source files at
33+
https://github.com/stm32duino/ST25DV
34+
35+
The ST25DV datasheets are available at:
36+
* https://www.st.com/content/st_com/en/products/nfc/st25-nfc-rfid-tags-readers/st25-dynamic-nfc-tags/st25dv-i2c-series-dynamic-nfc-tags/st25dv04k.html
37+
* https://www.st.com/content/st_com/en/products/nfc/st25-nfc-rfid-tags-readers/st25-dynamic-nfc-tags/st25dv-i2c-series-dynamic-nfc-tags/st25dv64k.html

keywords.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#######################################
2+
# Syntax Coloring Map For ST25DV
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
ST25DV KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
begin KEYWORD2
16+
writeURI KEYWORD2
17+
readURI KEYWORD2
18+
19+
#######################################
20+
# Constants (LITERAL1)
21+
#######################################

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=STM32duino ST25DV
2+
version=1.0.0
3+
author=STMicroelectronics
4+
maintainer=stm32duino
5+
sentence=Allows controlling the NFC ST25DV
6+
paragraph=This library provides the drivers and a sample application to control NFC ST25DV
7+
category=Communication
8+
url=https://github.com/stm32duino/ST25DV
9+
architectures=stm32,avr,samd,arc32

src/BSP/st25dv_nfctag.cpp

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
/**
2+
******************************************************************************
3+
* @file st25dv_nfctag.c
4+
* @author MMY Application Team
5+
* @version $Revision: 3306 $
6+
* @date $Date: 2017-01-13 11:18:15 +0100 (Fri, 13 Jan 2017) $
7+
* @brief This file provides a set of functions needed to manage a nfc dual
8+
* interface eeprom memory.
9+
******************************************************************************
10+
* @attention
11+
*
12+
* <h2><center>&copy; COPYRIGHT 2017 STMicroelectronics</center></h2>
13+
*
14+
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
15+
* You may not use this file except in compliance with the License.
16+
* You may obtain a copy of the License at:
17+
*
18+
* http://www.st.com/myliberty
19+
*
20+
* Unless required by applicable law or agreed to in writing, software
21+
* distributed under the License is distributed on an "AS IS" BASIS,
22+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
23+
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
25+
* See the License for the specific language governing permissions and
26+
* limitations under the License.
27+
*
28+
******************************************************************************
29+
*/
30+
31+
/* Includes ------------------------------------------------------------------*/
32+
#include "st25dv_nfctag.h"
33+
#include "Arduino.h"
34+
/** @addtogroup BSP
35+
* @{
36+
*/
37+
38+
/** @defgroup ST25DV_NFCTAG
39+
* @{
40+
*/
41+
/* Private typedef -----------------------------------------------------------*/
42+
/* Private defines -----------------------------------------------------------*/
43+
/** @defgroup ST25DV_NFCTAG_Private_Defines
44+
* @{
45+
*/
46+
#ifndef NULL
47+
#define NULL (void *) 0
48+
#endif
49+
/**
50+
* @}
51+
*/
52+
53+
/* Private macros ------------------------------------------------------------*/
54+
/* Private variables ---------------------------------------------------------*/
55+
/* Global variables ----------------------------------------------------------*/
56+
/** @defgroup ST25DV_NFCTAG_Private_Variables
57+
* @{
58+
*/
59+
static NFCTAG_DrvTypeDef *Nfctag_Drv = NULL;
60+
static uint8_t NfctagInitialized = 0;
61+
/**
62+
* @}
63+
*/
64+
/* Private function prototypes -----------------------------------------------*/
65+
/* Functions Definition ------------------------------------------------------*/
66+
/** @defgroup ST25DV_NFCTAG_Public_Functions
67+
* @{
68+
*/
69+
/**
70+
* @brief Initializes peripherals used by the I2C NFCTAG driver
71+
* @param None
72+
* @retval NFCTAG enum status
73+
*/
74+
NFCTAG_StatusTypeDef BSP_NFCTAG_Init(void)
75+
{
76+
uint8_t nfctag_id = 0;
77+
78+
if (!NfctagInitialized) {
79+
if (St25Dv_i2c_Drv.Init == NULL) {
80+
return NFCTAG_ERROR;
81+
}
82+
/* ST25DV Init */
83+
if (St25Dv_i2c_Drv.Init() != NFCTAG_OK) {
84+
return NFCTAG_ERROR;
85+
}
86+
87+
/* Check ST25DV driver ID */
88+
St25Dv_i2c_Drv.ReadID(&nfctag_id);
89+
90+
if ((nfctag_id == I_AM_ST25DV04) || (nfctag_id == I_AM_ST25DV64)) {
91+
NfctagInitialized = 1;
92+
Nfctag_Drv = &St25Dv_i2c_Drv;
93+
Nfctag_Drv->pData = &St25Dv_i2c_ExtDrv;
94+
} else {
95+
Nfctag_Drv = NULL;
96+
NfctagInitialized = 0;
97+
return NFCTAG_ERROR;
98+
}
99+
}
100+
101+
return NFCTAG_OK;
102+
}
103+
104+
/**
105+
* @brief Deinitializes peripherals used by the I2C NFCTAG driver
106+
* @param None
107+
* @retval None
108+
*/
109+
void BSP_NFCTAG_DeInit(void)
110+
{
111+
Nfctag_Drv->pData = NULL;
112+
Nfctag_Drv = NULL;
113+
NfctagInitialized = 0;
114+
}
115+
116+
/**
117+
* @brief Check if the nfctag is initialized
118+
* @param None
119+
* @retval 0 if the nfctag is not initialized, 1 if the nfctag is already initialized
120+
*/
121+
uint8_t BSP_NFCTAG_isInitialized(void)
122+
{
123+
return NfctagInitialized;
124+
}
125+
126+
/**
127+
* @brief Read the ID of the nfctag
128+
* @param wai_id : the pointer where the who_am_i of the device is stored
129+
* @retval NFCTAG enum status
130+
*/
131+
NFCTAG_StatusTypeDef BSP_NFCTAG_ReadID(uint8_t *const wai_id)
132+
{
133+
if (Nfctag_Drv->ReadID == NULL) {
134+
return NFCTAG_ERROR;
135+
}
136+
137+
return Nfctag_Drv->ReadID(wai_id);
138+
}
139+
140+
/**
141+
* @brief Return the size of the nfctag
142+
* @retval Size of the NFCtag in Bytes
143+
*/
144+
uint32_t BSP_NFCTAG_GetByteSize(void)
145+
{
146+
ST25DV_MEM_SIZE mem_size;
147+
((NFCTAG_ExtDrvTypeDef *)Nfctag_Drv->pData)->ReadMemSize(&mem_size);
148+
return (mem_size.BlockSize + 1) * (mem_size.Mem_Size + 1);
149+
}
150+
151+
/**
152+
* @brief Check if the nfctag is available
153+
* @param Trials : Number of trials
154+
* @retval NFCTAG enum status
155+
*/
156+
NFCTAG_StatusTypeDef BSP_NFCTAG_IsDeviceReady(const uint32_t Trials)
157+
{
158+
if (Nfctag_Drv->IsReady == NULL) {
159+
return NFCTAG_ERROR;
160+
}
161+
162+
return Nfctag_Drv->IsReady(Trials);
163+
}
164+
165+
/**
166+
* @brief Configure nfctag interrupt
167+
* @param ITConfig : store interrupt to configure
168+
* - 0x01 => RF BUSY
169+
* - 0x02 => WIP
170+
* @retval NFCTAG enum status
171+
*/
172+
NFCTAG_StatusTypeDef BSP_NFCTAG_ConfigIT(const uint16_t ITConfig)
173+
{
174+
if (Nfctag_Drv->ConfigIT == NULL) {
175+
return NFCTAG_ERROR;
176+
}
177+
return Nfctag_Drv->ConfigIT(ITConfig);
178+
}
179+
180+
/**
181+
* @brief Get nfctag interrupt configutration
182+
* @param ITConfig : store interrupt configuration
183+
* - 0x01 => RF BUSY
184+
* - 0x02 => WIP
185+
* @retval NFCTAG enum status
186+
*/
187+
NFCTAG_StatusTypeDef BSP_NFCTAG_GetITStatus(uint16_t *const ITConfig)
188+
{
189+
if (Nfctag_Drv->GetITStatus == NULL) {
190+
return NFCTAG_ERROR;
191+
}
192+
193+
return Nfctag_Drv->GetITStatus(ITConfig);
194+
}
195+
196+
/**
197+
* @brief Reads data in the nfctag at specific address
198+
* @param pData : pointer to store read data
199+
* @param TarAddr : I2C data memory address to read
200+
* @param Size : Size in bytes of the value to be read
201+
* @retval NFCTAG enum status
202+
*/
203+
NFCTAG_StatusTypeDef BSP_NFCTAG_ReadData(uint8_t *const pData, const uint16_t TarAddr, const uint16_t Size)
204+
{
205+
if (Nfctag_Drv->ReadData == NULL) {
206+
return NFCTAG_ERROR;
207+
}
208+
209+
return Nfctag_Drv->ReadData(pData, TarAddr, Size);
210+
}
211+
212+
/**
213+
* @brief Writes data in the nfctag at specific address
214+
* @param pData : pointer to the data to write
215+
* @param TarAddr : I2C data memory address to write
216+
* @param Size : Size in bytes of the value to be written
217+
* @retval NFCTAG enum status
218+
*/
219+
NFCTAG_StatusTypeDef BSP_NFCTAG_WriteData(const uint8_t *const pData, const uint16_t TarAddr, const uint16_t Size)
220+
{
221+
if (Nfctag_Drv->WriteData == NULL) {
222+
return NFCTAG_ERROR;
223+
}
224+
225+
return Nfctag_Drv->WriteData(pData, TarAddr, Size);
226+
}
227+
228+
/**
229+
* @brief Reads nfctag Register
230+
* @param pData : pointer to store read data
231+
* @param TarAddr : I2C register address to read
232+
* @param Size : Size in bytes of the value to be read
233+
* @retval NFCTAG enum status
234+
*/
235+
NFCTAG_StatusTypeDef BSP_NFCTAG_ReadRegister(uint8_t *const pData, const uint16_t TarAddr, const uint16_t Size)
236+
{
237+
if (Nfctag_Drv->ReadRegister == NULL) {
238+
return NFCTAG_ERROR;
239+
}
240+
241+
return Nfctag_Drv->ReadRegister(pData, TarAddr, Size);
242+
}
243+
244+
/**
245+
* @brief Writes nfctag Register
246+
* @param pData : pointer to the data to write
247+
* @param TarAddr : I2C register address to write
248+
* @param Size : Size in bytes of the value to be written
249+
* @retval NFCTAG enum status
250+
*/
251+
NFCTAG_StatusTypeDef BSP_NFCTAG_WriteRegister(const uint8_t *const pData, const uint16_t TarAddr, const uint16_t Size)
252+
{
253+
NFCTAG_StatusTypeDef ret_value;
254+
if (Nfctag_Drv->WriteRegister == NULL) {
255+
return NFCTAG_ERROR;
256+
}
257+
258+
ret_value = Nfctag_Drv->WriteRegister(pData, TarAddr, Size);
259+
if (ret_value == NFCTAG_OK) {
260+
while (BSP_NFCTAG_IsDeviceReady(1) != NFCTAG_OK) {};
261+
return NFCTAG_OK;
262+
}
263+
264+
return ret_value;
265+
}
266+
267+
/**
268+
* @brief Give extended features for component
269+
* @param None
270+
* @retval address of the Extended Component Structure
271+
*/
272+
NFCTAG_ExtDrvTypeDef *BSP_NFCTAG_GetExtended_Drv(void)
273+
{
274+
return (NFCTAG_ExtDrvTypeDef *)Nfctag_Drv->pData;
275+
}
276+
277+
/**
278+
* @}
279+
*/
280+
281+
/**
282+
* @}
283+
*/
284+
285+
/**
286+
* @}
287+
*/
288+
289+
/******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)