ESPHome 2025.5.0
Loading...
Searching...
No Matches
st7567_base.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7namespace esphome {
8namespace st7567_base {
9
10static const uint8_t ST7567_BOOSTER_ON = 0x2C; // internal power supply on
11static const uint8_t ST7567_REGULATOR_ON = 0x2E; // internal power supply on
12static const uint8_t ST7567_POWER_ON = 0x2F; // internal power supply on
13
14static const uint8_t ST7567_DISPLAY_ON = 0xAF; // Display ON. Normal Display Mode.
15static const uint8_t ST7567_DISPLAY_OFF = 0xAE; // Display OFF. All SEGs/COMs output with VSS
16static const uint8_t ST7567_SET_START_LINE = 0x40;
17static const uint8_t ST7567_POWER_CTL = 0x28;
18static const uint8_t ST7567_SEG_NORMAL = 0xA0; //
19static const uint8_t ST7567_SEG_REVERSE = 0xA1; // mirror X axis (horizontal)
20static const uint8_t ST7567_COM_NORMAL = 0xC0; //
21static const uint8_t ST7567_COM_REMAP = 0xC8; // mirror Y axis (vertical)
22static const uint8_t ST7567_PIXELS_NORMAL = 0xA4; // display ram content
23static const uint8_t ST7567_PIXELS_ALL_ON = 0xA5; // all pixels on
24static const uint8_t ST7567_INVERT_OFF = 0xA6; // normal pixels
25static const uint8_t ST7567_INVERT_ON = 0xA7; // inverted pixels
26static const uint8_t ST7567_SCAN_START_LINE = 0x40; // scrolling = 0x40 + (0..63)
27static const uint8_t ST7567_COL_ADDR_H = 0x10; // x pos (0..95) 4 MSB
28static const uint8_t ST7567_COL_ADDR_L = 0x00; // x pos (0..95) 4 LSB
29static const uint8_t ST7567_PAGE_ADDR = 0xB0; // y pos, 8.5 rows (0..8)
30static const uint8_t ST7567_BIAS_9 = 0xA2;
31static const uint8_t ST7567_CONTRAST = 0x80; // 0x80 + (0..31)
32static const uint8_t ST7567_SET_EV_CMD = 0x81;
33static const uint8_t ST7567_SET_EV_PARAM = 0x00;
34static const uint8_t ST7567_RESISTOR_RATIO = 0x20;
35static 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_();
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
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 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
void init_mirror_x(bool mirror_x)
Definition st7567_base.h:44
void draw_absolute_pixel_internal(int x, int y, Color color) override
void init_mirror_y(bool mirror_y)
Definition st7567_base.h:45
void set_reset_pin(GPIOPin *reset_pin)
Definition st7567_base.h:43
void set_invert_colors(bool invert_colors)
float get_setup_priority() const override
Definition st7567_base.h:61
void set_scroll(uint8_t line)
void init_invert_colors(bool invert_colors)
Definition st7567_base.h:46
void set_all_pixels_on(bool enable)
virtual void command(uint8_t value)=0
void fill(Color color) override
void set_brightness(uint8_t val)
void set_contrast(uint8_t val)
virtual void write_display_data()=0
display::DisplayType get_display_type() override
Definition st7567_base.h:64
mopeka_std_values val[4]
const float PROCESSOR
For components that use data from sensors like displays.
Definition component.cpp:20
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6