Jelajahi Sumber

fix: 补齐luat_spi_change_speed函数

Wendal Chen 3 tahun lalu
induk
melakukan
44854a5ea5

+ 9 - 0
app/port/luat_spi_air101.c

@@ -186,3 +186,12 @@ int luat_spi_send(int spi_id, const char* send_buf, size_t length) {
 int luat_spi_config_dma(int spi_id, uint32_t tx_channel, uint32_t rx_channel) {
     return 0;
 }
+
+int luat_spi_change_speed(int spi_id, uint32_t speed) {
+    int ret = tls_spi_set_speed(speed);
+    if (ret != 0) {
+        LLOGW("spi set speed %d fail %d", speed, ret);
+    }
+    return ret;
+}
+

+ 2 - 0
include/driver/wm_hostspi.h

@@ -278,6 +278,8 @@ int tls_spi_write_with_cmd(const u8 * cmd, u32 n_cmd, const u8 * txbuf, u32 n_tx
  */
 void tls_spi_trans_type(u8 type);
 
+int tls_spi_set_speed(u32 speed);
+
 /**
  * @}
  */

+ 27 - 0
platform/drivers/spi/wm_hostspi.c

@@ -1543,4 +1543,31 @@ int32_t tls_spi_xfer(const void *data_out, void *data_in, uint32_t num_out, uint
     return (ret == TLS_SPI_STATUS_OK) ? 0 : -1;
 }	
 	
+int tls_spi_set_speed(u32 fclk) {
+    if (spi_port->speed_hz == fclk)
+        return 0;
+    tls_sys_clk sysclk;
+    tls_sys_clk_get(&sysclk);
+
+    if ((fclk < TLS_SPI_FCLK_MIN) || (fclk > sysclk.apbclk*UNIT_MHZ/2))		//TLS_SPI_FCLK_MAX
+    {
+        TLS_DBGPRT_ERR("@fclk is invalid!\n");
+        return TLS_SPI_STATUS_ECLKNOSUPPORT;
+    }
+    else
+    {
+        spi_port->speed_hz = fclk;
+    }
 
+#ifdef SPI_USE_DMA
+    if (SPI_DMA_TRANSFER == spi_port->transtype)
+    {
+        SpiMasterInit(spi_port->mode, TLS_SPI_CS_LOW, fclk);
+        return TLS_SPI_STATUS_OK;
+    }
+#endif
+
+    spi_port->reconfig = 1;
+
+    return TLS_SPI_STATUS_OK;
+}