225 lines
5.2 KiB
C++
225 lines
5.2 KiB
C++
/**
|
|
* @filename : epd1in54b.h
|
|
* @brief : Header file for e-paper display library epd1in54b.cpp
|
|
* @author : Yehui from Waveshare
|
|
*
|
|
* Copyright (C) Waveshare August 10 2017
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documnetation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
#ifndef EPD1IN54B_H
|
|
#define EPD1IN54B_H
|
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
#include "../clock.hpp"
|
|
#include "../io/io.hpp"
|
|
|
|
// Display resolution
|
|
#define EPD_WIDTH 200
|
|
#define EPD_HEIGHT 200
|
|
|
|
// EPD1IN54B commands
|
|
#define PANEL_SETTING 0x00
|
|
#define POWER_SETTING 0x01
|
|
#define POWER_OFF 0x02
|
|
#define POWER_OFF_SEQUENCE_SETTING 0x03
|
|
#define POWER_ON 0x04
|
|
#define POWER_ON_MEASURE 0x05
|
|
#define BOOSTER_SOFT_START 0x06
|
|
#define DEEP_SLEEP 0x07
|
|
#define DATA_START_TRANSMISSION_1 0x10
|
|
#define DATA_STOP 0x11
|
|
#define DISPLAY_REFRESH 0x12
|
|
#define DATA_START_TRANSMISSION_2 0x13
|
|
#define PLL_CONTROL 0x30
|
|
#define TEMPERATURE_SENSOR_COMMAND 0x40
|
|
#define TEMPERATURE_SENSOR_CALIBRATION 0x41
|
|
#define TEMPERATURE_SENSOR_WRITE 0x42
|
|
#define TEMPERATURE_SENSOR_READ 0x43
|
|
#define VCOM_AND_DATA_INTERVAL_SETTING 0x50
|
|
#define LOW_POWER_DETECTION 0x51
|
|
#define TCON_SETTING 0x60
|
|
#define TCON_RESOLUTION 0x61
|
|
#define SOURCE_AND_GATE_START_SETTING 0x62
|
|
#define GET_STATUS 0x71
|
|
#define AUTO_MEASURE_VCOM 0x80
|
|
#define VCOM_VALUE 0x81
|
|
#define VCM_DC_SETTING_REGISTER 0x82
|
|
#define PROGRAM_MODE 0xA0
|
|
#define ACTIVE_PROGRAM 0xA1
|
|
#define READ_OTP_DATA 0xA2
|
|
|
|
// Pin definition
|
|
#define RST_PIN io::P::C1
|
|
#define DC_PIN io::P::C0
|
|
#define BUSY_PIN io::P::C2
|
|
|
|
template <typename Spi>
|
|
class Epd {
|
|
public:
|
|
unsigned long width;
|
|
unsigned long height;
|
|
|
|
Epd()
|
|
{
|
|
width = EPD_WIDTH;
|
|
height = EPD_HEIGHT;
|
|
}
|
|
|
|
~Epd() = default;
|
|
|
|
int Init()
|
|
{
|
|
/* this calls the peripheral hardware interface, see epdif */
|
|
io::Pin<RST_PIN>::dir(io::Dir::OUT);
|
|
io::Pin<DC_PIN>::dir(io::Dir::OUT);
|
|
io::Pin<BUSY_PIN>::dir(io::Dir::IN);
|
|
Spi::init();
|
|
|
|
/* EPD hardware init start */
|
|
Reset();
|
|
|
|
WaitUntilIdle();
|
|
SendCommand(0x12); // SWRESET
|
|
WaitUntilIdle();
|
|
|
|
SendCommand(0x01); // Driver output control
|
|
SendData(0xC7);
|
|
SendData(0x00);
|
|
SendData(0x01);
|
|
|
|
SendCommand(0x11); // data entry mode
|
|
SendData(0x01);
|
|
|
|
SendCommand(0x44); // set Ram-X address start/end position
|
|
SendData(0x00);
|
|
SendData(0x18); // 0x18-->(24+1)*8=200
|
|
|
|
SendCommand(0x45); // set Ram-Y address start/end position
|
|
SendData(0xC7); // 0xC7-->(199+1)=200
|
|
SendData(0x00);
|
|
SendData(0x00);
|
|
SendData(0x00);
|
|
|
|
SendCommand(0x3C); // BorderWavefrom
|
|
SendData(0x05);
|
|
|
|
SendCommand(0x18); // Read built-in temperature sensor
|
|
SendData(0x80);
|
|
|
|
SendCommand(0x4E); // set RAM x address count to 0;
|
|
SendData(0x00);
|
|
SendCommand(0x4F); // set RAM y address count to 0X199;
|
|
SendData(0xC7);
|
|
SendData(0x00);
|
|
WaitUntilIdle();
|
|
|
|
/* EPD hardware init end */
|
|
|
|
return 0;
|
|
}
|
|
|
|
void SendCommand(unsigned char command)
|
|
{
|
|
io::Pin<DC_PIN>::write(false);
|
|
SpiTransfer(command);
|
|
}
|
|
|
|
void SendData(unsigned char data)
|
|
{
|
|
io::Pin<DC_PIN>::write(true);
|
|
SpiTransfer(data);
|
|
}
|
|
|
|
void WaitUntilIdle()
|
|
{
|
|
while (io::Pin<BUSY_PIN>::read()) {
|
|
_delay_ms(100);
|
|
}
|
|
}
|
|
|
|
void Reset()
|
|
{
|
|
io::Pin<RST_PIN>::write(true);
|
|
_delay_ms(200);
|
|
io::Pin<RST_PIN>::write(false); // module reset
|
|
_delay_ms(10);
|
|
io::Pin<RST_PIN>::write(true);
|
|
_delay_ms(200);
|
|
}
|
|
|
|
void DisplayFrame(const unsigned char *frame_buffer_black, const unsigned char *frame_buffer_red)
|
|
{
|
|
unsigned int i;
|
|
|
|
SendCommand(0x24);
|
|
for (i = 0; i < this->width * this->height / 8; i++) {
|
|
SendData(pgm_read_byte(&frame_buffer_black[i]));
|
|
}
|
|
SendCommand(0x26);
|
|
for (i = 0; i < this->width * this->height / 8; i++) {
|
|
SendData(~pgm_read_byte(&frame_buffer_red[i]));
|
|
}
|
|
|
|
SendCommand(0x22);
|
|
SendData(0xF7);
|
|
SendCommand(0x20);
|
|
WaitUntilIdle();
|
|
}
|
|
|
|
void DisplayClear()
|
|
{
|
|
unsigned int i;
|
|
|
|
SendCommand(0x24);
|
|
for (i = 0; i < this->width * this->height / 8; i++) {
|
|
SendData(0xff);
|
|
}
|
|
SendCommand(0x26);
|
|
for (i = 0; i < this->width * this->height / 8; i++) {
|
|
SendData(0x00);
|
|
}
|
|
|
|
SendCommand(0x22);
|
|
SendData(0xF7);
|
|
SendCommand(0x20);
|
|
WaitUntilIdle();
|
|
}
|
|
|
|
void Sleep()
|
|
{
|
|
SendCommand(0x10); // power setting
|
|
SendData(0x01); // gate switch to external
|
|
_delay_ms(100);
|
|
}
|
|
|
|
void SpiTransfer(unsigned char data)
|
|
{
|
|
Spi::select(true);
|
|
Spi::transfer(data);
|
|
Spi::select(false);
|
|
}
|
|
};
|
|
|
|
#endif /* EPD1IN54B_H */
|
|
|
|
/* END OF FILE */
|