mbed OS 5 example application using X-NUCLEO-NFC02A1

Dependencies:   NDefLib X_NUCLEO_NFC02A1

Fork of HelloWorld_NFC02A1 by ST

Committer:
rosarium
Date:
Wed Jul 27 09:25:33 2016 +0000
Revision:
0:892175366555
Child:
1:11ae12d41082
first release of the complete mbed library for HelloWorld_NFC02A1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rosarium 0:892175366555 1 /**
rosarium 0:892175366555 2 ******************************************************************************
rosarium 0:892175366555 3 * @file main.cpp
rosarium 0:892175366555 4 * @author ST Central Labs
rosarium 0:892175366555 5 * @version V1.0.0
rosarium 0:892175366555 6 * @date 21 Dic 2015
rosarium 0:892175366555 7 * @brief This demo writes an ndef message with an url inside.
rosarium 0:892175366555 8 ******************************************************************************
rosarium 0:892175366555 9 * @attention
rosarium 0:892175366555 10 *
rosarium 0:892175366555 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
rosarium 0:892175366555 12 *
rosarium 0:892175366555 13 * Redistribution and use in source and binary forms, with or without modification,
rosarium 0:892175366555 14 * are permitted provided that the following conditions are met:
rosarium 0:892175366555 15 * 1. Redistributions of source code must retain the above copyright notice,
rosarium 0:892175366555 16 * this list of conditions and the following disclaimer.
rosarium 0:892175366555 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
rosarium 0:892175366555 18 * this list of conditions and the following disclaimer in the documentation
rosarium 0:892175366555 19 * and/or other materials provided with the distribution.
rosarium 0:892175366555 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
rosarium 0:892175366555 21 * may be used to endorse or promote products derived from this software
rosarium 0:892175366555 22 * without specific prior written permission.
rosarium 0:892175366555 23 *
rosarium 0:892175366555 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
rosarium 0:892175366555 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
rosarium 0:892175366555 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
rosarium 0:892175366555 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
rosarium 0:892175366555 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
rosarium 0:892175366555 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
rosarium 0:892175366555 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
rosarium 0:892175366555 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
rosarium 0:892175366555 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
rosarium 0:892175366555 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
rosarium 0:892175366555 34 *
rosarium 0:892175366555 35 ******************************************************************************
rosarium 0:892175366555 36 */
rosarium 0:892175366555 37
rosarium 0:892175366555 38 #include "mbed.h"
rosarium 0:892175366555 39
rosarium 0:892175366555 40 #include "X_NUCLEO_NFC02A1.h"
rosarium 0:892175366555 41 #include "DevI2C.h"
rosarium 0:892175366555 42 #include "m24lr.h"
rosarium 0:892175366555 43 #include "lib_NDEF_URI.h"
rosarium 0:892175366555 44 /**
rosarium 0:892175366555 45 * Write a Ndef URI message linking to st.com site.
rosarium 0:892175366555 46 */
rosarium 0:892175366555 47 int main(void)
rosarium 0:892175366555 48 {
rosarium 0:892175366555 49
rosarium 0:892175366555 50 sURI_Info URI;
rosarium 0:892175366555 51 NDEF_URI mNDEF_URI;
rosarium 0:892175366555 52 M24LR *mM24LRp;
rosarium 0:892175366555 53
rosarium 0:892175366555 54 /*use default board pinout*/
rosarium 0:892175366555 55 DevI2C i2cChannel(X_NUCLEO_NFC02A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC02A1::DEFAULT_SDL_PIN);
rosarium 0:892175366555 56 X_NUCLEO_NFC02A1 *nfcNucleo = X_NUCLEO_NFC02A1::Instance(i2cChannel,
rosarium 0:892175366555 57 X_NUCLEO_NFC02A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC02A1::DEFAULT_RF_DISABLE_PIN,
rosarium 0:892175366555 58 X_NUCLEO_NFC02A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC02A1::DEFAULT_LED2_PIN,
rosarium 0:892175366555 59 X_NUCLEO_NFC02A1::DEFAULT_LED3_PIN);
rosarium 0:892175366555 60
rosarium 0:892175366555 61 mM24LRp = nfcNucleo->getM24LR();
rosarium 0:892175366555 62 mNDEF_URI.setM24LR(mM24LRp);
rosarium 0:892175366555 63 /* Enable Energy Harvesting */
rosarium 0:892175366555 64 mM24LRp->Enable_EnergyHarvesting();
rosarium 0:892175366555 65
rosarium 0:892175366555 66 printf("System Initialization done: !\n\r");
rosarium 0:892175366555 67
rosarium 0:892175366555 68 /* Check if no NDEF detected, init mem in Tag Type 5 */
rosarium 0:892175366555 69 if( mNDEF_URI.NfcType5_NDEFDetection() != NDEF_OK)
rosarium 0:892175366555 70 {
rosarium 0:892175366555 71 mNDEF_URI.CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;
rosarium 0:892175366555 72 mNDEF_URI.CCFileStruct.Version = NFCT5_VERSION_V1_0;
rosarium 0:892175366555 73 mNDEF_URI.CCFileStruct.MemorySize = ( M24LR_MAX_SIZE / 8 ) & 0xFF;
rosarium 0:892175366555 74 mNDEF_URI.CCFileStruct.TT5Tag = 0x05;
rosarium 0:892175366555 75
rosarium 0:892175366555 76 /* Init of the Type Tag 5 component (M24LR) */
rosarium 0:892175366555 77 while( mNDEF_URI.NfcType5_TT5Init( ) != NFCTAG_OK);
rosarium 0:892175366555 78 }
rosarium 0:892175366555 79
rosarium 0:892175366555 80 /* Set the LED2 on to indicate Init done */
rosarium 0:892175366555 81 nfcNucleo->getLed2()=1;
rosarium 0:892175366555 82
rosarium 0:892175366555 83 /* Prepare URI NDEF message content */
rosarium 0:892175366555 84 strcpy( URI.protocol,URI_ID_0x01_STRING );
rosarium 0:892175366555 85 strcpy( URI.URI_Message,"st.com/st25" );
rosarium 0:892175366555 86 strcpy( URI.Information,"\0" );
rosarium 0:892175366555 87
rosarium 0:892175366555 88 /* Write NDEF to EEPROM */
rosarium 0:892175366555 89 while( mNDEF_URI.NDEF_WriteURI( &URI ) != NDEF_OK);
rosarium 0:892175366555 90
rosarium 0:892175366555 91 /* Set the LED3 on to indicate Programing done */
rosarium 0:892175366555 92 nfcNucleo->getLed3()=1;
rosarium 0:892175366555 93 }
rosarium 0:892175366555 94
rosarium 0:892175366555 95