Просмотр исходного кода

update: 为air640w引入rtt库已经合并的rt_hw_us_delay方法

Wendal Chen 5 лет назад
Родитель
Сommit
e75f0ccec7

+ 0 - 37
bsp/air640w/rtt/applications/rtt_w60x_patch.c

@@ -1,37 +0,0 @@
-
-#include "rtthread.h"
-
-#ifdef BSP_USING_WM_LIBRARIES
-#include "wm_regs.h"
-
-extern void rt_hw_us_delay(rt_uint32_t us)
-{
-    rt_uint32_t ticks;
-    rt_uint32_t told, tnow, tcnt = 0;
-    rt_uint32_t reload = SysTick->LOAD;
-
-    ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
-    told = SysTick->VAL;
-    while (1)
-    {
-        tnow = SysTick->VAL;
-        if (tnow != told)
-        {
-            if (tnow < told)
-            {
-                tcnt += told - tnow;
-            }
-            else
-            {
-                tcnt += reload - tnow + told;
-            }
-            told = tnow;
-            if (tcnt >= ticks)
-            {
-                break;
-            }
-        }
-    }
-}
-
-#endif

+ 36 - 0
bsp/air640w/rtt/drivers/board.c

@@ -213,6 +213,42 @@ void rt_hw_cpu_reset(void)
     tls_sys_reset();
 }
 
+/**
+ * The time delay function.
+ *
+ * @param microseconds.
+ */
+#include "wm_regs.h"
+void rt_hw_us_delay(rt_uint32_t us)
+{
+    rt_uint32_t ticks;
+    rt_uint32_t told, tnow, tcnt = 0;
+    rt_uint32_t reload = SysTick->LOAD;
+
+    ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
+    told = SysTick->VAL;
+    while (1)
+    {
+        tnow = SysTick->VAL;
+        if (tnow != told)
+        {
+            if (tnow < told)
+            {
+                tcnt += told - tnow;
+            }
+            else
+            {
+                tcnt += reload - tnow + told;
+            }
+            told = tnow;
+            if (tcnt >= ticks)
+            {
+                break;
+            }
+        }
+    }
+}
+
 #ifdef RT_USING_FINSH
 #include <finsh.h>
 static void reboot(uint8_t argc, char **argv)

+ 2 - 1
bsp/air640w/rtt/drivers/drv_pin.c

@@ -153,7 +153,8 @@ struct rt_pin_ops _wm_pin_ops =
     wm_pin_read,
     wm_pin_attach_irq,
     wm_pin_detach_irq,
-    wm_pin_irq_enable
+    wm_pin_irq_enable,
+    RT_NULL,
 };
 
 int wm_hw_pin_init(void)

+ 3 - 36
bsp/air640w/rtt/drivers/drv_soft_i2c.c

@@ -138,40 +138,7 @@ static rt_int32_t w60x_get_scl(void *data)
 
     return tls_gpio_read((enum tls_io_name)scl);
 }
-/**
- * The time delay function.
- *
- * @param microseconds.
- */
-static void w60x_udelay(rt_uint32_t us)
-{
-    rt_uint32_t ticks;
-    rt_uint32_t told, tnow, tcnt = 0;
-    rt_uint32_t reload = SysTick->LOAD;
 
-    ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
-    told = SysTick->VAL;
-    while (1)
-    {
-        tnow = SysTick->VAL;
-        if (tnow != told)
-        {
-            if (tnow < told)
-            {
-                tcnt += told - tnow;
-            }
-            else
-            {
-                tcnt += reload - tnow + told;
-            }
-            told = tnow;
-            if (tcnt >= ticks)
-            {
-                break;
-            }
-        }
-    }
-}
 
 static const struct rt_i2c_bit_ops w60x_bit_ops_default =
 {
@@ -180,7 +147,7 @@ static const struct rt_i2c_bit_ops w60x_bit_ops_default =
     .set_scl  = w60x_set_scl,
     .get_sda  = w60x_get_sda,
     .get_scl  = w60x_get_scl,
-    .udelay   = w60x_udelay,
+    .udelay   = rt_hw_us_delay,
     .delay_us = 1,
     .timeout  = 100
 };
@@ -201,9 +168,9 @@ static rt_err_t w60x_i2c_bus_unlock(const struct w60x_soft_i2c_config *cfg)
         while (i++ < 9)
         {
             rt_pin_write(cfg->scl, PIN_HIGH);
-            w60x_udelay(100);
+            rt_hw_us_delay(100);
             rt_pin_write(cfg->scl, PIN_LOW);
-            w60x_udelay(100);
+            rt_hw_us_delay(100);
         }
     }
     if (PIN_LOW == rt_pin_read(cfg->sda))