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

Implement async for lcd_cam i8080 #1834

Merged
merged 14 commits into from
Jul 29, 2024
Merged

Conversation

liebman
Copy link
Contributor

@liebman liebman commented Jul 18, 2024

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

Implement async i8080

Testing

new HIL tests
Local Hub75 application

@liebman
Copy link
Contributor Author

liebman commented Jul 18, 2024

One issue is that I8080::new() takes the TX part of a channel and this does not carry the Async marker and that means that there is no way prove that the TX channel passed is appropriate. The quick fix would be to have I8080::new() take the entire Channel.

@Dominaezzz
Copy link
Collaborator

I've had this one in my mental backlog but I'm glad someone else has gotten to it first.

I love that you've kept the blocking method around even when the driver is in "async" mode, so the new send_dma_async is like an optional extra.

One issue is that I8080::new() takes the TX part of a channel and this does not carry the Async marker and that means that there is no way prove that the TX channel passed is appropriate. The quick fix would be to have I8080::new() take the entire Channel.

When it comes to one shot DMA transfers, where you provide a filled buffer upfront and you just wait for the transfer to finish. You don't actually need an async DMA channel (and should probably avoid it maybe) to make the driver async, you just need to use the peripheral's (LCD_CAM) own interrupt. LCD_TRANS_DONE or something like this.
Some other drivers in the hal (like SPI) asynchronously wait for the DMA to finish, then blockingly drain the peripheral's FIFO, which is undesirable (I'm drafting a PR to fix it).
You can avoid that problem here by just using the LCD_CAM's interrupts directly.
(The channel async marker is more useful for circular transfers)

Since the LCD_CAM only has one interrupt handler (shared between the LCD and Camera), you'll have to move the new_async method up to the LcdCam struct and decide the async-ness there. I imagine the struct would look like this.

struct LcdCam<'d, DM> {
    lcd: Lcd<'d, DM>,
    cam: Cam<'d>,
}

I'm not too sure what to do with the shared INT_ENA register but since there's no set_interrupt_handler method on the LcdCam, I think you can skip the use of a critical section for now. Whoever adds async support to the Camera driver can worry about that 🙂.

@liebman
Copy link
Contributor Author

liebman commented Jul 21, 2024

Maybe we can do something similar to the way interrupts are handled in gpio::IO?

@Dominaezzz
Copy link
Collaborator

You mean the bit about allowing the user to setup their own handler even in async mode?

Copy link
Collaborator

@Dominaezzz Dominaezzz left a comment

Choose a reason for hiding this comment

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

Code looks great!

esp-hal/src/lcd_cam/lcd/i8080.rs Outdated Show resolved Hide resolved
esp-hal/src/lcd_cam/mod.rs Outdated Show resolved Hide resolved
esp-hal/src/lcd_cam/lcd/i8080.rs Outdated Show resolved Hide resolved
@liebman
Copy link
Contributor Author

liebman commented Jul 21, 2024

You mean the bit about allowing the user to setup their own handler even in async mode?

Yes and this could extend to a by default implementation that creates seperate handlers for Camera and Lcd.

@Dominaezzz
Copy link
Collaborator

You mean the bit about allowing the user to setup their own handler even in async mode?

Yes and this could extend to a by default implementation that creates seperate handlers for Camera and Lcd.

My only qualm against it is having to come up with some kind of contract about what the user handler is allowed to do.
i.e. Don't clear x interrupt bits, don't disable the interrupt, etc.
I also worry about the contract changing (the hal isn't stable yet) in such a way that users don't notice their interrupt handler is now broken after upgrading the hal in their Cargo.toml.
And also #1525 which I think could use more Send consideration.

I'd rather this sort of thing wait until the interrupt story in the HAL is more fleshed out.

@liebman
Copy link
Contributor Author

liebman commented Jul 21, 2024

I added tests to make sure that:

  • a blocking i8080 works with a blocking DMA channel
  • a blocking i8080 works with an async DMA channel
  • an async i8080 works with a blocking DMA channel
  • an async i8080 works with an async DMA channel

When the TX and RX parts of a DMA channel carry the Mode then this can be removed and we can enforce Blocking with Blocking and Async with Async.

@liebman liebman marked this pull request as ready for review July 24, 2024 15:41
Copy link
Collaborator

@Dominaezzz Dominaezzz left a comment

Choose a reason for hiding this comment

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

LGTM

Ideally send_dma_async should call self.tear_down_send() if the future it returns is cancelled but this hal in general doesn't support cancellation so I consider this optional.

Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

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

LGTM - I don't have the HW for it but maybe would be worth to at least re-test the blocking implementation example (@JurajSadel ?)

For the future would be good to have a way to have more checks in the test but at least we test it's not freezing or crashing the system

Copy link
Contributor

@JurajSadel JurajSadel left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@JurajSadel JurajSadel added this pull request to the merge queue Jul 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 29, 2024
@liebman
Copy link
Contributor Author

liebman commented Jul 29, 2024

rebased and update for ReadBuffer change

Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

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

Thanks!

@liebman
Copy link
Contributor Author

liebman commented Jul 29, 2024

Looks like the CI failure was a timeout to api.github.com

@jessebraham jessebraham added this pull request to the merge queue Jul 29, 2024
Merged via the queue into esp-rs:main with commit 67bb6c5 Jul 29, 2024
18 checks passed
@liebman liebman deleted the lcd-i8080-async branch July 29, 2024 14:19
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.

5 participants