Fix bug in st7735r144_4bit.py. SSD1351 drivers no longer set baudrate to 20MHz: seems too fast despite datasheet.

pull/8/head
Peter Hinch 2020-12-16 14:29:15 +00:00
rodzic f259ee068f
commit 186cef1d7a
7 zmienionych plików z 35 dodań i 41 usunięć

Wyświetl plik

@ -122,19 +122,18 @@ soft SPI may be used but hard may be faster.
* `pinrs` An initialised output pin. Initial value should be 1. * `pinrs` An initialised output pin. Initial value should be 1.
* `height=128` Display dimensions in pixels. Height must be 96 or 128. * `height=128` Display dimensions in pixels. Height must be 96 or 128.
* `width=128` * `width=128`
* `init_spi=spi_init` This optional arg enables flexible options in * `init_spi=False` This optional arg enables flexible options in configuring
configuring the SPI bus. The default preserves existing behaviour: the SPI bus the SPI bus. The default assumes exclusive access to the bus with
is initialised to 20MHz before each use. Other `spi.init` args are default. `color_setup.py` initialising it. Those settings will be left in place. If a
This facilitates bus sharing. Passing `False` disables this: `color_setup.py` callback function is passed, it will be called prior to each SPI bus write:
must initialise the bus. Those settings will be left in place. If a callback this is for shared bus applications. The callback will receive a single arg
function is passed, it will be called prior to each SPI bus write: this is for being the SPI bus instance. In normal use it will be a one-liner or lambda
shared bus applications where a non-standard `init` is required. The callback initialising the bus. A minimal example is this function:
will receive a single arg being the SPI bus instance. In normal use it will be
a one-liner or lambda initialising the bus. The default is this function:
```python ```python
def spi_init(spi): def spi_init(spi):
spi.init(baudrate=20_000_000) # Data sheet: should support 20MHz spi.init(baudrate=20_000_000) # Data sheet: should support 20MHz
``` ```
Despite the datasheet I failed to get this baudrate to work even on a PCB.
#### A "gotcha" in the datasheet #### A "gotcha" in the datasheet

Wyświetl plik

