Helpful ReplyHot!Designing a FONT for a ILI9341 TFT display.

Author
Dartmoor
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2017/08/24 06:06:17
  • Location: London, United Kingdom
  • Status: offline
2017/09/01 17:17:51 (permalink)
3 (1)

Designing a FONT for a ILI9341 TFT display.

Hi, 
 
Sorry if this is not the correct forum for the following.
 
I'm using the following code for running my display on the PIC18F26K22. 
https://pic-projekte.de/blog/ili9341-bibliothek/
 
There seems to be a font file here: https://github.com/PIC-Nico/ILI9341/blob/master/Source/font.h
Could someone please point me to a resource where I can understand how a TFT font file for the ILI9341 works?  
I need a font file that has larger numbers and characters. How is this generated and used? As a starter the number font has large number sizes, where would I make the call to use the increased size. 
 
Apologies for the silly questions, but I'm new to XC8 et. al. 
 
Many thanks
Dartmoor
 
 
#1
Gort2015
Klaatu Barada Nikto
  • Total Posts : 1473
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/02 06:25:51 (permalink)
+1 (1)
char invader2[28]={14,12,
    0b00000011,0b00000000,
    0b00000111,0b10000000,
    0b00011111,0b11100000,
    0b00111111,0b11110000,
    0b01110111,0b10111000,
    0b01111111,0b11111000,
    0b01111111,0b11111000,
    0b00011100,0b11100000,
    0b00111000,0b01110000,
    0b00111000,0b01110000,
    0b00011100,0b11100000,
    0b00001100,0b11000000};

 
In a bitmap font table, the first two bytes can denote the first ascii and last ascii code.  It could also be modified to contain words giving you codes 0 - 65535.
That's how I wrote mine, first two bytes ascii start/end.
Next two bytes width and height.
char
Font_Standard[]={32,144},   //start - end
Font_SPACE[]={5,7, //SPACE
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000},
FONT_EM[]={5,7, // !
0b00100000,
0b00100000,
0b00100000,
0b00100000,
0b00000000,
0b00100000,
0b00000000}, etc...

 
You need a function that can write/chop a bitmap(font) into a bitmap(display) at x,y.
 
Also clipping on x and y axis if you write to an area inside a window.
 
It's complicated code if need to understand it.
 
Your font could contain 1 char. or 1000's.
Converting to color, ior, xor, set, clr, invert.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#2
NorvisLM
Junior Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2015/10/06 07:32:11
  • Location: 0
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/02 06:54:49 (permalink) ☄ Helpfulby Dartmoor 2017/09/05 13:51:33
+3 (3)
The ili9341 has no notion of fonts. It is only capable of displaying pixels. You will need a Graphics Library to display fonts with the ili9341.
 
Assuming they are using this standard, a font file description can be found in the Microchip Application Note below:
 
AN1182 Fonts in the Microchip Graphics Library
 
The MikroElectronika GLCD Font Creator tool is what I use to create fonts in the Microchip format.
 
There is code in the Microchip Graphics Library that will display them.
 
Good Luck!
#3
CinziaG
rome burns :D
  • Total Posts : 3136
  • Reward points : 0
  • Joined: 2016/12/07 14:20:36
  • Location: Wien
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/02 08:52:47 (permalink)
+2 (2)
how many times I've been doing that in the 80s!! I even created my software for C128 named "Fontastic" Smile (inspired by something out there, and Wham!)
#4
malaugh
Super Member
  • Total Posts : 243
  • Reward points : 0
  • Joined: 2011/03/31 14:04:42
  • Location: San Diego
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/02 11:25:41 (permalink) ☄ Helpfulby Dartmoor 2017/09/05 04:12:02
+2 (2)
Did you look at a the Microchip MLA Microchip graphics library?  They have some great tools for font generation and display. 
 
Get a version from the archives.  Look for version with a date around 2010, before the Microchip software development team went off the rails.  I say use this date because after that date their GRC graphics conversion tool generated assembly files, and they added a bunch of code that complicated everything, but did not add any features. You want the one that generates C files.
 
Their graphics library is pretty daunting when you first look at it, but you can pick and choose what you want to use.  For your use you should only need a file called "primitives.c".  This contains the text drawing functions.  You will likely need to include a few header files to get it to compile.  You will also need to supply GetPixel and PutPixel hardware drivers for your graphics chip.
 
Now you can use the graphics generation tool to generate the fonts, and the OutText function in primitives.c to draw them.
 
Fonts are generated by the GRC (graphics resource converter).  It converts TrueType fonts to bitmapped fonts.  You select the font you want, the size you want, and the characters you want to include, and GRC does the rest.  You include the generated C files in your code, and OutText knows how to use the bitmaps to generate the fonts on your display.
 
There are many Microchip documents on how to use the tools.  
#5
Gort2015
Klaatu Barada Nikto
  • Total Posts : 1473
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/02 15:19:15 (permalink)
+2 (2)
CinziaG
how many times I've been doing that in the 80s!! I even created my software for C128 named "Fontastic"

