nuttx/configs/nucleo-l073rz/src/stm32_mfrc522.c
raiden00pl a234b909bc Merged in raiden00/nuttx_l0f0 (pull request #848)
Fixes for MFRC522

drivers/contactless/mfrc522.c: in mfrc522_read uid.sak must be different from 0x04 not as before from 0x00. SAK == 0x00 is a valid PICC type

drivers/contactless/mfrc522.c: add interface to read MIFARE Ultralight data

configs/nucleo-l073rz: add mfrc522 support

Approved-by: Gregory Nutt <gnutt@nuttx.org>
2019-04-05 15:49:45 +00:00

111 lines
3.7 KiB
C

/************************************************************************************
* configs/nucleo-l073rz/src/stm32_mfrc522.c
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Mateusz Szafoni <raiden00@railab.me>
*
* 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.
*
************************************************************************************/
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/spi/spi.h>
#include <nuttx/contactless/mfrc522.h>
#include "stm32.h"
#include "stm32_spi.h"
#include "nucleo-l073rz.h"
#if defined(CONFIG_SPI) && defined(CONFIG_STM32F0L0_SPI2) && defined(CONFIG_CL_MFRC522)
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
#define MFRC522_SPI_PORTNO 2 /* On SPI2 */
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: stm32_mfrc522initialize
*
* Description:
* Initialize and register the MFRC522 RFID driver.
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/rfid0"
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
************************************************************************************/
int stm32_mfrc522initialize(FAR const char *devpath)
{
FAR struct spi_dev_s *spi;
int ret;
/* Configure MFRC522 reset */
stm32_configgpio(GPIO_MFRC522_RESET);
/* MFRC522 hardware reset on rising edge */
stm32_gpiowrite(GPIO_MFRC522_RESET, true);
/* Initialize SPI */
spi = stm32_spibus_initialize(MFRC522_SPI_PORTNO);
if (!spi)
{
return -ENODEV;
}
/* Then register the MFRC522 */
ret = mfrc522_register(devpath, spi);
if (ret < 0)
{
snerr("ERROR: Error registering MFRC522\n");
}
return ret;
}
#endif /* CONFIG_SPI && CONFIG_MFRC522 */