Static avr-libc library providing basic support for TFT LCDs
  • C 93.1%
  • Makefile 5.9%
  • Shell 1%
Find a file
2026-04-07 21:59:03 +02:00
nbproject Add 'disasm' target, take care that types are defined 2025-07-08 12:38:11 +02:00
.gitignore Initial commit 2025-07-06 21:55:11 +02:00
CODE_OF_CONDUCT.md Initial commit 2025-07-06 21:55:11 +02:00
font.c Initial commit 2025-07-06 21:55:11 +02:00
font.h Add conversion from 8-bit (3/3/2) to 16-Bit (5/6/5) RGB 2025-07-12 22:55:59 +02:00
hack.c Initial commit 2025-07-06 21:55:11 +02:00
hack.h Initial commit 2025-07-06 21:55:11 +02:00
libtft.c Improve delays used in initialization 2025-11-12 21:26:10 +01:00
libtft.h Improve delays used in initialization 2025-11-12 21:26:10 +01:00
LICENSE Initial commit 2025-07-06 21:55:11 +02:00
Makefile Improve delays used in initialization 2025-11-12 21:26:10 +01:00
README.md Move to Forgejo 2026-04-07 21:59:03 +02:00
types.h Add 'disasm' target, take care that types are defined 2025-07-08 12:38:11 +02:00
unifont.c Initial commit 2025-07-06 21:55:11 +02:00
unifont.h Initial commit 2025-07-06 21:55:11 +02:00
utils.h Initial commit 2025-07-06 21:55:11 +02:00

libtft

About

Static avr-libc library providing basic support for TFT LCDs such as:

Currently implemented features:

  • Mostly complete UTF-8 set (code points U+0000 to U+00FF) of Unifont font (1-Bit monochrome)
  • Mostly complete UTF-8 set (code points U+0000 to U+00FF) of Hack font with antialiasing (4-Bit greyscale)
  • Write text, draw bitmaps

IMG_20250711_234547

Usage

  1. Include libtft.h, font.h, types.h and libtft.a in the project
  2. Include hack.h and/or unifont.h, depending on what font to use.
  3. Implement the _tft* functions in libtft.h in the application (this is to make the library CPU frequency independent)

Fonts

To include a font, add i.e. dejavu.h:

    #ifndef DEJAVU_H
    #define DEJAVU_H

    #include "font.h"

    /**
     * DejaVu font.
     */
    extern const __flash Font dejaVuFont;

    #endif /* DEJAVU_H */

and the matching implementation dejavu.c:

    #include "dejavu.h"
    #include "utils.h"

    #define HEIGHT 56

    static const __flash uint8_t SPACE[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        // more ...
    }

    // more chars ...

    const __flash Glyph glyphs[] = {
        {0x0020, 24, SPACE},
        {0x0021, 16, EXCLAMATION_MARK},
        {0x0023, 32, NUMBER_SIGN},
        {0x0025, 32, PERCENT_SIGN}
        // more ...
    }

    const __flash Font dejaVuFont = {glyphs, array_length(glyphs), HEIGHT, SPACE_MONO1};

and write some text in DejaVu to the display:

    const __flash Font *dejaVu = &dejaVuFont;
    tftWriteString(x, y, dejaVu, "123", WHITE, crc ? BLACK : RED);

Bitmaps

To display bitmaps, add i.e. bitmaps.c:

    #include "font.h"

    const __flash uint8_t TUX_DATA[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x03, 0xff, 0x80, 0x00, 0x00,
        0x00, 0x00, 0x07, 0xff, 0xc0, 0x00, 0x00,
        0x00, 0x00, 0x07, 0xff, 0xe0, 0x00, 0x00
        // more ...
    }

    const __flash Bitmap bitmaps[] = {
        {56, 64, SPACE_MONO1, TUX_DATA}
    };

and write Tux to the display:

    tftWriteBitmap(0, 176, 0, 0xffff, 0x0000);