@ -3,31 +3,41 @@
# Released under the MIT License (MIT). See LICENSE. # Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2020 Peter Hinch # Copyright (c) 2020 Peter Hinch
# As written, supports: # Pin nos. match my PCB for all displays.
# As written with commented-out lines, supports:
# Adafruit 1.5" 128*128 OLED display: https://www.adafruit.com/product/1431 # Adafruit 1.5" 128*128 OLED display: https://www.adafruit.com/product/1431
# Adafruit 1.27" 128*96 display https://www.adafruit.com/product/1673 # Adafruit 1.27" 128*96 display https://www.adafruit.com/product/1673
# Adfruit 1.8" 128*160 Color TFT LCD display https://www.adafruit.com/product/358
# Adfruit 1.44" 128*128 Color TFT LCD display https://www.adafruit.com/product/2088
# Edit the driver import for other displays. # Edit the driver import for other displays.
# WIRING (Adafruit pin nos and names). # WIRING (Adafruit pin nos and names).
# ESP SSD # ESP SSD
# 3v3 Vin (10) # 3v3 Vin (10)
# Gnd Gnd (11) # Gnd Gnd (11)
# IO25 DC (3 DC) # IO27 DC (3 DC)
# IO26 CS (5 OC OLEDCS) # IO25 CS (5 OC OLEDCS)
# IO27 Rst (4 R RESET) # IO26 Rst (4 R RESET)
# IO14 CLK (2 CL SCK) Hardware SPI1 # IO14 CLK (2 CL SCK) Hardware SPI1
# IO13 DATA (1 SI MOSI) # IO13 DATA (1 SI MOSI)
from machine import SPI, Pin from machine import SPI, Pin
import gc import gc
from drivers.ssd1351.ssd1351_generic import SSD1351 as SSD #from drivers.ssd1351.ssd1351_generic import SSD1351 as SSD
#from drivers.st7735r.st7735r import ST7735R as SSD
#from drivers.st7735r.st7735r144 import ST7735R as SSD
from drivers.st7735r.st7735r_4bit import ST7735R as SSD
height = 128 # Ensure height is correct (96/128) height = 96 # SSD1351: ensure height is correct (96/128)
pdc = Pin(25, Pin.OUT, value=0) # Arbitrary pins pdc = Pin(27, Pin.OUT, value=0) # Arbitrary pins
pcs = Pin(26, Pin.OUT, value=1) pcs = Pin(25, Pin.OUT, value=1)
prst = Pin(27, Pin.OUT, value=1) prst = Pin(26, Pin.OUT, value=1)
# Hardware SPI on native pins for performance # Hardware SPI on native pins for performance. Check DRIVERS.md for optimum baudrate.
spi = SPI(1, 10_000_000, sck=Pin(14), mosi=Pin(13), miso=Pin(12), init_spi=False) spi = SPI(1, 10_000_000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
gc.collect() gc.collect()
ssd = SSD(spi, pcs, pdc, prst, height=height) # ssd = SSD(spi, pcs, pdc, prst, height=height) # Must specify height for SSD1351
ssd = SSD(spi, pcs, pdc, prst) # The other Adafruit displays use defaults
# On st7735r 1.8 inch display can exchange height and width for portrait mode. See docs.
# The 1.44 inch display is symmetrical so this doesn't apply.

Wyświetl plik

@ -17,11 +17,6 @@ import gc
import micropython import micropython
from uctypes import addressof from uctypes import addressof
# ESP32 produces 20MHz, Pyboard D SF2W: 15MHz, SF6W: 18MHz, Pyboard 1.1: 10.5MHz
# OLED datasheet: should support 20MHz
def spi_init(spi):
spi.init(baudrate=20_000_000)
# Timings with standard emitter # Timings with standard emitter
# 1.86ms * 128 lines = 240ms. copy dominates: show() took 272ms # 1.86ms * 128 lines = 240ms. copy dominates: show() took 272ms
# Buffer transfer time = 272-240 = 32ms which accords with expected: # Buffer transfer time = 272-240 = 32ms which accords with expected:
@ -85,7 +80,7 @@ class SSD1351(framebuf.FrameBuffer):
def rgb(r, g, b): def rgb(r, g, b):
return (r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6) return (r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6)
def __init__(self, spi, pincs, pindc, pinrs, height=128, width=128, init_spi=spi_init): def __init__(self, spi, pincs, pindc, pinrs, height=128, width=128, init_spi=False):
if height not in (96, 128): if height not in (96, 128):
raise ValueError('Unsupported height {}'.format(height)) raise ValueError('Unsupported height {}'.format(height))
self.spi = spi self.spi = spi

Wyświetl plik

@ -20,11 +20,6 @@ from uctypes import addressof
# The ESP32 does not work reliably in SPI mode 1,1. Waveforms look correct. # The ESP32 does not work reliably in SPI mode 1,1. Waveforms look correct.
# Now using 0,0 on STM and ESP32 # Now using 0,0 on STM and ESP32
# ESP32 produces 20MHz, Pyboard D SF2W: 15MHz, SF6W: 18MHz, Pyboard 1.1: 10.5MHz
# OLED datasheet: should support 20MHz
def spi_init(spi):
spi.init(baudrate=20_000_000) # Data sheet: should support 20MHz
# Initialisation commands in cmd_init: # Initialisation commands in cmd_init:
# 0xfd, 0x12, 0xfd, 0xb1, # Unlock command mode # 0xfd, 0x12, 0xfd, 0xb1, # Unlock command mode
# 0xae, # display off (sleep mode) # 0xae, # display off (sleep mode)
@ -54,7 +49,7 @@ class SSD1351(framebuf.FrameBuffer):
def rgb(r, g, b): def rgb(r, g, b):
return ((r & 0xf8) << 5) | ((g & 0x1c) << 11) | (b & 0xf8) | ((g & 0xe0) >> 5) return ((r & 0xf8) << 5) | ((g & 0x1c) << 11) | (b & 0xf8) | ((g & 0xe0) >> 5)
def __init__(self, spi, pincs, pindc, pinrs, height=128, width=128, init_spi=spi_init): def __init__(self, spi, pincs, pindc, pinrs, height=128, width=128, init_spi=False):
if height not in (96, 128): if height not in (96, 128):
raise ValueError('Unsupported height {}'.format(height)) raise ValueError('Unsupported height {}'.format(height))
self.spi = spi self.spi = spi

Wyświetl plik

@ -77,7 +77,7 @@ class SSD1351(framebuf.FrameBuffer):
def rgb(r, g, b): def rgb(r, g, b):
return (r & 0xf8) << 5 | (g & 0x1c) << 11 | (g & 0xe0) >> 5 | (b & 0xf8) return (r & 0xf8) << 5 | (g & 0x1c) << 11 | (g & 0xe0) >> 5 | (b & 0xf8)
def __init__(self, spi, pincs, pindc, pinrs, height=128, width=128, init_spi=spi_init): def __init__(self, spi, pincs, pindc, pinrs, height=128, width=128, init_spi=False):
if height not in (96, 128): if height not in (96, 128):
raise ValueError('Unsupported height {}'.format(height)) raise ValueError('Unsupported height {}'.format(height))
self.spi = spi self.spi = spi

Wyświetl plik

@ -23,11 +23,6 @@ import sys
# The ESP32 does not work reliably in SPI mode 1,1. Waveforms look correct. # The ESP32 does not work reliably in SPI mode 1,1. Waveforms look correct.
# Now using 0,0 on STM and ESP32 # Now using 0,0 on STM and ESP32
# ESP32 produces 20MHz, Pyboard D SF2W: 15MHz, SF6W: 18MHz, Pyboard 1.1: 10.5MHz
# OLED datasheet: should support 20MHz
def spi_init(spi):
spi.init(baudrate=20_000_000) # Data sheet: should support 20MHz
# Timings with standard emitter # Timings with standard emitter
# 1.86ms * 128 lines = 240ms. copy dominates: show() took 272ms # 1.86ms * 128 lines = 240ms. copy dominates: show() took 272ms
# Buffer transfer time = 272-240 = 32ms which accords with expected: # Buffer transfer time = 272-240 = 32ms which accords with expected:
@ -72,7 +67,7 @@ class SSD1351(framebuf.FrameBuffer):
def rgb(r, g, b): def rgb(r, g, b):
return (r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6) return (r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6)
def __init__(self, spi, pincs, pindc, pinrs, height=128, width=128, init_spi=spi_init): def __init__(self, spi, pincs, pindc, pinrs, height=128, width=128, init_spi=False):
if height not in (96, 128): if height not in (96, 128):
raise ValueError('Unsupported height {}'.format(height)) raise ValueError('Unsupported height {}'.format(height))
self.spi = spi self.spi = spi

Wyświetl plik

@ -49,7 +49,7 @@ class ST7735R(framebuf.FrameBuffer):
# Same mapping in linebuf so LS byte is shifted out 1st # Same mapping in linebuf so LS byte is shifted out 1st
@staticmethod @staticmethod
def rgb(r, g, b): def rgb(r, g, b):
return (b & 0xf8) << 5 | (g & 0x1c) << 11 | (g & 0xe0) >> 5 | (r & 0xf8) return (r & 0xf8) << 5 | (g & 0x1c) << 11 | (g & 0xe0) >> 5 | (b & 0xf8)
# rst and cs are active low, SPI is mode 0 # rst and cs are active low, SPI is mode 0
def __init__(self, spi, cs, dc, rst, height=128, width=128, init_spi=False): def __init__(self, spi, cs, dc, rst, height=128, width=128, init_spi=False):