at24cm0x 1.0
at24cm0x driver library
Loading...
Searching...
No Matches
font.h File Reference

Header file for font handling and character bitmap retrieval. More...

#include <ctype.h>
#include <avr/eeprom.h>
Include dependency graph for font.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FONT_TYPE   FONT_5X7_ASCII
 Defines the type of the font that is being used.
#define FONT_WIDTH   5
 Defines the width in pixels of each character in the font.
#define FONT_HEIGHT   7
 Defines the height in pixels of each character in the font.
#define FONT_ASCII_START_CHAR   ' '
 Specifies the starting ASCII character for the font.
#define FONT_ASCII_END_CHAR   '~'
 Specifies the ending ASCII character for the font.
#define FONT_IGNORE_LOWER_CASE
 Converts all lowercase letters to uppercase to save memory in PROGMEM or EEPROM.
#define FONT_STORE_IN_EEPROM
 Stores the font data in EEPROM memory.

Functions

void font_get_bitmap (char character, unsigned char *bitmap)
 Retrieves the bitmap array for a given ASCII character from the font table.

Detailed Description

Header file for font handling and character bitmap retrieval.

This file defines macros for font dimensions, ASCII character range, and configuration options such as storing fonts in EEPROM or ignoring lower case characters. It provides the prototype for font_get_bitmap, a function that creates bitmap data of a given ASCII character. The font data supports rendering text on graphical displays like OLED by converting characters into pixel patterns. Configuration macros allow customization of font size and storage.

Author
g.raf
Date
2026-07-15
Version
1.0 Release
Note
This file is part of a larger project and subject to the license specified in the repository. For updates and the complete revision history, see the GitHub repository.
See also
https://github.com/0x007e/drivers-display-font "Drivers Display Font GitHub Repository"

Macro Definition Documentation

◆ FONT_ASCII_END_CHAR

#define FONT_ASCII_END_CHAR   '~'

Specifies the ending ASCII character for the font.

This macro defines the last ASCII character that the font supports or displays. It is used to set the ending character code when mapping font glyphs.

◆ FONT_ASCII_START_CHAR

#define FONT_ASCII_START_CHAR   ' '

Specifies the starting ASCII character for the font.

This macro defines the first ASCII character that the font supports or displays. It is used to set the beginning character code when mapping font glyphs.

◆ FONT_HEIGHT

#define FONT_HEIGHT   7

Defines the height in pixels of each character in the font.

This macro sets the vertical size of a single character glyph in pixels. It is used to define the font height for rendering text on graphical displays.

◆ FONT_IGNORE_LOWER_CASE

#define FONT_IGNORE_LOWER_CASE

Converts all lowercase letters to uppercase to save memory in PROGMEM or EEPROM.

When this macro is defined, only uppercase letters are displayed by converting any lowercase letters to their uppercase equivalents. This helps reduce memory usage in program memory (PROGMEM) or EEPROM by avoiding the storage of separate lowercase glyphs.

Note
Defining this macro enables the ignoring of lowercase characters entirely.

◆ FONT_STORE_IN_EEPROM

#define FONT_STORE_IN_EEPROM

Stores the font data in EEPROM memory.

When this macro is defined, font data is saved in the EEPROM memory, which helps reduce PROGMEM usage. The amount of EEPROM required depends on the character set:

  • All ASCII characters require approximately 470 bytes of EEPROM.
  • ASCII characters without lowercase letters require approximately 340 bytes of EEPROM.
Note
Using EEPROM for font storage extends PROGMEM availability but be mindful of EEPROM write limits.

◆ FONT_TYPE

#define FONT_TYPE   FONT_5X7_ASCII

Defines the type of the font that is being used.

This macro sets the type of the font, such as FONT_5X7_ASCII. It is used to identify the font type for rendering and bitmap retrieval.

Note
The default font type is FONT_5X7_ASCII, which supports standard ASCII characters.

The maximum font size is undef x 8 pixels (width x length), and the minimum font size is 1x1 pixel. The font type can be changed by defining this macro before including this header file.

- | - LENGTH - |
| # # # # # # # #
W # # # # # # # #
I # # # # # # # #
D # # # # # # # #
T # # # # # # # #
H # # # # # # # #
| # # # # # # # #
-

The start address is at ARRAY[0] -> Bit 0,0 (top left corner).

Example (Character B):

- | - LENGTH - |
| 1 1 1 1 1 1 1 1
W 1 0 0 0 1 0 0 1
D 1 0 0 0 1 0 0 1
T 1 0 0 0 1 0 0 1
H 0 1 1 1 0 1 1 0
-

◆ FONT_WIDTH

#define FONT_WIDTH   5

Defines the width in pixels of each character in the font.

This macro sets the horizontal size of a single character glyph in pixels. It is used to calculate spacing and positioning when rendering text on graphical displays.

Function Documentation

◆ font_get_bitmap()

void font_get_bitmap ( char character,
unsigned char * bitmap )

Retrieves the bitmap array for a given ASCII character from the font table.

Parameters
characterThe ASCII character to retrieve the bitmap for.
bitmapPointer to a array for storing the bitmap bytes representing the character.

This function maps an input ASCII character to its corresponding bitmap pattern stored in the font table. If the character is outside the supported ASCII range defined by FONT_ASCII_START_CHAR and FONT_ASCII_END_CHAR, it defaults is the '?' character. When the macro FONT_IGNORE_LOWER_CASE is defined, lowercase letters are converted to uppercase to save memory, and adjustments are made to the character code accordingly.

Note
The bitmap data is read from either EEPROM or program memory (PROGMEM) depending on the macro FONT_STORE_IN_EEPROM. The data is copied into an array pointed to. The operator has to prevent the correct size of this array!
Here is the caller graph for this function: