Henry Lovett / Mbed 2 deprecated MifareRFIDReaderWriter

Dependencies:   mbed

Committer:
seblovett
Date:
Wed Jun 26 19:09:58 2013 +0000
Revision:
0:340078fc5139
Got read, get uid and write to  EEPROM working!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
seblovett 0:340078fc5139 1 /*
seblovett 0:340078fc5139 2 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
seblovett 0:340078fc5139 3
seblovett 0:340078fc5139 4 Permission is hereby granted, free of charge, to any person obtaining a copy
seblovett 0:340078fc5139 5 of this software and associated documentation files (the "Software"), to deal
seblovett 0:340078fc5139 6 in the Software without restriction, including without limitation the rights
seblovett 0:340078fc5139 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
seblovett 0:340078fc5139 8 copies of the Software, and to permit persons to whom the Software is
seblovett 0:340078fc5139 9 furnished to do so, subject to the following conditions:
seblovett 0:340078fc5139 10
seblovett 0:340078fc5139 11 The above copyright notice and this permission notice shall be included in
seblovett 0:340078fc5139 12 all copies or substantial portions of the Software.
seblovett 0:340078fc5139 13
seblovett 0:340078fc5139 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
seblovett 0:340078fc5139 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
seblovett 0:340078fc5139 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
seblovett 0:340078fc5139 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
seblovett 0:340078fc5139 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
seblovett 0:340078fc5139 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
seblovett 0:340078fc5139 20 THE SOFTWARE.
seblovett 0:340078fc5139 21 */
seblovett 0:340078fc5139 22
seblovett 0:340078fc5139 23 #ifndef RWD_MODULE_H
seblovett 0:340078fc5139 24 #define RWD_MODULE_H
seblovett 0:340078fc5139 25
seblovett 0:340078fc5139 26 #include "mbed.h"
seblovett 0:340078fc5139 27
seblovett 0:340078fc5139 28 //!Generic driver for the RWD RFID Modules from IB Technology.
seblovett 0:340078fc5139 29 /*!
seblovett 0:340078fc5139 30 The RWD modules from IB Technology are RFID readers working with different frequencies and protocols but with a common instructions set and pinout.
seblovett 0:340078fc5139 31 */
seblovett 0:340078fc5139 32 class RWDModule
seblovett 0:340078fc5139 33 {
seblovett 0:340078fc5139 34 public:
seblovett 0:340078fc5139 35 //!Creates an instance of the class.
seblovett 0:340078fc5139 36 /*!
seblovett 0:340078fc5139 37 Connect module using serial port pins tx, rx and DigitalIn pin cts (clear-to-send).
seblovett 0:340078fc5139 38 */
seblovett 0:340078fc5139 39 RWDModule(PinName tx, PinName rx, PinName cts);
seblovett 0:340078fc5139 40
seblovett 0:340078fc5139 41 /*!
seblovett 0:340078fc5139 42 Destroys instance.
seblovett 0:340078fc5139 43 */
seblovett 0:340078fc5139 44 //virtual ();
seblovett 0:340078fc5139 45
seblovett 0:340078fc5139 46 //!Executes a command.
seblovett 0:340078fc5139 47 /*!
seblovett 0:340078fc5139 48 Executes the command cmd on the reader, with parameters set in params buffer of paramsLen length. The acknowledge byte sent back by the reader masked with ackOkMask must be equal to ackOk for the command to be considered a success. If so, the result is stored in buffer resp of length respLen.
seblovett 0:340078fc5139 49 This is a non-blocking function, and ready() should be called to check completion.
seblovett 0:340078fc5139 50 Please note that the buffers references must remain valid until the command has been executed.
seblovett 0:340078fc5139 51 */
seblovett 0:340078fc5139 52 void command(uint8_t cmd, const uint8_t* params, int paramsLen, uint8_t* resp, size_t respLen, uint8_t ackOk, size_t ackOkMask); //Ack Byte is not included in the resp buf
seblovett 0:340078fc5139 53
seblovett 0:340078fc5139 54 //!Ready for a command / response is available.
seblovett 0:340078fc5139 55 /*!
seblovett 0:340078fc5139 56 Returns true if the previous command has been executed and an other command is ready to be sent.
seblovett 0:340078fc5139 57 */
seblovett 0:340078fc5139 58 bool ready();
seblovett 0:340078fc5139 59
seblovett 0:340078fc5139 60 //!Get whether last command was succesful, and complete ack byte if a ptr is provided.
seblovett 0:340078fc5139 61 /*!
seblovett 0:340078fc5139 62 Returns true if the previous command was successful. If pAck is provided, the actual acknowledge byte returned by the reader is stored in that variable.
seblovett 0:340078fc5139 63 */
seblovett 0:340078fc5139 64 bool result(uint8_t* pAck = NULL);
seblovett 0:340078fc5139 65
seblovett 0:340078fc5139 66 private:
seblovett 0:340078fc5139 67 void intClearToSend(); //Called on interrupt when CTS line falls
seblovett 0:340078fc5139 68 void intTx(); //Called on interrupt when TX buffer is not full anymore (bytes sent)
seblovett 0:340078fc5139 69 void intRx(); //Called on interrrupt when RX buffer is not empty anymore (bytes received)
seblovett 0:340078fc5139 70
seblovett 0:340078fc5139 71 Serial m_serial;
seblovett 0:340078fc5139 72 InterruptIn m_cts;
seblovett 0:340078fc5139 73
seblovett 0:340078fc5139 74 uint8_t m_cmd;
seblovett 0:340078fc5139 75 uint8_t* m_paramsBuf;
seblovett 0:340078fc5139 76 uint8_t* m_respBuf;
seblovett 0:340078fc5139 77 size_t m_pos;
seblovett 0:340078fc5139 78 size_t m_paramsLen;
seblovett 0:340078fc5139 79 size_t m_respLen;
seblovett 0:340078fc5139 80
seblovett 0:340078fc5139 81 uint8_t m_ackOk;
seblovett 0:340078fc5139 82 uint8_t m_ackOkMask;
seblovett 0:340078fc5139 83
seblovett 0:340078fc5139 84 uint8_t m_ack;
seblovett 0:340078fc5139 85
seblovett 0:340078fc5139 86 enum
seblovett 0:340078fc5139 87 {
seblovett 0:340078fc5139 88 READY,
seblovett 0:340078fc5139 89 CMD_QUEUED,
seblovett 0:340078fc5139 90 SENDING_CMD,
seblovett 0:340078fc5139 91 WAITING_FOR_ACK,
seblovett 0:340078fc5139 92 RECEIVING_ACK
seblovett 0:340078fc5139 93 } m_state;
seblovett 0:340078fc5139 94
seblovett 0:340078fc5139 95 };
seblovett 0:340078fc5139 96
seblovett 0:340078fc5139 97 #endif