diff --git a/cmake_modules/LibnfcDrivers.cmake b/cmake_modules/LibnfcDrivers.cmake index 219163b..f2cd200 100644 --- a/cmake_modules/LibnfcDrivers.cmake +++ b/cmake_modules/LibnfcDrivers.cmake @@ -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) diff --git a/contrib/windows.h b/contrib/windows.h index caad550..c97e07a 100644 --- a/contrib/windows.h +++ b/contrib/windows.h @@ -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 diff --git a/libnfc/buses/uart.h b/libnfc/buses/uart.h index e88ceb4..b899f28 100644 --- a/libnfc/buses/uart.h +++ b/libnfc/buses/uart.h @@ -35,29 +35,6 @@ # include -// Handle platform specific includes -# ifndef _WIN32 -# include -# include -# include -# include -# include -# include -# include -# include -# include -# 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) diff --git a/libnfc/buses/uart_posix.c b/libnfc/buses/uart_posix.c index 0d40d54..0a34a53 100644 --- a/libnfc/buses/uart_posix.c +++ b/libnfc/buses/uart_posix.c @@ -27,16 +27,23 @@ /* vim: set ts=2 sw=2 et: */ -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -# 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 diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index 89f30b9..ae2c1cd 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -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; +}