Przeglądaj źródła

Moved repository to actions

dherrada 5 lat temu
rodzic
commit
cda87b4dba

+ 46 - 0
.github/ISSUE_TEMPLATE.md

@@ -0,0 +1,46 @@
+Thank you for opening an issue on an Adafruit Arduino library repository.  To
+improve the speed of resolution please review the following guidelines and
+common troubleshooting steps below before creating the issue:
+
+- **Do not use GitHub issues for troubleshooting projects and issues.**  Instead use
+  the forums at http://forums.adafruit.com to ask questions and troubleshoot why
+  something isn't working as expected.  In many cases the problem is a common issue
+  that you will more quickly receive help from the forum community.  GitHub issues
+  are meant for known defects in the code.  If you don't know if there is a defect
+  in the code then start with troubleshooting on the forum first.
+
+- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
+  check all of the steps and commands to run have been followed.  Consult the
+  forum if you're unsure or have questions about steps in a guide/tutorial.
+
+- **For Arduino projects check these very common issues to ensure they don't apply**:
+
+  - For uploading sketches or communicating with the board make sure you're using
+    a **USB data cable** and **not** a **USB charge-only cable**.  It is sometimes
+    very hard to tell the difference between a data and charge cable!  Try using the
+    cable with other devices or swapping to another cable to confirm it is not
+    the problem.
+
+  - **Be sure you are supplying adequate power to the board.**  Check the specs of
+    your board and plug in an external power supply.  In many cases just
+    plugging a board into your computer is not enough to power it and other
+    peripherals.
+
+  - **Double check all soldering joints and connections.**  Flakey connections
+    cause many mysterious problems.  See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
+
+  - **Ensure you are using an official Arduino or Adafruit board.** We can't
+    guarantee a clone board will have the same functionality and work as expected
+    with this code and don't support them.
+
+If you're sure this issue is a defect in the code and checked the steps above
+please fill in the following fields to provide enough troubleshooting information.
+You may delete the guideline and text above to just leave the following details:
+
+- Arduino board:  **INSERT ARDUINO BOARD NAME/TYPE HERE**
+
+- Arduino IDE version (found in Arduino -> About Arduino menu):  **INSERT ARDUINO
+  VERSION HERE**
+
+- List the steps to reproduce the problem below (if possible attach a sketch or
+  copy the sketch code in too): **LIST REPRO STEPS BELOW**

+ 26 - 0
.github/PULL_REQUEST_TEMPLATE.md

@@ -0,0 +1,26 @@
+Thank you for creating a pull request to contribute to Adafruit's GitHub code!
+Before you open the request please review the following guidelines and tips to
+help it be more easily integrated:
+
+- **Describe the scope of your change--i.e. what the change does and what parts
+  of the code were modified.**  This will help us understand any risks of integrating
+  the code.
+
+- **Describe any known limitations with your change.**  For example if the change
+  doesn't apply to a supported platform of the library please mention it.
+
+- **Please run any tests or examples that can exercise your modified code.**  We
+  strive to not break users of the code and running tests/examples helps with this
+  process.
+
+Thank you again for contributing!  We will try to test and integrate the change
+as soon as we can, but be aware we have many GitHub repositories to manage and
+can't immediately respond to every request.  There is no need to bump or check in
+on a pull request (it will clutter the discussion of the request).
+
+Also don't be worried if the request is closed or not integrated--sometimes the
+priorities of Adafruit's GitHub code (education, ease of use) might not match the
+priorities of the pull request.  Don't fret, the open source community thrives on
+forks and GitHub makes it easy to keep your changes in a forked repo.
+
+After reviewing the guidelines above you can delete this text from the pull request.

+ 32 - 0
.github/workflows/githubci.yml

@@ -0,0 +1,32 @@
+name: Arduino Library CI
+
+on: [pull_request, push, repository_dispatch]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    
+    steps:
+    - uses: actions/setup-python@v1
+      with:
+        python-version: '3.x'
+    - uses: actions/checkout@v2
+    - uses: actions/checkout@v2
+      with:
+         repository: adafruit/ci-arduino
+         path: ci
+
+    - name: pre-install
+      run: bash ci/actions_install.sh
+
+    - name: test platforms
+      run: python3 ci/build_platform.py main_platforms
+
+    - name: clang
+      run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 
+
+    - name: doxygen
+      env:
+        GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
+        PRETTYNAME : "Adafruit MFRC630 Library"
+      run: bash ci/doxy_gen_and_deploy.sh

+ 0 - 26
.travis.yml

@@ -1,26 +0,0 @@
-language: c
-sudo: false
-cache:
-  directories:
-    - ~/arduino_ide
-    - ~/.arduino15/packages/
-git:
-  depth: false
-  quiet: true
-env:
-  global:
-     - ARDUINO_IDE_VERSION="1.8.7"
-     - PRETTYNAME="Adafruit MFRC630 Arduino Library"
-# Optional, will default to "$TRAVIS_BUILD_DIR/Doxyfile"
-#    - DOXYFILE: $TRAVIS_BUILD_DIR/Doxyfile
-
-before_install:
-   - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
-
-script:
-   - build_main_platforms
-
-# Generate and deploy documentation
-after_success:
-  - source <(curl -SLs  https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh)
-  - source <(curl -SLs  https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)

Plik diff jest za duży
+ 319 - 340
Adafruit_MFRC630.cpp


+ 285 - 286
Adafruit_MFRC630.h

@@ -1,326 +1,325 @@
-/***************************************************************************
-  This is a library for the Adafruit MFRC630 Breakout
-
-  Designed specifically to work with the Adafruit MFRC630 Breakout:
-  http://www.adafruit.com/products/xxx
-
-  These boards use I2C to communicate, 2 pins are required to interface.
-
-  Adafruit invests time and resources providing this open source code,
-  please support Adafruit andopen-source hardware by purchasing products
-  from Adafruit!
-
-  Written by Kevin Townsend for Adafruit Industries.
-  BSD license, all text above must be included in any redistribution
- ***************************************************************************/
+/*!
+ * @file Adafruit_MFRC630.h
+ */
 #ifndef __ADAFRUIT_MFRC630_H__
 #define __ADAFRUIT_MFRC630_H__
 
+#include "Adafruit_MFRC630_consts.h"
+#include "Adafruit_MFRC630_regs.h"
 #include "Arduino.h"
-#include <Wire.h>
 #include <SPI.h>
 #include <Stream.h>
-#include "Adafruit_MFRC630_regs.h"
-#include "Adafruit_MFRC630_consts.h"
+#include <Wire.h>
 
-#define MFRC630_I2C_ADDR              (0x28)
+/*!
+ * @brief MFRC630 I2C Address
+ */
+#define MFRC630_I2C_ADDR (0x28)
 
 /* Debug output level */
 /*
  * NOTE: Setting this macro above RELEASE may require more SRAM than small
  *       MCUs like the Atmel 32u4 can provide!
  */
-#define MFRC630_VERBOSITY_RELEASE     (0)   /* No debug output */
-#define MFRC630_VERBOSITY_DEBUG       (1)   /* Debug message output */
-#define MFRC630_VERBOSITY_TRACE       (2)   /* Full packet trace dumps */
-#define MFRC630_VERBOSITY             (MFRC630_VERBOSITY_RELEASE)
+#define MFRC630_VERBOSITY_RELEASE (0) //!< No debug output
+#define MFRC630_VERBOSITY_DEBUG (1)   //!< Debug message output
+#define MFRC630_VERBOSITY_TRACE (2)   //!< Full packet trace dumps
+#define MFRC630_VERBOSITY                                                      \
+  (MFRC630_VERBOSITY_RELEASE) //!< Sets verbosity variable
 
-#define MFRC630_ALWAYS_DISP_ERRORS    (1)
+#define MFRC630_ALWAYS_DISP_ERRORS (1) //!< Sets error output
 
 /* Macro for debug output */
 #if MFRC630_VERBOSITY >= MFRC630_VERBOSITY_DEBUG
-  #define DEBUG_PRINT(...)   Serial.print(__VA_ARGS__)
-  #define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__)
-  #define DEBUG_TIMESTAMP()  Serial.print(F("\tD [+")); \
-                             Serial.print(millis()); \
-                             Serial.print(F("ms] "));
+#define DEBUG_PRINT(...) Serial.print(__VA_ARGS__)
+#define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__)
+#define DEBUG_TIMESTAMP()                                                      \
+  Serial.print(F("\tD [+"));                                                   \
+  Serial.print(millis());                                                      \
+  Serial.print(F("ms] "));
 #else
-  #define DEBUG_PRINT(...)
-  #define DEBUG_PRINTLN(...)
-  #define DEBUG_TIMESTAMP(...)
+#define DEBUG_PRINT(...)     //!< Disables debug printing
+#define DEBUG_PRINTLN(...)   //!< Disables debug println
+#define DEBUG_TIMESTAMP(...) //!< Disables debug timestamp
 #endif
 
 /* Macro for trace output */
 #if MFRC630_VERBOSITY >= MFRC630_VERBOSITY_TRACE
-  #define TRACE_PRINT(...)   Serial.print(__VA_ARGS__)
-  #define TRACE_PRINTLN(...) Serial.println(__VA_ARGS__)
-  #define TRACE_TIMESTAMP()  Serial.print(F("\t. [+")); \
-                             Serial.print(millis()); \
-                             Serial.print(F("ms] "));
+#define TRACE_PRINT(...) Serial.print(__VA_ARGS__)
+#define TRACE_PRINTLN(...) Serial.println(__VA_ARGS__)
+#define TRACE_TIMESTAMP()                                                      \
+  Serial.print(F("\t. [+"));                                                   \
+  Serial.print(millis());                                                      \
+  Serial.print(F("ms] "));
 #else
-  #define TRACE_PRINT(...)
-  #define TRACE_PRINTLN(...)
-  #define TRACE_TIMESTAMP(...)
+#define TRACE_PRINT(...)     //!< Disables trace output printing
+#define TRACE_PRINTLN(...)   //!< Disables trace output println
+#define TRACE_TIMESTAMP(...) //!< Disables trace output timestamp
 #endif
 
 /* Macro for error output */
 #if MFRC630_ALWAYS_DISP_ERRORS
-  #define ERROR_PRINT(...)   Serial.print(__VA_ARGS__)
-  #define ERROR_PRINTLN(...) Serial.println(__VA_ARGS__)
-  #define ERROR_TIMESTAMP()  Serial.print(F("\t! [+")); \
-                             Serial.print(millis()); \
-                             Serial.print(F("ms] "));
+#define ERROR_PRINT(...) Serial.print(__VA_ARGS__) //!< Enables error printing
+#define ERROR_PRINTLN(...)                                                     \
+  Serial.println(__VA_ARGS__) //!< Enables error println
+#define ERROR_TIMESTAMP()                                                      \
+  Serial.print(F("\t! [+"));                                                   \
+  Serial.print(millis());                                                      \
+  Serial.print(F("ms] ")); //!< Enables error timestamp
 #else
-#define ERROR_PRINT(...)   DEBUG_PRINT(__VA_ARGS__)
+#define ERROR_PRINT(...) DEBUG_PRINT(__VA_ARGS__)
 #define ERROR_PRINTLN(...) DEBUG_PRINTLN(__VA_ARGS__)
-#define ERROR_TIMESTAMP()  DEBUG_PRINT(F("\t! [+")); \
-                           DEBUG_PRINT(millis()); \
-                           DEBUG_PRINT(F("ms] "));
+#define ERROR_TIMESTAMP()                                                      \
+  DEBUG_PRINT(F("\t! [+"));                                                    \
+  DEBUG_PRINT(millis());                                                       \
+  DEBUG_PRINT(F("ms] "));
 #endif
 
+/*!
+ * @brief Different cases used for I2C, SPI, and SERIAL data transfer
+ */
 enum mfrc630_transport {
-    MFRC630_TRANSPORT_I2C = 0,
-    MFRC630_TRANSPORT_SPI = 1,
-    MFRC630_TRANSPORT_SERIAL = 2
+  MFRC630_TRANSPORT_I2C = 0,
+  MFRC630_TRANSPORT_SPI = 1,
+  MFRC630_TRANSPORT_SERIAL = 2
 };
 
 /**
  * Driver for the Adafruit MFRC630 RFID front-end.
  */
