Skip to content

Commit 35c3adf

Browse files
Merge pull request #154 from wangxiangwangeuse/master
增加了2.13和2.9墨水屏的驱动文件
2 parents 2da796f + 3612358 commit 35c3adf

File tree

3 files changed

+705
-28
lines changed

3 files changed

+705
-28
lines changed

src/HT_DEPG0290BxS800FxX_BW.h

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#ifndef __DEPG0290BxS800FxX_BW_H__
2+
#define __DEPG0290BxS800FxX_BW_H__
3+
4+
#include <HT_Display.h>
5+
#include <SPI.h>
6+
7+
8+
class DEPG0290BxS800FxX_BW : public ScreenDisplay {
9+
private:
10+
uint8_t _rst;
11+
uint8_t _dc;
12+
int8_t _cs;
13+
int8_t _clk;
14+
int8_t _mosi;
15+
int8_t _miso;
16+
uint32_t _freq;
17+
uint8_t _spi_num;
18+
int8_t _busy;
19+
uint8_t _bbf[4736];
20+
SPISettings _spiSettings;
21+
22+
public:
23+
DEPG0290BxS800FxX_BW(uint8_t _rst, uint8_t _dc, int8_t _cs, int8_t _busy, int8_t _sck, int8_t _mosi,int8_t _miso,uint32_t _freq = 6000000, DISPLAY_GEOMETRY g =
24+
GEOMETRY_296_128) {
25+
setGeometry(g);
26+
this->_rst = _rst;
27+
this->_dc = _dc;
28+
this->_cs = _cs;
29+
this->_freq = _freq;
30+
this->_clk = _sck;
31+
this->_mosi = _mosi;
32+
this->_miso = _miso;
33+
this->_busy = _busy;
34+
this->displayType = E_INK;
35+
}
36+
37+
bool connect(){
38+
pinMode(_dc, OUTPUT);
39+
pinMode(_rst, OUTPUT);
40+
pinMode(_cs, OUTPUT);
41+
digitalWrite(_cs, HIGH);
42+
pinMode(_busy, INPUT);
43+
this->buffer = _bbf;
44+
SPI.begin (this->_clk,this->_miso,this->_mosi);
45+
_spiSettings._clock=this->_freq;
46+
// Pulse Reset low for 10ms
47+
digitalWrite(_rst, HIGH);
48+
delay(100);
49+
digitalWrite(_rst, LOW);
50+
delay(100);
51+
digitalWrite(_rst, HIGH);
52+
return true;
53+
}
54+
55+
void display(void) {
56+
57+
if(rotate_angle==ANGLE_0_DEGREE||rotate_angle==ANGLE_180_DEGREE)
58+
{
59+
sendCommand(0x24);
60+
digitalWrite(_cs,LOW);
61+
int xmax=this->width();
62+
int ymax=this->height()>>3;
63+
if(rotate_angle==ANGLE_0_DEGREE)
64+
{
65+
SPI.beginTransaction(SPISettings(6000000, LSBFIRST, SPI_MODE0));
66+
for(int x=0;x<xmax;x++)
67+
{
68+
for(int y=0;y<ymax;y++)
69+
{
70+
SPI.transfer(~buffer[x + y * xmax]);
71+
}
72+
}
73+
}
74+
else
75+
{
76+
SPI.beginTransaction(SPISettings(6000000, MSBFIRST, SPI_MODE0));
77+
for(int x=xmax-1;x>=0;x--)
78+
{
79+
for(int y=(ymax-1);y>=0;y--)
80+
{
81+
SPI.transfer(~buffer[x + y * xmax]);
82+
}
83+
}
84+
}
85+
SPI.endTransaction();
86+
digitalWrite(_cs,HIGH);
87+
sendCommand(0x20);
88+
WaitUntilIdle();
89+
}
90+
else
91+
{
92+
uint8_t buffer_rotate[displayBufferSize];
93+
memset(buffer_rotate,0,displayBufferSize);
94+
uint8_t temp;
95+
for(uint16_t i=0;i<this->width();i++)
96+
{
97+
for(uint16_t j=0;j<this->height();j++)
98+
{
99+
temp = buffer[(j>>3)*this->width()+i]>>(j&7)&0x01;
100+
buffer_rotate[(i>>3)*this->height()+j]|=(temp<<(i&7));
101+
}
102+
}
103+
sendCommand(0x24);
104+
digitalWrite(_cs,LOW);
105+
int xmax=this->height();
106+
int ymax=this->width()>>3;
107+
if(rotate_angle==ANGLE_90_DEGREE)
108+
{
109+
SPI.beginTransaction(SPISettings(6000000, MSBFIRST, SPI_MODE0));
110+
for(int x=0;x<xmax;x++)
111+
{
112+
for(int y=ymax-1;y>=0;y--)
113+
{
114+
SPI.transfer(~buffer_rotate[x + y * xmax]);
115+
}
116+
}
117+
}
118+
else
119+
{
120+
SPI.beginTransaction(SPISettings(6000000, LSBFIRST, SPI_MODE0));
121+
for(int x=xmax-1;x>=0;x--)
122+
{
123+
for(int y=0;y<ymax;y++)
124+
{
125+
SPI.transfer(~buffer_rotate[x + y * xmax]);
126+
}
127+
}
128+
}
129+
SPI.endTransaction();
130+
digitalWrite(_cs,HIGH);
131+
sendCommand(0x20);
132+
WaitUntilIdle();
133+
}
134+
}
135+
136+
void stop(){
137+
end();
138+
}
139+
140+
private:
141+
int getBufferOffset(void) {
142+
return 0;
143+
}
144+
145+
void WaitUntilIdle()
146+
{
147+
while(digitalRead(_busy)) { //LOW: idle, HIGH: busy
148+
delay(1);
149+
}
150+
delay(100);
151+
}
152+
inline void sendCommand(uint8_t com) __attribute__((always_inline)){
153+
digitalWrite(_dc, LOW);
154+
digitalWrite(_cs,LOW);
155+
SPI.beginTransaction(_spiSettings);
156+
SPI.transfer(com);
157+
SPI.endTransaction();
158+
digitalWrite(_cs,HIGH);
159+
digitalWrite(_dc, HIGH);
160+
}
161+
void sendData(unsigned char data) {
162+
digitalWrite(this->_cs, LOW);
163+
SPI.transfer(data);
164+
digitalWrite(this->_cs, HIGH);
165+
}
166+
167+
void sendInitCommands(void)
168+
{
169+
if (geometry == GEOMETRY_RAWMODE)
170+
return;
171+
WaitUntilIdle();
172+
sendCommand(0x12); // soft reset
173+
WaitUntilIdle();
174+
175+
}
176+
void sendScreenRotateCommand(){}
177+
};
178+
179+
#endif

0 commit comments

Comments
 (0)