Переглянути джерело

fix: luat_spi_change_speed应该先判断设备是否已经打开

Wendal Chen 2 роки тому
батько
коміт
3188c7cee3
1 змінених файлів з 4 додано та 3 видалено
  1. 4 3
      luatos/components/luat/port/luat_spi_idf5.c

+ 4 - 3
luatos/components/luat/port/luat_spi_idf5.c

@@ -485,11 +485,12 @@ int luat_spi_config_dma(int spi_id, uint32_t tx_channel, uint32_t rx_channel) {
 }
 
 int luat_spi_change_speed(int spi_id, uint32_t speed) {
+    int ret = 0;
     spi_device_interface_config_t* dev_config = &spi_config[spi_id-2];
     dev_config->clock_speed_hz = speed;
-    int ret = spi_bus_remove_device(spi_handle[spi_id-2]);
-    if (ret != 0){
-        return ret;
+    if (spi_handle[spi_id-2]) {
+        ret = spi_bus_remove_device(spi_handle[spi_id-2]);
+        // spi_handle[spi_id-2] = NULL;
     }
     ret =  spi_bus_add_device(spi_id-1, dev_config, &spi_handle[spi_id-2]);
     return ret;