-class Adafruit_MFRC630
-{
-  public:
-    /**
-     * Default I2C bus constructor
-     *
-     * @param i2c_addr      The I2C address to use (default value is empty)
-     * @param pdown_pin     The power down pin number (required)/
-     */
-    Adafruit_MFRC630(uint8_t i2c_addr, int8_t pdown_pin = -1);
-
-    /**
-     * Custom I2C bus constructor with user-defined I2C bus
-     *
-     * @param wireBus       The I2C bus to use
-     * @param i2c_addr      The I2C address to use (default value is empty)
-     * @param pdown_pin     The power down pin number (required)/
-     */
-    Adafruit_MFRC630(TwoWire* wireBus, uint8_t i2c_addr, int8_t pdown_pin = -1);
-
-    /**
-     * HW SPI bus constructor
-     *
-     * @param transport     The transport to use when communicating with the IC
-     * @param cs            The CS/Sel pin for HW SPI access.
-     * @param pdown_pin     The power down pin number (required)/
-     *
-     * @note This instance of the constructor requires the 'transport'
-     *       parameter to distinguish is from the default I2C version.
-     */
-    Adafruit_MFRC630(enum mfrc630_transport transport,
-        int8_t cs, int8_t pdown_pin = -1);
-
-    /**
-     * SW serial bus constructor
-     *
-     * @param serial        The Serial instance to use
-     * @param pdown_pin     The power down pin number (required)/
-     */
-    Adafruit_MFRC630(Stream* serial, int8_t pdown_pin = -1);
-
-    /**
-     * Initialises the IC and performs some simple system checks.
-     *
-     * @return True if init succeeded, otherwise false.
-     */
-    bool begin(void);
-
-    /* FIFO helpers (see section 7.5) */
-    /**
-     * Returns the number of bytes current in the FIFO buffer.
-     *
-     * @return The number of bytes in the FIFO buffer.
-     */
-    int16_t readFIFOLen(void);
-
-    /**
-     * Reads data from the FIFO buffer.
-     *
-     * @param len       The number of bytes to read
-     * @param buffer    The buffer to write data into.
-     *
-     * @return The actual number of bytes read from the FIFO buffer.
-     */
-    int16_t readFIFO(uint16_t len, uint8_t *buffer);
-
-    /**
-     * Write sdata into the FIFO buffer.
-     *
-     * @param len       The number of bytes to write.
-     * @param buffer    The data to write into the FIFO buffer.
-     *
-     * @return The actual number of bytes written.
-     */
-    int16_t writeFIFO(uint16_t len, uint8_t *buffer);
-
-    /**
-     * Clears the contents of the FIFO buffer.
-     */
-    void clearFIFO(void);
-
-    /* Command wrappers */
-    /**
-     * Sends an unparameterized command to the IC.
-     *
-     * @param command   The command register to send.
-     */
-    void writeCommand(byte command);
-
-    /**
-     * Sends a parametrized command to the IC.
-     *
-     * @param command   The command register to send.
-     * @param paramlen  The number of parameter bytes.
-     * @param params    The paramater values to send.
-     */
-    void writeCommand(byte command, uint8_t paramlen, uint8_t *params);
-
-    /* Radio config. */
-    /**
-     * Configures the radio for the specified protocol.
-     *
-     * @param cfg   The radio config setup to use.
-     *
-     * @return True if succeeded, otherwise false.
-     */
-    bool configRadio(mfrc630radiocfg cfg);
-
-    /* General helpers */
-    /**
-     * Returns the current 'comm status' of the IC's internal state machine.
-     *
-     * @return The 8-bit state ID.
-     */
-    uint8_t getComStatus(void);
-
-    /**
-     * Performs a soft-reset to put the IC into a known state.
-     */
-    void    softReset(void);
-
-    /* Generic ISO14443a commands (common to any supported card variety). */
-    /**
-     * Sends the REQA command, requesting an ISO14443A-106 tag.
-     *
-     * @return The ATQA value if a card was detected.
-     */
-    uint16_t iso14443aRequest(void);
-
-    /**
-     * Sends the WUPA wakeup command.
-     *
-     * @return The ATQA value if a card was detected.
-     */
-    uint16_t iso14443aWakeup(void);
-
-    /**
-     * Selects a detected ISO14443A card, retrieving the UID and SAK.
-     *
-     * @param uid   Pointer to the buffer where the uid should be written.
-     * @param sak   Pointer to the placeholder for the SAK value.
-     *
-     * @return True if init succeeded, otherwise false.
-     */
-    uint8_t  iso14443aSelect(uint8_t *uid, uint8_t *sak);
-
-    /* Mifare commands. */
-    /**
-     * Loads the specified authentication keys on the IC.
-     *
-     * @param key   Pointer to the buffer containing the key values.
-     */
-    void     mifareLoadKey(uint8_t *key);
-
-    /**
-     * Authenticates the selected card using the previously supplied key/
-     *
-     * @param key_type  Whether to use KEYA or KEYB for authentication.
-     * @param blocknum  The block number to authenticate.
-     * @param uid       The UID of the card to authenticate.
-     *
-     * @return True if init succeeded, otherwise false.
-     */
-    bool     mifareAuth(uint8_t key_type, uint8_t blocknum, uint8_t *uid);
-
-    /**
-     * Reads the contents of the specified (and previously authenticated)
-     * memory block.
-     *
-     * @param blocknum  The block number to read.
-     * @param buf       The buffer the data should be written into.
-     *
-     * @return The number of bytes read.
-     */
-    uint16_t mifareReadBlock(uint8_t blocknum, uint8_t *buf);
-
-    /**
-     * Writes the supplied data to the previously authenticated
-     * memory block.
-     *
-     * @param blocknum  The block number to read.
-     * @param buf       The buffer holding the data to write.
-     *
-     * @return The number of bytes written.
-     */
-    uint16_t mifareWriteBlock(uint16_t blocknum, uint8_t *buf);
-
-    /**
-     * The default key for fresh Mifare cards.
-     */
-    uint8_t  mifareKeyGlobal[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
-
-    /**
-     * The default key for NDEF formatted cards.
-     */
-    uint8_t  mifareKeyNDEF[6]   = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
-
-    /* NTAG commands */
-    /**
-     * Reads the contents of the specified page.
-     *
-     * @param pagenum   The page number to read.
-     * @param buf       The buffer the data should be written into.
-     *
-     * @return The number of bytes read.
-     */
-    uint16_t ntagReadPage(uint16_t pagenum, uint8_t *buf);
-
-    /**
-     * Writes the supplied content of the specified page.
-     *
-     * @param pagenum   The page number to write to.
-     * @param buf       The data to write to the card.
-     *
-     * @return The number of bytes written.
-     */
-    uint16_t ntagWritePage(uint16_t pagenum, uint8_t *buf);
-
-  private:
-    int8_t _pdown;
-    uint8_t _i2c_addr;
-    TwoWire* _wire;
-    Stream* _serial;
-    int8_t _cs;
-    enum mfrc630_transport _transport;
-
-    void write8(byte reg, byte value);
-    void writeBuffer(byte reg, uint16_t len, uint8_t *buffer);
-    byte read8(byte reg);
-
-    void printHex(uint8_t *buf, size_t len);
-    void printError(enum mfrc630errors err);
-
-    uint16_t iso14443aCommand(enum iso14443_cmd cmd);
+class Adafruit_MFRC630 {
+public:
+  /**
+   * Default I2C bus constructor
+   *
+   * @param i2c_addr      The I2C address to use (default value is empty)
+   * @param pdown_pin     The power down pin number (required)/
+   */
+  Adafruit_MFRC630(uint8_t i2c_addr, int8_t pdown_pin = -1);
+
+  /**
+   * Custom I2C bus constructor with user-defined I2C bus
+   *
+   * @param wireBus       The I2C bus to use
+   * @param i2c_addr      The I2C address to use (default value is empty)
+   * @param pdown_pin     The power down pin number (required)/
+   */
+  Adafruit_MFRC630(TwoWire *wireBus, uint8_t i2c_addr, int8_t pdown_pin = -1);
+
+  /**
+   * HW SPI bus constructor
+   *
+   * @param transport     The transport to use when communicating with the IC
+   * @param cs            The CS/Sel pin for HW SPI access.
+   * @param pdown_pin     The power down pin number (required)/
+   *
+   * @note This instance of the constructor requires the 'transport'
+   *       parameter to distinguish is from the default I2C version.
+   */
+  Adafruit_MFRC630(enum mfrc630_transport transport, int8_t cs,
+                   int8_t pdown_pin = -1);
+
+  /**
+   * SW serial bus constructor
+   *
+   * @param serial        The Serial instance to use
+   * @param pdown_pin     The power down pin number (required)/
+   */
+  Adafruit_MFRC630(Stream *serial, int8_t pdown_pin = -1);
+
+  /**
+   * Initialises the IC and performs some simple system checks.
+   *
+   * @return True if init succeeded, otherwise false.
+   */
+  bool begin(void);
+
+  /* FIFO helpers (see section 7.5) */
+  /**
+   * Returns the number of bytes current in the FIFO buffer.
+   *
+   * @return The number of bytes in the FIFO buffer.
+   */
+  int16_t readFIFOLen(void);
+
+  /**
+   * Reads data from the FIFO buffer.
+   *
+   * @param len       The number of bytes to read
+   * @param buffer    The buffer to write data into.
+   *
+   * @return The actual number of bytes read from the FIFO buffer.
+   */
+  int16_t readFIFO(uint16_t len, uint8_t *buffer);
+
+  /**
+   * Write sdata into the FIFO buffer.
+   *
+   * @param len       The number of bytes to write.
+   * @param buffer    The data to write into the FIFO buffer.
+   *
+   * @return The actual number of bytes written.
+   */
+  int16_t writeFIFO(uint16_t len, uint8_t *buffer);
+
+  /**
+   * Clears the contents of the FIFO buffer.
+   */
+  void clearFIFO(void);
+
+  /* Command wrappers */
+  /**
+   * Sends an unparameterized command to the IC.
+   *
+   * @param command   The command register to send.
+   */
+  void writeCommand(byte command);
+
+  /**
+   * Sends a parametrized command to the IC.
+   *
+   * @param command   The command register to send.
+   * @param paramlen  The number of parameter bytes.
+   * @param params    The paramater values to send.
+   */
+  void writeCommand(byte command, uint8_t paramlen, uint8_t *params);
+
+  /* Radio config. */
+  /**
+   * Configures the radio for the specified protocol.
+   *
+   * @param cfg   The radio config setup to use.
+   *
+   * @return True if succeeded, otherwise false.
+   */
+  bool configRadio(mfrc630radiocfg cfg);
+
+  /* General helpers */
+  /**
+   * Returns the current 'comm status' of the IC's internal state machine.
+   *
+   * @return The 8-bit state ID.
+   */
+  uint8_t getComStatus(void);
+
+  /**
+   * Performs a soft-reset to put the IC into a known state.
+   */
+  void softReset(void);
+
+  /* Generic ISO14443a commands (common to any supported card variety). */
+  /**
+   * Sends the REQA command, requesting an ISO14443A-106 tag.
+   *
+   * @return The ATQA value if a card was detected.
+   */
+  uint16_t iso14443aRequest(void);
+
+  /**
+   * Sends the WUPA wakeup command.
+   *
+   * @return The ATQA value if a card was detected.
+   */
+  uint16_t iso14443aWakeup(void);
+
+  /**
+   * Selects a detected ISO14443A card, retrieving the UID and SAK.
+   *
+   * @param uid   Pointer to the buffer where the uid should be written.
+   * @param sak   Pointer to the placeholder for the SAK value.
+   *
+   * @return True if init succeeded, otherwise false.
+   */
+  uint8_t iso14443aSelect(uint8_t *uid, uint8_t *sak);
+
+  /* Mifare commands. */
+  /**
+   * Loads the specified authentication keys on the IC.
+   *
+   * @param key   Pointer to the buffer containing the key values.
+   */
+  void mifareLoadKey(uint8_t *key);
+
+  /**
+   * Authenticates the selected card using the previously supplied key/
+   *
+   * @param key_type  Whether to use KEYA or KEYB for authentication.
+   * @param blocknum  The block number to authenticate.
+   * @param uid       The UID of the card to authenticate.
+   *
+   * @return True if init succeeded, otherwise false.
+   */
+  bool mifareAuth(uint8_t key_type, uint8_t blocknum, uint8_t *uid);
+
+  /**
+   * Reads the contents of the specified (and previously authenticated)
+   * memory block.
+   *
+   * @param blocknum  The block number to read.
+   * @param buf       The buffer the data should be written into.
+   *
+   * @return The number of bytes read.
+   */
+  uint16_t mifareReadBlock(uint8_t blocknum, uint8_t *buf);
+
+  /**
+   * Writes the supplied data to the previously authenticated
+   * memory block.
+   *
+   * @param blocknum  The block number to read.
+   * @param buf       The buffer holding the data to write.
+   *
+   * @return The number of bytes written.
+   */
+  uint16_t mifareWriteBlock(uint16_t blocknum, uint8_t *buf);
+
+  /**
+   * The default key for fresh Mifare cards.
+   */
+  uint8_t mifareKeyGlobal[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+
+  /**
+   * The default key for NDEF formatted cards.
+   */
+  uint8_t mifareKeyNDEF[6] = {0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7};
+
+  /* NTAG commands */
+  /**
+   * Reads the contents of the specified page.
+   *
+   * @param pagenum   The page number to read.
+   * @param buf       The buffer the data should be written into.
+   *
+   * @return The number of bytes read.
+   */
+  uint16_t ntagReadPage(uint16_t pagenum, uint8_t *buf);
+
+  /**
+   * Writes the supplied content of the specified page.
+   *
+   * @param pagenum   The page number to write to.
+   * @param buf       The data to write to the card.
+   *
+   * @return The number of bytes written.
+   */
+  uint16_t ntagWritePage(uint16_t pagenum, uint8_t *buf);
+
+private:
+  int8_t _pdown;
+  uint8_t _i2c_addr;
+  TwoWire *_wire;
+  Stream *_serial;
+  int8_t _cs;
+  enum mfrc630_transport _transport;
+
+  void write8(byte reg, byte value);
+  void writeBuffer(byte reg, uint16_t len, uint8_t *buffer);
+  byte read8(byte reg);
+
+  void printHex(uint8_t *buf, size_t len);
+  void printError(enum mfrc630errors err);
+
+  uint16_t iso14443aCommand(enum iso14443_cmd cmd);
 };
 
 #endif

+ 25 - 45
Adafruit_MFRC630_consts.c

@@ -13,62 +13,42 @@
   Written by Kevin Townsend for Adafruit Industries.
   BSD license, all text above must be included in any redistribution
  ***************************************************************************/
- #include "Arduino.h"
+#include "Arduino.h"
 
 /* ANTENNA CONFIGURATION SETTINGS (registers 0x28..0x39) */
 /* -------------------------------------------------------- */
 /* ISO/IEC14443-A 106 */
-uint8_t antcfg_iso14443a_106[18] =
-{
-  0x8E, 0x12, 0x39, 0x0A, 0x18, 0x18, 0x0F, 0x21, 0x00,
-  0xC0, 0x12, 0xCF, 0x00, 0x04, 0x90, 0x5C, 0x12, 0x0A
-};
+uint8_t antcfg_iso14443a_106[18] = {0x8E, 0x12, 0x39, 0x0A, 0x18, 0x18,
+                                    0x0F, 0x21, 0x00, 0xC0, 0x12, 0xCF,
+                                    0x00, 0x04, 0x90, 0x5C, 0x12, 0x0A};
 /* ISO/IEC14443-A 212 */
-uint8_t antcfg_iso14443a_212[18] =
-{
-  0x8E, 0xD2, 0x11, 0x0A, 0x18, 0x18, 0x0F, 0x10, 0x00,
-  0xC0, 0x12, 0xCF, 0x00, 0x05, 0x90, 0x3C, 0x12, 0x0B
-};
+uint8_t antcfg_iso14443a_212[18] = {0x8E, 0xD2, 0x11, 0x0A, 0x18, 0x18,
+                                    0x0F, 0x10, 0x00, 0xC0, 0x12, 0xCF,
+                                    0x00, 0x05, 0x90, 0x3C, 0x12, 0x0B};
 /* ISO/IEC14443-A 424 */
-uint8_t antcfg_iso14443a_424[18] =
-{
-  0x8F, 0xDE, 0x11, 0x0F, 0x18, 0x18, 0x0F, 0x07, 0x00,
-  0xC0, 0x12, 0xCF, 0x00, 0x06, 0x90, 0x2B, 0x12, 0x0B
-};
+uint8_t antcfg_iso14443a_424[18] = {0x8F, 0xDE, 0x11, 0x0F, 0x18, 0x18,
+                                    0x0F, 0x07, 0x00, 0xC0, 0x12, 0xCF,
+                                    0x00, 0x06, 0x90, 0x2B, 0x12, 0x0B};
 /* ISO/IEC14443-A 848 */
-uint8_t antcfg_iso14443a_848[18] =
-{
-  0x8F, 0xDB, 0x21, 0x0F, 0x18, 0x18, 0x0F, 0x02, 0x00,
-  0xC0, 0x12, 0xCF, 0x00, 0x07, 0x90, 0x3A, 0x12, 0x0B
-};
+uint8_t antcfg_iso14443a_848[18] = {0x8F, 0xDB, 0x21, 0x0F, 0x18, 0x18,
+                                    0x0F, 0x02, 0x00, 0xC0, 0x12, 0xCF,
+                                    0x00, 0x07, 0x90, 0x3A, 0x12, 0x0B};
 
 /* PROTOCOL CONFIGURATION SETTINGS */
 /* -------------------------------------------------------- */
 /* ISO/IEC14443-A 106/ MIFARE */
-uint8_t protcfg_iso14443a_106[24] =
-{
-  0x20, 0x00, 0x04, 0x50, 0x40, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02, 0x00,
-  0x00, 0x01, 0x00, 0x08, 0x80, 0xB2
-};
+uint8_t protcfg_iso14443a_106[24] = {
+    0x20, 0x00, 0x04, 0x50, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x01, 0x00, 0x08, 0x80, 0xB2};
 /* ISO/IEC14443-A 212/ MIFARE */
-uint8_t protcfg_iso14443a_212[24] =
-{
-  0x20, 0x00, 0x05, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x22, 0x00,
-  0x00, 0x00, 0x00, 0x0D, 0x80, 0xB2
-};
+uint8_t protcfg_iso14443a_212[24] = {
+    0x20, 0x00, 0x05, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x50, 0x22, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x80, 0xB2};
 /* ISO/IEC14443-A 424/ MIFARE */
-uint8_t protcfg_iso14443a_424[24] =
-{
-  0x20, 0x00, 0x06, 0x50, 0x60, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x22, 0x00,
-  0x00, 0x00, 0x00, 0x0D, 0x80, 0xB2
-};
+uint8_t protcfg_iso14443a_424[24] = {
+    0x20, 0x00, 0x06, 0x50, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x50, 0x22, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x80, 0xB2};
 /* ISO/IEC14443-A 848/ MIFARE */
-uint8_t protcfg_iso14443a_848[24] =
-{
-  0x20, 0x00, 0x07, 0x50, 0x70, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x22, 0x00,
-  0x00, 0x00, 0x00, 0x0D, 0x80, 0xB2
-};
+uint8_t protcfg_iso14443a_848[24] = {
+    0x20, 0x00, 0x07, 0x50, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x50, 0x22, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x80, 0xB2};

+ 179 - 182
Adafruit_MFRC630_regs.h

@@ -1,211 +1,208 @@
-/***************************************************************************
-  This is a library for the Adafruit MFRC630 Breakout
-
-  Designed specifically to work with the Adafruit MFRC630 Breakout:
-  http://www.adafruit.com/products/xxx
-
-  These boards use I2C to communicate, 2 pins are required to interface.
-
-  Adafruit invests time and resources providing this open source code,
-  please support Adafruit andopen-source hardware by purchasing products
-  from Adafruit!
-
-  Written by Kevin Townsend for Adafruit Industries.
-  BSD license, all text above must be included in any redistribution
- ***************************************************************************/
+/*!
+ * @file Adafruit_MFRC630_regs.h
+ */
 #ifndef __ADAFRUIT_MFRC630_REGS_H__
 #define __ADAFRUIT_MFRC630_REGS_H__
 
-enum mfrc630reg
-{
-  MFRC630_REG_COMMAND                 = 0x00,
-  MFRC630_REG_HOST_CTRL               = 0x01,
-  MFRC630_REG_FIFO_CONTROL            = 0x02,
-  MFRC630_REG_WATER_LEVEL             = 0x03,
-  MFRC630_REG_FIFO_LENGTH             = 0x04,
-  MFRC630_REG_FIFO_DATA               = 0x05,
-  MFRC630_REG_IRQ0                    = 0x06,
-  MFRC630_REG_IRQ1                    = 0x07,
-  MFRC630_REG_IRQOEN                  = 0x08,
-  MFRC630_REG_IRQ1EN                  = 0x09,
-  MFRC630_REG_ERROR                   = 0x0A,
-  MFRC630_REG_STATUS                  = 0x0B,
-  MFRC630_REG_RX_BIT_CTRL             = 0x0C,
-  MFRC630_REG_RX_COLL                 = 0x0D,
-  MFRC630_REG_T_CONTROL               = 0x0E,
-  MFRC630_REG_T0_CONTROL              = 0x0F,
-  MFRC630_REG_T0_RELOAD_HI            = 0x10,
-  MFRC630_REG_TO_RELOAD_LO            = 0x11,
-  MFRC630_REG_T0_COUNTER_VAL_HI       = 0x12,
-  MFRC630_REG_T0_COUNTER_VAL_LO       = 0x13,
-  MFRC630_REG_T1_CONTROL              = 0x14,
-  MFRC630_REG_T1_RELOAD_HI            = 0x15,
-  MFRC630_REG_T1_RELOAD_LO            = 0x16,
-  MFRC630_REG_T1_COUNTER_VAL_HI       = 0x17,
-  MFRC630_REG_T1_COUNTER_VAL_LO       = 0x18,
-  MFRC630_REG_T2_CONTROL              = 0x19,
-  MFRC630_REG_T2_RELOAD_HI            = 0x1A,
-  MFRC630_REG_T2_RELOAD_LO            = 0x1B,
-  MFRC630_REG_T2_COUNTER_VAL_HI       = 0x1C,
-  MFRC630_REG_T2_COUNTER_VAL_LO       = 0x1D,
-  MFRC630_REG_T3_CONTROL              = 0x1E,
-  MFRC630_REG_T3_RELOAD_HI            = 0x1F,
-  MFRC630_REG_T3_RELOAD_LO            = 0x20,
-  MFRC630_REG_T3_COUNTER_VAL_HI       = 0x21,
-  MFRC630_REG_T3_COUNTER_VAL_LO       = 0x22,
-  MFRC630_REG_T4_CONTROL              = 0x23,
-  MFRC630_REG_T4_RELOAD_HI            = 0x24,
-  MFRC630_REG_T4_RELOAD_LO            = 0x25,
-  MFRC630_REG_T4_COUNTER_VAL_HI       = 0x26,
-  MFRC630_REG_T4_COUNTER_VAL_LO       = 0x27,
+/*!
+ * @brief MFRC630 command set
+ */
+enum mfrc630reg {
+  MFRC630_REG_COMMAND = 0x00,
+  MFRC630_REG_HOST_CTRL = 0x01,
+  MFRC630_REG_FIFO_CONTROL = 0x02,
+  MFRC630_REG_WATER_LEVEL = 0x03,
+  MFRC630_REG_FIFO_LENGTH = 0x04,
+  MFRC630_REG_FIFO_DATA = 0x05,
+  MFRC630_REG_IRQ0 = 0x06,
+  MFRC630_REG_IRQ1 = 0x07,
+  MFRC630_REG_IRQOEN = 0x08,
+  MFRC630_REG_IRQ1EN = 0x09,
+  MFRC630_REG_ERROR = 0x0A,
+  MFRC630_REG_STATUS = 0x0B,
+  MFRC630_REG_RX_BIT_CTRL = 0x0C,
+  MFRC630_REG_RX_COLL = 0x0D,
+  MFRC630_REG_T_CONTROL = 0x0E,
+  MFRC630_REG_T0_CONTROL = 0x0F,
+  MFRC630_REG_T0_RELOAD_HI = 0x10,
+  MFRC630_REG_TO_RELOAD_LO = 0x11,
+  MFRC630_REG_T0_COUNTER_VAL_HI = 0x12,
+  MFRC630_REG_T0_COUNTER_VAL_LO = 0x13,
+  MFRC630_REG_T1_CONTROL = 0x14,
+  MFRC630_REG_T1_RELOAD_HI = 0x15,
+  MFRC630_REG_T1_RELOAD_LO = 0x16,
+  MFRC630_REG_T1_COUNTER_VAL_HI = 0x17,
+  MFRC630_REG_T1_COUNTER_VAL_LO = 0x18,
+  MFRC630_REG_T2_CONTROL = 0x19,
+  MFRC630_REG_T2_RELOAD_HI = 0x1A,
+  MFRC630_REG_T2_RELOAD_LO = 0x1B,
+  MFRC630_REG_T2_COUNTER_VAL_HI = 0x1C,
+  MFRC630_REG_T2_COUNTER_VAL_LO = 0x1D,
+  MFRC630_REG_T3_CONTROL = 0x1E,
+  MFRC630_REG_T3_RELOAD_HI = 0x1F,
+  MFRC630_REG_T3_RELOAD_LO = 0x20,
+  MFRC630_REG_T3_COUNTER_VAL_HI = 0x21,
+  MFRC630_REG_T3_COUNTER_VAL_LO = 0x22,
+  MFRC630_REG_T4_CONTROL = 0x23,
+  MFRC630_REG_T4_RELOAD_HI = 0x24,
+  MFRC630_REG_T4_RELOAD_LO = 0x25,
+  MFRC630_REG_T4_COUNTER_VAL_HI = 0x26,
+  MFRC630_REG_T4_COUNTER_VAL_LO = 0x27,
 
   /* 0x28..0x39 = Antenna Configuration */
-  MFRC630_REG_DRV_MOD                 = 0x28, /**<  (ISO/IEC14443-A 106 = 0x8E) */
-  MFRC630_REG_TX_AMP                  = 0x29, /**<  (ISO/IEC14443-A 106 = 0x12) */
-  MFRC630_REG_DRV_CON                 = 0x2A, /**<  (ISO/IEC14443-A 106 = 0x39) */
-  MFRC630_REG_TXL                     = 0x2B, /**<  (ISO/IEC14443-A 106 = 0x0A) */
-  MFRC630_REG_TX_CRC_PRESET           = 0x2C, /**<  (ISO/IEC14443-A 106 = 0x18) */
-  MFRC630_REG_RX_CRC_CON              = 0x2D, /**<  (ISO/IEC14443-A 106 = 0x18) */
-  MFRC630_REG_TX_DATA_NUM             = 0x2E, /**<  (ISO/IEC14443-A 106 = 0x0F) */
-  MFRC630_REG_TX_MOD_WIDTH            = 0x2F, /**<  (ISO/IEC14443-A 106 = 0x21) */
-  MFRC630_REG_TX_SYM_10_BURST_LEN     = 0x30, /**<  (ISO/IEC14443-A 106 = 0x00) */
-  MFRC630_REG_TX_WAIT_CTRL            = 0x31, /**<  (ISO/IEC14443-A 106 = 0xC0) */
-  MFRC630_REG_TX_WAIT_LO              = 0x32, /**<  (ISO/IEC14443-A 106 = 0x12) */
-  MFRC630_REG_FRAME_CON               = 0x33, /**<  (ISO/IEC14443-A 106 = 0xCF) */
-  MFRC630_REG_RX_SOFD                 = 0x34, /**<  (ISO/IEC14443-A 106 = 0x00) */
-  MFRC630_REG_RX_CTRL                 = 0x35, /**<  (ISO/IEC14443-A 106 = 0x04) */
-  MFRC630_REG_RX_WAIT                 = 0x36, /**<  (ISO/IEC14443-A 106 = 0x90) */
-  MFRC630_REG_RX_THRESHOLD            = 0x37, /**<  (ISO/IEC14443-A 106 = 0x5C) */
-  MFRC630_REG_RCV                     = 0x38, /**<  (ISO/IEC14443-A 106 = 0x12) */
-  MFRC630_REG_RX_ANA                  = 0x39, /**<  (ISO/IEC14443-A 106 = 0x0A) */
-
-  MFRC630_REG_RFU_LPCD                = 0x3A,
-  MFRC630_REG_SERIAL_SPEED            = 0x3B,
-  MFRC630_REG_LFO_TRIMM               = 0x3C,
-  MFRC630_REG_PLL_CTRL                = 0x3D,
-  MFRC630_REG_PLL_DIVOUT              = 0x3E,
-  MFRC630_REG_LPCD_QMIN               = 0x3F,
-  MFRC630_REG_LPCD_QMAX               = 0x40,
-  MFRC630_REG_LPCD_IMIN               = 0x41,
-  MFRC630_REG_LPCD_I_RESULT           = 0x42,
-  MFRC630_REG_LPCD_Q_RESULT           = 0x43,
-  MFRC630_REG_PADEN                   = 0x44,
-  MFRC630_REG_PADOUT                  = 0x45,
-  MFRC630_REG_PADIN                   = 0x46,
-  MFRC630_REG_SIGOUT                  = 0x47,
-  MFRC630_REG_VERSION                 = 0x7F
+  MFRC630_REG_DRV_MOD = 0x28,             /**<  (ISO/IEC14443-A 106 = 0x8E) */
+  MFRC630_REG_TX_AMP = 0x29,              /**<  (ISO/IEC14443-A 106 = 0x12) */
+  MFRC630_REG_DRV_CON = 0x2A,             /**<  (ISO/IEC14443-A 106 = 0x39) */
+  MFRC630_REG_TXL = 0x2B,                 /**<  (ISO/IEC14443-A 106 = 0x0A) */
+  MFRC630_REG_TX_CRC_PRESET = 0x2C,       /**<  (ISO/IEC14443-A 106 = 0x18) */
+  MFRC630_REG_RX_CRC_CON = 0x2D,          /**<  (ISO/IEC14443-A 106 = 0x18) */
+  MFRC630_REG_TX_DATA_NUM = 0x2E,         /**<  (ISO/IEC14443-A 106 = 0x0F) */
+  MFRC630_REG_TX_MOD_WIDTH = 0x2F,        /**<  (ISO/IEC14443-A 106 = 0x21) */
+  MFRC630_REG_TX_SYM_10_BURST_LEN = 0x30, /**<  (ISO/IEC14443-A 106 = 0x00) */
+  MFRC630_REG_TX_WAIT_CTRL = 0x31,        /**<  (ISO/IEC14443-A 106 = 0xC0) */
+  MFRC630_REG_TX_WAIT_LO = 0x32,          /**<  (ISO/IEC14443-A 106 = 0x12) */
+  MFRC630_REG_FRAME_CON = 0x33,           /**<  (ISO/IEC14443-A 106 = 0xCF) */
+  MFRC630_REG_RX_SOFD = 0x34,             /**<  (ISO/IEC14443-A 106 = 0x00) */
+  MFRC630_REG_RX_CTRL = 0x35,             /**<  (ISO/IEC14443-A 106 = 0x04) */
+  MFRC630_REG_RX_WAIT = 0x36,             /**<  (ISO/IEC14443-A 106 = 0x90) */
+  MFRC630_REG_RX_THRESHOLD = 0x37,        /**<  (ISO/IEC14443-A 106 = 0x5C) */
+  MFRC630_REG_RCV = 0x38,                 /**<  (ISO/IEC14443-A 106 = 0x12) */
+  MFRC630_REG_RX_ANA = 0x39,              /**<  (ISO/IEC14443-A 106 = 0x0A) */
+
+  MFRC630_REG_RFU_LPCD = 0x3A,
+  MFRC630_REG_SERIAL_SPEED = 0x3B,
+  MFRC630_REG_LFO_TRIMM = 0x3C,
+  MFRC630_REG_PLL_CTRL = 0x3D,
+  MFRC630_REG_PLL_DIVOUT = 0x3E,
+  MFRC630_REG_LPCD_QMIN = 0x3F,
+  MFRC630_REG_LPCD_QMAX = 0x40,
+  MFRC630_REG_LPCD_IMIN = 0x41,
+  MFRC630_REG_LPCD_I_RESULT = 0x42,
+  MFRC630_REG_LPCD_Q_RESULT = 0x43,
+  MFRC630_REG_PADEN = 0x44,
+  MFRC630_REG_PADOUT = 0x45,
+  MFRC630_REG_PADIN = 0x46,
+  MFRC630_REG_SIGOUT = 0x47,
+  MFRC630_REG_VERSION = 0x7F
 };
 
-/* See Table 7.10.2: Command Set */
-enum mfrc630cmd
-{
-  MFRC630_CMD_IDLE                    = 0x00, /**< Cancels current command */
-  MFRC630_CMD_LPCD                    = 0x01, /**< Low power card detection */
-  MFRC630_CMD_LOADKEY                 = 0x02, /**< Reads a 6 byte MIFARE key and puts it into KEY BUFFER */
-  MFRC630_CMD_MFAUTHENT               = 0x03, /**< Performs Mifare Classic authentication */
-  MFRC630_CMD_RECEIVE                 = 0x05, /**< Activates the receive circuit */
-  MFRC630_CMD_TRANSMIT                = 0x06, /**< Transmits data from the FIFO buffer */
-  MFRC630_CMD_TRANSCEIVE              = 0x07, /**< Transmits data from the FIFO buffer and automatically activates the receive buffer when finished */
-  MFRC630_CMD_WRITEE2                 = 0x08, /**< Gets 1 byte from FIFO and writes to EEPROM */
-  MFRC630_CMD_WRITEE2PAGE             = 0x09, /**< Gets up to 64 bytes from FIFO and writes to EEPROM */
-  MFRC630_CMD_READE2                  = 0x0A, /**< Reads data from EEPROM and copies it into the FIFO buffer */
-  MFRC630_CMD_LOADREG                 = 0x0C, /**< Reads data from the internal EEPROM and initializes the MFRC630 registers. EEPROM address needs to be within EEPROM sector 2 */
-  MFRC630_CMD_LOADPROTOCOL            = 0x0D, /**< Reads data from the internal EEPROM and initializes the MFRC630 registers needed for a protocol change. */
-  MFRC630_CMD_LOADKEYE2               = 0x0E, /**< Copies a key from EEPROM into the key buffer */
-  MFRC630_CMD_STOREKEYE2              = 0x0F, /**< Stores a MIFARE key (6 bytes) into EEPROM */
-  MFRC630_CMD_READRNR                 = 0x1C, /**< Copies bytes from the random number generator into the FIFO buffer until the FIFO is full */
-  MFRC630_CMD_SOFTRESET               = 0x1F  /**< SW resets the MFRC630 */
+/*! See Table 7.10.2: Command Set */
+enum mfrc630cmd {
+  MFRC630_CMD_IDLE = 0x00, /**< Cancels current command */
+  MFRC630_CMD_LPCD = 0x01, /**< Low power card detection */
+  MFRC630_CMD_LOADKEY =
+      0x02, /**< Reads a 6 byte MIFARE key and puts it into KEY BUFFER */
+  MFRC630_CMD_MFAUTHENT = 0x03, /**< Performs Mifare Classic authentication */
+  MFRC630_CMD_RECEIVE = 0x05,   /**< Activates the receive circuit */
+  MFRC630_CMD_TRANSMIT = 0x06,  /**< Transmits data from the FIFO buffer */
+  MFRC630_CMD_TRANSCEIVE =
+      0x07, /**< Transmits data from the FIFO buffer and automatically activates
+               the receive buffer when finished */
+  MFRC630_CMD_WRITEE2 = 0x08, /**< Gets 1 byte from FIFO and writes to EEPROM */
+  MFRC630_CMD_WRITEE2PAGE =
+      0x09, /**< Gets up to 64 bytes from FIFO and writes to EEPROM */
+  MFRC630_CMD_READE2 =
+      0x0A, /**< Reads data from EEPROM and copies it into the FIFO buffer */
+  MFRC630_CMD_LOADREG =
+      0x0C, /**< Reads data from the internal EEPROM and initializes the MFRC630
+               registers. EEPROM address needs to be within EEPROM sector 2 */
+  MFRC630_CMD_LOADPROTOCOL =
+      0x0D, /**< Reads data from the internal EEPROM and initializes the MFRC630
+               registers needed for a protocol change. */
+  MFRC630_CMD_LOADKEYE2 =
+      0x0E, /**< Copies a key from EEPROM into the key buffer */
+  MFRC630_CMD_STOREKEYE2 =
+      0x0F,                   /**< Stores a MIFARE key (6 bytes) into EEPROM */
+  MFRC630_CMD_READRNR = 0x1C, /**< Copies bytes from the random number generator
+                                 into the FIFO buffer until the FIFO is full */
+  MFRC630_CMD_SOFTRESET = 0x1F /**< SW resets the MFRC630 */
 };
 
-/* ISO14443 Commands (see ISO-14443-3) */
-enum iso14443_cmd
-{
-  ISO14443_CMD_REQA               = 0x26, /**< Request command. */
-  ISO14443_CMD_WUPA               = 0x52, /**< Wakeup command. */
-  ISO14443_CAS_LEVEL_1            = 0x93, /**< Anticollision cascade level 1. */
-  ISO14443_CAS_LEVEL_2            = 0x95, /**< Anticollision cascade level 2. */
-  ISO14443_CAS_LEVEL_3            = 0x97  /**< Anticollision cascade level 3. */
+/*! ISO14443 Commands (see ISO-14443-3) */
+enum iso14443_cmd {
+  ISO14443_CMD_REQA = 0x26,    /**< Request command. */
+  ISO14443_CMD_WUPA = 0x52,    /**< Wakeup command. */
+  ISO14443_CAS_LEVEL_1 = 0x93, /**< Anticollision cascade level 1. */
+  ISO14443_CAS_LEVEL_2 = 0x95, /**< Anticollision cascade level 2. */
+  ISO14443_CAS_LEVEL_3 = 0x97  /**< Anticollision cascade level 3. */
 };
 
-/* Mifare Commands */
-enum mifare_cmd
-{
-  MIFARE_CMD_AUTH_A                   = 0x60,
-  MIFARE_CMD_AUTH_B                   = 0x61,
-  MIFARE_CMD_READ                     = 0x30,
-  MIFARE_CMD_WRITE                    = 0xA0,
-  MIFARE_CMD_TRANSFER                 = 0xB0,
-  MIFARE_CMD_DECREMENT                = 0xC0,
-  MIFARE_CMD_INCREMENT                = 0xC1,
-  MIFARE_CMD_STORE                    = 0xC2,
-  MIFARE_ULTRALIGHT_CMD_WRITE         = 0xA2
+/*! Mifare Commands */
+enum mifare_cmd {
+  MIFARE_CMD_AUTH_A = 0x60,
+  MIFARE_CMD_AUTH_B = 0x61,
+  MIFARE_CMD_READ = 0x30,
+  MIFARE_CMD_WRITE = 0xA0,
+  MIFARE_CMD_TRANSFER = 0xB0,
+  MIFARE_CMD_DECREMENT = 0xC0,
+  MIFARE_CMD_INCREMENT = 0xC1,
+  MIFARE_CMD_STORE = 0xC2,
+  MIFARE_ULTRALIGHT_CMD_WRITE = 0xA2
 };
 
-/* NTAG Commands */
-enum ntag_cmd
-{
-  NTAG_CMD_READ                       = 0x30, /**> NTAG page read. */
-  NTAG_CMD_WRITE                      = 0xA2, /**< NTAG-specfiic 4 byte write. */
-  NTAG_CMD_COMP_WRITE                 = 0xA0  /**< Mifare Classic 16-byte compat. write. */
+/*! NTAG Commands */
+enum ntag_cmd {
+  NTAG_CMD_READ = 0x30,      /**> NTAG page read. */
+  NTAG_CMD_WRITE = 0xA2,     /**< NTAG-specfiic 4 byte write. */
+  NTAG_CMD_COMP_WRITE = 0xA0 /**< Mifare Classic 16-byte compat. write. */
 };
 
-/* 'ComState' values for for the MFRC630_REG_STATUS register (0x0B) */
-enum mfrc630comstat
-{
-  MFRC630_COMSTAT_IDLE                = 0b000, /**< IDLE */
-  MFRC630_COMSTAT_TXWAIT              = 0b001, /**< TX Wait */
-  MFRC630_COMSTAT_TRANSMITTING        = 0b011, /**< Transmitting */
-  MFRC630_COMSTAT_RXWAIT              = 0b101, /**< RX Wait */
-  MFRC630_COMSTAT_WAITFORDATA         = 0b110, /**< Waiting for DATA */
-  MFRC630_COMSTAT_RECEIVING           = 0b111  /**< Receiving */
+/*! 'ComState' values for for the MFRC630_REG_STATUS register (0x0B) */
+enum mfrc630comstat {
+  MFRC630_COMSTAT_IDLE = 0b000,         /**< IDLE */
+  MFRC630_COMSTAT_TXWAIT = 0b001,       /**< TX Wait */
+  MFRC630_COMSTAT_TRANSMITTING = 0b011, /**< Transmitting */
+  MFRC630_COMSTAT_RXWAIT = 0b101,       /**< RX Wait */
+  MFRC630_COMSTAT_WAITFORDATA = 0b110,  /**< Waiting for DATA */
+  MFRC630_COMSTAT_RECEIVING = 0b111     /**< Receiving */
 };
 
-/* Radio config modes */
-enum mfrc630radiocfg
-{
-  MFRC630_RADIOCFG_ISO1443A_106       = 1,     /**< ISO1443A 106 Mode */
+/*! Radio config modes */
+enum mfrc630radiocfg {
+  MFRC630_RADIOCFG_ISO1443A_106 = 1, /**< ISO1443A 106 Mode */
   MFRC630_LAST
 };
 
-enum mfrc630errors
-{
-  MFRC630_ERROR_EEPROM    = (1 << 7), /**< EEPROM error. */
-  MFRC630_ERROR_FIFOWR    = (1 << 6), /**< FIFO write error. */
-  MFRC630_ERROR_FIFOOVL   = (1 << 5), /**< FIFO already full! */
-  MFRC630_ERROR_MINFRAME  = (1 << 4), /**< Not enough data in frame. */
-  MFRC630_ERROR_NODATA    = (1 << 3), /**< FIFO empty! */
-  MFRC630_ERROR_COLLDET   = (1 << 2), /**< Collision detection, see RxColl. */
-  MFRC630_ERROR_PROT      = (1 << 1), /**< Protocol error. */
-  MFRC630_ERROR_INTEG     = (1 << 0)  /**< Data integrity error. */
+/*! MFRC360 errors */
+enum mfrc630errors {
+  MFRC630_ERROR_EEPROM = (1 << 7),   /**< EEPROM error. */
+  MFRC630_ERROR_FIFOWR = (1 << 6),   /**< FIFO write error. */
+  MFRC630_ERROR_FIFOOVL = (1 << 5),  /**< FIFO already full! */
+  MFRC630_ERROR_MINFRAME = (1 << 4), /**< Not enough data in frame. */
+  MFRC630_ERROR_NODATA = (1 << 3),   /**< FIFO empty! */
+  MFRC630_ERROR_COLLDET = (1 << 2),  /**< Collision detection, see RxColl. */
+  MFRC630_ERROR_PROT = (1 << 1),     /**< Protocol error. */
+  MFRC630_ERROR_INTEG = (1 << 0)     /**< Data integrity error. */
 };
 
-enum mfrc630irq0
-{
-  MFRC630IRQ0_SET         = (1 << 7), /**< Sets/Clears interrupt. */
-  MFRC630IRQ0_HIALERTIRQ  = (1 << 6), /**< FIFO has reached top level. */
-  MFRC630IRQ0_LOALERTIRQ  = (1 << 5), /**< FIFO has reached bottom level. */
-  MFRC630IRQ0_IDLEIRQ     = (1 << 4), /**< Command terminated by itself. */
-  MFRC630IRQ0_TXIRQ       = (1 << 3), /**< Data transmission complete */
-  MFRC630IRQ0_RXIRQ       = (1 << 2), /**< Receiver detected end of stream */
-  MFRC630IRQ0_ERRIRQ      = (1 << 1), /**< FifoWrErr, FiFoOvl, ProtErr, NoDataErr, IntegErr. */
-  MFRC630IRQ0_RXSOF       = (1 << 0)  /**< RX start of frame detected. */
+/*! MFRC630 interrupt requests 0 */
+enum mfrc630irq0 {
+  MFRC630IRQ0_SET = (1 << 7),        /**< Sets/Clears interrupt. */
+  MFRC630IRQ0_HIALERTIRQ = (1 << 6), /**< FIFO has reached top level. */
+  MFRC630IRQ0_LOALERTIRQ = (1 << 5), /**< FIFO has reached bottom level. */
+  MFRC630IRQ0_IDLEIRQ = (1 << 4),    /**< Command terminated by itself. */
+  MFRC630IRQ0_TXIRQ = (1 << 3),      /**< Data transmission complete */
+  MFRC630IRQ0_RXIRQ = (1 << 2),      /**< Receiver detected end of stream */
+  MFRC630IRQ0_ERRIRQ =
+      (1 << 1), /**< FifoWrErr, FiFoOvl, ProtErr, NoDataErr, IntegErr. */
+  MFRC630IRQ0_RXSOF = (1 << 0) /**< RX start of frame detected. */
 };
 
-enum mfrc630irq1
-{
-  MFRC630IRQ1_SET         = (1 << 7), /**< Sets/Clears interrupt. */
-  MFRC630IRQ1_GLOBALIRQ   = (1 << 6), /**< Set if an enabled IRQ occured */
-  MFRC630IRQ1_LPCDIRQ     = (1 << 5), /**< Card detected in low power mode */
-  MFRC630IRQ1_TIMER4IRQ   = (1 << 4), /**< Timer 4 underflow */
-  MFRC630IRQ1_TIMER3IRQ   = (1 << 3), /**< Timer 3 underflow */
-  MFRC630IRQ1_TIMER2IRQ   = (1 << 2), /**< Timer 2 underflow */
-  MFRC630IRQ1_TIMER1IRQ   = (1 << 1), /**< Timer 1 underflow */
-  MFRC630IRQ1_TIMER0IRQ   = (1 << 0), /**< Timer 0 underflow */
+/*! MFRC630 interrupt requests 1 */
+enum mfrc630irq1 {
+  MFRC630IRQ1_SET = (1 << 7),       /**< Sets/Clears interrupt. */
+  MFRC630IRQ1_GLOBALIRQ = (1 << 6), /**< Set if an enabled IRQ occured */
+  MFRC630IRQ1_LPCDIRQ = (1 << 5),   /**< Card detected in low power mode */
+  MFRC630IRQ1_TIMER4IRQ = (1 << 4), /**< Timer 4 underflow */
+  MFRC630IRQ1_TIMER3IRQ = (1 << 3), /**< Timer 3 underflow */
+  MFRC630IRQ1_TIMER2IRQ = (1 << 2), /**< Timer 2 underflow */
+  MFRC630IRQ1_TIMER1IRQ = (1 << 1), /**< Timer 1 underflow */
+  MFRC630IRQ1_TIMER0IRQ = (1 << 0), /**< Timer 0 underflow */
 };
 
-enum mfrc630status
-{
-  MFRC630STATUS_CRYPTO1ON = (1 << 5)  /**< Mifare Classic Crypto engine on */
+/*! MFRC630 crypto engine status */
+enum mfrc630status {
+  MFRC630STATUS_CRYPTO1ON = (1 << 5) /**< Mifare Classic Crypto engine on */
 };
 
 #endif

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=Adafruit MFRC630 RFID
-version=1.0.1
+version=1.1.0
 author=Adafruit
 maintainer=Adafruit <info@adafruit.com>
 sentence=Arduino library for I2C and SPI access to the MFRC630 RFID/Near Field Communication chip

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików