7" BuyDisplay LCD RA8875 - ext font chip support added

I enabled the external font chip:

/media/uploads/JackB/20150619_092402_b_640.jpg

I added some variables:

    // Jack: External font chip use
    bool ext_font_used;
    unsigned int ext_font_type;
    unsigned int ext_font_size;
    unsigned int ext_font_height;

I added a few functions:

// Jack: Enable external font chip
void RA8875::SetExtFontType(unsigned int Font)
{
    // Font 0...2
    // Size 0...2
    ext_font_used = true;
    ext_font_type = Font;
    WriteCommand(0x21, (unsigned int)0x20);
    WriteCommand(0x2f, (unsigned int)0x80 + Font);
}

// Jack: Enable external font chip
void RA8875::SetExtFontSize(unsigned int Size)
{
    // Font 0...2
    // Size 0...2
    ext_font_used = true;
    ext_font_size = Size;
    WriteCommand(0x21, (unsigned int)0x20);
    if (Size == 0) {
        WriteCommand(0x2e, (unsigned int)0x00); // 0x00 0x20 (5:0) Horizontal spacing between characters
        ext_font_height = 16;
    }
    if (Size == 1) {
        WriteCommand(0x2e, (unsigned int)0x40); // 0x00 0x20 (5:0) Horizontal spacing between characters
        ext_font_height = 24;
    }
    if (Size == 2) {
        WriteCommand(0x2e, (unsigned int)0x80); // 0x00 0x20 (5:0) Horizontal spacing between characters
        ext_font_height = 32;
    }
}

// Jack: Disable external font chip
void RA8875::SetIntFont(void)
{
    ext_font_used = false;
    WriteCommand(0x21, (unsigned int)0x00);
    WriteCommand(0x2e, (unsigned int)0x00);
    WriteCommand(0x2f, (unsigned int)0x00);
}

And a modified these existing functions:

RetCode_t RA8875::init(int width, int height, int color_bpp, bool poweron, bool keypadon, bool touchscreenon)
{
    font = NULL;                        // no external font, use internal.
    pKeyMap = DefaultKeyMap;            // set default key map
    _select(false);                      // deselect the display
    frequency(RA8875_DEFAULT_SPI_FREQ); // data rate
    Reset();
    WriteCommand(0x88, 0x0B);                   // PLLC1 - Phase Lock Loop registers
    wait_ms(1);
    WriteCommand(0x89, 0x02);
    wait_ms(1);

    // System Config Register (SYSR)
    if (color_bpp == 16) {
        WriteCommand(0x10, 0x0C);               // 16-bpp (65K colors) color depth, 8-bit interface
    } else { // color_bpp == 8
        WriteCommand(0x10, 0x00);               // 8-bpp (256 colors)
    }
    // Pixel Clock Setting Register (PCSR)
    WriteCommand(0x04, 0x82);                   // PDAT on PCLK falling edge, PCLK = 4 x System Clock
    wait_ms(1);

    // Horizontal Settings
    screenwidth = width;
    WriteCommand(0x14, width/8 - 1);            //HDWR//Horizontal Display Width Setting Bit[6:0]
    WriteCommand(0x15, 0x02);                   //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
    WriteCommand(0x16, 0x03);                   //HNDR//Horizontal Non-Display Period Bit[4:0]
    WriteCommand(0x17, 0x01);                   //HSTR//HSYNC Start Position[4:0]
    WriteCommand(0x18, 0x03);                   //HPWR//HSYNC Polarity ,The period width of HSYNC.

    // Vertical Settings
    screenheight = height;
    WriteCommand(0x19, (height-1)&0xFF);        //VDHR0 //Vertical Display Height Bit [7:0]
    WriteCommand(0x1a, (height-1)>>8);          //VDHR1 //Vertical Display Height Bit [8]
    WriteCommand(0x1b, 0x0F);                   //VNDR0 //Vertical Non-Display Period Bit [7:0]
    WriteCommand(0x1c, 0x00);                   //VNDR1 //Vertical Non-Display Period Bit [8]
    WriteCommand(0x1d, 0x0e);                   //VSTR0 //VSYNC Start Position[7:0]
    WriteCommand(0x1e, 0x06);                   //VSTR1 //VSYNC Start Position[8]
    WriteCommand(0x1f, 0x01);                   //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]

    if (width >= 800 && height >= 480 && color_bpp > 8) {
        WriteCommand(0x20, 0x00);               // DPCR - 1-layer mode when the resolution is too high
    } else {
        WriteCommand(0x20, 0x80);               // DPCR - 2-layer mode
    }

    // Set display image to Blue on Black as default
    window(0,0, width, height);             // Initialize to full screen
    SetTextCursorControl();
    foreground(Blue);
    background(Black);
    cls(3);

    // Jack: external font used
    ext_font_used = false;
    ext_font_type = 0;
    ext_font_size = 0;
    ext_font_height = 16;

    Power(poweron);
    if (poweron)
        Backlight_u8(255);
    if (keypadon)
        KeypadInit();
    if (touchscreenon)
        TouchPanelInit();
#ifdef PERF_METRICS
    performance.start();
    ClearPerformance();
#endif
    return noerror;
}

int RA8875::_internal_putc(int c)
{
    if (c) {
        unsigned char mwcr0;

        mwcr0 = ReadCommand(0x40);
        if ((mwcr0 & 0x80) == 0x00) {
            WriteCommand(0x40, 0x80 | mwcr0);    // Put in Text mode if not already
        }
        if (c == '\r') {
            loc_t x;
            x = ReadCommand(0x30) | (ReadCommand(0x31) << 8);   // Left edge of active window
            WriteCommandW(0x2A, x);
        } else if (c == '\n') {
            loc_t y;
            y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8);   // current y location
            // Jack: external font support
            if (ext_font_used) {
                y += ext_font_height; 
            }
            else {
                y += fontheight(); 
            }
            if (y >= height())               // @TODO after bottom of active window, then scroll window?
                y = 0;
            WriteCommandW(0x2C, y);
        } else {
            WriteCommand(0x02);                 // RA8875 Internal Fonts
            _select(true);
            WriteData(c);
            _WaitWhileBusy(0x80);
            _select(false);
        }
    }
    return c;
}


1 comment on 7" BuyDisplay LCD RA8875 - ext font chip support added:

04 Sep 2016

hi Jack, I've recently acquired a new, larger display with the capacitive touch screen, but I didn't get the additional font chip. I should have, which would make integrating your changes more "testable".

Have you updated to my more recent library for the RA8875? If you have, and then reintegrated your changes for the external font chip, could you try applying a pull request? or bracket identifying your changes. thanks!

Please log in to post comments.