Reminds be of something I created called sdo, which stood for sprite do.
Allowed sprites and fonts to be written to a bitmapped display, written in z80 machine code.
 
That increased the resolution by allowing more text to be displayed and output from the listing of my assembler which could compile itself in about 2 seconds.
 
The power of the Zilog Z80.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#6
Gort2015
Klaatu Barada Nikto
  • Total Posts : 1473
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/02 15:23:10 (permalink)
+2 (2)
Writing bytes is more efficent than writing pixels.
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#7
CinziaG
rome burns :D
  • Total Posts : 3136
  • Reward points : 0
  • Joined: 2016/12/07 14:20:36
  • Location: Wien
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/02 15:51:55 (permalink)
0
Nice!
And yes. Another nice idea, talikin' bout sprites, was around 1986 and we had x movement and y movement... and I wanted to add a "z movement" i.e. sprite increasing in size or decreasing as if it were getting closer or farther...
 
I was not good enough or maybe machines would not have been fast enough or... I just did not need those, in the end. A pity Smile
#8
Gort2015
Klaatu Barada Nikto
  • Total Posts : 1473
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/03 03:13:40 (permalink)
+1 (1)
Yeah, cpu not powerful enough to do scaling or viewpoint along the Z.
We were running at 4MHz.
 
My first good chip was the Motorolla 68K.
 
The first game I wrote was Space Invaders on a 6502 in black and white.
Hand written on paper and then typed in the hex codes.
 
Saving on to tape because a floppy disk drive was too expensive at the time.
 
You had to use assembler to get the refresh rate.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#9
CinziaG
rome burns :D
  • Total Posts : 3136
  • Reward points : 0
  • Joined: 2016/12/07 14:20:36
  • Location: Wien
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/03 03:22:16 (permalink)
0
Yeah, C128 was 2MHz...
 
I remember looking at a 68000 book somewhere in 1989 and indeed it looked like a wonderful one for the times! But then I never touched it: I had my Acorn Archimedes and... yeah, Mips, it was so strange...
 
