RA8876 Parallel Display Library Testing

@KurtE and @wwatson

Lied a bit.
1. Updated the _p branch to @KurtE's drawChar changes
and
2. Figured out my issue with the sketch. Chanaged clock from 20 to 18 and it worked.

EDIT: Back to running at 20Mhz. Forgot to uncomment delaynanoseconds (missed a change)
Code:
delayNanoseconds(10);  // Initially setup for the T4.1 board
Change pushed to branch
That delay is what I adjusted for longer wires on the MicroMod and Dev Board to get the highest clock speeds. If it is not large enough you usually see 2D errors...
 
That delay is what I adjusted for longer wires on the MicroMod and Dev Board to get the highest clock speeds. If it is not large enough you usually see 2D errors...
Interesting before I made the change I had to run it at 18mhz, after I can run at 20Mhz without issue. Could be the wire length?

PS. With the change ran at 24Mhz no issue, 30mhz ran but saw some tearing. Used the pictureembed sketch and writeRotatedRect sketch

NOTE: Retested this morning with the delay commented out and guess what it WORKED this time. Must have a ghost in the system. Nothing else changed ????? I am so confused and hate when this happens.
 
added a few extra functions to my branch:
readPixel
readRect
fillRectVGradient
fillRectHGradient

So @KurtE's test sketch is beginning to get filled out (test sketch now in testcases directory)
1719491566776.jpeg
 
Interesting before I made the change I had to run it at 18mhz, after I can run at 20Mhz without issue. Could be the wire length?

PS. With the change ran at 24Mhz no issue, 30mhz ran but saw some tearing. Used the pictureembed sketch and writeRotatedRect sketch

NOTE: Retested this morning with the delay commented out and guess what it WORKED this time. Must have a ghost in the system. Nothing else changed ????? I am so confused and hate when this happens.

added a few extra functions to my branch:
readPixel
readRect
fillRectVGradient
fillRectHGradient

So @KurtE's test sketch is beginning to get filled out (test sketch now in testcases directory)
View attachment 34814
Works on my side as well. Glad your side is up and running. There are times when I have to completely power down the Teensy and the display and power up just to make sure they are not in a bad state. This also goes for the Arduino IDE's.
 
@wwatson - @KurtE
Went through and updated all the examples so they would run using SPI or 8080, just adjust the define accordingly.
Code:
//#define use_spi
#if defined(use_spi)
#include <SPI.h>
#include <RA8876_t3.h>
#else
#include <RA8876_t41_p.h>
#endif

Ran through all the examples except USB and touch examples. Just noticed that Touch is missing from the parallel library.

Also was thinking there is a lot of duplication of code between the 3 libraries wondering if its worth creating a separate class for the common code if the 3 libs are going to remain separate.
 
Morning, all.
I was trying out my writeRect8BPP and the like the WriteRect example is not working on 2nd image:
1719574896819.png

From I believe this code:
Code:
        uint16_t *rotatedImage = tft.rotateImageRect(400, 272, td_t4_top, rotation);
        tft.writeRotatedRect(CENTER, CENTER, 400, 272, rotatedImage);  // 480x320
        free(rotatedImage);
        nextPage();

I commented it out and the next and my new output shows..

EDIT: should mention SPI version and on T4.1 slightly modified from your testcase version... Added my other calls after this,
plus changed pin numbers, and turn on backlight...
 
I was trying out my writeRect8BPP and the like the WriteRect example is not working on 2nd image:
Noticed that last night as well on the SPI version but seems to work on the parallel version. Not sure why yet. In process of checking all the SPI examples are working right now.
 
Quick updates:
@mjs513 found swapping the order of the two drawings of the images, worked... May need to debug it later. Not sure could be malloc issue? Maybe not as works on FlexIO version, Maybe with SPI using DMA? ... Maybe memory overwrite? ...

I also found that the SPI version has problem with the writeRect in rotation 2...
1719583416232.png

