Skip to content

Conversation

tonuonu
Copy link

@tonuonu tonuonu commented Jul 19, 2025

User description

Fixes issue #10765 where last line of OLED shown garbage.


PR Type

Bug fix


Description

This description is generated by an AI tool. It may have inaccuracies

  • Fixed OLED display garbage on last line

  • Improved page-by-page clearing method for all 8 pages

  • Added proper address reset after clearing operation


Diagram Walkthrough

flowchart LR
  A["Old Method"] --> B["Single loop 1024 iterations"]
  C["New Method"] --> D["8 pages loop"]
  D --> E["128 columns per page"]
  E --> F["Proper address reset"]
  B --> G["Garbage on last line"]
  F --> H["Clean display"]
Loading

File Walkthrough

Relevant files
Bug fix
display_ug2864hsweg01.c
Fix OLED clear function page addressing                                   

src/main/drivers/display_ug2864hsweg01.c

  • Replaced single 1024-iteration loop with proper 8-page clearing
  • Added page-by-page addressing for complete display coverage
  • Added address reset commands after clearing operation
  • Improved code comments for clarity
+18/-9   

Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
⚡ Recommended focus areas for review

Addressing Mode

The code sets horizontal addressing mode but then uses page addressing commands. This mixed addressing approach may not work correctly on all OLED controllers and could cause display issues.

i2c_OLED_send_cmd(0x20);              // Set Memory Addressing Mode
i2c_OLED_send_cmd(0x00);              // Set Memory Addressing Mode to Horizontal addressing mode

// Clear all 8 pages (0-7)
for (uint8_t page = 0; page < 8; page++) {
    i2c_OLED_send_cmd(0xb0 + page);   // set page address
Missing Command

The original code included display start line register command (0x40) which was removed. This command may be necessary for proper display initialization and its removal could affect display behavior.

void i2c_OLED_clear_display(void)
{
    i2c_OLED_send_cmd(0xa6);              // Set Normal Display
    i2c_OLED_send_cmd(0xae);              // Display OFF
    i2c_OLED_send_cmd(0x20);              // Set Memory Addressing Mode
    i2c_OLED_send_cmd(0x00);              // Set Memory Addressing Mode to Horizontal addressing mode

    // Clear all 8 pages (0-7)
    for (uint8_t page = 0; page < 8; page++) {
        i2c_OLED_send_cmd(0xb0 + page);   // set page address
        i2c_OLED_send_cmd(0x00);          // set low col address to 0
        i2c_OLED_send_cmd(0x10);          // set high col address to 0

        for (uint8_t col = 0; col < 128; col++) {
            i2c_OLED_send_byte(0x00);      // clear
        }
    }

    i2c_OLED_send_cmd(0xb0);              // Reset to page 0
    i2c_OLED_send_cmd(0x00);              // Reset low col address to 0
    i2c_OLED_send_cmd(0x10);              // Reset high col address to 0

    i2c_OLED_send_cmd(0x81);              // Setup CONTRAST CONTROL
    i2c_OLED_send_cmd(200);               // Contrast value
    i2c_OLED_send_cmd(0xaf);              // Display ON
}

Copy link

qodo-merge-pro bot commented Jul 19, 2025

PR Code Suggestions ✨

No code suggestions found for the PR.

@tonuonu
Copy link
Author

tonuonu commented Jul 19, 2025

There is also PR #10760 which in my opinion is not fixing root cause and possibly overwrites something wrong.

- Changed from horizontal (0x00) to page addressing mode (0x02) to match the page-by-page clearing approach
- Restored the display start line command (0x40) that was missing from the previous commit
- This ensures proper OLED initialization and prevents garbage on the last line
@tonuonu
Copy link
Author

tonuonu commented Jul 20, 2025

Fixed @qodo-merge-pro valid concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant