Henry Lovett / Mbed 2 deprecated MifareRFIDReaderWriter

Dependencies:   mbed

Committer:
seblovett
Date:
Wed Jun 26 19:09:58 2013 +0000
Revision:
0:340078fc5139
Child:
1:c5be8c1c9e10
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 ARM Limited
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 /*
seblovett 0:340078fc5139 24 This is a specific and quick implementation for the Mifare MicroRWD modules.
seblovett 0:340078fc5139 25 The class configures the reader for Mifare operation and can poll for UIDs.
seblovett 0:340078fc5139 26 */
seblovett 0:340078fc5139 27
seblovett 0:340078fc5139 28 #ifndef RWD_MIFARE_H
seblovett 0:340078fc5139 29 #define RWD_MIFARE_H
seblovett 0:340078fc5139 30
seblovett 0:340078fc5139 31 #include "mbed.h"
seblovett 0:340078fc5139 32 #include "RWDModule.h"
seblovett 0:340078fc5139 33
seblovett 0:340078fc5139 34 class RWDMifare : public RWDModule
seblovett 0:340078fc5139 35 {
seblovett 0:340078fc5139 36 public:
seblovett 0:340078fc5139 37 RWDMifare(PinName tx, PinName rx, PinName cts);
seblovett 0:340078fc5139 38 virtual ~RWDMifare();
seblovett 0:340078fc5139 39
seblovett 0:340078fc5139 40 enum RWDMifareErr {
seblovett 0:340078fc5139 41 MIFARE_OK, //No error
seblovett 0:340078fc5139 42 MIFARE_HW, //Hardware-specific error
seblovett 0:340078fc5139 43 MIFARE_NOCARD, //No card in field
seblovett 0:340078fc5139 44 MIFARE_WRONGKEY //Key is not valid (for auth command)
seblovett 0:340078fc5139 45 };
seblovett 0:340078fc5139 46 // Command definitions
seblovett 0:340078fc5139 47 #define CMD_Get_Status 0x53
seblovett 0:340078fc5139 48 //#define CMD_Get_Message_Report 0x7A//not implemented
seblovett 0:340078fc5139 49 #define CMD_Prog_EEPROM 0x50
seblovett 0:340078fc5139 50 #define CMD_Read_Block 0x52
seblovett 0:340078fc5139 51 #define CMD_Store_Key 0x4b
seblovett 0:340078fc5139 52 //Ackknowledge Codes
seblovett 0:340078fc5139 53 #define Ack_Code_EEPROM_ERR 0x01
seblovett 0:340078fc5139 54 #define Ack_Code_Card_OK 0x02
seblovett 0:340078fc5139 55 #define Ack_Code_RX_OK 0x04
seblovett 0:340078fc5139 56 #define Ack_Code_RS232_ERR 0x08
seblovett 0:340078fc5139 57 #define Ack_Code_MF_Type 0x10
seblovett 0:340078fc5139 58 #define Ack_Code_UL_Type 0x20
seblovett 0:340078fc5139 59 #define Ack_Code_MRRFC_Err 0x40
seblovett 0:340078fc5139 60
seblovett 0:340078fc5139 61 //EEPROM Addresses
seblovett 0:340078fc5139 62 #define EEP_Addr_POLL 0x00
seblovett 0:340078fc5139 63 #define EEP_Addr_POLL_4ms 0x00
seblovett 0:340078fc5139 64 #define EEP_Addr_POLL_8ms 0x10
seblovett 0:340078fc5139 65 #define EEP_Addr_POLL_16ms 0x20
seblovett 0:340078fc5139 66 #define EEP_Addr_POLL_32ms 0x30
seblovett 0:340078fc5139 67 #define EEP_Addr_POLL_65ms 0x40
seblovett 0:340078fc5139 68 #define EEP_Addr_POLL_132ms 0x50
seblovett 0:340078fc5139 69 #define EEP_Addr_POLL_262ms_d 0x60
seblovett 0:340078fc5139 70 #define EEP_Addr_POLL_524ms 0x70
seblovett 0:340078fc5139 71 #define EEP_Addr_POLL_1s 0x80
seblovett 0:340078fc5139 72 #define EEP_Addr_POLL_2s 0x90
seblovett 0:340078fc5139 73 #define EEP_Addr_POLL_4s 0xA0
seblovett 0:340078fc5139 74 #define EEP_Addr_POLL_8s 0xB0
seblovett 0:340078fc5139 75
seblovett 0:340078fc5139 76 #define EEP_Addr_Aux_Data_OP 0x01
seblovett 0:340078fc5139 77 #define EEP_Addr_Aux_Data_OP_OFF 0x00
seblovett 0:340078fc5139 78 #define EEP_Addr_Aux_Data_OP_24bit_W 0x01
seblovett 0:340078fc5139 79 #define EEP_Addr_Aux_Data_OP_32bit_W 0x02
seblovett 0:340078fc5139 80 #define EEP_Addr_Aux_Data_OP_Serial_OP0 0x03
seblovett 0:340078fc5139 81
seblovett 0:340078fc5139 82 #define EEP_Addr_Checksum 0x02
seblovett 0:340078fc5139 83
seblovett 0:340078fc5139 84 #define EEP_Addr_Mifare_ICODE 0x03
seblovett 0:340078fc5139 85 #define EEP_Addr_Mifare_ICODE_MIFARE 0x00
seblovett 0:340078fc5139 86 #define EEP_Addr_Mifare_ICODE_ICODE 0x01
seblovett 0:340078fc5139 87
seblovett 0:340078fc5139 88 #define EEP_Addr_Weigand_Parity 0x04
seblovett 0:340078fc5139 89 #define EEP_Addr_Weigand_Parity_None 0x00
seblovett 0:340078fc5139 90 #define EEP_Addr_Weigand_Parity_On 0x01
seblovett 0:340078fc5139 91
seblovett 0:340078fc5139 92 #define EEP_Addr_Aux_Block_Addr 0x05
seblovett 0:340078fc5139 93
seblovett 0:340078fc5139 94 #define EEP_Addr_Key_Number 0x06
seblovett 0:340078fc5139 95
seblovett 0:340078fc5139 96 #define EEP_Addr_Beep_Delay 0x07
seblovett 0:340078fc5139 97 #define EEP_Addr_Beep_Delay_OFF 0x00
seblovett 0:340078fc5139 98
seblovett 0:340078fc5139 99 #define EEP_Addr_OP_Source_Data 0x08
seblovett 0:340078fc5139 100 #define EEP_Addr_OP_Source_Data_UID 0x00
seblovett 0:340078fc5139 101 #define EEP_Addr_OP_Source_Data_Block 0x01
seblovett 0:340078fc5139 102
seblovett 0:340078fc5139 103 #define EEP_Addr_Aux_Out_ReDir 0x09
seblovett 0:340078fc5139 104 #define EEP_Addr_Aux_Out_ReDir_OP0 0x00
seblovett 0:340078fc5139 105 #define EEP_Addr_Aux_Out_ReDir_TX 0x01
seblovett 0:340078fc5139 106
seblovett 0:340078fc5139 107 #define EEP_Addr_OP_Fmt 0x0A
seblovett 0:340078fc5139 108 #define EEP_Addr_OP_Fmt_Hex 0x00
seblovett 0:340078fc5139 109 #define EEP_Addr_OP_Fmt_ASCII 0x01
seblovett 0:340078fc5139 110
seblovett 0:340078fc5139 111 #define EEP_Addr_Byte_Order 0x0B
seblovett 0:340078fc5139 112 #define EEP_Addr_Byte_Order_Default 0x00
seblovett 0:340078fc5139 113 #define EEP_Addr_Byte_Order_Reversed 0x01
seblovett 0:340078fc5139 114
seblovett 0:340078fc5139 115 //Initialize the reader to operate in Mifare mode
seblovett 0:340078fc5139 116 RWDMifareErr init();
seblovett 0:340078fc5139 117
seblovett 0:340078fc5139 118 //Checks if a card is present, and if so gets its UID
seblovett 0:340078fc5139 119 //Returns UID length as well (4, 7, or 10-bytes long)
seblovett 0:340078fc5139 120 RWDMifareErr getUID(uint8_t* pUID, size_t* pLen); //pUID must be at least 10-bytes long
seblovett 0:340078fc5139 121
seblovett 0:340078fc5139 122 //Gets Status
seblovett 0:340078fc5139 123 RWDMifareErr getStatus(uint8_t* Status);
seblovett 0:340078fc5139 124 RWDMifareErr Prog_EEPROM(uint8_t Address, uint8_t Value);
seblovett 0:340078fc5139 125 RWDMifareErr ReadBlock(uint8_t Addr, uint8_t KeyNumber, uint8_t Type, uint8_t* Data);
seblovett 0:340078fc5139 126 RWDMifareErr AuthAllCards();
seblovett 0:340078fc5139 127 };
seblovett 0:340078fc5139 128
seblovett 0:340078fc5139 129 #endif