tinygo-org / drivers

TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
622 stars 196 forks source link

ssd1306: Add function `SetFlip` and `GetFlip` #702

Closed notpop closed 3 months ago

notpop commented 3 months ago

Implementation of the Flip Functions

Hello, I am new to contributing to OSS, so I apologize in advance if there are any mistakes.

What I did

I added a Flip functions to the ssd1306 driver.

Background

While playing with ssd1306, I wanted to flip the display, but I found that there was no method implemented for it. I had to directly execute commands within the application. Thus, I thought it would be helpful to implement this functionality in the driver itself.

Why I didn't extend SetRotation

Initially, I thought it would be best to integrate the flip functionality into SetRotation to align with the other existing implementations. However, I found that implementing 90° and 270° rotations is quite challenging. To help clarify my point, please refer to the images below:

From my current understanding, it seems that the ssd1306 hardware does not support these kinds of rotation features directly, so a more complex implementation would be required. However, I believe that even just implementing the flip functionality is useful, so I decided to start with this.

Thank you for your time and consideration.

deadprogram commented 3 months ago

I think we would be better off with SetRotation like other displays instead of adding another API. The implementation could return an error if you tried to set to a currently unsupported rotation for a particular display.

notpop commented 3 months ago

Thank you for your feedback. Based on your suggestions, I have revised the SetRotation function.

deadprogram commented 3 months ago

Thank you for making the changes @notpop looks good to me.

I changed the branch for this PR to dev as discussed here: https://github.com/tinygo-org/drivers/blob/release/CONTRIBUTING.md#how-to-use-our-github-repository

@sago35 or anyone else have any comments before I squash/merge?

deadprogram commented 3 months ago

Thank you @notpop and @sago35