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 sh1106 driver and update docs and create config sample #48

Merged
merged 2 commits into from
Feb 13, 2023

Conversation

freemansoft
Copy link
Contributor

@freemansoft freemansoft commented Feb 12, 2023

Adding sh driver from https://github.com/robert-hh/SH1106 along with sample program and doc updates. Passes the monochrome tests.

This is based on the monochrome driver similar to the ssd1306.

  • Trailing spaces aren't required in the README for lists (bullet or numbered). It would be great if the README file didn't rely on 2 trailing spaces on some lines for formatting.
  • Tested with the monochrome samples - looks good
  • The rgb settings were copied from the SSD1306 driver but I don't know if they are correct.

Note
The SH1106 driver fails when called from color examples. There is a commit note on the SSD1306 that says it was made compatible with color (as gray scale) but I dont' understand how that works. I implemented the same rgb() function but the cwriter fails.

@freemansoft freemansoft mentioned this pull request Feb 13, 2023
@peterhinch
Copy link
Owner

The rgb method is non-critical. It merely converts and RGB tuple into a single bit for monochrome rendering. Colors in the demos are mainly saturated so they will render in white. Colors with low RGB values will render as black. The cause of the problem is elsewhere.

I think I've allowed the development of nano-gui to get ahead of the monochrome drivers. Please could you try the following, to see if this enables the color demos to work. Add this line to the imports:

from drivers.boolpalette import BoolPalette

In the constructor save the framebuffer mode (either MONO_HMSB or MONO_VLSB depending on rotation) and add the line

self.palette = BoolPalette(mode)

I think this will enable the color demos to work, but if not please show me any error traceback.

The driver looks as if it took a good deal of effort to write. Congratulations!

Copy link
Owner

@peterhinch peterhinch left a comment

Choose a reason for hiding this comment

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

Please see my suggestions in the conversation section.

@freemansoft
Copy link
Contributor Author

Added the BoolPallete changes to sh1106.py and the aclock demo now runs. It provides the expected boundry exceeded messages because the display is 128x64

This shows the new initializer section containing refs to BoolPalette

        if self.rotate90:
            # decouple renderbuf and displaybuf
            self.displaybuf = bytearray(self.bufsize)
            # HMSB is required to keep the bit order in the render buffer
            # compatible with byte-for-byte remapping to the display buffer,
            # which is in VLSB. Else we'd have to copy bit-by-bit!
            mode = framebuf.MONO_HMSB
            self.palette = BoolPalette(mode)
            super().__init__(self.renderbuf, self.height, self.width, mode)
        else:
            self.displaybuf = self.renderbuf
            mode = framebuf.MONO_VLSB
            self.palette = BoolPalette(mode)
            super().__init__(self.renderbuf, self.width, self.height, mode)

Tested with

	1. cp -r drivers /pyboard
	2. cp -r gui /pyboard
	3. cp setup_examples/sh1106_spi_pico.py /pyboard/color_setup.py
	4. 
	5. repl ~ import gui.demos.aclock
	6. repl ~ import gui.demos.mono_test

I wish I could take credit for the driver but it actually came from the location at the top of the file.

@peterhinch peterhinch merged commit f970a95 into peterhinch:master Feb 13, 2023
@peterhinch
Copy link
Owner

Excellent, thank you.

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