esphome/esphome/components/ili9341/ili9341_display.h
Vc 9816e677a6
add Ili9341 display (#1233)
* setup ili9341 framework
used epaper-waveshare as start

* first version working

* added models for now only M5Stack

* get_buffer_length is huge

* fill, low/high watermark, buffer tests failed.
RAM is to small for ili9341 16 bit color mode

* removed high/low watermark debug log

* added standard 2.4" TFT model

* code cleanup

* make ledpin optional
busy pin is not needed

* make bufer 1 byte to avoid the
buffer allocation error

* gitignore

* added backlight pin to dump_config

* huge speed increase
8bit color framebuffer (256 colors)
lo and high watermark for drawing to screen

* fix for images

* higher spi data rates

* Set spi data rate to 40Mhz Experimental

* fixed: formatting
fixed: the last row and column being trimmed
fixed: namings

* Update the code to use Color class

* fixed minor color things

* fixed linting

* #patch minor fixes

* fix gitignore too

* Update esphome/components/ili9341/ili9341_display.cpp

Co-authored-by: Oleg <epushiron+github@gmail.com>

* reverting the changes as it's being fixed in PR-1241

Co-authored-by: Michiel van Turnhout <qris.online@gmail.com>
Co-authored-by: Michiel van Turnhout <m.vanturnhout@exxellence.nl>
Co-authored-by: Oleg <epushiron+github@gmail.com>
2020-11-08 22:53:35 -03:00

92 lines
2.6 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/components/spi/spi.h"
#include "esphome/components/display/display_buffer.h"
#include "ili9341_defines.h"
#include "ili9341_init.h"
namespace esphome {
namespace ili9341 {
enum ILI9341Model {
M5STACK = 0,
TFT_24,
};
class ILI9341Display : public PollingComponent,
public display::DisplayBuffer,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_40MHZ> {
public:
void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
float get_setup_priority() const override;
void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
void set_led_pin(GPIOPin *led) { this->led_pin_ = led; }
void set_model(ILI9341Model model) { this->model_ = model; }
void command(uint8_t value);
void data(uint8_t value);
void send_command(uint8_t command_byte, const uint8_t *data_bytes, uint8_t num_data_bytes);
uint8_t read_command(uint8_t command_byte, uint8_t index);
virtual void initialize() = 0;
void update() override;
void fill(Color color) override;
void dump_config() override;
void setup() override {
this->setup_pins_();
this->initialize();
}
protected:
void draw_absolute_pixel_internal(int x, int y, Color color) override;
void setup_pins_();
void init_lcd_(const uint8_t *init_cmd);
void set_addr_window_(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
void invert_display_(bool invert);
void reset_();
void fill_internal_(Color color);
void display_();
uint16_t convert_to_16bit_color_(uint8_t color_8bit);
uint8_t convert_to_8bit_color_(uint16_t color_16bit);
ILI9341Model model_;
int16_t width_{320}; ///< Display width as modified by current rotation
int16_t height_{240}; ///< Display height as modified by current rotation
uint16_t x_low_{0};
uint16_t y_low_{0};
uint16_t x_high_{0};
uint16_t y_high_{0};
uint32_t get_buffer_length_();
int get_width_internal() override;
int get_height_internal() override;
void start_command_();
void end_command_();
void start_data_();
void end_data_();
GPIOPin *reset_pin_{nullptr};
GPIOPin *led_pin_{nullptr};
GPIOPin *dc_pin_;
GPIOPin *busy_pin_{nullptr};
};
//----------- M5Stack display --------------
class ILI9341M5Stack : public ILI9341Display {
public:
void initialize() override;
};
//----------- ILI9341_24_TFT display --------------
class ILI9341TFT24 : public ILI9341Display {
public:
void initialize() override;
};
} // namespace ili9341
} // namespace esphome