B4R Question ILI9488 tft Library Fonts

lenk54

Member
Licensed User
Longtime User
Hi

I have used the ILI9488 library from Candide and it works fine with a 3.5in tft ILI9488 controller. The problem is the standard font is very blocky when using the larger text sizes.

How do I use other fonts with this Library?

I see that there is a mention of setFont in the ILI9488.CPP file but I think it is just a comment.

// void setFont(GFXfont * f = NULL)

Can anyone help?

I have used this code from Erel with the ILI9341 controller and it works fine but it will not compile with the ILI9488 library.
#if C
#include "FreeSans9pt7b.h"
#include "FreeSans18pt7b.h"
void SetFontL(B4R::Object* o) {
b4r_main::_tft->GFX->gfx->setFont(&FreeSans18pt7b);
}
void SetFont(B4R::Object* o) {
b4r_main::_tft->GFX->gfx->setFont(&FreeSans9pt7b);
}
void SetFontD(B4R::Object* o) {
b4r_main::_tft->GFX->gfx->setFont();
}
#End If
 

candide

Active Member
Licensed User
I have to check but i think Fonts managemant can be open on wrapper.

it can work with a restriction : 2 modifications in rILI9488.h are needed for each font available. (i didn't find better solution)
 
Upvote 0

lenk54

Member
Licensed User
Longtime User
can you check this version with 7 fonts added ?

how to add fonts :
First, all fonts must be in directory : Arduino/libraries/Adafruit_GFX_Library/Fonts


*****************************************************************
after, to install fonts in wrapper, you have to modify rILI9488.h
*****************************************************************
below we have example for 7 fonts
B4X:
//********************************************
//fonts addition Phase 1 => add one line #include for each font to add
//fonts must be in "Arduino/libraries/Adafruit_GFX_Library/Fonts" directory
//********************************************
#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSerif9pt7b.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBoldOblique9pt7b.h>
#include <Fonts/FreeMonoOblique9pt7b.h>
#include <Fonts/FreeSansBold9pt7b.h>
//********************************************
=> here we have 7 fonts

B4X:
//****************************************************
//fonts addition Phase 2 => add each font in an array
//****************************************************
            const GFXfont * myfonts[7]= {     // number of fonts
              &FreeMono9pt7b,                 // => setfont(00)
              &FreeSans9pt7b,                 // => setfont(01)
              &FreeSerif9pt7b,                // => setfont(02)
              &FreeMonoBold9pt7b,             // => setfont(03)
              &FreeMonoBoldOblique9pt7b,      // => setfont(04)
              &FreeMonoOblique9pt7b,          // => setfont(05)
              &FreeSansBold9pt7b              // => setfont(06)
            };
//****************************************************
=> we have to indicate number of fonts in first line and name of each font after

B4X:
//********************************************
//fonts addition Phase 3 => a #define is added for each font available on B4R interface
//********************************************
        #define /*byte    FreeMono9pt7b;*/            BAR_FreeMono9pt7b             00   // setfont(tft.FreeMono9pt7b) <=> setfont(00)
        #define /*byte    FreeSans9pt7b;*/            BAR_FreeSans9pt7b             01   // setfont(tft.FreeSans9pt7b) <=> setfont(01)
        #define /*byte    FreeSerif9pt7b;*/           BAR_FreeSerif9pt7b            02   // setfont(tft.FreeSerif9pt7b) <=> setfont(02)
        #define /*byte    FreeMonoBold9pt7b;*/        BAR_FreeMonoBold9pt7b         03   // setfont(tft.FreeMonoBold9pt7b) <=> setfont(03)
        #define /*byte    FreeMonoBoldOblique9pt7b;*/ BAR_FreeMonoBoldOblique9pt7b  04   // setfont(tft.FreeMonoBoldOblique9pt7b) <=> setfont(04)
        #define /*byte    FreeMonoOblique9pt7b;*/     BAR_FreeMonoOblique9pt7b      05   // setfont(tft.FreeMonoOblique9pt7b) <=> setfont(05)
        #define /*byte    FreeSansBold9pt7b;*/        BAR_FreeSansBold9pt7b         06   // setfont(tft.FreeSansBold9pt7b) <=> setfont(06)
//********************************************
=> we have also to indicate fonts for B4R interface



***************************************************************
at end of rILI9488.xml, we have to add fonts for B4R interface
***************************************************************
here we have configuration in rILI9488.xml for 7 fonts
B4X:
       <field>
            <name DefineMethod="true" DesignerName="FreeMono9pt7b">BAR_FreeMono9pt7b</name>
            <returntype>byte</returntype>
        </field>
        <field>
            <name DefineMethod="true" DesignerName="FreeSans9pt7b">BAR_FreeSans9pt7b</name>
            <returntype>byte</returntype>
        </field>
        <field>
            <name DefineMethod="true" DesignerName="FreeSerif9pt7b">BAR_FreeSerif9pt7b</name>
            <returntype>byte</returntype>
        </field>
        <field>
            <name DefineMethod="true" DesignerName="FreeMonoBold9pt7b">BAR_FreeMonoBold9pt7b</name>
            <returntype>byte</returntype>
        </field>
        <field>
            <name DefineMethod="true" DesignerName="FreeMonoBoldOblique9pt7b">BAR_FreeMonoBoldOblique9pt7b</name>
            <returntype>byte</returntype>
        </field>
        <field>
            <name DefineMethod="true" DesignerName="FreeMonoOblique9pt7b">BAR_FreeMonoOblique9pt7b</name>
            <returntype>byte</returntype>
        </field>
        <field>
            <name DefineMethod="true" DesignerName="FreeSansBold9pt7b">BAR_FreeSansBold9pt7b</name>
            <returntype>byte</returntype>
        </field>


Hi

Thanks, I will try it tomorrow.

thanks for the prompt reply.
 
Upvote 0

candide

Active Member
Licensed User
at last i found a better way to manage fonts without modification of wrapper: fonts are declared in inline C

we add fonts in inline C, and from process below:
=> 1) we add "#define fonts true" to activate fonts management in wrapper
=> 2) we add "#include font" for each font to add
=> 3) at last, we include each font in a variable declared in wrapper B4R::B4RILI9488::myfonts

example for 7 fonts :
B4X:
#if C
  #define fonts true
  #include <Fonts/FreeMono9pt7b.h>
  #include <Fonts/FreeSans9pt7b.h>
  #include <Fonts/FreeSerif9pt7b.h>
  #include <Fonts/FreeMonoBold9pt7b.h>
  #include <Fonts/FreeMonoBoldOblique9pt7b.h>
  #include <Fonts/FreeMonoOblique9pt7b.h>
  #include <Fonts/FreeSansBold9pt7b.h>

  const GFXfont * B4R::B4RILI9488::myfonts[7]= {
      &FreeMono9pt7b,                 // => setfont(00)
      &FreeSans9pt7b,                 // => setfont(01)
      &FreeSerif9pt7b,                // => setfont(02)
      &FreeMonoBold9pt7b,             // => setfont(03)
      &FreeMonoBoldOblique9pt7b,      // => setfont(04)
      &FreeMonoOblique9pt7b,          // => setfont(05)
      &FreeSansBold9pt7b              // => setfont(06)
  };
#End If

after, management of fonts in B4X project is done by tft.setFont(xx) with xx= font level in B4R::B4RILI9488::myfonts

wrapper is below
 

Attachments

  • rILI9488v2.1.zip
    20.5 KB · Views: 146
Upvote 0

lenk54

Member
Licensed User
Longtime User
Hi

Tried the new Lib above it compiles but the fonts do not change.

Fonts are in Arduino/libraries/Adafruit_GFX_Library/Fonts

This is the code I added to test the fonts.

B4X:
    tft.begin
    tft.setTextSize(4)
    tft.setTextColor(tft.ILI9488_CYAN)
    tft.setFont(00)
    tft.println("Font 0")
    Delay(2000)
    tft.setFont(01)
    tft.println("Font 1")
    Delay(2000)
    tft.setFont(02)
    tft.println("Font 2")
    Delay(2000)
    tft.setFont(03)
    tft.println("Font 3")
    Delay(2000)
    tft.setFont(04)
    tft.println("Font 4")
    Delay(2000)
    tft.setFont(05)
    tft.println("Font 5")
    Delay(2000)
    tft.setFont(06)
    tft.println("Font 6")
    Delay(2000)

This is the output to the display.

ili9488.jpg



Thanks very much for your effort.
 
Upvote 0

candide

Active Member
Licensed User
can you share inline C added ?

if pointer to font is "nullptr" or if "fonts"is "not define", nothing is done.

and can you make tests with wrapper below? some traces are added on "setfont" function
 

Attachments

  • rILI9488v2.1_for test.zip
    14.4 KB · Views: 117
