roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
st77xx.h
Go to the documentation of this file.
1#pragma once
2
4#include "roo_threads.h"
5#include "roo_threads/thread.h"
6
7namespace roo_display {
8namespace st77xx {
9
10enum Command {
11 NOP = 0x00,
12 SWRESET = 0x01,
13 SLPIN = 0x10,
14 SLPOUT = 0x11,
15 PTLON = 0x12,
16 NORON = 0x13,
17 INVOFF = 0x20,
18 INVON = 0x21,
19 DISPOFF = 0x28,
20 DISPON = 0x29,
21 CASET = 0x2A,
22 RASET = 0x2B,
23 RAMWR = 0x2C,
24
25 MADCTL = 0x36,
26 COLMOD = 0x3A,
27
28 DIC = 0xB4,
29 DFC = 0xB6,
30
31 PWR1 = 0xC0,
32 PWR2 = 0xC1,
33 PWR3 = 0xC2,
34
35 VCMPCTL = 0xC5,
36
37 PGC = 0xE0,
38 NGC = 0xE1,
39 DOCA = 0xE8,
40 CSCON = 0xF0,
41};
42
43enum MadCtl {
44 MY = 0x80,
45 MX = 0x40,
46 MV = 0x20,
47 ML = 0x10,
48 BGR = 0x08,
49 MH = 0x04,
50 RGB = 0x00,
51};
52
53template <typename Transport, typename Initializer, int16_t display_width,
55 int16_t rpad = lpad, int16_t bpad = tpad, bool inverted = false,
56 bool bgr = false, bool hflipped = false>
58 public:
60 static constexpr ByteOrder byte_order = roo_io::kBigEndian;
61
63 : transport_(std::move(transport)),
64 width_(display_width),
65 height_(display_height),
66 x_offset_(lpad),
67 y_offset_(rpad),
68 last_x0_(-1),
69 last_x1_(-1),
70 last_y0_(-1),
71 last_y1_(-1) {}
72
73 int16_t width() const { return width_; }
74
75 int16_t height() const { return height_; }
76
77 void begin() {
78 transport_.beginWriteOnlyTransaction();
79 transport_.begin();
80 }
81
82 void end() {
83 transport_.end();
84 transport_.endTransaction();
85 }
86
87 void init() {
88 transport_.init();
90 begin();
91 init.init(*this, lpad, display_width + lpad + rpad - 1, tpad,
92 display_height + tpad + bpad - 1, inverted);
93 end();
94 }
95
96 void setOrientation(Orientation orientation) {
97 bool is_xy_swapped = orientation.isXYswapped();
98 bool is_top_to_bottom = orientation.isTopToBottom();
99 bool is_left_to_right = orientation.isLeftToRight() ^ hflipped;
100 uint8_t d = (bgr ? BGR : RGB) | (is_xy_swapped ? MV : 0) |
101 (is_top_to_bottom ? 0 : MY) | (is_left_to_right ? 0 : MX);
103 transport_.write(d);
106 x_offset_ = is_xy_swapped ? yoffset : xoffset;
107 y_offset_ = is_xy_swapped ? xoffset : yoffset;
108 }
109
111 __attribute__((always_inline)) {
112 if (last_x0_ != x0 || last_x1_ != x1) {
114 transport_.write16x2((x0 + x_offset_), (x1 + x_offset_));
115 last_x0_ = x0;
116 last_x1_ = x1;
117 }
118 if (last_y0_ != y0 || last_y1_ != y1) {
120 transport_.write16x2((y0 + y_offset_), (y1 + y_offset_));
121 last_y0_ = y0;
122 last_y1_ = y1;
123 }
124 }
125
126 void startRamWrite() __attribute__((always_inline)) { writeCommand(RAMWR); }
127
128 void flush() __attribute__((always_inline)) { transport_.flush(); }
129
130 void ramWrite(const roo::byte* data, size_t pixel_count)
131 __attribute__((always_inline)) {
132 transport_.writeBytes(data, pixel_count * 2);
133 }
134
135 void ramFill(const roo::byte* data, size_t pixel_count)
136 __attribute__((always_inline)) {
137 transport_.fill16(data, pixel_count);
138 }
139
140 void ramWriteAsyncBlit(const roo::byte* data, size_t row_stride_bytes,
141 size_t row_bytes, size_t row_count)
142 __attribute__((always_inline)) {
143 transport_.async_blit(data, row_stride_bytes, row_bytes, row_count);
144 }
145
146 void writeCommand(uint8_t c) __attribute__((always_inline)) {
147 transport_.cmdBegin();
148 transport_.write(c);
149 transport_.cmdEnd();
150 }
151
152 void writeCommand(uint8_t c, const std::initializer_list<uint8_t>& d,
153 uint32_t delay_ms = 0) {
155 for (uint8_t i : d) transport_.write(i);
156 if (delay_ms > 0) sleep_ms(delay_ms);
157 }
158
159 private:
160 void sleep_ms(uint32_t ms) {
161 roo::this_thread::sleep_for(roo_time::Millis(ms));
162 }
163
164 Transport transport_;
165 int16_t width_;
166 int16_t height_;
167 int16_t x_offset_;
168 int16_t y_offset_;
169 uint16_t last_x0_, last_x1_, last_y0_, last_y1_;
170};
171
172} // namespace st77xx
173} // namespace roo_display
Represents the orientation of a display device.
Definition orientation.h:25
bool isLeftToRight() const
Return whether horizontal direction is left-to-right.
Definition orientation.h:98
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
16-bit RGB565 color mode (opaque).
void flush() __attribute__((always_inline))
Definition st77xx.h:128
void setOrientation(Orientation orientation)
Definition st77xx.h:96
void ramWriteAsyncBlit(const roo::byte *data, size_t row_stride_bytes, size_t row_bytes, size_t row_count) __attribute__((always_inline))
Definition st77xx.h:140
void ramFill(const roo::byte *data, size_t pixel_count) __attribute__((always_inline))
Definition st77xx.h:135
void writeCommand(uint8_t c) __attribute__((always_inline))
Definition st77xx.h:146
void ramWrite(const roo::byte *data, size_t pixel_count) __attribute__((always_inline))
Definition st77xx.h:130
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) __attribute__((always_inline))
Definition st77xx.h:110
void writeCommand(uint8_t c, const std::initializer_list< uint8_t > &d, uint32_t delay_ms=0)
Definition st77xx.h:152
St77xxTarget(Transport transport=Transport())
Definition st77xx.h:62
void startRamWrite() __attribute__((always_inline))
Definition st77xx.h:126
static constexpr ByteOrder byte_order
Definition st77xx.h:60
Defines 140 opaque HTML named colors.
roo_io::ByteOrder ByteOrder
Definition byte_order.h:7