]> granicus.if.org Git - esp-idf/commitdiff
spi_master: fix the timing a little so that can assign delay half clock manually
authorMichael (XIAO Xufeng) <xiaoxufeng@espressif.com>
Thu, 6 Dec 2018 09:32:48 +0000 (17:32 +0800)
committerMichael (XIAO Xufeng) <xiaoxufeng@espressif.com>
Fri, 25 Jan 2019 16:10:41 +0000 (00:10 +0800)
components/driver/spi_master.c

index 514a3be68363b7ff712207c2bf0d018d7b44cdac..5976b008ffbedec84cdbec4806a49b29ff24fdc0 100644 (file)
@@ -380,11 +380,14 @@ esp_err_t spi_bus_free(spi_host_device_t host)
 void spi_get_timing(bool gpio_is_used, int input_delay_ns, int eff_clk, int* dummy_o, int* cycles_remain_o)
 {
     const int apbclk_kHz = APB_CLK_FREQ/1000;
+    //calculate how many apb clocks a period has
     const int apbclk_n = APB_CLK_FREQ/eff_clk;
     const int gpio_delay_ns = gpio_is_used ? 25 : 0;
 
-    //calculate how many apb clocks a period has, the 1 is to compensate in case ``input_delay_ns`` is rounded off.
+    //calculate how many apb clocks the delay is, the 1 is to compensate in case ``input_delay_ns`` is rounded off.
     int apb_period_n = (1 + input_delay_ns + gpio_delay_ns)*apbclk_kHz/1000/1000;
+    if (apb_period_n < 0) apb_period_n = 0;
+
     int dummy_required = apb_period_n/apbclk_n;
 
     int miso_delay = 0;
@@ -406,8 +409,10 @@ int spi_get_freq_limit(bool gpio_is_used, int input_delay_ns)
     const int apbclk_kHz = APB_CLK_FREQ/1000;
     const int gpio_delay_ns = gpio_is_used ? 25 : 0;
 
-    //calculate how many apb clocks a period has, the 1 is to compensate in case ``input_delay_ns`` is rounded off.
+    //calculate how many apb clocks the delay is, the 1 is to compensate in case ``input_delay_ns`` is rounded off.
     int apb_period_n = (1 + input_delay_ns + gpio_delay_ns)*apbclk_kHz/1000/1000;
+    if (apb_period_n < 0) apb_period_n = 0;
+
     return APB_CLK_FREQ/(apb_period_n+1);
 }