From 8c1bf6f56fa304ef4e2dfe6da87b4c57fb5875d5 Mon Sep 17 00:00:00 2001 From: Samy Kamkar Date: Sat, 16 Jan 2021 11:59:46 -0800 Subject: [PATCH] Complete macOS + PN532 UART support --- README.md | 7 ------- libnfc/buses/i2c.c | 4 ++++ libnfc/buses/spi.c | 4 ++++ libnfc/buses/uart.c | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 51b8272..ec7d62f 100644 --- a/README.md +++ b/README.md @@ -201,13 +201,6 @@ them in a modprobe conf file. This file is provided within libnfc archive: sudo cp contrib/linux/blacklist-libnfc.conf /etc/modprobe.d/blacklist-libnfc.conf -PN532 UART on macOS: --------------------- - -- Receiving error: "Unable to set serial port speed to 115200 baud. Speed value must be one of those defined in termios(3)." - - The PN532 High Speed UART (HSU) requires a baud rate of 115200, however macOS may use the incorrect `termios.h` (valid path: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/termios.h) preventing the detection of the `B115200` definition producing the error above. - - Solution: Either add `-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/termios.h` as an include path before the rest of your includes or manually add `#define B115200 115200`. - FEITIAN bR500 and R502: ----------------------- diff --git a/libnfc/buses/i2c.c b/libnfc/buses/i2c.c index dc1ad1f..52180e6 100644 --- a/libnfc/buses/i2c.c +++ b/libnfc/buses/i2c.c @@ -47,7 +47,11 @@ #include #include #include +#ifdef __APPLE__ +#include +#else #include +#endif #include #include #include diff --git a/libnfc/buses/spi.c b/libnfc/buses/spi.c index 0e68f9b..774d17d 100644 --- a/libnfc/buses/spi.c +++ b/libnfc/buses/spi.c @@ -49,7 +49,11 @@ #include #include #include +#ifdef __APPLE__ +#include +#else #include +#endif #include #include diff --git a/libnfc/buses/uart.c b/libnfc/buses/uart.c index 8008037..0cff3f2 100644 --- a/libnfc/buses/uart.c +++ b/libnfc/buses/uart.c @@ -47,7 +47,11 @@ #include #include #include +#ifdef __APPLE__ +#include +#else #include +#endif #include #include @@ -95,6 +99,19 @@ const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", "ttyACM", "ttyAMA" // Work-around to claim uart interface using the c_iflag (software input processing) from the termios struct # define CCLAIMED 0x80000000 +// If macOS and still haven't detected required baud rates, set them as we do have support for some +#ifdef __APPLE__ +#ifndef B57600 +#define B57600 57600 +#endif +#ifndef B115200 +#define B115200 115200 +#endif +#ifndef B230400 +#define B230400 230400 +#endif +#endif + struct serial_port_unix { int fd; // Serial port file descriptor struct termios termios_backup; // Terminal info before using the port