Plant Monitor SAM3X8E
Loading...
Searching...
No Matches
st7789.h File Reference

Interface for ST7789 driver. More...

#include "hal/spi.h"
#include "hal/pio.h"
#include "hal/tc.h"

Go to the source code of this file.

Macros

#define DISPLAY_WIDTH   0x00F0
#define DISPLAY_HEIGHT   0x0140
#define CS_PIN   17
#define DC_PIN   18
#define RST_PIN   19
#define NOP   0x00
#define SWRESET   0x01
#define RDDID   0x04
#define RDDST   0x09
#define RDDPM   0x0A
#define RDD_MADCTL   0x0B
#define RDD_COLMOD   0x0C
#define RDDIM   0x0D
#define RDDSM   0x0E
#define RDDSDR   0x0F
#define SLPIN   0x10
#define SLPOUT   0x11
#define PTLON   0x12
#define NORON   0x13
#define INVOFF   0x20
#define INVON   0x21
#define GAMSET   0x26
#define DISPOFF   0x28
#define DISPON   0x29
#define CASET   0x2A
#define RASET   0x2B
#define RAMWR   0x2C
#define RAMRD   0x2E
#define PTLAR   0x30
#define VSCRDEF   0x33
#define TEOFF   0x34
#define TEON   0x35
#define MADCTL   0x36
#define VSCRSADD   0x37
#define IDMOFF   0x38
#define IDMON   0x39
#define COLMOD   0x3A
#define RAMWRC   0x3C
#define RAMRDC   0x3E
#define TESCAN   0x44
#define RDTESCAN   0x45
#define WRDISBV   0x51
#define RDDISBV   0x52
#define WRCTRLD   0x53
#define RDCTRLD   0x54
#define WRCACE   0x55
#define RDCABC   0x56
#define WRCABCMB   0x5E
#define RDCABCMB   0x5F
#define RDABCSDR   0x68
#define RDID1   0xDA
#define RDID2   0xDB
#define RDID3   0xDC
#define RAMCTRL   0xB0
#define RGBCTRL   0xB1
#define PORCTRL   0xB2
#define FRCTRL1   0xB3
#define GCTRL   0xB7
#define DGMEN   0xBA
#define VCOMS   0xBB
#define LCMCTRL   0xC0
#define IDSET   0xC1
#define VDVVRHEN   0xC2
#define VRHS   0xC3
#define VDVSET   0xC4
#define VCMOFSET   0xC5
#define FRCTRL2   0xC6
#define CABCCTRL   0xC7
#define REGSEL1   0xC8
#define REGSEL2   0xCA
#define PWMFRSEL   0xCC
#define PWCTRL1   0xD0
#define VAPVANEN   0xD2
#define CMD2EN   { 0xDF, 0x5A, 0x69, 0x02 }
#define PVGAMCTRL   0xE0
#define NVGAMCTRL   0xE1
#define DGMLUTR   0xE2
#define DGMLUTB   0xE3
#define GATECTRL   0xE4
#define PWCTRL2   0xE8
#define EQCTRL   0xE9
#define PROMCTRL   0xEC
#define PROMEN   0xFA
#define NVMSET   0xFC
#define PROMACT   0xFE

Functions

void st7789_init (void)
 ST7789 initialization.
void st7789_clear (const uint16_t color)
 Clears display.
void st7789_draw_glyph (const uint16_t xs, const uint16_t ys, const uint16_t glyph_width, const uint16_t glyph_height, const uint16_t fg_color, const uint16_t bg_color, const uint8_t *bitmap_data)
 Draws a character glyph to the display.

Detailed Description

Interface for ST7789 driver.

Contains functions for initializing the display, clearing, and rendering glyphs.

Author
Vladimir Zhelev

Definition in file st7789.h.

Macro Definition Documentation

◆ CABCCTRL

#define CABCCTRL   0xC7

Definition at line 136 of file st7789.h.

◆ CASET

#define CASET   0x2A

Definition at line 93 of file st7789.h.

