Skip to content

drivers/display/ssd1306.py upside_down static method added #5160

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

Closed
wants to merge 2 commits into from

Conversation

stroobandt
Copy link

The added upside_down static method causes the contents to be rendered with a 180° rotation.
If a display is to be run upside down, this method must be called prior to instantiating a Writer for this display.
This particular OLED command sequence was originally discussed here.

A similar static method only works for the Cwriter class.

The added `upside_down` static method causes the contents to be rendered with a 180° rotation.
If a display is to be run upside down, this method must be called prior to instantiating a `Writer` for this display.
This particular OLED command sequence was originally discussed [here](https://digistump.com/board/index.php?topic=1669.0).

A similar static method [only works for the `Cwriter` class](https://github.com/peterhinch/micropython-font-to-py/blob/master/writer/WRITER.md#221-static-method).
@stroobandt stroobandt changed the title drivers/display/ssd1306.py drivers/display/ssd1306.py upside_down static method added Sep 29, 2019
@mcauser
Copy link
Contributor

mcauser commented Sep 30, 2019

If you have a boolean argument, rotation can be toggled.

    def rotated(self, rotated=True):
        self.write_cmd(SET_SEG_REMAP | (rotated & 1))
        self.write_cmd(SET_COM_OUT_DIR | ((rotated & 1) << 3))

@mcauser
Copy link
Contributor

mcauser commented Sep 30, 2019

Or if you want to be able to toggle either the segment or common ordering independently:

    def remap(self, seg=True, com=True):
        self.write_cmd(SET_SEG_REMAP | (seg & 1))
        self.write_cmd(SET_COM_OUT_DIR | ((com & 1) << 3))

Which will give you: rotate 0 deg, mirror-x, mirror-y and rotate 180 deg.

@stroobandt
Copy link
Author

stroobandt commented Sep 30, 2019

@mcauser I would then be in favour of adding separate mirror-x and mirror-y static methods as well. This would keep things easy and self-evident for the casual programmer.
seg, com, and even rotated are not very descriptive terms.
Remember, there are also kids learning with Micropython.

@mcauser
Copy link
Contributor

mcauser commented Oct 1, 2019

Hi @stroobandt
seg is short for Set Segment Re-map - 10.1.8 in the datasheet
com is short for Set COM Output Scan Direction - 10.1.14 in the datasheet
They can be used to control how the data written to the display driver is interpreted and shown.
Not the most novice friendly names, I agree. That's just what they are called in the datasheet.

There's a whole bunch more functionality this display supports which is not exposed in this driver.
Given this is a simple driver which is built into some ports, I'd go with a minimal implementation.
It's not obvious that mirror-x + mirror-y == rotate 180 deg either.

Changing the com output direction updates immediately on the display, but remapping the segments only affects new data that is written to the display, adding to novice confusion.

Perhaps it should be added to init_display() instead, as most, I'm assuming, would set the rotation once on init, then never rotate it at runtime. Same applies for setting the start address (for different size displays) and addressing mode (which has to match the framebuf mode).

@stroobandt
Copy link
Author

@mcauser Dear Mike, I entirely agree with you that setting this during the initialisation of the display is the safest thing to do. However, the init_display() method belongs to the SSD1306 super class. In practice, this method is never directly used by the programmer.

I would rather propose adding a named upside_down=False parameter to the initialisation method of the following child classes:

class SSD1306_I2C(SSD1306):
     def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False, upside_down=False):
         …

class SSD1306_SPI(SSD1306):
    def __init__(self, width, height, spi, dc, res, cs, external_vcc=False, upside_down=False):
        …

How do I proceed further?
Do I close this pull request and create a new one, or can I still change this one?

@mcauser
Copy link
Contributor

mcauser commented Oct 1, 2019

You could just add another commit, or update your existing commit with an --amend.
No need for a new PR. The PR is tied to your branch, so you can rewrite it as many times as you want and force push when you're done.

@mcauser
Copy link
Contributor

mcauser commented May 14, 2021

Display rotation was implemented in PR #7135

tannewt added a commit to tannewt/circuitpython that referenced this pull request Aug 18, 2021
Removed default UART, SPI and I2C from Tiny2040 config
@dpgeorge
Copy link
Member

As mentioned above, rotation was implemented in 9eea51b and it looks like that is more general than the patch here. So closing.

@dpgeorge dpgeorge closed this Nov 30, 2021
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.

3 participants