This is in rotation 2. SPI version on top. the White rectangle bottom right starts at 10, 10 done by fillRect.
The red rectangle should be an opposite corner using writeRect... I filled a memory area with 400 RED... and did a 20,20
Notice the FlexIO one is correct, the SPI version is not.

I have put in the writeRect fix plus writeRect8BPP 1BPP, 2BPP, 4BPP NBPP up into a new branch:

Will do PR after some more testing
 
@mjs513 - Finally back to test the latest changes you made. As far as creating a common class, that makes sense. Kind of like the FS class. Maintaining all of the branches can be confusing, time consuming and error prone. Having it all in one big file makes it really hard to maintain as well. Having separate board specific classes would make it easier to maintain and port.

@KurtE - That little square in the upper left corner looks suspiciously like a text cursor. Did you happen to run a previous sketch that had the text cursor turned on? The reason I am asking is I ran into the same thing myself and it was due to not turning off the cursor during board initialization. I have since added:
Code:
    // Setup graphic cursor
    Set_Graphic_Cursor_Color_1(0xff); // Foreground color
    Set_Graphic_Cursor_Color_2(0x00); // Outline color
        Disable_Graphic_Cursor(); // Turn off Graphic Cusor
------>        Disable_Text_Cursor(); // Turn off text Cusor     <-----------------
    Graphic_cursor_initial();  // Initialize Graphic Cursor
    Select_Graphic_Cursor_2(); // Select Arrow Graphic Cursor
    // Set default foreground and background colors
    setTextColor(_TXTForeColor, _TXTBackColor);  
    // Position text cursor to default
    setTextCursor(_scrollXL, _scrollYT);
    // Setup Text Cursor
    cursorInit();
    // Set Margins to default settings
    setTMargins(0, 0, 0, 0); // Left Side, Top Side, Right Side, Bottom Side

    // This must be called before usage of fillScreen() which calls drawSquareFill().
    // drawSquareFill() is ineffective otherwise.
    setClipRect();
to ra8876Initialize() at about line #785 in the .cpp file. That could be a possible reason you are seeing that.
Then again, maybe not :)
EDIT: Never mind you fixed it. I did add the disable text cursor to the init routine...
 
hat little square in the upper left corner looks suspiciously like a text cursor.
Note: I added that rectangle as a test to see where the origin is for the rotation.
C++:
// Set which Display we are using and at what speed
// Currently I have options for both MICROMOD and T42 to make it
// easier for testing

#include "Arduino.h"
#define use_spi

#if defined(use_spi)
#include <SPI.h>
#include <RA8876_t3.h>
#else
#include <RA8876_t41_p.h>
#endif
#include "font_Arial.h"
#include "flexio_teensy_mm.c"
#include "T41_top_card.c"

#if defined(use_spi)
//#define TFT_CS 8
//#define TFT_RST 9
#define TFT_CS 30
#define TFT_RST 28
#define RA8875_INT 6
#define TFT_BL 29

RA8876_t3 tft = RA8876_t3(TFT_CS, TFT_RST);
#else
uint8_t dc = 13;
uint8_t cs = 11;
uint8_t rst = 12;
RA8876_t41_p tft = RA8876_t41_p(dc,cs,rst); //(dc, cs, rst)
#endif

void setup() {
    Serial.begin(115200);
    delay(1000);
    if (CrashReport) {
        Serial.print(CrashReport);
    }

#if defined(TFT_BL)
    pinMode(TFT_BL, OUTPUT);
    digitalWrite(TFT_BL, HIGH);
#endif

#if defined(use_spi)
  tft.begin(18000000); // 20 is working in 8bit and 16bit mode on T41
#else
  tft.begin(20);
#endif
    tft.backlight(true);

  tft.graphicMode(true);
  tft.setTextCursor(0,0);
  tft.setFont(Arial_14);


    for (uint8_t rotation = 0; rotation < 4; rotation++) {
        tft.setRotation(rotation);
        displayRotation(rotation);
        delay(1000);
        tft.fillScreen(BLACK);
    }
    tft.setRotation(0);
}

void loop() {
    for (uint8_t rotation = 0; rotation < 4; rotation++) {
        tft.setRotation(rotation);
        displayRotation(rotation);
        nextPage();

         uint16_t *rotatedImage = tft.rotateImageRect(480, 320, flexio_teensy_mm, rotation);
        tft.writeRotatedRect(CENTER, CENTER, 480, 320, rotatedImage);  // 480x320
        free(rotatedImage);
        nextPage();
       rotatedImage = tft.rotateImageRect(400, 272, td_t4_top, rotation);
        tft.writeRotatedRect(CENTER, CENTER, 400, 272, rotatedImage);  // 480x320
        free(rotatedImage);
        nextPage();
        tft.writeRect(CENTER, CENTER, 480, 320, flexio_teensy_mm);  // 480x320
        int ch = nextPage();
        if (ch != 's') {
            draw_8bit_bmp(rotation);
            nextPage();
        }
    }
}

void draw_8bit_bmp(uint8_t rotation) {
    uint16_t palette[] = { RED, GREEN, BLUE, YELLOW, CYAN, WHITE, BLACK, MAGENTA };

#define BAND_WIDTH 200
#define BAND_HEIGHT 50
#define BANDS (sizeof(palette) / sizeof(palette[0]))
    uint8_t *buffer = (uint8_t *)malloc(BAND_WIDTH * BAND_HEIGHT * BANDS);
    if (buffer == nullptr ) return;

    for (uint8_t i = 0; i < BANDS; i++) {
        memset(buffer + (i * BAND_WIDTH * BAND_HEIGHT), i, (BAND_WIDTH * BAND_HEIGHT));
    }
    tft.writeRect8BPP(CENTER, CENTER, BAND_WIDTH, BAND_HEIGHT * BANDS, buffer, palette);
    
    // Second one to make sure X's and Ys are OK
    #define BAND_W2 100
    #define BAND_H2 50
    uint8_t *pb = buffer;
    int x;
    for (uint8_t i = 0; i < BANDS; i +=2) {
        for (uint8_t j = 0; j < BAND_H2; j++) {
            for (x = 0; x < BAND_W2 / 2; x++) *pb++ = i;
            for (; x < BAND_W2; x++) *pb++ = i+1;
        }
    }   
    tft.writeRect8BPP(50, 50, BAND_W2, BAND_H2 * BANDS / 2, buffer, palette);

    // Try 4 bit
    pb = buffer;
    for (uint8_t i = 0; i < 4; i +=2) {
        for (uint8_t j = 0; j < BAND_H2; j++) {
            for (x = 0; x < BAND_W2 / 2; x+=2) *pb++ = (i << 4) | i;
            for (; x < BAND_W2; x+=2) *pb++ = ((i+1) << 4) | (i+1);
        }
    }   
    
    tft.writeRect4BPP(tft.width() - (50 + BAND_W2), tft.height() - (50 + BAND_H2 * 4 / 2), BAND_W2, BAND_H2 * 4 / 2, buffer, palette);

    // Lets put a White rectangle as a marker at 20, 20
    tft.fillRect(10, 10, 20, 20, WHITE);

    uint16_t *pb16 = (uint16_t*)buffer;
    for (int i = 0; i < 400; i++) *pb16++ = RED;
    tft.writeRect(tft.width()-30, tft.height() - 30, 20, 20, (uint16_t*)buffer);


    free(buffer);
}


int nextPage() {
    Serial.println("Press anykey to continue");
    int ch;
    while ((ch = Serial.read()) == -1)
        ;
    while (Serial.read() != -1)
        ;

    tft.fillScreen(BLACK);
    return ch;
}

void displayRotation(uint8_t rotation) {
  tft.fillScreen(RED);
  tft.setCursor(tft.width()/2, tft.height()/2, true);
  tft.printf("Rotation: %d", rotation);
  Serial.printf("WIDTH: %d, HEIGHT: %d\n", tft.width(), tft.height());
  tft.setCursor(200, 300);
  Serial.printf("  Set cursor(200, 300), retrieved(%d %d)",
                tft.getCursorX(), tft.getCursorY());
  tft.setCursor(50, 50);
  tft.print("0");
  tft.setCursor(tft.width() - 50, 50);
  tft.print("1");
  tft.setCursor(50, tft.height() - 50);
  tft.print("2");
  tft.setCursor(tft.width() - 50, tft.height() - 50);
  tft.print("3");
}
That is the line: tft.fillRect(10, 10, 20, 20, WHITE);

The Red one is done by:
Code:
// Lets put a White rectangle as a marker at 20, 20
    tft.fillRect(10, 10, 20, 20, WHITE);

    uint16_t *pb16 = (uint16_t*)buffer;
    for (int i = 0; i < 400; i++) *pb16++ = RED;
    tft.writeRect(tft.width()-30, tft.height() - 30, 20, 20, (uint16_t*)buffer);
 
I have put in the writeRect fix plus writeRect8BPP 1BPP, 2BPP, 4BPP NBPP up into a new branch:
Already incorporated in the t41_p branch that I am working with :)

Finally back to test the latest changes you made. As far as creating a common class, that makes sense. Kind of like the FS class. Maintaining all of the branches can be confusing, time consuming and error prone. Having it all in one big file makes it really hard to maintain as well. Having separate board specific classes would make it easier to maintain and port.
Probably will look at doing what we did for the Teensy_GFX class which has all graphic primitives - theres a lot more in the RA8876 so may take a while to disentangle all of it
 
Morning all
Ran through all the tests this morning (not ones with usb/mouse - graphicscursor and touch). Everything seems to be except clipping in @KurtE's FB sketch - when selected it hangs.. after drawing a bit - not sure what I messed up
 
@mjs513 - Modified the gauges sketch to use RA8876_t41_p.h and a couple of other things and it compiled and ran perfectly:) This is going to be fun...
 
Just went through all examples after transfer all except the ones in testcases folder. A few are not working in 8Bit mode and quite a few are not working in 16Bit mode. I am will to go through all of them and get them working. Once RA8876_t41_p examples are working the other boards should be easier to adapt. Thoughts?
 
Just went through all examples after transfer all except the ones in testcases folder. A few are not working in 8Bit mode and quite a few are not working in 16Bit mode. I am will to go through all of them and get them working. Once RA8876_t41_p examples are working the other boards should be easier to adapt. Thoughts?
I ran through all the examples except a couple this morning - I pushed them up this morning. Not sure when you last synched?

Edit: But yes but when this is all working then other boards should be easier to adapt.
 
Ok getting confused now threads.
Ok guys created a new combined branch that has 3 libraries: https://github.com/mjs513/Ra8876LiteTeensy/tree/RA8896_combined
1719782041201.png



GFX has all the common functions across devices
t41_p: obviously for the t41 with flexio
t3 : is for SPI only

Probably still some issues but probably done for the day. Haven't run through all the examples been playing mainly with the test sketches. Eventually would like to combine somehow the device libraries, i.e., t41_p and t3 but not sure yet.

Cheers.
Mike
 
Quick update:
Branch renamed: https://github.com/mjs513/Ra8876LiteTeensy/tree/RA8876_combined

I had DrawPixel and writeRect in each lib but moved them back to RA8876 common.

Doing some testing
1. the embedPicture sketch is giving me 2d ready fails in rotation 2 but still draws the image and returns - not sure why
2. With Kurts FB Sketch when I shift origin getting some wierdness but probably I missed something
1719836120142.jpeg


Feel free to test and debug - need a little break today I think from the RA8876 - head is spinning
 
Back
Top