10 static const uint16_t SPI_SETUP_US = 100;
11 static const uint16_t SPI_MAX_BLOCK_SIZE = 4092;
14 static inline void put16_be(uint8_t *buf, uint16_t value) {
30 esph_log_d(TAG,
"Wrote MADCTL 0x%02X", mad);
34 ESP_LOGD(TAG,
"Setting up ILI9xxx");
75 LOG_DISPLAY(
"",
"ili9xxx",
this);
76 ESP_LOGCONFIG(TAG,
" Width Offset: %u", this->
offset_x_);
77 ESP_LOGCONFIG(TAG,
" Height Offset: %u", this->
offset_y_);
80 ESP_LOGCONFIG(TAG,
" Color mode: 8bit Indexed");
83 ESP_LOGCONFIG(TAG,
" Color mode: 16bit");
86 ESP_LOGCONFIG(TAG,
" Color mode: 8bit 332 mode");
90 ESP_LOGCONFIG(TAG,
" 18-Bit Mode: YES");
92 ESP_LOGCONFIG(TAG,
" Data rate: %dMHz", (
unsigned) (this->
data_rate_ / 1000000));
95 LOG_PIN(
" CS Pin: ", this->
cs_);
96 LOG_PIN(
" DC Pin: ", this->
dc_pin_);
99 ESP_LOGCONFIG(TAG,
" Swap_xy: %s", YESNO(this->
swap_xy_));
100 ESP_LOGCONFIG(TAG,
" Mirror_x: %s", YESNO(this->
mirror_x_));
101 ESP_LOGCONFIG(TAG,
" Mirror_y: %s", YESNO(this->
mirror_y_));
104 ESP_LOGCONFIG(TAG,
" => Failed to init Memory: YES!");
106 LOG_UPDATE_INTERVAL(
this);
114 uint16_t new_color = 0;
127 if (((uint8_t) (new_color >> 8)) == ((uint8_t) new_color)) {
129 memset(this->
buffer_, (uint8_t) new_color, buffer_length_16_bits);
131 for (uint32_t i = 0; i < buffer_length_16_bits; i = i + 2) {
132 this->
buffer_[i] = (uint8_t) (new_color >> 8);
133 this->
buffer_[i + 1] = (uint8_t) new_color;
152 uint32_t pos = (y *
width_) + x;
154 bool updated =
false;
162 if (this->
buffer_[pos] != (uint8_t) (new_color >> 8)) {
163 this->
buffer_[pos] = (uint8_t) (new_color >> 8);
167 new_color = new_color & 0xFF;
174 if (this->
buffer_[pos] != new_color) {
175 this->
buffer_[pos] = new_color;
208 if ((this->x_high_ < this->
x_low_) || (this->y_high_ < this->
y_low_)) {
213 size_t const w = this->
x_high_ - this->x_low_ + 1;
214 size_t const h = this->
y_high_ - this->y_low_ + 1;
218 size_t sw_time = this->
width_ * h * 16 / mhz + this->
width_ * h * 2 / SPI_MAX_BLOCK_SIZE * SPI_SETUP_US * 2;
222 "Start display(xlow:%d, ylow:%d, xhigh:%d, yhigh:%d, width:%d, " 223 "height:%zu, mode=%d, 18bit=%d, sw_time=%zuus, mw_time=%zuus)",
229 ESP_LOGV(TAG,
"Doing single write of %zu bytes", this->
width_ * h * 2);
233 ESP_LOGV(TAG,
"Doing multiple write");
238 size_t pos = this->y_low_ * this->
width_ + this->
x_low_;
255 transfer_buffer[idx++] = (uint8_t) ((color_val & 0xF800) >> 8);
256 transfer_buffer[idx++] = (uint8_t) ((color_val & 0x7E0) >> 3);
257 transfer_buffer[idx++] = (uint8_t) (color_val << 3);
259 put16_be(transfer_buffer + idx, color_val);
279 ESP_LOGV(TAG,
"Data write took %dms", (
unsigned) (
millis() - now));
281 this->x_low_ = this->
width_;
290 int x_offset,
int y_offset,
int x_pad) {
291 if (w <= 0 || h <= 0)
298 return display::Display::draw_pixels_at(x_start, y_start, w, h, ptr, order, bitness, big_endian, x_offset, y_offset,
303 if (x_offset == 0 && x_pad == 0 && y_offset == 0) {
307 auto stride = x_offset + w + x_pad;
308 for (
size_t y = 0;
y !=
h;
y++) {
309 this->
write_array(ptr + (
y + y_offset) * stride + x_offset, w * 2);
360 uint8_t
cmd,
x, num_args;
362 while ((cmd = *addr++) > 0) {
380 this->
data(x1 & 0xFF);
382 this->
data(x2 & 0xFF);
385 this->
data(y1 & 0xFF);
387 this->
data(y2 & 0xFF);
395 this->
command(invert ? ILI9XXX_INVON : ILI9XXX_INVOFF);
void send_command(uint8_t command_byte, const uint8_t *data_bytes, uint8_t num_data_bytes)
virtual void digital_write(bool value)=0
uint32_t get_buffer_length_()
uint8_t const * init_sequence_
static uint16_t color_to_565(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
void spi_setup() override
void set_addr_window_(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2)
void write_byte(uint8_t data)
uint32_t IRAM_ATTR HOT millis()
int16_t width_
Display width as modified by current rotation.
void init_internal_(uint32_t buffer_length)
void draw_absolute_pixel_internal(int x, int y, Color color) override
int16_t height_
Display height as modified by current rotation.
int get_width_internal() override
ILI9XXXColorMode buffer_color_mode_
display::ColorOrder color_order_
static uint8_t color_to_332(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
int get_height_internal() override
float get_setup_priority() const override
void dump_config() override
static Color index8_to_color_palette888(uint8_t index, const uint8_t *palette)
const size_t ILI9XXX_TRANSFER_BUFFER_SIZE
Application App
Global storage of Application pointer - only one Application can exist.
virtual void data(uint8_t value)
DisplayRotation rotation_
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
virtual void set_madctl()
static uint8_t color_to_index8_palette888(Color color, const uint8_t *palette)
virtual void mark_failed()
Mark this component as failed.
void write_array(const uint8_t *data, size_t length)
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
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
static Color rgb332_to_color(uint8_t rgb332_color)
virtual void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorOrder order, ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad)
Given an array of pixels encoded in the nominated format, draw these into the display's buffer...
virtual void command(uint8_t value)
void IRAM_ATTR HOT delay(uint32_t ms)
void invert_colors(bool invert)