Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include <stdio.h> #define ST7789_CLK 21 #define ST7789_DATA 22 #define ST7789_RST 27 // active low #define ST7789_CS 26 // active low #define ST7789_DC 25 // 1=data, 0=cmd #define DATA_MODE gpio_set_level(ST7789_DC, 1); #define CMD_MODE gpio_set_level(ST7789_DC, 0); // TFT LCD 76x284 // 4-wire SPI with DCX #include <driver/gpio.h> #include <spi_bus.h> inline void wait(const uint16_t ms) { vTaskDelay(pdMS_TO_TICKS(ms)); } void st7789_init(spi_bus_device_handle_t dev); void st7789_setAddrWindow(spi_bus_device_handle_t dev, uint16_t x, uint16_t y, uint16_t w, uint16_t h); void app_main(void) { gpio_reset_pin(ST7789_DC); gpio_reset_pin(ST7789_RST); gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT); // hw reset gpio_set_level(ST7789_RST, 1); wait(1); gpio_set_level(ST7789_RST, 0); wait(1); gpio_set_level(ST7789_RST, 1); spi_bus_handle_t bus_hdl = {0}; spi_bus_device_handle_t dev = {0}; spi_config_t bus_cfg = {.mosi_io_num = ST7789_DATA, .miso_io_num = -1, .sclk_io_num = ST7789_CLK, .max_transfer_sz = 1}; spi_device_config_t st7789_cfg = { .cs_io_num = ST7789_CS, .mode = 0, .clock_speed_hz = SPI_MASTER_FREQ_10M}; bus_hdl = spi_bus_create(SPI3_HOST, &bus_cfg); if (!bus_hdl) { printf("SPI bus error: Cannot create SPI bus\n"); exit(-1); } dev = spi_bus_device_create(bus_hdl, &st7789_cfg); if (!dev) { printf("SPI bus error: Cannot create SPI device\n"); exit(-1); } // <---perform SPI here---> st7789_init(dev); CMD_MODE spi_bus_transfer_byte(dev, 0x2C, NULL); // memory write DATA_MODE for (uint8_t i = 0; i < 25; i++) { for (uint8_t j = 0; j < 25; j++) { // fill 25x25 area with 0xAAAA spi_bus_transfer_byte(dev, 0xAA, NULL); spi_bus_transfer_byte(dev, 0xAA, NULL); } } CMD_MODE // <---endregion---> spi_bus_device_delete(&dev); spi_bus_delete(&bus_hdl); } void st7789_init(spi_bus_device_handle_t dev) { spi_bus_transfer_byte(dev, 0x01, NULL); // sw reset wait(10); spi_bus_transfer_byte(dev, 0x26, NULL); // set gamma DATA_MODE spi_bus_transfer_byte(dev, 0x01, NULL); // gamma 2.2 CMD_MODE spi_bus_transfer_byte(dev, 0x36, NULL); // memory data access control DATA_MODE spi_bus_transfer_byte(dev, 0x00, NULL); // 000000_xxb - normal mode CMD_MODE spi_bus_transfer_byte(dev, 0x3A, NULL); // pixel format DATA_MODE spi_bus_transfer_byte(dev, 0x26, NULL); // 0_101_0_101 - 65K@16bit CMD_MODE spi_bus_transfer_byte(dev, 0xB0, NULL); // RAM control DATA_MODE spi_bus_transfer_byte(dev, 0x00, NULL); // RAM access from MCU spi_bus_transfer_byte(dev, 0xCA, NULL); // RAM LE+MSB CMD_MODE spi_bus_transfer_byte(dev, 0xB2, NULL); // porch settings DATA_MODE spi_bus_transfer_byte(dev, 0x0C, NULL); spi_bus_transfer_byte(dev, 0x0C, NULL); spi_bus_transfer_byte(dev, 0x00, NULL); spi_bus_transfer_byte(dev, 0x33, NULL); spi_bus_transfer_byte(dev, 0x33, NULL); CMD_MODE spi_bus_transfer_byte(dev, 0xB7, NULL); // gate control DATA_MODE spi_bus_transfer_byte(dev, 0x45, NULL); // 13.65-10.43V CMD_MODE spi_bus_transfer_byte(dev, 0x2B, NULL); // VCOM DATA_MODE spi_bus_transfer_byte(dev, 0x2B, NULL); // 1.175V CMD_MODE spi_bus_transfer_byte(dev, 0xC0, NULL); // LCM DATA_MODE spi_bus_transfer_byte(dev, 0x2C, NULL); // XBGR, XMX, XMH CMD_MODE spi_bus_transfer_byte(dev, 0xC2, NULL); // VDV and VRH DATA_MODE spi_bus_transfer_byte(dev, 0x01, NULL); // VDV and VRH from CMD wire spi_bus_transfer_byte(dev, 0xFF, NULL); // always FFh CMD_MODE spi_bus_transfer_byte(dev, 0xC3, NULL); // VRH DATA_MODE spi_bus_transfer_byte(dev, 0x11, NULL); // 4.4+V CMD_MODE spi_bus_transfer_byte(dev, 0xC4, NULL); // VDV DATA_MODE spi_bus_transfer_byte(dev, 0x20, NULL); // 0V CMD_MODE spi_bus_transfer_byte(dev, 0xC6, NULL); // framerate control DATA_MODE spi_bus_transfer_byte(dev, 0x0F, NULL); // 60Hz CMD_MODE spi_bus_transfer_byte(dev, 0xD0, NULL); // power control DATA_MODE spi_bus_transfer_byte(dev, 0xA4, NULL); // always A4h spi_bus_transfer_byte(dev, 0xA1, NULL); // 6.8V, -4.8V, 2.3V CMD_MODE spi_bus_transfer_byte(dev, 0xE0, NULL); // positive voltage gamma control DATA_MODE spi_bus_transfer_byte(dev, 0xD0, NULL); spi_bus_transfer_byte(dev, 0x00, NULL); spi_bus_transfer_byte(dev, 0x05, NULL); spi_bus_transfer_byte(dev, 0x0E, NULL); spi_bus_transfer_byte(dev, 0x15, NULL); spi_bus_transfer_byte(dev, 0x0D, NULL); spi_bus_transfer_byte(dev, 0x37, NULL); spi_bus_transfer_byte(dev, 0x43, NULL); spi_bus_transfer_byte(dev, 0x47, NULL); spi_bus_transfer_byte(dev, 0x09, NULL); spi_bus_transfer_byte(dev, 0x15, NULL); spi_bus_transfer_byte(dev, 0x12, NULL); spi_bus_transfer_byte(dev, 0x16, NULL); spi_bus_transfer_byte(dev, 0x19, NULL); CMD_MODE spi_bus_transfer_byte(dev, 0xE0, NULL); // negative voltage gamma control DATA_MODE spi_bus_transfer_byte(dev, 0xD0, NULL); spi_bus_transfer_byte(dev, 0x00, NULL); spi_bus_transfer_byte(dev, 0x05, NULL); spi_bus_transfer_byte(dev, 0x0D, NULL); spi_bus_transfer_byte(dev, 0x0C, NULL); spi_bus_transfer_byte(dev, 0x06, NULL); spi_bus_transfer_byte(dev, 0x2D, NULL); spi_bus_transfer_byte(dev, 0x44, NULL); spi_bus_transfer_byte(dev, 0x40, NULL); spi_bus_transfer_byte(dev, 0x0E, NULL); spi_bus_transfer_byte(dev, 0x1C, NULL); spi_bus_transfer_byte(dev, 0x18, NULL); spi_bus_transfer_byte(dev, 0x16, NULL); spi_bus_transfer_byte(dev, 0x19, NULL); CMD_MODE spi_bus_transfer_byte(dev, 0x11, NULL); // sleep out wait(5); spi_bus_transfer_byte(dev, 0x29, NULL); // display on spi_bus_transfer_byte(dev, 0x13, NULL); // normal display on spi_bus_transfer_byte(dev, 0x21, NULL); // inv on /*spi_bus_transfer_byte(dev, 0x2A, NULL); // column addr set DATA_MODE spi_bus_transfer_byte(dev, 0x00, NULL); // XS[15:8] spi_bus_transfer_byte(dev, 0x00, NULL); // XS[7:0] spi_bus_transfer_byte(dev, 0x00, NULL); // XE[15:8] spi_bus_transfer_byte(dev, 0x00, NULL); // XE[7:0] CMD_MODE spi_bus_transfer_byte(dev, 0x2B, NULL); // row addr set DATA_MODE spi_bus_transfer_byte(dev, 0x00, NULL); // YS[15:8] spi_bus_transfer_byte(dev, 0x00, NULL); // YS[7:0] spi_bus_transfer_byte(dev, 0x00, NULL); // YE[15:8] spi_bus_transfer_byte(dev, 0x00, NULL); // YE[7:0] CMD_MODE*/ st7789_setAddrWindow(dev, 0, 0, 76, 284); } void st7789_setAddrWindow(spi_bus_device_handle_t dev, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { const uint16_t xs = x; const uint16_t xe = x + w; const uint16_t ys = y; const uint16_t ye = y + h; CMD_MODE spi_bus_transfer_byte(dev, 0x2A, NULL); // column addr set DATA_MODE spi_bus_transfer_byte(dev, xs >> 8, NULL); // XS[15:8] spi_bus_transfer_byte(dev, xs & 0xff, NULL); // XS[7:0] spi_bus_transfer_byte(dev, xe >> 8, NULL); // XE[15:8] spi_bus_transfer_byte(dev, xe & 0xff, NULL); // XE[7:0] CMD_MODE spi_bus_transfer_byte(dev, 0x2B, NULL); // row addr set DATA_MODE spi_bus_transfer_byte(dev, ys >> 8, NULL); // YS[15:8] spi_bus_transfer_byte(dev, ys & 0xff, NULL); // YS[7:0] spi_bus_transfer_byte(dev, ye >> 8, NULL); // Ye[15:8] spi_bus_transfer_byte(dev, ye & 0xff, NULL); // Ye[7:0] CMD_MODE }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
56 min ago | 0.52 KB
P4IGNORE for Unreal Development
1 hour ago | 2.10 KB
Untitled
1 hour ago | 13.08 KB
Matthew Quote
2 hours ago | 0.18 KB
Input_AOC
6 hours ago | 18.01 KB
Untitled
19 hours ago | 13.15 KB
Analog GPUs: THE FUTURE
1 day ago | 8.88 KB
Quotes I believe to be true.
1 day ago | 0.16 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!