Преглед на файлове

Support for Pi5 and the latest Raspberry PI system, Arudino upper and lower case character issues fixed

shhds преди 1 година
родител
ревизия
9303f14a45

+ 2 - 2
Arduino/epd1in64g/epdif.cpp

@@ -26,7 +26,7 @@
  */
 
 #include "epdif.h"
-#include <spi.h>
+#include <SPI.h>
 
 EpdIf::EpdIf() {
 };
@@ -61,4 +61,4 @@ int EpdIf::IfInit(void) {
     SPI.begin();
     SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
     return 0;
-}
+}

+ 1 - 1
Arduino/epd1in64g/epdif.h

@@ -28,7 +28,7 @@
 #ifndef EPDIF_H
 #define EPDIF_H
 
-#include <arduino.h>
+#include <Arduino.h>
 
 // Pin definition
 #define RST_PIN         8

+ 1 - 1
Arduino/epd2in13d/epd2in13d.cpp

@@ -28,7 +28,7 @@
 #
 ******************************************************************************/
 #include "epd2in13d.h"
-#include <arduino.h>
+#include <Arduino.h>
 /**
  * full screen update LUT
 **/

+ 2 - 2
Arduino/epd2in36g/epdif.cpp

@@ -26,7 +26,7 @@
  */
 
 #include "epdif.h"
-#include <spi.h>
+#include <SPI.h>
 
 EpdIf::EpdIf() {
 };
@@ -61,4 +61,4 @@ int EpdIf::IfInit(void) {
     SPI.begin();
     SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
     return 0;
-}
+}

+ 1 - 1
Arduino/epd2in36g/epdif.h

@@ -28,7 +28,7 @@
 #ifndef EPDIF_H
 #define EPDIF_H
 
-#include <arduino.h>
+#include <Arduino.h>
 
 // Pin definition
 #define RST_PIN         8

+ 2 - 2
Arduino/epd3in0g/epdif.cpp

@@ -26,7 +26,7 @@
  */
 
 #include "epdif.h"
-#include <spi.h>
+#include <SPI.h>
 
 EpdIf::EpdIf() {
 };
@@ -61,4 +61,4 @@ int EpdIf::IfInit(void) {
     SPI.begin();
     SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
     return 0;
-}
+}

+ 1 - 1
Arduino/epd3in0g/epdif.h

@@ -28,7 +28,7 @@
 #ifndef EPDIF_H
 #define EPDIF_H
 
-#include <arduino.h>
+#include <Arduino.h>
 
 // Pin definition
 #define RST_PIN         8

+ 1 - 1
Arduino/epd4in37g/epdif.cpp

@@ -26,7 +26,7 @@
  */
 
 #include "epdif.h"
-#include <spi.h>
+#include <SPI.h>
 
 EpdIf::EpdIf() {
 };

+ 1 - 1
Arduino/epd4in37g/epdif.h

@@ -28,7 +28,7 @@
 #ifndef EPDIF_H
 #define EPDIF_H
 
-#include <arduino.h>
+#include <Arduino.h>
 
 // Pin definition
 #define RST_PIN         8

+ 1 - 1
Arduino/epd5in83/epdif.cpp

@@ -26,7 +26,7 @@
  */
 
 #include "epdif.h"
-#include <spi.h>
+#include <SPI.h>
 
 EpdIf::EpdIf() {
 };

+ 1 - 1
Arduino/epd5in83/epdif.h

@@ -28,7 +28,7 @@
 #ifndef EPDIF_H
 #define EPDIF_H
 
-#include <arduino.h>
+#include <Arduino.h>
 
 // Pin definition
 #define RST_PIN         8

+ 1 - 1
Arduino/epd7in3f/epdif.cpp

@@ -26,7 +26,7 @@
  */
 
 #include "epdif.h"
-#include <spi.h>
+#include <SPI.h>
 
 EpdIf::EpdIf() {
 };

+ 1 - 1
Arduino/epd7in3f/epdif.h

@@ -28,7 +28,7 @@
 #ifndef EPDIF_H
 #define EPDIF_H
 
-#include <arduino.h>
+#include <Arduino.h>
 
 // Pin definition
 #define RST_PIN         8

+ 2 - 2
Arduino/epd7in3g/epdif.cpp

@@ -26,7 +26,7 @@
  */
 
 #include "epdif.h"
-#include <spi.h>
+#include <SPI.h>
 
 EpdIf::EpdIf() {
 };
@@ -61,4 +61,4 @@ int EpdIf::IfInit(void) {
     SPI.begin();
     SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
     return 0;
-}
+}

+ 1 - 1
Arduino/epd7in3g/epdif.h

@@ -28,7 +28,7 @@
 #ifndef EPDIF_H
 #define EPDIF_H
 
-#include <arduino.h>
+#include <Arduino.h>
 
 // Pin definition
 #define RST_PIN         8

+ 10 - 6
README.md

@@ -1,9 +1,13 @@
-# e-Paper  
-waveshare electronics
+# 说明 explain
+Development 分支用于存放用户的提交的修改代码,经验证后,我们将移植到主分支中;非常感谢您对我们的支持</br>
+The Development branch is used to store the modified code submitted by users. After verification, we will migrate it to the main branch. Thank you very much for your support 
+
+# e-Paper  
+waveshare electronics</br>
 ![waveshare_logo.png](waveshare_logo.png)
 
 ## 中文:  
-Jetson Nano、Raspberry Pi、Arduino、STM32例程
+Jetson Nano、Raspberry Pi、Arduino、STM32例程</br>
 * RaspberryPi_JetsonNano  
     > C
     > Python 
@@ -12,12 +16,12 @@ Jetson Nano、Raspberry Pi、Arduino、STM32例程
 * STM32:  
     > STM32F103ZET6 
     
-更多资料请在官网上搜索:  
+更多资料请在官网上搜索:  </br>
 http://www.waveshare.net
 
 
 ## English:  
-Jetson Nano、Raspberry Pi、Arduino、STM32 Demo:  
+Jetson Nano、Raspberry Pi、Arduino、STM32 Demo:  </br>
 * RaspberryPi_JetsonNano:  
     > C
     > Python
@@ -26,7 +30,7 @@ Jetson Nano、Raspberry Pi、Arduino、STM32 Demo:
 * STM32:  
     > STM32F103ZET6 
     
-For more information, please search on the official website:   
+For more information, please search on the official website:   </br>
 https://www.waveshare.com
 
 

+ 5 - 5
RaspberryPi_JetsonNano/c/Makefile

@@ -184,15 +184,15 @@ endif
 
 OBJ_C = $(wildcard ${OBJ_C_EPD} ${DIR_GUI}/*.c ${OBJ_C_Examples} ${DIR_Examples}/main.c ${DIR_Examples}/ImageData2.c ${DIR_Examples}/ImageData.c ${DIR_FONTS}/*.c )
 OBJ_O = $(patsubst %.c,${DIR_BIN}/%.o,$(notdir ${OBJ_C}))
-RPI_DEV_C = $(wildcard $(DIR_BIN)/dev_hardware_SPI.o $(DIR_BIN)/RPI_sysfs_gpio.o $(DIR_BIN)/DEV_Config.o )
+RPI_DEV_C = $(wildcard $(DIR_BIN)/dev_hardware_SPI.o $(DIR_BIN)/RPI_gpiod.o $(DIR_BIN)/DEV_Config.o )
 JETSON_DEV_C = $(wildcard $(DIR_BIN)/sysfs_software_spi.o $(DIR_BIN)/sysfs_gpio.o $(DIR_BIN)/DEV_Config.o )
 
 
 DEBUG = -D DEBUG
 
-USELIB_RPI = USE_BCM2835_LIB
+# USELIB_RPI = USE_BCM2835_LIB
 # USELIB_RPI = USE_WIRINGPI_LIB
-# USELIB_RPI = USE_DEV_LIB
+USELIB_RPI = USE_DEV_LIB
 
 LIB_RPI=-Wl,--gc-sections
 ifeq ($(USELIB_RPI), USE_BCM2835_LIB)
@@ -200,7 +200,7 @@ ifeq ($(USELIB_RPI), USE_BCM2835_LIB)
 else ifeq ($(USELIB_RPI), USE_WIRINGPI_LIB)
 	LIB_RPI += -lwiringPi -lm 
 else ifeq ($(USELIB_RPI), USE_DEV_LIB)
-	LIB_RPI += -lm 
+	LIB_RPI += -lgpiod -lm 
 endif
 DEBUG_RPI = -D $(USELIB_RPI) -D RPI
 
@@ -247,7 +247,7 @@ ${DIR_BIN}/%.o:$(DIR_GUI)/%.c
 
 RPI_DEV:
 	$(CC) $(CFLAGS) $(DEBUG_RPI) -c	 $(DIR_Config)/dev_hardware_SPI.c -o $(DIR_BIN)/dev_hardware_SPI.o $(LIB_RPI) $(DEBUG)
-	$(CC) $(CFLAGS) $(DEBUG_RPI) -c	 $(DIR_Config)/RPI_sysfs_gpio.c -o $(DIR_BIN)/RPI_sysfs_gpio.o $(LIB_RPI) $(DEBUG)
+	$(CC) $(CFLAGS) $(DEBUG_RPI) -c	 $(DIR_Config)/RPI_gpiod.c -o $(DIR_BIN)/RPI_gpiod.o $(LIB_RPI) $(DEBUG)
 	$(CC) $(CFLAGS) $(DEBUG_RPI) -c	 $(DIR_Config)/DEV_Config.c -o $(DIR_BIN)/DEV_Config.o $(LIB_RPI) $(DEBUG)
 	
 JETSON_DEV:

+ 18 - 12
RaspberryPi_JetsonNano/c/lib/Config/DEV_Config.c

@@ -28,7 +28,7 @@
 #
 ******************************************************************************/
 #include "DEV_Config.h"
-
+#include "RPI_gpiod.h"
 /**
  * GPIO
 **/
@@ -49,7 +49,7 @@ void DEV_Digital_Write(UWORD Pin, UBYTE Value)
 #elif USE_WIRINGPI_LIB
 	digitalWrite(Pin, Value);
 #elif USE_DEV_LIB
-	SYSFS_GPIO_Write(Pin, Value);
+	GPIOD_Write(Pin, Value);
 #endif
 #endif
 
@@ -71,7 +71,7 @@ UBYTE DEV_Digital_Read(UWORD Pin)
 #elif USE_WIRINGPI_LIB
 	Read_value = digitalRead(Pin);
 #elif USE_DEV_LIB
-	Read_value = SYSFS_GPIO_Read(Pin);
+	Read_value = GPIOD_Read(Pin);
 #endif
 #endif
 
@@ -153,14 +153,13 @@ void DEV_GPIO_Mode(UWORD Pin, UWORD Mode)
 		// Debug (" %d OUT \r\n",Pin);
 	}
 #elif USE_DEV_LIB
-	SYSFS_GPIO_Export(Pin);
-	if(Mode == 0 || Mode == SYSFS_GPIO_IN) {
-		SYSFS_GPIO_Direction(Pin, SYSFS_GPIO_IN);
-		// Debug("IN Pin = %d\r\n",Pin);
-	} else {
-		SYSFS_GPIO_Direction(Pin, SYSFS_GPIO_OUT);
-		// Debug("OUT Pin = %d\r\n",Pin);
-	}
+    if(Mode == 0 || Mode == GPIOD_IN) {
+        GPIOD_Direction(Pin, GPIOD_IN);
+        // Debug("IN Pin = %d\r\n",Pin);
+    } else {
+        GPIOD_Direction(Pin, GPIOD_OUT);
+        // Debug("OUT Pin = %d\r\n",Pin);
+    }
 #endif
 #endif
 
@@ -266,14 +265,15 @@ void DEV_GPIO_Init(void)
 	EPD_BUSY_PIN    = GPIO24;
 #endif
 
+    DEV_GPIO_Mode(EPD_BUSY_PIN, 0);
 	DEV_GPIO_Mode(EPD_RST_PIN, 1);
 	DEV_GPIO_Mode(EPD_DC_PIN, 1);
 	DEV_GPIO_Mode(EPD_CS_PIN, 1);
     DEV_GPIO_Mode(EPD_PWR_PIN, 1);
