diff --git a/.gitignore b/.gitignore index f4e440a..d66bda0 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,12 @@ build/frame/CMakeFiles/frame.dir/manifest.res build/frame/CMakeFiles/frame.dir/vc140.pdb build/.cmake/api/v1/reply/cache-v2-dd95df14d5968b8bc03c.json build/.cmake/api/v1/reply/index-2022-02-12T19-46-35-0149.json +.vscode/settings.json +build/.cmake/api/v1/reply/cache-v2-b08d9ee268491a48090a.json +build/.cmake/api/v1/reply/codemodel-v2-1315d454ed7a6fd4530a.json +build/.cmake/api/v1/reply/index-2022-02-12T20-17-15-0123.json +build/.cmake/api/v1/reply/target-bcm2835-Debug-370fe998a1b6bb8b7242.json +build/.cmake/api/v1/reply/target-frame-Debug-bbe37aa3d79fa8b439c0.json +build/.cmake/api/v1/reply/target-waveshare-Debug-223ca8c705d057f21abf.json +build/bcm2835/cmake_install.cmake +build/waveshare/cmake_install.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b3a5e4..b476f13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,10 @@ project(Frame) set(CMAKE_CXX_STANDARD 17) -if (UNIX) +#if (UNIX) add_subdirectory(bcm2835) -endif (UNIX) + add_subdirectory(waveshare) +#endif (UNIX) add_subdirectory(frame) diff --git a/bcm2835/CMakeLists.txt b/bcm2835/CMakeLists.txt index 6dd803b..4c452d5 100644 --- a/bcm2835/CMakeLists.txt +++ b/bcm2835/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(bcm2835 STATIC include/bcm2836.h src/bcm2836.c) +add_library(bcm2835 STATIC include/bcm2835.h src/bcm2835.c) target_include_directories(bcm2835 PUBLIC include/) \ No newline at end of file diff --git a/frame/CMakeLists.txt b/frame/CMakeLists.txt index b9b2049..4f58e0b 100644 --- a/frame/CMakeLists.txt +++ b/frame/CMakeLists.txt @@ -2,4 +2,5 @@ set(target frame) -add_executable(${target} main.cpp) \ No newline at end of file +add_executable(${target} main.cpp) +target_link_libraries(${target} PRIVATE waveshare) \ No newline at end of file diff --git a/frame/main.cpp b/frame/main.cpp index 21b7742..4fc53fb 100644 --- a/frame/main.cpp +++ b/frame/main.cpp @@ -1,7 +1,47 @@ #include +#include +#include +#include + +using namespace std::chrono_literals; + +#include + int main() { std::cout << "Hallo Welt" << std::endl; + + EPD_7IN5_V2_Init(); + + EPD_7IN5_V2_ClearBlack(); + + std::this_thread::sleep_for(2s); + + EPD_7IN5_V2_Clear(); + + std::this_thread::sleep_for(2s); + + std::vector image; + image.resize(EPD_7IN5_V2_HEIGHT * EPD_7IN5_V2_WIDTH); + + uint8_t color = 0; + for(int x = 0; x < EPD_7IN5_V2_WIDTH; ++x) + { + for(int y = 0; y < EPD_7IN5_V2_HEIGHT; ++y) + { + image[EPD_7IN5_V2_WIDTH * y + x] = color; + } + + color = ~color; + } + + EPD_7IN5_V2_Display(image.data()); + + std::this_thread::sleep_for(10s); + + EPD_7IN5_V2_Clear(); + EPD_7IN5_V2_Sleep(); + return 0; } \ No newline at end of file diff --git a/waveshare/CMakeLists.txt b/waveshare/CMakeLists.txt new file mode 100644 index 0000000..0e6f6ea --- /dev/null +++ b/waveshare/CMakeLists.txt @@ -0,0 +1,13 @@ + +set(target waveshare) + +set(src + include/DEV_Config.h + include/EPD_7in5_V2.h + src/DEV_Config.c + src/EPD_7in5_V2.c +) + +add_library(${target} STATIC ${src}) +target_include_directories(${target} PUBLIC include/) +target_link_libraries(${target} PRIVATE bcm2835) \ No newline at end of file diff --git a/waveshare/include/DEV_Config.h b/waveshare/include/DEV_Config.h new file mode 100644 index 0000000..105ea19 --- /dev/null +++ b/waveshare/include/DEV_Config.h @@ -0,0 +1,108 @@ +/***************************************************************************** +* | File : DEV_Config.h +* | Author : Waveshare team +* | Function : Hardware underlying interface +* | Info : +* Used to shield the underlying layers of each master +* and enhance portability +*---------------- +* | This version: V2.0 +* | Date : 2018-10-30 +* | Info : +* 1.add: +* UBYTE\UWORD\UDOUBLE +* 2.Change: +* EPD_RST -> EPD_RST_PIN +* EPD_DC -> EPD_DC_PIN +* EPD_CS -> EPD_CS_PIN +* EPD_BUSY -> EPD_BUSY_PIN +* 3.Remote: +* EPD_RST_1\EPD_RST_0 +* EPD_DC_1\EPD_DC_0 +* EPD_CS_1\EPD_CS_0 +* EPD_BUSY_1\EPD_BUSY_0 +* 3.add: +* #define DEV_Digital_Write(_pin, _value) bcm2835_GPIOI_write(_pin, _value) +* #define DEV_Digital_Read(_pin) bcm2835_GPIOI_lev(_pin) +* #define DEV_SPI_WriteByte(__value) bcm2835_spi_transfer(__value) +# +# 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: +# +# 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. +# +******************************************************************************/ +#ifndef _DEV_CONFIG_H_ +#define _DEV_CONFIG_H_ + +#include +#include +#include +#include +#include +#include +#include "Debug.h" + +#ifdef RPI + #ifdef USE_BCM2835_LIB + #include + #elif USE_WIRINGPI_LIB + #include + #include + #elif USE_DEV_LIB + #include "RPI_sysfs_gpio.h" + #include "dev_hardware_SPI.h" + #endif +#endif + +#ifdef JETSON + #ifdef USE_DEV_LIB + #include "sysfs_gpio.h" + #include "sysfs_software_spi.h" + #elif USE_HARDWARE_LIB + + #endif + +#endif + +/** + * data +**/ +#define UBYTE uint8_t +#define UWORD uint16_t +#define UDOUBLE uint32_t + +/** + * GPIOI config +**/ +extern int EPD_RST_PIN; +extern int EPD_DC_PIN; +extern int EPD_CS_PIN; +extern int EPD_BUSY_PIN; + +/*------------------------------------------------------------------------------------------------------*/ +void DEV_Digital_Write(UWORD Pin, UBYTE Value); +UBYTE DEV_Digital_Read(UWORD Pin); + +void DEV_SPI_WriteByte(UBYTE Value); +void DEV_SPI_Write_nByte(uint8_t *pData, uint32_t Len); +void DEV_Delay_ms(UDOUBLE xms); + +UBYTE DEV_Module_Init(void); +void DEV_Module_Exit(void); + + +#endif diff --git a/waveshare/include/EPD_7in5_V2.h b/waveshare/include/EPD_7in5_V2.h new file mode 100644 index 0000000..f6e8761 --- /dev/null +++ b/waveshare/include/EPD_7in5_V2.h @@ -0,0 +1,49 @@ +/***************************************************************************** +* | File : EPD_7in5_V2.h +* | Author : Waveshare team +* | Function : Electronic paper driver +* | Info : +*---------------- +* | This version: V2.0 +* | Date : 2018-11-09 +* | Info : +* 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8] +* 2.Change:EPD_Display(UBYTE *Image) +* Need to pass parameters: pointer to cached data +# +# 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: +# +# 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. +# +******************************************************************************/ +#ifndef _EPD_7IN5_V2_H_ +#define _EPD_7IN5_V2_H_ + +#include "DEV_Config.h" + + +// Display resolution +#define EPD_7IN5_V2_WIDTH 800 +#define EPD_7IN5_V2_HEIGHT 480 + +UBYTE EPD_7IN5_V2_Init(void); +void EPD_7IN5_V2_Clear(void); +void EPD_7IN5_V2_ClearBlack(void); +void EPD_7IN5_V2_Display(const UBYTE *blackimage); +void EPD_7IN5_V2_Sleep(void); + +#endif diff --git a/waveshare/src/DEV_Config.c b/waveshare/src/DEV_Config.c new file mode 100644 index 0000000..6c7d609 --- /dev/null +++ b/waveshare/src/DEV_Config.c @@ -0,0 +1,385 @@ +/***************************************************************************** +* | File : DEV_Config.c +* | Author : Waveshare team +* | Function : Hardware underlying interface +* | Info : +*---------------- +* | This version: V3.0 +* | Date : 2019-07-31 +* | Info : +# +# 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 theex Software, and to permit persons to whom the Software is +# furished to do so, subject to the following conditions: +# +# 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. +# +******************************************************************************/ +#include "DEV_Config.h" +#include + +/** + * GPIO +**/ +int EPD_RST_PIN; +int EPD_DC_PIN; +int EPD_CS_PIN; +int EPD_BUSY_PIN; + +/** + * GPIO read and write +**/ +void DEV_Digital_Write(UWORD Pin, UBYTE Value) +{ +#ifdef RPI +#ifdef USE_BCM2835_LIB + bcm2835_gpio_write(Pin, Value); +#elif USE_WIRINGPI_LIB + digitalWrite(Pin, Value); +#elif USE_DEV_LIB + SYSFS_GPIO_Write(Pin, Value); +#endif +#endif + +#ifdef JETSON +#ifdef USE_DEV_LIB + SYSFS_GPIO_Write(Pin, Value); +#elif USE_HARDWARE_LIB + Debug("not support"); +#endif +#endif +} + +UBYTE DEV_Digital_Read(UWORD Pin) +{ + UBYTE Read_value = 0; +#ifdef RPI +#ifdef USE_BCM2835_LIB + Read_value = bcm2835_gpio_lev(Pin); +#elif USE_WIRINGPI_LIB + Read_value = digitalRead(Pin); +#elif USE_DEV_LIB + Read_value = SYSFS_GPIO_Read(Pin); +#endif +#endif + +#ifdef JETSON +#ifdef USE_DEV_LIB + Read_value = SYSFS_GPIO_Read(Pin); +#elif USE_HARDWARE_LIB + Debug("not support"); +#endif +#endif + return Read_value; +} + +/** + * SPI +**/ +void DEV_SPI_WriteByte(uint8_t Value) +{ +#ifdef RPI +#ifdef USE_BCM2835_LIB + bcm2835_spi_transfer(Value); +#elif USE_WIRINGPI_LIB + wiringPiSPIDataRW(0,&Value,1); +#elif USE_DEV_LIB + DEV_HARDWARE_SPI_TransferByte(Value); +#endif +#endif + +#ifdef JETSON +#ifdef USE_DEV_LIB + SYSFS_software_spi_transfer(Value); +#elif USE_HARDWARE_LIB + Debug("not support"); +#endif +#endif +} + +void DEV_SPI_Write_nByte(uint8_t *pData, uint32_t Len) +{ +#ifdef RPI +#ifdef USE_BCM2835_LIB + char rData[Len]; + bcm2835_spi_transfernb((char *)pData,rData,Len); +#elif USE_WIRINGPI_LIB + wiringPiSPIDataRW(0, pData, Len); +#elif USE_DEV_LIB + DEV_HARDWARE_SPI_Transfer(pData, Len); +#endif +#endif + +#ifdef JETSON +#ifdef USE_DEV_LIB + //JETSON nano waits for hardware SPI + Debug("not support"); +#elif USE_HARDWARE_LIB + Debug("not support"); +#endif +#endif +} + +/** + * GPIO Mode +**/ +void DEV_GPIO_Mode(UWORD Pin, UWORD Mode) +{ +#ifdef RPI +#ifdef USE_BCM2835_LIB + if(Mode == 0 || Mode == BCM2835_GPIO_FSEL_INPT) { + bcm2835_gpio_fsel(Pin, BCM2835_GPIO_FSEL_INPT); + } else { + bcm2835_gpio_fsel(Pin, BCM2835_GPIO_FSEL_OUTP); + } +#elif USE_WIRINGPI_LIB + if(Mode == 0 || Mode == INPUT) { + pinMode(Pin, INPUT); + pullUpDnControl(Pin, PUD_UP); + } else { + pinMode(Pin, OUTPUT); + // 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); + } +#endif +#endif + +#ifdef JETSON +#ifdef USE_DEV_LIB + SYSFS_GPIO_Export(Pin); + SYSFS_GPIO_Direction(Pin, Mode); +#elif USE_HARDWARE_LIB + Debug("not support"); +#endif +#endif +} + +/** + * delay x ms +**/ +void DEV_Delay_ms(UDOUBLE xms) +{ +#ifdef RPI +#ifdef USE_BCM2835_LIB + bcm2835_delay(xms); +#elif USE_WIRINGPI_LIB + delay(xms); +#elif USE_DEV_LIB + UDOUBLE i; + for(i=0; i < xms; i++) { + usleep(1000); + } +#endif +#endif + +#ifdef JETSON + UDOUBLE i; + for(i=0; i < xms; i++) { + usleep(1000); + } +#endif +} + +static int DEV_Equipment_Testing(void) +{ + int i; + int fd; + char value_str[20]; + fd = open("/etc/issue", O_RDONLY); + printf("Current environment: "); + while(1) { + if (fd < 0) { + Debug( "Read failed Pin\n"); + return -1; + } + for(i=0;; i++) { + if (read(fd, &value_str[i], 1) < 0) { + Debug( "failed to read value!\n"); + return -1; + } + if(value_str[i] ==32) { + printf("\r\n"); + break; + } + printf("%c",value_str[i]); + } + break; + } +#ifdef RPI + if(i<5) { + printf("Unrecognizable\r\n"); + } else { + char RPI_System[10] = {"Raspbian"}; + for(i=0; i<6; i++) { + if(RPI_System[i]!= value_str[i]) { + printf("Please make JETSON !!!!!!!!!!\r\n"); + return -1; + } + } + } +#endif +#ifdef JETSON + if(i<5) { + Debug("Unrecognizable\r\n"); + } else { + char JETSON_System[10]= {"Ubuntu"}; + for(i=0; i<6; i++) { + if(JETSON_System[i]!= value_str[i] ) { + printf("Please make RPI !!!!!!!!!!\r\n"); + return -1; + } + } + } +#endif + return 0; +} + + + +void DEV_GPIO_Init(void) +{ +#ifdef RPI + EPD_RST_PIN = 17; + EPD_DC_PIN = 25; + EPD_CS_PIN = 8; + EPD_BUSY_PIN = 24; +#elif JETSON + EPD_RST_PIN = GPIO17; + EPD_DC_PIN = GPIO25; + EPD_CS_PIN = SPI0_CS0; + EPD_BUSY_PIN = GPIO24; +#endif + + 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_BUSY_PIN, 0); + + DEV_Digital_Write(EPD_CS_PIN, 1); +} +/****************************************************************************** +function: Module Initialize, the library and initialize the pins, SPI protocol +parameter: +Info: +******************************************************************************/ +UBYTE DEV_Module_Init(void) +{ + printf("/***********************************/ \r\n"); + if(DEV_Equipment_Testing() < 0) { + return 1; + } +#ifdef RPI +#ifdef USE_BCM2835_LIB + if(!bcm2835_init()) { + printf("bcm2835 init failed !!! \r\n"); + return 1; + } else { + printf("bcm2835 init success !!! \r\n"); + } + + // GPIO Config + DEV_GPIO_Init(); + + bcm2835_spi_begin(); //Start spi interface, set spi pin for the reuse function + bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); //High first transmission + bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); //spi mode 0 + bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_128); //Frequency + bcm2835_spi_chipSelect(BCM2835_SPI_CS0); //set CE0 + bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); //enable cs0 + +#elif USE_WIRINGPI_LIB + //if(wiringPiSetup() < 0)//use wiringpi Pin number table + if(wiringPiSetupGpio() < 0) { //use BCM2835 Pin number table + printf("set wiringPi lib failed !!! \r\n"); + return 1; + } else { + printf("set wiringPi lib success !!! \r\n"); + } + + // GPIO Config + DEV_GPIO_Init(); + wiringPiSPISetup(0,10000000); + // wiringPiSPISetupMode(0, 32000000, 0); +#elif USE_DEV_LIB + printf("Write and read /dev/spidev0.0 \r\n"); + DEV_GPIO_Init(); + DEV_HARDWARE_SPI_begin("/dev/spidev0.0"); + DEV_HARDWARE_SPI_setSpeed(10000000); +#endif + +#elif JETSON +#ifdef USE_DEV_LIB + DEV_GPIO_Init(); + printf("Software spi\r\n"); + SYSFS_software_spi_begin(); + SYSFS_software_spi_setBitOrder(SOFTWARE_SPI_MSBFIRST); + SYSFS_software_spi_setDataMode(SOFTWARE_SPI_Mode0); + SYSFS_software_spi_setClockDivider(SOFTWARE_SPI_CLOCK_DIV4); +#elif USE_HARDWARE_LIB + printf("Write and read /dev/spidev0.0 \r\n"); + DEV_GPIO_Init(); + DEV_HARDWARE_SPI_begin("/dev/spidev0.0"); +#endif + +#endif + printf("/***********************************/ \r\n"); + return 0; +} + +/****************************************************************************** +function: Module exits, closes SPI and BCM2835 library +parameter: +Info: +******************************************************************************/ +void DEV_Module_Exit(void) +{ +#ifdef RPI +#ifdef USE_BCM2835_LIB + DEV_Digital_Write(EPD_CS_PIN, LOW); + DEV_Digital_Write(EPD_DC_PIN, LOW); + DEV_Digital_Write(EPD_RST_PIN, LOW); + + bcm2835_spi_end(); + bcm2835_close(); +#elif USE_WIRINGPI_LIB + DEV_Digital_Write(EPD_CS_PIN, 0); + 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); +#endif + +#elif JETSON +#ifdef USE_DEV_LIB + SYSFS_GPIO_Unexport(EPD_CS_PIN); + SYSFS_GPIO_Unexport(EPD_DC_PIN); + SYSFS_GPIO_Unexport(EPD_RST_PIN); + SYSFS_GPIO_Unexport(EPD_BUSY_PIN); +#elif USE_HARDWARE_LIB + Debug("not support"); +#endif +#endif +} diff --git a/waveshare/src/EPD_7in5_V2.c b/waveshare/src/EPD_7in5_V2.c new file mode 100644 index 0000000..ffb1770 --- /dev/null +++ b/waveshare/src/EPD_7in5_V2.c @@ -0,0 +1,321 @@ +/***************************************************************************** +* | File : EPD_7in5.c +* | Author : Waveshare team +* | Function : Electronic paper driver +* | Info : +*---------------- +* | This version: V2.0 +* | Date : 2018-11-09 +* | Info : +***************************************************************************** +# +# 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: +# +# 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. +# +******************************************************************************/ +#include "EPD_7in5_V2.h" +#include "Debug.h" + + +UBYTE Voltage_Frame_7IN5_V2[]={ + 0x6, 0x3F, 0x3F, 0x11, 0x24, 0x7, 0x17, +}; + +UBYTE LUT_VCOM_7IN5_V2[]={ + 0x0, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x0, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +UBYTE LUT_WW_7IN5_V2[]={ + 0x10, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x84, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x20, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +UBYTE LUT_BW_7IN5_V2[]={ + 0x10, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x84, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x20, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +UBYTE LUT_WB_7IN5_V2[]={ + 0x80, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x84, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x40, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +UBYTE LUT_BB_7IN5_V2[]={ + 0x80, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x84, 0xF, 0x1, 0xF, 0x1, 0x2, + 0x40, 0xF, 0xF, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +/****************************************************************************** +function : Software reset +parameter: +******************************************************************************/ +static void EPD_Reset(void) +{ + DEV_Digital_Write(EPD_RST_PIN, 1); + DEV_Delay_ms(20); + DEV_Digital_Write(EPD_RST_PIN, 0); + DEV_Delay_ms(2); + DEV_Digital_Write(EPD_RST_PIN, 1); + DEV_Delay_ms(20); +} + +/****************************************************************************** +function : send command +parameter: + Reg : Command register +******************************************************************************/ +static void EPD_SendCommand(UBYTE Reg) +{ + DEV_Digital_Write(EPD_DC_PIN, 0); + DEV_Digital_Write(EPD_CS_PIN, 0); + DEV_SPI_WriteByte(Reg); + DEV_Digital_Write(EPD_CS_PIN, 1); +} + +/****************************************************************************** +function : send data +parameter: + Data : Write data +******************************************************************************/ +static void EPD_SendData(UBYTE Data) +{ + DEV_Digital_Write(EPD_DC_PIN, 1); + DEV_Digital_Write(EPD_CS_PIN, 0); + DEV_SPI_WriteByte(Data); + DEV_Digital_Write(EPD_CS_PIN, 1); +} + +/****************************************************************************** +function : Wait until the busy_pin goes LOW +parameter: +******************************************************************************/ +static void EPD_WaitUntilIdle(void) +{ + Debug("e-Paper busy\r\n"); + do{ + DEV_Delay_ms(5); + }while(!(DEV_Digital_Read(EPD_BUSY_PIN))); + DEV_Delay_ms(5); + Debug("e-Paper busy release\r\n"); +} + +static void EPD_7IN5_V2_LUT(UBYTE* lut_vcom, UBYTE* lut_ww, UBYTE* lut_bw, UBYTE* lut_wb, UBYTE* lut_bb) +{ + UBYTE count; + + EPD_SendCommand(0x20); //VCOM + for(count=0; count<42; count++) + EPD_SendData(lut_vcom[count]); + + EPD_SendCommand(0x21); //LUTBW + for(count=0; count<42; count++) + EPD_SendData(lut_ww[count]); + + EPD_SendCommand(0x22); //LUTBW + for(count=0; count<42; count++) + EPD_SendData(lut_bw[count]); + + EPD_SendCommand(0x23); //LUTWB + for(count=0; count<42; count++) + EPD_SendData(lut_wb[count]); + + EPD_SendCommand(0x24); //LUTBB + for(count=0; count<42; count++) + EPD_SendData(lut_bb[count]); +} + +/****************************************************************************** +function : Turn On Display +parameter: +******************************************************************************/ +static void EPD_7IN5_V2_TurnOnDisplay(void) +{ + EPD_SendCommand(0x12); //DISPLAY REFRESH + DEV_Delay_ms(100); //!!!The delay here is necessary, 200uS at least!!! + EPD_WaitUntilIdle(); +} + +/****************************************************************************** +function : Initialize the e-Paper register +parameter: +******************************************************************************/ +UBYTE EPD_7IN5_V2_Init(void) +{ + EPD_Reset(); + + // EPD_SendCommand(0x01); //POWER SETTING + // EPD_SendData(0x07); + // EPD_SendData(0x07); //VGH=20V,VGL=-20V + // EPD_SendData(0x3f); //VDH=15V + // EPD_SendData(0x3f); //VDL=-15V + + EPD_SendCommand(0x01); // power setting + EPD_SendData(0x17); // 1-0=11: internal power + EPD_SendData(*(Voltage_Frame_7IN5_V2+6)); // VGH&VGL + EPD_SendData(*(Voltage_Frame_7IN5_V2+1)); // VSH + EPD_SendData(*(Voltage_Frame_7IN5_V2+2)); // VSL + EPD_SendData(*(Voltage_Frame_7IN5_V2+3)); // VSHR + + EPD_SendCommand(0x82); // VCOM DC Setting + EPD_SendData(*(Voltage_Frame_7IN5_V2+4)); // VCOM + + EPD_SendCommand(0x06); // Booster Setting + EPD_SendData(0x27); + EPD_SendData(0x27); + EPD_SendData(0x2F); + EPD_SendData(0x17); + + EPD_SendCommand(0x30); // OSC Setting + EPD_SendData(*(Voltage_Frame_7IN5_V2+0)); // 2-0=100: N=4 ; 5-3=111: M=7 ; 3C=50Hz 3A=100HZ + + EPD_SendCommand(0x04); //POWER ON + DEV_Delay_ms(100); + EPD_WaitUntilIdle(); + + EPD_SendCommand(0X00); //PANNEL SETTING + EPD_SendData(0x3F); //KW-3f KWR-2F BWROTP 0f BWOTP 1f + + EPD_SendCommand(0x61); //tres + EPD_SendData(0x03); //source 800 + EPD_SendData(0x20); + EPD_SendData(0x01); //gate 480 + EPD_SendData(0xE0); + + EPD_SendCommand(0X15); + EPD_SendData(0x00); + + EPD_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING + EPD_SendData(0x10); + EPD_SendData(0x00); + + EPD_SendCommand(0X60); //TCON SETTING + EPD_SendData(0x22); + + EPD_SendCommand(0x65); // Resolution setting + EPD_SendData(0x00); + EPD_SendData(0x00);//800*480 + EPD_SendData(0x00); + EPD_SendData(0x00); + + EPD_7IN5_V2_LUT(LUT_VCOM_7IN5_V2, LUT_WW_7IN5_V2, LUT_BW_7IN5_V2, LUT_WB_7IN5_V2, LUT_BB_7IN5_V2); + + return 0; +} + +/****************************************************************************** +function : Clear screen +parameter: +******************************************************************************/ +void EPD_7IN5_V2_Clear(void) +{ + UWORD Width, Height; + Width =(EPD_7IN5_V2_WIDTH % 8 == 0)?(EPD_7IN5_V2_WIDTH / 8 ):(EPD_7IN5_V2_WIDTH / 8 + 1); + Height = EPD_7IN5_V2_HEIGHT; + + UWORD i; + EPD_SendCommand(0x10); + for(i=0; i