Plant Monitor SAM3X8E
Loading...
Searching...
No Matches
st7789.h
Go to the documentation of this file.
1
9
10#ifndef ST7789_H
11#define ST7789_H
12
13#include "hal/spi.h"
14#include "hal/pio.h"
15#include "hal/tc.h"
16
17/*================================
18 * LCD Display Parameters
19 * for Waveshare 2-inch LCD module
20 *================================*/
21
23#define DISPLAY_WIDTH 0x00F0
24
26#define DISPLAY_HEIGHT 0x0140
27
29#define CS_PIN 17
30#define DC_PIN 18
31#define RST_PIN 19
32
33/*================================
34 * Function Declarations
35 *================================*/
36
42void st7789_init(void);
43
50void st7789_clear(const uint16_t color);
51
65void 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);
66
67/*================================
68 * ST7789 Command Macros
69 *
70 * Command codes defined in ST7789
71 * controller datasheet.
72 *================================*/
73
74#define NOP 0x00
75#define SWRESET 0x01
76#define RDDID 0x04
77#define RDDST 0x09
78#define RDDPM 0x0A
79#define RDD_MADCTL 0x0B
80#define RDD_COLMOD 0x0C
81#define RDDIM 0x0D
82#define RDDSM 0x0E
83#define RDDSDR 0x0F
84#define SLPIN 0x10
85#define SLPOUT 0x11
86#define PTLON 0x12
87#define NORON 0x13
88#define INVOFF 0x20
89#define INVON 0x21
90#define GAMSET 0x26
91#define DISPOFF 0x28
92#define DISPON 0x29
93#define CASET 0x2A
94#define RASET 0x2B
95#define RAMWR 0x2C
96#define RAMRD 0x2E
97#define PTLAR 0x30
98#define VSCRDEF 0x33
99#define TEOFF 0x34
100#define TEON 0x35
101#define MADCTL 0x36
102#define VSCRSADD 0x37
103#define IDMOFF 0x38
104#define IDMON 0x39
105#define COLMOD 0x3A
106#define RAMWRC 0x3C
107#define RAMRDC 0x3E
108#define TESCAN 0x44
109#define RDTESCAN 0x45
110#define WRDISBV 0x51
111#define RDDISBV 0x52
112#define WRCTRLD 0x53
113#define RDCTRLD 0x54
114#define WRCACE 0x55
115#define RDCABC 0x56
116#define WRCABCMB 0x5E
117#define RDCABCMB 0x5F
118#define RDABCSDR 0x68
119#define RDID1 0xDA
120#define RDID2 0xDB
121#define RDID3 0xDC
122#define RAMCTRL 0xB0
123#define RGBCTRL 0xB1
124#define PORCTRL 0xB2
125#define FRCTRL1 0xB3
126#define GCTRL 0xB7
127#define DGMEN 0xBA
128#define VCOMS 0xBB
129#define LCMCTRL 0xC0
130#define IDSET 0xC1
131#define VDVVRHEN 0xC2
132#define VRHS 0xC3
133#define VDVSET 0xC4
134#define VCMOFSET 0xC5
135#define FRCTRL2 0xC6
136#define CABCCTRL 0xC7
137#define REGSEL1 0xC8
138#define REGSEL2 0xCA
139#define PWMFRSEL 0xCC
140#define PWCTRL1 0xD0
141#define VAPVANEN 0xD2
142#define CMD2EN { 0xDF, 0x5A, 0x69, 0x02 }
143#define PVGAMCTRL 0xE0
144#define NVGAMCTRL 0xE1
145#define DGMLUTR 0xE2
146#define DGMLUTB 0xE3
147#define GATECTRL 0xE4
148#define PWCTRL2 0xE8
149#define EQCTRL 0xE9
150#define PROMCTRL 0xEC
151#define PROMEN 0xFA
152#define NVMSET 0xFC
153#define PROMACT 0xFE
154
155/*================================
156 * ST7789 Initialization Parameters
157 *
158 * Register configuration values for
159 * initialization. Based on manufa-
160 * cturor configuration.
161 *================================*/
162
163static const uint8_t madctl_init[] = { 0xC0 };
164static const uint8_t colmod_init[] = { 0x05 };
165static const uint8_t caset_init[] = { 0x00, 0x01, 0x00, 0x3F };
166static const uint8_t raset_init[] = { 0x00, 0x00, 0x00, 0xEF };
167static const uint8_t porctrl_init[] = { 0x0C, 0x0C, 0x00, 0x33, 0x33 };
168static const uint8_t gctrl_init[] = { 0x35 };
169static const uint8_t vcoms_init[] = { 0x1F };
170static const uint8_t lcmctrl_init[] = { 0x2C };
171static const uint8_t vdvvrhen_init[] = { 0x01 };
172static const uint8_t vrhs_init[] = { 0x12 };
173static const uint8_t vdvset_init[] = { 0x20 };
174static const uint8_t frctrl2_init[] = { 0x0F };
175static const uint8_t pwctrl1_init[] = { 0xA4, 0xA1 };
176static const uint8_t pvgamctrl_init[] = { 0xD0, 0x08, 0x11, 0x08, 0x0C, 0x15, 0x39, 0x33, 0x50, 0x36, 0x13, 0x14, 0x29, 0x2D };
177static const uint8_t nvgamctrl_init[] = { 0xD0, 0x08, 0x10, 0x08, 0x06, 0x06, 0x39, 0x44, 0x51, 0x0B, 0x16, 0x14, 0x2F, 0x31, 0x21 };
178
179#endif
HAL interface for GPIO of SAM3X8E.
HAL interface for SPI peripheral of SAM3X8E.
void st7789_init(void)
ST7789 initialization.
Definition st7789.c:108
void st7789_clear(const uint16_t color)
Clears display.
Definition st7789.c:190
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.
Definition st7789.c:206
HAL interface for timer counter of SAM3X8E.