Skip to content

Commit 9d9c7fc

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 9d9c7fc

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

Adafruit_SharpMem.cpp

+25-16
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ All text above, and the splash screen must be included in any redistribution
6767
* @param height The display height
6868
* @param freq The SPI clock frequency desired (unlikely to be that fast in soft
6969
* spi mode!)
70+
* @param color_depth_bits The color depth in bits per pixel
7071
*/
7172
Adafruit_SharpMem::Adafruit_SharpMem(uint8_t clk, uint8_t mosi, uint8_t cs,
72-
uint16_t width, uint16_t height,
73-
uint32_t freq)
73+
uint16_t width, uint16_t height,uint32_t freq,
74+
uint8_t color_depth_bits)
7475
: Adafruit_GFX(width, height) {
7576
_cs = cs;
77+
_color_depth_bits = color_depth_bits;
7678
if (spidev) {
7779
delete spidev;
7880
}
@@ -87,13 +89,15 @@ Adafruit_SharpMem::Adafruit_SharpMem(uint8_t clk, uint8_t mosi, uint8_t cs,
8789
* @param cs The display chip select pin - **NOTE** this is ACTIVE HIGH!
8890
* @param width The display width
8991
* @param height The display height
92+
* @param color_depth_bits The color depth in bits per pixel
9093
* @param freq The SPI clock frequency desired
9194
*/
9295
Adafruit_SharpMem::Adafruit_SharpMem(SPIClass *theSPI, uint8_t cs,
9396
uint16_t width, uint16_t height,
94-
uint32_t freq)
97+
uint8_t color_depth_bits, uint32_t freq)
9598
: Adafruit_GFX(width, height) {
9699
_cs = cs;
100+
_color_depth_bits = color_depth_bits;
97101
if (spidev) {
98102
delete spidev;
99103
}
@@ -118,7 +122,7 @@ boolean Adafruit_SharpMem::begin(void) {
118122
// Set the vcom bit to a defined state
119123
_sharpmem_vcom = SHARPMEM_BIT_VCOM;
120124

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

123127
if (!sharpmem_buffer)
124128
return false;
@@ -165,11 +169,14 @@ void Adafruit_SharpMem::drawPixel(int16_t x, int16_t y, uint16_t color) {
165169
y = HEIGHT - 1 - y;
166170
break;
167171
}
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]);
172+
for (int i = 0; i < _color_depth_bits; i++) {
173+
if (color & set[i]) {
174+
sharpmem_buffer[((y * WIDTH + x) * _color_depth_bits + i) / 8] |=
175+
pgm_read_byte(&set[(x * _color_depth_bits + i) & 7]);
176+
} else {
177+
sharpmem_buffer[((y * WIDTH + x) * _color_depth_bits + i) / 8] &=
178+
pgm_read_byte(&clr[(x * _color_depth_bits + i) & 7]);
179+
}
173180
}
174181
}
175182

@@ -204,8 +211,10 @@ uint8_t Adafruit_SharpMem::getPixel(uint16_t x, uint16_t y) {
204211
break;
205212
}
206213

207-
return sharpmem_buffer[(y * WIDTH + x) / 8] & pgm_read_byte(&set[x & 7]) ? 1
208-
: 0;
214+
return sharpmem_buffer[(y * WIDTH + x) * _color_depth_bits / 8] &
215+
pgm_read_byte(&set[x * _color_depth_bits & 7])
216+
? 1
217+
: 0;
209218
}
210219

211220
/**************************************************************************/
@@ -214,7 +223,7 @@ uint8_t Adafruit_SharpMem::getPixel(uint16_t x, uint16_t y) {
214223
*/
215224
/**************************************************************************/
216225
void Adafruit_SharpMem::clearDisplay() {
217-
memset(sharpmem_buffer, 0xff, (WIDTH * HEIGHT) / 8);
226+
memset(sharpmem_buffer, 0xff, (WIDTH * HEIGHT * _color_depth_bits) / 8);
218227

219228
spidev->beginTransaction();
220229
// Send the clear screen command rather than doing a HW refresh (quicker)
@@ -244,14 +253,14 @@ void Adafruit_SharpMem::refresh(void) {
244253
spidev->transfer(_sharpmem_vcom | SHARPMEM_BIT_WRITECMD);
245254
TOGGLE_VCOM;
246255

247-
uint8_t bytes_per_line = WIDTH / 8;
248-
uint16_t totalbytes = (WIDTH * HEIGHT) / 8;
256+
uint8_t bytes_per_line = WIDTH * _color_depth_bits / 8;
257+
uint16_t totalbytes = (WIDTH * HEIGHT * _color_depth_bits) / 8;
249258

250259
for (i = 0; i < totalbytes; i += bytes_per_line) {
251260
uint8_t line[bytes_per_line + 2];
252261

253262
// Send address byte
254-
currentline = ((i + 1) / (WIDTH / 8)) + 1;
263+
currentline = ((i + 1) / (WIDTH * _color_depth_bits / 8)) + 1;
255264
line[0] = currentline;
256265
// copy over this line
257266
memcpy(line + 1, sharpmem_buffer + i, bytes_per_line);
@@ -273,5 +282,5 @@ void Adafruit_SharpMem::refresh(void) {
273282
*/
274283
/**************************************************************************/
275284
void Adafruit_SharpMem::clearDisplayBuffer() {
276-
memset(sharpmem_buffer, 0xff, (WIDTH * HEIGHT) / 8);
285+
memset(sharpmem_buffer, 0xff, (WIDTH * HEIGHT * _color_depth_bits) / 8);
277286
}

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,
41+
uint32_t freq = 2000000, uint8_t color_depth_bits = 1);
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,
44+
uint32_t freq = 2000000, uint8_t color_depth_bits = 1);
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, 2000000, 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)