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

Add SSD1309 Device using non-traditional SPI #2316

Merged
merged 5 commits into from
Aug 22, 2024

Conversation

AdamJSchofield
Copy link
Contributor

@AdamJSchofield AdamJSchofield commented May 20, 2024

Adds support for SSD1309 displays such as this one. Datasheet for the SSD1309 available here.

These transparent displays have many potential applications but the coolest is mini volumetric displays like this one (not my video).

Implementation Notes:

  • This display supports I2C and SPI. The SPI implementation suggested here uses additional GPIO pins for DC (Data/Command) and RST (Reset) as described in the datasheet.
  • When the DC pin is pulled LOW, data read into the command buffer of the driver. When the DC pin is pulled HIGH, data will be written to display memory.
  • Cycling the RST pin from HIGH -> LOW -> HIGH will reset the display.
  • A new PreRenderBitmap method was added to the base Ssd13xx class. This is useful because it may not always be desired to send frames to the display immediately. An example of this is the simulation I included which uses one thread to buffer/render display-ready frames and another to send them to the display at a fixed rate. Obviously this only works for multi-core boards.

Sample Notes:
Included is a sample simulation for falling sand. It looks pretty cool on the transparent OLED I tested with. My 4-core RaspberryPi Zero 2 was able to maintain 45 FPS without dropping frames. Rendering to a SkiaSharp bitmap is the bottleneck. Much faster speeds are possible with a large buffer or by using a 2D byte-array as the render state instead of drawing to a BitmapImage.

If desired, a PreRenderBitmap method could be added to the GraphicDisplay base class allowing for the Ssd1309Simulation class to be extended for many other displays.

Microsoft Reviewers: Open in CodeFlow

@AdamJSchofield
Copy link
Contributor Author

@dotnet-policy-service agree

{
Span<byte> commandBytes = command?.GetBytes();

_gpioController?.Write(_dc, PinValue.Low);
Copy link
Contributor Author

@AdamJSchofield AdamJSchofield May 20, 2024

Choose a reason for hiding this comment

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

The main difference between this and the existing I2C implementation is that the DC pin is set to LOW for commands and HIGH for data. The SSD1306 with I2C uses a control byte here.

@joperezr joperezr requested a review from pgrawehr May 30, 2024 16:01
@joperezr
Copy link
Member

@AdamJSchofield I noticed you marked this as work in progress and it is still a draft. Is this ready for review though? Is there anything we can do to help making it ready for review?

@AdamJSchofield
Copy link
Contributor Author

@AdamJSchofield I noticed you marked this as work in progress and it is still a draft. Is this ready for review though? Is there anything we can do to help making it ready for review?

Hi! I have since got it working and am putting together a final draft of the PR with a working example in the samples project for RaspberryPi boards. I hit a small snag last night but I expect I'll be able to push that up and mark it ready for review in the next few days.

I'm also happy to close this PR/issue and open a new one when its actually ready if that helps you all stay organized. I jumped the gun a bit but I've since worked out most of the kinks. I may do that anyway since the nature of the PR will be more of a contribution with documentation and less of a cry for help 😆

@joperezr
Copy link
Member

Great to hear you have got it working now! No need to close this PR, we just need to mark it ready for review once you are ready, and then we can jump and take a peek 😃

@AdamJSchofield AdamJSchofield marked this pull request as ready for review June 3, 2024 23:53
@AdamJSchofield
Copy link
Contributor Author

Hi @joperezr @pgrawehr - I've marked this as ready for review. Let me know what you think!

Copy link
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

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

Thanks for the addition! couple of comments in a very quick review

src/devices/Ssd13xx/Ssd1309.cs Outdated Show resolved Hide resolved
src/devices/Ssd13xx/Ssd1309.cs Show resolved Hide resolved
src/devices/Ssd13xx/Ssd13xx.cs Outdated Show resolved Hide resolved
src/devices/Ssd13xx/samples/Program.cs Outdated Show resolved Hide resolved
@Ellerbach
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- Move SPI sample to separate sample project
- Add sample ./deployToPi.ps1 script
- Make SpiDevice internal and a property on Ssd13xx class
Copy link
Contributor

@pgrawehr pgrawehr left a comment

Choose a reason for hiding this comment

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

Just a few questions left.

Sorry I forgot that I was assigned to this PR. Nice work!

src/devices/Ssd13xx/Ssd1306.cs Show resolved Hide resolved
_rstGpioPin.Write(PinValue.Low);
Thread.Sleep(100);
_rstGpioPin.Write(PinValue.High);
Thread.Sleep(100);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be useful to call Initialize() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method was intended to just execute the specific sequence to reset the controller according to the datasheet. But practically, it could be useful to include other reset-related tasks. Calling Reset and then Initialize separately in a "re-initialization" procedure feels more intuitive to me personally, but I can see advantages to both.

@pgrawehr
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@joperezr joperezr added this to the v3.3.0 milestone Aug 15, 2024
@pgrawehr
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pgrawehr pgrawehr merged commit 376398a into dotnet:main Aug 22, 2024
10 checks passed
@pgrawehr
Copy link
Contributor

@AdamJSchofield Thanks for this contribution

@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants