Make libnfc compile under Windows
Apply adapted patch from Glenn (Thanks!)
This commit is contained in:
parent
3fb4b0e0ee
commit
544030099e
5 changed files with 48 additions and 53 deletions
|
@ -1,8 +1,7 @@
|
|||
SET(LIBNFC_DRIVER_ACR122 ON CACHE BOOL "Enable ACR122 support (Depends on PC/SC)")
|
||||
SET(LIBNFC_DRIVER_PN531_USB ON CACHE BOOL "Enable PN531_USB support (Depends on libusb)")
|
||||
SET(LIBNFC_DRIVER_PN533_USB ON CACHE BOOL "Enable PN533_USB support (Depends on libusb)")
|
||||
SET(LIBNFC_DRIVER_PN53X_USB ON CACHE BOOL "Enable PN531 and PN531 USB support (Depends on libusb)")
|
||||
SET(LIBNFC_DRIVER_ARYGON ON CACHE BOOL "Enable ARYGON support (Use serial port)")
|
||||
SET(LIBNFC_DRIVER_PN532_UART OFF CACHE BOOL "Enable PN533_USB support (Use serial port)")
|
||||
SET(LIBNFC_DRIVER_PN532_UART OFF CACHE BOOL "Enable PN532 UART support (Use serial port)")
|
||||
|
||||
IF(LIBNFC_DRIVER_ACR122)
|
||||
FIND_PACKAGE(PCSC REQUIRED)
|
||||
|
@ -10,26 +9,20 @@ IF(LIBNFC_DRIVER_ACR122)
|
|||
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/acr122")
|
||||
ENDIF(LIBNFC_DRIVER_ACR122)
|
||||
|
||||
IF(LIBNFC_DRIVER_PN531_USB)
|
||||
IF(LIBNFC_DRIVER_PN53X_USB)
|
||||
FIND_PACKAGE(LIBUSB REQUIRED)
|
||||
ADD_DEFINITIONS("-DDRIVER_PN531_USB_ENABLED")
|
||||
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn531_usb" "drivers/pn53x_usb.c")
|
||||
ENDIF(LIBNFC_DRIVER_PN531_USB)
|
||||
|
||||
IF(LIBNFC_DRIVER_PN533_USB)
|
||||
FIND_PACKAGE(LIBUSB REQUIRED)
|
||||
ADD_DEFINITIONS("-DDRIVER_PN533_USB_ENABLED")
|
||||
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn533_usb" "drivers/pn53x_usb.c")
|
||||
ENDIF(LIBNFC_DRIVER_PN533_USB)
|
||||
ADD_DEFINITIONS("-DDRIVER_PN53X_USB_ENABLED")
|
||||
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn53x_usb")
|
||||
ENDIF(LIBNFC_DRIVER_PN53X_USB)
|
||||
|
||||
IF(LIBNFC_DRIVER_ARYGON)
|
||||
ADD_DEFINITIONS("-DDRIVER_ARYGON_ENABLED")
|
||||
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} drivers/arygon)
|
||||
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/arygon")
|
||||
ENDIF(LIBNFC_DRIVER_ARYGON)
|
||||
|
||||
IF(LIBNFC_DRIVER_PN532_UART)
|
||||
ADD_DEFINITIONS("-DDRIVER_PN532_UART_ENABLED")
|
||||
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} drivers/pn532_uart)
|
||||
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn532_uart")
|
||||
ENDIF(LIBNFC_DRIVER_PN532_UART)
|
||||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/drivers)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Public platform independent Near Field Communication (NFC) library
|
||||
*
|
||||
* Copyright (C) 2010, Romuald Conty
|
||||
* Copyright (C) 2011, Glenn Ergeerts
|
||||
*
|
||||
* 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
|
||||
|
@ -30,6 +31,7 @@
|
|||
# define snprintf(S, n, F, ...) sprintf(S, F, __VA_ARGS__)
|
||||
# define MAX(a,b) max(a,b)
|
||||
# define MIN(a,b) min(a,b)
|
||||
# define pipe(fds) _pipe(fds, 5000, _O_BINARY)
|
||||
# else
|
||||
# define snprintf sprintf_s
|
||||
# define strdup _strdup
|
||||
|
|
|
@ -35,29 +35,6 @@
|
|||
|
||||
# include <nfc/nfc-types.h>
|
||||
|
||||
// Handle platform specific includes
|
||||
# ifndef _WIN32
|
||||
# include <termios.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <limits.h>
|
||||
# include <sys/time.h>
|
||||
# include <unistd.h>
|
||||
# define delay_ms( X ) usleep( X * 1000 )
|
||||
# else
|
||||
# include "contrib/windows.h"
|
||||
# define delay_ms( X ) Sleep( X )
|
||||
# endif
|
||||
|
||||
// Path to the serial port is OS-dependant.
|
||||
// Try to guess what we should use.
|
||||
# if defined (_WIN32)
|
||||
# define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL }
|
||||
# endif
|
||||
|
||||
// Define shortcut to types to make code more readable
|
||||
typedef void *serial_port;
|
||||
# define INVALID_SERIAL_PORT (void*)(~1)
|
||||
|
|
|
@ -27,16 +27,23 @@
|
|||
|
||||
/* vim: set ts=2 sw=2 et: */
|
||||
|
||||
# include <sys/types.h>
|
||||
# include <sys/select.h>
|
||||
# include <sys/param.h>
|
||||
# include <ctype.h>
|
||||
# include <dirent.h>
|
||||
# include <errno.h>
|
||||
# include <stdio.h>
|
||||
# include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
# include "nfc-internal.h"
|
||||
#include "nfc-internal.h"
|
||||
|
||||
# if defined(__APPLE__)
|
||||
// FIXME: find UART connection string for PN53X device on Mac OS X when multiples devices are used
|
||||
|
|
|
@ -19,10 +19,14 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file uart.c
|
||||
* @file uart_win32.c
|
||||
* @brief Windows UART driver
|
||||
*/
|
||||
|
||||
// Handle platform specific includes
|
||||
#include "contrib/windows.h"
|
||||
#define delay_ms( X ) Sleep( X )
|
||||
|
||||
typedef struct {
|
||||
HANDLE hPort; // Serial port handle
|
||||
DCB dcb; // Device control settings
|
||||
|
@ -140,14 +144,14 @@ uart_get_speed (const serial_port sp)
|
|||
}
|
||||
|
||||
int
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx)
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, int iAbortFd)
|
||||
{
|
||||
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, (DWORD)(*pszRx), (LPDWORD) pszRx, NULL)) {
|
||||
// TODO: Implement abort mecanism (using iAbortFd)
|
||||
DWORD dwRxLen = szRx;
|
||||
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, dwRxLen, &dwRxLen, NULL)) {
|
||||
return DEIO;
|
||||
}
|
||||
if (!*pszRx)
|
||||
return DEIO;
|
||||
return 0;
|
||||
return (dwRwLen == (DWORD) szRx) ? 0 : DEIO;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -162,3 +166,15 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Path to the serial port is OS-dependant.
|
||||
// Try to guess what we should use.
|
||||
#define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL }
|
||||
char **
|
||||
uart_list_ports (void)
|
||||
{
|
||||
// TODO: Wrote an automatic detection of Windows serial ports
|
||||
|
||||
// FIXME: Construct an dynamic allocated array of char* that contains default serial ports.
|
||||
const char ** availablePorts = DEFAULT_SERIAL_PORTS;
|
||||
return availablePorts;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue