From b16056c67b00269683a8f2b4d5d7ea15d1a30a49 Mon Sep 17 00:00:00 2001 From: Ronald Date: Sun, 1 Nov 2020 00:50:01 +0100 Subject: [PATCH] use the _Wait function where possible --- .../c/lib/Config/DEV_Config.c | 38 ++++++++-- .../c/lib/Config/DEV_Config.h | 1 + .../c/lib/Config/RPI_sysfs_gpio.c | 73 +++++++++++++++++++ .../c/lib/Config/RPI_sysfs_gpio.h | 7 +- .../c/lib/Config/dev_hardware_SPI.c | 11 +-- .../c/lib/Config/sysfs_gpio.c | 73 +++++++++++++++++++ .../c/lib/Config/sysfs_gpio.h | 7 +- .../c/lib/e-Paper/EPD_1in54.c | 5 +- .../c/lib/e-Paper/EPD_1in54_V2.c | 12 +-- .../c/lib/e-Paper/EPD_1in54b.c | 6 +- .../c/lib/e-Paper/EPD_1in54b_V2.c | 6 +- .../c/lib/e-Paper/EPD_2in13.c | 5 +- .../c/lib/e-Paper/EPD_2in13_V2.c | 5 +- .../c/lib/e-Paper/EPD_2in13bc.c | 5 +- .../c/lib/e-Paper/EPD_2in66.c | 7 +- .../c/lib/e-Paper/EPD_2in7b.c | 5 +- .../c/lib/e-Paper/EPD_2in9.c | 7 +- .../c/lib/e-Paper/EPD_2in9bc.c | 5 +- .../c/lib/e-Paper/EPD_3in7.c | 6 +- .../c/lib/e-Paper/EPD_4in2bc.c | 5 +- .../c/lib/e-Paper/EPD_5in83.c | 5 +- .../c/lib/e-Paper/EPD_7in5.c | 5 +- .../c/lib/e-Paper/EPD_7in5_HD.c | 6 +- .../c/lib/e-Paper/EPD_7in5b_HD.c | 5 +- 24 files changed, 231 insertions(+), 79 deletions(-) diff --git a/RaspberryPi&JetsonNano/c/lib/Config/DEV_Config.c b/RaspberryPi&JetsonNano/c/lib/Config/DEV_Config.c index 4b972054c..17a840cdc 100644 --- a/RaspberryPi&JetsonNano/c/lib/Config/DEV_Config.c +++ b/RaspberryPi&JetsonNano/c/lib/Config/DEV_Config.c @@ -29,6 +29,7 @@ ******************************************************************************/ #include "DEV_Config.h" #include +#include /** * GPIO @@ -85,6 +86,31 @@ UBYTE DEV_Digital_Read(UWORD Pin) return Read_value; } +void DEV_Digital_Wait(UWORD Pin, UBYTE Value) +{ +#ifdef RPI +#ifdef USE_BCM2835_LIB + do { + DEV_Delay_ms(10); + } while(bcm2835_gpio_lev(Pin) != Value); +#elif USE_WIRINGPI_LIB + do { + DEV_Delay_ms(10); + } while(digitalRead(Pin) != Value); +#elif USE_DEV_LIB + SYSFS_GPIO_Wait(Pin, Value); +#endif +#endif + +#ifdef JETSON +#ifdef USE_DEV_LIB + SYSFS_GPIO_Wait(Pin, Value); +#elif USE_HARDWARE_LIB + Debug("not support"); +#endif +#endif +} + /** * SPI **/ @@ -185,10 +211,10 @@ void DEV_Delay_ms(UDOUBLE xms) #elif USE_WIRINGPI_LIB delay(xms); #elif USE_DEV_LIB - UDOUBLE i; - for(i=0; i < xms; i++) { - usleep(1000); - } + struct timespec tv; + tv.tv_nsec=(xms%1000)*1000000; + tv.tv_sec=xms/1000; + nanosleep(&tv, NULL); #endif #endif @@ -229,7 +255,7 @@ static int DEV_Equipment_Testing(void) if(i<5) { printf("Unrecognizable\r\n"); } else { - char RPI_System[10] = {"Raspbian"}; + char RPI_System[10] = {"Debian"}; for(i=0; i<6; i++) { if(RPI_System[i]!= value_str[i]) { printf("Please make JETSON !!!!!!!!!!\r\n"); @@ -366,10 +392,10 @@ void DEV_Module_Exit(void) DEV_Digital_Write(EPD_DC_PIN, 0); DEV_Digital_Write(EPD_RST_PIN, 0); #elif USE_DEV_LIB - DEV_HARDWARE_SPI_end(); DEV_Digital_Write(EPD_CS_PIN, 0); DEV_Digital_Write(EPD_DC_PIN, 0); DEV_Digital_Write(EPD_RST_PIN, 0); + DEV_HARDWARE_SPI_end(); #endif #elif JETSON diff --git a/RaspberryPi&JetsonNano/c/lib/Config/DEV_Config.h b/RaspberryPi&JetsonNano/c/lib/Config/DEV_Config.h index 105ea1964..49d9fb95e 100644 --- a/RaspberryPi&JetsonNano/c/lib/Config/DEV_Config.h +++ b/RaspberryPi&JetsonNano/c/lib/Config/DEV_Config.h @@ -96,6 +96,7 @@ extern int EPD_BUSY_PIN; /*------------------------------------------------------------------------------------------------------*/ void DEV_Digital_Write(UWORD Pin, UBYTE Value); UBYTE DEV_Digital_Read(UWORD Pin); +void DEV_Digital_Wait(UWORD Pin, UBYTE Value); void DEV_SPI_WriteByte(UBYTE Value); void DEV_SPI_Write_nByte(uint8_t *pData, uint32_t Len); diff --git a/RaspberryPi&JetsonNano/c/lib/Config/RPI_sysfs_gpio.c b/RaspberryPi&JetsonNano/c/lib/Config/RPI_sysfs_gpio.c index e5905e45c..9aaffa0ba 100644 --- a/RaspberryPi&JetsonNano/c/lib/Config/RPI_sysfs_gpio.c +++ b/RaspberryPi&JetsonNano/c/lib/Config/RPI_sysfs_gpio.c @@ -36,6 +36,7 @@ #include #include #include +#include int SYSFS_GPIO_Export(int Pin) { @@ -107,6 +108,32 @@ int SYSFS_GPIO_Direction(int Pin, int Dir) return 0; } +int SYSFS_GPIO_Edge(int Pin, int edge) +{ + const char *edge_str[] = {"rising","falling","both"}; + const int edge_str_l[] = {6, 7, 4}; + char path[DIR_MAXSIZ]; + int fd; + + snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/edge", Pin); + fd = open(path, O_WRONLY); + if (fd < 0) { + SYSFS_GPIO_Debug( "Set Edge failed: Pin%d\n", Pin); + return -1; + } + + if (edge>2) edge=2; + if (write(fd, edge_str[edge], edge_str_l[edge]) < 0) { + SYSFS_GPIO_Debug("failed to set edge!\r\n"); + return -1; + } + + SYSFS_GPIO_Debug("Pin%d:%s edge\r\n", Pin, edge_str[edge]); + + close(fd); + return 0; +} + int SYSFS_GPIO_Read(int Pin) { char path[DIR_MAXSIZ]; @@ -122,6 +149,7 @@ int SYSFS_GPIO_Read(int Pin) if (read(fd, value_str, 3) < 0) { SYSFS_GPIO_Debug( "failed to read value!\n"); + close(fd); return -1; } @@ -129,6 +157,50 @@ int SYSFS_GPIO_Read(int Pin) return(atoi(value_str)); } +int SYSFS_GPIO_Wait(int Pin, int value) +{ + char path[DIR_MAXSIZ]; + char value_str[3]; + int fd; + struct pollfd pfd[1]; + + SYSFS_GPIO_Edge(Pin, SYSFS_GPIO_BOTH); + snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/value", Pin); + fd = open(path, O_RDONLY); + if (fd < 0) { + SYSFS_GPIO_Debug( "Read failed Pin%d\n", Pin); + return -1; + } + + while (1) { + int n; + if (read(fd, value_str, 3) < 0) { + SYSFS_GPIO_Debug( "failed to read value!\n"); + close(fd); + return -1; + } + if (atoi(value_str) == value) break; + pfd[0].fd=fd; + pfd[0].events=POLLPRI; + n = poll(pfd, 1, -1); + if (n < 0) { + SYSFS_GPIO_Debug( "poll failed: %m!\n"); + close(fd); + return -1; + } + /* lseek(0) doesn't seem to work reliably */ + close(fd); + fd = open(path, O_RDONLY); + if (fd < 0) { + SYSFS_GPIO_Debug( "open failed: %m\n"); + return -1; + } + } + + close(fd); + return 0; +} + int SYSFS_GPIO_Write(int Pin, int value) { const char s_values_str[] = "01"; @@ -144,6 +216,7 @@ int SYSFS_GPIO_Write(int Pin, int value) if (write(fd, &s_values_str[value == SYSFS_GPIO_LOW ? 0 : 1], 1) < 0) { SYSFS_GPIO_Debug( "failed to write value!\n"); + close(fd); return -1; } diff --git a/RaspberryPi&JetsonNano/c/lib/Config/RPI_sysfs_gpio.h b/RaspberryPi&JetsonNano/c/lib/Config/RPI_sysfs_gpio.h index 5c33a97f0..d768e392c 100644 --- a/RaspberryPi&JetsonNano/c/lib/Config/RPI_sysfs_gpio.h +++ b/RaspberryPi&JetsonNano/c/lib/Config/RPI_sysfs_gpio.h @@ -39,6 +39,10 @@ #define SYSFS_GPIO_LOW 0 #define SYSFS_GPIO_HIGH 1 +#define SYSFS_GPIO_RISING 0 +#define SYSFS_GPIO_FALLING 1 +#define SYSFS_GPIO_BOTH 2 + #define NUM_MAXBUF 4 #define DIR_MAXSIZ 60 @@ -78,5 +82,6 @@ int SYSFS_GPIO_Unexport(int Pin); int SYSFS_GPIO_Direction(int Pin, int Dir); int SYSFS_GPIO_Read(int Pin); int SYSFS_GPIO_Write(int Pin, int value); +int SYSFS_GPIO_Wait(int Pin, int value); -#endif \ No newline at end of file +#endif diff --git a/RaspberryPi&JetsonNano/c/lib/Config/dev_hardware_SPI.c b/RaspberryPi&JetsonNano/c/lib/Config/dev_hardware_SPI.c index 125fec04b..89265e5f6 100644 --- a/RaspberryPi&JetsonNano/c/lib/Config/dev_hardware_SPI.c +++ b/RaspberryPi&JetsonNano/c/lib/Config/dev_hardware_SPI.c @@ -330,18 +330,13 @@ function: SPI port sends one byte of data uint8_t DEV_HARDWARE_SPI_TransferByte(uint8_t buf) { uint8_t rbuf[1]; - tr.len = 1; - tr.tx_buf = (unsigned long)&buf; - tr.rx_buf = (unsigned long)rbuf; - - //ioctl Operation, transmission of data - if ( ioctl(hardware_SPI.fd, SPI_IOC_MESSAGE(1), &tr) < 1 ) - DEV_HARDWARE_SPI_Debug("can't send spi message\r\n"); + rbuf[0] = buf; + DEV_HARDWARE_SPI_Transfer(rbuf, 1); return rbuf[0]; } /****************************************************************************** -function: The SPI port reads a byte +function: The SPI port reads some bytes parameter: Info: Return read data ******************************************************************************/ diff --git a/RaspberryPi&JetsonNano/c/lib/Config/sysfs_gpio.c b/RaspberryPi&JetsonNano/c/lib/Config/sysfs_gpio.c index 279cbe0d0..386ab1e2d 100644 --- a/RaspberryPi&JetsonNano/c/lib/Config/sysfs_gpio.c +++ b/RaspberryPi&JetsonNano/c/lib/Config/sysfs_gpio.c @@ -36,6 +36,7 @@ #include #include #include +#include int SYSFS_GPIO_Export(int Pin) { @@ -107,6 +108,32 @@ int SYSFS_GPIO_Direction(int Pin, int Dir) return 0; } +int SYSFS_GPIO_Edge(int Pin, int edge) +{ + const char *edge_str[] = {"rising","falling","both"}; + const int edge_str_l[] = {6, 7, 4}; + char path[DIR_MAXSIZ]; + int fd; + + snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/edge", Pin); + fd = open(path, O_WRONLY); + if (fd < 0) { + SYSFS_GPIO_Debug( "Set Edge failed: Pin%d\n", Pin); + return -1; + } + + if (edge>2) edge=2; + if (write(fd, edge_str[edge], edge_str_l[edge]) < 0) { + SYSFS_GPIO_Debug("failed to set edge!\r\n"); + return -1; + } + + SYSFS_GPIO_Debug("Pin%d:%s edge\r\n", Pin, edge_str[edge]); + + close(fd); + return 0; +} + int SYSFS_GPIO_Read(int Pin) { char path[DIR_MAXSIZ]; @@ -122,6 +149,7 @@ int SYSFS_GPIO_Read(int Pin) if (read(fd, value_str, 3) < 0) { SYSFS_GPIO_Debug( "failed to read value!\n"); + close(fd); return -1; } @@ -129,6 +157,50 @@ int SYSFS_GPIO_Read(int Pin) return(atoi(value_str)); } +int SYSFS_GPIO_Wait(int Pin, int value) +{ + char path[DIR_MAXSIZ]; + char value_str[3]; + int fd; + struct pollfd pfd[1]; + + SYSFS_GPIO_Edge(Pin, SYSFS_GPIO_BOTH); + snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/value", Pin); + fd = open(path, O_RDONLY); + if (fd < 0) { + SYSFS_GPIO_Debug( "Read failed Pin%d\n", Pin); + return -1; + } + + while (1) { + int n; + if (read(fd, value_str, 3) < 0) { + SYSFS_GPIO_Debug( "failed to read value!\n"); + close(fd); + return -1; + } + if (atoi(value_str) == value) break; + pfd[0].fd=fd; + pfd[0].events=POLLPRI; + n = poll(pfd, 1, -1); + if (n < 0) { + SYSFS_GPIO_Debug( "poll failed: %m!\n"); + close(fd); + return -1; + } + /* lseek(0) doesn't seem to work reliably */ + close(fd); + fd = open(path, O_RDONLY); + if (fd < 0) { + SYSFS_GPIO_Debug( "open failed: %m\n"); + return -1; + } + } + + close(fd); + return 0; +} + int SYSFS_GPIO_Write(int Pin, int value) { const char s_values_str[] = "01"; @@ -144,6 +216,7 @@ int SYSFS_GPIO_Write(int Pin, int value) if (write(fd, &s_values_str[value == LOW ? 0 : 1], 1) < 0) { SYSFS_GPIO_Debug( "failed to write value!\n"); + close(fd); return -1; } diff --git a/RaspberryPi&JetsonNano/c/lib/Config/sysfs_gpio.h b/RaspberryPi&JetsonNano/c/lib/Config/sysfs_gpio.h index cb24d84fe..e2e68d5cb 100644 --- a/RaspberryPi&JetsonNano/c/lib/Config/sysfs_gpio.h +++ b/RaspberryPi&JetsonNano/c/lib/Config/sysfs_gpio.h @@ -39,6 +39,10 @@ #define LOW 0 #define HIGH 1 +#define SYSFS_GPIO_RISING 0 +#define SYSFS_GPIO_FALLING 1 +#define SYSFS_GPIO_BOTH 2 + #define NUM_MAXBUF 4 #define DIR_MAXSIZ 60 @@ -80,5 +84,6 @@ int SYSFS_GPIO_Unexport(int Pin); int SYSFS_GPIO_Direction(int Pin, int Dir); int SYSFS_GPIO_Read(int Pin); int SYSFS_GPIO_Write(int Pin, int value); +int SYSFS_GPIO_Wait(int Pin, int value); -#endif \ No newline at end of file +#endif diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54.c index a6dbc1c26..4ce3262c6 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54.c @@ -147,10 +147,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_1IN54_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 0); Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54_V2.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54_V2.c index c1c9d9541..86be588a8 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54_V2.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54_V2.c @@ -76,17 +76,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ static void EPD_1IN54_V2_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; 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 - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54b.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54b.c index c9fc13a16..95b7043ae 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54b.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54b.c @@ -149,11 +149,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ static void EPD_1IN54B_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return; Debug("e-Paper busy\r\n"); - while(1) { - if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) - break; - } + DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle DEV_Delay_ms(200); Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54b_V2.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54b_V2.c index 439312c58..43ffd65c5 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54b_V2.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_1in54b_V2.c @@ -77,11 +77,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ static void EPD_1IN54B_V2_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; Debug("e-Paper busy\r\n"); - while(1) { - if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) - break; - } + DEV_Digital_Wait(EPD_BUSY_PIN, 0); DEV_Delay_ms(200); Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13.c index 70ee55157..95a007b64 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13.c @@ -110,10 +110,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_2IN13_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13_V2.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13_V2.c index a0bf1a424..9951aa04e 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13_V2.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13_V2.c @@ -134,10 +134,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_2IN13_V2_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 0); Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13bc.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13bc.c index bb6cb43c7..83b07eba7 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13bc.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in13bc.c @@ -129,10 +129,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_2IN13BC_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in66.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in66.c index 14bf30c4e..62d437734 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in66.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in66.c @@ -96,11 +96,10 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ static void EPD_2IN66_ReadBusy(void) { + DEV_Delay_ms(200); + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; Debug("e-Paper busy\r\n"); - DEV_Delay_ms(200); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy - DEV_Delay_ms(5); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle DEV_Delay_ms(100); Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in7b.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in7b.c index 9a41a702b..c35606ef2 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in7b.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in7b.c @@ -190,10 +190,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ static void EPD_2IN7B_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //0: busy, 1: idle - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in9.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in9.c index 24171a46a..27d618c63 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in9.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in9.c @@ -142,11 +142,10 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_2IN9_ReadBusy(void) { - Debug("e-Paper busy\r\n"); DEV_Delay_ms(100); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy - DEV_Delay_ms(100); - } + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; + Debug("e-Paper busy\r\n"); + DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in9bc.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in9bc.c index 9746e7207..968a47ef0 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in9bc.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_2in9bc.c @@ -130,10 +130,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_2IN9BC_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_3in7.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_3in7.c index b6a2a6120..f8f76da43 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_3in7.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_3in7.c @@ -133,11 +133,9 @@ static void EPD_3IN7_SendData(UBYTE Data) static void EPD_3IN7_ReadBusy_HIGH(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; Debug("e-Paper busy\r\n"); - UBYTE busy; - do { - busy = DEV_Digital_Read(EPD_BUSY_PIN); - } while(busy); + DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle DEV_Delay_ms(200); Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_4in2bc.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_4in2bc.c index dc4f10def..aa739c4e8 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_4in2bc.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_4in2bc.c @@ -130,10 +130,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_4IN2BC_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //0: busy, 1: idle - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_5in83.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_5in83.c index 9d4cb8c29..1b0c499aa 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_5in83.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_5in83.c @@ -133,10 +133,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ static void EPD_5IN83_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5.c index 3da6d6a03..bea895b42 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5.c @@ -133,10 +133,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_7IN5_ReadBusy(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy - DEV_Delay_ms(100); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle Debug("e-Paper busy release\r\n"); } diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5_HD.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5_HD.c index d9f4bc556..d4c8c37fc 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5_HD.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5_HD.c @@ -77,10 +77,10 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ static void EPD_7IN5_HD_WaitUntilIdle(void) { + DEV_Delay_ms(10); + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; Debug("e-Paper busy\r\n"); - do{ - DEV_Delay_ms(10); - }while(DEV_Digital_Read(EPD_BUSY_PIN) == 1); + DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle DEV_Delay_ms(200); Debug("e-Paper busy release\r\n"); diff --git a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5b_HD.c b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5b_HD.c index ea0431171..34f872721 100644 --- a/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5b_HD.c +++ b/RaspberryPi&JetsonNano/c/lib/e-Paper/EPD_7in5b_HD.c @@ -77,10 +77,9 @@ function : Wait until the busy_pin goes LOW ******************************************************************************/ void EPD_7IN5B_HD_WaitUntilIdle(void) { + if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return; Debug("e-Paper busy\r\n"); - while(DEV_Digital_Read(EPD_BUSY_PIN)){ - DEV_Delay_ms(10); - } + DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle DEV_Delay_ms(200); Debug("e-Paper busy release\r\n"); }