-
Notifications
You must be signed in to change notification settings - Fork 442
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
20b3fdd
9f3c859
8c1bf6f
62216df
f1b6ee4
27836d7
c8cf4b9
4c50adc
27f7537
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,26 @@ uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) | |
return 0; | ||
} | ||
|
||
/** | ||
* @brief Send \a pbtTx content to UART one byte at a time | ||
* | ||
* @return 0 on success, otherwise a driver error is returned | ||
*/ | ||
int | ||
uart_send_single(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) | ||
{ | ||
(void) timeout; | ||
int error = 0; | ||
for (int i = 0; i < szTx; i++) | ||
{ | ||
error |= uart_send(sp, pbtTx+i, 1, timeout); | ||
delay_ms(1); // ceil(1_000_000us / 115200baud) = 9us but no usleep on windows | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sleeping in userland seems terrible… Timing should be managed at the underlying level (UART driver of the OS?) |
||
} | ||
|
||
return error ? NFC_EIO : 0; | ||
} | ||
|
||
|
||
BOOL is_port_available(int nPort) | ||
{ | ||
TCHAR szPort[15]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
||
|
@@ -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 | ||
|
@@ -367,6 +384,26 @@ uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, i | |
return NFC_SUCCESS; | ||
} | ||
|
||
/** | ||
* @brief Send \a pbtTx content to UART one byte at a time | ||
* | ||
* @return 0 on success, otherwise a driver error is returned | ||
*/ | ||
int | ||
uart_send_single(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) | ||
{ | ||
(void) timeout; | ||
int error = 0; | ||
for (int i = 0; i < szTx; i++) | ||
{ | ||
error |= uart_send(sp, pbtTx+i, 1, timeout); | ||
samyk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
usleep(9); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sleeping in userland seems terrible… Timing should be managed at the underlying level (UART driver of the OS?) |
||
} | ||
|
||
|
||
return error ? NFC_EIO : NFC_SUCCESS; | ||
} | ||
|
||
/** | ||
* @brief Send \a pbtTx content to UART | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this I guess