Fix PN532 UART support (8 data bits per HSU TX)

This commit is contained in:
Samy Kamkar 2021-01-16 11:50:41 -08:00
parent 20b3fddc89
commit 9f3c859c3b
2 changed files with 19 additions and 3 deletions

View File

@ -367,6 +367,22 @@ select:
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);
return error ? NFC_EIO : NFC_SUCCESS;
}
/**
* @brief Send \a pbtTx content to UART
*

View File

@ -304,7 +304,7 @@ pn532_uart_wakeup(nfc_device *pnd)
{
/* High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
const uint8_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int res = uart_send(DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof(pn532_wakeup_preamble), 0);
int res = uart_send_single(DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof(pn532_wakeup_preamble), 0);
CHIP_DATA(pnd)->power_mode = NORMAL; // PN532 should now be awake
return res;
}
@ -348,7 +348,7 @@ pn532_uart_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, in
return pnd->last_error;
}
res = uart_send(DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout);
res = uart_send_single(DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout);
if (res != 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
pnd->last_error = res;
@ -507,7 +507,7 @@ pn532_uart_ack(nfc_device *pnd)
return res;
}
}
return (uart_send(DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof(pn53x_ack_frame), 0));
return (uart_send_single(DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof(pn53x_ack_frame), 0));
}
static int