
A simple application providing an example of asynchronous access to the X-NUCLEO_NFC01A1 Dynamic NFC Tag board.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of HelloWord_Async_NFC01A1 by
X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board Firmware Package
Introduction
This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board based on M24SR.
Example Application
The application provides a simple example of asynchronous access to the X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board. The program writes a URI link to the M24SR dynamic tag using the asynchronous programming model. The URI can then be retrieved from an NFC enabled smartphone/tablet.
A simpler example providing synchronous access to the tag is also available.
main.cpp@10:a7834e6dd638, 2017-08-21 (annotated)
- Committer:
- giovannivisentini
- Date:
- Mon Aug 21 12:20:40 2017 +0000
- Revision:
- 10:a7834e6dd638
- Parent:
- 9:ed8eff7c4cf4
update NDefLib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 0:79807a600c87 | 1 | /** |
giovannivisentini | 0:79807a600c87 | 2 | ****************************************************************************** |
Davidroid | 7:cd34abf10350 | 3 | * @file main.cpp |
giovannivisentini | 0:79807a600c87 | 4 | * @date 22/01/2016 |
giovannivisentini | 0:79807a600c87 | 5 | * @brief Test the async comunication api |
giovannivisentini | 0:79807a600c87 | 6 | ****************************************************************************** |
giovannivisentini | 0:79807a600c87 | 7 | * |
giovannivisentini | 0:79807a600c87 | 8 | * COPYRIGHT(c) 2015 STMicroelectronics |
giovannivisentini | 0:79807a600c87 | 9 | * |
giovannivisentini | 0:79807a600c87 | 10 | * Redistribution and use in source and binary forms, with or without modification, |
giovannivisentini | 0:79807a600c87 | 11 | * are permitted provided that the following conditions are met: |
giovannivisentini | 0:79807a600c87 | 12 | * 1. Redistributions of source code must retain the above copyright notice, |
giovannivisentini | 0:79807a600c87 | 13 | * this list of conditions and the following disclaimer. |
giovannivisentini | 0:79807a600c87 | 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
giovannivisentini | 0:79807a600c87 | 15 | * this list of conditions and the following disclaimer in the documentation |
giovannivisentini | 0:79807a600c87 | 16 | * and/or other materials provided with the distribution. |
giovannivisentini | 0:79807a600c87 | 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
giovannivisentini | 0:79807a600c87 | 18 | * may be used to endorse or promote products derived from this software |
giovannivisentini | 0:79807a600c87 | 19 | * without specific prior written permission. |
giovannivisentini | 0:79807a600c87 | 20 | * |
giovannivisentini | 0:79807a600c87 | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
giovannivisentini | 0:79807a600c87 | 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
giovannivisentini | 0:79807a600c87 | 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
giovannivisentini | 0:79807a600c87 | 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
giovannivisentini | 0:79807a600c87 | 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
giovannivisentini | 0:79807a600c87 | 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
giovannivisentini | 0:79807a600c87 | 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
giovannivisentini | 0:79807a600c87 | 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
giovannivisentini | 0:79807a600c87 | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
giovannivisentini | 0:79807a600c87 | 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
giovannivisentini | 0:79807a600c87 | 31 | * |
giovannivisentini | 0:79807a600c87 | 32 | ****************************************************************************** |
giovannivisentini | 0:79807a600c87 | 33 | */ |
giovannivisentini | 0:79807a600c87 | 34 | |
giovannivisentini | 0:79807a600c87 | 35 | #include "mbed.h" |
giovannivisentini | 6:01e1182e2320 | 36 | #include "XNucleoNFC01A1.h" |
Davidroid | 7:cd34abf10350 | 37 | #include "ReadUriCallbacks.h" |
Davidroid | 7:cd34abf10350 | 38 | #include "WriteUriCallbacks.h" |
nikapov | 9:ed8eff7c4cf4 | 39 | #include "NDefNfcTagM24SR.h" |
giovannivisentini | 0:79807a600c87 | 40 | #include "NDefLib/RecordType/RecordURI.h" |
Davidroid | 7:cd34abf10350 | 41 | |
giovannivisentini | 6:01e1182e2320 | 42 | |
giovannivisentini | 4:416db8919ca4 | 43 | /** variable set to true when we receive an interrupt from the nfc component*/ |
giovannivisentini | 4:416db8919ca4 | 44 | static volatile bool nfcInterruptFlag=false; |
giovannivisentini | 6:01e1182e2320 | 45 | |
giovannivisentini | 4:416db8919ca4 | 46 | /** variable set to true when the user press the board user button*/ |
giovannivisentini | 4:416db8919ca4 | 47 | static volatile bool buttonPress=false; |
giovannivisentini | 6:01e1182e2320 | 48 | |
giovannivisentini | 4:416db8919ca4 | 49 | /** Nfc ISR called when the nfc component has a message ready*/ |
Davidroid | 7:cd34abf10350 | 50 | static void nfc_interrupt_callback() { |
giovannivisentini | 4:416db8919ca4 | 51 | nfcInterruptFlag=true; |
giovannivisentini | 4:416db8919ca4 | 52 | }//nfcInterruptCallback |
giovannivisentini | 6:01e1182e2320 | 53 | |
Davidroid | 7:cd34abf10350 | 54 | static void set_button_press() { |
giovannivisentini | 4:416db8919ca4 | 55 | buttonPress=true; |
giovannivisentini | 4:416db8919ca4 | 56 | }//if buttonPress |
giovannivisentini | 6:01e1182e2320 | 57 | |
Davidroid | 7:cd34abf10350 | 58 | int main(int argc,char *args[]) { |
giovannivisentini | 0:79807a600c87 | 59 | (void)argc; (void)args; |
giovannivisentini | 6:01e1182e2320 | 60 | |
giovannivisentini | 4:416db8919ca4 | 61 | #if defined(TARGET_STM) |
giovannivisentini | 4:416db8919ca4 | 62 | InterruptIn userButton(USER_BUTTON); |
giovannivisentini | 6:01e1182e2320 | 63 | userButton.fall(set_button_press); |
giovannivisentini | 4:416db8919ca4 | 64 | #endif |
giovannivisentini | 6:01e1182e2320 | 65 | |
giovannivisentini | 0:79807a600c87 | 66 | //create the nfc component |
giovannivisentini | 6:01e1182e2320 | 67 | I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN); |
giovannivisentini | 0:79807a600c87 | 68 | |
giovannivisentini | 6:01e1182e2320 | 69 | XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,&nfc_interrupt_callback, |
Davidroid | 7:cd34abf10350 | 70 | XNucleoNFC01A1::DEFAULT_GPO_PIN,XNucleoNFC01A1::DEFAULT_RF_DISABLE_PIN, |
Davidroid | 7:cd34abf10350 | 71 | XNucleoNFC01A1::DEFAULT_LED1_PIN,XNucleoNFC01A1::DEFAULT_LED2_PIN, |
Davidroid | 7:cd34abf10350 | 72 | XNucleoNFC01A1::DEFAULT_LED3_PIN); |
giovannivisentini | 6:01e1182e2320 | 73 | |
giovannivisentini | 0:79807a600c87 | 74 | //No call back needed since default behavior is sync |
giovannivisentini | 6:01e1182e2320 | 75 | nfcNucleo->get_M24SR().get_session(); |
giovannivisentini | 6:01e1182e2320 | 76 | nfcNucleo->get_M24SR().manage_I2C_GPO(M24SR::I2C_ANSWER_READY); //switch to async mode |
giovannivisentini | 6:01e1182e2320 | 77 | |
giovannivisentini | 6:01e1182e2320 | 78 | NDefLib::NDefNfcTag &tag = nfcNucleo->get_M24SR().get_NDef_tag(); |
giovannivisentini | 0:79807a600c87 | 79 | printf("System Init done!\n\r"); |
giovannivisentini | 6:01e1182e2320 | 80 | |
giovannivisentini | 0:79807a600c87 | 81 | //crate the callback to use for write a tag |
giovannivisentini | 6:01e1182e2320 | 82 | WriteUriCallbacks NDefWriteCallback(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3()); |
giovannivisentini | 6:01e1182e2320 | 83 | ReadUriCallbacks NDefReadCallback(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3()); |
giovannivisentini | 6:01e1182e2320 | 84 | tag.set_callback(&NDefWriteCallback); //set the callback |
giovannivisentini | 6:01e1182e2320 | 85 | tag.open_session(); //start the callback chain |
giovannivisentini | 6:01e1182e2320 | 86 | |
giovannivisentini | 0:79807a600c87 | 87 | printf("Start Main Loop\n\r"); |
Davidroid | 7:cd34abf10350 | 88 | while(true) { |
Davidroid | 7:cd34abf10350 | 89 | if (nfcInterruptFlag) { |
giovannivisentini | 0:79807a600c87 | 90 | nfcInterruptFlag=false; |
giovannivisentini | 0:79807a600c87 | 91 | //manage an async event from the nfc component |
giovannivisentini | 6:01e1182e2320 | 92 | nfcNucleo->get_M24SR().manage_event(); |
giovannivisentini | 0:79807a600c87 | 93 | }//if |
giovannivisentini | 4:416db8919ca4 | 94 | #if defined(TARGET_STM) |
Davidroid | 7:cd34abf10350 | 95 | if (buttonPress) { |
giovannivisentini | 4:416db8919ca4 | 96 | buttonPress=false; |
giovannivisentini | 4:416db8919ca4 | 97 | printf("Pressed"); |
giovannivisentini | 6:01e1182e2320 | 98 | tag.set_callback(&NDefReadCallback); |
giovannivisentini | 6:01e1182e2320 | 99 | tag.open_session(); |
giovannivisentini | 4:416db8919ca4 | 100 | } |
giovannivisentini | 4:416db8919ca4 | 101 | #endif |
giovannivisentini | 0:79807a600c87 | 102 | __WFE(); |
giovannivisentini | 0:79807a600c87 | 103 | }//while |
giovannivisentini | 6:01e1182e2320 | 104 | |
giovannivisentini | 0:79807a600c87 | 105 | //return 0; |
Davidroid | 7:cd34abf10350 | 106 | } |