oled 1.0
OLED Graphics Control Library
|
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"
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). |
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.
#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.
#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.
#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.
#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.
#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.
#define TTY_HOME | ( | ) |
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.
#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).
void tty_clear_line | ( | unsigned char | line | ) |
Clears a specific text line on the TTY interface.
line | The 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.
void tty_cursor | ( | unsigned char | column, |
unsigned char | line ) |
Sets the cursor position in the TTY text interface.
column | The column index (0-based) to move the cursor to. Must be less than TTY_WIDTH. |
line | The 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.
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.
int tty_printf | ( | char | data, |
FILE * | stream ) |
Writes a single character to the TTY interface (used as a printf output function).
data | The character to output. |
stream | Pointer to the output stream (unused, required by standard library interface). |
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.
char tty_putchar | ( | char | character | ) |
Writes a single character to the TTY text interface on the OLED display.
character | The ASCII character to display. |
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.
void tty_string | ( | const char * | string | ) |
Writes a null-terminated string to the TTY text interface.
string | Pointer 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.