Space invaders was of course one of my passions back in 1978 or so Smile but I only tried programming it way after, say end of the 80s still on the Commodore. But... time before this all, I remember fantasizing of computers and videogame when I was probably 10 or 11 and I imagined creating these videogames straight out of a tape-recorded data stream... drawn on a panel made of a led matrix... no code, no instruction (I could not imagine that). I wanted my father to build this panel using hundreds of leds and try this out!
And I was asking my schoolmates to draw pattern for the monsters.
#10
qhb
Superb Member
  • Total Posts : 6235
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/03 03:57:46 (permalink)
+2 (2)
Ahh nostalgia, there's nothing like it! ;)
 

 
#11
CinziaG
rome burns :D
  • Total Posts : 3136
  • Reward points : 0
  • Joined: 2016/12/07 14:20:36
  • Location: Wien
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/03 04:06:32 (permalink)
0
Something like this
http://www.pacxon4u.com/space-invaders/
(even if that's not perfect!)
Smile
#12
Dartmoor
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2017/08/24 06:06:17
  • Location: London, United Kingdom
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/05 14:01:03 (permalink)
0
FaulknerPD
The ili9341 has no notion of fonts. It is only capable of displaying pixels. You will need a Graphics Library to display fonts with the ili9341.
 
Assuming they are using this standard, a font file description can be found in the Microchip Application Note below:
 
AN1182 Fonts in the Microchip Graphics Library
 
The MikroElectronika GLCD Font Creator tool is what I use to create fonts in the Microchip format.
 
There is code in the Microchip Graphics Library that will display them.
 
Good Luck!




Hi, 
I have the code that I used here: https://pic-projekte.de/blog/ili9341-bibliothek/
and here: https://github.com/PIC-Nico/ILI9341
What am I missing? How do I match the font file used above with what is generated by the tool?
 
Thank you
 
/D
#13
malaugh
Super Member
  • Total Posts : 243
  • Reward points : 0
  • Joined: 2011/03/31 14:04:42
  • Location: San Diego
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/05 15:02:52 (permalink) ☄ Helpfulby Dartmoor 2017/09/06 01:28:10
+3 (3)
Look at the function lcd_draw_char in the lcd.c source file in the GIT repo.  This function assumes you have a array somewhere in your code called font, that has the bitmaps of the font you wish to use.  Note also that they lcd_draw pixel to write the bits in the pixel to the screen
 
This function a fairly simplistic implementation, it assumes that FONT_WIDTH and FONT_HEIGHT are fixed values, which means the firmware will only support one mono-spaced font.  If you want multiple fonts and variable font spacing, you need a more sophisticated function.  You can use the OutText function from the Microchip graphics library, which supports multiple fonts with varying font heights and widths, and use the existing lcd_draw_pixel function from lcd.c to render the characters on the LCD.  To make a font file in the format expected by OutText, you need to use GRC.
#14
Dartmoor
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2017/08/24 06:06:17
  • Location: London, United Kingdom
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/06 02:54:49 (permalink)
0
malaugh
Look at the function lcd_draw_char in the lcd.c source file in the GIT repo.  This function assumes you have a array somewhere in your code called font, that has the bitmaps of the font you wish to use.  Note also that they lcd_draw pixel to write the bits in the pixel to the screen
 
This function a fairly simplistic implementation, it assumes that FONT_WIDTH and FONT_HEIGHT are fixed values, which means the firmware will only support one mono-spaced font.  If you want multiple fonts and variable font spacing, you need a more sophisticated function.  You can use the OutText function from the Microchip graphics library, which supports multiple fonts with varying font heights and widths, and use the existing lcd_draw_pixel function from lcd.c to render the characters on the LCD.  To make a font file in the format expected by OutText, you need to use GRC.


I've downloaded several versions of MLA going back to several years but all of those output a file that is meant for C30 or C32. Which version would allow me get a file such as this 
#ifndef __FONT_H
#define __FONT_H

#include <xc.h>

const unsigned char Courier_New_Bold_20[] = {
/****************************************
 * Font header
 ****************************************/
    0x00, // Information
    0x00, // ID
    0x20, 0x00, // First Character
    0x7E, 0x00, // Last Character
    0x17, // Height
    0x00, // Reserved
/****************************************
 * Font Glyph Table
 ****************************************/
    0x0C, 0x84, 0x01, 0x00, // width, MSB Offset, LSB offset
........

/***********************************
 * Font Characters
 ***********************************/
    0x00, 0x00, //
    0x00, 0x00, //
    0x00, 0x00, //
    0x00, 0x00, //

.....
};

#endif

#15
malaugh
Super Member
  • Total Posts : 243
  • Reward points : 0
  • Joined: 2011/03/31 14:04:42
  • Location: San Diego
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/12 15:44:50 (permalink) ☄ Helpfulby Dartmoor 2017/09/13 15:51:25
+3 (3)
The GRC version I use is version 3.3.  That's why I was advising staying away form the versions that generate ASM files.  If you select C32 on the GRC tools, even though its says its for a C32 you get a standard C file which should compile on any platform.
 
#16
Dartmoor
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2017/08/24 06:06:17
  • Location: London, United Kingdom
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/13 15:52:18 (permalink)
0
malaugh
The GRC version I use is version 3.3.  That's why I was advising staying away form the versions that generate ASM files.  If you select C32 on the GRC tools, even though its says its for a C32 you get a standard C file which should compile on any platform.
 


Grateful thanks, I have it working now, all sorted. Is there a way of reducing the size of the code?
#17
malaugh
Super Member
  • Total Posts : 243
  • Reward points : 0
  • Joined: 2011/03/31 14:04:42
  • Location: San Diego
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/14 13:42:02 (permalink) ☄ Helpfulby Dartmoor 2017/09/14 14:36:12
+2 (2)
Are you talking about the fonts or the code.  If you are talking about the fonts, the best way to limit the size is to limit the number of characters.  By default, you get the characters from 20 (space) to 7E (~).  To reduce the number of characters you need to use a font filter or limit the range, and specify only those characters you actually use. For example you may want to restrict the largest size characters to caps only, so set the range from 65 (A) to 90 (Z).  After you do this you will get a smaller font table, but you will need to add some custom code in OutText to handle the this.  If you look in the code the standard formula is
 
font _index = ASCII - 20;
 
You will need to add something like
 
if(Big_Font)
{
    font_index = ASCII - 65;
}
 
We handle foreign languages in our code and normally use font filters to select the exact characters we need.  We have a much more complicated character code to font index formula.
 
 
#18
Dartmoor
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2017/08/24 06:06:17
  • Location: London, United Kingdom
  • Status: offline
Re: Designing a FONT for a ILI9341 TFT display. 2017/09/14 14:37:54 (permalink)
0
malaugh
Are you talking about the fonts or the code.  If you are talking about the fonts, the best way to limit the size is to limit the number of characters.  By default, you get the characters from 20 (space) to 7E (~).  To reduce the number of characters you need to use a font filter or limit the range, and specify only those characters you actually use. For example you may want to restrict the largest size characters to caps only, so set the range from 65 (A) to 90 (Z).  After you do this you will get a smaller font table, but you will need to add some custom code in OutText to handle the this.  If you look in the code the standard formula is
 
font _index = ASCII - 20;
 
You will need to add something like
 
if(Big_Font)
{
    font_index = ASCII - 65;
}
 
We handle foreign languages in our code and normally use font filters to select the exact characters we need.  We have a much more complicated character code to font index formula.
 
 


Thanks that's thought!:-) I need just some alphabets for the GRID REFERENCE and Numbers so will reduce the font code space!! :-)
#19
Jump to:
© 2017 APG vNext Commercial Version 4.5