oled 1.0
OLED Graphics Control Library
Loading...
Searching...
No Matches
frame.c File Reference

Source file implementing frame management and drawing functions for OLED display. More...

#include "frame.h"
Include dependency graph for frame.c:

Functions

void frame_init (void)
 Initializes the frame system and OLED display.
void frame_draw_text (const char *text, DRAWING_Position position)
 Renders a text string on the OLED display at a specified position.
void frame_draw_char (const char character, DRAWING_Position position)
 Renders a single character on the OLED display at a specified position.
void frame_draw_number (const void *number, unsigned char length, NUMBER_Type type, NUMBER_Radix radix, DRAWING_Position position)
 Renders a formatted number on the OLED display at a specified position.
void frame_draw_number_uint (const unsigned int number, unsigned char length, NUMBER_Radix radix, DRAWING_Position position)
 Inline helper function to draw an unsigned integer number on the OLED display.
void frame_draw_number_int (const int number, unsigned char length, NUMBER_Radix radix, DRAWING_Position position)
 Inline helper function to draw a signed integer number on the OLED display.
void frame_clear (void)
 Clears the entire display frame.
void frame_draw_bar (DRAWING_Position position, DRAWING_Size size, unsigned char percent)
 Draws a horizontal progress bar on the OLED display.

Variables

const unsigned char frame_background[8][128] PROGMEM

Detailed Description

Source file implementing frame management and drawing functions for OLED display.

This file contains the implementation of functions to initialize the frame system, draw text and numbers with various numeric formats, render progress bars, and manage display areas. It supports an optional specific background image stored in program memory, which is drawn and maintained during display updates to ensure visual consistency. The rendering functions integrate with font data and OLED driver modules to output characters and graphical elements. Numeric drawing supports unsigned, signed, and optionally decimal numbers with configurable precision. The code is designed for embedded environments with memory constraints, utilizing PROGMEM for constant data storage and conditional compilation for feature configuration.

Author
g.raf
Date
2025-09-03
Version
1.0 Release
Note
This file is part of a larger project and subject to the license specified in the repository. For detailed updates and revision history, see the GitHub repository.
See also
https://github.com/0x007e/oled "AVR ATmega GitHub Repository"

Function Documentation

◆ frame_clear()

void frame_clear ( void )

Clears the entire display frame.

This function resets the OLED display content to a blank state by calling oled_clear(). If the compile-time macro FRAME_SPECIFIC_BACKGROUND is defined, it additionally redraws the predefined background image stored in frame_background to maintain the visual context. Without FRAME_SPECIFIC_BACKGROUND, the screen is simply cleared to black.

The function's linkage depends on the background setting:

  • Inline when no specific background is used, suggesting compiler optimization for small size.
  • Normal function otherwise due to potentially larger code size from background redraw.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ frame_draw_bar()

void frame_draw_bar ( DRAWING_Position position,
DRAWING_Size size,
unsigned char percent )

Draws a horizontal progress bar on the OLED display.

This function renders a progress bar at the specified position with the given size, visually representing the completion percentage as a filled section of the bar. The filled area of the bar corresponds to the percentage value (0-100%), calculated as a width increment. The unfilled remainder of the bar is cleared to maintain visual clarity.

Parameters
positionThe starting coordinates (x, y) of the progress bar on the display.
sizeThe width and height dimensions of the progress bar.
percentThe completion percentage to display (0 to 100).
Note
If the percentage exceeds 100, the bar is considered fully filled. The function internally handles clearing and filling the appropriate regions.

◆ frame_draw_char()

void frame_draw_char ( const char character,
DRAWING_Position position )

Renders a single character on the OLED display at a specified position.

This function draws a character bitmap starting at the coordinates specified by position. It determines which display pages are affected based on the font height and divides the character rendering across multiple OLED memory pages if necessary. For each column of the character, the corresponding font data is fetched from the font table and optionally combined with a predefined background buffer (if enabled). Bit shifting is applied to align the character correctly on display pages that do not align with the character boundaries. The final pixel data for each column is sent to the OLED driver via the oled_column function.

Parameters
characterThe ASCII character to be drawn.
positionThe starting position (x, y) on the display for the character.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ frame_draw_number()

void frame_draw_number ( const void * number,
unsigned char length,
NUMBER_Type type,
NUMBER_Radix radix,
DRAWING_Position position )

Renders a formatted number on the OLED display at a specified position.

This function receives a pointer to a number as any supported type (unsigned, signed, float, or double), converts it to a string representation according to the specified number type and radix (base), and draws the result as text at the given display position. The output can be padded with leading spaces (decimal) or zeros (other bases) to fit the desired field length. Supports decimal, hexadecimal, and other numeric bases, as well as fixed precision for floating-point numbers if FRAME_NUMBER_ENABLE_FLOATING_POINT is defined. Internally utilizes font rendering to display the formatted string.

Parameters
numberPointer to the value to display (type selected via the type argument).
lengthMinimum output width in characters (for padding).
typeThe type of the number (unsigned/signed int/long, or float/double if enabled).
radixNumber base for formatting (e.g., decimal, hexadecimal).
positionDisplay coordinates (x, y) for the output string.
Note
Floating point support increases code size and should be enabled only when required.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ frame_draw_number_int()

void frame_draw_number_int ( const int number,
unsigned char length,
NUMBER_Radix radix,
DRAWING_Position position )
inline

Inline helper function to draw a signed integer number on the OLED display.

This function is a simple wrapper around the generic frame_draw_number function, specifically for signed integers. It passes the address of the given number, the desired output length, radix, and position to the main number drawing function, specifying the type as signed int.

Note
Declared as inline to suggest compiler optimization by embedding the function code directly at the call site, minimizing function call overhead.
Parameters
numberThe signed integer value to draw.
lengthThe minimum number of characters to display (with padding if necessary).
radixThe numeric base (e.g., decimal, hexadecimal) for displaying the number.
positionThe screen coordinates (x, y) where the number will be rendered.
Here is the call graph for this function:

◆ frame_draw_number_uint()

void frame_draw_number_uint ( const unsigned int number,
unsigned char length,
NUMBER_Radix radix,
DRAWING_Position position )
inline

Inline helper function to draw an unsigned integer number on the OLED display.

This function wraps the more general frame_draw_number function, providing a convenient interface specifically for unsigned integers. It forwards the number pointer, length, radix, and drawing position to the main number rendering function with the appropriate type parameter.

Note
Declared as inline to suggest the compiler to optimize by embedding the function code at the call site, reducing function call overhead.
Parameters
numberThe unsigned integer value to draw.
lengthThe minimum number of characters to display (padding as needed).
radixThe numeric base (e.g., decimal, hexadecimal) for number display.
positionThe coordinates (x, y) on the display where the number will be rendered.
Here is the call graph for this function:

◆ frame_draw_text()

void frame_draw_text ( const char * text,
DRAWING_Position position )

Renders a text string on the OLED display at a specified position.

This function draws the given null-terminated string starting at the coordinates specified by position. It calculates affected display pages based on the character height and handles multi-page rendering for characters that span page boundaries. For each character in the string, the corresponding font bitmap is fetched and individual bytes are combined with the optional background pattern (if enabled) to preserve display background beneath the text. Bit-shifting is applied to properly align the character pixels vertically on partial pages. The function outputs the composed columns of pixel data to the OLED display using the lower-level oled_column function.

Parameters
textPointer to the null-terminated string to be drawn.
positionThe starting position (x, y) on the display for the text.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ frame_init()

void frame_init ( void )

Initializes the frame system and OLED display.

This function initializes the OLED display by calling the OLED driver initialization function (oled_init()) and then clears the display frame to prepare it for new content using frame_clear(). It should be called once during system startup before any text or graphics are drawn.

Note
This setup ensures the OLED hardware is ready and the display memory is cleared to a known state.
Here is the call graph for this function:

Variable Documentation

◆ PROGMEM

const unsigned char frame_background [8][128] PROGMEM