@@ -67,12 +67,14 @@ All text above, and the splash screen must be included in any redistribution
67
67
* @param height The display height
68
68
* @param freq The SPI clock frequency desired (unlikely to be that fast in soft
69
69
* spi mode!)
70
+ * @param color_depth_bits The color depth in bits per pixel
70
71
*/
71
72
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 )
74
75
: Adafruit_GFX(width, height) {
75
76
_cs = cs;
77
+ _color_depth_bits = color_depth_bits;
76
78
if (spidev) {
77
79
delete spidev;
78
80
}
@@ -87,13 +89,15 @@ Adafruit_SharpMem::Adafruit_SharpMem(uint8_t clk, uint8_t mosi, uint8_t cs,
87
89
* @param cs The display chip select pin - **NOTE** this is ACTIVE HIGH!
88
90
* @param width The display width
89
91
* @param height The display height
92
+ * @param color_depth_bits The color depth in bits per pixel
90
93
* @param freq The SPI clock frequency desired
91
94
*/
92
95
Adafruit_SharpMem::Adafruit_SharpMem (SPIClass *theSPI, uint8_t cs,
93
96
uint16_t width, uint16_t height,
94
- uint32_t freq)
97
+ uint8_t color_depth_bits, uint32_t freq)
95
98
: Adafruit_GFX(width, height) {
96
99
_cs = cs;
100
+ _color_depth_bits = color_depth_bits;
97
101
if (spidev) {
98
102
delete spidev;
99
103
}
@@ -118,7 +122,7 @@ boolean Adafruit_SharpMem::begin(void) {
118
122
// Set the vcom bit to a defined state
119
123
_sharpmem_vcom = SHARPMEM_BIT_VCOM;
120
124
121
- sharpmem_buffer = (uint8_t *)malloc ((WIDTH * HEIGHT) / 8 );
125
+ sharpmem_buffer = (uint8_t *)malloc ((WIDTH * HEIGHT * _color_depth_bits ) / 8 );
122
126
123
127
if (!sharpmem_buffer)
124
128
return false ;
@@ -165,11 +169,14 @@ void Adafruit_SharpMem::drawPixel(int16_t x, int16_t y, uint16_t color) {
165
169
y = HEIGHT - 1 - y;
166
170
break ;
167
171
}
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
+ }
173
180
}
174
181
}
175
182
@@ -204,8 +211,10 @@ uint8_t Adafruit_SharpMem::getPixel(uint16_t x, uint16_t y) {
204
211
break ;
205
212
}
206
213
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 ;
209
218
}
210
219
211
220
/* *************************************************************************/
@@ -214,7 +223,7 @@ uint8_t Adafruit_SharpMem::getPixel(uint16_t x, uint16_t y) {
214
223
*/
215
224
/* *************************************************************************/
216
225
void Adafruit_SharpMem::clearDisplay () {
217
- memset (sharpmem_buffer, 0xff , (WIDTH * HEIGHT) / 8 );
226
+ memset (sharpmem_buffer, 0xff , (WIDTH * HEIGHT * _color_depth_bits ) / 8 );
218
227
219
228
spidev->beginTransaction ();
220
229
// Send the clear screen command rather than doing a HW refresh (quicker)
@@ -244,14 +253,14 @@ void Adafruit_SharpMem::refresh(void) {
244
253
spidev->transfer (_sharpmem_vcom | SHARPMEM_BIT_WRITECMD);
245
254
TOGGLE_VCOM;
246
255
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 ;
249
258
250
259
for (i = 0 ; i < totalbytes; i += bytes_per_line) {
251
260
uint8_t line[bytes_per_line + 2 ];
252
261
253
262
// Send address byte
254
- currentline = ((i + 1 ) / (WIDTH / 8 )) + 1 ;
263
+ currentline = ((i + 1 ) / (WIDTH * _color_depth_bits / 8 )) + 1 ;
255
264
line[0 ] = currentline;
256
265
// copy over this line
257
266
memcpy (line + 1 , sharpmem_buffer + i, bytes_per_line);
@@ -273,5 +282,5 @@ void Adafruit_SharpMem::refresh(void) {
273
282
*/
274
283
/* *************************************************************************/
275
284
void Adafruit_SharpMem::clearDisplayBuffer () {
276
- memset (sharpmem_buffer, 0xff , (WIDTH * HEIGHT) / 8 );
285
+ memset (sharpmem_buffer, 0xff , (WIDTH * HEIGHT * _color_depth_bits ) / 8 );
277
286
}
0 commit comments