|
@@ -13,6 +13,8 @@
|
|
|
#include "luat_log.h"
|
|
#include "luat_log.h"
|
|
|
#include "luat_timer.h"
|
|
#include "luat_timer.h"
|
|
|
|
|
|
|
|
|
|
+static uint8_t luat_spi_mode = 0;
|
|
|
|
|
+
|
|
|
int luat_spi_device_config(luat_spi_device_t* spi_dev) {
|
|
int luat_spi_device_config(luat_spi_device_t* spi_dev) {
|
|
|
unsigned int clk;
|
|
unsigned int clk;
|
|
|
uint8_t TLS_SPI_MODE = 0x00 ;
|
|
uint8_t TLS_SPI_MODE = 0x00 ;
|
|
@@ -112,6 +114,8 @@ int luat_spi_setup(luat_spi_t* spi) {
|
|
|
tls_spi_trans_type(SPI_DMA_TRANSFER);
|
|
tls_spi_trans_type(SPI_DMA_TRANSFER);
|
|
|
ret = tls_spi_setup(TLS_SPI_MODE, TLS_SPI_CS_LOW, clk);
|
|
ret = tls_spi_setup(TLS_SPI_MODE, TLS_SPI_CS_LOW, clk);
|
|
|
|
|
|
|
|
|
|
+ luat_spi_mode = spi->mode;
|
|
|
|
|
+
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -119,9 +123,19 @@ int luat_spi_setup(luat_spi_t* spi) {
|
|
|
int luat_spi_close(int spi_id) {
|
|
int luat_spi_close(int spi_id) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//收发SPI数据,返回接收字节数
|
|
//收发SPI数据,返回接收字节数
|
|
|
|
|
+int32_t tls_spi_xfer(const void *data_out, void *data_in, uint32_t num_out, uint32_t num_in);
|
|
|
int luat_spi_transfer(int spi_id, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length){
|
|
int luat_spi_transfer(int spi_id, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length){
|
|
|
- tls_spi_read_with_cmd(send_buf, send_length, recv_buf, recv_length);
|
|
|
|
|
|
|
+ //tls_spi_read_with_cmd(send_buf, send_length, recv_buf, recv_length);
|
|
|
|
|
+ if (luat_spi_mode == 0)
|
|
|
|
|
+ tls_spi_xfer(send_buf, recv_buf, send_buf, recv_length);
|
|
|
|
|
+ else {
|
|
|
|
|
+ if (send_length > 0)
|
|
|
|
|
+ tls_spi_write(send_buf, send_length);
|
|
|
|
|
+ if (recv_length > 0)
|
|
|
|
|
+ tls_spi_read(recv_buf, recv_length);
|
|
|
|
|
+ }
|
|
|
return recv_length;
|
|
return recv_length;
|
|
|
}
|
|
}
|
|
|
//收SPI数据,返回接收字节数
|
|
//收SPI数据,返回接收字节数
|