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

Header file for TTY interface - text output on OLED display. More...

#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include "../oled.h"
#include "../font/font.h"
Include dependency graph for tty.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define F_CPU   12000000UL
 System clock frequency definition.
#define TTY_WIDTH   (OLED_COLUMN_SIZE/FONT_WIDTH)
 Defines the number of text columns available in the TTY interface.
#define TTY_HEIGHT   (OLED_ROW_SIZE/OLED_PAGE_SIZE)
 Defines the number of text lines available in the TTY interface.
#define TTY_AUTOSCROLL
 Enables automatic scrolling of text when the cursor reaches the bottom of the display.
#define TTY_ENABLE_PRINTF
 Enables support for printf-style formatted output in the TTY interface.
#define TTY_DYNAMIC_TEXT
 Enables dynamic spacing adjustment between characters in the TTY text output.
#define TTY_HOME()
 Moves the TTY cursor to the home position (top-left corner) of the text area.

Functions

void tty_init (void)
 Initializes the TTY text output interface.
void tty_cursor (unsigned char column, unsigned char line)
 Sets the cursor position in the TTY text interface.
void tty_clear_line (unsigned char line)
 Clears a specific text line on the TTY 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

Header file for TTY interface - text output on OLED display.

This file provides function prototypes, macro definitions, and constants for text output on a graphical OLED display. It supports cursor control, text rendering, line clearing, and optional printf functionality. The TTY interface abstracts text handling by using font data and display parameters defined elsewhere and adapts to platform-specific settings. Configuration macros control buffer dimensions, autoscrolling behavior, and printf support. The interface depends on the OLED driver and font data provided in separate modules.

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"

Macro Definition Documentation

◆ F_CPU

#define F_CPU   12000000UL

System clock frequency definition.

This macro defines the operating frequency of the microcontroller's clock in Hertz. It is used by delay functions and timing calculations. The value should match the actual hardware clock frequency to ensure correct timing behavior in the software.

◆ TTY_AUTOSCROLL

#define TTY_AUTOSCROLL

Enables automatic scrolling of text when the cursor reaches the bottom of the display.

When this macro is defined, the TTY interface will automatically scroll the displayed text upward as new lines are added beyond the last visible line. This ensures that newly written text remains visible without manual intervention to clear or reposition the display.

Note
If undefined, the TTY interface may either stop rendering new lines or overwrite existing content without scrolling. This macro acts as a compile-time flag to control autoscrolling behavior.

◆ TTY_DYNAMIC_TEXT

#define TTY_DYNAMIC_TEXT

Enables dynamic spacing adjustment between characters in the TTY text output.

When this macro is defined, the TTY interface dynamically regulates the horizontal spacing between individual characters during text rendering to minimize large gaps. This helps achieve a more visually balanced and compact text appearance on the OLED display, improving readability and aesthetics.

Note
If undefined, fixed-width spacing will be used for all characters, potentially resulting in uneven gaps. This macro acts as a compile-time flag to enable or disable dynamic character spacing.

◆ TTY_ENABLE_PRINTF

#define TTY_ENABLE_PRINTF

Enables support for printf-style formatted output in the TTY interface.

Defining this macro includes the implementation of functions that allow using printf-style formatting to send formatted text strings to the OLED display via the TTY interface. This facilitates flexible and convenient text output with variable substitution and formatting.

Note
If undefined, the printf functionality is excluded, reducing code size and complexity. This macro serves as a compile-time option to include or exclude printf support.

◆ TTY_HEIGHT

#define TTY_HEIGHT   (OLED_ROW_SIZE/OLED_PAGE_SIZE)

Defines the number of text lines available in the TTY interface.

This macro calculates the height of the text display area in lines by dividing the total number of OLED pixel rows (OLED_ROW_SIZE) by the height of one page of the display.

Note
It determines how many text lines can be displayed vertically on the screen.

◆ TTY_HOME

#define TTY_HOME ( )
Value:
(tty_cursor(0, 0))
void tty_cursor(unsigned char column, unsigned char line)
Sets the cursor position in the TTY text interface.
Definition tty.c:126

Moves the TTY cursor to the home position (top-left corner) of the text area.

This macro calls the function tty_cursor with coordinates (0, 0), which sets the text cursor to the first column and first line of the TTY interface. It is commonly used to reset the cursor position before writing new text or clearing the display.

◆ TTY_WIDTH

#define TTY_WIDTH   (OLED_COLUMN_SIZE/FONT_WIDTH)

Defines the number of text columns available in the TTY interface.

This macro calculates the width of the text display area in characters by dividing the total number of OLED display columns (OLED_COLUMN_SIZE) by the width of a single font character (FONT_WIDTH).

Note
It sets the maximum number of characters that can fit horizontally on the screen.

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: