Browse Source

add:eink添加异步接口

Dozingfiretruck 3 years ago
parent
commit
e2d526ef2b
42 changed files with 677 additions and 557 deletions
  1. 4 3
      components/eink/epd1in54.c
  2. 4 3
      components/eink/epd2in9.c
  3. 43 5
      components/eink/luat_lib_eink.c
  4. 4 0
      components/epaper/DEV_Config.h
  5. 15 14
      components/epaper/EPD_1in02d.c
  6. 13 12
      components/epaper/EPD_1in54.c
  7. 21 19
      components/epaper/EPD_1in54_V2.c
  8. 13 12
      components/epaper/EPD_1in54_V3.c
  9. 16 15
      components/epaper/EPD_1in54b.c
  10. 16 15
      components/epaper/EPD_1in54b_V2.c
  11. 13 12
      components/epaper/EPD_1in54c.c
  12. 13 12
      components/epaper/EPD_2in13.c
  13. 13 12
      components/epaper/EPD_2in13_V2.c
  14. 18 17
      components/epaper/EPD_2in13b_V3.c
  15. 13 12
      components/epaper/EPD_2in13bc.c
  16. 18 17
      components/epaper/EPD_2in13d.c
  17. 15 14
      components/epaper/EPD_2in66.c
  18. 15 14
      components/epaper/EPD_2in66b.c
  19. 18 17
      components/epaper/EPD_2in7.c
  20. 13 12
      components/epaper/EPD_2in7b.c
  21. 13 12
      components/epaper/EPD_2in9.c
  22. 17 16
      components/epaper/EPD_2in9_V2.c
  23. 20 19
      components/epaper/EPD_2in9b_V3.c
  24. 13 12
      components/epaper/EPD_2in9bc.c
  25. 18 17
      components/epaper/EPD_2in9d.c
  26. 16 15
      components/epaper/EPD_3in7.c
  27. 15 14
      components/epaper/EPD_4in2.c
  28. 18 17
      components/epaper/EPD_4in2b_V2.c
  29. 13 12
      components/epaper/EPD_4in2bc.c
  30. 20 18
      components/epaper/EPD_5in65f.c
  31. 13 12
      components/epaper/EPD_5in83.c
  32. 16 15
      components/epaper/EPD_5in83_V2.c
  33. 20 19
      components/epaper/EPD_5in83b_V2.c
  34. 17 16
      components/epaper/EPD_5in83bc.c
  35. 13 12
      components/epaper/EPD_7in5.c
  36. 14 13
      components/epaper/EPD_7in5_HD.c
  37. 18 17
      components/epaper/EPD_7in5_V2.c
  38. 14 13
      components/epaper/EPD_7in5b_HD.c
  39. 18 17
      components/epaper/EPD_7in5b_V2.c
  40. 17 16
      components/epaper/EPD_7in5bc.c
  41. 55 17
      components/epaper/epd.c
  42. 1 1
      components/epaper/epd.h

+ 4 - 3
components/eink/epd1in54.c

@@ -350,9 +350,10 @@ void EPD_1IN54F_SendData(EPD* epd, unsigned char data) {
  *  @brief: Wait until the busy_pin goes LOW
  */
 void EPD_1IN54F_WaitUntilIdle(EPD* epd) {
-  while(EPD_1IN54F_DigitalRead(epd, epd->busy_pin) == HIGH) {      //0: busy, 1: idle
-    EPD_1IN54F_DelayMs(epd, 100);
-  }      
+  EPD_Busy_WaitUntil(0,0);
+  // while(EPD_1IN54F_DigitalRead(epd, epd->busy_pin) == HIGH) {      //0: busy, 1: idle
+  //   EPD_1IN54F_DelayMs(epd, 100);
+  // }      
 }
 
 /**

+ 4 - 3
components/eink/epd2in9.c

@@ -115,9 +115,10 @@ void EPD_2IN9F_SendData(EPD* epd, unsigned char data) {
  *  @brief: Wait until the busy_pin goes LOW
  */
 void EPD_2IN9F_WaitUntilIdle(EPD* epd) {
-  while(EPD_2IN9F_DigitalRead(epd, epd->busy_pin) == HIGH) {      //0: busy, 1: idle
-    EPD_2IN9F_DelayMs(epd, 100);
-  }      
+  EPD_Busy_WaitUntil(0,0);
+  // while(EPD_2IN9F_DigitalRead(epd, epd->busy_pin) == HIGH) {      //0: busy, 1: idle
+  //   EPD_2IN9F_DelayMs(epd, 100);
+  // }      
 }
 
 /**

+ 43 - 5
components/eink/luat_lib_eink.c

@@ -56,7 +56,7 @@ eink显示屏初始化
 -- 初始化spi0的eink.MODEL_4in2bc) 注意:eink初始化之前需要先初始化spi
 spi_eink = spi.deviceSetup(0,20,0,0,8,20000000,spi.MSB,1,1)
 log.info("eink.init",
-eink.init(eink.MODEL_4in2bc),{port = "device",pin_dc = 17, pin_pwr = 7,pin_rst = 19,direction = 2,w = 160,h = 80,xoffset = 1,yoffset = 26},spi_eink))
+eink.init(eink.MODEL_4in2bc,{port = "device",pin_dc = 17, pin_pwr = 7,pin_rst = 19,direction = 2,w = 160,h = 80,xoffset = 1,yoffset = 26},spi_eink))
 */
 static int l_eink_init(lua_State* L) {
     if (lua_type(L, 3) == LUA_TUSERDATA){
@@ -129,6 +129,10 @@ static int l_eink_init(lua_State* L) {
     size_t epd_h = 0;
     size_t colors = 0;
 
+    if (econf.async){
+      econf.idp = luat_pushcwait(L);
+    }
+
     int status = EPD_Init(econf.full_mode, &epd_w, &epd_h, &colors);
 
     if (status != 0) {
@@ -160,10 +164,16 @@ static int l_eink_init(lua_State* L) {
     u8g2_SetFontMode(&(econf.luat_eink_u8g2), 0);
     u8g2_SetFontDirection(&(econf.luat_eink_u8g2), 0);
     lua_pushboolean(L, 1);
+    if (econf.async){
+      luat_pushcwait_error(L,1);
+    }
     return 1;
 
 end:
     lua_pushboolean(L, 0);
+    if (econf.async){
+      luat_pushcwait_error(L,1);
+    }
     return 1;
 }
 
@@ -211,6 +221,9 @@ static int l_eink_setup(lua_State *L) {
     size_t epd_w = 0;
     size_t epd_h = 0;
     size_t colors = 0;
+    if (econf.async){
+      econf.idp = luat_pushcwait(L);
+    }
     if(status == 0)
     {
         if(econf.full_mode)
@@ -251,6 +264,9 @@ static int l_eink_setup(lua_State *L) {
     //paint.inited = 1;
     //LLOGD("epd init complete");
     lua_pushboolean(L, 1);
+    if (econf.async){
+      luat_pushcwait_error(L,1);
+    }
     return 1;
 }
 
@@ -261,7 +277,11 @@ static int l_eink_setup(lua_State *L) {
 static int l_eink_sleep(lua_State *L)
 {
     EPD_Sleep();
-    return 0;
+    lua_pushboolean(L, 1);
+    if (econf.async){
+      luat_pushcwait_error(L,1);
+    }
+    return 1;
 }
 
 /**
@@ -279,7 +299,11 @@ static int l_eink_clear(lua_State *L)
     Paint_Clear(&econf.ctxs[econf.ctx_index]->paint, colored);
     if(lua_toboolean(L, 2))
       EPD_Clear();
-    return 0;
+    lua_pushboolean(L, 1);
+    if (econf.async){
+      luat_pushcwait_error(L,1);
+    }
+    return 1;
 }
 
 /**
@@ -636,7 +660,11 @@ static int l_eink_show(lua_State *L)
       EPD_Display(econf.ctxs[0]->fb, NULL);
     else
       EPD_Display(econf.ctxs[0]->fb, econf.ctxs[1]->fb);
-    return 0;
+    lua_pushboolean(L, 1);
+    if (econf.async){
+      luat_pushcwait_error(L,1);
+    }
+    return 1;
 }
 
 /**
@@ -661,7 +689,11 @@ static int l_eink_draw(lua_State *L)
     if(!no_clear)
       EPD_Clear();
     EPD_Display(buff->addr, buff2->addr);
-    return 0;
+    lua_pushboolean(L, 1);
+    if (econf.async){
+      luat_pushcwait_error(L,1);
+    }
+    return 1;
 }
 
 
@@ -1173,9 +1205,15 @@ static int l_eink_set_ctx(lua_State *L) {
   return 1;
 }
 
+static int l_eink_async(lua_State *L) {
+  econf.async = luaL_checkinteger(L, 1);
+  return 0;
+}
+
 #include "rotable2.h"
 static const rotable_Reg_t reg_eink[] =
 {
+    { "async",          ROREG_FUNC(l_eink_async)},
     { "init",           ROREG_FUNC(l_eink_init)},
     { "setup",          ROREG_FUNC(l_eink_setup)},
     { "sleep",          ROREG_FUNC(l_eink_sleep)},

+ 4 - 0
components/epaper/DEV_Config.h

@@ -77,11 +77,15 @@ typedef struct eink_conf {
     uint8_t pin_dc;
     uint8_t pin_cs;
     uint8_t pin_busy;
+    uint8_t async;
+    uint64_t idp;
     uint32_t ctx_index;
     eink_ctx_t *ctxs[2]; // 暂时只支持2种颜色, 有需要的话后续继续
     u8g2_t luat_eink_u8g2;
     luat_spi_device_t* eink_spi_device;
     int eink_spi_ref;
+    uint8_t timer_count;
+    void* readbusy_timer;
     void* userdata;
 }eink_conf_t;
 

+ 15 - 14
components/epaper/EPD_1in02d.c

@@ -158,20 +158,21 @@ function :	Wait until the busy_pin goes LOW
 ******************************************************************************/
 void EPD_1IN02_WaitUntilIdle(void)
 {
-	unsigned char busy;
-    unsigned char count = 100;
-	do
-	{
-		EPD_1IN02_SendCommand(0x71);
-		busy = DEV_Digital_Read(EPD_BUSY_PIN);
-		busy =!(busy & 0x01);
-		if(!(count--))
-            break;
-        else
-            DEV_Delay_ms(100);
-	}
-	while(busy);
-	DEV_Delay_ms(800);                       
+	EPD_Busy_WaitUntil(1,1);
+	// unsigned char busy;
+    // unsigned char count = 100;
+	// do
+	// {
+	// 	EPD_1IN02_SendCommand(0x71);
+	// 	busy = DEV_Digital_Read(EPD_BUSY_PIN);
+	// 	busy =!(busy & 0x01);
+	// 	if(!(count--))
+    //         break;
+    //     else
+    //         DEV_Delay_ms(100);
+	// }
+	// while(busy);
+	// DEV_Delay_ms(800);                       
 }
 
 

+ 13 - 12
components/epaper/EPD_1in54.c

@@ -147,18 +147,19 @@ parameter:
 ******************************************************************************/
 void EPD_1IN54_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 21 - 19
components/epaper/EPD_1in54_V2.c

@@ -76,25 +76,27 @@ parameter:
 ******************************************************************************/
 static void EPD_1IN54_V2_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    // UBYTE busy;
-    // do {
-        // EPD_1IN54_V2_SendCommand(0x71);
-        // busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        // busy = !(busy & 0x01);
-    // } while(busy);
-    // DEV_Delay_ms(200);
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // // UBYTE busy;
+    // // do {
+    //     // EPD_1IN54_V2_SendCommand(0x71);
+    //     // busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     // busy = !(busy & 0x01);
+    // // } while(busy);
+    // // DEV_Delay_ms(200);
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_1in54_V3.c

@@ -48,18 +48,19 @@ parameter:
 ******************************************************************************/
 static void EPD_1IN54_V3_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //0:BUSY,1:FREE
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //0:BUSY,1:FREE
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 16 - 15
components/epaper/EPD_1in54b.c

@@ -149,21 +149,22 @@ parameter:
 ******************************************************************************/
 static void EPD_1IN54B_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(1) {
-        if(DEV_Digital_Read(EPD_BUSY_PIN) == 1)
-            break;
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    DEV_Delay_ms(200);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(1) {
+    //     if(DEV_Digital_Read(EPD_BUSY_PIN) == 1)
+    //         break;
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // DEV_Delay_ms(200);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 16 - 15
components/epaper/EPD_1in54b_V2.c

@@ -77,21 +77,22 @@ parameter:
 ******************************************************************************/
 static void EPD_1IN54B_V2_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(1) {
-        if(DEV_Digital_Read(EPD_BUSY_PIN) == 0)
-            break;
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    DEV_Delay_ms(200);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(1) {
+    //     if(DEV_Digital_Read(EPD_BUSY_PIN) == 0)
+    //         break;
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // DEV_Delay_ms(200);
+    // Debug("e-Paper busy release\r\n");
 }
 
 

+ 13 - 12
components/epaper/EPD_1in54c.c

@@ -127,18 +127,19 @@ parameter:
 ******************************************************************************/
 static void EPD_1IN54C_ReadBusy(void)
 {
-    unsigned char busy;
-    unsigned char count = 100;
-    do {
-        EPD_1IN54C_SendCommand(0x71);
-        busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        busy =!(busy & 0x01);
-		if(!(count--))
-            break;
-        else
-            DEV_Delay_ms(100);
-    }	while(busy);
-    DEV_Delay_ms(200);
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char busy;
+    // unsigned char count = 100;
+    // do {
+    //     EPD_1IN54C_SendCommand(0x71);
+    //     busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     busy =!(busy & 0x01);
+	// 	if(!(count--))
+    //         break;
+    //     else
+    //         DEV_Delay_ms(100);
+    // }	while(busy);
+    // DEV_Delay_ms(200);
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_2in13.c

@@ -110,18 +110,19 @@ parameter:
 ******************************************************************************/
 void EPD_2IN13_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_2in13_V2.c

@@ -134,18 +134,19 @@ parameter:
 ******************************************************************************/
 void EPD_2IN13_V2_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 18 - 17
components/epaper/EPD_2in13b_V3.c

@@ -80,23 +80,24 @@ parameter:
 ******************************************************************************/
 void EPD_2IN13B_V3_ReadBusy(void)
 {
-    unsigned char count = 100;
-    UBYTE busy;
-    Debug("e-Paper busy\r\n");
-    do{
-        EPD_2IN13B_V3_SendCommand(0x71);
-        busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        busy =!(busy & 0x01);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }while(busy);
-    Debug("e-Paper busy release\r\n");
-    DEV_Delay_ms(200);
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 100;
+    // UBYTE busy;
+    // Debug("e-Paper busy\r\n");
+    // do{
+    //     EPD_2IN13B_V3_SendCommand(0x71);
+    //     busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     busy =!(busy & 0x01);
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }while(busy);
+    // Debug("e-Paper busy release\r\n");
+    // DEV_Delay_ms(200);
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_2in13bc.c

@@ -129,18 +129,19 @@ parameter:
 ******************************************************************************/
 void EPD_2IN13BC_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 18 - 17
components/epaper/EPD_2in13d.c

@@ -211,23 +211,24 @@ parameter:
 ******************************************************************************/
 static void EPD_2IN13D_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    UBYTE busy;
-    do {
-        EPD_2IN13D_SendCommand(0x71);
-        busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        busy =!(busy & 0x01);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    } while(busy);
-    DEV_Delay_ms(200);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // UBYTE busy;
+    // do {
+    //     EPD_2IN13D_SendCommand(0x71);
+    //     busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     busy =!(busy & 0x01);
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // } while(busy);
+    // DEV_Delay_ms(200);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 15 - 14
components/epaper/EPD_2in66.c

@@ -96,20 +96,21 @@ parameter:
 ******************************************************************************/
 void EPD_2IN66_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    DEV_Delay_ms(100);
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    DEV_Delay_ms(100);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // DEV_Delay_ms(100);
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // DEV_Delay_ms(100);
+    // Debug("e-Paper busy release\r\n");
 }
 
 

+ 15 - 14
components/epaper/EPD_2in66b.c

@@ -76,20 +76,21 @@ parameter:
 ******************************************************************************/
 static void EPD_2IN66B_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    DEV_Delay_ms(50);
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    DEV_Delay_ms(50);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // DEV_Delay_ms(50);
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // DEV_Delay_ms(50);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 18 - 17
components/epaper/EPD_2in7.c

@@ -239,23 +239,24 @@ parameter:
 ******************************************************************************/
 static void EPD_2in7_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    UBYTE busy;
-    do {
-        EPD_2in7_SendCommand(0x71);
-        busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        busy =!(busy & 0x01);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    } while(busy);
-    DEV_Delay_ms(200);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // UBYTE busy;
+    // do {
+    //     EPD_2in7_SendCommand(0x71);
+    //     busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     busy =!(busy & 0x01);
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // } while(busy);
+    // DEV_Delay_ms(200);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_2in7b.c

@@ -190,18 +190,19 @@ parameter:
 ******************************************************************************/
 static void EPD_2IN7B_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //0: busy, 1: idle
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }    
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //0: busy, 1: idle
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }    
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_2in9.c

@@ -141,18 +141,19 @@ parameter:
 ******************************************************************************/
 void EPD_2IN9_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 17 - 16
components/epaper/EPD_2in9_V2.c

@@ -100,22 +100,23 @@ parameter:
 ******************************************************************************/
 void EPD_2IN9_V2_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-	while(1)
-	{	 //=1 BUSY
-		if(DEV_Digital_Read(EPD_BUSY_PIN)==0) 
-			break;
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-	}
-	DEV_Delay_ms(50);
-    Debug("e-Paper busy release\r\n");
+	EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+	// while(1)
+	// {	 //=1 BUSY
+	// 	if(DEV_Digital_Read(EPD_BUSY_PIN)==0) 
+	// 		break;
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+	// }
+	// DEV_Delay_ms(50);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 20 - 19
components/epaper/EPD_2in9b_V3.c

@@ -77,25 +77,26 @@ parameter:
 ******************************************************************************/
 void EPD_2IN9B_V3_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    UBYTE busy;
-	do
-	{
-		EPD_2IN9B_V3_SendCommand(0x71);
-		busy = DEV_Digital_Read(EPD_BUSY_PIN);
-		busy =!(busy & 0x01);        
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-	}
-	while(busy); 
-    Debug("e-Paper busy release\r\n");
-    DEV_Delay_ms(200);
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // UBYTE busy;
+	// do
+	// {
+	// 	EPD_2IN9B_V3_SendCommand(0x71);
+	// 	busy = DEV_Digital_Read(EPD_BUSY_PIN);
+	// 	busy =!(busy & 0x01);        
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+	// }
+	// while(busy); 
+    // Debug("e-Paper busy release\r\n");
+    // DEV_Delay_ms(200);
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_2in9bc.c

@@ -130,18 +130,19 @@ parameter:
 ******************************************************************************/
 void EPD_2IN9BC_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 18 - 17
components/epaper/EPD_2in9d.c

@@ -202,23 +202,24 @@ parameter:
 ******************************************************************************/
 void EPD_2IN9D_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    UBYTE busy;
-    do {
-        EPD_2IN9D_SendCommand(0x71);
-        busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        busy =!(busy & 0x01);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    } while(busy);
-    DEV_Delay_ms(200);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // UBYTE busy;
+    // do {
+    //     EPD_2IN9D_SendCommand(0x71);
+    //     busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     busy =!(busy & 0x01);
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // } while(busy);
+    // DEV_Delay_ms(200);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 16 - 15
components/epaper/EPD_3in7.c

@@ -133,21 +133,22 @@ static void EPD_3IN7_SendData(UBYTE Data)
 
 static void EPD_3IN7_ReadBusy_HIGH(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    UBYTE busy;
-    do {
-        busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    } while(busy);
-    DEV_Delay_ms(200);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // UBYTE busy;
+    // do {
+    //     busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // } while(busy);
+    // DEV_Delay_ms(200);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 15 - 14
components/epaper/EPD_4in2.c

@@ -310,20 +310,21 @@ parameter:
 ******************************************************************************/
 void EPD_4IN2_ReadBusy(void)
 {
-    unsigned char count = 200;
-    Debug("e-Paper busy\r\n");
-    EPD_4IN2_SendCommand(0x71);
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //LOW: idle, HIGH: busy
-        EPD_4IN2_SendCommand(0x71);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 200;
+    // Debug("e-Paper busy\r\n");
+    // EPD_4IN2_SendCommand(0x71);
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //LOW: idle, HIGH: busy
+    //     EPD_4IN2_SendCommand(0x71);
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 18 - 17
components/epaper/EPD_4in2b_V2.c

@@ -77,23 +77,24 @@ parameter:
 ******************************************************************************/
 void EPD_4IN2B_V2_ReadBusy(void)
 {
-    unsigned char count = 200;
-    Debug("e-Paper busy\r\n");
-    unsigned char busy;
-    do{
-        EPD_4IN2B_V2_SendCommand(0x71);
-		busy = DEV_Digital_Read(EPD_BUSY_PIN);
-		busy =!(busy & 0x01); 
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }while(busy);
-    Debug("e-Paper busy release\r\n");
-    DEV_Delay_ms(200);
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 200;
+    // Debug("e-Paper busy\r\n");
+    // unsigned char busy;
+    // do{
+    //     EPD_4IN2B_V2_SendCommand(0x71);
+	// 	busy = DEV_Digital_Read(EPD_BUSY_PIN);
+	// 	busy =!(busy & 0x01); 
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }while(busy);
+    // Debug("e-Paper busy release\r\n");
+    // DEV_Delay_ms(200);
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_4in2bc.c

@@ -130,18 +130,19 @@ parameter:
 ******************************************************************************/
 void EPD_4IN2BC_ReadBusy(void)
 {
-    unsigned char count = 200;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //0: busy, 1: idle
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 200;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //0: busy, 1: idle
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 20 - 18
components/epaper/EPD_5in65f.c

@@ -73,28 +73,30 @@ static void EPD_5IN65F_SendData(UBYTE Data)
 
 static void EPD_5IN65F_BusyHigh(void)// If BUSYN=0 then waiting
 {
-    unsigned char count = 100;
-    while(!(DEV_Digital_Read(EPD_BUSY_PIN))){
-        if(!(count--))
-        {
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 100;
+    // while(!(DEV_Digital_Read(EPD_BUSY_PIN))){
+    //     if(!(count--))
+    //     {
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
 }
 
 static void EPD_5IN65F_BusyLow(void)// If BUSYN=1 then waiting
 {
-    unsigned char count = 100;
-    while(DEV_Digital_Read(EPD_BUSY_PIN)){
-        if(!(count--))
-        {
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // while(DEV_Digital_Read(EPD_BUSY_PIN)){
+    //     if(!(count--))
+    //     {
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_5in83.c

@@ -133,18 +133,19 @@ parameter:
 ******************************************************************************/
 static void EPD_5IN83_ReadBusy(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 16 - 15
components/epaper/EPD_5in83_V2.c

@@ -77,21 +77,22 @@ parameter:
 ******************************************************************************/
 static void EPD_5in83_V2_ReadBusy(void)
 {
-    unsigned char count = 100;
-	Debug("e-Paper busy\r\n");
-	do {
-		EPD_5in83_V2_SendCommand(0x71);
-		if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-	}
-	while(!DEV_Digital_Read(EPD_BUSY_PIN));   
-	Debug("e-Paper busy release\r\n");
-	DEV_Delay_ms(50);    
+	EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 100;
+	// Debug("e-Paper busy\r\n");
+	// do {
+	// 	EPD_5in83_V2_SendCommand(0x71);
+	// 	if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+	// }
+	// while(!DEV_Digital_Read(EPD_BUSY_PIN));   
+	// Debug("e-Paper busy release\r\n");
+	// DEV_Delay_ms(50);    
 }
 
 /******************************************************************************

+ 20 - 19
components/epaper/EPD_5in83b_V2.c

@@ -76,25 +76,26 @@ parameter:
 ******************************************************************************/
 void EPD_5IN83B_V2_WaitUntilIdle(void)
 {
-    unsigned char count = 100;
-  Debug("e-Paper busy\r\n");
-	UBYTE busy;
-	do
-	{
-		EPD_5IN83B_V2_SendCommand(0x71);
-		busy = DEV_Digital_Read(EPD_BUSY_PIN);
-		busy =!(busy & 0x01);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-	}
-	while(busy);   
-	DEV_Delay_ms(200);     
-  Debug("e-Paper busy release\r\n");
+	EPD_Busy_WaitUntil(1,1);
+//     unsigned char count = 100;
+//   Debug("e-Paper busy\r\n");
+// 	UBYTE busy;
+// 	do
+// 	{
+// 		EPD_5IN83B_V2_SendCommand(0x71);
+// 		busy = DEV_Digital_Read(EPD_BUSY_PIN);
+// 		busy =!(busy & 0x01);
+//         if(!(count--))
+//         {
+//             Debug("error: e-Paper busy timeout!!!\r\n");
+//             break;
+//         }
+//         else
+//             DEV_Delay_ms(100);
+// 	}
+// 	while(busy);   
+// 	DEV_Delay_ms(200);     
+//   Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 17 - 16
components/epaper/EPD_5in83bc.c

@@ -131,22 +131,23 @@ parameter:
 ******************************************************************************/
 void EPD_5IN83BC_ReadBusy(void)
 {
-    unsigned char count = 100;
-    UBYTE busy;
-    Debug("e-Paper busy\r\n");
-    do {
-        EPD_5IN83BC_SendCommand(0x71);
-        busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        busy =!(busy & 0x01);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    } while(busy);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 100;
+    // UBYTE busy;
+    // Debug("e-Paper busy\r\n");
+    // do {
+    //     EPD_5IN83BC_SendCommand(0x71);
+    //     busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     busy =!(busy & 0x01);
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // } while(busy);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 13 - 12
components/epaper/EPD_7in5.c

@@ -133,18 +133,19 @@ parameter:
 ******************************************************************************/
 void EPD_7IN5_ReadBusy(void)
 {
-    unsigned char count = 200;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //LOW: idle, HIGH: busy
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,0);
+    // unsigned char count = 200;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {      //LOW: idle, HIGH: busy
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // Debug("e-Paper busy release\r\n");
 }
 
 

+ 14 - 13
components/epaper/EPD_7in5_HD.c

@@ -77,19 +77,20 @@ parameter:
 ******************************************************************************/
 static void EPD_7IN5_HD_WaitUntilIdle(void)
 {
-    unsigned char count = 100;
-    Debug("e-Paper busy\r\n");
-    do{
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }while(DEV_Digital_Read(EPD_BUSY_PIN) == 1);   
-    DEV_Delay_ms(200);      
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 100;
+    // Debug("e-Paper busy\r\n");
+    // do{
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }while(DEV_Digital_Read(EPD_BUSY_PIN) == 1);   
+    // DEV_Delay_ms(200);      
+    // Debug("e-Paper busy release\r\n");
     
 }
 

+ 18 - 17
components/epaper/EPD_7in5_V2.c

@@ -77,23 +77,24 @@ parameter:
 ******************************************************************************/
 static void EPD_WaitUntilIdle(void)
 {
-    unsigned char count = 200;
-    Debug("e-Paper busy\r\n");
-    unsigned char busy;
-	do{
-		EPD_SendCommand(0x71);
-		busy = DEV_Digital_Read(EPD_BUSY_PIN);
-		busy =!(busy & 0x01);        
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-	}while(busy);   
-	DEV_Delay_ms(200);      
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 200;
+    // Debug("e-Paper busy\r\n");
+    // unsigned char busy;
+	// do{
+	// 	EPD_SendCommand(0x71);
+	// 	busy = DEV_Digital_Read(EPD_BUSY_PIN);
+	// 	busy =!(busy & 0x01);        
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+	// }while(busy);   
+	// DEV_Delay_ms(200);      
+    // Debug("e-Paper busy release\r\n");
 		
 }
 

+ 14 - 13
components/epaper/EPD_7in5b_HD.c

@@ -77,19 +77,20 @@ parameter:
 ******************************************************************************/
 void EPD_7IN5B_HD_WaitUntilIdle(void)
 {
-    unsigned char count = 200;
-    Debug("e-Paper busy\r\n");
-    while(DEV_Digital_Read(EPD_BUSY_PIN)){
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    }
-    DEV_Delay_ms(200);      
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(0,0);
+    // unsigned char count = 200;
+    // Debug("e-Paper busy\r\n");
+    // while(DEV_Digital_Read(EPD_BUSY_PIN)){
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // }
+    // DEV_Delay_ms(200);      
+    // Debug("e-Paper busy release\r\n");
 }
 
 

+ 18 - 17
components/epaper/EPD_7in5b_V2.c

@@ -76,23 +76,24 @@ parameter:
 ******************************************************************************/
 void EPD_7IN5B_V2_WaitUntilIdle(void)
 {
-    unsigned char count = 300;
-	Debug("e-Paper busy\r\n");
-	unsigned char busy;
-	do	{
-		EPD_7IN5B_V2_SendCommand(0x71);
-		busy = DEV_Digital_Read(EPD_BUSY_PIN);
-		busy =!(busy & 0x01);        
-        // if(!(count--))
-        // {
-        //     Debug("error: e-Paper busy timeout!!!\r\n");
-        //     break;
-        // }
-        // else
-            DEV_Delay_ms(100);
-	}while(busy);
-	DEV_Delay_ms(200);      
-	Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 300;
+	// Debug("e-Paper busy\r\n");
+	// unsigned char busy;
+	// do	{
+	// 	EPD_7IN5B_V2_SendCommand(0x71);
+	// 	busy = DEV_Digital_Read(EPD_BUSY_PIN);
+	// 	busy =!(busy & 0x01);        
+    //     // if(!(count--))
+    //     // {
+    //     //     Debug("error: e-Paper busy timeout!!!\r\n");
+    //     //     break;
+    //     // }
+    //     // else
+    //         DEV_Delay_ms(100);
+	// }while(busy);
+	// DEV_Delay_ms(200);      
+	// Debug("e-Paper busy release\r\n");
 		
 }
 

+ 17 - 16
components/epaper/EPD_7in5bc.c

@@ -131,22 +131,23 @@ parameter:
 ******************************************************************************/
 void EPD_7IN5BC_ReadBusy(void)
 {
-    unsigned char count = 100;
-    UBYTE busy;
-    Debug("e-Paper busy\r\n");
-    do {
-        EPD_7IN5BC_SendCommand(0x71);
-        busy = DEV_Digital_Read(EPD_BUSY_PIN);
-        busy =!(busy & 0x01);
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            break;
-        }
-        else
-            DEV_Delay_ms(100);
-    } while(busy);
-    Debug("e-Paper busy release\r\n");
+    EPD_Busy_WaitUntil(1,1);
+    // unsigned char count = 100;
+    // UBYTE busy;
+    // Debug("e-Paper busy\r\n");
+    // do {
+    //     EPD_7IN5BC_SendCommand(0x71);
+    //     busy = DEV_Digital_Read(EPD_BUSY_PIN);
+    //     busy =!(busy & 0x01);
+    //     if(!(count--))
+    //     {
+    //         Debug("error: e-Paper busy timeout!!!\r\n");
+    //         break;
+    //     }
+    //     else
+    //         DEV_Delay_ms(100);
+    // } while(busy);
+    // Debug("e-Paper busy release\r\n");
 }
 
 /******************************************************************************

+ 55 - 17
components/epaper/epd.c

@@ -98,22 +98,60 @@ void EPD_Sleep(void) {
     eink_regs[cur_model_index].sleep();
 }
 
-void EPD_ReadBusy(void)
-{
-    uint16_t count = 1000;
-    Debug("e-Paper busy\r\n");
-	while(1)
-	{	 //=1 BUSY
-		if(DEV_Digital_Read(EPD_BUSY_PIN)==0) 
-			break;
-        if(!(count--))
-        {
-            Debug("error: e-Paper busy timeout!!!\r\n");
-            return;
+static LUAT_RT_RET_TYPE readbusy_timer_cb(LUAT_RT_CB_PARAM){
+    if (econf.timer_count++ > 200){
+        luat_stop_rtos_timer(econf.readbusy_timer);
+        luat_release_rtos_timer(econf.readbusy_timer);
+        luat_cbcwait_noarg(econf.eink_spi_ref);
+    }
+    uint8_t level = *(uint8_t *)param;
+    if (level){
+        if(DEV_Digital_Read(EPD_BUSY_PIN)) {
+            luat_stop_rtos_timer(econf.readbusy_timer);
+            luat_release_rtos_timer(econf.readbusy_timer);
+            luat_cbcwait_noarg(econf.eink_spi_ref);
+        }
+    }else{
+        DEV_Digital_Write(EPD_DC_PIN, 0);
+        DEV_Digital_Write(EPD_CS_PIN, 0);
+        DEV_SPI_WriteByte(0x71);
+        DEV_Digital_Write(EPD_CS_PIN, 1);
+        if(DEV_Digital_Read(EPD_BUSY_PIN)==0) {
+            luat_stop_rtos_timer(econf.readbusy_timer);
+            luat_release_rtos_timer(econf.readbusy_timer);
+            luat_cbcwait_noarg(econf.eink_spi_ref);
         }
-        else
-            DEV_Delay_ms(10);
-	}
-	DEV_Delay_ms(50);
-    Debug("e-Paper busy release\r\n");
+    }
+}
+
+void EPD_Busy_WaitUntil(uint8_t level,uint8_t send_cmd){
+    uint16_t count = 100;//10s
+
+    if (econf.async){
+        econf.readbusy_timer = luat_create_rtos_timer(readbusy_timer_cb, &level, NULL);
+        luat_start_rtos_timer(econf.readbusy_timer, 100, 1);
+    }else{
+        while(1){
+            if (level){
+                if (send_cmd){
+                    DEV_Digital_Write(EPD_DC_PIN, 0);
+                    DEV_Digital_Write(EPD_CS_PIN, 0);
+                    DEV_SPI_WriteByte(0x71);
+                    DEV_Digital_Write(EPD_CS_PIN, 1);
+                }
+                if(DEV_Digital_Read(EPD_BUSY_PIN)) 
+                    break;
+            }else{
+                if(DEV_Digital_Read(EPD_BUSY_PIN)==0) 
+                    break;
+            }
+            if(!(count--)){
+                Debug("error: e-Paper busy timeout!!!\r\n");
+                return;
+            }
+            else
+                DEV_Delay_ms(100);
+        }
+        DEV_Delay_ms(100);
+    }
 }

+ 1 - 1
components/epaper/epd.h

@@ -11,7 +11,7 @@ int EPD_Init(UBYTE Mode, size_t *w, size_t *h, size_t* color_count);
 void EPD_Clear(void);
 void EPD_Display(UBYTE *Image, UBYTE *Image2);
 void EPD_Sleep(void);
-void EPD_ReadBusy(void);
+void EPD_Busy_WaitUntil(uint8_t level,uint8_t send_cmd);
 
 enum EPD_MODEL {
         MODEL_1in02d = 1,