Skip to content

Commit 0b3466e

Browse files
Melissa LeBlanc-WilliamsMelissa LeBlanc-Williams
Melissa LeBlanc-Williams
authored and
Melissa LeBlanc-Williams
committed
Added HX8357 Display Support
1 parent 404f4e3 commit 0b3466e

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

adafruit_rgb_display/hx8357.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_rgb_display.hx8357`
24+
====================================================
25+
26+
A simple driver for the HX8357-based displays.
27+
28+
* Author(s): Melissa LeBlanc-Williams
29+
"""
30+
from micropython import const
31+
from adafruit_rgb_display.rgb import DisplaySPI
32+
33+
__version__ = "0.0.0-auto.0"
34+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git"
35+
36+
_SWRESET = const(0x01)
37+
_SLPOUT = const(0x11)
38+
_NORON = const(0x13)
39+
_INVOFF = const(0x20)
40+
_INVON = const(0x21)
41+
_DISPOFF = const(0x28)
42+
_DISPON = const(0x29)
43+
_CASET = const(0x2a)
44+
_PASET = const(0x2b)
45+
_RAMWR = const(0x2c)
46+
_RAMRD = const(0x2e)
47+
_TEON = const(0x35)
48+
_MADCTL = const(0x36)
49+
_COLMOD = const(0x3a)
50+
_TEARLINE = const(0x44)
51+
_SETOSC = const(0xb0)
52+
_SETPWR1 = const(0xb1)
53+
_SETRGB = const(0xb3)
54+
_SETCYC = const(0xb4)
55+
_SETCOM = const(0xb6)
56+
_SETC = const(0xb9)
57+
_SETSTBA = const(0xc0)
58+
_SETPANEL = const(0xcc)
59+
_SETGAMMA = const(0xe0)
60+
61+
class HX8357(DisplaySPI):
62+
"""
63+
A simple driver for the HX8357-based displays.
64+
65+
>>> import busio
66+
>>> import digitalio
67+
>>> import board
68+
>>> from adafruit_rgb_display import color565
69+
>>> import adafruit_rgb_display.hx8357 as hx8357
70+
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
71+
>>> display = hx8357.HX8357(spi, cs=digitalio.DigitalInOut(board.GPIO0),
72+
... dc=digitalio.DigitalInOut(board.GPIO15))
73+
>>> display.fill(0x7521)
74+
>>> display.pixel(64, 64, 0)
75+
"""
76+
_COLUMN_SET = _CASET
77+
_PAGE_SET = _PASET
78+
_RAM_WRITE = _RAMWR
79+
_RAM_READ = _RAMRD
80+
_INIT = (
81+
(_SWRESET, None),
82+
(_SETC, b'\xFF\x83\x57'),
83+
(_SETRGB, b'\x80\x00\x06\x06'), # 0x80 enables SDO pin (0x00 disables)
84+
(_SETCOM, b'\x25'), # -1.52V
85+
(_SETOSC, b'\x68'), # Normal mode 70Hz, Idle mode 55 Hz
86+
(_SETPANEL, b'\x05'), # BGR, Gate direction swapped
87+
(_SETPWR1, b'\x00\x15\x1C\x1C\x83\xAA'), # Not deep standby BT VSPR VSNR AP
88+
(_SETSTBA, b'\x50\x50\x01\x3C\x1E\x08'), # OPON normal OPON idle STBA GEN
89+
(_SETCYC, b'\x02\x40\x00\x2A\x2A\x0D\x78'), # NW 0x02 RTN DIV DUM DUM GDON GDOFF
90+
(_SETGAMMA, b'\x02\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x02\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x00\x01'),
91+
(_COLMOD, b'\x55'), # 16 bit
92+
(_MADCTL, b'\xc0'),
93+
(_TEON, b'\x00'),
94+
(_TEARLINE, b'\x00\x02'), # TW off
95+
(_SLPOUT, None),
96+
(_MADCTL, b'\xa0'),
97+
(_DISPON, None),
98+
)
99+
_ENCODE_PIXEL = ">H"
100+
_ENCODE_POS = ">HH"
101+
102+
#pylint: disable-msg=useless-super-delegation, too-many-arguments
103+
def __init__(self, spi, dc, cs, rst=None, width=480, height=320,
104+
baudrate=16000000, polarity=0, phase=0):
105+
super().__init__(spi, dc, cs, rst, width, height,
106+
baudrate=baudrate, polarity=polarity, phase=phase)

examples/rgbdisplay_hx8357test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Quick test of 3.5" TFT FeatherWing (HX8357) with Feather M0 or M4
2+
# This will work even on a device running displayio
3+
# Will fill the TFT black and put a red pixel in the center, wait 2 seconds,
4+
# then fill the screen blue (with no pixel), wait 2 seconds, and repeat.
5+
import time
6+
import random
7+
import digitalio
8+
import board
9+
import displayio
10+
11+
from adafruit_rgb_display.rgb import color565
12+
import adafruit_rgb_display.hx8357 as hx8357
13+
14+
displayio.release_displays()
15+
16+
# Configuration for CS and DC pins (these are TFT FeatherWing defaults):
17+
cs_pin = digitalio.DigitalInOut(board.D9)
18+
dc_pin = digitalio.DigitalInOut(board.D10)
19+
20+
# Config for display baudrate (default max is 24mhz):
21+
BAUDRATE = 24000000
22+
23+
# Setup SPI bus using hardware SPI:
24+
spi = board.SPI()
25+
26+
# Create the HX8357 display:
27+
display = hx8357.HX8357(spi, cs=cs_pin, dc=dc_pin, baudrate=BAUDRATE)
28+
29+
# Main loop:
30+
while True:
31+
# Fill the screen red, green, blue, then black:
32+
for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255)):
33+
display.fill(color565(color))
34+
# Clear the display
35+
display.fill(0)
36+
# Draw a red pixel in the center.
37+
display.pixel(display.width//2, display.height//2, color565(255, 0, 0))
38+
# Pause 2 seconds.
39+
time.sleep(2)
40+
# Clear the screen a random color
41+
display.fill(color565(random.randint(0, 255),
42+
random.randint(0, 255),
43+
random.randint(0, 255)))
44+
# Pause 2 seconds.
45+
time.sleep(2)

0 commit comments

Comments
 (0)