Skip to content

Commit 8ddfa25

Browse files
committed
Support color depth for 8 colors screen
Replace LS013B7DH06 from Breakout Board and tested. It needs tripled RAM size than mono screen.
1 parent ebb82a6 commit 8ddfa25

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

Adafruit_SharpMem.cpp

+22-15
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ All text above, and the splash screen must be included in any redistribution
7070
*/
7171
Adafruit_SharpMem::Adafruit_SharpMem(uint8_t clk, uint8_t mosi, uint8_t cs,
7272
uint16_t width, uint16_t height,
73-
uint32_t freq)
73+
uint8_t color_depth_bits, uint32_t freq)
7474
: Adafruit_GFX(width, height) {
7575
_cs = cs;
76+
_color_depth_bits = color_depth_bits;
7677
if (spidev) {
7778
delete spidev;
7879
}
@@ -91,9 +92,10 @@ Adafruit_SharpMem::Adafruit_SharpMem(uint8_t clk, uint8_t mosi, uint8_t cs,
9192
*/
9293
Adafruit_SharpMem::Adafruit_SharpMem(SPIClass *theSPI, uint8_t cs,
9394
uint16_t width, uint16_t height,
94-
uint32_t freq)
95+
uint8_t color_depth_bits, uint32_t freq)
9596
: Adafruit_GFX(width, height) {
9697
_cs = cs;
98+
_color_depth_bits = color_depth_bits;
9799
if (spidev) {
98100
delete spidev;
99101
}
@@ -118,7 +120,7 @@ boolean Adafruit_SharpMem::begin(void) {
118120
// Set the vcom bit to a defined state
119121
_sharpmem_vcom = SHARPMEM_BIT_VCOM;
120122

121-
sharpmem_buffer = (uint8_t *)malloc((WIDTH * HEIGHT) / 8);
123+
sharpmem_buffer = (uint8_t *)malloc((WIDTH * HEIGHT * _color_depth_bits) / 8);
122124

123125
if (!sharpmem_buffer)
124126
return false;
@@ -165,11 +167,14 @@ void Adafruit_SharpMem::drawPixel(int16_t x, int16_t y, uint16_t color) {
165167
y = HEIGHT - 1 - y;
166168
break;
167169
}
168-
169-
if (color) {
170-
sharpmem_buffer[(y * WIDTH + x) / 8] |= pgm_read_byte(&set[x & 7]);
171-
} else {
172-
sharpmem_buffer[(y * WIDTH + x) / 8] &= pgm_read_byte(&clr[x & 7]);
170+
for (int i = 0; i < _color_depth_bits; i++) {
171+
if (color & set[i]) {
172+
sharpmem_buffer[((y * WIDTH + x) * _color_depth_bits + i) / 8] |=
173+
pgm_read_byte(&set[(x * _color_depth_bits + i) & 7]);
174+
} else {
175+
sharpmem_buffer[((y * WIDTH + x) * _color_depth_bits + i) / 8] &=
176+
pgm_read_byte(&clr[(x * _color_depth_bits + i) & 7]);
177+
}
173178
}
174179
}
175180

@@ -204,8 +209,10 @@ uint8_t Adafruit_SharpMem::getPixel(uint16_t x, uint16_t y) {
204209
break;
205210
}
206211

207-
return sharpmem_buffer[(y * WIDTH + x) / 8] & pgm_read_byte(&set[x & 7]) ? 1
208-
: 0;
212+
return sharpmem_buffer[(y * WIDTH + x) * _color_depth_bits / 8] &
213+
pgm_read_byte(&set[x * _color_depth_bits & 7])
214+
? 1
215+
: 0;
209216
}
210217

211218
/**************************************************************************/
@@ -214,7 +221,7 @@ uint8_t Adafruit_SharpMem::getPixel(uint16_t x, uint16_t y) {
214221
*/
215222
/**************************************************************************/
216223
void Adafruit_SharpMem::clearDisplay() {
217-
memset(sharpmem_buffer, 0xff, (WIDTH * HEIGHT) / 8);
224+
memset(sharpmem_buffer, 0xff, (WIDTH * HEIGHT * _color_depth_bits) / 8);
218225

219226
spidev->beginTransaction();
220227
// Send the clear screen command rather than doing a HW refresh (quicker)
@@ -244,14 +251,14 @@ void Adafruit_SharpMem::refresh(void) {
244251
spidev->transfer(_sharpmem_vcom | SHARPMEM_BIT_WRITECMD);
245252
TOGGLE_VCOM;
246253

247-
uint8_t bytes_per_line = WIDTH / 8;
248-
uint16_t totalbytes = (WIDTH * HEIGHT) / 8;
254+
uint8_t bytes_per_line = WIDTH * _color_depth_bits / 8;
255+
uint16_t totalbytes = (WIDTH * HEIGHT * _color_depth_bits) / 8;
249256

250257
for (i = 0; i < totalbytes; i += bytes_per_line) {
251258
uint8_t line[bytes_per_line + 2];
252259

253260
// Send address byte
254-
currentline = ((i + 1) / (WIDTH / 8)) + 1;
261+
currentline = ((i + 1) / (WIDTH * _color_depth_bits / 8)) + 1;
255262
line[0] = currentline;
256263
// copy over this line
257264
memcpy(line + 1, sharpmem_buffer + i, bytes_per_line);
@@ -273,5 +280,5 @@ void Adafruit_SharpMem::refresh(void) {
273280
*/
274281
/**************************************************************************/
275282
void Adafruit_SharpMem::clearDisplayBuffer() {
276-
memset(sharpmem_buffer, 0xff, (WIDTH * HEIGHT) / 8);
283+
memset(sharpmem_buffer, 0xff, (WIDTH * HEIGHT * _color_depth_bits) / 8);
277284
}

Adafruit_SharpMem.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ All text above, and the splash screen must be included in any redistribution
3737
class Adafruit_SharpMem : public Adafruit_GFX {
3838
public:
3939
Adafruit_SharpMem(uint8_t clk, uint8_t mosi, uint8_t cs, uint16_t w = 96,
40-
uint16_t h = 96, uint32_t freq = 2000000);
40+
uint16_t h = 96, uint8_t color_depth_bits = 1,
41+
uint32_t freq = 2000000);
4142
Adafruit_SharpMem(SPIClass *theSPI, uint8_t cs, uint16_t w = 96,
42-
uint16_t h = 96, uint32_t freq = 2000000);
43+
uint16_t h = 96, uint8_t color_depth_bits = 1,
44+
uint32_t freq = 2000000);
4345
boolean begin();
4446
void drawPixel(int16_t x, int16_t y, uint16_t color);
4547
uint8_t getPixel(uint16_t x, uint16_t y);
@@ -52,6 +54,7 @@ class Adafruit_SharpMem : public Adafruit_GFX {
5254
uint8_t *sharpmem_buffer = NULL;
5355
uint8_t _cs;
5456
uint8_t _sharpmem_vcom;
57+
uint8_t _color_depth_bits;
5558
};
5659

5760
#endif

examples/sharpmemtest/sharpmemtest.ino

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ All text above, must be included in any redistribution
2424
#define SHARP_MOSI 11
2525
#define SHARP_SS 10
2626

27+
// Set the size and color depth, default is 1 bit depth.
28+
// For example: 3 bits for LS013B7DH06 (8 colors 128x128 display)
29+
// Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 128, 128, 3);
30+
2731
// Set the size of the display here, e.g. 144x168!
2832
Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
2933
// The currently-available SHARP Memory Display (144x168 pixels)

0 commit comments

Comments
 (0)