ESPHome 2026.11.0b6
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
8ESPHOME_LOG_TAG(TAG, "pcd_8544");
9
11 this->spi_setup();
12 pulse_reset(this->reset_pin_, {.high_before_ms = 1, .low_ms = 10});
13 this->dc_pin_->setup();
14}
15
18
20 // LCD bias select (4 is optimal?)
21 this->command(this->PCD8544_SETBIAS | 0x04);
22
23 // contrast
24 this->command(this->PCD8544_SETVOP | this->contrast_);
25
26 // normal mode
27 this->command(this->PCD8544_FUNCTIONSET);
28
29 // Set display to Normal
31}
32
34 this->dc_pin_->digital_write(false);
35 this->enable();
36}
37void PCD8544::end_command_() { this->disable(); }
39 this->dc_pin_->digital_write(true);
40 this->enable();
41}
42void PCD8544::end_data_() { this->disable(); }
43
44int PCD8544::get_width_internal() { return 84; }
45int PCD8544::get_height_internal() { return 48; }
46
48 return size_t(this->get_width_internal()) * size_t(this->get_height_internal()) / 8u;
49}
50
51void HOT PCD8544::display() {
52 uint8_t col, maxcol, p;
53
54 for (p = 0; p < 6; p++) {
55 this->command(this->PCD8544_SETYADDR | p);
56
57 // start at the beginning of the row
58 col = 0;
59 maxcol = this->get_width_internal() - 1;
60
61 this->command(this->PCD8544_SETXADDR | col);
62
63 this->start_data_();
64 for (; col <= maxcol; col++) {
65 this->write_byte(this->buffer_[(this->get_width_internal() * p) + col]);
66 }
67 this->end_data_();
68 }
69
70 this->command(this->PCD8544_SETYADDR);
71}
72
74 if (x >= this->get_width_internal() || y >= this->get_height_internal() || x < 0 || y < 0) {
75 return;
76 }
77
78 uint16_t pos = x + (y / 8) * this->get_width_internal();
79 uint8_t subpos = y % 8;
80 assign_bits(this->buffer_[pos], 1 << subpos, color.is_on());
81}
82
84 LOG_DISPLAY("", "PCD8544", this);
85 LOG_PIN(" DC Pin: ", this->dc_pin_);
86 LOG_PIN(" Reset Pin: ", this->reset_pin_);
87 LOG_UPDATE_INTERVAL(this);
88}
89
90void PCD8544::command(uint8_t value) {
91 this->start_command_();
92 this->write_byte(value);
93 this->end_command_();
94}
95
97 this->do_update_();
98 this->display();
99}
100
101void PCD8544::fill(Color color) {
102 // If clipping is active, fall back to base implementation
103 if (this->get_clipping().is_set()) {
104 Display::fill(color);
105 return;
106 }
107
108 uint8_t fill = color.is_on() ? 0xFF : 0x00;
109 for (uint32_t i = 0; i < this->get_buffer_length_(); i++)
110 this->buffer_[i] = fill;
111}
112
113} // 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:826
const uint8_t PCD8544_EXTENDEDINSTRUCTION
Definition pcd_8544.h:15
int get_width_internal() override
Definition pcd_8544.cpp:44
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:45
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:73
const uint8_t PCD8544_SETXADDR
Definition pcd_8544.h:25
void update() override
Definition pcd_8544.cpp:96
const uint8_t PCD8544_SETBIAS
Definition pcd_8544.h:28
void command(uint8_t value)
Definition pcd_8544.cpp:90
void fill(Color color) override
Definition pcd_8544.cpp:101
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:83
ESPHOME_LOG_TAG(TAG, "pcd_8544")
uint32_t value
Definition hal.cpp:41
ESPHOME_ALWAYS_INLINE constexpr void assign_bits(T &value, std::type_identity_t< T > mask, bool on)
Set the bits of mask in value when on is true, clear them otherwise.
Definition helpers.h:1150
size_t size_t pos
Definition helpers.h:1333
ESPHOME_ALWAYS_INLINE void pulse_reset(GPIOPin *pin, ResetPulse pulse)
Set up an active-low reset pin and drive it through pulse.
Definition gpio_pin.h:163
static void uint32_t
bool is_on() const ESPHOME_ALWAYS_INLINE
Definition color.h:76
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6