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

Exponential backoff for timeout and Rotation functionality. #8

Merged
merged 7 commits into from
Jan 15, 2025

Conversation

kolupaev
Copy link
Contributor

@kolupaev kolupaev commented Jan 2, 2025

Hi,

Was using your library for M5EPD, and it worked perfectly, except 2 minor features:

  • Frequent timeouts on screen busy-wait, along with, I believe, free-rtos freezes
  • Functionality to rotate the screen

Anyhow, here is a pull request. I've tried to minimize modifications to the public interfaces, however to prevent extra copying needed to make some. However I don't think it will break any code.

I took liberty to add a bit more logging to simplify debugging, which is disabled by default (via log-max-level).

Rotation itself ported from M5EPD driver (see https://github.com/m5stack/M5EPD/blob/main/src/M5EPD_Driver.cpp#L368 )

Example use:

    let epd: M5Display = IT8951::new_with_mcs(
        display_interface,
        Config::default(),
        MemoryConverterSetting {
            rotation: it8951::memory_converter_settings::MemoryConverterRotation::Rotate90,
            ..Default::default()
        },
    )
    .init(2300)
    .expect("Unable to initialize display");

    let refresh_box = { 
      // Use as normal via embedded_graphics
      // fill_contiguous is rotated automatically by it8951 controller
    };
    // refresh_box is rotated by driver code 
    display.display_area(refresh_box)?;
    

Code is tested on M5EPD (0, and 90 rotation), and works as expected.

For M5EPD display often times out on big operations. This mitigates it by setting it configurable.

Additionaly, I beleive EpsDelay implementation does busy-loop uncinditionally, however esp_idf_svc::hal::delay::Delay
conditionally flips to FreeRtos task based delay, once delay interval is past tick threshold.

Adding exponential backoff here, enables other tasks in free-rtos proceed on longer waits.
Allows to draw on a rotated screen.

Images passed in load_image_area are rotated by the controller
automatically, while display_area calls perform rotation via software
for consumer convinience.

Tested on M5EPD, rotated 90 degrees.
@pbert519
Copy link
Owner

pbert519 commented Jan 2, 2025

Hi,

rotation is a great feature, thanks for implementing.

We do have timeout issues on the busy wait too, but no solution yet. (on esp32c3 with esp32-hal)
From my initial analysis, it looks like the IT8951 itself freezes.
A possible next step would be to do a full compare of all communication against a working c-library, but time :(
For our usecase, a full reset of the it8951 is enough.

I'll not be able to test your code till next thursday.

The CI shows some clippy warnings, could you fix them?

@kolupaev
Copy link
Contributor Author

kolupaev commented Jan 2, 2025

We do have timeout issues on the busy wait too, but no solution yet. (on esp32c3 with esp32-hal)
From my initial analysis, it looks like the IT8951 itself freezes.

Interesting, never noticed that on mine, sleep/wakeup cycle works fine as well. However, at times takes up to ~600ms.

I (1273) app::hardware: Initializing display
I (1276) gpio: GPIO[27]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1700) it8951::interface: Total delay ~335800 us
I (2129) it8951::interface: Total delay ~6200 us
I (2133) app::hardware: Initialized display: DevInfo { panel_width: 960, panel_height: 540, memory_address: 1193696, firmware_version: "5mtsca_k.v.0\01", lut_version: "M841\0T" }
I (2566) it8951::interface: Total delay ~340600 us
I (3422) it8951::interface: Total delay ~6200 us
I (3426) it8951::interface: Total delay ~3000 us
I (3430) it8951::interface: Total delay ~3000 us
...
I (7640) app::ui: Screen powered down, awaiting change
I (7861) it8951::interface: Total delay ~151800 us
I (7862) app::ui: Display awakened
I (7938) app::ui: Complete draw Rectangle { top_left: Point { x: 192, y: 251 }, size: Size { width: 208, height: 32 } }
I (7939) app::ui: Refreshing Rectangle { top_left: Point { x: 192, y: 251 }, size: Size { width: 208, height: 32 } }
I (7958) it8951::interface: Total delay ~6200 us
I (7962) it8951::interface: Total delay ~3000 us
I (7963) it8951::interface: Total delay ~600 us
I (8817) it8951::interface: Total delay ~679800 us
I (8818) app::ui: Screen powered down, awaiting change

The CI shows some clippy warnings, could you fix them?

Completely missed that clippy exists, thanks, fixed.

Copy link
Owner

@pbert519 pbert519 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall i dont think exposing MemoryConverterSettings as whole is a good approach for the normal embedded_graphics user.
It allows the user of the API to set random values for e.g. endians and bit per pixel, and the impl for embedded_graphics does not check if the settings are correctly set.

Instead we should provide a dedicated rotation setting.

src/lib.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/interface.rs Outdated Show resolved Hide resolved
@pbert519
Copy link
Owner

pbert519 commented Jan 10, 2025 via email

@pbert519
Copy link
Owner

Looks good.
If you could run cargo fmt to make the CI happy, i will merge your changes.

@kolupaev
Copy link
Contributor Author

Thanks, pushed a commit with format-fix.

@kolupaev kolupaev requested a review from pbert519 January 15, 2025 03:51
@pbert519 pbert519 merged commit a004023 into pbert519:main Jan 15, 2025
6 checks passed
@pbert519
Copy link
Owner

Many thanks for your contribution.
I created a new release 0.4.2 with your changes, which is available on crates.io.

@kolupaev
Copy link
Contributor Author

Happy to help!
thank you for the library to begin with :)

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.

2 participants