-	DEV_GPIO_Mode(EPD_BUSY_PIN, 0);
 
 	DEV_Digital_Write(EPD_CS_PIN, 1);
     DEV_Digital_Write(EPD_PWR_PIN, 1);
+    
 }
 /******************************************************************************
 function:	Module Initialize, the library and initialize the pins, SPI protocol
@@ -320,6 +320,7 @@ UBYTE DEV_Module_Init(void)
 	// wiringPiSPISetupMode(0, 32000000, 0);
 #elif USE_DEV_LIB
 	printf("Write and read /dev/spidev0.0 \r\n");
+    GPIOD_Export();
 	DEV_GPIO_Init();
 	DEV_HARDWARE_SPI_begin("/dev/spidev0.0");
     DEV_HARDWARE_SPI_setSpeed(10000000);
@@ -371,6 +372,11 @@ void DEV_Module_Exit(void)
     DEV_Digital_Write(EPD_PWR_PIN, 0);
 	DEV_Digital_Write(EPD_DC_PIN, 0);
 	DEV_Digital_Write(EPD_RST_PIN, 0);
+    GPIOD_Unexport(EPD_PWR_PIN);
+    GPIOD_Unexport(EPD_DC_PIN);
+    GPIOD_Unexport(EPD_RST_PIN);
+    GPIOD_Unexport(EPD_BUSY_PIN);
+    GPIOD_Unexport_GPIO();
 #endif
 
 #elif JETSON

+ 1 - 1
RaspberryPi_JetsonNano/c/lib/Config/DEV_Config.h

@@ -63,7 +63,7 @@
         #include <wiringPi.h>
         #include <wiringPiSPI.h>
     #elif USE_DEV_LIB
-        #include "RPI_sysfs_gpio.h"
+        #include "RPI_gpiod.h"
         #include "dev_hardware_SPI.h"
     #endif
 #endif

+ 170 - 0
RaspberryPi_JetsonNano/c/lib/Config/RPI_gpiod.c

@@ -0,0 +1,170 @@
+/*****************************************************************************
+* | File        :   RPI_GPIOD.c
+* | Author      :   Waveshare team
+* | Function    :   Drive GPIO
+* | Info        :   Read and write gpio
+*----------------
+* |	This version:   V1.0
+* | Date        :   2023-11-15
+* | Info        :   Basic version
+*
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documnetation files (the "Software"), to deal
+# GPIOD_IN the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to  whom the Software is
+# furished to do so, subject to the folGPIOD_LOWing conditions:
+#
+# The above copyright notice and this permission notice shall be included GPIOD_IN
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. GPIOD_IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY WHETHER GPIOD_IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# GPIOD_OUT OF OR GPIOD_IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS GPIOD_IN
+# THE SOFTWARE.
+#
+******************************************************************************/
+#include "RPI_gpiod.h"
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <gpiod.h>
+
+struct gpiod_chip *gpiochip;
+struct gpiod_line *gpioline;
+int ret;
+
+int GPIOD_Export()
+{   
+    char buffer[NUM_MAXBUF];
+    FILE *fp;
+
+    fp = popen("cat /proc/cpuinfo | grep 'Raspberry Pi 5'", "r");
+    if (fp == NULL) {
+        GPIOD_Debug("It is not possible to determine the model of the Raspberry PI\n");
+        return -1;
+    }
+
+    if(fgets(buffer, sizeof(buffer), fp) != NULL)
+    {
+        gpiochip = gpiod_chip_open("/dev/gpiochip4");
+        if (gpiochip == NULL)
+        {
+            GPIOD_Debug( "gpiochip4 Export Failed\n");
+            return -1;
+        }
+    }
+    else
+    {
+        gpiochip = gpiod_chip_open("/dev/gpiochip0");
+        if (gpiochip == NULL)
+        {
+            GPIOD_Debug( "gpiochip0 Export Failed\n");
+            return -1;
+        }
+    }
+
+        
+    return 0;
+}
+
+int GPIOD_Unexport(int Pin)
+{
+    gpioline = gpiod_chip_get_line(gpiochip, Pin);
+    if (gpioline == NULL)
+    {
+        GPIOD_Debug( "Export Failed: Pin%d\n", Pin);
+        return -1;
+    }
+
+    gpiod_line_release(gpioline);
+    
+    GPIOD_Debug( "Unexport: Pin%d\r\n", Pin);
+    
+    return 0;
+}
+
+int GPIOD_Unexport_GPIO(void)
+{
+    gpiod_line_release(gpioline);
+    gpiod_chip_close(gpiochip);
+
+    return 0;
+}
+
+int GPIOD_Direction(int Pin, int Dir)
+{
+    gpioline = gpiod_chip_get_line(gpiochip, Pin);
+    if (gpioline == NULL)
+    {
+        GPIOD_Debug( "Export Failed: Pin%d\n", Pin);
+        return -1;
+    }
+
+    if(Dir == GPIOD_IN)
+    {
+        ret = gpiod_line_request_input(gpioline, "gpio");
+        if (ret != 0)
+        {
+            GPIOD_Debug( "Export Failed: Pin%d\n", Pin);
+            return -1;
+        }        
+        GPIOD_Debug("Pin%d:intput\r\n", Pin);
+    }
+    else
+    {
+        ret = gpiod_line_request_output(gpioline, "gpio", 0);
+        if (ret != 0)
+        {
+            GPIOD_Debug( "Export Failed: Pin%d\n", Pin);
+            return -1;
+        }        
+        GPIOD_Debug("Pin%d:Output\r\n", Pin);
+    }
+    return 0;
+}
+
+int GPIOD_Read(int Pin)
+{
+    gpioline = gpiod_chip_get_line(gpiochip, Pin);
+    if (gpioline == NULL)
+    {
+        GPIOD_Debug( "Export Failed: Pin%d\n", Pin);
+        return -1;
+    }
+
+    ret = gpiod_line_get_value(gpioline);
+    if (ret < 0)
+    {
+        GPIOD_Debug( "failed to read value!\n");
+        return -1;
+    }
+
+    return(ret);
+}
+
+int GPIOD_Write(int Pin, int value)
+{
+    gpioline = gpiod_chip_get_line(gpiochip, Pin);
+    if (gpioline == NULL)
+    {
+        GPIOD_Debug( "Export Failed: Pin%d\n", Pin);
+        return -1;
+    }     
+
+    ret = gpiod_line_set_value(gpioline, value);
+    if (ret != 0)
+    {
+        GPIOD_Debug( "failed to write value! : Pin%d\n", Pin);
+        return -1;
+    }
+    return 0;
+}

+ 88 - 0
RaspberryPi_JetsonNano/c/lib/Config/RPI_gpiod.h

@@ -0,0 +1,88 @@
+/*****************************************************************************
+* | File        :   gpiod.h
+* | Author      :   Waveshare team
+* | Function    :   Drive GPIO
+* | Info        :   Read and write gpio
+*----------------
+* |	This version:   V1.0
+* | Date        :   2023-11-15
+* | Info        :   Basic version
+*d
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documnetation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to  whom the Software is
+# furished to do so, subject to the following conditions:
+#D
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+************************D******************************************************/
+#ifndef __GPIOD_
+#define __GPIOD_
+
+#include <stdio.h>
+#include <gpiod.h>
+
+#define GPIOD_IN  0
+#define GPIOD_OUT 1
+
+#define GPIOD_LOW  0
+#define GPIOD_HIGH 1
+
+#define NUM_MAXBUF  4
+#define DIR_MAXSIZ  60
+
+#define GPIOD_DEBUG 0
+#if GPIOD_DEBUG 
+	#define GPIOD_Debug(__info,...) printf("Debug: " __info,##__VA_ARGS__)
+#else
+	#define GPIOD_Debug(__info,...)  
+#endif 
+
+// BCM GPIO for Jetson nano
+#define GPIO4 4 // 7, 4
+#define GPIO17 7 // 11, 17
+#define GPIO18 18 // 12, 18
+#define GPIO27 27 // 13, 27
+#define GPIO22 22 // 15, 22
+#define GPIO23 23 // 16, 23
+#define GPIO24 24 // 18, 24
+#define SPI0_MOSI 10 // 19, 10
+#define SPI0_MISO 9 // 21, 9
+#define GPIO25 28 // 22, 25
+#define SPI0_SCK 11 // 23, 11
+#define SPI0_CS0 8 // 24, 8
+#define SPI0_CS1 7 // 26, 7
+#define GPIO5 5 // 29, 5
+#define GPIO6 6 // 31, 6
+#define GPIO12 12 // 32, 12
+#define GPIO13 13 // 33, 13
+#define GPIO19 19 // 35, 19
+#define GPIO16 16 // 36, 16
+#define GPIO26 26 // 37, 26
+#define GPIO20 20 // 38, 20
+#define GPIO21 21 // 40, 21
+
+extern struct gpiod_chip *gpiochip;
+extern struct gpiod_line *gpioline;
+extern int ret;
+
+int GPIOD_Export();
+int GPIOD_Unexport(int Pin);
+int GPIOD_Unexport_GPIO(void);
+int GPIOD_Direction(int Pin, int Dir);
+int GPIOD_Read(int Pin);
+int GPIOD_Write(int Pin, int value);
+
+#endif