◆ CMD2EN

#define CMD2EN   { 0xDF, 0x5A, 0x69, 0x02 }

Definition at line 142 of file st7789.h.

◆ COLMOD

#define COLMOD   0x3A

Definition at line 105 of file st7789.h.

◆ CS_PIN

#define CS_PIN   17

GPIO pin assignments (Arduino DUE)

Definition at line 29 of file st7789.h.

◆ DC_PIN

#define DC_PIN   18

Definition at line 30 of file st7789.h.

◆ DGMEN

#define DGMEN   0xBA

Definition at line 127 of file st7789.h.

◆ DGMLUTB

#define DGMLUTB   0xE3

Definition at line 146 of file st7789.h.

◆ DGMLUTR

#define DGMLUTR   0xE2

Definition at line 145 of file st7789.h.

◆ DISPLAY_HEIGHT

#define DISPLAY_HEIGHT   0x0140

Display height in pixels

Definition at line 26 of file st7789.h.

◆ DISPLAY_WIDTH

#define DISPLAY_WIDTH   0x00F0

Display width in pixels

Definition at line 23 of file st7789.h.

◆ DISPOFF

#define DISPOFF   0x28

Definition at line 91 of file st7789.h.

◆ DISPON

#define DISPON   0x29

Definition at line 92 of file st7789.h.

◆ EQCTRL

#define EQCTRL   0xE9

Definition at line 149 of file st7789.h.

◆ FRCTRL1

#define FRCTRL1   0xB3

Definition at line 125 of file st7789.h.

◆ FRCTRL2

#define FRCTRL2   0xC6

Definition at line 135 of file st7789.h.

◆ GAMSET

#define GAMSET   0x26

Definition at line 90 of file st7789.h.

◆ GATECTRL

#define GATECTRL   0xE4

Definition at line 147 of file st7789.h.

◆ GCTRL

#define GCTRL   0xB7

Definition at line 126 of file st7789.h.

◆ IDMOFF

#define IDMOFF   0x38

Definition at line 103 of file st7789.h.

◆ IDMON

#define IDMON   0x39

Definition at line 104 of file st7789.h.

◆ IDSET

#define IDSET   0xC1

Definition at line 130 of file st7789.h.

◆ INVOFF

#define INVOFF   0x20

Definition at line 88 of file st7789.h.

◆ INVON

#define INVON   0x21

Definition at line 89 of file st7789.h.

◆ LCMCTRL

#define LCMCTRL   0xC0

Definition at line 129 of file st7789.h.

◆ MADCTL

#define MADCTL   0x36

Definition at line 101 of file st7789.h.

◆ NOP

#define NOP   0x00

Definition at line 74 of file st7789.h.

◆ NORON

#define NORON   0x13

Definition at line 87 of file st7789.h.

◆ NVGAMCTRL

#define NVGAMCTRL   0xE1

Definition at line 144 of file st7789.h.

◆ NVMSET

#define NVMSET   0xFC

Definition at line 152 of file st7789.h.

◆ PORCTRL

#define PORCTRL   0xB2

Definition at line 124 of file st7789.h.

◆ PROMACT

#define PROMACT   0xFE

Definition at line 153 of file st7789.h.

◆ PROMCTRL

#define PROMCTRL   0xEC

Definition at line 150 of file st7789.h.

◆ PROMEN

#define PROMEN   0xFA

Definition at line 151 of file st7789.h.

◆ PTLAR

#define PTLAR   0x30

Definition at line 97 of file st7789.h.

◆ PTLON

#define PTLON   0x12

Definition at line 86 of file st7789.h.

◆ PVGAMCTRL

#define PVGAMCTRL   0xE0

Definition at line 143 of file st7789.h.

◆ PWCTRL1

#define PWCTRL1   0xD0

Definition at line 140 of file st7789.h.

◆ PWCTRL2

#define PWCTRL2   0xE8

Definition at line 148 of file st7789.h.

◆ PWMFRSEL

#define PWMFRSEL   0xCC

Definition at line 139 of file st7789.h.

◆ RAMCTRL

#define RAMCTRL   0xB0

Definition at line 122 of file st7789.h.

◆ RAMRD

#define RAMRD   0x2E

Definition at line 96 of file st7789.h.

◆ RAMRDC

#define RAMRDC   0x3E

Definition at line 107 of file st7789.h.

◆ RAMWR

#define RAMWR   0x2C

Definition at line 95 of file st7789.h.

◆ RAMWRC

#define RAMWRC   0x3C

Definition at line 106 of file st7789.h.

◆ RASET

#define RASET   0x2B

Definition at line 94 of file st7789.h.

◆ RDABCSDR

#define RDABCSDR   0x68

Definition at line 118 of file st7789.h.

◆ RDCABC

#define RDCABC   0x56

Definition at line 115 of file st7789.h.

◆ RDCABCMB

#define RDCABCMB   0x5F

Definition at line 117 of file st7789.h.

◆ RDCTRLD

#define RDCTRLD   0x54

Definition at line 113 of file st7789.h.

◆ RDD_COLMOD

#define RDD_COLMOD   0x0C

Definition at line 80 of file st7789.h.

◆ RDD_MADCTL

#define RDD_MADCTL   0x0B

Definition at line 79 of file st7789.h.

◆ RDDID

#define RDDID   0x04

Definition at line 76 of file st7789.h.

◆ RDDIM

#define RDDIM   0x0D

Definition at line 81 of file st7789.h.

◆ RDDISBV

#define RDDISBV   0x52

Definition at line 111 of file st7789.h.

◆ RDDPM

#define RDDPM   0x0A

Definition at line 78 of file st7789.h.

◆ RDDSDR

#define RDDSDR   0x0F

Definition at line 83 of file st7789.h.

◆ RDDSM

#define RDDSM   0x0E

Definition at line 82 of file st7789.h.

◆ RDDST

#define RDDST   0x09

Definition at line 77 of file st7789.h.

◆ RDID1

#define RDID1   0xDA

Definition at line 119 of file st7789.h.

◆ RDID2

#define RDID2   0xDB

Definition at line 120 of file st7789.h.

◆ RDID3

#define RDID3   0xDC

Definition at line 121 of file st7789.h.

◆ RDTESCAN

#define RDTESCAN   0x45

Definition at line 109 of file st7789.h.

◆ REGSEL1

#define REGSEL1   0xC8

Definition at line 137 of file st7789.h.

◆ REGSEL2

#define REGSEL2   0xCA

Definition at line 138 of file st7789.h.

◆ RGBCTRL

#define RGBCTRL   0xB1

Definition at line 123 of file st7789.h.

◆ RST_PIN

#define RST_PIN   19

Definition at line 31 of file st7789.h.

◆ SLPIN

#define SLPIN   0x10

Definition at line 84 of file st7789.h.

◆ SLPOUT

#define SLPOUT   0x11

Definition at line 85 of file st7789.h.

◆ SWRESET

#define SWRESET   0x01

Definition at line 75 of file st7789.h.

◆ TEOFF

#define TEOFF   0x34

Definition at line 99 of file st7789.h.

◆ TEON

#define TEON   0x35

Definition at line 100 of file st7789.h.

◆ TESCAN

#define TESCAN   0x44

Definition at line 108 of file st7789.h.

◆ VAPVANEN

#define VAPVANEN   0xD2

Definition at line 141 of file st7789.h.

◆ VCMOFSET

#define VCMOFSET   0xC5

Definition at line 134 of file st7789.h.

◆ VCOMS

#define VCOMS   0xBB

Definition at line 128 of file st7789.h.

◆ VDVSET

#define VDVSET   0xC4

Definition at line 133 of file st7789.h.

◆ VDVVRHEN

#define VDVVRHEN   0xC2

Definition at line 131 of file st7789.h.

◆ VRHS

#define VRHS   0xC3

Definition at line 132 of file st7789.h.

◆ VSCRDEF

#define VSCRDEF   0x33

Definition at line 98 of file st7789.h.

◆ VSCRSADD

#define VSCRSADD   0x37

Definition at line 102 of file st7789.h.

◆ WRCABCMB

#define WRCABCMB   0x5E

Definition at line 116 of file st7789.h.

◆ WRCACE

#define WRCACE   0x55

Definition at line 114 of file st7789.h.

◆ WRCTRLD

#define WRCTRLD   0x53

Definition at line 112 of file st7789.h.

◆ WRDISBV

#define WRDISBV   0x51

Definition at line 110 of file st7789.h.

Function Documentation

◆ st7789_clear()

void st7789_clear ( const uint16_t color)

Clears display.

Fills display with a single color, which can be thought of as "clearing" the scren.

Parameters
colorColor to fill display with upon clear.

Definition at line 190 of file st7789.c.

191{
192 st7789_set_window(0, DISPLAY_WIDTH - 1, 0, DISPLAY_HEIGHT - 1);
193
194 uint8_t pixel_buffer[DISPLAY_WIDTH * 2u];
195
196 for (size_t i = 0; i < sizeof(pixel_buffer); i += 2 )
197 {
198 pixel_buffer[i] = color >> 8u;
199 pixel_buffer[i+1] = color & 0xFFu;
200 }
201
202 for (size_t j = 0; j < DISPLAY_HEIGHT; j++)
203 st7789_write_data(pixel_buffer, sizeof(pixel_buffer));
204}
#define DISPLAY_HEIGHT
Definition st7789.h:26
#define DISPLAY_WIDTH
Definition st7789.h:23

◆ st7789_draw_glyph()

void st7789_draw_glyph ( const uint16_t xs,
const uint16_t ys,
const uint16_t glyph_width,
const uint16_t glyph_height,
const uint16_t fg_color,
const uint16_t bg_color,
const uint8_t * bitmap_data )

Draws a character glyph to the display.

Takes coordinates, glyph dimensions, and bitmap data to display a character glyph on the screen.

Parameters
xsColumn to start drawing glyph.
ysRow to start drawing glyph.
glyph_widthWidth of passed glyph.
glyph_heightHeight of passed glyph.
fg_colorColor
bg_color
bitmap_dataByte array containing glyph data. Each row is a single byte.

Definition at line 206 of file st7789.c.

207{
208 st7789_set_window(xs, (xs + glyph_width) - 1, ys, (ys + glyph_height) - 1);
209
210 uint8_t glyph_buffer[(glyph_width * glyph_height) * 2u];
211
212 for (size_t i = 0; i < glyph_height; i++)
213 {
214 for (size_t j = 0; j < glyph_width; j++)
215 {
216 uint16_t color = (bitmap_data[i] & (1u << (7u - j))) ? fg_color : bg_color;
217 size_t pixel_index = ((i * glyph_width) + j) * 2u;
218
219 glyph_buffer[pixel_index] = color >> 8u;
220 glyph_buffer[pixel_index + 1] = color & 0xFF;
221 }
222 }
223
224 st7789_write_data(glyph_buffer, sizeof(glyph_buffer));
225}

◆ st7789_init()

void st7789_init ( void )

ST7789 initialization.

Configures and initializes ST7789 for drawing.

Definition at line 108 of file st7789.c.

