ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
pcd_8544.cpp
Go to the documentation of this file.
1#include "pcd_8544.h"
4#include "esphome/core/log.h"
5
6namespace esphome::pcd8544 {
7
8static const char *const TAG = "pcd_8544";
9
11 this->spi_setup();
12 this->init_reset_();
13 this->dc_pin_->setup();
14}
15
17 if (this->reset_pin_ != nullptr) {
18 this->reset_pin_->setup();
19 this->reset_pin_->digital_write(true);
20 delay(1);
21 // Trigger Reset
22 this->reset_pin_->digital_write(false);
23 delay(10);
24 // Wake up
25 this->reset_pin_->digital_write(true);
26 }
27}
28
31
33 // LCD bias select (4 is optimal?)
34 this->command(this->PCD8544_SETBIAS | 0x04);
35
36 // contrast
37 this->command(this->PCD8544_SETVOP | this->contrast_);
38
39 // normal mode
40 this->command(this->PCD8544_FUNCTIONSET);
41
42 // Set display to Normal
44}
45
47 this->dc_pin_->digital_write(false);
48 this->enable();
49}
50void PCD8544::end_command_() { this->disable(); }
52 this->dc_pin_->digital_write(true);
53 this->enable();
54}
55void PCD8544::end_data_() { this->disable(); }
56
57int PCD8544::get_width_internal() { return 84; }
58int PCD8544::get_height_internal() { return 48; }
59
61 return size_t(this->get_width_internal()) * size_t(this->get_height_internal()) / 8u;
62}
63
64void HOT PCD8544::display() {
65 uint8_t col, maxcol, p;
66
67 for (p = 0; p < 6; p++) {
68 this->command(this->PCD8544_SETYADDR | p);
69
70 // start at the beginning of the row
71 col = 0;
72 maxcol = this->get_width_internal() - 1;
73
74 this->command(this->PCD8544_SETXADDR | col);
75
76 this->start_data_();
77 for (; col <= maxcol; col++) {
78 this->write_byte(this->buffer_[(this->get_width_internal() * p) + col]);
79 }
80 this->end_data_();
81 }
82
83 this->command(this->PCD8544_SETYADDR);
84}
85
87 if (x >= this->get_width_internal() || y >= this->get_height_internal() || x < 0 || y < 0) {
88 return;
89 }
90
91 uint16_t pos = x + (y / 8) * this->get_width_internal();
92 uint8_t subpos = y % 8;
93 if (color.is_on()) {
94 this->buffer_[pos] |= (1 << subpos);
95 } else {
96 this->buffer_[pos] &= ~(1 << subpos);
97 }
98}
99
101 LOG_DISPLAY("", "PCD8544", this);
102 LOG_PIN(" DC Pin: ", this->dc_pin_);
103 LOG_PIN(" Reset Pin: ", this->reset_pin_);
104 LOG_UPDATE_INTERVAL(this);
105}
106
107void PCD8544::command(uint8_t value) {
108 this->start_command_();
109 this->write_byte(value);
110 this->end_command_();
111}
112
114 this->do_update_();
115 this->display();
116}
117
118void PCD8544::fill(Color color) {
119 // If clipping is active, fall back to base implementation
120 if (this->get_clipping().is_set()) {
121 Display::fill(color);
122 return;
123 }
124
125 uint8_t fill = color.is_on() ? 0xFF : 0x00;
126 for (uint32_t i = 0; i < this->get_buffer_length_(); i++)
127 this->buffer_[i] = fill;
128}
129
130} // namespace esphome::pcd8544
virtual void setup()=0
virtual void digital_write(bool value)=0
void init_internal_(uint32_t buffer_length)
Rect get_clipping() const
Get the current the clipping rectangle.
Definition display.cpp:766
const uint8_t PCD8544_EXTENDEDINSTRUCTION
Definition pcd_8544.h:15
int get_width_internal() override
Definition pcd_8544.cpp:57
const uint8_t PCD8544_SETYADDR
Definition pcd_8544.h:24
const uint8_t PCD8544_SETVOP
Definition pcd_8544.h:29
int get_height_internal() override
Definition pcd_8544.cpp:58
const uint8_t PCD8544_FUNCTIONSET
Definition pcd_8544.h:22
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition pcd_8544.cpp:86
const uint8_t PCD8544_SETXADDR
Definition pcd_8544.h:25
void update() override
Definition pcd_8544.cpp:113
const uint8_t PCD8544_SETBIAS
Definition pcd_8544.h:28
void command(uint8_t value)
Definition pcd_8544.cpp:107
void fill(Color color) override
Definition pcd_8544.cpp:118
const uint8_t PCD8544_DISPLAYNORMAL
Definition pcd_8544.h:18
const uint8_t PCD8544_DISPLAYCONTROL
Definition pcd_8544.h:23
void dump_config() override
Definition pcd_8544.cpp:100
size_t size_t pos
Definition helpers.h:1038
void HOT delay(uint32_t ms)
Definition hal.cpp:85
static void uint32_t
bool is_on() ESPHOME_ALWAYS_INLINE
Definition color.h:70
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6