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
604 stars 188 forks source link

fix(ssd1351): Fix mirrored text on OLED display #418

Closed tonygilkerson closed 2 years ago

tonygilkerson commented 2 years ago

Having issue with mirrored text on my OLED display. Setup summary:

The issue is in the ssd1351 configure method, the SET_REMAP_COLORDEPH is set to 0x72(see), but it should be 0x62

The problem

The issue is with the fourth bit which controls the scan direction. Each bit of the SET_REMAP_COLORDEPH does something different according to page 32 of this ssd1351 data sheet. For the current setting 0x72 we can see that bit-4 is 1 which tells the device to scan backwards.

0x72 = 0b01110010
            |   |
            |   └── bit 0
            └──---- bit 4 - set to 1, scan backwards 

# from ssd1351 data sheet
0 - Scan from COM0 to COM[N –1] [reset]
1 - Scan from COM[N-1] to COM0. Where N is the Multiplex ratio.

The Fix

The fix was to set bit 4 to zero, i.e. set 0x62 as the correct value.

0x62 = 0b01100010
            |   |
            |   └── bit 0
            └──---- bit 4 - set to 0, scan forward

To test this on my display I added the following two lines after calling configure and it works.

display.Command(ssd1351.SET_REMAP_COLORDEPTH)
display.Data(0x62)
deadprogram commented 2 years ago

Great research on this @tonygilkerson now merging.