diff --git a/libnfc/buses/uart.h b/libnfc/buses/uart.h index 87f9f27..8b0ea8a 100644 --- a/libnfc/buses/uart.h +++ b/libnfc/buses/uart.h @@ -43,8 +43,34 @@ #include #include #include + + // unistd.h is needed for usleep() fct. + #include + #define delay_ms( X ) usleep( X * 1000 ) #else #include + + #define snprintf _snprintf + #define strdup _strdup + #define delay_ms( X ) Sleep( X ) +#endif + +// Path to the serial port is OS-dependant. +// Try to guess what we should use. +// +// XXX: Some review from users cross-compiling is welcome! +#if defined(_WIN32) + #define SERIAL_STRING "COM" +//#elif defined(__APPLE__) +// TODO: find UART connection string for PN53X device on Mac OS X +// #define SERIAL_STRING "" +#elif defined (__FreeBSD__) || defined (__OpenBSD__) + // XXX: Not tested + #define SERIAL_STRING "/dev/cuau" +#elif defined (__linux__) + #define SERIAL_STRING "/dev/ttyUSB" +#else + #error "Can't determine serial string for your system" #endif // Define shortcut to types to make code more readable diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 8c43f21..0ff9090 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -41,25 +41,6 @@ // Bus #include "uart.h" -#ifdef _WIN32 - #define SERIAL_STRING "COM" - #define snprintf _snprintf - #define strdup _strdup - #define delay_ms( X ) Sleep( X ) -#else - // unistd.h is needed for usleep() fct. - #include - #define delay_ms( X ) usleep( X * 1000 ) - - #ifdef __APPLE__ - // MacOS - #define SERIAL_STRING "/dev/tty.SLAB_USBtoUART" - #else - // *BSD, Linux and others POSIX systems - #define SERIAL_STRING "/dev/ttyUSB" - #endif -#endif - #define BUFFER_LENGTH 256 /** @def DEV_ARYGON_PROTOCOL_ARYGON_ASCII diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 26c89a0..6359bcd 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -38,33 +38,6 @@ // Bus #include "uart.h" -#ifdef _WIN32 - #define SERIAL_STRING "COM" - #define snprintf _snprintf - #define strdup _strdup - #define delay_ms( X ) Sleep( X ) -#else - // unistd.h is needed for usleep() fct. - #include - #define delay_ms( X ) usleep( X * 1000 ) - - #ifdef __APPLE__ - // MacOS - // TODO: find UART connection string for PN53X device on Mac OS X - #define SERIAL_STRING "" - #elif defined(__FreeBSD__) - // XXX: Not tested - #define SERIAL_STRING "/dev/cuau" - #else - // Linux and maybe some operating systems - // FIXME: We'd rather have an #elif defined(__linux__) or something like - // that and an #else that triggers an error at compile time instead - // of "falling-back" on a value that is likely to not be suitable - // for most operating systems. - #define SERIAL_STRING "/dev/ttyUSB" - #endif -#endif - #define BUFFER_LENGTH 256 #define SERIAL_DEFAULT_PORT_SPEED 115200