• Resolved

TM4C123GH6PGE: How to create 5x7 Font

Expert 1900 points

Replies: 40

Views: 794

Part Number: TM4C123GH6PGE

Hello,

Please tell me how to create 5x7 Font source code. ?

I need a small size font.

for example, 

The example below is like 6x8 Font source code. (  Grlib / fonts (fontfixed6x8.c) )

Regards.

Jame,Shin

//*****************************************************************************

#include <stdint.h>
#include <stdbool.h>
#include "grlib/grlib.h"

//*****************************************************************************
//
// Details of this font:
//     Style: fixed
//     Size: 8 point
//     Bold: no
//     Italic: no
//     Memory usage: 960 bytes
//
//*****************************************************************************

//*****************************************************************************
//
// The uncompressed data for the fixed-point 6x8 font.
//
//*****************************************************************************
static const uint8_t g_pui8FontFixed6x8Data[760] =
{
      8,   6,   0,   0,   0,   0,   0,   0,   8,   6,  32, 130,
      8,   0,   2,   0,   8,   6,  81,  69,   0,   0,   0,   0,
      8,   6,  81,  79, 148, 249,  69,   0,   8,   6,  33, 234,
     28,  43, 194,   0,   8,   6, 195,  33,   8,  66,  97, 128,
      8,   6,  98,  74,  16, 170,  70, 128,   8,   6,  96, 132,
      0,   0,   0,   0,   8,   6,  16, 132,  16,  64, 129,   0,
      8,   6,  64, 129,   4,  16, 132,   0,   8,   6,   0, 138,
    156, 168, 128,   0,   8,   6,   0, 130,  62,  32, 128,   0,
      8,   6,   0,   0,   0,  96, 132,   0,   8,   6,   0,   0,
     62,   0,   0,   0,   8,   6,   0,   0,   0,   1, 134,   0,
      8,   6,   0,  33,   8,  66,   0,   0,   8,   6, 114,  41,
    170, 202,  39,   0,   8,   6,  33, 130,   8,  32, 135,   0,
      8,   6, 114,  32, 132,  33,  15, 128,   8,   6, 248,  66,
      4,  10,  39,   0,   8,   6,  16, 197,  36, 248,  65,   0,
      8,   6, 250,  15,   2,  10,  39,   0,   8,   6,  49,   8,
     60, 138,  39,   0,   8,   6, 248,  33,   8,  65,   4,   0,
      8,   6, 114,  40, 156, 138,  39,   0,   8,   6, 114,  40,
    158,   8,  70,   0,   8,   6,   1, 134,   0,  97, 128,   0,
      8,   6,   1, 134,   0,  96, 132,   0,   8,   6,  16, 132,
     32,  64, 129,   0,   8,   6,   0,  15, 128, 248,   0,   0,
      8,   6,  64, 129,   2,  16, 132,   0,   8,   6, 114,  32,
    132,  32,   2,   0,   8,   6, 114,  32, 154, 170, 167,   0,
      8,   6, 114,  40, 162, 250,  40, 128,   8,   6, 242,  40,
    188, 138,  47,   0,   8,   6, 114,  40,  32, 130,  39,   0,
      8,   6, 226,  72, 162, 138,  78,   0,   8,   6, 250,   8,
     60, 130,  15, 128,   8,   6, 250,   8,  60, 130,   8,   0,
      8,   6, 114,  40,  46, 138,  39, 128,   8,   6, 138,  40,
    190, 138,  40, 128,   8,   6, 112, 130,   8,  32, 135,   0,
      8,   6,  56,  65,   4,  18,  70,   0,   8,   6, 138,  74,
     48, 162,  72, 128,   8,   6, 130,   8,  32, 130,  15, 128,
      8,   6, 139, 106, 170, 138,  40, 128,   8,   6, 138,  44,
    170, 154,  40, 128,   8,   6, 114,  40, 162, 138,  39,   0,
      8,   6, 242,  40, 188, 130,   8,   0,   8,   6, 114,  40,
    162, 170,  70, 128,   8,   6, 242,  40, 188, 162,  72, 128,
      8,   6, 122,   8,  28,   8,  47,   0,   8,   6, 248, 130,
      8,  32, 130,   0,   8,   6, 138,  40, 162, 138,  39,   0,
      8,   6, 138,  40, 162, 137,  66,   0,   8,   6, 138,  40,
    170, 170, 165,   0,   8,   6, 138,  37,   8,  82,  40, 128,
      8,   6, 138,  40, 148,  32, 130,   0,   8,   6, 248,  33,
      8,  66,  15, 128,   8,   6, 113,   4,  16,  65,   7,   0,
      8,   6,   2,   4,   8,  16,  32,   0,   8,   6, 112,  65,
      4,  16,  71,   0,   8,   6,  33,  72, 128,   0,   0,   0,
      8,   6,   0,   0,   0,   0,  15, 128,   8,   6,  64, 129,
      0,   0,   0,   0,   8,   6,   0,   7,   2, 122,  39, 128,
      8,   6, 130,  11,  50, 138,  47,   0,   8,   6,   0,   7,
     32, 130,  39,   0,   8,   6,   8,  38, 166, 138,  39, 128,
      8,   6,   0,   7,  34, 250,   7,   0,   8,   6,  49,  36,
     56,  65,   4,   0,   8,   6,   1, 232, 162, 120,  39,   0,
      8,   6, 130,  11,  50, 138,  40, 128,   8,   6,  32,   6,
      8,  32, 135,   0,   8,   6,  16,   3,   4,  18,  70,   0,
      8,   6, 130,   9,  40, 194, 137,   0,   8,   6,  96, 130,
      8,  32, 135,   0,   8,   6,   0,  13,  42, 170,  40, 128,
      8,   6,   0,  11,  50, 138,  40, 128,   8,   6,   0,   7,
     34, 138,  39,   0,   8,   6,   0,  15,  34, 242,   8,   0,
      8,   6,   0,   6, 166, 120,  32, 128,   8,   6,   0,  11,
     50, 130,   8,   0,   8,   6,   0,   7,  32, 112,  47,   0,
      8,   6,  65,  14,  16,  65,  35,   0,   8,   6,   0,   8,
    162, 138, 102, 128,   8,   6,   0,   8, 162, 137,  66,   0,
      8,   6,   0,   8, 162, 170, 165,   0,   8,   6,   0,   8,
    148,  33,  72, 128,   8,   6,   0,   8, 162, 120,  39,   0,
      8,   6,   0,  15, 132,  33,  15, 128,   8,   6,  16, 130,
     16,  32, 129,   0,   8,   6,  32, 130,   8,  32, 130,   0,
      8,   6,  64, 130,   4,  32, 132,   0,   8,   6,  66, 161,
      0,   0,   0,   0,
};

//*****************************************************************************
//
// The font definition for the fixed-point 6x8 font.
//
//*****************************************************************************
const tFont g_sFontFixed6x8 =
{
    //
    // The format of the font.
    //
    FONT_FMT_UNCOMPRESSED,

    //
    // The maximum width of the font.
    //
    6,

    //
    // The height of the font.
    //
    8,

    //
    // The baseline of the font.
    //
    7,

    //
    // The offset to each character in the font.
    //
    {
           0,    8,   16,   24,   32,   40,   48,   56,
          64,   72,   80,   88,   96,  104,  112,  120,
         128,  136,  144,  152,  160,  168,  176,  184,
         192,  200,  208,  216,  224,  232,  240,  248,
         256,  264,  272,  280,  288,  296,  304,  312,
         320,  328,  336,  344,  352,  360,  368,  376,
         384,  392,  400,  408,  416,  424,  432,  440,
         448,  456,  464,  472,  480,  488,  496,  504,
         512,  520,  528,  536,  544,  552,  560,  568,
         576,  584,  592,  600,  608,  616,  624,  632,
         640,  648,  656,  664,  672,  680,  688,  696,
         704,  712,  720,  728,  736,  744,  752,
    },

    //
    // A pointer to the actual font data
    //
    g_pui8FontFixed6x8Data
};

  • Jame shin
    Please tell me how to create 5x7 Font source code. ?

    Is that not - exactly - just what your, "fixed point, 6x8 font" achieves?   (which you've ably & completely presented!)

    Kindly note that the 6x8 nomenclature refers to the embedding of, "One extra (blank) font column & one extra (blank) font row" - to nicely 'encase' the 5x7 font pixel field.   (Minus those 2 blank areas (one column & one row between characters) - the individual font characters would, 'run together' - preventing clear/eased character recognition.)

    Ninty-five font characters are revealed.    Most always these represent the 'Visible' characters - which 'start' at  '0x20'  (that's the space character.)

    Indeed your 'font table' starts (up top) with:  "8,   6,   0,   0,   0,   0,   0,   0."    Moving to your cryptographic chair/position - those 6 '0s' describe 5 pixel (vertical) columns and the enforced 6th (blank) column.   (which again - prevents the individual font pixel characters from 'bleeding into' each other...)    The '8 & 6' are used by the font generator to properly create the '5x7 pixel font'  WITHIN  a '6x8' pixel cell.

    Cryptography informs/advises that: Scanning the, 'Known Character Field for: 'Simple/Minimal Pixel representations'  (- . _ |) or 'Symmetric Pixel representations' (" # H U) reasonably enables one to 'Crack' the individual 'weighting' of each pixel bit w/in each individual font column.    Recall that the individual column values are presented in sequence via the, 'Fixed6x8dData' array - which (again) includes one 'dummy  (blank)' column.

    Tag: 5x7 code ... alive & well ... although (apparently) unrecognized here...

  • In reply to cb1_mobile:

    Hi cb1,

      I learn so much from your post. I have no clue how to generate a 5x7 font or how any fonts are created until your excellent explanation. 

    Hi Jame,

      All the fonts that come with the TivaWare library will be in <TivaWare_Installation>/grlib/fonts. If you don't find the fonts you want in the library then you will need to either create your own with tips from cb1 or Google search public fonts that you can import to the library.  

    regards,

    Charles

     

  • In reply to Charles Tsai:

    Hi back, Charles,

    Thank you - your comment is (very) generous.   

    As our poster has (actually) presented the '5x7' font - might it have been that he (really) sought the (smaller) 5x5 Font?     

    And - in that case - crack/young staff have 'found' that (5x5) - which was (and is) employed by a gorgeous 'Siemens 5x5 Led, Multiple Character Matrix.'   (those multi-character, Led Modules - are as much (if not more) a, 'Work of Art' as compared to an 'electronic display'.   (They really POP - their 'downside' - they are 'Multiples of the Price' of equivalent Lcd character modules.)    We have deployed these in aircraft cockpits & various medical devices - where 'Superb Contrast & endless Viewing Angle' - are key (enforced) requirements.

    Several things deserve further mention:

    • Font table which poster presented is marked as, "uncompressed."    Staff here notes that this vendor (also) provides "compressed" font tables - which may drastically reduce the size (thus the memory requirements) - forced upon the application.
    • As my firm developed similar font tables (well prior to ARM) we worked most always w/'compressed fonts' - but unlike this vendor - stored our font data off chip (MCU!)    (i.e. in non-volatile serial memory)   As the MCU 'load time' was an order of magnitude higher then - this eased (actually enabled) the use of the MCU's (far smaller, then) internal memory to contain all of the Program Code.   (which the inclusion of the entire Font Table data (multiple fonts) would simply 'overwhelm!')    My firm (still) prefers to place such Font Table data & Calibration Values - off chip.
    • ASCII Tables usually reserve the lower 32 table entries for Control Codes & similar - which are (rarely) displayed.    (i.e. CR, LF, ESC etc.)
    • There exist (some) variation w/in the various font tables.    Usually they will be highly (yet not completely) consistent.
    • The 96th font entry (usually) serves as a 'Delete' - like the space - all column (or row) entries will be '0s.'
    • Some tables extend to the area above, '0x7F' (delete).   This space (0x80 - 0xFF) often provides 'foreign' characters & special symbols (primarily math based')

    Tag: (Almost) everything you wanted to know about Font Tables (especially those ASCII based).

  • In reply to cb1_mobile:

    Hello Charles

    Thank you for your reply

    Also,  thank you for Cb1's answer.

    I searched on Google and found the free of charge License, Oled-font-5x7 source code.

    By the way, I'm thinking about how to import.

    Compared to <TivaWare_Installation> / grlib / fonts / fontfixed6x8.c

    There is no offset for each character in the font

    What should I do?

    regards,

    Jame,Shin

    The source I found is below.

    https://github.com/noopkat/oled-font-5x7/blob/master/oled-font-5x7.js

  • In reply to Jame shin:

    Hello Jame,

      Why don't you first get the 6x8 font to display first? If you can get the 6x8 font to properly display then you can look on the display how each character is formed (their bit map) and compared with the 6x8 font table in the fontfixed6x8.c file. As well explained by cb1, a 5x7 font can be implemented/referenced from a 6x8 cell with the sixth column omitted. Get the 6x8 font to display first and change the 6x8 table by removing the sixth column for each character and see how they come out on the display. They may not appear as aesthetic  at first (i.e. characters have not spacing between them). But with some manipulation of the table data, you can get it to appear better. Or import the 5x7 font that you already fount on the web. However, I don't understand what offset you are referring to. I'm not an expert in the font generation. Please understand our support is mainly on using the MCU. As much as I'd like to support you, we cannot possibly understand every application the MCU can be put into. If you can get the 5x7 font to work, please do share with the community. It will be a bookmark for me to reference to others when asked in the future. I'm sure it will benefit many who are looking for the same solution. 

       

    regards,

    Charles

     

  • In reply to Jame shin:

    Jame shin
       There is no offset for each character in the font.   (fontfixed6x8.c)    What should I do?   

    May I disagree - just like the MCU's Vector Table (resident w/in the Start-Up file) - there   IS  very much an offset for each character!   (Minus that 'offset' how could the font data (or the vector's location) be determined?)

    You've specified a 'fixed font' - in which all  (visible) characters employ the identical pixel width & height.   Thus - the offset is regular - and determined by the character's 'Distance from the base' (usually 0x20 'the space character').   For example the numeric '0' character (0x30) is '0x10 (16 decimal) distant' from the 'starting' space character.  The offset to any character is that character's distance from the base (space) times the number of fixed values which constitute each font character.   (i.e. if the font is as your initial post revealed: (8,6,0,0,0,0,0,0, 8,6...) then each successive character is 8 memory locations (from its neighbor) or 8 * (character's table value - (minus) 0x20).    (where 'table value' is the number of characters appearing between 'space (0x20)' and the desired character.)   

    Some common 'font table value offsets' are:  '0' (0x30) Offset is 0x10; 'A' (0x41) Offset is 0x21; 'a' (ox61) Offset is 0x41.   Again - the table value offset must be multiplied by the number of 'fixed values' which define each character.   (which would be '8' in the example your initial post presented here.)

    Now such 'font fixed' characters 'suffer' in that the display space allotted to (i) is the same as that allotted to (W)!    Thus such fixed spacing is (both) wasteful & unattractive.   That reality led to the development of 'variable' sized characters - yet placed w/in the (same) font table.   (in such case - the 'W' character is far wider than the 'i'.)   And - as the size of characters is non-constant - the unique 'offset' for each/every character - must be specified...

    Vendor's Charles has duly noted that your questions/concerns have 'moved far' from 'MCU-Centric' - which (really) is outside the design intent of 'most any' MCU based forum.    It is noted that vendor agents have been (very) generous in devoting time & effort in your behalf!     And perhaps too - this humble forum outsider...

    'KISS' dictates that, 'Each of us be 'properly prepared' (prior) to accepting a new task.    You have (often) signaled your 'belief in KISS' - yet  does not your 'reach' often exceed your 'readiness'  (experience & present capability) - which can not always - end well...   Instead - might the 'high detail' you regularly seek (here) -  benefit from  'somewhat less challenging tech tasks'  AND the investigation of 'additional tech resources' - which may be better equipped (and chartered) - to meet your on-going (minimally MCU based) programming, electronic, & display (learning) requirements...

  • In reply to cb1_mobile:

    Hi cb1,

     LIKE! At first I thought the offset that Jame was talking about was the offset field shown below (0, 8,  16...). But I wasn't sure when I was replying.

    cb1_mobile
    The offset to any character is that character's distance from the base (space) times the number of fixed values which constitute each font character.

    I guess for 5x7, the offset will be (0, 7, 14, 21....).

    Cb1, thanks again.

    regards,

    Charles

     

  • In reply to Charles Tsai:

    Hi Charles,

    Thank you - and again - the amount of 'time/attention' devoted to this poster reveals great patience upon (especially) your part.    Earlier he described himself as a 'beginner' - yet the tasks he's attempting - prove 'FAR from those aimed at beginners!'     And - are only 'barely' MCU-centric - which forces vendor agents 'Away' from their central charter.  (purpose)

    Now - from experience - fonts may be 'creative in their pixel organization' - and sometimes aim to organize & present data in the 'optimal format required by the Display.'    (and/or the display's controller)

    In the case (just above) it must be noted that a '5x7 font' may be, 'Column or Row based.'    The font you've just listed clearly is 'Row based' - thus will be larger than one 'Character based.'    For example - if  'column-based'  each character may be represented by 'just' 5 bytes; if  'row-based' - that representation expands to 7 bytes.   (the use of the blank row/column 'separators' proves dependent upon the character generator which works in concert w/the font table.)

    While the difference proves nominal for 'so small a size font' - users must consider the implications of the, 'Column vs. Row' decision - when larger fonts (20-60+ pixel tall fonts) are employed.   These larger fonts greatly benefit from 'compression techniques' - and your firm imho has done very well in that regard!    (via the extensive number of fonts w/in the Graphic Library)

    My sense is that the offset (really is) '8' - as the comment in the font table specifies.    If '7' was used instead - the fetch of font data would become 'progressively Off' -  especially as the selected character resides 'deeper w/in the font table.'   (the font's 'character generator' (uses) the 'extra dead row' (in this case) to implement a 'proper surround'  (to insure separation) - between adjacent font characters...)

  • In reply to cb1_mobile:

    I am using the Kentec BOOSTXL-K350QVG-S1 320 x 240 display. It is a very nice display and the library supplied by TI is very useful.

    However I have noticed some characters are not displaying properly (e.g. "<", ">"). After reading the explanation of how the compressed font is encoded I have started modifying the table of the particular font I am using. I'll post some before and after pictures of the display for anyone interested in modifying their own font. 

    I also just wanted to say what a great product TI have made. I've used quite a few microcontrollers over the years and the LaunchPad series of boards (I have an EK-TM4C123GXL and EK-TM4C1294XL) and Code Composer Studio IDE are just awesome. I love how you can program in C and assembly and the way the whole thing is set out is very user friendly (auto-indent saves me a lot of time + many other nice features), and the online training material is of great help for hobbyists like myself. Also making it free of charge is pretty amazing, I remember not too long ago software like this was quite expensive. It still is (e.g. Keil - another great product but beyond reach for most hobbyists).  

    Keep up the great work TI!  

  • In reply to Daniel Milutinovic:

    Hello Daniel,

    I saw your post well.

    Being helpful, I am also glad.

    I look forward to the results.

    regards,

    Jame,Shin