109{
110 /* Initialize timer counter */
111 tc_init();
112
113 /* Disable watchdog timer */
114 wdt_disable();
115
116 /* Initialize SPI */
117 spi_init(&st7789_cfg);
118
119 /* Initialize GPIO */
123
124 /* Perform HW reset */
125 st7789_reset();
126
127 /* Perform SW reset */
128 st7789_write_cmd(SWRESET);
129 tc_delay_ms(5);
130
131 /* Configure row/column addressing order */
132 st7789_write_cmd(MADCTL);
133 st7789_write_data(madctl_init, sizeof(madctl_init));
134
135 st7789_write_cmd(COLMOD);
136 st7789_write_data(colmod_init, sizeof(colmod_init));
137
138 /* Turn on inversion */
139 st7789_write_cmd(INVON);
140
141 /* Column & row address windows */
142 st7789_write_cmd(CASET);
143 st7789_write_data(caset_init, sizeof(caset_init));
144 st7789_write_cmd(RASET);
145 st7789_write_data(raset_init, sizeof(raset_init));
146
147 /* Porch settings */
148 st7789_write_cmd(PORCTRL);
149 st7789_write_data(porctrl_init, sizeof(porctrl_init));
150
151 /* Gate control */
152 st7789_write_cmd(GCTRL);
153 st7789_write_data(gctrl_init, sizeof(gctrl_init));
154
155 /* Common electrode voltage across LCD panel */
156 st7789_write_cmd(VCOMS);
157 st7789_write_data(vcoms_init, sizeof(vcoms_init));
158
159 st7789_write_cmd(LCMCTRL);
160 st7789_write_data(lcmctrl_init, sizeof(lcmctrl_init));
161
162 st7789_write_cmd(VDVVRHEN);
163 st7789_write_data(vdvvrhen_init, sizeof(vdvvrhen_init));
164
165 st7789_write_cmd(VRHS);
166 st7789_write_data(vrhs_init, sizeof(vrhs_init));
167
168 st7789_write_cmd(VDVSET);
169 st7789_write_data(vdvset_init, sizeof(vdvset_init));
170
171 st7789_write_cmd(FRCTRL2);
172 st7789_write_data(frctrl2_init, sizeof(frctrl2_init));
173
174 st7789_write_cmd(PWCTRL1);
175 st7789_write_data(pwctrl1_init, sizeof(pwctrl1_init));
176
177 st7789_write_cmd(PVGAMCTRL);
178 st7789_write_data(pvgamctrl_init, sizeof(pvgamctrl_init));
179
180 st7789_write_cmd(NVGAMCTRL);
181 st7789_write_data(nvgamctrl_init, sizeof(nvgamctrl_init));
182
183 st7789_write_cmd(SLPOUT);
184 tc_delay_ms(120);
185
186 st7789_write_cmd(DISPON);
187 tc_delay_ms(20);
188}
void pio_init(const pio_id_t pio_id, const uint32_t pin)
Initializes GPIO pin.
Definition pio.c:12
@ PIO_B
Definition pio.h:24
void spi_init(const spi_cfg_t *cfg)
Initializes SPI0 peripheral of SAM3X8E.
Definition spi.c:13
#define VDVSET
Definition st7789.h:133
#define RST_PIN
Definition st7789.h:31
#define PORCTRL
Definition st7789.h:124
#define COLMOD
Definition st7789.h:105
#define DC_PIN
Definition st7789.h:30
#define PVGAMCTRL
Definition st7789.h:143
#define FRCTRL2
Definition st7789.h:135
#define PWCTRL1
Definition st7789.h:140
#define DISPON
Definition st7789.h:92
#define SLPOUT
Definition st7789.h:85
#define VCOMS
Definition st7789.h:128
#define MADCTL
Definition st7789.h:101
#define LCMCTRL
Definition st7789.h:129
#define VRHS
Definition st7789.h:132
#define CASET
Definition st7789.h:93
#define NVGAMCTRL
Definition st7789.h:144
#define INVON
Definition st7789.h:89
#define CS_PIN
Definition st7789.h:29
#define RASET
Definition st7789.h:94
#define VDVVRHEN
Definition st7789.h:131
#define GCTRL
Definition st7789.h:126
#define SWRESET
Definition st7789.h:75
void tc_delay_ms(uint32_t ms)
Creates a hardware delay in milliseconds.
Definition tc.c:32
void tc_init(void)
Initializes TC0->Channel0.
Definition tc.c:12
void wdt_disable(void)
Disables SAM3X8E watchdog timer.
Definition tc.c:41