Skip to content

Commit

Permalink
Adding a SPI driver for pn532
Browse files Browse the repository at this point in the history
The driver seems to work well.
I tested it on Linux with i.mx233-based board using hardware SPI.
I tried to modify the build files as well, but it's probably a little messy.
I'm not sure whether it will work on other *nix OSes,
so it's probably better to limit the driver to Linux only using build system.
  • Loading branch information
evgeny-boger authored and doegox committed Feb 28, 2013
1 parent a0ebd8b commit d9fd915
Show file tree
Hide file tree
Showing 9 changed files with 1,141 additions and 8 deletions.
4 changes: 2 additions & 2 deletions libnfc/buses/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
AM_CPPFLAGS = $(all_includes) $(LIBNFC_CFLAGS)

noinst_LTLIBRARIES = libnfcbuses.la
libnfcbuses_la_SOURCES = uart.c uart.h
libnfcbuses_la_SOURCES = uart.c uart.h spi.c spi.h
libnfcbuses_la_CFLAGS = -I$(top_srcdir)/libnfc

EXTRA_DIST = uart_posix.c uart_win32.c
EXTRA_DIST = uart_posix.c uart_win32.c spi_posix.c

44 changes: 44 additions & 0 deletions libnfc/buses/spi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*-
* Public platform independent Near Field Communication (NFC) library
*
* Copyright (C) 2013 Evgeny Boger
* Copyright (C) 2009, 2010 Roel Verdult
* Copyright (C) 2009, 2010 Romuald Conty
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

/**
* @file spi.c
* @brief SPI driver wrapper
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif // HAVE_CONFIG_H

#include "spi.h"

#include <nfc/nfc.h>
#include "nfc-internal.h"

// Test if we are dealing with unix operating systems
#ifndef _WIN32
// The POSIX SPI port implementation
# include "spi_posix.c"
#else
// The windows SPI port implementation
# error "Not implemented"
#endif /* _WIN32 */
60 changes: 60 additions & 0 deletions libnfc/buses/spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*-
* Public platform independent Near Field Communication (NFC) library
*
* Copyright (C) 2013 Evgeny Boger
* Copyright (C) 2009, 2010 Roel Verdult
* Copyright (C) 2010, 2011 Romain Tarti?re
* Copyright (C) 2009, 2010, 2011 Romuald Conty
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

/**
* @file spi.h
* @brief SPI driver header
*/

#ifndef __NFC_BUS_SPI_H__
# define __NFC_BUS_SPI_H__

# include <sys/time.h>

# include <stdio.h>
# include <string.h>
# include <stdlib.h>

# include <linux/spi/spidev.h>

# include <nfc/nfc-types.h>

// Define shortcut to types to make code more readable
typedef void *spi_port;
# define INVALID_SPI_PORT (void*)(~1)
# define CLAIMED_SPI_PORT (void*)(~2)

spi_port spi_open(const char *pcPortName);
void spi_close(const spi_port sp);

void spi_set_speed(spi_port sp, const uint32_t uiPortSpeed);
void spi_set_mode(spi_port sp, const uint32_t uiPortMode);
uint32_t spi_get_speed(const spi_port sp);

int spi_receive(spi_port sp, uint8_t *pbtRx, const size_t szRx, bool lsb_first);
int spi_send(spi_port sp, const uint8_t *pbtTx, const size_t szTx, bool lsb_first);
int spi_send_receive(spi_port sp, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, bool lsb_first);

char **spi_list_ports(void);

#endif // __NFC_BUS_SPI_H__
Loading

0 comments on commit d9fd915

Please sign in to comment.