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!
Revision 10:2af578c635cd, committed 2012-11-07
- Comitter:
- AppNearMe
- Date:
- Wed Nov 07 18:18:52 2012 +0000
- Parent:
- 9:621a03f8d2f3
- Child:
- 11:5be631376e5b
- Commit message:
- Updated library
Changed in this revision
--- a/PN532/EventCallback.cpp Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - EventCallback.cpp - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -#include "EventCallback.h" - -EventCallback::EventCallback() -{ - -} - -void EventCallback::init(void (*fn)(target_event_callback, void*)) -{ - fn(staticCallback, this); -} - -void EventCallback::attach(void (*fn)(NFCEvent, void*), void* arg) -{ - m_inst = NULL; - m_fn = fn; - m_arg = arg; -} - -void EventCallback::callback(target_event event) -{ - if(m_inst) - { - m_caller((NFCEvent)event); //At some point, should not cast event directly - } - else if(m_fn) - { - m_fn((NFCEvent)event, m_arg); - } -} - -/*static*/ void EventCallback::staticCallback(target_event event, void* param) -{ - ((EventCallback*)(param))->callback(event); -} - - - - -
--- a/PN532/EventCallback.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - EventCallback.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef EVENTCALLBACK_H_ -#define EVENTCALLBACK_H_ - -#include "NFCEvent.h" - -#include "munfc/core/fwk.h" -#include "munfc/target/event.h" - -class EventCallback -{ -protected: - EventCallback(); - - void init( void (*fn)(target_event_callback, void*) ); //Callable by MuNFC - - void attach(void (*fn)(NFCEvent, void*), void* arg); - - template <class T> - void attach(T* inst, void (T::*member)(NFCEvent)) - { - m_fn = NULL; - m_inst = inst; - m_member = member; - m_caller = &EventCallback::memberCaller<T>; - } - - -private: - void callback(target_event event); - - //Function - void(*m_fn)(NFCEvent, void*); - void* m_arg; - - //Member of object instance - void* m_inst; - void* m_member; - void* (*m_caller)(NFCEvent); - - template <class T> - static inline void memberCaller(NFCEvent event) - { - T* inst = (T*) m_inst; - void (T::*member)(NFCEvent) = m_member; - inst->member(event); - } - - static void staticCallback(target_event event, void* param); - - friend class MuNFC; -}; - - - -#endif /* EVENTCALLBACK_H_ */
Binary file PN532/LPC11U24/uARM/munfc.ar has changed
Binary file PN532/LPC1768/ARM/munfc.ar has changed
--- a/PN532/MuNFC.cpp Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - 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 MUNFC_RTOS - if(m_pThread != NULL) - { - delete m_pThread; - } - #endif -} - -bool MuNFC::init() -{ - #if MUNFC_RTOS - if(m_pThread == NULL) - { - m_pThread = new Thread(MuNFC::staticCallback, (void*)this); - } - #endif -#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
--- a/PN532/MuNFC.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/* - MuNFC.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef MUNFC_H_ -#define MUNFC_H_ - -#include "MuNFCConfig.h" - -#include <cstdint> //For uint_*t -#include <cstring> //For size_t - -using std::uint8_t; -using std::uint16_t; -using std::uint32_t; -using std::size_t; - -#include "NFCEvent.h" -#include "NdefCallback.h" -#include "EventCallback.h" -#include "TLVList.h" - -#include "mbed.h" -#if MUNFC_RTOS -#include "rtos/rtos.h" -#endif - -/** A library for embedded NFC applications using NXP's PN512/PN532 NFC transceivers. -* Visit http://www.appnearme.com/ -*/ -class MuNFC -{ -public: - - - /** Instantiate the µNFC stack for the following mobile app and using the following PN512/PN532 chip. - * @param appHash 16 chars-long hash of the corresponding mobile app - * @param version Minimum version of the mobile app to use in BCD format encoded as an uint32_t (0x01000000 is version 1.0.0.0) - * @param mosi MOSI pin of the SPI interface - * @param miso MISO pin of the SPI interface - * @param sclk SCLK pin of the SPI interface - * @param cs CS pin connected to the chip - * @param isr ISR pin connected to the chip - */ - MuNFC(char appHash[16], uint32_t version, - PinName mosi, PinName miso, PinName sclk, PinName cs, PinName isr); - - ~MuNFC(); - - /** Set Encode Callback. - * The encode callback will be called on each start of NFC transaction. - * to populate the data structure that will be transmitted to the reader - * @param fn pointer to the function to be called - * @param arg argument that will be passed to the callback - */ - inline void encode(void (*fn)(TLVList*, void*), void* arg) - { - m_encodeCb.attach(fn, arg); - } - - /** Set Encode Callback. - * The encode callback will be called on each start of NFC transaction. - * to populate the data structure that will be transmitted to the reader - * @param inst pointer to the object on which to call the member - * @param member pointer to the object's member to be called - */ - template <class T> - inline void encode(T* inst, void (T::*member)(TLVList*)) - { - m_encodeCb.attach(inst, member); - } - - /** Set Decode Callback. - * The decode callback will be called on each successful termination of NFC transaction. - * populated with the data structure that was transmitted by the reader - * @param fn pointer to the function to be called - * @param arg argument that will be passed to the callback - */ - inline void decode(void (*fn)(TLVList*, void*), void* arg) - { - m_decodeCb.attach(fn, arg); - } - - /** Set Decode Callback. - * The decode callback will be called on each successful termination of NFC transaction. - * populated with the data structure that was transmitted by the reader - * @param inst pointer to the object on which to call the member - * @param member pointer to the object's member to be called - */ - template <class T> - inline void decode(T* inst, void (T::*member)(TLVList*)) - { - m_decodeCb.attach(inst, member); - } - - /** Set Event Callback. - * The event callback will be called on each of the following event: - * - Transaction started - * - Transaction successful - * - Transaction failed - * @param fn pointer to the function to be called - * @param arg argument that will be passed to the callback - */ - inline void event(void (*fn)(NFCEvent, void*), void* arg) - { - m_eventCb.attach(fn, arg); - } - - /** Set Event Callback. - * The event callback will be called on each of the following event: - * - Transaction started - * - Transaction successful - * - Transaction failed - * @param fn pointer to the function to be called - * @param arg argument that will be passed to the callback - */ - template <class T> - inline void event(T* inst, void (T::*member)(NFCEvent)); - - /** Initialize stack. - * @return true if stack was initialized correctly, false otherwise - */ - bool init(); - -//#if MUNFC_RTOS -- flasg must be disabled for proper doxygen support - /** Start NFC thread (threaded mode) - * - */ - void run(); -//#endif - -#if MUNFC_RTOS -protected: - /** NFC Thread - * - */ - void process(); -#endif - -#if MUNFC_RTOS - protected: -#else - public: -#endif - /** Poll for NFC reader (polling mode). - * @param timeoutMs (maximum polling time) - */ - void poll(int timeoutMs); - -private: -#if MUNFC_RTOS - static void staticCallback(void const* p); -#endif - - NdefCallback m_encodeCb; - NdefCallback m_decodeCb; - EventCallback m_eventCb; - - //DigitalIn m_irq_pin_int; - InterruptIn m_irq_pin_isr; - DigitalOut m_cs_pin; - SPI m_spi; - -#if MUNFC_RTOS - Thread* m_pThread; -#endif - -}; - - -#endif /* MUNFC_H_ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/MuNFCConfig.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,18 @@ +/* + MuNFCConfig.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef MUNFCCONFIG_H_ +#define MUNFCCONFIG_H_ + +#include "munfc/nfc_config.h" + + +#define MUNFC_RTOS 1 + + +#endif /* MUNFCCONFIG_H_ */
--- a/PN532/MuNFCMbedPlatform.cpp Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,348 +0,0 @@ -/* - MuNFCMbedPlatform.cpp - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ - */ - -#include "mbed.h" - -#include "MuNFCConfig.h" -#include "munfc/nfc_config.h" - -#if MUNFC_RTOS -#include "rtos/rtos.h" -#endif - -//DigitalIn* nfc_irq_pin_int; -InterruptIn* nfc_irq_pin_isr; -DigitalOut* nfc_cs_pin; -SPI* nfc_spi; - -extern "C" -{ -#if NFC_CONTROLLER == PN512 -#include "munfc/platform/pn512_platform.h" -#elif NFC_CONTROLLER == PN532 -#include "munfc/platform/pn532_platform.h" -#endif -#include "munfc/platform/rtos.h" - -#if NFC_CONTROLLER == PN512 -void pn512_io_init() -{ - nfc_irq_pin_isr->rise(pn512_irq); - *nfc_cs_pin = 1; -} - -/* - * Get the IRQ pin's state - */ -bool pn512_irq_pin_get() -{ - //return (nfc_irq_pin_int->read() ? true : false); - return (nfc_irq_pin_isr->read() ? true : false); -} - -/* - * Set the CS pin to 0 (active low) - */ -void pn512_cs_set() -{ - *nfc_cs_pin = 0; -} - -/* - * Set the CS pin to 1 (active high) - */ -void pn512_cs_clear() -{ - *nfc_cs_pin = 1; -} - -/* - * You MUST call pn512_irq() on each raising front of IRQ pin - */ -#endif - -#if NFC_CONTROLLER == PN532 -/* - * Init - */ -void pn532_io_init(void) -{ - nfc_irq_pin_isr->mode(PullUp); - #if 0//defined( TARGET_LPC11U24 ) - nfc_irq_pin_isr->rise(pn532_irq); //Cannot trigger on falling edge - #else - nfc_irq_pin_isr->fall(pn532_irq); - #endif - *nfc_cs_pin = 1; -} - -/* - * Get the IRQ pin's state - */ -bool pn532_irq_pin_get(void) -{ - //return (nfc_irq_pin_int->read() ? false : true); - #if 0//defined( TARGET_LPC11U24 ) - return (nfc_irq_pin_isr->read() ? true : false); - #else - return (nfc_irq_pin_isr->read() ? false : true); - #endif -} - -/* - * Set the CS pin to 0 (active low) - */ -void pn532_cs_set(void) -{ - //*nfc_cs_pin = 0; - nfc_cs_pin->write(0); -} - -/* - * Set the CS pin to 1 (active high) - */ -void pn532_cs_clear(void) -{ - *nfc_cs_pin = 1; -} - -/* - * You MUST call pn532_irq() on each falling front of IRQ pin - */ -#endif - -#if MUNFC_RTOS -struct rtos_semaphore //To be defined by impl -{ - Semaphore* s; -}; - -struct rtos_semaphore* rtos_semaphore_new() //Should return NULL if fails -{ - struct rtos_semaphore* pSem; - pSem = new struct rtos_semaphore; - pSem->s = new Semaphore(1); - pSem->s->wait(osWaitForever); - return pSem; -} - -int rtos_semaphore_produce(struct rtos_semaphore* pSem) -{ - pSem->s->release(); - return OK; -} - -int rtos_semaphore_consume(struct rtos_semaphore* pSem, int timeout) -{ - int resid; - if(timeout == -1) - { - resid = pSem->s->wait(osWaitForever); - } - else - { - resid = pSem->s->wait(timeout); - } - if(resid>0) - { - while( pSem->s->wait(0) > 0 ); - return OK; - } - else - { - return ERR_TIMEOUT; - } -} -#else -struct rtos_semaphore //To be defined by impl -{ - volatile int p; -}; - -struct rtos_semaphore* rtos_semaphore_new() //Should return NULL if fails -{ - struct rtos_semaphore* pSem; - pSem = new struct rtos_semaphore; - pSem->p = 1; - return pSem; -} - -//Will only be called from ISR -int rtos_semaphore_produce(struct rtos_semaphore* pSem) -{ - pSem->p++; - return OK; -} - -void ___voidf(void) -{ - -} - -int rtos_semaphore_consume(struct rtos_semaphore* pSem, int timeout) -{ - if(timeout == -1) - { - while(!pSem->p) - { - __WFI(); - } - pSem->p--; - } - else if(timeout == 0) - { - if(pSem->p) - { - pSem->p--; - } - else - { - return ERR_TIMEOUT; - } - } - else - { - Timer t; - t.start(); - Ticker t_isr; - t_isr.attach_us(&___voidf, 1000); //Just to generate an interrupt periodically - while(!pSem->p) - { - __WFI(); - if(t.read_ms()>=timeout) - { - return ERR_TIMEOUT; - } - } - pSem->p--; - } - return OK; -} -#endif - - -//These functions must be implemented for each platform - -#if NFC_CONTROLLER == PN512 -/* - * Initialize SPI - */ -int pn512_spi_init() -{ - nfc_spi->format(8, 3); - nfc_spi->frequency(10000000); //To change to 10000000 - return 0; -} -#endif - -#if NFC_CONTROLLER == PN532 -/* - * Initialize SPI - */ -int pn532_spi_init() -{ - nfc_spi->format(8, 0); - nfc_spi->frequency(5000000); - return 0; -} -#endif - -#define reverse(x) ( (x & 0x01) << 7 \ - | (x & 0x02) << 5 \ - | (x & 0x04) << 3 \ - | (x & 0x08) << 1 \ - | (x & 0x10) >> 1 \ - | (x & 0x20) >> 3 \ - | (x & 0x40) >> 5 \ - | (x & 0x80) >> 7 ) - -/* - * After skipping outSkip bytes, write outLen bytes - * After skipping inSkip bytes, read inLen bytes - * This will generate MAX(outSkip + outLen, inSkip + inLen) transfers on the SPI bus - */ -int spi_transfer(uint8_t* outBuf, size_t outLen, size_t outSkip, uint8_t* inBuf, - size_t inLen, size_t inSkip) -{ - int len; - int writeb; - int readb; - int outPos; - int inPos; - - outPos = inPos = 0; - - len = - (outSkip + outLen) > (inSkip + inLen) ? (outSkip + outLen) : - (inSkip + inLen); - - while (len--) - { - if (outSkip) - { - writeb = 0x00; - outSkip--; - } - else if (outPos < outLen) - { - writeb = outBuf[outPos]; - outPos++; - } - else - { - writeb = 0x00; - } - -#if NFC_CONTROLLER == PN532 - writeb = reverse(writeb); -#endif - - readb = nfc_spi->write(writeb); - -#if NFC_CONTROLLER == PN532 - readb = reverse(readb); -#endif - - if (inSkip) - { - inSkip--; - } - else if (inPos < inLen) - { - inBuf[inPos] = readb; - inPos++; - } - } - return 0; -} - -/* - * Write outLen bytes - */ -int spi_write(uint8_t* outBuf, size_t outLen) -{ - return spi_transfer(outBuf, outLen, 0, (uint8_t*) NULL, 0, 0); -} - -/* - * Read inLen bytes - */ -int spi_read(uint8_t* inBuf, size_t inLen) -{ - return spi_transfer((uint8_t*) NULL, 0, 0, inBuf, inLen, 0); -} - -/* - * Skip len bytes - */ -int spi_skip(size_t len) -{ - return spi_transfer((uint8_t*) NULL, 0, len, (uint8_t*) NULL, 0, len); -} - -} -
--- a/PN532/NFCEvent.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -/* - NFCEvent.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -/** \file NFCEvent.h -* NFC-related events -*/ - -#ifndef NFCEVENT_H_ -#define NFCEVENT_H_ - -/** NFC-related events - * - */ -enum NFCEvent -{ - NFC_TRANSACTION_STARTED, //!< Transaction with reader started (anticollision successful) - NFC_TRANSACTION_SUCCESSFUL, //!< Transaction with reader successful - NFC_TRANSACTION_FAILED //!< Transaction with reader failed -}; - -#endif /* NFCEVENT_H_ */
--- a/PN532/NdefCallback.cpp Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - NdefCallback.cpp - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -#include "NdefCallback.h" -#include "TLVList.h" - -NdefCallback::NdefCallback() -{ - -} - -void NdefCallback::init(void (*fn)(appnearme_ndef_callback, void*)) -{ - fn(staticCallback, this); -} - -void NdefCallback::attach(void (*fn)(TLVList*, void*), void* arg) -{ - m_inst = NULL; - m_fn = fn; - m_arg = arg; -} - -void NdefCallback::callback(tlv_list* payload) -{ - m_tlvList.wrap(payload); - if(m_inst) - { - m_caller(&m_tlvList); - } - else if(m_fn) - { - m_fn(&m_tlvList, m_arg); - } -} - -/*static*/ void NdefCallback::staticCallback(tlv_list* payload, void* param) -{ - ((NdefCallback*)(param))->callback(payload); -} - -
--- a/PN532/NdefCallback.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - NdefCallback.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef NDEFCALLBACK_H_ -#define NDEFCALLBACK_H_ - -#include "TLVList.h" - -#include "munfc/core/fwk.h" -#include "munfc/ndef/appnearme_ndef.h" - -class NdefCallback -{ -protected: - NdefCallback(); //Callable by MuNFC - - void init(void (*fn)(appnearme_ndef_callback, void*)); - - void attach(void (*fn)(TLVList*, void*), void* arg); - - template <class T> - void attach(T* inst, void (T::*member)(TLVList*)) - { - m_fn = NULL; - m_inst = inst; - m_member = member; - m_caller = &NdefCallback::memberCaller<T>; - } - -private: - void callback(tlv_list* payload); - - //Data - TLVList m_tlvList; - - //Function - void(*m_fn)(TLVList*, void*); - void* m_arg; - - //Member of object instance - void* m_inst; - void* m_member; - void* (*m_caller)(TLVList*); - - template <class T> - static inline void memberCaller(TLVList* tlvList) - { - T* inst = (T*) m_inst; - void (T::*member)(TLVList*) = m_member; - inst->member(tlvList); - } - - static void staticCallback(tlv_list* payload, void* param); - - friend class MuNFC; -}; - - -#endif /* NDEFCALLBACK_H_ */
--- a/PN532/TLVList.cpp Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,235 +0,0 @@ -/* - TLVList.cpp - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -#include "TLVList.h" - -#include "munfc/core/fwk.h" -#include "munfc/ndef/appnearme_ndef_tlv.h" - -#include <cstring> //For memcpy, strlen -using std::memcpy; -using std::strlen; - -TLVList::TLVList() : m_tlvList(NULL) -{ - -} - -void TLVList::wrap(tlv_list* payload) -{ - m_tlvList = payload; - m_space = true; - m_type = NONE; -} - - - -/* Getters */ - -/** Iterate to next item - * @return type if next item exists, NONE otherwise - */ -TLVList::TLVType TLVList::getNext() -{ - if(!m_tlvList) - { - return NONE; - } - - m_type = (TLVList::TLVType) appnearme_ndef_tlv_next_type(m_tlvList); //Explicit cast, this is the same enum - switch(m_type) - { - case UINT8: - m_arrayLen = 0; - m_uint8 = appnearme_ndef_tlv_get_uint8(m_tlvList); - break; - case UINT32: - m_arrayLen = 0; - m_uint32 = appnearme_ndef_tlv_get_uint32(m_tlvList); - break; - case UINT8_ARRAY: - //In this order, otherwise would break state-machine - m_arrayLen = appnearme_ndef_tlv_get_array_length(m_tlvList); - m_array = appnearme_ndef_tlv_get_array(m_tlvList); - break; - case STRING: - //In this order, otherwise would break state-machine - m_strLen = appnearme_ndef_tlv_get_string_length(m_tlvList); - m_str = appnearme_ndef_tlv_get_string(m_tlvList); - break; - } - return m_type; -} - -/** Get uint8_t value - * If the current item's type is uint32_t, the value will be masked with 0xFF - * @return uint8_t value OR 0 if the type is incompatible - */ -uint8_t TLVList::getUInt8() -{ - switch(m_type) - { - case UINT8: - return m_uint8; - case UINT32: - return m_uint32 & 0xFF; - default: - return 0; - } -} - -/** Get uint32_t value - * If the current item's type is uint8_t, the value will be casted to uint32_t - * @return uint32_t value OR 0 if the type is incompatible - */ -uint32_t TLVList::getUInt32() -{ - switch(m_type) - { - case UINT32: - return m_uint32; - case UINT8: - return m_uint8 & 0xFF; - default: - return 0; - } -} - -/** Get array length - * @return bytes array length - */ -size_t TLVList::getArrayLength() -{ - switch(m_type) - { - case UINT8_ARRAY: - return m_arrayLen; - default: - return 0; - } -} - -/** Get array - * @param buf pointer to buffer's start - * @param maxLen maximum number of bytes to copy - * @return number of copied bytes - */ -size_t TLVList::getArray(uint8_t* buf, size_t maxLen) -{ - if(m_type != UINT8_ARRAY) - { - return 0; - } - size_t len = MIN(maxLen, m_arrayLen); - memcpy(buf, m_array, len); - return len; -} - -/** Get string length - * @return string length - */ -size_t TLVList::getStringLength() -{ - switch(m_type) - { - case STRING: - return m_strLen; - default: - return 0; - } -} - - -/** Get string - * Copy string to buffer (including null-terminating char) - * @param str pointer to string's start - * @param maxLen maximum number of chars to copy (not including null-terminating char) - * @return number of copied chars - */ -size_t TLVList::getString(char* str, size_t maxLen) -{ - if(m_type != STRING) - { - return 0; - } - size_t len = MIN(maxLen, m_strLen); - memcpy(str, m_str, len); - str[len] = '\0'; //Add null-terminating char - return len; -} - -/* Setters */ - -/** Check whether there is space left in list - * @return true if there is space left, false otherwise - */ -bool TLVList::isSpace() -{ - return m_space; -} - -/** Put uint8_t value - * @param value uint8_t value - * @return true on success, false if there is not enough space in buffer - */ -bool TLVList::putUInt8(uint8_t value) -{ - int res = appnearme_ndef_tlv_put_uint8(m_tlvList, value); - if( !res ) - { - m_space = false; - return false; - } - return true; -} - -/** Put uint32_t value - * @param value uint32_t value - * @return true on success, false if there is not enough space in buffer - */ -bool TLVList::putUInt32(uint32_t value) -{ - int res = appnearme_ndef_tlv_put_uint32(m_tlvList, value); - if( !res ) - { - m_space = false; - return false; - } - return true; -} - -/** Put array - * @param buf pointer to buffer's start - * @param len number of bytes to copy - * @return number of copied bytes - */ -size_t TLVList::putArray(uint8_t* buf, size_t len) -{ - int res = appnearme_ndef_tlv_put_array(m_tlvList, buf, len); - if( !res ) - { - m_space = false; - return 0; - } - return len; -} - -/** Put string - * @param str pointer to null-terminated string's start - * @return number of copied bytes - */ -size_t TLVList::putString(char* str) -{ - int res = appnearme_ndef_tlv_put_string(m_tlvList, str); - if( !res ) - { - m_space = false; - return 0; - } - return strlen(str); -} -
--- a/PN532/TLVList.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -/* - TLVList.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -/** \file TLVList.h -* List of Type/Length/Values items -*/ - -#ifndef TLVLIST_H_ -#define TLVLIST_H_ - -#include <cstdint> //For uint_*t -#include <cstring> //For size_t - -using std::uint8_t; -using std::uint16_t; -using std::uint32_t; -using std::size_t; - -typedef struct __tlv_list tlv_list; - -/** A simple container -* List of Type/Length/Values items -*/ -class TLVList -{ -public: - - //getNext... - //get() - //put() - - - //typedef tlv_type TLVType; - /** Type of a TLV item - * - */ - enum TLVType - { - UINT8, //!< Unsigned char (byte) - UINT32, //!< Unsigned int - UINT8_ARRAY, ///< Byte array - STRING, //!<String - NONE, //!<End of packet - UNKNOWN //!< Unknown type - }; - - /* Getters */ - - /** Iterate to next item. - * @return type if next item exists, NONE otherwise - */ - TLVType getNext(); - - /** Get uint8_t value. - * If the current item's type is uint32_t, the value will be masked with 0xFF. - * @return uint8_t value OR 0 if the type is incompatible - */ - uint8_t getUInt8(); - - /** Get uint32_t value. - * If the current item's type is uint8_t, the value will be casted to uint32_t. - * @return uint32_t value OR 0 if the type is incompatible - */ - uint32_t getUInt32(); - - /** Get array length. - * @return bytes array length - */ - size_t getArrayLength(); - - /** Get array. - * @param buf pointer to buffer's start - * @param maxLen maximum number of bytes to copy - * @return number of copied bytes - */ - size_t getArray(uint8_t* buf, size_t maxLen); - - /** Get string length. - * @return string length - */ - size_t getStringLength(); - - /** Get string. - * Copy string to buffer (including null-terminating char). - * @param str pointer to string's start - * @param maxLen maximum number of chars to copy (not including null-terminating char) - * @return number of copied chars - */ - size_t getString(char* str, size_t maxLen); - - /* Setters */ - - /** Check whether there is space left in list. - * @return true if there is space left, false otherwise - */ - bool isSpace(); - - /** Put uint8_t value. - * @param value uint8_t value - * @return true on success, false if there is not enough space in buffer - */ - bool putUInt8(uint8_t value); - - /** Put uint32_t value. - * @param value uint32_t value - * @return true on success, false if there is not enough space in buffer - */ - bool putUInt32(uint32_t value); - - /** Put array. - * @param buf pointer to buffer's start - * @param len number of bytes to copy - * @return number of copied bytes - */ - size_t putArray(uint8_t* buf, size_t len); - - /** Put string. - * @param str pointer to null-terminated string's start - * @return number of copied bytes - */ - size_t putString(char* str); - -protected: - TLVList(); - - void wrap(tlv_list* payload); - -private: - tlv_list* m_tlvList; - - TLVType m_type; - - union - { - uint8_t m_uint8; - uint32_t m_uint32; - uint8_t* m_array; - char* m_str; - }; - - union - { - size_t m_arrayLen; - size_t m_strLen; - }; - - bool m_space; - - friend class NdefCallback; -}; - - -#endif /* TLVLIST_H_ */
Binary file PN532/munfc/LPC11U24/munfc.ar has changed
Binary file PN532/munfc/LPC1768/munfc.ar has changed
--- a/PN532/munfc/core/buffer.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - buffer.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -#ifndef BUFFER_H_ -#define BUFFER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" - -typedef struct __buffer -{ - uint8_t* bufdata; - size_t size; - - uint8_t* start; - size_t first_byte_length; //In bits - - uint8_t* end; - size_t last_byte_length; //In bits - - struct __buffer* next; - -} buffer; - -void buffer_init(buffer* pBuf, uint8_t* bufdata, size_t size); - -void buffer_byref(buffer* pBuf, uint8_t* bufdata, size_t length); //New buffer by ref on a size_t array, no malloc (useful on PIC for instance) - -buffer* buffer_new(size_t size); //malloc - -uint8_t* buffer_data(buffer* pBuf); - -void buffer_reset(buffer* pBuf); - -size_t buffer_size(buffer* pBuf); - -size_t buffer_length(buffer* pBuf); - -bool buffer_empty(buffer* pBuf); - -void buffer_set_length(buffer* pBuf, size_t length); - -size_t buffer_last_byte_length(buffer* pBuf); - -void buffer_set_last_byte_length(buffer* pBuf, size_t length); - -size_t buffer_bits_count(buffer* pBuf); - -void buffer_write_byte(buffer* pBuf, uint8_t b); - -void buffer_write_bit(buffer* pBuf, uint8_t b); - -#if 0 -size_t buffer_read_byte(buffer* pBuf, uint8_t b); - -size_t buffer_read_bit(buffer* pBuf, uint8_t b); -#endif - -buffer* buffer_next(buffer* pBuf); - -void buffer_set_next(buffer* pBuf, buffer* pNextBuf); - -void buffer_append(buffer* pBuf, buffer* pAppBuf); - -void buffer_unlink(buffer* pBuf, buffer* pLinkedBuf); - -size_t buffer_total_size(buffer* pBuf); - -size_t buffer_total_length(buffer* pBuf); - -void buffer_set_total_length(buffer* pBuf, size_t length); - -void buffer_free(buffer* pBuf); - -#ifdef __cplusplus -} -#endif - -#endif /* BUFFER_H_ */
--- a/PN532/munfc/core/debug.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - debug.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -#ifndef DEBUG_H_ -#define DEBUG_H_ - -#include "core/fwk.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if !DEBUG_DISABLED - -void debug(int level, const char* module, int line, const char* fmt, ...); -void debugx_enter(void); -void debugx(const char* fmt, ...); -void debugx_leave(void); - -#else -#ifdef __DEBUG__ -#undef __DEBUG__ -#define __DEBUG__ 0 -#endif - -#endif - -#if __DEBUG__ > 0 -#ifndef __MODULE__ -#error "__MODULE__ must be defined" -#endif -#endif - -#if __DEBUG__ >= 1 -#define ERR(...) do{ debug(1, __MODULE__, __LINE__, __VA_ARGS__); }while(0) -#else -#define ERR(...) -#endif - -#if __DEBUG__ >= 2 -#define WARN(...) do{ debug(2, __MODULE__, __LINE__, __VA_ARGS__); }while(0) -#else -#define WARN(...) -#endif - -#if __DEBUG__ >= 3 -#define DBG(...) do{ debug(3, __MODULE__, __LINE__, __VA_ARGS__); }while(0) -#define DBGX_ENTER() do{ debugx_enter(); }while(0); -#define DBGX(...) do{ debugx(__VA_ARGS__); }while(0) -#define DBGX_LEAVE() do{ debugx_leave(); }while(0); -#else -#define DBG(...) -#define DBGX_ENTER() -#define DBGX(...) -#define DBGX_LEAVE() -#endif - -#ifdef __cplusplus -} -#endif - -#endif -
--- a/PN532/munfc/core/errors.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - errors.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -#ifndef ERRORS_H_ -#define ERRORS_H_ - -#define OK 0 //No error - -#define ERR_UNKNOWN 1 -#define ERR_LENGTH 2 -#define ERR_NOT_FOUND 3 -#define ERR_UNSUPPORTED 4 -#define ERR_PARAMS 5 -#define ERR_BUFFER_TOO_SMALL 6 -#define ERR_TIMEOUT 7 -#define ERR_CRC 8 -#define ERR_NOCARD 9 -#define ERR_PARITY 10 -#define ERR_FIELD 11 //Lost RF field -#define ERR_COLLISION 12 -#define ERR_WRONG_COMM 13 -#define ERR_PROTOCOL 14 //Protocol is not conformant -#define ERR_BUSY 15 -#define ERR_CONTROLLER 16 //Controller failure - -#endif /* ERRORS_H_ */
--- a/PN532/munfc/core/fwk.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - fwk.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef FWK_H_ -#define FWK_H_ - -#include "nfc_config.h" - -//Standard types definition -#include "stdint.h" - -//Definition of size_t on 32-bit arch -typedef uint32_t size_t; - -#ifndef __cplusplus -typedef uint8_t bool; //Define boolean type for pure-C functions -#define true 1 -#define false 0 -#endif - -//NULL pointer definition -#ifndef NULL -#define NULL ((void*)0) -#endif - -//Error codes -#include "errors.h" - -//RTOS abstraction -#include "platform/rtos.h" - -//Debugging -#include "debug.h" - -//Buffer -#include "buffer.h" - -//Macros -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#endif /* FWK_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn512/pn512.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,24 @@ +/* + pn512.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef PN512_H_ +#define PN512_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * To be called on each interrupt + */ +void pn512_irq(void); + +#ifdef __cplusplus +} +#endif + +#endif /* PN512_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn512/pn512_cmd.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,68 @@ +/* + pn512_cmd.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef PN512_CMD_H_ +#define PN512_CMD_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" + +#define PN512_CMD_IDLE 0x00 //No action, cancels current command execution +#define PN512_CMD_MEM 0x01 //Stores 25 bytes into the internal buffer +#define PN512_CMD_CONFIG 0x01 //Configures the PN512 for FeliCa, MIFARE and NFCIP-1 communication +#define PN512_CMD_RNDIDG 0x02 //Generates a 10-byte random ID number +#define PN512_CMD_CRC 0x03 //Activates the CRC coprocessor or performs a self test +#define PN512_CMD_TRANSMIT 0x04 //Transmits data from the FIFO buffer +#define PN512_CMD_NOCHANGE 0x07 //No command change +#define PN512_CMD_RECEIVE 0x08 //Activates the receiver circuits +#define PN512_CMD_TRANSCEIVE 0x0C //Transmits data from FIFO buffer to antenna and automatically activates the receiver after transmission +#define PN512_CMD_AUTOCOLL 0x0D //Handles FeliCa polling (Card Operation mode only) and MIFARE anticollision (Card Operation mode only) +#define PN512_CMD_MFAUTH 0x0E //Performs the MIFARE standard authentication as a reader +#define PN512_CMD_SOFTRST 0x0F //Resets the PN512 + +#define PN512_CMD_REG_MASK 0x0F + +void pn512_cmd_init(void); + +//Fifo read / write +size_t pn512_fifo_write(uint8_t* buf, size_t len); +size_t pn512_fifo_read(uint8_t* buf, size_t len); + +//Fifo clear +void pn512_fifo_clear(void); + +//Fifo bytes read +size_t pn512_fifo_space(void); +size_t pn512_fifo_length(void); + +//Execute command +void pn512_cmd_exec(uint8_t cmd); + +//Read executed command +uint8_t pn512_cmd_get(void); + +//Sets xmit last byte bits +void pn512_tx_set_last_byte_size(size_t bits); + +//Gets rcv last byte bits +size_t pn512_rx_get_last_byte_size(void); + +#define PN512_TRANSCEIVE_TX 1 +#define PN512_TRANSCEIVE_RX 2 +//Start transceive +int pn512_transceive(int option); + +int pn512_target_anticollision(void); + +#ifdef __cplusplus +} +#endif + +#endif /* PN512_CMD_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn512/pn512_hw.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,27 @@ +/* + pn512_hw.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef PN512_HW_H_ +#define PN512_HW_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void pn512_hw_init(void); + +void pn512_hw_write(uint8_t addr, uint8_t* buf, size_t len); +void pn512_hw_read(uint8_t addr, uint8_t* buf, size_t len); + +bool pn512_hw_irq_state(void); + +#ifdef __cplusplus +} +#endif + +#endif /* PN512_HW_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn512/pn512_irq.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,58 @@ +/* + pn512_irq.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef PN512_IRQ_H_ +#define PN512_IRQ_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define PN512_IRQ_TX (1<<6) +#define PN512_IRQ_RX (1<<5) +#define PN512_IRQ_IDLE (1<<4) +#define PN512_IRQ_HIGH_ALERT (1<<3) +#define PN512_IRQ_LOW_ALERT (1<<2) +#define PN512_IRQ_ERR (1<<1) +#define PN512_IRQ_TIMER (1<<0) + +#define PN512_IRQ_SIGIN (1<<(4+8)) +#define PN512_IRQ_MODE (1<<(3+8)) +#define PN512_IRQ_CRC (1<<(2+8)) +#define PN512_IRQ_RF_ON (1<<(1+8)) +#define PN512_IRQ_RF_OFF (1<<(0+8)) + +#define PN512_IRQ_NONE 0 + +#define PN512_REG_COMIEN_MASK 0x7F +#define PN512_REG_COMIEN_VAL 0x00 + +#define PN512_REG_DIVIEN_MASK 0x1F +#define PN512_REG_DIVIEN_VAL 0x80 + +#define PN512_REG_COMIRQ_MASK 0x7F +#define PN512_REG_COMIRQ_CLEAR 0x00 + +#define PN512_REG_DIVIRQ_MASK 0x1F +#define PN512_REG_DIVIRQ_CLEAR 0x00 + +void pn512_irq_init(void); + +void pn512_irq_set(uint16_t irqs); //ORed +uint16_t pn512_irq_get(void); //ORed + +int pn512_irq_wait(int timeout); + +void pn512_irq_clear(void); + +bool pn512_irq_state(void); + +#ifdef __cplusplus +} +#endif + +#endif /* PN512_IRQ_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn512/pn512_registers.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,91 @@ +/* + pn512_registers.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef PN512_REGISTERS_H_ +#define PN512_REGISTERS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +//Page 0 - Command and Status +#define PN512_REG_PAGE 0x00 //Selects the register page +#define PN512_REG_COMMAND 0x01 //Starts and stops command execution +#define PN512_REG_COMIEN 0x02 //Controls bits to enable and disable the passing of Interrupt Requests +#define PN512_REG_DIVIEN 0x03 //Controls bits to enable and disable the passing of Interrupt Requests +#define PN512_REG_COMIRQ 0x04 //Contains Interrupt Request bits +#define PN512_REG_DIVIRQ 0x05 //Contains Interrupt Request bits +#define PN512_REG_ERROR 0x06 //Error bits showing the error status of the last command executed +#define PN512_REG_STATUS1 0x07 //Contains status bits for communication +#define PN512_REG_STATUS2 0x08 //Contains status bits of the receiver and transmitter +#define PN512_REG_FIFODATA 0x09 //In- and output of 64 byte FIFO-buffer +#define PN512_REG_FIFOLEVEL 0x0A //Indicates the number of bytes stored in the FIFO +#define PN512_REG_WATERLEVEL 0x0B //Defines the level for FIFO under- and overflow warning +#define PN512_REG_CONTROL 0x0C //Contains miscellaneous Control Registers +#define PN512_REG_BITFRAMING 0x0D //Adjustments for bit oriented frames +#define PN512_REG_COLL 0x0E //Bit position of the first bit collision detected on the RF-interface + +//Page 1 - Command +//#define PN512_REG_PAGE 0x10 //Selects the register page +#define PN512_REG_MODE 0x11 //Defines general modes for transmitting and receiving +#define PN512_REG_TXMODE 0x12 //Defines the data rate and framing during transmission +#define PN512_REG_RXMODE 0x13 //Defines the data rate and framing during receiving +#define PN512_REG_TXCONTROL 0x14 //Controls the logical behavior of the antenna driver pins TX1 and TX2 +#define PN512_REG_TXAUTO 0x15 //Controls the setting of the antenna drivers +#define PN512_REG_TXSEL 0x16 //Selects the internal sources for the antenna driver +#define PN512_REG_RXSEL 0x17 //Selects internal receiver settings +#define PN512_REG_RXTHRESHOLD 0x18 //Selects thresholds for the bit decoder +#define PN512_REG_DEMOD 0x19 //Defines demodulator settings +#define PN512_REG_FELNFC1 0x1A //Defines the length of the valid range for the receive package +#define PN512_REG_FELNFC2 0x1B //Defines the length of the valid range for the receive package +#define PN512_REG_MIFNFC 0x1C //Controls the communication in ISO/IEC 14443/MIFARE and NFC target mode at 106 kbit +#define PN512_REG_MANUALRCV 0x1D //Allows manual fine tuning of the internal receiver +#define PN512_REG_TYPEB 0x1E //Configure the ISO/IEC 14443 type B +#define PN512_REG_SERIALSPEED 0x1F //Selects the speed of the serial UART interface + +//Page 2 - CFG +//#define PN512_REG_PAGE 0x20 //Selects the register page +#define PN512_REG_CRCRESULT 0x21 //Shows the actual MSB and LSB values of the CRC calculation +#define PN512_REG_GSNOFF 0x23 //Selects the conductance of the antenna driver pins TX1 and TX2 for modulation, when the driver is switched off +#define PN512_REG_MODWIDTH 0x24 //Controls the setting of the ModWidth +#define PN512_REG_TXBITPHASE 0x25 //Adjust the TX bit phase at 106 kbit +#define PN512_REG_RFCFG 0x26 //Configures the receiver gain and RF level +#define PN512_REG_GSNON 0x27 //Selects the conductance of the antenna driver pins TX1 and TX2 for modulation when the drivers are switched on +#define PN512_REG_CWGSP 0x28 //Selects the conductance of the antenna driver pins TX1 and TX2 for modulation during times of no modulation +#define PN512_REG_MODGSP 0x29 //Selects the conductance of the antenna driver pins TX1 and TX2 for modulation during modulation +#define PN512_REG_TMODE_TPRESCALERHIGH 0x2A //Defines settings for the internal timer +#define PN512_REG_TPRESCALERLOW 0x2B //Defines settings for the internal timer +#define PN512_REG_TRELOADHIGH 0x2C //Describes the 16-bit timer reload value +#define PN512_REG_TRELOADLOW 0x2D //Describes the 16-bit timer reload value +#define PN512_REG_TCOUNTERVALHIGH 0x2E //Shows the 16-bit actual timer value +#define PN512_REG_TCOUNTERVALLOW 0x2F //Shows the 16-bit actual timer value + +//Page 3 - TestRegister +//#define PN512_REG_PAGE 0x30 //Selects the register page +#define PN512_REG_TESTSEL1 0x31 //General test signal configuration +#define PN512_REG_TESTSEL2 0x32 //General test signal configuration and PRBS control +#define PN512_REG_TESTPINEN 0x33 //Enables pin output driver on 8-bit parallel bus (Note: For serial interfaces only) +#define PN512_REG_TESTPINVALUE 0x34 //Defines the values for the 8-bit parallel bus when it is used as I/O bus +#define PN512_REG_TESTBUS 0x35 //Shows the status of the internal testbus +#define PN512_REG_AUTOTEST 0x36 //Controls the digital selftest +#define PN512_REG_VERSION 0x37 //Shows the version +#define PN512_REG_ANALOGTEST 0x38 //Controls the pins AUX1 and AUX2 +#define PN512_REG_TESTDAC1 0x39 //Defines the test value for the TestDAC1 +#define PN512_REG_TESTDAC2 0x3A //Defines the test value for the TestDAC2 +#define PN512_REG_TESTADC 0x3B //Shows the actual value of ADC I and Q + + +void pn512_registers_init(void); + +void pn512_register_write(uint8_t address, uint8_t data); +uint8_t pn512_register_read(uint8_t address); + +#ifdef __cplusplus +} +#endif + +#endif /* PN512_REGISTERS_H_ */
--- a/PN532/munfc/drv/pn532/pn532.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -/* - pn532.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef PN532_H_ -#define PN532_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * To be called on each interrupt - */ -void pn532_irq(void); - -#ifdef __cplusplus -} -#endif - -#endif /* PN532_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn532/pn532_cmd.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,94 @@ +/* + pn532_cmd.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef PN532_CMD_H_ +#define PN532_CMD_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" + +// Commands +int pn532_cmd_get_firmware_version( uint8_t* pIc, uint16_t* pVersion, int timeout ); + +#define PN532_PARAMETERS_NONE 0x00 +#define PN532_PARAMETERS_NAD_USED 0x01 +#define PN532_PARAMETERS_DID_USED 0x02 +#define PN532_PARAMETERS_AUTO_ATR_RES 0x04 +#define PN532_PARAMETERS_AUTO_RATS 0x10 +#define PN532_PARAMETERS_ISO_14443_4_EMU 0x20 +#define PN532_PARAMETERS_NO_PRE_POSTAMBLE 0x40 + +int pn532_cmd_set_parameters( uint8_t flags, int timeout ); + +int pn532_cmd_sam_configuration( uint8_t mode, int timeout ); + +//Target mode selection +#define PN532_TARGET_PASSIVE_ONLY 0x01 +#define PN532_TARGET_DEP_ONLY 0x02 +#define PN532_TARGET_PICC_ONLY 0x04 + +//Target mode +#define PN532_TARGET_BAUDRATE_MASK 0x70 +#define PN532_TARGET_BAUDRATE_106K 0x00 +#define PN532_TARGET_BAUDRATE_212K 0x01 +#define PN532_TARGET_BAUDRATE_414K 0x02 +#define PN532_TARGET_ISO_14443_4_PICC 0x08 +#define PN532_TARGET_DEP 0x04 +#define PN532_TARGET_FRAMING_MASK 0x03 +#define PN532_TARGET_FRAMING_MIFARE 0x00 +#define PN532_TARGET_FRAMING_ACTIVE 0x01 +#define PN532_TARGET_FRAMING_FELICA 0x02 + +//Initiator mode +#define PN532_READER_MODE_ISO14443A_106K 0x00 +#define PN532_READER_MODE_FELICA_212K 0x01 +#define PN532_READER_MODE_FELICA_424K 0x02 +#define PN532_READER_MODE_ISO14443B_106K 0x03 +#define PN532_READER_MODE_JEWEL_106K 0x04 + +// pMifareParams : 6 bytes long, pFelicaParams : 18, pNfcId3 : 10 +int pn532_cmd_target_init( uint8_t outMode, buffer* pMifareParams, buffer* pFelicaParams, + buffer* pNfcId3, buffer* pAtrG, buffer* pAtrT, uint8_t* pInMode, buffer* pData, int timeout); + +int pn532_cmd_target_get( buffer* pData, uint8_t* pStatus, int timeout ); + +int pn532_cmd_target_respond( buffer* pData, uint8_t* pStatus, int timeout ); + +//PN532 handles framing +int pn532_cmd_target_data_get( buffer* pData, uint8_t* pStatus, int timeout ); + +int pn532_cmd_target_data_respond( buffer* pData, uint8_t* pStatus, int timeout ); + +int pn532_cmd_target_status( uint8_t* pState, uint8_t* pBaudrate, int timeout ); + +int pn532_cmd_reader_poll( uint8_t mode, uint8_t* pTargetDetected, buffer* pInitiatorData, int timeout ); + +//PN532 handles framing +int pn532_cmd_reader_data_transceive( buffer* pDataOut, buffer* pDataIn, uint8_t* pStatus, int timeout ); + +int pn532_cmd_register_read( uint16_t address, uint8_t* pData, int timeout ); + +int pn532_cmd_register_write( uint16_t address, uint8_t data, int timeout ); + +int pn532_cmd_set_rf_field( bool on, int timeout ); + +int pn532_cmd_set_rf_iso14443a_params( buffer* pData, int timeout ); + +int pn532_cmd_get_status( uint8_t* pErr, uint8_t* pField, int timeout ); + +// Low-level command +int pn532_cmd_exec( buffer* pDataOut, buffer* pDataIn, int timeout ); + +#ifdef __cplusplus +} +#endif + +#endif /* PN532_CMD_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn532/pn532_frame.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,35 @@ +/* + pn532_frame.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef PN532_FRAME_H_ +#define PN532_FRAME_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" +#include "core/buffer.h" + +int pn532_frame_send( buffer* pBuf ); + +int pn532_frame_receive( buffer* pBuf ); + +int pn532_frame_send_ack( void ); + +int pn532_frame_send_nack( void ); + +int pn532_frame_receive_ack_nack( void ); + +int pn532_frame_available( void ); + +#ifdef __cplusplus +} +#endif + +#endif /* PN532_FRAME_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn532/pn532_irq.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,25 @@ +/* + pn532_irq.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef PN532_IRQ_H_ +#define PN532_IRQ_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void pn532_irq_init(void); + +int pn532_irq_wait(int timeout); + +bool pn532_irq_state(void); + +#ifdef __cplusplus +} +#endif + +#endif /* PN532_IRQ_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn532/pn532_registers.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,33 @@ +/* + pn532_registers.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef PN532_REGISTERS_H_ +#define PN532_REGISTERS_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +//We only place common SFR-accessible registers here for now +#define PN532_REG_CLU_STATUS2 0x6338 //Contains status flags of the receiver, transmitter and Data Mode Detector +#define PN532_REG_CLU_CONTROL 0x633C//0xFFED //Contains miscellaneous Control Registers +#define PN532_REG_CLU_BITFRAMING 0x633D//0xFFEE //Adjustments for bit oriented frames +#define PN532_REG_CLU_MANUALRCV 0x630D //Tuning of the internal receiver +#define PN532_REG_CLU_TXMODE 0x6302 //Defines the transmission data rate and framing during transmission +#define PN532_REG_CLU_RXMODE 0x6303 //Defines the reception data rate and framing during receiving +#define PN532_REG_CLU_TXAUTO 0x6305 //Controls the setting of the antenna driver +#define PN532_REG_CLU_MODE 0x6301 //Defines general modes for transmitting and receiving. +#define PN532_REG_CLU_MIFNFC 0x630C //Defines ISO/IEC 14443A/MIFARE/NFC specific settings in target or card operating mode. + +#ifdef __cplusplus +} +#endif + + +#endif /* PN532_REGISTERS_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/pn532/pn532_status.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,64 @@ +/* + pn532_status.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef PN532_STATUS_H_ +#define PN532_STATUS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/errors.h" + +#define PN532_STATUS_TIMEOUT 0x01 //Time Out, the target has not answered +#define PN532_STATUS_CRC 0x02 //A CRC error has been detected by the CIU +#define PN532_STATUS_PARITY 0x03 //A Parity error has been detected by the CIU 0x03 +#define PN532_STATUS_BITCOUNT 0x04 //During an anti-collision/select operation (ISO/IEC14443-3 + //Type A and ISO/IEC18092 106 kbps passive mode), an + //erroneous Bit Count has been detected +#define PN532_STATUS_FRAMING 0x05 //Framing error during Mifare operation +#define PN532_STATUS_ANTICOLL 0x06 //An abnormal bit-collision has been detected during bit wise + //anti-collision at 106 kbps +#define PN532_STATUS_BUFFER_TOO_SMALL 0x07 //Communication buffer size insufficient 0x07 +#define PN532_STATUS_BUFFER_OVERFLOW 0x09 //RF Buffer overflow has been detected by the CIU (bit + //BufferOvfl of the register CIU_Error) +#define PN532_STATUS_NFCIP1_ACTIVE 0x0A //In active communication mode, the RF field has not been + //switched on in time by the counterpart (as defined in NFCIP-1 + //standard) +#define PN532_STATUS_RF 0x0B //RF Protocol error +#define PN532_STATUS_OVERHEAT 0x0D //Temperature error: the internal temperature sensor has + //detected overheating, and therefore has automatically + //switched off the antenna drivers +#define PN532_STATUS_INTERNAL 0x0E //Internal buffer overflow +#define PN532_STATUS_INVALID_PARAM 0x10 //Invalid parameter (range, format, ) +#define PN532_STATUS_RELEASED 0x29 //Target has been released (RF off) + +#define ___PN532_STATUS_CHECK(e,s) ((e&0x3F)==s) +#define PN532_STATUS_TO_ERR( e ) (___PN532_STATUS_CHECK((e&0x3F),0)?OK: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_TIMEOUT))?ERR_TIMEOUT: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_CRC))?ERR_CRC: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_PARITY))?ERR_PARITY: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_BITCOUNT))?ERR_PROTOCOL: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_FRAMING))?ERR_PROTOCOL: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_NFCIP1_ACTIVE))?ERR_PROTOCOL: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_RF))?ERR_PROTOCOL: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_ANTICOLL))?ERR_COLLISION: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_BUFFER_TOO_SMALL))?ERR_BUFFER_TOO_SMALL: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_BUFFER_OVERFLOW))?ERR_CONTROLLER: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_OVERHEAT))?ERR_CONTROLLER: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_INTERNAL))?ERR_CONTROLLER: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_INVALID_PARAM))?ERR_PARAMS: \ + (___PN532_STATUS_CHECK(e,PN532_STATUS_RELEASED))?ERR_FIELD: \ + ERR_UNKNOWN \ + ) + +#ifdef __cplusplus +} +#endif + +#endif /* PN532_STATUS_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/protocols.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,51 @@ +/* + protocols.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef PROTOCOLS_H_ +#define PROTOCOLS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum __RF_PROTOCOL +{ + __RF_PROTOCOL_UNKNOWN = 0, + //Reader + RF_PROTOCOL_ISO_14443_A_READER, + RF_PROTOCOL_ISO_14443_B_READER, + RF_PROTOCOL_INNOVATRON_READER, + RF_PROTOCOL_ISO_15693_READER, + RF_PROTOCOL_FELICA_READER, + //... add other protocols here + RF_PROTOCOL_ISO_14443_A_TARGET, + RF_PROTOCOL_ISO_14443_B_TARGET, + RF_PROTOCOL_INNOVATRON_TARGET, + RF_PROTOCOL_ISO_15693_TARGET, + RF_PROTOCOL_FELICA_TARGET, + RF_PROTOCOL_ISO_DEP_TARGET, //ISO 7816-3/4 over ISO 14443-4 link + //... add other protocols here + +} RF_PROTOCOL; + +#define RF_PROTOCOL_IS_TARGET(x) ((x)>=RF_PROTOCOL_ISO_14443_A_TARGET) +#define RF_PROTOCOL_IS_READER(x) (!RF_PROTOCOL_IS_TARGET(x)) + +typedef uint32_t RF_OPTION; +//These options can be ORed +#define RF_OPTION_NONE 0x00 +#define RF_OPTION_COMPUTE_CRC 0x01 +#define RF_OPTION_COMPUTE_PARITY 0x02 +#define RF_OPTION_CHECK_CRC 0x04 +#define RF_OPTION_CHECK_PARITY 0x08 + + +#ifdef __cplusplus +} +#endif + +#endif /* PROTOCOLS_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/drv/transceiver.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,40 @@ +/* + transceiver.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef TRANSCEIVER_H_ +#define TRANSCEIVER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" +#include "core/buffer.h" +#include "protocols.h" + +//Must be implemented + +int transceiver_init(void); +int transceiver_set_protocol(RF_PROTOCOL protocol); + +int transceiver_transceive(RF_PROTOCOL protocol, buffer* pDataOutBuf, buffer* pDataInBuf, RF_OPTION options /*= RF_OPTION_NONE*/); + +int transceiver_set_RF_field(bool on); + +int transceiver_target_anticollision(buffer* pUID, /*TODO: buffer* pParams [SAK/etc], */ int timeout); + +int transceiver_target_halt(void); + +int transceiver_reader_anticollision(buffer* pUID, buffer* pParams, int timeout); + +int transceiver_free(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TRANSCEIVER_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/event/transaction_event.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,43 @@ +/* + transaction_event.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef TRANSACTION_EVENT_H_ +#define TRANSACTION_EVENT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" + +typedef enum __transaction_event +{ + TRANSACTION_STARTED, //< Transaction with reader/tag started (anticollision successful) + TRANSACTION_SUCCESSFUL, //< Transaction with reader/tag successful + TRANSACTION_FAILED //< Transaction with reader/tag failed +} transaction_event; + +typedef enum __transaction_type +{ + TRANSACTION_READER, //< Transaction in reader mode (with a tag) + TRANSACTION_TARGET, //< Transaction in target mode (with a reader) +} transaction_type; + +typedef void (*transaction_event_callback)(transaction_event event, transaction_type type, void* param); + +void transaction_event_init(void); + +void transaction_event_register_callback(transaction_event_callback cb, void* param); + +void transaction_event_fire(transaction_event event, transaction_type type); + +#ifdef __cplusplus +} +#endif + +#endif /* TRANSACTION_EVENT_H_ */
--- a/PN532/munfc/ndef/appnearme_ndef.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - appnearme_ndef.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef APPNEARME_NDEF_H_ -#define APPNEARME_NDEF_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" -#include "core/buffer.h" - -#include "appnearme_ndef_tlv.h" - -#define APPNEARME_HASH_SIZE 16 - -typedef void (*appnearme_ndef_callback)(tlv_list* payload, void* param); - -int appnearme_ndef_init(char app_hash[APPNEARME_HASH_SIZE], uint32_t version); - -void appnearme_ndef_register_encode_callback(appnearme_ndef_callback cb, void* param); - -void appnearme_ndef_register_decode_callback(appnearme_ndef_callback cb, void* param); - -int appnearme_ndef_encode_message(buffer* pMem); - -int appnearme_ndef_decode_message(buffer* pMem); - -#ifdef __cplusplus -} -#endif - -#endif /* APPNEARME_NDEF_H_ */
--- a/PN532/munfc/ndef/appnearme_ndef_tlv.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - appnearme_ndef_tlv.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -#ifndef APPNEARME_NDEF_TLV_H_ -#define APPNEARME_NDEF_TLV_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" -#include "core/buffer.h" - -typedef enum __tlv_type -{ - UINT8, - UINT32, - UINT8_ARRAY, - STRING, - NONE, //End of packet - UNKNOWN -} tlv_type; - -typedef struct __tlv_list -{ - buffer* buf; - size_t pos; - //bool writer_nreader; -} tlv_list; - -void appnearme_ndef_tlv_byref(tlv_list* pList, buffer* pBuf/*, bool writer_nreader*/); - -tlv_type appnearme_ndef_tlv_next_type(tlv_list* pList); - -uint8_t appnearme_ndef_tlv_get_uint8(tlv_list* pList); - -uint32_t appnearme_ndef_tlv_get_uint32(tlv_list* pList); - -size_t appnearme_ndef_tlv_get_array_length(tlv_list* pList); - -uint8_t* appnearme_ndef_tlv_get_array(tlv_list* pList); - -size_t appnearme_ndef_tlv_get_string_length(tlv_list* pList); - -char* appnearme_ndef_tlv_get_string(tlv_list* pList); - -int appnearme_ndef_tlv_put_uint8(tlv_list* pList, uint8_t b); //-1 if no space left - -int appnearme_ndef_tlv_put_uint32(tlv_list* pList, uint32_t b); - -int appnearme_ndef_tlv_put_array(tlv_list* pList, uint8_t* data, size_t len); - -int appnearme_ndef_tlv_put_string(tlv_list* pList, char* str); - -#ifdef __cplusplus -} -#endif - -#endif /* APPNEARME_NDEF_TLV_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/ndef/appnearme_ndef_util.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,29 @@ +/* + appnearme_ndef_util.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef APPNEARME_NDEF_UTIL_H_ +#define APPNEARME_NDEF_UTIL_H_ + +#include "core/fwk.h" + +//MSB first +#define WRITE_UINT32_NDEF( addr, val ) do{ *(((uint8_t*)(addr)) + 0) = (val >> 24 ) & 0xFF; \ + *(((uint8_t*)(addr)) + 1) = (val >> 16 ) & 0xFF; \ + *(((uint8_t*)(addr)) + 2) = (val >> 8 ) & 0xFF; \ + *(((uint8_t*)(addr)) + 3) = (val >> 0 ) & 0xFF; } while(0) +#define WRITE_UINT16_NDEF( addr, val ) do{ *(((uint8_t*)(addr)) + 0) = (val >> 8 ) & 0xFF; \ + *(((uint8_t*)(addr)) + 1) = (val >> 0 ) & 0xFF; } while(0) + +//MSB first +#define READ_UINT32_NDEF( addr, val ) do{ val = (*(((uint8_t*)(addr)) + 0) << 24 ) \ + | (*(((uint8_t*)(addr)) + 1) << 16 ) \ + | (*(((uint8_t*)(addr)) + 2) << 8 ) \ + | (*(((uint8_t*)(addr)) + 3) << 0 ); } while(0) +#define READ_UINT16_NDEF( addr, val ) do{ val = (*(((uint8_t*)(addr)) + 0) << 8 ) \ + | (*(((uint8_t*)(addr)) + 1) << 0 ); } while(0) + +#endif /* APPNEARME_NDEF_UTIL_H_ */
--- a/PN532/munfc/nfc_config.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* - nfc_config.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef NFC_CONFIG_H_ -#define NFC_CONFIG_H_ - -#define PN512 1 -#define PN532 2 - -#define DEBUG_DISABLED 0 -#define TARGET_HW_ANTICOLLISION 1 -#define NFC_CONTROLLER PN532 //In Makefile -//#define APPNEARME_HASH "00000001aZSe2vF5" -//#define APPNEARME_VERSION 0x01000000 - -#endif /* NFC_CONFIG_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/platform/pn512_platform.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,53 @@ +/* + pn512_platform.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef PN512_PLATFORM_H_ +#define PN512_PLATFORM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" + +#include "drv/pn512/pn512.h" + +/* + * Initialize SPI + */ +int pn512_spi_init(void); + +/* + * Init + */ +void pn512_io_init(void); + +/* + * Get the IRQ pin's state + */ +bool pn512_irq_pin_get(void); + +/* + * Set the CS pin to 0 (active low) + */ +void pn512_cs_set(void); + +/* + * Set the CS pin to 1 (active high) + */ +void pn512_cs_clear(void); + +/* + * You MUST call pn512_irq() on each raising front of IRQ pin + */ + +#ifdef __cplusplus +} +#endif + +#endif /* PN512_PLATFORM_H_ */
--- a/PN532/munfc/platform/pn532_platform.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - pn532_platform.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef PN532_PLATFORM_H_ -#define PN532_PLATFORM_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" - -#include "drv/pn532/pn532.h" - -/* - * Initialize SPI - */ -int pn532_spi_init(void); - -/* - * Init - */ -void pn532_io_init(void); - -/* - * Get the IRQ pin's state - */ -bool pn532_irq_pin_get(void); - -/* - * Set the CS pin to 0 (active low) - */ -void pn532_cs_set(void); - -/* - * Set the CS pin to 1 (active high) - */ -void pn532_cs_clear(void); - -/* - * You MUST call pn532_irq() on each falling front of IRQ pin - */ - -#ifdef __cplusplus -} -#endif - -#endif /* PN532_PLATFORM_H_ */
--- a/PN532/munfc/platform/rtos.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - rtos.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef RTOS_H_ -#define RTOS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" - -struct rtos_semaphore; //To be defined by impl -typedef struct rtos_semaphore rtos_semaphore_t; - -rtos_semaphore_t* rtos_semaphore_new(void); //Should return NULL if fails - -int rtos_semaphore_produce(rtos_semaphore_t* pSem); -int rtos_semaphore_consume(rtos_semaphore_t* pSem, int timeout); - -#ifdef __cplusplus -} -#endif - -#endif /* RTOS_H_ */
--- a/PN532/munfc/platform/spi.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - spi.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - -#ifndef SPI_H_ -#define SPI_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" - -//These functions must be implemented for each platform - -/* - * After skipping outSkip bytes, write outLen bytes - * After skipping inSkip bytes, read inLen bytes - * This will generate MAX(outSkip + outLen, inSkip + inLen) transfers on the SPI bus - */ -int spi_transfer( uint8_t* outBuf, size_t outLen, size_t outSkip, uint8_t* inBuf, size_t inLen, size_t inSkip ); - -/* - * Write outLen bytes - */ -int spi_write( uint8_t* outBuf, size_t outLen ); - -/* - * Read inLen bytes - */ -int spi_read( uint8_t* inBuf, size_t inLen ); - -/* - * Skip len bytes - */ -int spi_skip( size_t len ); - -#ifdef __cplusplus -} -#endif - -#endif /* SPI_H_ */
--- a/PN532/munfc/target/event.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - event.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef EVENT_H_ -#define EVENT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" - -typedef enum __target_event -{ - TRANSACTION_STARTED, //< Transaction with reader started (anticollision successful) - TRANSACTION_SUCCESSFUL, //< Transaction with reader successful - TRANSACTION_FAILED //< Transaction with reader failed -} target_event; - -typedef void (*target_event_callback)(target_event event, void* param); - -void target_event_init(void); - -void target_register_event_callback(target_event_callback cb, void* param); - -void target_fire_event(target_event event); - -#ifdef __cplusplus -} -#endif - -#endif /* EVENT_H_ */
--- a/PN532/munfc/target/nfctype2.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - nfctype2.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef NFCTYPE2_H_ -#define NFCTYPE2_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" - -//Emulates an NFC Forum TYPE 2 Tag - -int target_nfctype2_start(void); -int target_nfctype2_process(void); - -#ifdef __cplusplus -} -#endif - -#endif /* NFCTYPE2_H_ */
--- a/PN532/munfc/target/nfctype4.h Wed Aug 29 11:59:09 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - nfctype4.h - Copyright (c) Donatien Garnier 2012 - donatien.garnier@appnearme.com - http://www.appnearme.com/ -*/ - - -#ifndef NFCTYPE4_H_ -#define NFCTYPE4_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "core/fwk.h" - -//Emulates an NFC Forum TYPE 4 Tag - supported by PN532 only - -int target_nfctype4_start(void); -int target_nfctype4_process(void); - -#ifdef __cplusplus -} -#endif - -#endif /* NFCTYPE4_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/target/target_iso14443a.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,24 @@ +/* + target_iso14443a.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + +#ifndef TARGET_ISO14443A_H_ +#define TARGET_ISO14443A_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" + +int target_iso14443a_start(void); +int target_iso14443a_anticollision(buffer* pUID, int timeout); + +#ifdef __cplusplus +} +#endif + +#endif /* TARGET_ISO14443A_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/target/target_nfctype2.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,27 @@ +/* + target_nfctype2.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef TARGET_NFCTYPE2_H_ +#define TARGET_NFCTYPE2_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" + +//Emulates an NFC Forum TYPE 2 Tag + +int target_nfctype2_start(void); +int target_nfctype2_process(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TARGET_NFCTYPE2_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PN532/munfc/target/target_nfctype4.h Wed Nov 07 18:18:52 2012 +0000 @@ -0,0 +1,27 @@ +/* + target_nfctype4.h + Copyright (c) Donatien Garnier 2012 + donatien.garnier@appnearme.com + http://www.appnearme.com/ +*/ + + +#ifndef TARGET_NFCTYPE4_H_ +#define TARGET_NFCTYPE4_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/fwk.h" + +//Emulates an NFC Forum TYPE 4 Tag - supported by PN532 only + +int target_nfctype4_start(void); +int target_nfctype4_process(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TARGET_NFCTYPE4_H_ */