diff --git a/c/examples/EPD_Test.h b/c/examples/EPD_Test.h index 67a188e..1b244c6 100644 --- a/c/examples/EPD_Test.h +++ b/c/examples/EPD_Test.h @@ -4,7 +4,7 @@ * | Function : test Demo * | Info : *---------------- -* | This version: V1.0 +* | This version: V1.0 * | Date : 2021-03-16 * | Info : # @@ -43,6 +43,7 @@ int OLED_2in23_test(void); int LCD_0in96_test(void); int LCD_1in14_test(void); +int LCD_1in28_test(void); int LCD_1in44_test(void); void LCD_1IN54_test(void); int LCD_1in8_test(void); diff --git a/c/examples/LCD_1in28_test.c b/c/examples/LCD_1in28_test.c new file mode 100644 index 0000000..d11cf47 --- /dev/null +++ b/c/examples/LCD_1in28_test.c @@ -0,0 +1,249 @@ +/***************************************************************************** +* | File : LCD_1in28_test.c +* | Author : Waveshare team, Julianno F. C. Silva (@juliannojungle) +* | Function : 1.28inch LCD test demo +* | Info : +*---------------- +* | This version: V1.0 +* | Date : 2023-03-26 +* | 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_Test.h" +#include "LCD_1in28.h" + +bool reserved_addr(uint8_t addr) { +return (addr & 0x78) == 0 || (addr & 0x78) == 0x78; +} + +int LCD_1in28_test(void) +{ + DEV_Delay_ms(100); + printf("LCD_1in28_test Demo\r\n"); + + if (DEV_Module_Init() != 0) { + return -1; + } + + DEV_SET_PWM(50); + /* LCD Init */ + printf("1.28inch LCD demo...\r\n"); + LCD_1IN28_Init(HORIZONTAL); + LCD_1IN28_Clear(WHITE); + + /* Turn backlight on */ + EPD_BL_PIN = 25; + DEV_GPIO_Mode(EPD_BL_PIN, GPIO_OUT); + DEV_Digital_Write(EPD_CS_PIN, 1); + DEV_Digital_Write(EPD_DC_PIN, 0); + DEV_Digital_Write(EPD_BL_PIN, 1); + //LCD_SetBacklight(1023); + UDOUBLE Imagesize = LCD_1IN28_HEIGHT*LCD_1IN28_WIDTH*2; + UWORD *BlackImage; + if((BlackImage = (UWORD *)malloc(Imagesize)) == NULL) { + printf("Failed to apply for black memory...\r\n"); + exit(0); + } + // /*1.Create a new image cache named IMAGE_RGB and fill it with white*/ + Paint_NewImage((UBYTE *)BlackImage,LCD_1IN28.WIDTH,LCD_1IN28.HEIGHT, 0, WHITE); + Paint_SetScale(65); + Paint_Clear(WHITE); + Paint_SetRotate(ROTATE_0); + Paint_Clear(WHITE); + + // /* GUI */ + printf("drawing...\r\n"); + // /*2.Drawing on the image*/ +#if 1 + Paint_DrawPoint(2,1, BLACK, DOT_PIXEL_1X1, DOT_FILL_RIGHTUP);//240 240 + Paint_DrawPoint(2,6, BLACK, DOT_PIXEL_2X2, DOT_FILL_RIGHTUP); + Paint_DrawPoint(2,11, BLACK, DOT_PIXEL_3X3, DOT_FILL_RIGHTUP); + Paint_DrawPoint(2,16, BLACK, DOT_PIXEL_4X4, DOT_FILL_RIGHTUP); + Paint_DrawPoint(2,21, BLACK, DOT_PIXEL_5X5, DOT_FILL_RIGHTUP); + Paint_DrawLine( 10, 5, 40, 35, MAGENTA, DOT_PIXEL_2X2, LINE_STYLE_SOLID); + Paint_DrawLine( 10, 35, 40, 5, MAGENTA, DOT_PIXEL_2X2, LINE_STYLE_SOLID); + + Paint_DrawLine( 80, 20, 110, 20, CYAN, DOT_PIXEL_1X1, LINE_STYLE_DOTTED); + Paint_DrawLine( 95, 5, 95, 35, CYAN, DOT_PIXEL_1X1, LINE_STYLE_DOTTED); + + Paint_DrawRectangle(10, 5, 40, 35, RED, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(45, 5, 75, 35, BLUE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + + Paint_DrawCircle(95, 20, 15, GREEN, DOT_PIXEL_1X1, DRAW_FILL_EMPTY); + Paint_DrawCircle(130, 20, 15, GREEN, DOT_PIXEL_1X1, DRAW_FILL_FULL); + + Paint_DrawNum (50, 40 ,9.87654321, &Font20,3, WHITE, BLACK); + Paint_DrawString_EN(1, 40, "ABC", &Font20, 0x000f, 0xfff0); + Paint_DrawString_CN(1,60, "��ӭʹ��", &Font24CN, WHITE, BLUE); + Paint_DrawString_EN(1, 100, "WaveShare", &Font16, RED, WHITE); + + // /*3.Refresh the picture in RAM to LCD*/ + LCD_1IN28_Display(BlackImage); + DEV_Delay_ms(2000); + +#endif +#if 1 + Paint_DrawImage(gImage_1inch3_1,0,0,240,240); + LCD_1IN28_Display(BlackImage); + DEV_Delay_ms(2000); + +#endif +#if 1 + + uint8_t keyA = 15; + uint8_t keyB = 17; + uint8_t keyX = 19; + uint8_t keyY = 21; + + uint8_t up = 2; + uint8_t dowm = 18; + uint8_t left = 16; + uint8_t right = 20; + uint8_t ctrl = 3; + + + SET_Infrared_PIN(keyA); + SET_Infrared_PIN(keyB); + SET_Infrared_PIN(keyX); + SET_Infrared_PIN(keyY); + + SET_Infrared_PIN(up); + SET_Infrared_PIN(dowm); + SET_Infrared_PIN(left); + SET_Infrared_PIN(right); + SET_Infrared_PIN(ctrl); + + + Paint_Clear(WHITE); + Paint_DrawRectangle(208, 15, 237, 45, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(208, 75, 237, 105, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(208, 135, 237, 165, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(208, 195, 237, 225, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(60, 60, 91, 90, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(60, 150, 91, 180, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(15, 105, 46, 135, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(105, 105, 136, 135, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + Paint_DrawRectangle(60, 105, 91, 135, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_EMPTY); + LCD_1IN28_Display(BlackImage); + + + while(1){ + if(DEV_Digital_Read(keyA ) == 0){ + Paint_DrawRectangle(208, 15, 236, 45, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(208, 15, 236, 45,BlackImage); + printf("gpio =%d\r\n",keyA); + } + else{ + Paint_DrawRectangle(208, 15, 236, 45, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(208, 15, 236, 45,BlackImage); + } + + if(DEV_Digital_Read(keyB ) == 0){ + Paint_DrawRectangle(208, 75, 236, 105, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(208, 75, 236, 105,BlackImage); + printf("gpio =%d\r\n",keyB); + } + else{ + Paint_DrawRectangle(208, 75, 236, 105, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(208, 75, 236, 105,BlackImage); + } + + if(DEV_Digital_Read(keyX ) == 0){ + Paint_DrawRectangle(208, 135, 236, 165, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(208, 135, 236, 165,BlackImage); + printf("gpio =%d\r\n",keyX); + } + else{ + Paint_DrawRectangle(208, 135, 236, 165, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(208, 135, 236, 165,BlackImage); + } + + if(DEV_Digital_Read(keyY ) == 0){ + Paint_DrawRectangle(208, 195, 236, 225, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(208, 195, 236, 225,BlackImage); + printf("gpio =%d\r\n",keyY); + } + else{ + Paint_DrawRectangle(208, 195, 236, 225, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(208, 195, 236, 225,BlackImage); + } + + + if(DEV_Digital_Read(up ) == 0){ + Paint_DrawRectangle(60, 60, 90, 90, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(60, 60, 90, 90,BlackImage); + printf("gpio =%d\r\n",up); + } + else{ + Paint_DrawRectangle(60, 60, 90, 90, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(60, 60, 90, 90,BlackImage); + } + + if(DEV_Digital_Read(dowm ) == 0){ + Paint_DrawRectangle(60, 150, 90, 180, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(60, 150, 90, 180,BlackImage); + printf("gpio =%d\r\n",dowm); + } + else{ + Paint_DrawRectangle(60, 150, 90, 180, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(60, 150, 90, 180,BlackImage); + } + + if(DEV_Digital_Read(left ) == 0){ + Paint_DrawRectangle(15, 105, 45, 135, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(15, 105, 45, 135,BlackImage); + printf("gpio =%d\r\n",left); + } + else{ + Paint_DrawRectangle(15, 105, 45, 135, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(15, 105, 45, 135,BlackImage); + } + + if(DEV_Digital_Read(right ) == 0){ + Paint_DrawRectangle(105, 105, 135, 135, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(105, 105, 135, 135,BlackImage); + printf("gpio =%d\r\n",right); + } + else{ + Paint_DrawRectangle(105, 105, 135, 135, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(105, 105, 135, 135,BlackImage); + } + + if(DEV_Digital_Read(ctrl ) == 0){ + Paint_DrawRectangle(60, 105, 90, 135, 0xF800, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(60, 105, 90, 135,BlackImage); + printf("gpio =%d\r\n",ctrl); + } + else{ + Paint_DrawRectangle(60, 105, 90, 135, WHITE, DOT_PIXEL_2X2,DRAW_FILL_FULL); + LCD_1IN28_DisplayWindows(60, 105, 90, 135,BlackImage); + } + } + +#endif + + /* Module Exit */ + free(BlackImage); + BlackImage = NULL; + + DEV_Module_Exit(); + return 0; +} diff --git a/c/examples/LCD_2in_test.c b/c/examples/LCD_2in_test.c index 76a89ab..e76f8b6 100644 --- a/c/examples/LCD_2in_test.c +++ b/c/examples/LCD_2in_test.c @@ -28,7 +28,7 @@ # ******************************************************************************/ #include "EPD_Test.h" -#include "LCD_2IN.h" +#include "LCD_2in.h" bool reserved_addr(uint8_t addr) { return (addr & 0x78) == 0 || (addr & 0x78) == 0x78; @@ -88,7 +88,7 @@ int LCD_2in_test(void) Paint_DrawNum (50, 40 ,9.87654321, &Font20,5, WHITE, BLACK); Paint_DrawString_EN(1, 40, "ABC", &Font20, 0x000f, 0xfff0); - Paint_DrawString_CN(1,60, "»¶Ó­Ê¹ÓÃ", &Font24CN, WHITE, BLUE); + Paint_DrawString_CN(1,60, "��ӭʹ��", &Font24CN, WHITE, BLUE); Paint_DrawString_EN(1, 100, "WaveShare", &Font16, RED, WHITE); // /*3.Refresh the picture in RAM to LCD*/ diff --git a/c/lib/GUI/GUI_Paint.c b/c/lib/GUI/GUI_Paint.c index e6e6b0b..addf386 100644 --- a/c/lib/GUI/GUI_Paint.c +++ b/c/lib/GUI/GUI_Paint.c @@ -16,25 +16,24 @@ function: Create Image Height : The height of the picture Color : Whether the picture is inverted ******************************************************************************/ -void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) -{ +void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color) { Paint.Image = NULL; Paint.Image = image; Paint.WidthMemory = Width; Paint.HeightMemory = Height; - Paint.Color = Color; - Paint.Scale = 2; - + Paint.Color = Color; + Paint.Scale = 2; + Paint.WidthByte = (Width % 8 == 0)? (Width / 8 ): (Width / 8 + 1); - Paint.HeightByte = Height; + Paint.HeightByte = Height; // printf("WidthByte = %d, HeightByte = %d\r\n", Paint.WidthByte, Paint.HeightByte); // printf(" EPD_WIDTH / 8 = %d\r\n", 122 / 8); - + Paint.Rotate = Rotate; Paint.Mirror = MIRROR_NONE; - - if(Rotate == ROTATE_0 || Rotate == ROTATE_180) { + + if (Rotate == ROTATE_0 || Rotate == ROTATE_180) { Paint.Width = Width; Paint.Height = Height; } else { @@ -48,8 +47,7 @@ function: Select Image parameter: image : Pointer to the image cache ******************************************************************************/ -void Paint_SelectImage(UBYTE *image) -{ +void Paint_SelectImage(UBYTE *image) { Paint.Image = image; } @@ -58,9 +56,8 @@ function: Select Image Rotate parameter: Rotate : 0,90,180,270 ******************************************************************************/ -void Paint_SetRotate(UWORD Rotate) -{ - if(Rotate == ROTATE_0 || Rotate == ROTATE_90 || Rotate == ROTATE_180 || Rotate == ROTATE_270) { +void Paint_SetRotate(UWORD Rotate) { + if (Rotate == ROTATE_0 || Rotate == ROTATE_90 || Rotate == ROTATE_180 || Rotate == ROTATE_270) { Debug("Set image Rotate %d\r\n", Rotate); Paint.Rotate = Rotate; } else { @@ -68,40 +65,45 @@ void Paint_SetRotate(UWORD Rotate) } } -void Paint_SetScale(UBYTE scale) -{ - if(scale == 2){ - Paint.Scale = scale; - Paint.WidthByte = (Paint.WidthMemory % 8 == 0)? (Paint.WidthMemory / 8 ): (Paint.WidthMemory / 8 + 1); - }else if(scale == 4){ - Paint.Scale = scale; - Paint.WidthByte = (Paint.WidthMemory % 4 == 0)? (Paint.WidthMemory / 4 ): (Paint.WidthMemory / 4 + 1); - }else if(scale ==16) { - Paint.Scale = scale; - Paint.WidthByte = (Paint.WidthMemory%2==0) ? (Paint.WidthMemory/2) : (Paint.WidthMemory/2+1); - }else if(scale ==65) { - Paint.Scale = scale; - Paint.WidthByte = Paint.WidthMemory*2; - }else{ - Debug("Set Scale Input parameter error\r\n"); - Debug("Scale Only support: 2 4 16 65\r\n"); +void Paint_SetScale(UBYTE scale) { + switch (scale) { + case 2: { + Paint.Scale = scale; + Paint.WidthByte = (Paint.WidthMemory % 8 == 0) ? (Paint.WidthMemory / 8 ) : (Paint.WidthMemory / 8 + 1); + } break; + case 4: { + Paint.Scale = scale; + Paint.WidthByte = (Paint.WidthMemory % 4 == 0) ? (Paint.WidthMemory / 4 ) : (Paint.WidthMemory / 4 + 1); + } break; + case 16: { + Paint.Scale = scale; + Paint.WidthByte = (Paint.WidthMemory % 2 == 0) ? (Paint.WidthMemory / 2) : (Paint.WidthMemory / 2 + 1); + } break; + case 65: { + Paint.Scale = scale; + Paint.WidthByte = Paint.WidthMemory * 2; + } break; + default: { + Debug("Set Scale Input parameter error\r\n"); + Debug("Scale Only support: 2 4 16 65\r\n"); + } } } + /****************************************************************************** -function: Select Image mirror +function: Select Image mirror parameter: mirror :Not mirror,Horizontal mirror,Vertical mirror,Origin mirror ******************************************************************************/ -void Paint_SetMirroring(UBYTE mirror) -{ - if(mirror == MIRROR_NONE || mirror == MIRROR_HORIZONTAL || +void Paint_SetMirroring(UBYTE mirror) { + if (mirror == MIRROR_NONE || mirror == MIRROR_HORIZONTAL || mirror == MIRROR_VERTICAL || mirror == MIRROR_ORIGIN) { - Debug("mirror image x:%s, y:%s\r\n",(mirror & 0x01)? "mirror":"none", ((mirror >> 1) & 0x01)? "mirror":"none"); + Debug("mirror image x:%s, y:%s\r\n", (mirror & 0x01) ? "mirror" : "none", ((mirror >> 1) & 0x01) ? "mirror" : "none"); Paint.Mirror = mirror; } else { Debug("mirror should be MIRROR_NONE, MIRROR_HORIZONTAL, \ MIRROR_VERTICAL or MIRROR_ORIGIN\r\n"); - } + } } /****************************************************************************** @@ -111,83 +113,80 @@ function: Draw Pixels Ypoint : At point Y Color : Painted colors ******************************************************************************/ -void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) -{ - if(Xpoint > Paint.Width || Ypoint > Paint.Height){ +void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color) { + if (Xpoint > Paint.Width || Ypoint > Paint.Height) { Debug("Exceeding display boundaries\r\n"); return; - } + } + UWORD X, Y; - switch(Paint.Rotate) { - case 0: - X = Xpoint; - Y = Ypoint; - break; - case 90: - X = Paint.WidthMemory - Ypoint - 1; - Y = Xpoint; - break; - case 180: - X = Paint.WidthMemory - Xpoint - 1; - Y = Paint.HeightMemory - Ypoint - 1; - break; - case 270: - X = Ypoint; - Y = Paint.HeightMemory - Xpoint - 1; - break; - default: - return; + switch (Paint.Rotate) { + case 0: + X = Xpoint; + Y = Ypoint; + break; + case 90: + X = Paint.WidthMemory - Ypoint - 1; + Y = Xpoint; + break; + case 180: + X = Paint.WidthMemory - Xpoint - 1; + Y = Paint.HeightMemory - Ypoint - 1; + break; + case 270: + X = Ypoint; + Y = Paint.HeightMemory - Xpoint - 1; + break; + default: return; } - - switch(Paint.Mirror) { - case MIRROR_NONE: - break; - case MIRROR_HORIZONTAL: - X = Paint.WidthMemory - X - 1; - break; - case MIRROR_VERTICAL: - Y = Paint.HeightMemory - Y - 1; - break; - case MIRROR_ORIGIN: - X = Paint.WidthMemory - X - 1; - Y = Paint.HeightMemory - Y - 1; - break; - default: - return; + + switch (Paint.Mirror) { + case MIRROR_NONE: + break; + case MIRROR_HORIZONTAL: + X = Paint.WidthMemory - X - 1; + break; + case MIRROR_VERTICAL: + Y = Paint.HeightMemory - Y - 1; + break; + case MIRROR_ORIGIN: + X = Paint.WidthMemory - X - 1; + Y = Paint.HeightMemory - Y - 1; + break; + default: return; } - if(X > Paint.WidthMemory || Y > Paint.HeightMemory){ + if (X > Paint.WidthMemory || Y > Paint.HeightMemory) { Debug("Exceeding display boundaries\r\n"); return; } - - if(Paint.Scale == 2){ + + if (Paint.Scale == 2) { UDOUBLE Addr = X / 8 + Y * Paint.WidthByte; UBYTE Rdata = Paint.Image[Addr]; - if(Color&0xff == BLACK) + if (Color &0xff == BLACK) Paint.Image[Addr] = Rdata & ~(0x80 >> (X % 8)); else Paint.Image[Addr] = Rdata | (0x80 >> (X % 8)); - }else if(Paint.Scale == 4){ + } else if (Paint.Scale == 4) { UDOUBLE Addr = X / 4 + Y * Paint.WidthByte; - Color = Color % 4;//Guaranteed color scale is 4 --- 0~3 + Color = Color % 4; //Guaranteed color scale is 4 --- 0~3 UBYTE Rdata = Paint.Image[Addr]; - - Rdata = Rdata & (~(0xC0 >> ((X % 4)*2))); - Paint.Image[Addr] = Rdata | ((Color << 6) >> ((X % 4)*2)); - }else if(Paint.Scale == 16) { + + Rdata = Rdata & (~(0xC0 >> ((X % 4) * 2))); + Paint.Image[Addr] = Rdata | ((Color << 6) >> ((X % 4) * 2)); + } else if (Paint.Scale == 16) { UDOUBLE Addr = X / 2 + Y * Paint.WidthByte; UBYTE Rdata = Paint.Image[Addr]; Color = Color % 16; - Rdata = Rdata & (~(0xf0 >> ((X % 2)*4))); - Paint.Image[Addr] = Rdata | ((Color << 4) >> ((X % 2)*4)); - }else if(Paint.Scale == 65) { - UDOUBLE Addr = X*2 + Y*Paint.WidthByte; - Paint.Image[Addr] = 0xff & (Color>>8); - Paint.Image[Addr+1] = 0xff & Color; + Rdata = Rdata & (~(0xf0 >> ((X % 2) * 4))); + Paint.Image[Addr] = Rdata | ((Color << 4) >> ((X % 2) * 4)); + } else if (Paint.Scale == 65) { + UDOUBLE Addr = X * 2 + Y * Paint.WidthByte; + Paint.Image[Addr] = 0xff & (Color >> 8); + Paint.Image[Addr + 1] = 0xff & Color; } - } /****************************************************************************** @@ -195,28 +194,27 @@ function: Clear the color of the picture parameter: Color : Painted colors ******************************************************************************/ -void Paint_Clear(UWORD Color) -{ - if(Paint.Scale == 2 || Paint.Scale == 4) { +void Paint_Clear(UWORD Color) { + if (Paint.Scale == 2 || Paint.Scale == 4) { for (UWORD Y = 0; Y < Paint.HeightByte; Y++) { - for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte - UDOUBLE Addr = X + Y*Paint.WidthByte; + for (UWORD X = 0; X < Paint.WidthByte; X++) {//8 pixel = 1 byte + UDOUBLE Addr = X + Y * Paint.WidthByte; Paint.Image[Addr] = Color; } } - }else if(Paint.Scale == 16) { + } else if (Paint.Scale == 16) { for (UWORD Y = 0; Y < Paint.HeightByte; Y++) { for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte - UDOUBLE Addr = X + Y*Paint.WidthByte; + UDOUBLE Addr = X + Y * Paint.WidthByte; Color = Color & 0x0f; - Paint.Image[Addr] = (Color<<4) | Color; + Paint.Image[Addr] = (Color << 4) | Color; } } - }else if(Paint.Scale == 65) { + } else if (Paint.Scale == 65) { for (UWORD Y = 0; Y < Paint.HeightByte; Y++) { - for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte - UDOUBLE Addr = X*2 + Y*Paint.WidthByte; - Paint.Image[Addr] = 0xff & (Color>>8); + for (UWORD X = 0; X < Paint.WidthByte; X++) {//8 pixel = 1 byte + UDOUBLE Addr = X * 2 + Y * Paint.WidthByte; + Paint.Image[Addr] = 0xff & (Color >> 8); Paint.Image[Addr+1] = 0xff & Color; } } @@ -232,8 +230,7 @@ function: Clear the color of a window Yend : y end point Color : Painted colors ******************************************************************************/ -void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) -{ +void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color) { UWORD X, Y; for (Y = Ystart; Y < Yend; Y++) { for (X = Xstart; X < Xend; X++) {//8 pixel = 1 byte @@ -245,15 +242,14 @@ void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWOR /****************************************************************************** function: Draw Point(Xpoint, Ypoint) Fill the color parameter: - Xpoint : The Xpoint coordinate of the point - Ypoint : The Ypoint coordinate of the point - Color : Painted color - Dot_Pixel : point size - Dot_Style : point Style + Xpoint : The Xpoint coordinate of the point + Ypoint : The Ypoint coordinate of the point + Color : Painted color + Dot_Pixel : point size + Dot_Style : point Style ******************************************************************************/ void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, - DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) -{ + DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style) { if (Xpoint > Paint.Width || Ypoint > Paint.Height) { Debug("Paint_DrawPoint Input exceeds the normal display range\r\n"); printf("Xpoint = %d , Paint.Width = %d \r\n ",Xpoint,Paint.Width); @@ -265,7 +261,7 @@ void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, if (Dot_Style == DOT_FILL_AROUND) { for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) { for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) { - if(Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0) + if (Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0) break; // printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel); Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color); @@ -292,8 +288,7 @@ function: Draw a line of arbitrary slope Line_Style: Solid and dotted lines ******************************************************************************/ void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, - UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style) -{ + UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style) { if (Xstart > Paint.Width || Ystart > Paint.Height || Xend > Paint.Width || Yend > Paint.Height) { Debug("Paint_DrawLine Input exceeds the normal display range\r\n"); @@ -318,20 +313,22 @@ void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, //Painted dotted line, 2 point is really virtual if (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0) { //Debug("LINE_DOTTED\r\n"); - if(Color) - Paint_DrawPoint(Xpoint, Ypoint, BLACK, Line_width, DOT_STYLE_DFT); + if(Color) + Paint_DrawPoint(Xpoint, Ypoint, BLACK, Line_width, DOT_STYLE_DFT); else - Paint_DrawPoint(Xpoint, Ypoint, WHITE, Line_width, DOT_STYLE_DFT); + Paint_DrawPoint(Xpoint, Ypoint, WHITE, Line_width, DOT_STYLE_DFT); Dotted_Len = 0; } else { Paint_DrawPoint(Xpoint, Ypoint, Color, Line_width, DOT_STYLE_DFT); } + if (2 * Esp >= dy) { if (Xpoint == Xend) break; Esp += dy; Xpoint += XAddway; } + if (2 * Esp <= dx) { if (Ypoint == Yend) break; @@ -353,8 +350,7 @@ function: Draw a rectangle Draw_Fill : Whether to fill the inside of the rectangle ******************************************************************************/ void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, - UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) -{ + UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) { if (Xstart > Paint.Width || Ystart > Paint.Height || Xend > Paint.Width || Yend > Paint.Height) { Debug("Input exceeds the normal display range\r\n"); @@ -386,8 +382,7 @@ function: Use the 8-point method to draw a circle of the Draw_Fill : Whether to fill the inside of the Circle ******************************************************************************/ void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, - UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) -{ + UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill) { if (X_Center > Paint.Width || Y_Center >= Paint.Height) { Debug("Paint_DrawCircle Input exceeds the normal display range\r\n"); return; @@ -414,12 +409,14 @@ void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//7 Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT); } + if (Esp < 0 ) Esp += 4 * XCurrent + 6; else { Esp += 10 + 4 * (XCurrent - YCurrent ); YCurrent --; } + XCurrent ++; } } else { //Draw a hollow circle @@ -455,8 +452,7 @@ function: Show English characters Color_Background : Select the background color ******************************************************************************/ void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char, - sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) -{ + sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) { UWORD Page, Column; if (Xpoint > Paint.Width || Ypoint > Paint.Height) { @@ -469,7 +465,6 @@ void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char, for (Page = 0; Page < Font->Height; Page ++ ) { for (Column = 0; Column < Font->Width; Column ++ ) { - //To determine whether the font background color and screen background color is consistent if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan if (*ptr & (0x80 >> (Column % 8))) @@ -484,17 +479,19 @@ void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char, // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); } } + //One pixel is 8 bits if (Column % 8 == 7) ptr++; }// Write a line + if (Font->Width % 8 != 0) ptr++; }// Write all } /****************************************************************************** -function: Display the string +function: Display the string parameter: Xstart :X coordinate Ystart :Y coordinate @@ -504,8 +501,7 @@ function: Display the string Color_Background : Select the background color ******************************************************************************/ void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, - sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) -{ + sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) { UWORD Xpoint = Xstart; UWORD Ypoint = Ystart; @@ -526,10 +522,11 @@ void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, Xpoint = Xstart; Ypoint = Ystart; } - Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground); + + Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Foreground, Color_Background); //The next character of the address - pString ++; + pString++; //The next word of the abscissa increases the font of the broadband Xpoint += Font->Width; @@ -549,17 +546,16 @@ function: Display the string Color_Background : Select the background color ******************************************************************************/ void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, - UWORD Color_Foreground, UWORD Color_Background) -{ + UWORD Color_Foreground, UWORD Color_Background) { const char* p_text = pString; int x = Xstart, y = Ystart; - int i, j,Num; + int i, j, Num; /* Send the string character by character on EPD */ while (*p_text != 0) { - if(*p_text <= 0x7F) { //ASCII < 126 - for(Num = 0; Num < font->size; Num++) { - if(*p_text== font->table[Num].index[0]) { + if (*p_text <= 0x7F) { //ASCII < 126 + for (Num = 0; Num < font->size; Num++) { + if (*p_text== font->table[Num].index[0]) { const char* ptr = &font->table[Num].matrix[0]; for (j = 0; j < font->Height; j++) { @@ -578,24 +574,28 @@ void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT // Paint_DrawPoint(x + i, y + j, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); } } + if (i % 8 == 7) { ptr++; } } + if (font->Width % 8 != 0) { ptr++; } } + break; } } + /* Point on the next character */ p_text += 1; /* Decrement the column position by 16 */ x += font->ASCII_Width; } else { //Chinese - for(Num = 0; Num < font->size; Num++) { - if((*p_text== font->table[Num].index[0]) && (*(p_text+1) == font->table[Num].index[1])) { + for (Num = 0; Num < font->size; Num++) { + if ((*p_text== font->table[Num].index[0]) && (*(p_text + 1) == font->table[Num].index[1])) { const char* ptr = &font->table[Num].matrix[0]; for (j = 0; j < font->Height; j++) { @@ -614,17 +614,21 @@ void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT // Paint_DrawPoint(x + i, y + j, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); } } + if (i % 8 == 7) { ptr++; } } + if (font->Width % 8 != 0) { ptr++; } } + break; } } + /* Point on the next character */ p_text += 2; /* Decrement the column position by 16 */ @@ -634,55 +638,60 @@ void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT } /****************************************************************************** -function: Display nummber +function: Display nummber parameter: Xstart :X coordinate Ystart : Y coordinate Nummber : The number displayed Font :A structure pointer that displays a character size - Digit : Fractional width + Digit : Fractional width Color_Foreground : Select the foreground color Color_Background : Select the background color ******************************************************************************/ #define ARRAY_LEN 255 void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, - sFONT* Font, UWORD Digit,UWORD Color_Foreground, UWORD Color_Background) -{ + sFONT* Font, UWORD Digit,UWORD Color_Foreground, UWORD Color_Background) { int16_t Num_Bit = 0, Str_Bit = 0; uint8_t Str_Array[ARRAY_LEN] = {0}, Num_Array[ARRAY_LEN] = {0}; uint8_t *pStr = Str_Array; - int temp = Nummber; - float decimals; - uint8_t i; + int temp = Nummber; + float decimals; + uint8_t i; + if (Xpoint > Paint.Width || Ypoint > Paint.Height) { Debug("Paint_DisNum Input exceeds the normal display range\r\n"); return; } - if(Digit > 0) { - decimals = Nummber - temp; - for(i=Digit; i > 0; i--) { - decimals*=10; - } - temp = decimals; - //Converts a number to a string - for(i=Digit; i>0; i--) { - Num_Array[Num_Bit] = temp % 10 + '0'; - Num_Bit++; - temp /= 10; - } - Num_Array[Num_Bit] = '.'; - Num_Bit++; - } - - temp = Nummber; + if (Digit > 0) { + decimals = Nummber - temp; + + for(i = Digit; i > 0; i--) { + decimals*=10; + } + + temp = decimals; + + //Converts a number to a string + for(i=Digit; i>0; i--) { + Num_Array[Num_Bit] = temp % 10 + '0'; + Num_Bit++; + temp /= 10; + } + + Num_Array[Num_Bit] = '.'; + Num_Bit++; + } + + temp = Nummber; + //Converts a number to a string while (temp) { Num_Array[Num_Bit] = temp % 10 + '0'; Num_Bit++; temp /= 10; } - + //The string is inverted while (Num_Bit > 0) { Str_Array[Str_Bit] = Num_Array[Num_Bit - 1]; @@ -691,11 +700,11 @@ void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, double Nummber, } //show - Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground); + Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Foreground, Color_Background); } /****************************************************************************** -function: Display time +function: Display time parameter: Xstart :X coordinate Ystart : Y coordinate @@ -705,63 +714,56 @@ function: Display time Color_Background : Select the background color ******************************************************************************/ void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, - UWORD Color_Foreground, UWORD Color_Background) -{ + UWORD Color_Foreground, UWORD Color_Background) { uint8_t value[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; - UWORD Dx = Font->Width; //Write data into the cache - Paint_DrawChar(Xstart , Ystart, value[pTime->Hour / 10], Font, Color_Background, Color_Foreground); - Paint_DrawChar(Xstart + Dx , Ystart, value[pTime->Hour % 10], Font, Color_Background, Color_Foreground); - Paint_DrawChar(Xstart + Dx + Dx / 4 + Dx / 2 , Ystart, ':' , Font, Color_Background, Color_Foreground); - Paint_DrawChar(Xstart + Dx * 2 + Dx / 2 , Ystart, value[pTime->Min / 10] , Font, Color_Background, Color_Foreground); - Paint_DrawChar(Xstart + Dx * 3 + Dx / 2 , Ystart, value[pTime->Min % 10] , Font, Color_Background, Color_Foreground); - Paint_DrawChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':' , Font, Color_Background, Color_Foreground); - Paint_DrawChar(Xstart + Dx * 5 , Ystart, value[pTime->Sec / 10] , Font, Color_Background, Color_Foreground); - Paint_DrawChar(Xstart + Dx * 6 , Ystart, value[pTime->Sec % 10] , Font, Color_Background, Color_Foreground); - + Paint_DrawChar(Xstart, Ystart, value[pTime->Hour / 10], Font, Color_Foreground, Color_Background); + Paint_DrawChar(Xstart + Dx, Ystart, value[pTime->Hour % 10], Font, Color_Foreground, Color_Background); + Paint_DrawChar(Xstart + Dx + Dx / 4 + Dx / 2, Ystart, ':', Font, Color_Foreground, Color_Background); + Paint_DrawChar(Xstart + Dx * 2 + Dx / 2, Ystart, value[pTime->Min / 10], Font, Color_Foreground, Color_Background); + Paint_DrawChar(Xstart + Dx * 3 + Dx / 2, Ystart, value[pTime->Min % 10], Font, Color_Foreground, Color_Background); + Paint_DrawChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':', Font, Color_Foreground, Color_Background); + Paint_DrawChar(Xstart + Dx * 5, Ystart, value[pTime->Sec / 10], Font, Color_Foreground, Color_Background); + Paint_DrawChar(Xstart + Dx * 6, Ystart, value[pTime->Sec % 10], Font, Color_Foreground, Color_Background); } - -void Paint_DrawImage(const unsigned char *image, UWORD xStart, UWORD yStart, UWORD W_Image, UWORD H_Image) -{ - int i,j; - for(j = 0; j < H_Image; j++){ - for(i = 0; i < W_Image; i++){ - if(xStart+i < Paint.WidthMemory && yStart+j < Paint.HeightMemory)//Exceeded part does not display - Paint_SetPixel(xStart + i, yStart + j, (*(image + j*W_Image*2 + i*2+1))<<8 | (*(image + j*W_Image*2 + i*2))); - //Using arrays is a property of sequential storage, accessing the original array by algorithm - //j*W_Image*2 Y offset - //i*2 X offset - } - } +void Paint_DrawImage(const unsigned char *image, UWORD xStart, UWORD yStart, UWORD W_Image, UWORD H_Image) { + int i, j; + for (j = 0; j < H_Image; j++) { + for (i = 0; i < W_Image; i++) { + if (xStart + i < Paint.WidthMemory && yStart + j < Paint.HeightMemory) //Exceeded part does not display + Paint_SetPixel(xStart + i, yStart + j, (*(image + j * W_Image * 2 + i * 2 + 1)) << 8 | (*(image + j * W_Image * 2 + i * 2))); + //Using arrays is a property of sequential storage, accessing the original array by algorithm + //j*W_Image*2 Y offset + //i*2 X offset + } + } } -void Paint_DrawImage1(const unsigned char *image, UWORD xStart, UWORD yStart, UWORD W_Image, UWORD H_Image) -{ - int i,j; - for(j = 0; j < H_Image; j++){ - for(i = 0; i < W_Image; i++){ - if(xStart+i < Paint.HeightMemory && yStart+j < Paint.WidthMemory)//Exceeded part does not display - Paint_SetPixel(xStart + i, yStart + j, (*(image + j*W_Image*2 + i*2+1))<<8 | (*(image + j*W_Image*2 + i*2))); - //Using arrays is a property of sequential storage, accessing the original array by algorithm - //j*W_Image*2 Y offset - //i*2 X offset - } - } +void Paint_DrawImage1(const unsigned char *image, UWORD xStart, UWORD yStart, UWORD W_Image, UWORD H_Image) { + int i, j; + for (j = 0; j < H_Image; j++) { + for (i = 0; i < W_Image; i++) { + if (xStart + i < Paint.HeightMemory && yStart + j < Paint.WidthMemory) //Exceeded part does not display + Paint_SetPixel(xStart + i, yStart + j, (*(image + j * W_Image * 2 + i * 2 + 1)) << 8 | (*(image + j * W_Image * 2 + i * 2))); + //Using arrays is a property of sequential storage, accessing the original array by algorithm + //j*W_Image*2 Y offset + //i*2 X offset + } + } } /****************************************************************************** -function: Display monochrome bitmap +function: Display monochrome bitmap parameter: image_buffer :A picture data converted to a bitmap info: Use a computer to convert the image into a corresponding array, and then embed the array directly into Imagedata.cpp as a .c file. ******************************************************************************/ -void Paint_DrawBitMap(const unsigned char* image_buffer) -{ +void Paint_DrawBitMap(const unsigned char* image_buffer) { UWORD x, y; UDOUBLE Addr = 0; @@ -773,32 +775,28 @@ void Paint_DrawBitMap(const unsigned char* image_buffer) } } -void Paint_DrawBitMap_Block(const unsigned char* image_buffer, UBYTE Region) -{ +void Paint_DrawBitMap_Block(const unsigned char* image_buffer, UBYTE Region) { UWORD x, y; UDOUBLE Addr = 0; - for (y = 0; y < Paint.HeightByte; y++) { - for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte - Addr = x + y * Paint.WidthByte ; - Paint.Image[Addr] = \ - (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*(Region - 1)]; - } - } -} - + for (y = 0; y < Paint.HeightByte; y++) { + for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte + Addr = x + y * Paint.WidthByte ; + Paint.Image[Addr] = \ + (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*(Region - 1)]; + } + } +} void Paint_BmpWindows(unsigned char x,unsigned char y,const unsigned char *pBmp, - unsigned char chWidth,unsigned char chHeight) -{ - uint16_t i, j, byteWidth = (chWidth + 7)/8; - for(j = 0; j < chHeight; j ++){ - for(i = 0; i < chWidth; i ++ ) { - if(*(pBmp + j * byteWidth + i / 8) & (128 >> (i & 7))) { - Paint_SetPixel(x+i, y+j, 0xffff); + unsigned char chWidth,unsigned char chHeight) { + uint16_t i, j, byteWidth = (chWidth + 7) / 8; + + for (j = 0; j < chHeight; j ++) { + for (i = 0; i < chWidth; i ++ ) { + if (*(pBmp + j * byteWidth + i / 8) & (128 >> (i & 7))) { + Paint_SetPixel(x + i, y + j, 0xffff); } } } } - - diff --git a/c/lib/LCD/LCD_1in28.c b/c/lib/LCD/LCD_1in28.c new file mode 100644 index 0000000..13f6889 --- /dev/null +++ b/c/lib/LCD/LCD_1in28.c @@ -0,0 +1,495 @@ +/***************************************************************************** +* | File : LCD_1in28.c +* | Author : Waveshare team, Julianno F. C. Silva (@juliannojungle) +* | Function : Hardware underlying interface +* | Info : +* Used to shield the underlying layers of each master +* and enhance portability +*---------------- +* | This version: V1.0 +* | Date : 2023-03-26 +* | Info : Basic version +* +******************************************************************************/ +#include "LCD_1in28.h" +#include "DEV_Config.h" + +#include //itoa() +#include + +LCD_1IN28_ATTRIBUTES LCD_1IN28; + +/****************************************************************************** +function : Hardware reset +parameter: +******************************************************************************/ +static void LCD_1IN28_Reset(void) +{ + DEV_Digital_Write(EPD_RST_PIN, 1); + DEV_Delay_ms(100); + DEV_Digital_Write(EPD_RST_PIN, 0); + DEV_Delay_ms(100); + DEV_Digital_Write(EPD_RST_PIN, 1); + DEV_Delay_ms(100); +} + +/****************************************************************************** +function : send command +parameter: + Reg : Command register +******************************************************************************/ +static void LCD_1IN28_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 LCD_1IN28_SendData_8Bit(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 : send data +parameter: + Data : Write data +******************************************************************************/ +static void LCD_1IN28_SendData_16Bit(UWORD Data) +{ + DEV_Digital_Write(EPD_DC_PIN, 1); + DEV_Digital_Write(EPD_CS_PIN, 0); + DEV_SPI_WriteByte((Data >> 8) & 0xFF); + DEV_SPI_WriteByte(Data & 0xFF); + DEV_Digital_Write(EPD_CS_PIN, 1); +} + +/****************************************************************************** +function : Initialize the lcd register +parameter: +******************************************************************************/ +static void LCD_1IN28_InitReg(void) +{ + LCD_1IN28_SendCommand(0x11); /* Sleep mode OFF */ + + DEV_Delay_ms(120); /* Delay 120ms */ + + LCD_1IN28_SendCommand(0xEF); /* Inter register enable 2 */ + + LCD_1IN28_SendCommand(0xEB); + LCD_1IN28_SendData_8Bit(0x14); + + /* BEGIN set inter_command HIGH */ + LCD_1IN28_SendCommand(0xFE); /* Inter register enable 1 */ + LCD_1IN28_SendCommand(0xEF); /* Inter register enable 2 */ + /* END set inter_command HIGH */ + + LCD_1IN28_SendCommand(0xEB); + LCD_1IN28_SendData_8Bit(0x14); + + LCD_1IN28_SendCommand(0x84); + LCD_1IN28_SendData_8Bit(0x40); + + LCD_1IN28_SendCommand(0x85); + LCD_1IN28_SendData_8Bit(0xFF); + + LCD_1IN28_SendCommand(0x86); + LCD_1IN28_SendData_8Bit(0xFF); + + LCD_1IN28_SendCommand(0x87); + LCD_1IN28_SendData_8Bit(0xFF); + + LCD_1IN28_SendCommand(0x88); + LCD_1IN28_SendData_8Bit(0x0A); + + LCD_1IN28_SendCommand(0x89); + LCD_1IN28_SendData_8Bit(0x21); + + LCD_1IN28_SendCommand(0x8A); + LCD_1IN28_SendData_8Bit(0x00); + + LCD_1IN28_SendCommand(0x8B); + LCD_1IN28_SendData_8Bit(0x80); + + LCD_1IN28_SendCommand(0x8C); + LCD_1IN28_SendData_8Bit(0x01); + + LCD_1IN28_SendCommand(0x8D); + LCD_1IN28_SendData_8Bit(0x01); + + LCD_1IN28_SendCommand(0x8E); + LCD_1IN28_SendData_8Bit(0xFF); + + LCD_1IN28_SendCommand(0x8F); + LCD_1IN28_SendData_8Bit(0xFF); + + /* Display function control */ + LCD_1IN28_SendCommand(0xB6); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x00); + /* END Display function control */ + + /* Memory access control - defined on LCD_1IN28_SetAttributes */ + // LCD_1IN28_SendCommand(0x36); + // LCD_1IN28_SendData_8Bit(0x48); + /* END Memory access control */ + + /* Pixel format */ + LCD_1IN28_SendCommand(0x3A); + LCD_1IN28_SendData_8Bit(0x05); + /* END Pixel format */ + + LCD_1IN28_SendCommand(0x90); + LCD_1IN28_SendData_8Bit(0x08); + LCD_1IN28_SendData_8Bit(0x08); + LCD_1IN28_SendData_8Bit(0x08); + LCD_1IN28_SendData_8Bit(0x08); + + LCD_1IN28_SendCommand(0xBD); + LCD_1IN28_SendData_8Bit(0x06); + + LCD_1IN28_SendCommand(0xBC); + LCD_1IN28_SendData_8Bit(0x00); + + LCD_1IN28_SendCommand(0xFF); + LCD_1IN28_SendData_8Bit(0x60); + LCD_1IN28_SendData_8Bit(0x01); + LCD_1IN28_SendData_8Bit(0x04); + + /* Voltage regulator 1a */ + LCD_1IN28_SendCommand(0xC3); + LCD_1IN28_SendData_8Bit(0x13); + /* END Voltage regulator 1a */ + + /* Voltage regulator 1b */ + LCD_1IN28_SendCommand(0xC4); + LCD_1IN28_SendData_8Bit(0x13); + /* END Voltage regulator 1b */ + + /* Voltage regulator 2a */ + LCD_1IN28_SendCommand(0xC9); + LCD_1IN28_SendData_8Bit(0x22); + /* END Voltage regulator 2a */ + + LCD_1IN28_SendCommand(0xBE); + LCD_1IN28_SendData_8Bit(0x11); + + LCD_1IN28_SendCommand(0xE1); + LCD_1IN28_SendData_8Bit(0x10); + LCD_1IN28_SendData_8Bit(0x0E); + + LCD_1IN28_SendCommand(0xDF); + LCD_1IN28_SendData_8Bit(0x21); + LCD_1IN28_SendData_8Bit(0x0c); + LCD_1IN28_SendData_8Bit(0x02); + + /* Set gamma1 */ + LCD_1IN28_SendCommand(0xF0); + LCD_1IN28_SendData_8Bit(0x45); + LCD_1IN28_SendData_8Bit(0x09); + LCD_1IN28_SendData_8Bit(0x08); + LCD_1IN28_SendData_8Bit(0x08); + LCD_1IN28_SendData_8Bit(0x26); + LCD_1IN28_SendData_8Bit(0x2A); + /* END Set gamma1 */ + + /* Set gamma2 */ + LCD_1IN28_SendCommand(0xF1); + LCD_1IN28_SendData_8Bit(0x43); + LCD_1IN28_SendData_8Bit(0x70); + LCD_1IN28_SendData_8Bit(0x72); + LCD_1IN28_SendData_8Bit(0x36); + LCD_1IN28_SendData_8Bit(0x37); + LCD_1IN28_SendData_8Bit(0x6F); + /* END Set gamma2 */ + + /* Set gamma3 */ + LCD_1IN28_SendCommand(0xF2); + LCD_1IN28_SendData_8Bit(0x45); + LCD_1IN28_SendData_8Bit(0x09); + LCD_1IN28_SendData_8Bit(0x08); + LCD_1IN28_SendData_8Bit(0x08); + LCD_1IN28_SendData_8Bit(0x26); + LCD_1IN28_SendData_8Bit(0x2A); + /* END Set gamma3 */ + + /* Set gamma4 */ + LCD_1IN28_SendCommand(0xF3); + LCD_1IN28_SendData_8Bit(0x43); + LCD_1IN28_SendData_8Bit(0x70); + LCD_1IN28_SendData_8Bit(0x72); + LCD_1IN28_SendData_8Bit(0x36); + LCD_1IN28_SendData_8Bit(0x37); + LCD_1IN28_SendData_8Bit(0x6F); + /* END Set gamma4 */ + + LCD_1IN28_SendCommand(0xED); + LCD_1IN28_SendData_8Bit(0x1B); + LCD_1IN28_SendData_8Bit(0x0B); + + LCD_1IN28_SendCommand(0xAE); + LCD_1IN28_SendData_8Bit(0x77); + + LCD_1IN28_SendCommand(0xCD); + LCD_1IN28_SendData_8Bit(0x63); + + LCD_1IN28_SendCommand(0x70); + LCD_1IN28_SendData_8Bit(0x07); + LCD_1IN28_SendData_8Bit(0x07); + LCD_1IN28_SendData_8Bit(0x04); + LCD_1IN28_SendData_8Bit(0x0E); + LCD_1IN28_SendData_8Bit(0x0F); + LCD_1IN28_SendData_8Bit(0x09); + LCD_1IN28_SendData_8Bit(0x07); + LCD_1IN28_SendData_8Bit(0x08); + LCD_1IN28_SendData_8Bit(0x03); + + /* Frame rate */ + LCD_1IN28_SendCommand(0xE8); + LCD_1IN28_SendData_8Bit(0x34); + /* END Frame rate */ + + LCD_1IN28_SendCommand(0x62); + LCD_1IN28_SendData_8Bit(0x18); + LCD_1IN28_SendData_8Bit(0x0D); + LCD_1IN28_SendData_8Bit(0x71); + LCD_1IN28_SendData_8Bit(0xED); + LCD_1IN28_SendData_8Bit(0x70); + LCD_1IN28_SendData_8Bit(0x70); + LCD_1IN28_SendData_8Bit(0x18); + LCD_1IN28_SendData_8Bit(0x0F); + LCD_1IN28_SendData_8Bit(0x71); + LCD_1IN28_SendData_8Bit(0xEF); + LCD_1IN28_SendData_8Bit(0x70); + LCD_1IN28_SendData_8Bit(0x70); + + LCD_1IN28_SendCommand(0x63); + LCD_1IN28_SendData_8Bit(0x18); + LCD_1IN28_SendData_8Bit(0x11); + LCD_1IN28_SendData_8Bit(0x71); + LCD_1IN28_SendData_8Bit(0xF1); + LCD_1IN28_SendData_8Bit(0x70); + LCD_1IN28_SendData_8Bit(0x70); + LCD_1IN28_SendData_8Bit(0x18); + LCD_1IN28_SendData_8Bit(0x13); + LCD_1IN28_SendData_8Bit(0x71); + LCD_1IN28_SendData_8Bit(0xF3); + LCD_1IN28_SendData_8Bit(0x70); + LCD_1IN28_SendData_8Bit(0x70); + + LCD_1IN28_SendCommand(0x64); + LCD_1IN28_SendData_8Bit(0x28); + LCD_1IN28_SendData_8Bit(0x29); + LCD_1IN28_SendData_8Bit(0xF1); + LCD_1IN28_SendData_8Bit(0x01); + LCD_1IN28_SendData_8Bit(0xF1); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x07); + + LCD_1IN28_SendCommand(0x66); + LCD_1IN28_SendData_8Bit(0x3C); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0xCD); + LCD_1IN28_SendData_8Bit(0x67); + LCD_1IN28_SendData_8Bit(0x45); + LCD_1IN28_SendData_8Bit(0x45); + LCD_1IN28_SendData_8Bit(0x10); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x00); + + LCD_1IN28_SendCommand(0x67); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x3C); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x01); + LCD_1IN28_SendData_8Bit(0x54); + LCD_1IN28_SendData_8Bit(0x10); + LCD_1IN28_SendData_8Bit(0x32); + LCD_1IN28_SendData_8Bit(0x98); + + LCD_1IN28_SendCommand(0x74); + LCD_1IN28_SendData_8Bit(0x10); + LCD_1IN28_SendData_8Bit(0x85); + LCD_1IN28_SendData_8Bit(0x80); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(0x4E); + LCD_1IN28_SendData_8Bit(0x00); + + LCD_1IN28_SendCommand(0x98); + LCD_1IN28_SendData_8Bit(0x3e); + LCD_1IN28_SendData_8Bit(0x07); + + LCD_1IN28_SendCommand(0x35); /* Tearing effect ON */ + + LCD_1IN28_SendCommand(0x21); /* Display color inversion ON */ + + LCD_1IN28_SendCommand(0x11); /* Sleep mode OFF */ + + DEV_Delay_ms(12); /* Delay 12ms */ + + LCD_1IN28_SendCommand(0x29); /* Display ON */ + + DEV_Delay_ms(20); /* Delay 20ms */ +} + +/******************************************************************************** +function: Set the resolution and scanning method of the screen +parameter: + Scan_dir: Scan direction +********************************************************************************/ +static void LCD_1IN28_SetAttributes(UBYTE Scan_dir) +{ + //Get the screen scan direction + LCD_1IN28.SCAN_DIR = Scan_dir; + UBYTE MemoryAccessReg = 0x00; + + //Get GRAM and LCD width and height + if(Scan_dir == HORIZONTAL) { + LCD_1IN28.HEIGHT = LCD_1IN28_WIDTH; + LCD_1IN28.WIDTH = LCD_1IN28_HEIGHT; + MemoryAccessReg = 0x48; + } else { + LCD_1IN28.HEIGHT = LCD_1IN28_HEIGHT; + LCD_1IN28.WIDTH = LCD_1IN28_WIDTH; + MemoryAccessReg = 0x24; + } + + // Set the read / write scan direction of the frame memory + LCD_1IN28_SendCommand(0x36); //MX, MY, RGB mode + LCD_1IN28_SendData_8Bit(MemoryAccessReg); //0x08 set RGB +} + +/******************************************************************************** +function : Initialize the lcd +parameter: +********************************************************************************/ +void LCD_1IN28_Init(UBYTE Scan_dir) +{ + DEV_SET_PWM(90); + //Hardware reset + LCD_1IN28_Reset(); + + //Set the resolution and scanning method of the screen + LCD_1IN28_SetAttributes(Scan_dir); + + //Set the initialization register + LCD_1IN28_InitReg(); +} + +/******************************************************************************** +function: Sets the start position and size of the display area +parameter: + Xstart: X direction Start coordinates + Ystart: Y direction Start coordinates + Xend : X direction end coordinates + Yend : Y direction end coordinates +********************************************************************************/ +void LCD_1IN28_SetWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend) +{ + //set the X coordinates + LCD_1IN28_SendCommand(0x2A); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(Xstart); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(Xend-1); + + //set the Y coordinates + LCD_1IN28_SendCommand(0x2B); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(Ystart); + LCD_1IN28_SendData_8Bit(0x00); + LCD_1IN28_SendData_8Bit(Yend-1); + + LCD_1IN28_SendCommand(0X2C); + // printf("%d %d\r\n",x,y); +} + +/****************************************************************************** +function : Clear screen +parameter: +******************************************************************************/ +void LCD_1IN28_Clear(UWORD Color) +{ + UWORD j,i; + UWORD Image[LCD_1IN28.WIDTH*LCD_1IN28.HEIGHT]; + + Color = ((Color<<8)&0xff00)|(Color>>8); + + for (j = 0; j < LCD_1IN28.HEIGHT*LCD_1IN28.WIDTH; j++) { + Image[j] = Color; + } + + LCD_1IN28_SetWindows(0, 0, LCD_1IN28.WIDTH, LCD_1IN28.HEIGHT); + DEV_Digital_Write(EPD_DC_PIN, 1); + DEV_Digital_Write(EPD_CS_PIN, 0); + // printf("HEIGHT %d, WIDTH %d\r\n",LCD_1IN28.HEIGHT,LCD_1IN28.WIDTH); + + for (j = 0; j < LCD_1IN28.HEIGHT; j++) { + DEV_SPI_Write_nByte((uint8_t *)&Image[j*LCD_1IN28.WIDTH], LCD_1IN28.WIDTH*2); + } + + DEV_Digital_Write(EPD_CS_PIN, 1); +} + +/****************************************************************************** +function : Sends the image buffer in RAM to displays +parameter: +******************************************************************************/ +void LCD_1IN28_Display(UWORD *Image) +{ + UWORD j; + LCD_1IN28_SetWindows(0, 0, LCD_1IN28.WIDTH, LCD_1IN28.HEIGHT); + DEV_Digital_Write(EPD_DC_PIN, 1); + DEV_Digital_Write(EPD_CS_PIN, 0); + + for (j = 0; j < LCD_1IN28.HEIGHT; j++) { + DEV_SPI_Write_nByte((uint8_t *)&Image[j*LCD_1IN28.WIDTH], LCD_1IN28.WIDTH*2); + } + + DEV_Digital_Write(EPD_CS_PIN, 1); + LCD_1IN28_SendCommand(0x29); +} + +void LCD_1IN28_DisplayWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD *Image) +{ + // display + UDOUBLE Addr = 0; + UWORD j; + LCD_1IN28_SetWindows(Xstart, Ystart, Xend , Yend); + DEV_Digital_Write(EPD_DC_PIN, 1); + DEV_Digital_Write(EPD_CS_PIN, 0); + + for (j = Ystart; j < Yend - 1; j++) { + Addr = Xstart + j * LCD_1IN28.WIDTH ; + DEV_SPI_Write_nByte((uint8_t *)&Image[Addr], (Xend-Xstart)*2); + } + + DEV_Digital_Write(EPD_CS_PIN, 1); +} + +void LCD_1IN28_DisplayPoint(UWORD X, UWORD Y, UWORD Color) +{ + LCD_1IN28_SetWindows(X,Y,X,Y); + LCD_1IN28_SendData_16Bit(Color); +} + +void Handler_1IN28_LCD(int signo) +{ + //System Exit + printf("\r\nHandler:Program stop\r\n"); + DEV_Module_Exit(); + exit(0); +} diff --git a/c/lib/LCD/LCD_1in28.h b/c/lib/LCD/LCD_1in28.h new file mode 100644 index 0000000..bd63772 --- /dev/null +++ b/c/lib/LCD/LCD_1in28.h @@ -0,0 +1,49 @@ +/***************************************************************************** +* | File : LCD_1in28.h +* | Author : Waveshare team, Julianno F. C. Silva (@juliannojungle) +* | Function : Hardware underlying interface +* | Info : +* Used to shield the underlying layers of each master +* and enhance portability +*---------------- +* | This version: V1.0 +* | Date : 2023-03-26 +* | Info : Basic version +* +******************************************************************************/ +#ifndef __LCD_1IN28_H +#define __LCD_1IN28_H + +#include "DEV_Config.h" +#include + +#include //itoa() +#include + +#define LCD_1IN28_HEIGHT 240 +#define LCD_1IN28_WIDTH 240 + +#define HORIZONTAL 0 +#define VERTICAL 1 + +#define LCD_1IN28_SetBacklight(Value); + +typedef struct{ + UWORD WIDTH; + UWORD HEIGHT; + UBYTE SCAN_DIR; +}LCD_1IN28_ATTRIBUTES; +extern LCD_1IN28_ATTRIBUTES LCD_1IN28; + +/******************************************************************************** +function: + Macro definition variable name +********************************************************************************/ +void LCD_1IN28_Init(UBYTE Scan_dir); +void LCD_1IN28_Clear(UWORD Color); +void LCD_1IN28_Display(UWORD *Image); +void LCD_1IN28_DisplayWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD *Image); +void LCD_1IN28_DisplayPoint(UWORD X, UWORD Y, UWORD Color); + +void Handler_1IN28_LCD(int signo); +#endif diff --git a/c/lib/LCD/LCD_2in.c b/c/lib/LCD/LCD_2in.c index 99c0567..667c1ea 100644 --- a/c/lib/LCD/LCD_2in.c +++ b/c/lib/LCD/LCD_2in.c @@ -11,7 +11,7 @@ * | Info : Basic version * ******************************************************************************/ -#include "LCD_2IN.h" +#include "LCD_2in.h" #include "DEV_Config.h" #include //itoa() diff --git a/c/main.c b/c/main.c index a68644d..21af2e7 100644 --- a/c/main.c +++ b/c/main.c @@ -5,12 +5,12 @@ int main(void) //OLED //OLED_1in3_C_test(); //OLED_2in23_test(); - - + //LCD - //LCD_0in96_test(); + //LCD_0in96_test(); //LCD_1in14_test(); - //LCD_1in3_test(); + //LCD_1in28_test(); + //LCD_1in3_test(); //LCD_1in44_test(); //LCD_1in8_test(); LCD_2in_test(); diff --git a/c/uf2/LCD_1in28_test.uf2 b/c/uf2/LCD_1in28_test.uf2 new file mode 100644 index 0000000..debdd53 Binary files /dev/null and b/c/uf2/LCD_1in28_test.uf2 differ