AppNearMe / MicroNFCBoardAPI

Dependents:   MicroNFCBoardAPI_P2P_Client MicroNFCBoardAPI_Blink MicroNFCBoardAPI_Tag_Emulator MicroNFCBoardAPI_Tag_Reader ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers transport.h Source File

transport.h

00001 /*
00002 MicroNFCBoard mbed API
00003 
00004 Copyright (c) 2014-2015 AppNearMe Ltd
00005 
00006 Licensed under the Apache License, Version 2.0 (the "License");
00007 you may not use this file except in compliance with the License.
00008 You may obtain a copy of the License at
00009 
00010 http://www.apache.org/licenses/LICENSE-2.0
00011 
00012 Unless required by applicable law or agreed to in writing, software
00013 distributed under the License is distributed on an "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 See the License for the specific language governing permissions and
00016 limitations under the License.
00017  */
00018 
00019 #ifndef SRC_TRANSPORT_H_
00020 #define SRC_TRANSPORT_H_
00021 
00022 #include "mbed.h"
00023 #include <cstddef>
00024 
00025 class Transport
00026 {
00027 public:
00028   Transport(PinName mosi, PinName miso, PinName sck, PinName cs, PinName irq);
00029 
00030   void init();
00031 
00032   void reset();
00033 
00034   bool statusChanged();
00035 
00036   uint32_t status();
00037 
00038   void nfcPoll(bool readerWriter, bool emulator, bool p2p);
00039 
00040   void nfcOperation(bool readOp, bool writeOp);
00041 
00042   void nfcGetInfoIsoA(uint8_t* atqa, uint8_t* sak, uint8_t* uid, size_t* pUidLength);
00043 
00044   void nfcGetMessageInfo(size_t* pRecordCount);
00045 
00046   void nfcSetMessageInfo(size_t recordCount);
00047 
00048   void nfcGetRecordInfo(size_t recordNumber, uint16_t* pType, uint16_t* info, size_t infoCount);
00049 
00050   void nfcSetRecordInfo(size_t recordNumber, uint16_t type, const uint16_t* info, size_t infoCount);
00051 
00052   void nfcGetRecordData(size_t recordNumber, size_t item, size_t offset, uint8_t* data, size_t length);
00053 
00054   void nfcSetRecordData(size_t recordNumber, size_t item, size_t offset, const uint8_t* data, size_t length);
00055 
00056   void nfcPrepareMessage(bool lock, bool generate);
00057 
00058   void nfcDecodePrefix(uint8_t prefix, char* data, size_t* pDataLength);
00059 
00060   void nfcEncodePrefix(uint8_t* pPrefix, const char* data, size_t* pDataLength);
00061 
00062   void leds(bool led1, bool led2);
00063 
00064 protected:
00065   enum CommandError
00066   {
00067     OK                  = 0,
00068     ERR_LENGTH          = 1,
00069     ERR_EMPTY           = 2,
00070     ERR_UNKNOWN_COMMAND = 3,
00071     ERR_TIMEOUT         = 4,
00072     ERR_PARAMS          = 5,
00073     ERR_STATUS          = 6,
00074   };
00075 
00076   enum CommandCode
00077   {
00078     GET_STATUS = 0,
00079     INFO = 1,
00080     RESET = 2,
00081     LEDS = 3,
00082     NFC_POLL = 4,
00083     NFC_OPERATION = 5,
00084     NFC_GET_INFO = 6,
00085     NFC_GET_MESSAGE_INFO = 7,
00086     NFC_GET_RECORD_INFO = 8,
00087     NFC_GET_RECORD_DATA = 9,
00088     NFC_SET_MESSAGE_INFO = 10,
00089     NFC_SET_RECORD_INFO = 11,
00090     NFC_SET_RECORD_DATA = 12,
00091     NFC_PREPARE_MESSAGE = 13,
00092     NFC_DECODE_PREFIX = 14,
00093     NFC_ENCODE_PREFIX = 15
00094   };
00095 
00096   CommandError command(CommandCode command, uint8_t* outBuf, size_t outLength, uint8_t* inBuf, size_t inLength);
00097 
00098 private:
00099   DigitalOut _cs;
00100   SPI _spi;
00101   DigitalIn _int;
00102 };
00103 
00104 
00105 
00106 #endif /* SRC_TRANSPORT_H_ */