Last edited:
Upvote 0

lenk54

Member
Licensed User
Longtime User
can you share inline C added ?

if pointer to font is "nullptr" or if "fonts"is "not define", nothing is done.

and can you make tests with wrapper below? some traces are added on "setfont" function
Hi

I made sure I had the latest copy of the GFX Library in case there was a problem with that
and put it in "Arduino/libraries/" directory.

e.g. the fonts are in "Arduino/libraries/Adafruit_GFX_Library/Fonts"


Tried latest files above and results are as follows:

Inline C: (Is this supposed to be all one line?)

#if C #define fonts true #include <Fonts/FreeMono9pt7b.h> #include <Fonts/FreeSans9pt7b.h> #include <Fonts/FreeSerif9pt7b.h> #include <Fonts/FreeMonoBold9pt7b.h> #include <Fonts/FreeMonoBoldOblique9pt7b.h> #include <Fonts/FreeMonoOblique9pt7b.h> #include <Fonts/FreeSansBold9pt7b.h> const GFXfont * B4R::B4RILI9488::myfonts[7]= { &FreeMono9pt7b, // => setfont(00) &FreeSans9pt7b, // => setfont(01) &FreeSerif9pt7b, // => setfont(02) &FreeMonoBold9pt7b, // => setfont(03) &FreeMonoBoldOblique9pt7b, // => setfont(04) &FreeMonoOblique9pt7b, // => setfont(05) &FreeSansBold9pt7b // => setfont(06) }; #End If

Logs

B4X:
DEBUG StatusLogger Stopped XmlConfiguration[location=jar:file:/C:/Program%20Files%20(x86)/Arduino/lib/pde.jar!/log4j2.xml] OK
DEBUG StatusLogger Stopped LoggerContext[name=1e6f5c3, org.apache.logging.log4j.core.LoggerContext@1f72f5] with status true
********************* PROGRAM STARTING ****************
ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
AppStart
ILI9488 Test!
start_setfont
start_setfont
start_setfont
start_setfont
start_setfont
start_setfont
start_setfont
Display Power Mode: 0x0000
MADCTL Mode: 0x0000
Pixel Format: 0x0000
Image Format: 0x0000
Self Diagnostic: 0x0000
Benchmark Time16208558
Screen fill              2942685
Text                     80377
Lines                    1563034
Horiz/Vert Lines         239447
Rectangles (outline)     2676
Rectangles (filled)      7173729
Circles (filled)         716216
Circles (outline)        669131
Triangles (outline)      310397
Triangles (filled)       2303285
Rounded rects (outline)  281104
Rounded rects (filled)   7126844
Done!

Hope this helps

Thanks
 
Upvote 0

candide

Active Member
Licensed User
thanks for your test.

it seems " #define fonts true" is not seen in wrapper. i will check this part and i will come back.

for inline C part, you should have several lines, and i suppose it can have a sad effect to have everything on same line, including comments...

for tests, you should have this format :
B4X:
#if C 
 #define fonts true 
 #include <Fonts/FreeMono9pt7b.h> 
 #include <Fonts/FreeSans9pt7b.h> 
 #include <Fonts/FreeSerif9pt7b.h> 
 #include <Fonts/FreeMonoBold9pt7b.h> 
 #include <Fonts/FreeMonoBoldOblique9pt7b.h> 
 #include <Fonts/FreeMonoOblique9pt7b.h> 
 #include <Fonts/FreeSansBold9pt7b.h> 
 const GFXfont * B4R::B4RILI9488::myfonts[7]= { 
    &FreeMono9pt7b, // => setfont(00) 
    &FreeSans9pt7b, // => setfont(01) 
    &FreeSerif9pt7b, // => setfont(02) 
    &FreeMonoBold9pt7b, // => setfont(03) 
    &FreeMonoBoldOblique9pt7b, // => setfont(04) 
    &FreeMonoOblique9pt7b, // => setfont(05) 
    &FreeSansBold9pt7b // => setfont(06) }; 
    
#End If
 
Upvote 0

candide

Active Member
Licensed User
can you test wrapper attached with inline C below ? it should work with font 00<06
please to make setfont() only on existing fonts or you will have crash...

B4X:
#if C
  #include <Fonts/FreeMono9pt7b.h>
  #include <Fonts/FreeSans9pt7b.h>
  #include <Fonts/FreeSerif9pt7b.h>
  #include <Fonts/FreeMonoBold9pt7b.h>
  #include <Fonts/FreeMonoBoldOblique9pt7b.h>
  #include <Fonts/FreeMonoOblique9pt7b.h>
  #include <Fonts/FreeSansBold9pt7b.h>

  const GFXfont * B4R::B4RILI9488::myfonts[7]= { 
      &FreeMono9pt7b,                 // => setfont(00)
      &FreeSans9pt7b,                 // => setfont(01)
      &FreeSerif9pt7b,                // => setfont(02)
      &FreeMonoBold9pt7b,             // => setfont(03)
      &FreeMonoBoldOblique9pt7b,      // => setfont(04)
      &FreeMonoOblique9pt7b,          // => setfont(05)
      &FreeSansBold9pt7b              // => setfont(06)
  };
#End If
 

Attachments

  • rILI9488v2.2fortest.zip
    11.6 KB · Views: 114
Upvote 0

lenk54

Member
Licensed User
Longtime User
can you test wrapper attached with inline C below ? it should work with font 00<06
please to make setfont() only on existing fonts or you will have crash...

B4X:
#if C
  #include <Fonts/FreeMono9pt7b.h>
  #include <Fonts/FreeSans9pt7b.h>
  #include <Fonts/FreeSerif9pt7b.h>
  #include <Fonts/FreeMonoBold9pt7b.h>
  #include <Fonts/FreeMonoBoldOblique9pt7b.h>
  #include <Fonts/FreeMonoOblique9pt7b.h>
  #include <Fonts/FreeSansBold9pt7b.h>

  const GFXfont * B4R::B4RILI9488::myfonts[7]= {
      &FreeMono9pt7b,                 // => setfont(00)
      &FreeSans9pt7b,                 // => setfont(01)
      &FreeSerif9pt7b,                // => setfont(02)
      &FreeMonoBold9pt7b,             // => setfont(03)
      &FreeMonoBoldOblique9pt7b,      // => setfont(04)
      &FreeMonoOblique9pt7b,          // => setfont(05)
      &FreeSansBold9pt7b              // => setfont(06)
  };
#End If
Hi

I have tried the above and all seems great! I have substituted other fonts and all seems ok.

I must thank you very much for your help. I could not have done it myself.

Thanks
Len
 
Upvote 0

lenk54

Member
Licensed User
Longtime User
Hi

I have tried the above and all seems great! I have substituted other fonts and all seems ok.

I must thank you very much for your help. I could not have done it myself.

Thanks
Len
Hi

Sorry for this but there seems a problem with the Library.

I added this code to the test program to check that I could achieve one of the things
which I require in my project. (Display a temperature up to approx 1350)

The program crashed continuously until I increased the stack buffer to 6500. I assume if I
increased the number count I would need to increase the buffer size as the prog crashed
at higher values as I increased the buffer size.

Added code

B4X:
    tft.begin
    tft.setTextColor(tft.ILI9488_WHITE)
    tft.fillScreen(tft.ILI9488_BLACK)
    tft.setFont(5)
    tft.setTextColor(tft.ILI9488_RED)
    tft.setTextSize(2)
    Dim n As UInt
    Do Until n=1350
        n=n+1
    tft.drawRect(49,4,202,87,tft.ILI9488_WHITE)
    tft.fillRect(50,5,200,85,tft.ILI9488_BLACK)
    tft.setCursor(50,80)
    tft.print(n)
    Log(n)
    Delay(400)
    Loop
    Log("Cont")

Sorry to be a pain.
Regards
 
Upvote 0

candide

Active Member
Licensed User
can you add line below at several points of your project, just to see where buffer is increasing ?
before and after "setfont"
and after each line in the loop

B4X:
    Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM)
also, can you make same test with an other font ? or only with standard font ? (to check if issue is due to new font.)

on my part, i will clean wrapper to remove all traces added on "setfont()"[/code]
 
Upvote 0

candide

Active Member
Licensed User
can you check your loop with a sub in this way:
B4X:
 Do Until n=1350
        n=n+1
    callsubplus("printvalue",400,0)  
    Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM)
Loop
sub printvalue
    tft.drawRect(49,4,202,87,tft.ILI9488_WHITE)
    Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM)
    tft.fillRect(50,5,200,85,tft.ILI9488_BLACK)  
    Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM)
    tft.setCursor(50,80
    Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM))
    tft.print(n)
    Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM)
    Log(n)
    Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM)
 end sub
 
