@@ -202,41 +202,37 @@ void
202
202
Ili9341<Interface, Reset, Backlight, BufferSize>::drawHorizontalLine(
203
203
glcd::Point start, uint16_t length)
204
204
{
205
- uint16_t const pixelValue { modm::toBigEndian (foregroundColor.color ) };
206
205
auto minLength { std::min (std::size_t (length), BufferSize) };
207
- uint16_t *buffer16 { reinterpret_cast <uint16_t *>(buffer) };
208
- std::fill (buffer16, buffer16+minLength, pixelValue);
206
+ std::fill (buffer_rgb565, buffer_rgb565+minLength, foregroundColor);
209
207
210
208
BatchHandle h (*this );
211
209
212
210
setClipping (start.getX (), start.getY (), length, 1 );
213
211
while (length > BufferSize)
214
212
{
215
- this ->writeData (buffer , BufferSize * 2 );
213
+ this ->writeData (buffer_rgb565 , BufferSize);
216
214
length -= BufferSize;
217
215
}
218
- this ->writeData (buffer , length * 2 );
216
+ this ->writeData (buffer_rgb565 , length);
219
217
}
220
218
221
219
template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
222
220
void
223
221
Ili9341<Interface, Reset, Backlight, BufferSize>::drawVerticalLine(
224
222
glcd::Point start, uint16_t length)
225
223
{
226
- uint16_t const pixelValue { modm::toBigEndian (foregroundColor.color ) };
227
224
auto minLength { std::min (std::size_t (length), BufferSize) };
228
- uint16_t *buffer16 { reinterpret_cast <uint16_t *>(buffer) };
229
- std::fill (buffer16, buffer16+minLength, pixelValue);
225
+ std::fill (buffer_rgb565, buffer_rgb565+minLength, foregroundColor);
230
226
231
227
BatchHandle h (*this );
232
228
233
229
setClipping (start.getX (), start.getY (), 1 , length);
234
230
while (length > BufferSize)
235
231
{
236
- this ->writeData (buffer , BufferSize * 2 );
232
+ this ->writeData (buffer_rgb565 , BufferSize);
237
233
length -= BufferSize;
238
234
}
239
- this ->writeData (buffer , length * 2 );
235
+ this ->writeData (buffer_rgb565 , length);
240
236
}
241
237
242
238
template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
@@ -248,31 +244,25 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillRectangle(
248
244
auto const y { upperLeft.getY () };
249
245
std::size_t pixelCount { std::size_t (width) * std::size_t (height) };
250
246
251
- uint16_t const pixelValue { modm::toBigEndian (foregroundColor.color ) };
252
247
auto minLength { std::min (std::size_t (pixelCount), BufferSize) };
253
- uint16_t *buffer16 { reinterpret_cast <uint16_t *>(buffer) };
254
- std::fill (buffer16, buffer16+minLength, pixelValue);
248
+ std::fill (buffer_rgb565, buffer_rgb565+minLength, foregroundColor);
255
249
256
250
BatchHandle h (*this );
257
251
258
252
setClipping (x, y, width, height);
259
253
while (pixelCount > BufferSize)
260
254
{
261
- this ->writeData (buffer , BufferSize * 2 );
255
+ this ->writeData (buffer_rgb565 , BufferSize);
262
256
pixelCount -= BufferSize;
263
257
}
264
- if (pixelCount)
265
- this ->writeData (buffer, pixelCount * 2 );
258
+ this ->writeData (buffer_rgb565, pixelCount);
266
259
}
267
260
268
261
template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
269
262
void
270
263
Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
271
264
glcd::Point center, uint16_t radius)
272
265
{
273
- uint8_t const setColor[] { uint8_t ((foregroundColor.color >> 8 ) & 0xff ),
274
- uint8_t (foregroundColor.color & 0xff ) };
275
-
276
266
int16_t f = 1 - radius;
277
267
int16_t ddF_x = 0 ;
278
268
int16_t ddF_y = -2 * radius;
@@ -283,7 +273,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
283
273
284
274
setClipping (center.getX () - radius, center.getY (), 2 * radius, 1 );
285
275
for (std::size_t i = 0 ; i < 2 * radius; ++i)
286
- this ->writeData (setColor, 2 );
276
+ this ->writeData (foregroundColor. color );
287
277
288
278
while (x < y)
289
279
{
@@ -299,16 +289,16 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
299
289
300
290
setClipping (center.getX () - x, center.getY () - y, 2 * x, 1 );
301
291
for (std::size_t i = 0 ; i < 2 * x; ++i)
302
- this ->writeData (setColor, 2 );
292
+ this ->writeData (foregroundColor. color );
303
293
setClipping (center.getX () - y, center.getY () - x, 2 * y, 1 );
304
294
for (std::size_t i = 0 ; i < 2 * y; ++i)
305
- this ->writeData (setColor, 2 );
295
+ this ->writeData (foregroundColor. color );
306
296
setClipping (center.getX () - x, center.getY () + y, 2 * x, 1 );
307
297
for (std::size_t i = 0 ; i < 2 * x; ++i)
308
- this ->writeData (setColor, 2 );
298
+ this ->writeData (foregroundColor. color );
309
299
setClipping (center.getX () - y, center.getY () + x, 2 * y, 1 );
310
300
for (std::size_t i = 0 ; i < 2 * y; ++i)
311
- this ->writeData (setColor, 2 );
301
+ this ->writeData (foregroundColor. color );
312
302
}
313
303
}
314
304
@@ -317,11 +307,6 @@ void
317
307
Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upperLeft,
318
308
uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t > data)
319
309
{
320
- uint8_t const setColor[] { uint8_t ((foregroundColor.color >> 8 ) & 0xff ),
321
- uint8_t (foregroundColor.color & 0xff ) };
322
- uint8_t const clearColor[] { uint8_t ((backgroundColor.color >> 8 ) & 0xff ),
323
- uint8_t (backgroundColor.color & 0xff ) };
324
-
325
310
BatchHandle h (*this );
326
311
327
312
setClipping (upperLeft.getX (), upperLeft.getY (), width, height);
@@ -333,9 +318,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
333
318
{
334
319
uint8_t byte = data[(r / 8 ) * width + w];
335
320
if (byte & bit)
336
- this ->writeData (setColor, 2 );
321
+ this ->writeData (foregroundColor. color );
337
322
else
338
- this ->writeData (clearColor, 2 );
323
+ this ->writeData (backgroundColor. color );
339
324
}
340
325
// TODO: optimize, use ROL (rotate left)
341
326
bit <<= 1 ;
@@ -351,13 +336,8 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawRaw(glcd::Point upperLeft,
351
336
{
352
337
BatchHandle h (*this );
353
338
354
- uint16_t * buffer = (uint16_t *)data;
355
- for (size_t i = 0 ; i < size_t (width*height); i++) {
356
- buffer[i] = modm::fromBigEndian (buffer[i]);
357
- }
358
-
359
339
setClipping (upperLeft.getX (), upperLeft.getY (), width, height);
360
- this ->writeData (( uint8_t *)buffer , width * height * 2 );
340
+ this ->writeData (data , width * height);
361
341
}
362
342
363
343
template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
@@ -391,13 +371,10 @@ void
391
371
Ili9341<Interface, Reset, Backlight, BufferSize>::setColoredPixel(
392
372
int16_t x, int16_t y, color::Rgb565 const &color)
393
373
{
394
- auto const pixelColor { color };
395
- uint8_t const setColor[] { uint8_t ((pixelColor.color >> 8 ) & 0xff ), uint8_t (pixelColor.color & 0xff ) };
396
-
397
374
BatchHandle h (*this );
398
375
399
376
this ->setClipping (x, y, 1 , 1 );
400
- this ->writeData (setColor, 2 );
377
+ this ->writeData (color );
401
378
}
402
379
403
380
template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
0 commit comments