Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Change colors to RGB and partial flush for ILI9488 display #3135

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mikmog
Copy link
Contributor

@mikmog mikmog commented Mar 20, 2025

Description

Change colors in native Ili9488 display driver

  • Adjust colors to RGB instead of BGR.
  • Corrupted screen when using partial flush.

How Has This Been Tested?

  • Tested on ESP S3 Wroom 1 and a cheap Chinese 4" ili9488 display

Screenshots

IMG_8077
IMG_8075

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the color ordering so that display output now renders using proper RGB hues for more accurate and vibrant visuals.
  • Refactor
    • Enhanced the drawing routine to map display areas more precisely, ensuring a smoother and more reliable graphics experience.

@nfbot
Copy link
Member

nfbot commented Mar 20, 2025

Hi @mikmog,

😯 I'm afraid you'll have to use the PR template like the rest of us...
Make sure you've used the template and have include all the required information and fill in the appropriate details. After doing that feel free to reopen the PR. If you have questions we are here to help..

Copy link

coderabbitai bot commented Mar 20, 2025

Walkthrough

The changes update the graphics display driver for the ILI9488 by modifying the pixel order and control flow in the drawing routine. The pixel coloring is now set to use an RGB format instead of BGR, and the initialization command for display function control now includes an additional parameter. Additionally, the BitBlt method has been restructured from a single loop into nested loops iterating over the height and width dimensions, with source coordinate calculations now occurring inside the inner loop.

Changes

File Summary of Changes
src/nanoFramework.Graphics/…/ILI9488_480x320_SPI.cpp - Updated enum value from MADCTL_BGR (0x08) to MADCTL_RGB (0x00) for correct pixel ordering.
- Modified SendCommand in display initialization to accept 4 parameters instead of 3.
- Refactored the BitBlt method from a single loop to nested loops (height and width) with source coordinate computation inside the inner loop.

Sequence Diagram(s)

sequenceDiagram
    participant BitBlt
    participant OuterLoop
    participant InnerLoop
    participant PixelCalc
    participant Display

    BitBlt->>OuterLoop: Begin loop over height
    OuterLoop->>InnerLoop: Begin loop over width
    InnerLoop->>PixelCalc: Calculate srcX and srcY
    PixelCalc->>Display: Extract and convert pixel data
    Display-->>InnerLoop: Return processed pixel
    InnerLoop-->>OuterLoop: Complete inner loop iteration
    OuterLoop-->>BitBlt: Complete outer loop iteration
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a96713 and 40118bd.

📒 Files selected for processing (1)
  • src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ST_NUCLEO64_F091RC)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALX)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALTHREE)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (4)
src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp (4)

90-90: Approve BGR to RGB color format change

This change modifies the pixel color format from BGR to RGB (Blue-Green-Red to Red-Green-Blue), which addresses the color inversion issue mentioned in the PR objectives. The change effectively swaps the red and blue color channels in the display output.


175-175: Approve color format change in all orientations

The MADCTL_BGR flag has been consistently replaced with MADCTL_RGB across all four display orientations, ensuring the correct color representation regardless of how the display is oriented.

Also applies to: 181-181, 187-187, 195-195


291-324: Approve BitBlt method restructuring

The BitBlt method has been significantly improved by:

  1. Restructuring from a single loop to nested loops (y-outer, x-inner)
  2. Calculating source coordinates properly within the inner loop
  3. Implementing better buffer management with overflow checks

This change directly addresses the screen corruption issue during partial flush operations mentioned in the PR objectives. The nested loop approach ensures correct pixel mapping when performing partial screen updates.


143-143:

✅ Verification successful

Verify Display_Function_Control parameter count

The command now sends 4 parameters instead of 3. This change appears to be part of the fix for the ILI9488 display, but the datasheet should be consulted to confirm this is correct.


🌐 Web query:

ILI9488 Display_Function_Control command parameters

💡 Result:

The Display_Function_Control command (hex code 0xB6) for the ILI9488 TFT controller configures display orientation, interface settings, and scanning modes. Based on available documentation and implementation examples, the parameters are structured as follows:


Command Parameters

The command requires three bytes of configuration data:

  1. Scan Direction and Color Order

    • Bit 7: 0 (reserved)
    • Bits 6-5: Scan direction control (e.g., 00 for left-to-right, top-to-bottom)
    • Bits 4-3: Color order (e.g., 10 for BGR or 11 for RGB)
    • Bits 2-0: 000 (reserved)

    Example: 0x02 sets horizontal refresh order and BGR color mode[3][9].

  2. Gate Driver Arrangement

    • Bit 7: Gate driver scan direction (0 = top-to-bottom, 1 = bottom-to-top)
    • Bits 6-4: 000 (reserved)
    • Bit 3: Enable/disable reverse scanning of gate output
    • Bits 2-0: 010 (default)[2][3].
  3. Number of Gate Lines and Inversion

    • Bits 7-6: Set number of gate lines (e.g., 11 for 480 lines)
    • Bit 5: Select inversion mode (0 = column inversion, 1 = line inversion)
    • Bits 4-0: 1011 (default)[3][13].

Example Configurations

Use Case Parameters (Hex) Description
Default SPI Setup 0x02, 0x02, 0x3B Horizontal refresh with BGR color, 480 lines, line inversion[3][9].
Parallel Interface 0x08, 0x82, 0x27 Vertical refresh with RGB color, gate driver reverse scanning[2][5].
Custom Orientation Adjust bits 6-5 in first byte Modify scan direction and color order[13][15].

Implementation Notes

  • Library Dependence: Adafruit_ILI9341 and TFT_eSPI libraries often require modification of the ILI9488_Init.h file to match hardware configurations[1][9][15].
  • Code Snippet:
    // Example using SPI
    writecommand(0xB6); // Display Function Control
    writedata(0x02);
    writedata(0x02);
    writedata(0x3B);
  • Voltage Compatibility: Ensure logic levels match the ILI9488’s 3.3V requirement[4][10].

For custom configurations, consult the ILI9488 datasheet to adjust parameters for scan direction, color depth, and inversion modes[13][16].

Citations:


Command Parameter Count Verified as Correct

The Display_Function_Control command (0xB6) for the ILI9488 requires three configuration data bytes. In our code, the call

g_DisplayInterface.SendCommand(4, Display_Function_Control, 0x02, 0x02, 0x3B);

sends a total of 4 bytes—one command byte and three parameter bytes—which is consistent with the datasheet. No changes are necessary.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nfbot
Copy link
Member

nfbot commented Mar 20, 2025

Hi @mikmog,

😯 I'm afraid you'll have to use the PR template like the rest of us...
Make sure you've used the template and have include all the required information and fill in the appropriate details. After doing that feel free to reopen the PR. If you have questions we are here to help..

@mikmog mikmog changed the title Fix Invert colors and partial flush for ILI9488 display Fix Change colors to RGB and partial flush for ILI9488 display Mar 20, 2025
@nfbot
Copy link
Member

nfbot commented Mar 20, 2025

Hi @mikmog,

😯 I'm afraid you'll have to use the PR template like the rest of us...
Make sure you've used the template and have include all the required information and fill in the appropriate details. After doing that feel free to reopen the PR. If you have questions we are here to help..

@nfbot
Copy link
Member

nfbot commented Mar 20, 2025

@mikmog there are issues with the code style on the source files.
A PR was submitted with the code style fixes. Please click mikmog#1, review the changes if you want and merge it.

Make sure to follow the project code style. Check the details here on how it works and the tools required to help you with that.

@nfbot
Copy link
Member

nfbot commented Mar 20, 2025

Hi @mikmog,

😯 I'm afraid you'll have to use the PR template like the rest of us...
Make sure you've used the template and have include all the required information and fill in the appropriate details. After doing that feel free to reopen the PR. If you have questions we are here to help..

@alberk8
Copy link
Contributor

alberk8 commented Mar 21, 2025

I don't think Blue-Green-Red or Red-Green-Blue pixel color should be changed in the code like this. We need a way to change it from the managed code as there are panels with BGR and RGB in existence with the same controller chip.

@mikmog
Copy link
Contributor Author

mikmog commented Mar 21, 2025

I don't think Blue-Green-Red or Red-Green-Blue pixel color should be changed in the code like this. We need a way to change it from the managed code as there are panels with BGR and RGB in existence with the same controller chip.

I agree. A way to override or configure the MADCTL_* from managed side sounds sound. But I'm not sure how to proceed. Should the ili9488 be added as a generic driver on managed side?

Currently since using the ili9488 is a custom build anyway (I've updated GRAPHICS_DISPLAY in CMake to ILI9488). An alternative is to just merge the partial flush fix stuff. And make MADCTL_BGR/MADCTL_RGB configurable in code/driver native side

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

Successfully merging this pull request may close these issues.

3 participants