ESPHome  2022.6.2
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 
14 class ST7920 : public PollingComponent,
16  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH, spi::CLOCK_PHASE_TRAILING,
17  spi::DATA_RATE_200KHZ> {
18  public:
19  void set_writer(st7920_writer_t &&writer) { this->writer_local_ = writer; }
20  void set_height(uint16_t height) { this->height_ = height; }
21  void set_width(uint16_t width) { this->width_ = width; }
22 
23  // ========== INTERNAL METHODS ==========
24  // (In most use cases you won't need these)
25  void setup() override;
26  void dump_config() override;
27  float get_setup_priority() const override;
28  void update() override;
29  void fill(Color color) override;
30  void write_display_data();
31 
33 
34  protected:
35  void draw_absolute_pixel_internal(int x, int y, Color color) override;
36  int get_height_internal() override;
37  int get_width_internal() override;
38  size_t get_buffer_length_();
39  void display_init_();
40  void command_(uint8_t value);
41  void data_(uint8_t value);
42  void send_(uint8_t type, uint8_t value);
43  void goto_xy_(uint16_t x, uint16_t y);
44  void start_transaction_();
45  void end_transaction_();
46 
47  int16_t width_ = 128, height_ = 64;
49 };
50 
51 } // namespace st7920
52 } // 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:48
void set_writer(st7920_writer_t &&writer)
Definition: st7920.h:19
void set_width(uint16_t width)
Definition: st7920.h:21
std::function< void(ST7920 &)> st7920_writer_t
Definition: st7920.h:12
display::DisplayType get_display_type() override
Definition: st7920.h:32
void fill(Color color) override
Definition: st7920.cpp:93
This class simplifies creating components that periodically check a state.
Definition: component.h:266
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
void command_(uint8_t value)
Definition: st7920.cpp:42
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:20
float get_setup_priority() const override
Definition: st7920.cpp:102
Definition: a4988.cpp:4
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