Factorise UART-relative macros definitions.

This commit is contained in:
Romain Tartiere 2010-08-08 09:34:18 +00:00
parent 8e5d235cd2
commit d7c16d6d1a
3 changed files with 26 additions and 46 deletions

View file

@ -43,8 +43,34 @@
#include <sys/stat.h>
#include <limits.h>
#include <sys/time.h>
// unistd.h is needed for usleep() fct.
#include <unistd.h>
#define delay_ms( X ) usleep( X * 1000 )
#else
#include <windows.h>
#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

View file

@ -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 <unistd.h>
#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

View file

@ -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 <unistd.h>
#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