ESPHome  2024.5.0
st7567_base.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace st7567_base {
9 
10 static const uint8_t ST7567_BOOSTER_ON = 0x2C; // internal power supply on
11 static const uint8_t ST7567_REGULATOR_ON = 0x2E; // internal power supply on
12 static const uint8_t ST7567_POWER_ON = 0x2F; // internal power supply on
13 
14 static const uint8_t ST7567_DISPLAY_ON = 0xAF; // Display ON. Normal Display Mode.
15 static const uint8_t ST7567_DISPLAY_OFF = 0xAE; // Display OFF. All SEGs/COMs output with VSS
16 static const uint8_t ST7567_SET_START_LINE = 0x40;
17 static const uint8_t ST7567_POWER_CTL = 0x28;
18 static const uint8_t ST7567_SEG_NORMAL = 0xA0; //
19 static const uint8_t ST7567_SEG_REVERSE = 0xA1; // mirror X axis (horizontal)
20 static const uint8_t ST7567_COM_NORMAL = 0xC0; //
21 static const uint8_t ST7567_COM_REMAP = 0xC8; // mirror Y axis (vertical)
22 static const uint8_t ST7567_PIXELS_NORMAL = 0xA4; // display ram content
23 static const uint8_t ST7567_PIXELS_ALL_ON = 0xA5; // all pixels on
24 static const uint8_t ST7567_INVERT_OFF = 0xA6; // normal pixels
25 static const uint8_t ST7567_INVERT_ON = 0xA7; // inverted pixels
26 static const uint8_t ST7567_SCAN_START_LINE = 0x40; // scrolling = 0x40 + (0..63)
27 static const uint8_t ST7567_COL_ADDR_H = 0x10; // x pos (0..95) 4 MSB
28 static const uint8_t ST7567_COL_ADDR_L = 0x00; // x pos (0..95) 4 LSB
29 static const uint8_t ST7567_PAGE_ADDR = 0xB0; // y pos, 8.5 rows (0..8)
30 static const uint8_t ST7567_BIAS_9 = 0xA2;
31 static const uint8_t ST7567_CONTRAST = 0x80; // 0x80 + (0..31)
32 static const uint8_t ST7567_SET_EV_CMD = 0x81;
33 static const uint8_t ST7567_SET_EV_PARAM = 0x00;
34 static const uint8_t ST7567_RESISTOR_RATIO = 0x20;
35 static const uint8_t ST7567_SW_REFRESH = 0xE2;
36 
38  public:
39  void setup() override;
40 
41  void update() override;
42 
43  void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
44  void init_mirror_x(bool mirror_x) { this->mirror_x_ = mirror_x; }
45  void init_mirror_y(bool mirror_y) { this->mirror_y_ = mirror_y; }
46  void init_invert_colors(bool invert_colors) { this->invert_colors_ = invert_colors; }
47 
48  void set_invert_colors(bool invert_colors); // inversion of screen colors
49  void set_contrast(uint8_t val); // 0..63, 27-30 normal
50  void set_brightness(uint8_t val); // 0..7, 5 normal
51  void set_all_pixels_on(bool enable); // turn on all pixels, this doesn't affect RAM
52  void set_scroll(uint8_t line); // set display start line: for screen scrolling w/o affecting RAM
53 
54  bool is_on();
55  void turn_on();
56  void turn_off();
57 
58  void request_refresh(); // from datasheet: It is recommended to use the refresh sequence regularly in a specified
59  // interval.
60 
61  float get_setup_priority() const override { return setup_priority::PROCESSOR; }
62  void fill(Color color) override;
63 
65 
66  protected:
67  virtual void command(uint8_t value) = 0;
68  virtual void write_display_data() = 0;
69 
70  void init_reset_();
71  void display_init_();
73  void display_sw_refresh_();
74 
75  void draw_absolute_pixel_internal(int x, int y, Color color) override;
76 
77  int get_height_internal() override;
78  int get_width_internal() override;
79  size_t get_buffer_length_();
80 
81  int get_offset_x_() { return mirror_x_ ? 4 : 0; };
82 
83  const char *model_str_();
84 
85  GPIOPin *reset_pin_{nullptr};
86  bool is_on_{false};
87  // float contrast_{1.0};
88  // float brightness_{1.0};
89  uint8_t contrast_{27};
90  uint8_t brightness_{5};
91  bool mirror_x_{true};
92  bool mirror_y_{true};
93  bool invert_colors_{false};
94  bool all_pixels_on_{false};
95  uint8_t start_line_{0};
96  bool refresh_requested_{false};
97 };
98 
99 } // namespace st7567_base
100 } // namespace esphome
void set_invert_colors(bool invert_colors)
Definition: st7567_base.cpp:69
void fill(Color color) override
void set_brightness(uint8_t val)
Definition: st7567_base.cpp:86
uint16_t x
Definition: tt21100.cpp:17
void init_mirror_y(bool mirror_y)
Definition: st7567_base.h:45
mopeka_std_values val[4]
virtual void write_display_data()=0
void set_reset_pin(GPIOPin *reset_pin)
Definition: st7567_base.h:43
virtual void command(uint8_t value)=0
uint16_t y
Definition: tt21100.cpp:18
void init_mirror_x(bool mirror_x)
Definition: st7567_base.h:44
int get_height_internal() override
void line(int x1, int y1, int x2, int y2, Color color=COLOR_ON)
Draw a straight line from the point [x1,y1] to [x2,y2] with the given color.
Definition: display.cpp:18
const float PROCESSOR
For components that use data from sensors like displays.
Definition: component.cpp:20
void set_scroll(uint8_t line)
int get_width_internal() override
void init_invert_colors(bool invert_colors)
Definition: st7567_base.h:46
void draw_absolute_pixel_internal(int x, int y, Color color) override
display::DisplayType get_display_type() override
Definition: st7567_base.h:64
float get_setup_priority() const override
Definition: st7567_base.h:61
void set_contrast(uint8_t val)
Definition: st7567_base.cpp:74
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void set_all_pixels_on(bool enable)
Definition: st7567_base.cpp:64