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

Source file with implementation of TTY text output interface on OLED display. More...

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

Functions

void tty_init (void)
 Initializes the TTY text output interface.
void tty_clear_line (unsigned char line)
 Clears a specific text line on the TTY interface.
void tty_cursor (unsigned char column, unsigned char line)
 Sets the cursor position in the TTY text interface.
char tty_putchar (char character)
 Writes a single character to the TTY text interface on the OLED display.
void tty_string (const char *string)
 Writes a null-terminated string to the TTY text interface.
int tty_printf (char data, FILE *stream)
 Writes a single character to the TTY interface (used as a printf output function).

Detailed Description

Source file with implementation of TTY text output interface on OLED display.

This file contains the implementation of functions for text rendering on a graphical OLED display. It supports cursor positioning, character and string output, line clearing, and optional printf-style formatted output. The interface handles autoscrolling and dynamic character spacing for improved readability. The TTY layer relies on the OLED display driver and font data modules. It abstracts text rendering as characters drawn via pixel data segments using the configured font, respecting display size and constraints. Compile-time options toggle support for autoscroll, dynamic text spacing, and printf functionality.

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 updates and the complete revision history, see the GitHub repository.
See also
https://github.com/0x007e/oled "AVR ATmega GitHub Repository"

Function Documentation

◆ tty_clear_line()

void tty_clear_line ( unsigned char line)

Clears a specific text line on the TTY interface.

Parameters
lineThe line number (0-based) to clear. Must be less than TTY_HEIGHT.

This function checks if the specified line is within the valid range of the display. If it is, the function clears the corresponding page on the OLED display associated with that text line.

Note
Clearing effectively removes all characters and pixels on that line, preparing it for new content.
Here is the call graph for this function:

◆ tty_cursor()

void tty_cursor ( unsigned char column,
unsigned char line )

Sets the cursor position in the TTY text interface.

Parameters
columnThe column index (0-based) to move the cursor to. Must be less than TTY_WIDTH.
lineThe line index (0-based) to move the cursor to. Must be less than TTY_HEIGHT.

This function validates the requested cursor position to ensure it's within the display bounds. If valid, it updates the internal cursor tracking variables for character column and line. It then sets the corresponding pixel position on the OLED display by converting the column to pixel coordinates based on the font width and updating the OLED cursor to that position.

Here is the call graph for this function:

◆ tty_init()

void tty_init ( void )

Initializes the TTY text output interface.

This function initializes internal state variables for cursor position and scrolling, resets dynamic text spacing if enabled, and initializes the underlying OLED display. It clears the OLED screen to prepare for new text output. If printf support is enabled, it also configures the standard output stream stdout to use the TTY's printf handler function, allowing formatted output via standard C library functions.

Note
This function should be called once at system startup before any TTY text output operations.
Here is the call graph for this function:

◆ tty_printf()

int tty_printf ( char data,
FILE * stream )

Writes a single character to the TTY interface (used as a printf output function).

Parameters
dataThe character to output.
streamPointer to the output stream (unused, required by standard library interface).
Returns
Returns the result of tty_putchar, typically 0.

This function acts as a character output handler compatible with the standard C library printf mechanism. It redirects characters from formatted output to the TTY text rendering function tty_putchar.

Note
This enables using printf-style functions to display text on the OLED via the TTY interface.
Here is the call graph for this function:

◆ tty_putchar()

char tty_putchar ( char character)

Writes a single character to the TTY text interface on the OLED display.

Parameters
characterThe ASCII character to display.
Returns
Returns 0 on success or ignored character.

This function validates the input character against the supported font ASCII range, ignoring characters outside this range except newline (‘’
'). If the character is a newline, it triggers a line break via tty_newline(). For printable characters, it retrieves the pixel data bitmap from the font module. When dynamic text spacing (TTY_DYNAMIC_TEXT) is enabled, the function adjusts horizontal spacing to minimize large gaps between characters by manipulating tty_dynamic_text_rstrip. It draws the character on the current line and position using oled_page_segment`. When dynamic spacing is disabled, fixed character width spacing is used.

Note
After writing the character, the cursor advances horizontally. If the end of the line is reached, the function automatically inserts a newline to move to the next line.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tty_string()

void tty_string ( const char * string)

Writes a null-terminated string to the TTY text interface.

Parameters
stringPointer to the null-terminated character array (C-string) to display.

This function iterates through each character of the input string until it encounters the string terminator (‘’\0'). Each character is passed to tty_putchar` for rendering on the OLED display, thereby displaying the entire string sequentially.

Here is the call graph for this function: