-
Notifications
You must be signed in to change notification settings - Fork 10
+ TFT attempts to bug-fix #7
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
base: main
Are you sure you want to change the base?
Conversation
DnCraptor
commented
Oct 14, 2025
- small improvements
Summary of ChangesHello @DnCraptor, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request implements "bug-fixes" and "small improvements" primarily centered around the TFT display functionality. The core change introduces a user-configurable inversion setting for TFT displays, which is integrated into the system's persistent configuration and accessible through the menu. This involves refactoring the display initialization logic, adjusting CMake build options, and modifying the application's startup sequence to properly apply display settings and handle reboots when inversion is changed. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces several changes to fix bugs and improve TFT display support. The main change is refactoring the display inversion handling from a compile-time macro to a runtime setting, which is a good improvement for user experience. The PR also includes a critical fix for a buffer overflow when initializing the palette.
My review focuses on a few areas for improvement:
- There's a significant issue with a redefined
RGB888macro that could lead to incorrect colors. - The new runtime inversion logic seems incomplete for ILI9341 displays.
- Some minor issues include a magic number, a variable naming style inconsistency, and a typo in a UI string.
Overall, the changes are positive, but the identified issues, especially the macro redefinition and incomplete ILI9341 logic, should be addressed to ensure correctness and maintainability.
| #ifdef ILI9341 | ||
| // ILI9341 | ||
| #ifdef INVERSION | ||
| // ILI9341: переворот и инверсия цветов | ||
| 2, 0, 0x36, MADCTL_MY | MADCTL_MX | MADCTL_ROW_COLUMN_EXCHANGE | MADCTL_BGR_PIXEL_ORDER, // flip + BGR | ||
| #else | ||
| 2, 0, 0x36, MADCTL_ROW_COLUMN_EXCHANGE | MADCTL_BGR_PIXEL_ORDER, // Set MADCTL | ||
| #endif | ||
| #else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactoring from a compile-time INVERSION macro to a runtime variable seems incomplete for the ILI9341 display. The #ifdef INVERSION block will now always take the #else path since the INVERSION macro is no longer defined. This means display flipping for ILI9341 is now disabled and cannot be enabled at runtime. The INVERSION variable is also not used to control the MADCTL register setting for ILI9341.
To fix this, you'll need to dynamically construct the init_seq array or parts of it based on the INVERSION variable's value. Since init_seq is a const array, you cannot modify it. One approach is to remove const, making it a mutable local array, and then set the MADCTL parameter for the 0x36 command based on the INVERSION variable before calling lcd_init().
| #ifndef RGB888 | ||
| #define RGB888(r, g, b) (((r) << 16) | ((g) << 8 ) | (b)) | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding #ifndef prevents a compilation error, it introduces a more subtle issue. The RGB888 macro is also defined in drivers/st7789/st7789.h to perform a 24-bit to 16-bit color conversion. When TFT is enabled, graphics.h includes st7789.h, and due to this #ifndef, the 16-bit conversion macro from st7789.h is used everywhere RGB888 is called. This is problematic in files like src/main.cpp, where NesPalette888 is initialized with RGB888 and expects 24-bit color values, not 16-bit. This can lead to incorrect colors.
A better approach is to have uniquely named macros for different functionalities. I recommend the following changes:
- In
drivers/st7789/st7789.h, renameRGB888to something likeRGB888_TO_565. - In
drivers/st7789/st7789.c, update thetextmode_paletteinitialization to use the new macro name. - In this file (
drivers/graphics/graphics.h), you can then safely defineRGB888for 24-bit color without the#ifndefguard.
This will make the code clearer and prevent subtle color bugs.
| #define MADCTL_ROW_COLUMN_EXCHANGE (1<<5) | ||
| #define MADCTL_COLUMN_ADDRESS_ORDER_SWAP (1<<6) | ||
|
|
||
| uint8_t INVERSION = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using all-caps for a variable name like INVERSION can be misleading, as this convention is typically reserved for constants and macros. To improve clarity and adhere to common C/C++ style, consider renaming it to g_inversion to denote its global scope, or simply inversion. This would require updating its extern declaration and all usages across the project.
| #else | ||
| // ST7789 | ||
| // 2, 0, 0x36, MADCTL_COLUMN_ADDRESS_ORDER_SWAP | MADCTL_ROW_COLUMN_EXCHANGE, // Set MADCTL | ||
| 2, 0, 0x36, MADCTL_COLUMN_ADDRESS_ORDER_SWAP | 32, // Set MADCTL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the magic number 32 reduces code readability. It's better to use the MADCTL_ROW_COLUMN_EXCHANGE macro, which is defined in this file and represents the same value (1 << 5). This makes the code self-documenting and easier to maintain.
2, 0, 0x36, MADCTL_COLUMN_ADDRESS_ORDER_SWAP | MADCTL_ROW_COLUMN_EXCHANGE, // Set MADCTL| #endif | ||
| #if TFT | ||
| { "" }, | ||
| { "Investion %s", ARRAY, &settings.inversion, nullptr, 1, { "NO ", "YES" } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.