+ 5 - 1
RaspberryPi_JetsonNano/c/lib/Config/dev_hardware_SPI.c

@@ -72,20 +72,24 @@ void DEV_HARDWARE_SPI_begin(char *SPI_device)
     int ret = 0; 
     if((hardware_SPI.fd = open(SPI_device, O_RDWR )) < 0)  {
         perror("Failed to open SPI device.\n");  
+        printf("Failed to open SPI device\r\n");
         DEV_HARDWARE_SPI_Debug("Failed to open SPI device\r\n");
         exit(1); 
     } else {
+        printf("open : %s\r\n", SPI_device);
         DEV_HARDWARE_SPI_Debug("open : %s\r\n", SPI_device);
     }
     hardware_SPI.mode = 0;
     
     ret = ioctl(hardware_SPI.fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
     if (ret == -1) {
+        printf("can't set bits per word\r\n");
         DEV_HARDWARE_SPI_Debug("can't set bits per word\r\n"); 
     }
  
     ret = ioctl(hardware_SPI.fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
     if (ret == -1) {
+        printf("can't get bits per word\r\n");
         DEV_HARDWARE_SPI_Debug("can't get bits per word\r\n"); 
     }
     tr.bits_per_word = bits;
@@ -94,7 +98,7 @@ void DEV_HARDWARE_SPI_begin(char *SPI_device)
     DEV_HARDWARE_SPI_ChipSelect(SPI_CS_Mode_LOW);
     DEV_HARDWARE_SPI_SetBitOrder(SPI_BIT_ORDER_LSBFIRST);
     DEV_HARDWARE_SPI_setSpeed(20000000);
-    DEV_HARDWARE_SPI_SetDataInterval(0);
+    DEV_HARDWARE_SPI_SetDataInterval(5);
 }
 
 void DEV_HARDWARE_SPI_beginSet(char *SPI_device, SPIMode mode, uint32_t speed)

BIN
RaspberryPi_JetsonNano/python/lib/waveshare_epd/__pycache__/__init__.cpython-311.pyc


BIN
RaspberryPi_JetsonNano/python/lib/waveshare_epd/__pycache__/epd2in13_V4.cpython-311.pyc


BIN
RaspberryPi_JetsonNano/python/lib/waveshare_epd/__pycache__/epdconfig.cpython-311.pyc


+ 58 - 18
RaspberryPi_JetsonNano/python/lib/waveshare_epd/epdconfig.py

@@ -31,6 +31,7 @@ import os
 import logging
 import sys
 import time
+import subprocess
 
 logger = logging.getLogger(__name__)
 
@@ -45,16 +46,48 @@ class RaspberryPi:
 
     def __init__(self):
         import spidev
-        import RPi.GPIO
+        import gpiozero
 
-        self.GPIO = RPi.GPIO
         self.SPI = spidev.SpiDev()
+        self.GPIO_RST_PIN    = gpiozero.LED(self.RST_PIN)
+        self.GPIO_DC_PIN     = gpiozero.LED(self.DC_PIN)
+        # self.GPIO_CS_PIN     = gpiozero.LED(self.CS_PIN)
+        self.GPIO_PWR_PIN    = gpiozero.LED(self.PWR_PIN)
+        self.GPIO_BUSY_PIN   = gpiozero.Button(self.BUSY_PIN, pull_up = False)
 
     def digital_write(self, pin, value):
-        self.GPIO.output(pin, value)
+        if pin == self.RST_PIN:
+            if value:
+                self.GPIO_RST_PIN.on()
+            else:
+                self.GPIO_RST_PIN.off()
+        elif pin == self.DC_PIN:
+            if value:
+                self.GPIO_DC_PIN.on()
+            else:
+                self.GPIO_DC_PIN.off()
+        # elif pin == self.CS_PIN:
+        #     if value:
+        #         self.GPIO_CS_PIN.on()
+        #     else:
+        #         self.GPIO_CS_PIN.off()
+        elif pin == self.PWR_PIN:
+            if value:
+                self.GPIO_PWR_PIN.on()
+            else:
+                self.GPIO_PWR_PIN.off()
 
     def digital_read(self, pin):
-        return self.GPIO.input(pin)
+        if pin == self.BUSY_PIN:
+            return self.GPIO_BUSY_PIN.value
+        elif pin == self.RST_PIN:
+            return self.RST_PIN.value
+        elif pin == self.DC_PIN:
+            return self.DC_PIN.value
+        # elif pin == self.CS_PIN:
+        #     return self.CS_PIN.value
+        elif pin == self.PWR_PIN:
+            return self.PWR_PIN.value
 
     def delay_ms(self, delaytime):
         time.sleep(delaytime / 1000.0)
@@ -66,15 +99,7 @@ class RaspberryPi:
         self.SPI.writebytes2(data)
 
     def module_init(self):
-        self.GPIO.setmode(self.GPIO.BCM)
-        self.GPIO.setwarnings(False)
-        self.GPIO.setup(self.RST_PIN, self.GPIO.OUT)
-        self.GPIO.setup(self.DC_PIN, self.GPIO.OUT)
-        self.GPIO.setup(self.CS_PIN, self.GPIO.OUT)
-        self.GPIO.setup(self.PWR_PIN, self.GPIO.OUT)
-        self.GPIO.setup(self.BUSY_PIN, self.GPIO.IN)
-        
-        self.GPIO.output(self.PWR_PIN, 1)
+        self.GPIO_PWR_PIN.on()
 
         # SPI device, bus = 0, device = 0
         self.SPI.open(0, 0)
@@ -86,12 +111,19 @@ class RaspberryPi:
         logger.debug("spi end")
         self.SPI.close()
 
+        
+        self.GPIO_RST_PIN.off()
+        self.GPIO_DC_PIN.off()
+        self.GPIO_PWR_PIN.off()
+
+        self.GPIO_RST_PIN.close()
+        self.GPIO_DC_PIN.close()
+        # self.GPIO_CS_PIN.close()
+        self.GPIO_PWR_PIN.close()
+        self.GPIO_BUSY_PIN.close()
+
         logger.debug("close 5V, Module enters 0 power consumption ...")
-        self.GPIO.output(self.RST_PIN, 0)
-        self.GPIO.output(self.DC_PIN, 0)
-        self.GPIO.output(self.PWR_PIN, 0)
 
-        self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN, self.PWR_PIN])
 
 
 class JetsonNano:
@@ -230,7 +262,15 @@ class SunriseX3:
         self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN], self.PWR_PIN)
 
 
-if os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'):
+if sys.version_info[0] == 2:
+    process = subprocess.Popen("cat /proc/cpuinfo | grep Raspberry", shell=True, stdout=subprocess.PIPE)
+else:
+    process = subprocess.Popen("cat /proc/cpuinfo | grep Raspberry", shell=True, stdout=subprocess.PIPE, text=True)
+output, _ = process.communicate()
+if sys.version_info[0] == 2:
+    output = output.decode(sys.stdout.encoding)
+
+if "Raspberry" in output:
     implementation = RaspberryPi()
 elif os.path.exists('/sys/bus/platform/drivers/gpio-x3'):
     implementation = SunriseX3()