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

Source file with implementation of OLED display driver functions. More...

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

Functions

void oled_init (void)
 Initializes the OLED display.
void oled_disable (void)
 Disables the TWI interface used for OLED communication.
void oled_position (unsigned char column, unsigned char page)
 Sets the current write position on the OLED display.
void oled_scroll_vertical (unsigned char scroll)
 Scrolls the OLED display vertically by a specified offset.
void oled_frame (unsigned char *frame)
 Displays a full frame (all pages) of pixel data on the OLED.
void oled_page (unsigned char *data, unsigned char page)
 Writes a full page of pixel data to the OLED display.
void oled_page_segment (unsigned char *data, unsigned char column_start, unsigned char column_stop, unsigned char page)
 Writes a segment of pixel data to a specific page on the OLED display.
void oled_column (unsigned char data, unsigned char column, unsigned char page)
 Writes a single byte of pixel data to a specific column and page on the OLED display.
void oled_clear (void)
 Clears the entire OLED display.
void oled_clear_page (unsigned char page)
 Clears a single page of the OLED display.
void oled_clear_page_segment (unsigned char column_start, unsigned char column_stop, unsigned char page)
 Clears a specific segment of a page on the OLED display.
void oled_clear_column (unsigned char column, unsigned char page)
 Clears a single column within a specified page on the OLED display.

Variables

const unsigned char oled_init_commands[] EEMEM
unsigned char column_current_position
unsigned char page_current_position

Detailed Description

Source file with implementation of OLED display driver functions.

This file contains the initialization and control functions for the OLED display using TWI (I2C) communication, supporting both software and hardware TWI interfaces. It includes functions for sending commands and data to the display, positioning, scrolling, clearing, and updating display memory pages and segments.

Note
The OLED initialization routine commands are stored either in EEPROM or program memory, controlled by the OLED_INIT_ROUTINE_IN_EEPROM macro.

Communication with the OLED is abstracted through macros that select software or hardware TWI implementations based on compile-time 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 updates and the complete revision history, see the GitHub repository.
See also
https://github.com/0x007e/oled "AVR ATmega GitHub Repository"

Function Documentation

◆ oled_clear()

void oled_clear ( void )

Clears the entire OLED display.

This function iterates through all display pages and clears each one by calling oled_clear_page. After clearing all pages, it resets the cursor position to the home position (0,0) using OLED_HOME.

Note
This effectively resets the display content, turning off all pixels.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oled_clear_column()

void oled_clear_column ( unsigned char column,
unsigned char page )

Clears a single column within a specified page on the OLED display.

Parameters
columnThe column index (horizontal position) to clear.
pageThe page index (vertical position in groups of 8 pixel rows) where the column resides.

This function sets the cursor to the specified column and page, then writes a single zero byte to turn off all pixels in that column for the specified page. Communication with the display is done via TWI, using start and stop conditions, and the data control byte.

Note
Clearing a column effectively resets the pixels in that vertical segment to off.
Here is the call graph for this function:

◆ oled_clear_page()

void oled_clear_page ( unsigned char page)

Clears a single page of the OLED display.

Parameters
pageThe page index (0-based) to clear. Must be less than OLED_ROW_SIZE/OLED_PAGE_SIZE.

This function clears all columns within the specified page by calling oled_clear_page_segment with the full column range from 0 to OLED_COLUMN_SIZE - 1.

Note
It turns off all pixels on that page, effectively wiping the displayed content in that segment.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oled_clear_page_segment()

void oled_clear_page_segment ( unsigned char column_start,
unsigned char column_stop,
unsigned char page )

Clears a specific segment of a page on the OLED display.

Parameters
column_startThe starting column index of the segment to clear (inclusive).
column_stopThe ending column index of the segment to clear (inclusive).
pageThe page index (0-based) on which the segment is located. Must be less than OLED_ROW_SIZE/OLED_PAGE_SIZE.

This function clears a horizontal segment of a specified page by writing zeroes (turning off pixels) to the display RAM across the specified column range. It first validates the input parameters to ensure they are within the display boundaries and that column_start is less than or equal to column_stop. After setting the cursor position to the start column of the specified page, it sends a series of zero bytes over the TWI interface to clear each column in the segment. Communication starts with a start condition and a control byte indicating data transmission, and ends with a stop condition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ oled_column()

void oled_column ( unsigned char data,
unsigned char column,
unsigned char page )

Writes a single byte of pixel data to a specific column and page on the OLED display.

Parameters
dataThe byte of pixel data to write; each bit represents a pixel in the vertical column.
columnThe column index (horizontal position) where the data should be written.
pageThe page index where the data should be written.
Note
Both column and page must be within the display bounds (OLED_COLUMN_SIZE and OLED_ROW_SIZE/OLED_PAGE_SIZE respectively).

This function updates the pixel data of one specific column within a specified page. It first verifies that the target page and column are valid. Then, it sets the OLED cursor to the specified position and sends the pixel data byte via TWI. Communication begins with a start condition and a control byte indicating data transmission, followed by the data byte, and ends with a stop condition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ oled_disable()

void oled_disable ( void )
inline

Disables the TWI interface used for OLED communication.

This inline function disables the TWI (I2C) peripheral or software interface used to communicate with the OLED display, depending on whether software or hardware TWI is enabled. It is used to safely release TWI resources when OLED communication is no longer required, helping to reduce power consumption or prevent bus contention.

Here is the call graph for this function:

◆ oled_frame()

void oled_frame ( unsigned char * frame)

Displays a full frame (all pages) of pixel data on the OLED.

Parameters
framePointer to an array containing pixel data for the entire display, organized as consecutive pages.

This function updates the entire OLED screen by sequentially writing data page by page. It first resets the current cursor position to the home position (0,0), then iterates over all pages, calling oled_page to write each page’s data.

Note
The frame parameter should contain OLED_PAGE_SIZE pages of pixel data, where each page holds pixel data for the full width of the display.
Here is the call graph for this function:

◆ oled_init()

void oled_init ( void )

Initializes the OLED display.

This function initializes the TWI (I2C) communication interface to the OLED display, supports both software and hardware TWI based on compile-time configuration. It then sends a predefined sequence of initialization commands stored either in EEPROM or program memory to configure the OLED hardware registers and settings. After sending the initialization commands, the communication is ended with a stop condition, and the display is cleared to prepare it for use.

Note
This function must be called once during system startup before any display operations.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oled_page()

void oled_page ( unsigned char * data,
unsigned char page )

Writes a full page of pixel data to the OLED display.

Parameters
dataPointer to an array containing pixel data for one display page.
pageThe page index (0-based) to which the data should be written. Must be less than OLED_ROW_SIZE/OLED_PAGE_SIZE.

This function writes pixel data to a complete page (horizontal row of 8 pixel rows) on the OLED display. It performs boundary checking on the page parameter; if the page is invalid, the function returns without action.

Note
Internally, it calls oled_page_segment to update the entire width of the display on the specified page, passing the full column range from 0 to OLED_COLUMN_SIZE - 1.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oled_page_segment()

void oled_page_segment ( unsigned char * data,
unsigned char column_start,
unsigned char column_stop,
unsigned char page )

Writes a segment of pixel data to a specific page on the OLED display.

Parameters
dataPointer to an array containing pixel data for the segment to write.
column_startThe starting column index of the segment (inclusive).
column_stopThe ending column index of the segment (inclusive).
pageThe page index (0-based) where the data should be written. Must be less than OLED_ROW_SIZE/OLED_PAGE_SIZE.

This function writes a horizontal segment of pixel data on a specified page of the OLED display. It first validates the input parameters to ensure the page and column ranges are within the display bounds, and that the column start is less than the column stop.

The display cursor is set to the starting column and page before data transmission. Data bytes are then sent sequentially to the OLED over the TWI interface, using either software or hardware TWI accordingly. Communication begins with a start condition and control byte indicating data transmission, and ends with a stop condition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ oled_position()

void oled_position ( unsigned char column,
unsigned char page )

Sets the current write position on the OLED display.

Parameters
columnThe column index (horizontal position) to set, must be less than OLED_COLUMN_SIZE.
pageThe page index to set, must be less than OLED_ROW_SIZE/OLED_PAGE_SIZE.

This function updates the internal tracking variables column_current_position and page_current_position to the specified values and sends the corresponding commands to the OLED controller to set the memory addressing position for subsequent pixel data writes. It sends commands to set the page start address and the lower and higher nibbles of the column start address. Communication is done over the TWI interface in write mode.

Note
If the requested position exceeds display bounds, the function does nothing.
Here is the caller graph for this function:

◆ oled_scroll_vertical()

void oled_scroll_vertical ( unsigned char scroll)

Scrolls the OLED display vertically by a specified offset.

Parameters
scrollThe number of pixel rows to offset the display vertically. Must be less than OLED_ROW_SIZE to be valid.

This function adjusts the vertical display offset by sending the appropriate command and data to the OLED controller via TWI interface. It effectively shifts the visible area of the display vertically by the specified number of pixel rows, creating a scrolling effect.

Note
If the scroll value is equal to or exceeds the maximum row size, the function does nothing.

Variable Documentation

◆ column_current_position

unsigned char column_current_position

◆ EEMEM

const unsigned char oled_init_commands [] EEMEM
Initial value:
=
{
( 0xAE | 0x00 ),
0xA8 ,
0x3F ,
0xD3 ,
0x00 ,
(0x40 | 0x00 ),
(0xA0 | 0x01 ),
(0xC0 | 0x08 ),
0xDA ,
( 0x12 | 0x02 ),
0x81 ,
0x7F ,
(0xA4 | 0x00 ),
(0xA6 | 0x00 ),
0xD5 ,
( 0x80 | 0x00 ),
0x20 ,
0x02 ,
0x8D ,
0x14 ,
( 0xAE | 0x01 )
}

◆ page_current_position

unsigned char page_current_position