@@ -70,9 +70,10 @@ All text above, and the splash screen must be included in any redistribution
70
70
*/
71
71
Adafruit_SharpMem::Adafruit_SharpMem (uint8_t clk, uint8_t mosi, uint8_t cs,
72
72
uint16_t width, uint16_t height,
73
- uint32_t freq)
73
+ uint8_t color_depth_bits, uint32_t freq)
74
74
: Adafruit_GFX(width, height) {
75
75
_cs = cs;
76
+ _color_depth_bits = color_depth_bits;
76
77
if (spidev) {
77
78
delete spidev;
78
79
}
@@ -91,9 +92,10 @@ Adafruit_SharpMem::Adafruit_SharpMem(uint8_t clk, uint8_t mosi, uint8_t cs,
91
92
*/
92
93
Adafruit_SharpMem::Adafruit_SharpMem (SPIClass *theSPI, uint8_t cs,
93
94
uint16_t width, uint16_t height,
94
- uint32_t freq)
95
+ uint8_t color_depth_bits, uint32_t freq)
95
96
: Adafruit_GFX(width, height) {
96
97
_cs = cs;
98
+ _color_depth_bits = color_depth_bits;
97
99
if (spidev) {
98
100
delete spidev;
99
101
}
@@ -118,7 +120,7 @@ boolean Adafruit_SharpMem::begin(void) {
118
120
// Set the vcom bit to a defined state
119
121
_sharpmem_vcom = SHARPMEM_BIT_VCOM;
120
122
121
- sharpmem_buffer = (uint8_t *)malloc ((WIDTH * HEIGHT) / 8 );
123
+ sharpmem_buffer = (uint8_t *)malloc ((WIDTH * HEIGHT * _color_depth_bits ) / 8 );
122
124
123
125
if (!sharpmem_buffer)
124
126
return false ;
@@ -165,11 +167,14 @@ void Adafruit_SharpMem::drawPixel(int16_t x, int16_t y, uint16_t color) {
165
167
y = HEIGHT - 1 - y;
166
168
break ;
167
169
}
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
+ }
173
178
}
174
179
}
175
180
@@ -204,8 +209,10 @@ uint8_t Adafruit_SharpMem::getPixel(uint16_t x, uint16_t y) {
204
209
break ;
205
210
}
206
211
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 ;
209
216
}
210
217
211
218
/* *************************************************************************/
@@ -214,7 +221,7 @@ uint8_t Adafruit_SharpMem::getPixel(uint16_t x, uint16_t y) {
214
221
*/
215
222
/* *************************************************************************/
216
223
void Adafruit_SharpMem::clearDisplay () {
217
- memset (sharpmem_buffer, 0xff , (WIDTH * HEIGHT) / 8 );
224
+ memset (sharpmem_buffer, 0xff , (WIDTH * HEIGHT * _color_depth_bits ) / 8 );
218
225
219
226
spidev->beginTransaction ();
220
227
// Send the clear screen command rather than doing a HW refresh (quicker)
@@ -244,14 +251,14 @@ void Adafruit_SharpMem::refresh(void) {
244
251
spidev->transfer (_sharpmem_vcom | SHARPMEM_BIT_WRITECMD);
245
252
TOGGLE_VCOM;
246
253
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 ;
249
256
250
257
for (i = 0 ; i < totalbytes; i += bytes_per_line) {
251
258
uint8_t line[bytes_per_line + 2 ];
252
259
253
260
// Send address byte
254
- currentline = ((i + 1 ) / (WIDTH / 8 )) + 1 ;
261
+ currentline = ((i + 1 ) / (WIDTH * _color_depth_bits / 8 )) + 1 ;
255
262
line[0 ] = currentline;
256
263
// copy over this line
257
264
memcpy (line + 1 , sharpmem_buffer + i, bytes_per_line);
@@ -273,5 +280,5 @@ void Adafruit_SharpMem::refresh(void) {
273
280
*/
274
281
/* *************************************************************************/
275
282
void Adafruit_SharpMem::clearDisplayBuffer () {
276
- memset (sharpmem_buffer, 0xff , (WIDTH * HEIGHT) / 8 );
283
+ memset (sharpmem_buffer, 0xff , (WIDTH * HEIGHT * _color_depth_bits ) / 8 );
277
284
}
0 commit comments