8 ESP_LOGCONFIG(TAG,
"Setting up MIPI SPI");
16 pin->digital_write(
true);
29 auto when =
millis() + 120;
33 while (index != vec.size()) {
34 if (vec.size() - index < 2) {
35 ESP_LOGE(TAG,
"Malformed init sequence");
39 uint8_t cmd = vec[index++];
40 uint8_t
x = vec[index++];
41 if (
x == DELAY_FLAG) {
42 ESP_LOGD(TAG,
"Delay %dms", cmd);
45 uint8_t num_args =
x & 0x7F;
46 if (vec.size() - index < num_args) {
47 ESP_LOGE(TAG,
"Malformed init sequence");
51 auto arg_byte = vec[index];
57 ESP_LOGD(TAG,
"Sleep %dms",
duration);
78 const auto *ptr = vec.data() + index;
79 ESP_LOGD(TAG,
"Command %02X, length %d, byte %02X", cmd, num_args, arg_byte);
89 ESP_LOGCONFIG(TAG,
"MIPI SPI setup complete");
114 this->
width_ - w - this->x_low_);
116 this->x_low_ = this->
width_;
137 if (((uint8_t) (new_color >> 8)) == ((uint8_t) new_color)) {
141 auto *ptr_16 =
reinterpret_cast<uint16_t *
>(this->
buffer_);
144 *ptr_16++ = new_color;
157 size_t pos = (
y * this->
width_) + x;
161 if (this->
buffer_[pos] == new_color)
163 this->
buffer_[pos] = new_color;
168 auto *ptr_16 =
reinterpret_cast<uint16_t *
>(this->
buffer_);
169 uint8_t hi_byte =
static_cast<uint8_t
>(color.
r & 0xF8) | (color.
g >> 5);
170 uint8_t lo_byte =
static_cast<uint8_t
>((color.
g & 0x1C) << 3) | (color.
b >> 3);
171 uint16_t new_color = hi_byte | (lo_byte << 8);
172 if (ptr_16[pos] == new_color)
174 ptr_16[pos] = new_color;
202 while (index != vec.size()) {
203 if (vec.size() - index < 2) {
204 ESP_LOGE(TAG,
"Malformed init sequence");
208 uint8_t cmd = vec[index++];
209 uint8_t
x = vec[index++];
210 if (
x == DELAY_FLAG) {
211 ESP_LOGV(TAG,
"Delay %dms", cmd);
214 uint8_t num_args =
x & 0x7F;
215 if (vec.size() - index < num_args) {
216 ESP_LOGE(TAG,
"Malformed init sequence");
220 const auto *ptr = vec.data() + index;
226 ESP_LOGCONFIG(TAG,
"MIPI SPI setup complete");
230 ESP_LOGVV(TAG,
"Set addr %d/%d, %d/%d", x1, y1, x2, y2);
237 put16_be(buf + 2, y2);
240 put16_be(buf + 2, x2);
248 if (w <= 0 ||
h <= 0)
251 Display::draw_pixels_at(x_start, y_start, w,
h, ptr, order, bitness, big_endian, x_offset, y_offset, x_pad);
255 auto stride = x_offset + w + x_pad;
256 for (
int y = 0;
y !=
h;
y++) {
257 memcpy(this->
buffer_ + ((
y + y_start) * this->
width_ + x_start) * 2,
258 ptr + ((
y + y_offset) * stride + x_offset) * 2, w * 2);
273 uint8_t transfer_buffer[6 * 256];
276 for (
auto x = w;
x-- != 0;) {
277 auto color_val = *ptr++;
279 transfer_buffer[idx++] = (color_val & 0xF8);
280 transfer_buffer[idx++] = ((color_val & 0x7) << 5) | ((color_val & 0xE000) >> 11);
281 transfer_buffer[idx++] = (color_val >> 5) & 0xF8;
282 if (idx ==
sizeof(transfer_buffer)) {
295 uint8_t transfer_buffer[6 * 256];
298 for (
auto x = w;
x-- != 0;) {
299 auto color_val = *ptr++;
300 transfer_buffer[idx++] = color_val & 0xE0;
301 transfer_buffer[idx++] = (color_val << 3) & 0xE0;
302 transfer_buffer[idx++] = color_val << 6;
303 if (idx ==
sizeof(transfer_buffer)) {
316 uint8_t transfer_buffer[6 * 256];
319 for (
auto x = w;
x-- != 0;) {
320 auto color_val = *ptr++;
321 transfer_buffer[idx++] = (color_val & 0xE0) | ((color_val & 0x1C) >> 2);
322 transfer_buffer[idx++] = (color_val & 0x3) << 3;
323 if (idx ==
sizeof(transfer_buffer)) {
337 auto stride = x_offset + w + x_pad;
338 const auto *offset_ptr = ptr;
340 offset_ptr += y_offset * stride + x_offset;
343 offset_ptr += y_offset * stride + x_offset * 2;
349 if (x_offset == 0 && x_pad == 0 && y_offset == 0) {
355 for (
int y = 0;
y !=
h;
y++) {
357 offset_ptr += stride;
365 if (x_offset == 0 && x_pad == 0 && y_offset == 0) {
368 for (
int y = 0;
y !=
h;
y++) {
370 offset_ptr += stride;
386 if (x_offset == 0 && x_pad == 0 && y_offset == 0) {
389 for (
int y = 0;
y !=
h;
y++) {
391 offset_ptr += stride;
434 for (
size_t i = 0; i !=
len; i++) {
450 ESP_LOGCONFIG(TAG,
"MIPI_SPI Display");
451 ESP_LOGCONFIG(TAG,
" Model: %s", this->
model_);
452 ESP_LOGCONFIG(TAG,
" Width: %u", this->
width_);
453 ESP_LOGCONFIG(TAG,
" Height: %u", this->
height_);
455 ESP_LOGCONFIG(TAG,
" Offset width: %u", this->
offset_width_);
458 ESP_LOGCONFIG(TAG,
" Swap X/Y: %s", YESNO(this->
madctl_ & MADCTL_MV));
459 ESP_LOGCONFIG(TAG,
" Mirror X: %s", YESNO(this->
madctl_ & (MADCTL_MX | MADCTL_XFLIP)));
460 ESP_LOGCONFIG(TAG,
" Mirror Y: %s", YESNO(this->
madctl_ & (MADCTL_MY | MADCTL_YFLIP)));
462 ESP_LOGCONFIG(TAG,
" Invert colors: %s", YESNO(this->
invert_colors_));
463 ESP_LOGCONFIG(TAG,
" Color order: %s", this->
madctl_ & MADCTL_BGR ?
"BGR" :
"RGB");
468 ESP_LOGCONFIG(TAG,
" SPI 16bit: YES");
471 ESP_LOGCONFIG(TAG,
" Draw from origin: YES");
472 LOG_PIN(
" CS Pin: ", this->
cs_);
474 LOG_PIN(
" DC Pin: ", this->
dc_pin_);
475 ESP_LOGCONFIG(TAG,
" SPI Mode: %d", this->
mode_);
476 ESP_LOGCONFIG(TAG,
" SPI Data rate: %dMHz",
static_cast<unsigned>(this->
data_rate_ / 1000000));
477 ESP_LOGCONFIG(TAG,
" SPI Bus width: %d", this->
bus_width_);
virtual void mark_failed()
Mark this component as failed.
virtual void digital_write(bool value)=0
static uint16_t color_to_565(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
static uint8_t color_to_332(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
void dump_config() override
std::vector< uint8_t > init_sequence_
void set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
int get_width_internal() override
void write_18_from_16_bit_(const uint16_t *ptr, size_t w, size_t h, size_t stride)
int get_height_internal() override
void write_to_display_(int x_start, int y_start, int w, int h, const uint8_t *ptr, int x_offset, int y_offset, int x_pad)
optional< uint8_t > brightness_
void draw_absolute_pixel_internal(int x, int y, Color color) override
display::ColorBitness color_depth_
void write_command_(uint8_t cmd, const uint8_t *bytes, size_t len)
the RM67162 in quad SPI mode seems to work like this (not in the datasheet, this is deduced from the ...
std::vector< GPIOPin * > enable_pins_
void write_18_from_8_bit_(const uint8_t *ptr, size_t w, size_t h, size_t stride)
void write_16_from_8_bit_(const uint8_t *ptr, size_t w, size_t h, size_t stride)
void write_init_sequence_()
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order, display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override
void fill(Color color) override
value_type const & value() const
size_t get_bus_width() const
void spi_setup() override
void write_byte(uint8_t data)
void write_array(const uint8_t *data, size_t length)
void write_cmd_addr_data(size_t cmd_bits, uint32_t cmd, size_t addr_bits, uint32_t address, const uint8_t *data, size_t length, uint8_t bus_width=1)
@ BIT_ORDER_MSB_FIRST
The most significant bit is transmitted/received first.
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
std::string format_hex_pretty(const uint8_t *data, size_t length)
Format the byte array data of length len in pretty-printed, human-readable hex.