kopia lustrzana https://github.com/peterhinch/micropython-nano-gui
Fix bug in st7735r144_4bit.py. SSD1351 drivers no longer set baudrate to 20MHz: seems too fast despite datasheet.
rodzic
f259ee068f
commit
186cef1d7a
17
DRIVERS.md
17
DRIVERS.md
|
@ -122,19 +122,18 @@ soft SPI may be used but hard may be faster.
|
|||
* `pinrs` An initialised output pin. Initial value should be 1.
|
||||
* `height=128` Display dimensions in pixels. Height must be 96 or 128.
|
||||
* `width=128`
|
||||
* `init_spi=spi_init` This optional arg enables flexible options in
|
||||
configuring the SPI bus. The default preserves existing behaviour: the SPI bus
|
||||
is initialised to 20MHz before each use. Other `spi.init` args are default.
|
||||
This facilitates bus sharing. Passing `False` disables this: `color_setup.py`
|
||||
must initialise the bus. Those settings will be left in place. If a callback
|
||||
function is passed, it will be called prior to each SPI bus write: this is for
|
||||
shared bus applications where a non-standard `init` is required. The callback
|
||||
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:
|
||||
* `init_spi=False` This optional arg enables flexible options in configuring
|
||||
the SPI bus. The default assumes exclusive access to the bus with
|
||||
`color_setup.py` initialising it. Those settings will be left in place. If a
|
||||
callback function is passed, it will be called prior to each SPI bus write:
|
||||
this is for shared bus applications. The callback will receive a single arg
|
||||
being the SPI bus instance. In normal use it will be a one-liner or lambda
|
||||
initialising the bus. A minimal example is this function:
|
||||
```python
|
||||
def spi_init(spi):
|
||||
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
|
||||
|
||||
|
|
|
@ -3,31 +3,41 @@
|
|||
# Released under the MIT License (MIT). See LICENSE.
|
||||
# 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.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.
|
||||
|
||||
# WIRING (Adafruit pin nos and names).
|
||||
# ESP SSD
|
||||
# 3v3 Vin (10)
|
||||
# Gnd Gnd (11)
|
||||
# IO25 DC (3 DC)
|
||||
# IO26 CS (5 OC OLEDCS)
|
||||
# IO27 Rst (4 R RESET)
|
||||
# IO27 DC (3 DC)
|
||||
# IO25 CS (5 OC OLEDCS)
|
||||
# IO26 Rst (4 R RESET)
|
||||
# IO14 CLK (2 CL SCK) Hardware SPI1
|
||||
# IO13 DATA (1 SI MOSI)
|
||||
|
||||
from machine import SPI, Pin
|
||||
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
|
||||
pcs = Pin(26, Pin.OUT, value=1)
|
||||
prst = Pin(27, Pin.OUT, value=1)
|
||||
# Hardware SPI on native pins for performance
|
||||
spi = SPI(1, 10_000_000, sck=Pin(14), mosi=Pin(13), miso=Pin(12), init_spi=False)
|
||||
pdc = Pin(27, Pin.OUT, value=0) # Arbitrary pins
|
||||
pcs = Pin(25, Pin.OUT, value=1)
|
||||
prst = Pin(26, Pin.OUT, value=1)
|
||||
# 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))
|
||||
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.
|
||||
|
|
|
@ -17,11 +17,6 @@ import gc
|
|||
import micropython
|
||||
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
|
||||
# 1.86ms * 128 lines = 240ms. copy dominates: show() took 272ms
|
||||
# Buffer transfer time = 272-240 = 32ms which accords with expected:
|
||||
|
@ -85,7 +80,7 @@ class SSD1351(framebuf.FrameBuffer):
|
|||
def rgb(r, g, b):
|
||||
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):
|
||||
raise ValueError('Unsupported height {}'.format(height))
|
||||
self.spi = spi
|
||||
|
|
|
@ -20,11 +20,6 @@ from uctypes import addressof
|
|||
# The ESP32 does not work reliably in SPI mode 1,1. Waveforms look correct.
|
||||
# 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:
|
||||
# 0xfd, 0x12, 0xfd, 0xb1, # Unlock command mode
|
||||
# 0xae, # display off (sleep mode)
|
||||
|
@ -54,7 +49,7 @@ class SSD1351(framebuf.FrameBuffer):
|
|||
def rgb(r, g, b):
|
||||
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):
|
||||
raise ValueError('Unsupported height {}'.format(height))
|
||||
self.spi = spi
|
||||
|
|
|
@ -77,7 +77,7 @@ class SSD1351(framebuf.FrameBuffer):
|
|||
def rgb(r, g, b):
|
||||
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):
|
||||
raise ValueError('Unsupported height {}'.format(height))
|
||||
self.spi = spi
|
||||
|
|
|
@ -23,11 +23,6 @@ import sys
|
|||
# The ESP32 does not work reliably in SPI mode 1,1. Waveforms look correct.
|
||||
# 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
|
||||
# 1.86ms * 128 lines = 240ms. copy dominates: show() took 272ms
|
||||
# Buffer transfer time = 272-240 = 32ms which accords with expected:
|
||||
|
@ -72,7 +67,7 @@ class SSD1351(framebuf.FrameBuffer):
|
|||
def rgb(r, g, b):
|
||||
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):
|
||||
raise ValueError('Unsupported height {}'.format(height))
|
||||
self.spi = spi
|
||||
|
|
|
@ -49,7 +49,7 @@ class ST7735R(framebuf.FrameBuffer):
|
|||
# Same mapping in linebuf so LS byte is shifted out 1st
|
||||
@staticmethod
|
||||
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
|
||||
def __init__(self, spi, cs, dc, rst, height=128, width=128, init_spi=False):
|
||||
|
|
Ładowanie…
Reference in New Issue