//Example for Seeed Studio's 3-Color E-Ink display // Copyright (C) 2022 Raymond Allen // MIT License // Modified by RJA to work on Parallax Propeller I & II using FlexProp 5.9.6 //RJA: The original is here: https://github.com/Seeed-Studio/Seeed_Elink_Shield //RJA: This file is an adaptation of the Aruduino C++ file epd2in7b-demo.ino //RJA: Overall, the main change is turning the C++ to plain C and adding P2 specific pin work in epdif.c #include "platform.h" //settings and includes are here //RJA: Pin# settings are at top of epdif.h !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //RJA: To allow compiliation with FlexProp GUI, the .c files are here as includes so they don't need to be listed on the build command line #include "epd2in7b.h" #include "epdif.h" #include "epdpaint.h" #include "fonts.h" #include "epd2in7b.c" #include "epdif.c" #include "epdpaint.c" uint8_t stack[100]; int main() { printf("Initializing E-Ink...\n"); Init(); //RJA: init E-Ink display //printf("Running demo...\n"); //Demo(); //RJA: Run the original demo printf("Drawing Background...\n"); DrawBackground(); printf("Done.\n"); for (;;) {} } #define COLORED 1 #define UNCOLORED 0 //RJA: This is the local display buffer for drawing //RJA: Needs to be big enough for 1 bit per pixel for the screen are defined by Paint() or SetWidth()&SetHeight() //RJA: This is done for MCU with small memories, like P1 and Arduino //RJA: For P2, we can have buffers equal to full display size for both red and black unsigned char imageb[3000]; void DrawBackground() { //RJA: The display has an SRAM buffers for black and red data that we write to and at the end we tell it to update display using that buffer //RJA: For drawing, we use a seperate buffer in HUB RAM //RJA: Note: Driver written for portrait mode, but there is a SetRotate() function to set one of four screen rotations, such as ROTATE_90, defined in epdpaint.h /* This clears the SRAM of the e-paper display */ ClearFrame(); printf("Frame Cleared\n"); //Note: Resolution in absolute (not rotated) is 176x264 //Init Paint in given window size //Note: X and Y are absolute, not rotated Paint(imageb, 64, 264); //width should be the multiple of 8 printf("Paint Started\n"); //Rotate to landscape mode (have to do this after Paint() as that resets rotation to 0) SetRotate(ROTATE_270); //clear buffer Clear(UNCOLORED); //RJA: Fill local buffer with zeros //draw title DrawStringAt(5, 20, "Bruno Feed Tracker", &Font20, COLORED); //RJA: Draw string in color //Draw lines above and below text DrawFilledRectangle(0, 45, 263, 58, COLORED); DrawFilledRectangle(0, 0, 263, 13, COLORED); //Note: X and Y are absolute, not rotated --> Give the top-left corner of grapics box from the non-rotated point of view TransmitPartialBlack(GetImage(), 0, 0, GetWidth(), GetHeight()); //RJA: Send this area to display's black pixel SRAM //Draw Days of the Week //clear buffer Clear(UNCOLORED); //RJA: Fill local buffer with zeros DrawStringAt(35, 20, "Su Mo Tu We Th Fr Sa", &Font16, COLORED); //RJA: Draw string in color //Note: X and Y are absolute, not rotated --> Give the top-left corner of grapics box from the non-rotated point of view TransmitPartialBlack(GetImage(), 70, 0, GetWidth(), GetHeight()); //RJA: Send this area to display's black pixel SRAM //Draw AM/PM and circles in black //clear buffer Clear(UNCOLORED); //RJA: Fill local buffer with zeros DrawStringAt(5, 5, "AM", &Font16, COLORED); //RJA: Draw string in color DrawStringAt(5, 30, "PM", &Font16, COLORED); //RJA: Draw string in color //Note: X and Y are absolute, not rotated --> Give the top-left corner of grapics box from the non-rotated point of view TransmitPartialBlack(GetImage(), 110, 0, GetWidth(), GetHeight()); //RJA: Send this area to display's black pixel SRAM //Draw squares in RED //clear buffer Clear(UNCOLORED); //RJA: Fill local buffer with zeros int w = 23; int d = 33; int x1 = 35; int y1 = 0; for (int i=0;i<7;i++) for (int j=0;j<2;j++) DrawFilledRectangle(x1 + i * d, y1 + j * d, x1 + w + i * d, y1 + w + j * d, COLORED); TransmitPartialRed(GetImage(), 110, 0, GetWidth(), GetHeight()); //RJA: Send this area to display's red pixel SRAM /* This displays the data from the SRAM in e-Paper module */ //RJA: After filling the displays red and black SRAM with image data, final step is to tell it to refresh the screen with the SRAM data RefreshFrame(); } void Demo() { //RJA: The display has an SRAM buffers for black and red data that we write to and at the end we tell it to update display using that buffer //RJA: For drawing, we use a seperate buffer in HUB RAM //RJA: Note: Driver written for portrait mode, but there is a SetRotate() function to set one of four screen rotations, such as ROTATE_90, defined in epdpaint.h /* This clears the SRAM of the e-paper display */ ClearFrame(); printf("Frame Cleared\n"); /** Due to RAM not enough in Arduino UNO, a frame buffer is not allowed. In this case, a smaller image buffer is allocated and you have to update a partial display several times. 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time. */ Paint(imageb, 176, 24); //width should be the multiple of 8 printf("Paint Started\n"); Clear(UNCOLORED); //RJA: Fill local buffer with zeros DrawStringAt(0, 0, "e-Paper Demo", &Font16, COLORED); //RJA: Draw string in color TransmitPartialBlack(GetImage(), 16, 32, GetWidth(), GetHeight()); //RJA: Send this area to display's black pixel SRAM Clear(COLORED); //RJA: Fill local buffer with ones DrawStringAt(2, 2, "Hello P1 World!", &Font16, UNCOLORED); //RJA: Draw string, by removing color TransmitPartialRed(GetImage(), 0, 64, GetWidth(), GetHeight()); //RJA: Send this area to display's red pixel SRAM SetWidth(64); SetHeight(64); //RJA: inspect local buffer width, height, and image buffer pointers (for debugging) printf("Width=%d, Height=%d, pImage=%d\n", GetWidth(), GetHeight(), GetImage()); //RJA: This draws the hollow black box and cross on middle, left of screen Clear(UNCOLORED); DrawRectangle(0, 0, 40, 50, COLORED); DrawLine(0, 0, 40, 50, COLORED); DrawLine(40, 0, 0, 50, COLORED); TransmitPartialBlack(GetImage(), 10, 130, GetWidth(), GetHeight()); Clear(UNCOLORED); DrawCircle(32, 32, 30, COLORED); TransmitPartialBlack(GetImage(), 90, 120, GetWidth(), GetHeight()); Clear(UNCOLORED); DrawFilledRectangle(0, 0, 40, 50, COLORED); TransmitPartialRed(GetImage(), 10, 200, GetWidth(), GetHeight()); //RJA: Testing what happens if pixels are set for both red and black //RJA: Looks like red wins //Clear(UNCOLORED); //DrawFilledRectangle(0, 0, 40, 50, COLORED); //TransmitPartialBlack(GetImage(), 30, 200, GetWidth(), GetHeight()); Clear(UNCOLORED); DrawFilledCircle(32, 32, 30, COLORED); TransmitPartialRed(GetImage(), 90, 190, GetWidth(), GetHeight()); /* This displays the data from the SRAM in e-Paper module */ //RJA: After filling the displays red and black SRAM with image data, final step is to tell it to refresh the screen with the SRAM data RefreshFrame(); }