Skip to content

Conversation

@tannewt
Copy link
Member

@tannewt tannewt commented Mar 25, 2020

It was fixed as 0/0 even though it used to get it from the current
SPI state. This makes it more explicit with kwargs.

Thanks to magpie_lark and kmatocha on the Adafruit Support forum
for finding the issue: https://forums.adafruit.com/viewtopic.php?f=60&t=162515

It was fixed as 0/0 even though it used to get it from the current
SPI state. This makes it more explicit with kwargs.

Thanks to magpie_lark and kmatocha on the Adafruit Support forum
for finding the issue: https://forums.adafruit.com/viewtopic.php?f=60&t=162515
@tannewt tannewt added this to the 5.x.x - Bug Fixes milestone Mar 25, 2020
@tannewt tannewt requested a review from hierophect March 25, 2020 18:25
@kmatch98
Copy link

kmatch98 commented Mar 25, 2020

@tannewt updated the displayio.FourWire command to include options for baudrate, polarity and phase, and to fix a bug where the polarity and phase were not updated properly: https://github.com/adafruit/circuitpython/commit/ab74f45bfbed78fd752e3ed3a12c01fa910ad672

Please note that these SPI bus settings only go into effect the first time displayio goes to access the SPI bus. (Meaning that if you query the settings without accessing the bus with displayio, you will likely see just the previous settings.)

Here are the details of my setup

Hardware: ItsyBitsy M4 Express
Display: ST7789 generic 1.3" TFT 240x240 display that requires SPI Mode3 operation.

Connections:
ItsyBitsy M4 SCK -> Display SCL
ItsyBitsy M4 MO -> Display SDA
ItsyBitsy M4 Pin 12 -> Display BLK backlight
ItsyBitsy M4 Pin 10 -> Display DC
ItsyBitsy M4 Pin 9 -> Display RES reset

Display VCC and Gnd connected to 3.3V and Ground of ItsyBitsy M4.

Here is the sample code that I used. This works with a special UF2 that @tannewt created for me and will go into the pull request.

#This test will initialize the display using displayio and draw a solid green
#background, a smaller purple rectangle, and some yellow text.

import board
import busio
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_st7789 import ST7789
import time
import digitalio

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

# Release any resources currently in use for the displays
displayio.release_displays()

led.value = True
time.sleep(1)
led.value = False
time.sleep(1)
led.value = True
print("about to start")
time.sleep(1)
print("starting")

spi = board.SPI()
tft_cs = board.D5
tft_dc = board.D10
tft_backlight = board.D12

while not spi.try_lock():
    pass
#spi.configure(baudrate=1000000, polarity=1, phase=1, bits=8) # Configure SPI for 24MHz, Set polarity and phase for SPI_MODE
#spi.configure(baudrate=24000000, polarity=1, phase=1, bits=8) # Configure SPI for 24MHz, Set polarity and phase for SPI_MODE3
spi.unlock()
print("configured SPI")

display_bus = displayio.FourWire(
    spi, command=tft_dc, chip_select=tft_cs, reset=board.D9, baudrate=24000000, polarity=1, phase=1
)


print(spi.frequency)

#display = ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True)
display = ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True, backlight_pin=tft_backlight)

# Make the display context
splash = displayio.Group(max_size=10)


display.show(splash)
print(spi.frequency)

color_bitmap = displayio.Bitmap(240, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x00FF00  # Bright Green

bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)

# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(200, 200, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0xAA0088  # Purple
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
splash.append(inner_sprite)

# Draw a label
text_group = displayio.Group(max_size=10, scale=2, x=50, y=120)
text = "Hello World!"
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
text_group.append(text_area)  # Subgroup for text scaling
splash.append(text_group)

while True:
    led.value = False
    time.sleep(1)
    led.value = True
    time.sleep(1)
    print("looping")
    pass

hierophect
hierophect previously approved these changes Mar 25, 2020
Copy link
Collaborator

@hierophect hierophect left a comment

Choose a reason for hiding this comment

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

Looks good to me, I remember this issue from an STM32 settings problem where the default was "1" and never overwritten. Nice to see it more explicitly defined here.

@tannewt
Copy link
Member Author

tannewt commented Mar 27, 2020

Builds now!

@jepler jepler merged commit 54e8c63 into adafruit:master Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants