diff --git a/libnfc/buses/uart.c b/libnfc/buses/uart.c index ffe64aa..8008037 100644 --- a/libnfc/buses/uart.c +++ b/libnfc/buses/uart.c @@ -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 * diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index d82051d..dae0242 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -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