roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
ili9488.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
7#include "roo_io/data/byte_order.h"
8#include "roo_threads.h"
9#include "roo_threads/thread.h"
10
11namespace roo_display {
12
13namespace ili9488 {
14
15namespace internal {
16inline static constexpr uint32_t TruncTo6bit(uint8_t c) {
17 return (c - (c >> 7)) >> 2;
18}
19} // namespace internal
20
21// Stores R, G, B components in high bits of 3 subsequent bytes. Two low bits of
22// each byte are unused.
23class Rgb666h {
24 public:
25 static const int8_t bits_per_pixel = 24;
26
27 inline constexpr Color toArgbColor(uint32_t in) const {
28 uint32_t r6 = (in >> 18) & 0x3F;
29 uint32_t g6 = (in >> 10) & 0x3F;
30 uint32_t b6 = (in >> 2) & 0x3F;
31 auto expand = [](uint32_t v) { return (v << 2) | (v >> 4); };
32 return Color(expand(r6), expand(g6), expand(b6));
33 }
34
35 inline constexpr uint32_t fromArgbColor(Color color) const {
36 return (internal::TruncTo6bit(color.r()) << 18) |
37 (internal::TruncTo6bit(color.g()) << 10) |
38 (internal::TruncTo6bit(color.b()) << 2);
39 }
40
41 inline uint16_t rawAlphaBlend(uint32_t bg, Color color) const {
43 }
44
45 constexpr TransparencyMode transparency() const {
47 }
48};
49
50} // namespace ili9488
51
52namespace internal {
53
54template <>
59
60} // namespace internal
61
62namespace ili9488 {
63
64static const int16_t kDefaultWidth = 320;
65static const int16_t kDefaultHeight = 480;
66
67static const uint32_t kSpiFrequency = 20 * 1000 * 1000;
68
70
71enum Command {
72 NOP = 0x00,
73 SWRESET = 0x01,
74
75 SLPIN = 0x10,
76 SLPOUT = 0x11,
77
78 INVOFF = 0x20,
79
80 DISPOFF = 0x28,
81 DISPON = 0x29,
82 CASET = 0x2A,
83 PASET = 0x2B,
84 RAMWR = 0x2C,
85
86 MADCTL = 0x36,
87 PIXSET = 0x3A,
88
89 PWCTRL1 = 0xC0,
90 PWCTRL2 = 0xC1,
91 PWCTRL3 = 0xC2,
92 VMCTRL1 = 0xC5,
93 VMCTRL2 = 0xC7,
94
95 PGAMCTRL = 0xE0,
96 NGAMCTRL = 0xE1,
97};
98
99enum MadCtl {
100 MY = 0x80,
101 MX = 0x40,
102 MV = 0x20,
103 ML = 0x10,
104 BGR = 0x08,
105 MH = 0x04
107
108template <typename Transport>
110 public:
112 static constexpr ByteOrder byte_order = roo_io::kBigEndian;
113
116 : transport_(),
117 width_(width),
118 height_(height),
119 last_x0_(-1),
120 last_x1_(-1),
121 last_y0_(-1),
122 last_y1_(-1) {}
123
126 : transport_(std::move(transport)),
127 width_(width),
128 height_(height),
129 last_x0_(-1),
130 last_x1_(-1),
131 last_y0_(-1),
132 last_y1_(-1) {}
133
134 int16_t width() const { return width_; }
135
136 int16_t height() const { return height_; }
137
138 void begin() {
139 transport_.beginWriteOnlyTransaction();
140 transport_.begin();
141 }
142
143 void end() {
144 transport_.end();
145 transport_.endTransaction();
146 }
147
148 void init() {
149 transport_.init();
150 begin();
151
152 // Set Gamma.
153 writeCommand(PGAMCTRL, {0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78,
154 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F});
155 writeCommand(NGAMCTRL, {0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45,
156 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F});
157
158 writeCommand(PWCTRL1, {0x17, 0x15});
159 writeCommand(PWCTRL2, {0x41});
160
161 writeCommand(VMCTRL1, {0x00, 0x12, 0x80});
162
163 // Portrait mode.
164 writeCommand(MADCTL, {0x48});
165
166 writeCommand(PIXSET, {0x66});
167
168 // Interface Mode Control.
169 writeCommand(0xB0, {0x00});
170
171 // Frame Rate Control.
172 writeCommand(0xB1, {0xA0});
173
174 // Display Inversion Control.
175 writeCommand(0xB4, {0x02});
176
177 // Display Function Control.
178 writeCommand(0xB6, {0x02, 0x02, 0x3B});
179
180 // Entry Mode Set.
181 writeCommand(0xB7, {0xC6});
182
183 // Adjust Control 3.
184 writeCommand(0xF7, {0xA9, 0x51, 0x2C, 0x82});
185
186 writeCommand(SLPOUT);
187
188 end();
189
190 sleep_ms(120);
191
192 begin();
193 writeCommand(DISPON);
194 end();
195 }
196
197 void setOrientation(Orientation orientation) {
198 uint8_t d = BGR | (orientation.isXYswapped() ? MV : 0) |
199 (orientation.isTopToBottom() ? 0 : MY) |
200 (orientation.isRightToLeft() ? 0 : MX);
201 writeCommand(MADCTL);
202 transport_.write(d);
203 }
204
206 __attribute__((always_inline)) {
207 if (last_x0_ != x0 || last_x1_ != x1) {
208 writeCommand(CASET);
209 transport_.write16x2(x0, x1);
210 last_x0_ = x0;
211 last_x1_ = x1;
212 }
213 if (last_y0_ != y0 || last_y1_ != y1) {
214 writeCommand(PASET);
215 transport_.write16x2(y0, y1);
216 last_y0_ = y0;
217 last_y1_ = y1;
218 }
219 }
220
221 void startRamWrite() __attribute__((always_inline)) { writeCommand(RAMWR); }
222
223 void flush() __attribute__((always_inline)) { transport_.flush(); }
224
225 void ramWrite(const roo::byte* data, size_t pixel_count)
226 __attribute__((always_inline)) {
227 transport_.writeBytes(data, pixel_count * 3);
228 }
229
230 void ramFill(const roo::byte* data, size_t pixel_count)
231 __attribute__((always_inline)) {
232 transport_.fill24(data, pixel_count);
233 }
234
235 void ramWriteAsyncBlit(const roo::byte* data, size_t row_stride_bytes,
236 size_t row_bytes, size_t row_count)
237 __attribute__((always_inline)) {
238 transport_.async_blit(data, row_stride_bytes, row_bytes, row_count);
239 }
240
241 private:
242 void writeCommand(uint8_t c) __attribute__((always_inline)) {
243 transport_.cmdBegin();
244 transport_.write(c);
245 transport_.cmdEnd();
246 }
247
248 void writeCommand(uint8_t c, const std::initializer_list<uint8_t>& d) {
249 writeCommand(c);
250 for (uint8_t i : d) transport_.write(i);
251 }
252
253 void sleep_ms(uint32_t ms) {
254 roo::this_thread::sleep_for(roo_time::Millis(ms));
255 }
256
257 Transport transport_;
258 int16_t width_;
259 int16_t height_;
260 uint16_t last_x0_, last_x1_, last_y0_, last_y1_;
261};
262
263} // namespace ili9488
264
265template <typename Transport>
267
268template <int pinCS, int pinDC, int pinRST, typename Spi = DefaultSpi,
272
273} // namespace roo_display
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
Represents the orientation of a display device.
Definition orientation.h:25
bool isRightToLeft() const
Return whether horizontal direction is right-to-left.
bool isTopToBottom() const
Return whether vertical direction is top-to-bottom.
bool isXYswapped() const
Return whether x maps to the vertical direction.
Definition orientation.h:90
void ramWrite(const roo::byte *data, size_t pixel_count) __attribute__((always_inline))
Definition ili9488.h:225
void flush() __attribute__((always_inline))
Definition ili9488.h:223
static constexpr ByteOrder byte_order
Definition ili9488.h:112
void ramWriteAsyncBlit(const roo::byte *data, size_t row_stride_bytes, size_t row_bytes, size_t row_count) __attribute__((always_inline))
Definition ili9488.h:235
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) __attribute__((always_inline))
Definition ili9488.h:205
void ramFill(const roo::byte *data, size_t pixel_count) __attribute__((always_inline))
Definition ili9488.h:230
void startRamWrite() __attribute__((always_inline))
Definition ili9488.h:221
void setOrientation(Orientation orientation)
Definition ili9488.h:197
Ili9488Target(Transport transport, uint16_t width=kDefaultWidth, uint16_t height=kDefaultHeight)
Definition ili9488.h:124
Ili9488Target(uint16_t width=kDefaultWidth, uint16_t height=kDefaultHeight)
Definition ili9488.h:114
uint16_t rawAlphaBlend(uint32_t bg, Color color) const
Definition ili9488.h:41
constexpr uint32_t fromArgbColor(Color color) const
Definition ili9488.h:35
constexpr TransparencyMode transparency() const
Definition ili9488.h:45
static const int8_t bits_per_pixel
Definition ili9488.h:25
constexpr Color toArgbColor(uint32_t in) const
Definition ili9488.h:27
static constexpr uint32_t TruncTo6bit(uint8_t c)
Definition ili9488.h:16
static const int16_t kDefaultWidth
Definition ili9488.h:64
static const uint32_t kSpiFrequency
Definition ili9488.h:67
SpiSettings< kSpiFrequency, kSpiMsbFirst, kSpiMode0 > DefaultSpiSettings
Definition ili9488.h:69
static const int16_t kDefaultHeight
Definition ili9488.h:65
Defines 140 opaque HTML named colors.
TransparencyMode
Transparency information for a stream or color mode.
Definition blending.h:103
@ kNone
All colors are fully opaque.
Color AlphaBlendOverOpaque(Color bgc, Color fgc)
Definition blending.h:465
roo_io::ByteOrder ByteOrder
Definition byte_order.h:7
static constexpr const DisplayOutput::ColorFormat::Mode mode