Create readable names for display commands
This commit is contained in:
parent
1c01b17f4d
commit
612f6a9fbc
68
eink.hpp
68
eink.hpp
@ -12,6 +12,23 @@ class Epd {
|
||||
static constexpr auto width = uint16_t{200};
|
||||
static constexpr auto height = uint16_t{200};
|
||||
|
||||
struct Cmd {
|
||||
static constexpr auto SW_RESET = uint8_t{0x12};
|
||||
static constexpr auto DRIVER_OUTPUT_CONTROL = uint8_t{0x01};
|
||||
static constexpr auto DATA_ENTRY_MODE = uint8_t{0x11};
|
||||
static constexpr auto SET_RAM_X_ADDR_POSITIONS = uint8_t{0x44};
|
||||
static constexpr auto SET_RAM_Y_ADDR_POSITIONS = uint8_t{0x45};
|
||||
static constexpr auto BORDER_WAVEFORM_CONTROL = uint8_t{0x3C};
|
||||
static constexpr auto READ_TEMPERATURE_SENSOR = uint8_t{0x18};
|
||||
static constexpr auto SET_RAM_X_ADDR = uint8_t{0x4E};
|
||||
static constexpr auto SET_RAM_Y_ADDR = uint8_t{0x4F};
|
||||
static constexpr auto WRITE_RAM_BLACK = uint8_t{0x24};
|
||||
static constexpr auto WRITE_RAM_RED = uint8_t{0x26};
|
||||
static constexpr auto DISPLAY_UPDATE_CONTROL_2 = uint8_t{0x22};
|
||||
static constexpr auto UPDATE_DISPLAY = uint8_t{0x20};
|
||||
static constexpr auto DEEP_SLEEP_MODE = uint8_t{0x10};
|
||||
};
|
||||
|
||||
io::Pin<RstPin> m_rst;
|
||||
io::Pin<DcPin> m_dc;
|
||||
io::Pin<BusyPin> m_bsy;
|
||||
@ -27,45 +44,44 @@ class Epd {
|
||||
m_bsy.dir(io::Dir::IN);
|
||||
Spi::init();
|
||||
|
||||
/* EPD hardware init start */
|
||||
Reset();
|
||||
|
||||
WaitUntilIdle();
|
||||
SendCommand(0x12); // SWRESET
|
||||
SendCommand(Cmd::SW_RESET);
|
||||
WaitUntilIdle();
|
||||
|
||||
SendCommand(0x01); // Driver output control
|
||||
SendCommand(Cmd::DRIVER_OUTPUT_CONTROL);
|
||||
SendData(0xC7);
|
||||
SendData(0x00);
|
||||
SendData(0x01);
|
||||
|
||||
SendCommand(0x11); // data entry mode
|
||||
SendCommand(Cmd::DATA_ENTRY_MODE);
|
||||
SendData(0x01);
|
||||
|
||||
SendCommand(0x44); // set Ram-X address start/end position
|
||||
SendCommand(Cmd::SET_RAM_X_ADDR_POSITIONS);
|
||||
SendData(0x00);
|
||||
SendData(0x18); // 0x18-->(24+1)*8=200
|
||||
SendData((width / 8) - 1);
|
||||
|
||||
SendCommand(0x45); // set Ram-Y address start/end position
|
||||
SendData(0xC7); // 0xC7-->(199+1)=200
|
||||
SendCommand(Cmd::SET_RAM_Y_ADDR_POSITIONS);
|
||||
SendData(height - 1);
|
||||
SendData(0x00);
|
||||
SendData(0x00);
|
||||
SendData(0x00);
|
||||
|
||||
SendCommand(0x3C); // BorderWavefrom
|
||||
SendCommand(Cmd::BORDER_WAVEFORM_CONTROL);
|
||||
SendData(0x05);
|
||||
|
||||
SendCommand(0x18); // Read built-in temperature sensor
|
||||
SendCommand(Cmd::READ_TEMPERATURE_SENSOR);
|
||||
SendData(0x80);
|
||||
|
||||
SendCommand(0x4E); // set RAM x address count to 0;
|
||||
SendCommand(Cmd::SET_RAM_X_ADDR);
|
||||
SendData(0x00);
|
||||
SendCommand(0x4F); // set RAM y address count to 0X199;
|
||||
SendData(0xC7);
|
||||
SendData(0x00);
|
||||
WaitUntilIdle();
|
||||
|
||||
/* EPD hardware init end */
|
||||
SendCommand(Cmd::SET_RAM_Y_ADDR);
|
||||
SendData(height - 1);
|
||||
SendData(0x00);
|
||||
|
||||
WaitUntilIdle();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -101,42 +117,42 @@ class Epd {
|
||||
|
||||
void DisplayFrame(const unsigned char *frame_buffer_black, const unsigned char *frame_buffer_red)
|
||||
{
|
||||
SendCommand(0x24);
|
||||
SendCommand(Cmd::WRITE_RAM_BLACK);
|
||||
for (auto i = uint16_t{0}; i < width * height / 8; i++) {
|
||||
SendData(pgm_read_byte(&frame_buffer_black[i]));
|
||||
}
|
||||
SendCommand(0x26);
|
||||
SendCommand(Cmd::WRITE_RAM_RED);
|
||||
for (auto i = uint16_t{0}; i < width * height / 8; i++) {
|
||||
SendData(~pgm_read_byte(&frame_buffer_red[i]));
|
||||
}
|
||||
|
||||
SendCommand(0x22);
|
||||
SendCommand(Cmd::DISPLAY_UPDATE_CONTROL_2);
|
||||
SendData(0xF7);
|
||||
SendCommand(0x20);
|
||||
SendCommand(Cmd::UPDATE_DISPLAY);
|
||||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
void DisplayClear()
|
||||
{
|
||||
SendCommand(0x24);
|
||||
SendCommand(Cmd::WRITE_RAM_BLACK);
|
||||
for (auto i = uint16_t{0}; i < width * height / 8; i++) {
|
||||
SendData(0xff);
|
||||
}
|
||||
SendCommand(0x26);
|
||||
SendCommand(Cmd::WRITE_RAM_RED);
|
||||
for (auto i = uint16_t{0}; i < width * height / 8; i++) {
|
||||
SendData(0x00);
|
||||
}
|
||||
|
||||
SendCommand(0x22);
|
||||
SendCommand(Cmd::DISPLAY_UPDATE_CONTROL_2);
|
||||
SendData(0xF7);
|
||||
SendCommand(0x20);
|
||||
SendCommand(Cmd::UPDATE_DISPLAY);
|
||||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
void Sleep()
|
||||
{
|
||||
SendCommand(0x10); // power setting
|
||||
SendData(0x01); // gate switch to external
|
||||
SendCommand(Cmd::DEEP_SLEEP_MODE);
|
||||
SendData(0x01);
|
||||
_delay_ms(100);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user