Upvote 0

lenk54

Member
Licensed User
Longtime User
can you add line below at several points of your project, just to see where buffer is increasing ?
before and after "setfont"
and after each line in the loop

B4X:
    Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM)
also, can you make same test with an other font ? or only with standard font ? (to check if issue is due to new font.)
on my part, i will clean wrapper to remove all traces added on "setfont()"[/code]
Hi

Tested with setfont(5) and setfont remed out, output the same.

I appears that the tft.print(n) and tft.println(n) are the culprit.

B4X:
GFXfont found / Ptr: 1061165796
buffer: 0memory: 367724
buffer: 0memory: 367724
buffer: 0memory: 367724
buffer: 0memory: 367724
buffer: 0memory: 367724
buffer: 0memory: 367724
buffer: 0memory: 367724
buffer: 0memory: 367724
before tft.print(n)
buffer: 0memory: 367724
after tft.print(n)
buffer: 10memory: 367724
1
buffer: 10memory: 367724
buffer: 10memory: 367724
buffer: 10memory: 367724
buffer: 10memory: 367724
buffer: 10memory: 367724
before tft.print(n)
buffer: 10memory: 367724
after tft.print(n)
buffer: 22memory: 367724
2
buffer: 22memory: 367724
buffer: 22memory: 367724
buffer: 22memory: 367724
buffer: 22memory: 367724
buffer: 22memory: 367724
before tft.print(n)
buffer: 22memory: 367724
after tft.print(n)
buffer: 34memory: 367724
3
buffer: 34memory: 367724
buffer: 34memory: 367724
buffer: 34memory: 367724
buffer: 34memory: 367724
buffer: 34memory: 367724
before tft.print(n)
buffer: 34memory: 367724
after tft.print(n)

Thanks
 
Upvote 0

lenk54

Member
Licensed User
Longtime User
to use "tft.print" in a sub will avoid buffer issue.
If I just put the printing code in a sub and then call sub it does not work. You have to call the sub with a
value passed which must be declared as a Uint. See Code remarks. Strings seem OK to send directly.

Changed code.

B4X:
    tft.begin
    tft.setTextColor(tft.ILI9488_WHITE)
    tft.fillScreen(tft.ILI9488_BLACK)
    tft.setTextColor(tft.ILI9488_WHITE)
    tft.fillScreen(tft.ILI9488_BLACK)
    tft.setFont(5)
    tft.setTextColor(tft.ILI9488_RED)
    tft.setTextSize(2)
    Dim n As UInt
    Do Until n=1350
        n=n+1
        num=n
        tft.drawRect(49,4,202,87,tft.ILI9488_WHITE)
        tft.fillRect(50,5,200,85,tft.ILI9488_BLACK)
        tft.setCursor(50,80)
        tft.print("*")              'Sending a string is OK
        PrintToTft(n) 
        'tft.print(n)           'Sending a byte or Uint causes the problem
        Log(n)
        Log("buffer: ",StackBufferUsage, "memory: ",AvailableRAM)
        Delay(400)
    Loop
    Log("Cont")
End Sub
Sub PrintToTft(TxtNum As UInt)  'Print(txt as String)' Requests a string
    '******** Defining TxtNum as Uint where 'print() requests a string 'print(txt as String) As Uint'
    Dim testnum As UInt=TxtNum
    tft.print(testnum) 'works fine
    tft.print(num)     'printing a Global Uint in sub is OK
    tft.print(TxtNum)  'print(txt as String) As Uint
End Sub
Sub lLoop
  Dim rotation As Byte
  For rotation = 0 To 3 '<4
    tft.setRotation(rotation)
    testText
    Delay(1000)
  Next
End Sub

Sending a Byte or Uint causes the problem.
Sending a String is OK.
Defining a Uint in sub is OK even if the 'tft.Print(txt as String) as Uint' seems to require a String ???

Thanks
 
Upvote 0

candide

Active Member
Licensed User
in wrapper : uint16_t print(B4RString* txt);
=> wrapper function "print" accept only string in B4R : if you provide int or byte, a conversion is done with temporary variables created on the stack.

if conversion is done in a sub, stack is increased only during sub running and modification of stack is lost at end of sub
if conversion is done in a large loop, stack is increasing at each step of loop until end of sub supporting the loop

it is a problem linked to string manipulation in B4R, not a problem in wrapper. Solution is to use small sub to make string manipulation
 
Upvote 0
Top