From 1d1affdd2ba3eec4e2038d354d6f220363ed5e99 Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Wed, 31 Aug 2016 13:46:27 +0200 Subject: [PATCH] fix mfrc522 --- drivers/contactless/mfrc522.c | 1 + drivers/contactless/pn532.c | 2 +- include/nuttx/contactless/mfrc522.h | 116 ++++++++++++++++++++++++++++ include/nuttx/drivers/contactless.h | 2 +- 4 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 include/nuttx/contactless/mfrc522.h diff --git a/drivers/contactless/mfrc522.c b/drivers/contactless/mfrc522.c index b0c1a786df..01a7c30984 100644 --- a/drivers/contactless/mfrc522.c +++ b/drivers/contactless/mfrc522.c @@ -51,6 +51,7 @@ #include #include +#include #include "mfrc522.h" diff --git a/drivers/contactless/pn532.c b/drivers/contactless/pn532.c index 0f17f4c315..c40ba71fca 100644 --- a/drivers/contactless/pn532.c +++ b/drivers/contactless/pn532.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include "pn532.h" diff --git a/include/nuttx/contactless/mfrc522.h b/include/nuttx/contactless/mfrc522.h new file mode 100644 index 0000000000..6fe3d6847c --- /dev/null +++ b/include/nuttx/contactless/mfrc522.h @@ -0,0 +1,116 @@ +/**************************************************************************** + * include/wireless/mfrc522.h + * + * Copyright(C) 2016 Uniquix Ltda. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_WIRELESS_MFRC522_H +#define __INCLUDE_NUTTX_WIRELESS_MFRC522_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +#define MFRC522_MIFARE_ISO14443A (0x00) + +/* IOCTL Commands ***********************************************************/ + +#define MFRC522IOC_GET_PICC_UID _CLIOC_USER(0x0001) +#define MFRC522IOC_GET_STATE _CLIOC_USER(0x0002) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +enum mfrc522_state_e +{ + MFRC522_STATE_NOT_INIT, + MFRC522_STATE_IDLE, + MFRC522_STATE_CMD_SENT, + MFRC522_STATE_DATA_READY, +}; + +struct mfrc522_dev_s; + +struct picc_uid_s +{ + uint8_t size; /* Number of bytes in the UID. 4, 7 or 10 */ + uint8_t uid_data[10]; + uint8_t sak; /* The SAK (Select Acknowledge) return by the PICC */ +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: mfrc522_register + * + * Description: + * Register the MFRC522 character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/rfid0" + * spi - An instance of the SPI interface to use to communicate with MFRC522 + * config - Device persistent board data + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int mfrc522_register(FAR const char *devpath, FAR struct spi_dev_s *spi); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_WIRELESS_MFRC522_H */ diff --git a/include/nuttx/drivers/contactless.h b/include/nuttx/drivers/contactless.h index b5beaf56b1..8a887480e1 100644 --- a/include/nuttx/drivers/contactless.h +++ b/include/nuttx/drivers/contactless.h @@ -58,7 +58,7 @@ * commands, beginning with this value: */ -#define CLIOC_USER 0x0001 /* Lowest, unused CL ioctl command */ +#define CLIOC_USER 0x0003 /* Lowest, unused CL ioctl command */ #define _CLIOC_USER(nr) _CLIOC(nr + CLIOC_USER)