ESPHome  2024.11.0
st7920.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace st7920 {
9 
10 class ST7920;
11 
12 using st7920_writer_t = std::function<void(ST7920 &)>;
13 
15  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH, spi::CLOCK_PHASE_TRAILING,
16  spi::DATA_RATE_200KHZ> {
17  public:
18  void set_writer(st7920_writer_t &&writer) { this->writer_local_ = writer; }
19  void set_height(uint16_t height) { this->height_ = height; }
20  void set_width(uint16_t width) { this->width_ = width; }
21 
22  // ========== INTERNAL METHODS ==========
23  // (In most use cases you won't need these)
24  void setup() override;
25  void dump_config() override;
26  float get_setup_priority() const override;
27  void update() override;
28  void fill(Color color) override;
29  void write_display_data();
30 
32 
33  protected:
34  void draw_absolute_pixel_internal(int x, int y, Color color) override;
35  int get_height_internal() override;
36  int get_width_internal() override;
37  size_t get_buffer_length_();
38  void display_init_();
39  void command_(uint8_t value);
40  void data_(uint8_t value);
41  void send_(uint8_t type, uint8_t value);
42  void goto_xy_(uint16_t x, uint16_t y);
43  void start_transaction_();
44  void end_transaction_();
45 
46  int16_t width_ = 128, height_ = 64;
48 };
49 
50 } // namespace st7920
51 } // namespace esphome
int get_width_internal() override
Definition: st7920.cpp:111
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition: st7920.cpp:119
optional< st7920_writer_t > writer_local_
Definition: st7920.h:47
void set_writer(st7920_writer_t &&writer)
Definition: st7920.h:18
void set_width(uint16_t width)
Definition: st7920.h:20
uint16_t x
Definition: tt21100.cpp:17
std::function< void(ST7920 &)> st7920_writer_t
Definition: st7920.h:12
display::DisplayType get_display_type() override
Definition: st7920.h:31
void fill(Color color) override
Definition: st7920.cpp:93
int get_height_internal() override
Definition: st7920.cpp:113
void dump_config() override
Definition: st7920.cpp:95
void send_(uint8_t type, uint8_t value)
Definition: st7920.cpp:54
uint16_t y
Definition: tt21100.cpp:18
void command_(uint8_t value)
Definition: st7920.cpp:42
The SPIDevice is what components using the SPI will create.
Definition: spi.h:391
void goto_xy_(uint16_t x, uint16_t y)
Definition: st7920.cpp:60
void setup() override
Definition: st7920.cpp:34
uint8_t type
void set_height(uint16_t height)
Definition: st7920.h:19
float get_setup_priority() const override
Definition: st7920.cpp:102
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
size_t get_buffer_length_()
Definition: st7920.cpp:115
void update() override
Definition: st7920.cpp:104
void data_(uint8_t value)
Definition: st7920.cpp:48