AppNearMe µNFC stack for the NXP PN532 chip License: You can use the stack free of charge to prototype with mbed; if you want to use the stack with your commercial product, get in touch!
Dependents: IOT_sensor_nfc AppNearMe_MuNFC_PN532_Test p2p_nfc_test NFCMoodLamp ... more
License
You can use the stack free of charge to prototype with mbed; if you want to use the stack with your commercial product, get in touch!
Diff: PN532/MuNFC.cpp
- Revision:
- 3:0b949b2d3b55
- Parent:
- 2:913eb8fdfd9d
- Child:
- 5:e7e4fe1eb562
- Child:
- 6:15b1c45d50d4
--- a/PN532/MuNFC.cpp Thu Jul 26 10:02:19 2012 +0000 +++ b/PN532/MuNFC.cpp Tue Aug 07 21:55:12 2012 +0000 @@ -1,109 +1,109 @@ -/* - MuNFC.cpp - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#include "MuNFC.h" -#include "MuNFCConfig.h" - -#include "mbed.h" -#if MUNFC_RTOS -#include "rtos/rtos.h" -#endif - -#include "munfc/core/fwk.h" -#include "munfc/target/event.h" -#include "munfc/target/nfctype2.h" -#include "munfc/target/nfctype4.h" -#include "munfc/ndef/appnearme_ndef.h" -#include "munfc/ndef/appnearme_ndef_tlv.h" - -#include <cstring> //For memcpy, strlen - -//TODO add handles in NFC stack to avoid ugly things like that -//extern DigitalIn* nfc_irq_pin_int; -extern InterruptIn* nfc_irq_pin_isr; -extern DigitalOut* nfc_cs_pin; -extern SPI* nfc_spi; - -#define SIGNAL_START 0x01 - -MuNFC::MuNFC(char appHash[16], uint32_t version, - PinName mosi, PinName miso, PinName sclk, PinName cs, PinName isr) : - /* m_irq_pin_int(isr),*/ m_irq_pin_isr(isr), m_cs_pin(cs), m_spi(mosi, miso, sclk) -#if MUNFC_RTOS - , m_pThread(NULL)//m_thread(MuNFC::staticCallback, (void*)this) -#endif -{ - //nfc_irq_pin_int = &m_irq_pin_int; - nfc_irq_pin_isr = &m_irq_pin_isr; - nfc_cs_pin = &m_cs_pin; - nfc_spi = &m_spi; - - appnearme_ndef_init(appHash, version); - m_eventCb.init(target_register_event_callback); - m_encodeCb.init(appnearme_ndef_register_encode_callback); - m_decodeCb.init(appnearme_ndef_register_decode_callback); -} - -MuNFC::~MuNFC() -{ - if(m_pThread != NULL) - { - delete m_pThread; - } -} - -bool MuNFC::init() -{ - if(m_pThread == NULL) - { - m_pThread = new Thread(MuNFC::staticCallback, (void*)this); - } -#if NFC_CONTROLLER == PN512 - int ret = target_nfctype2_start(); -#elif NFC_CONTROLLER == PN532 - int ret = target_nfctype4_start(); -#endif - if(ret != OK) - { - return false; - } - return true; -} - -#if MUNFC_RTOS -void MuNFC::run() -{ - //Start NFC thread - m_pThread->signal_set(SIGNAL_START); -} - -void MuNFC::process() -{ - Thread::signal_wait(SIGNAL_START); - do - { - poll(-1); - } while(true); -} -#endif - -void MuNFC::poll(int timeoutMs) //TODO add Timeout -{ -#if NFC_CONTROLLER == PN512 - target_nfctype2_process(); -#elif NFC_CONTROLLER == PN532 - target_nfctype4_process(); -#endif -} - -#if MUNFC_RTOS - /*static*/ void MuNFC::staticCallback(void const* p) - { - ((MuNFC*)p)->process(); - } -#endif +/* + MuNFC.cpp + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#include "MuNFC.h" +#include "MuNFCConfig.h" + +#include "mbed.h" +#if MUNFC_RTOS +#include "rtos/rtos.h" +#endif + +#include "munfc/core/fwk.h" +#include "munfc/target/event.h" +#include "munfc/target/nfctype2.h" +#include "munfc/target/nfctype4.h" +#include "munfc/ndef/appnearme_ndef.h" +#include "munfc/ndef/appnearme_ndef_tlv.h" + +#include <cstring> //For memcpy, strlen + +//TODO add handles in NFC stack to avoid ugly things like that +//extern DigitalIn* nfc_irq_pin_int; +extern InterruptIn* nfc_irq_pin_isr; +extern DigitalOut* nfc_cs_pin; +extern SPI* nfc_spi; + +#define SIGNAL_START 0x01 + +MuNFC::MuNFC(char appHash[16], uint32_t version, + PinName mosi, PinName miso, PinName sclk, PinName cs, PinName isr) : + /* m_irq_pin_int(isr),*/ m_irq_pin_isr(isr), m_cs_pin(cs), m_spi(mosi, miso, sclk) +#if MUNFC_RTOS + , m_pThread(NULL)//m_thread(MuNFC::staticCallback, (void*)this) +#endif +{ + //nfc_irq_pin_int = &m_irq_pin_int; + nfc_irq_pin_isr = &m_irq_pin_isr; + nfc_cs_pin = &m_cs_pin; + nfc_spi = &m_spi; + + appnearme_ndef_init(appHash, version); + m_eventCb.init(target_register_event_callback); + m_encodeCb.init(appnearme_ndef_register_encode_callback); + m_decodeCb.init(appnearme_ndef_register_decode_callback); +} + +MuNFC::~MuNFC() +{ + if(m_pThread != NULL) + { + delete m_pThread; + } +} + +bool MuNFC::init() +{ + if(m_pThread == NULL) + { + m_pThread = new Thread(MuNFC::staticCallback, (void*)this); + } +#if NFC_CONTROLLER == PN512 + int ret = target_nfctype2_start(); +#elif NFC_CONTROLLER == PN532 + int ret = target_nfctype4_start(); +#endif + if(ret != OK) + { + return false; + } + return true; +} + +#if MUNFC_RTOS +void MuNFC::run() +{ + //Start NFC thread + m_pThread->signal_set(SIGNAL_START); +} + +void MuNFC::process() +{ + Thread::signal_wait(SIGNAL_START); + do + { + poll(-1); + } while(true); +} +#endif + +void MuNFC::poll(int timeoutMs) //TODO add Timeout +{ +#if NFC_CONTROLLER == PN512 + target_nfctype2_process(); +#elif NFC_CONTROLLER == PN532 + target_nfctype4_process(); +#endif +} + +#if MUNFC_RTOS + /*static*/ void MuNFC::staticCallback(void const* p) + { + ((MuNFC*)p)->process(); + } +#endif