Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PN532 UART support + macOS support #633

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Complete macOS + PN532 UART support
  • Loading branch information
samyk committed Jan 16, 2021
commit 8c1bf6f56fa304ef4e2dfe6da87b4c57fb5875d5
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
-----------------------

Expand Down
4 changes: 4 additions & 0 deletions libnfc/buses/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#ifdef __APPLE__
#include <sys/termios.h>
#else
#include <termios.h>
#endif
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
Expand Down
4 changes: 4 additions & 0 deletions libnfc/buses/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#ifdef __APPLE__
#include <sys/termios.h>
#else
#include <termios.h>
#endif
#include <unistd.h>

#include <nfc/nfc.h>
Expand Down
17 changes: 17 additions & 0 deletions libnfc/buses/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#ifdef __APPLE__
#include <sys/termios.h>
#else
#include <termios.h>
#endif
#include <unistd.h>
#include <stdlib.h>

Expand Down Expand Up @@ -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
Expand Down