//
// Created by Kai Jan Kriegel on 12.10.22.
//

#include <memory.h>
#include <esp_err.h>
#include "st25r3911_spi.h"
#include "platform.h"

spi_device_handle_t pSpi;
#define SPI_BUF_LEN 32

void st25r3911_spi_init(spi_device_handle_t spi) {
    pSpi = spi;
}

esp_err_t st25r3911_spiTxRx(const uint8_t *txData, uint8_t *rxData, uint16_t length) {
    if (length > SPI_BUF_LEN) {
        return ESP_FAIL;
    }

    spi_transaction_t t;
    memset(&t, 0, sizeof(t));
    t.length = length * 8;
    t.rx_buffer = rxData;
    t.tx_buffer = txData;

    esp_err_t ret = spi_device_polling_transmit(pSpi, &t);
    ESP_ERROR_CHECK(ret);

    return ret;
}


