@@ -202,41 +202,37 @@ void
202202Ili9341<Interface, Reset, Backlight, BufferSize>::drawHorizontalLine(
203203 glcd::Point start, uint16_t length)
204204{
205- uint16_t const pixelValue { modm::toBigEndian (foregroundColor.color ) };
206205 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);
209207
210208 BatchHandle h (*this );
211209
212210 setClipping (start.getX (), start.getY (), length, 1 );
213211 while (length > BufferSize)
214212 {
215- this ->writeData (buffer , BufferSize * 2 );
213+ this ->writeData (buffer_rgb565 , BufferSize);
216214 length -= BufferSize;
217215 }
218- this ->writeData (buffer , length * 2 );
216+ this ->writeData (buffer_rgb565 , length);
219217}
220218
221219template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
222220void
223221Ili9341<Interface, Reset, Backlight, BufferSize>::drawVerticalLine(
224222 glcd::Point start, uint16_t length)
225223{
226- uint16_t const pixelValue { modm::toBigEndian (foregroundColor.color ) };
227224 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);
230226
231227 BatchHandle h (*this );
232228
233229 setClipping (start.getX (), start.getY (), 1 , length);
234230 while (length > BufferSize)
235231 {
236- this ->writeData (buffer , BufferSize * 2 );
232+ this ->writeData (buffer_rgb565 , BufferSize);
237233 length -= BufferSize;
238234 }
239- this ->writeData (buffer , length * 2 );
235+ this ->writeData (buffer_rgb565 , length);
240236}
241237
242238template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
@@ -248,31 +244,25 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillRectangle(
248244 auto const y { upperLeft.getY () };
249245 std::size_t pixelCount { std::size_t (width) * std::size_t (height) };
250246
251- uint16_t const pixelValue { modm::toBigEndian (foregroundColor.color ) };
252247 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);
255249
256250 BatchHandle h (*this );
257251
258252 setClipping (x, y, width, height);
259253 while (pixelCount > BufferSize)
260254 {
261- this ->writeData (buffer , BufferSize * 2 );
255+ this ->writeData (buffer_rgb565 , BufferSize);
262256 pixelCount -= BufferSize;
263257 }
264- if (pixelCount)
265- this ->writeData (buffer, pixelCount * 2 );
258+ this ->writeData (buffer_rgb565, pixelCount);
266259}
267260
268261template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
269262void
270263Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
271264 glcd::Point center, uint16_t radius)
272265{
273- uint8_t const setColor[] { uint8_t ((foregroundColor.color >> 8 ) & 0xff ),
274- uint8_t (foregroundColor.color & 0xff ) };
275-
276266 int16_t f = 1 - radius;
277267 int16_t ddF_x = 0 ;
278268 int16_t ddF_y = -2 * radius;
@@ -283,7 +273,7 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
283273
284274 setClipping (center.getX () - radius, center.getY (), 2 * radius, 1 );
285275 for (std::size_t i = 0 ; i < 2 * radius; ++i)
286- this ->writeData (setColor, 2 );
276+ this ->writeData (foregroundColor. color );
287277
288278 while (x < y)
289279 {
@@ -299,16 +289,16 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::fillCircle(
299289
300290 setClipping (center.getX () - x, center.getY () - y, 2 * x, 1 );
301291 for (std::size_t i = 0 ; i < 2 * x; ++i)
302- this ->writeData (setColor, 2 );
292+ this ->writeData (foregroundColor. color );
303293 setClipping (center.getX () - y, center.getY () - x, 2 * y, 1 );
304294 for (std::size_t i = 0 ; i < 2 * y; ++i)
305- this ->writeData (setColor, 2 );
295+ this ->writeData (foregroundColor. color );
306296 setClipping (center.getX () - x, center.getY () + y, 2 * x, 1 );
307297 for (std::size_t i = 0 ; i < 2 * x; ++i)
308- this ->writeData (setColor, 2 );
298+ this ->writeData (foregroundColor. color );
309299 setClipping (center.getX () - y, center.getY () + x, 2 * y, 1 );
310300 for (std::size_t i = 0 ; i < 2 * y; ++i)
311- this ->writeData (setColor, 2 );
301+ this ->writeData (foregroundColor. color );
312302 }
313303}
314304
@@ -317,11 +307,6 @@ void
317307Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upperLeft,
318308 uint16_t width, uint16_t height, modm::accessor::Flash<uint8_t > data)
319309{
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-
325310 BatchHandle h (*this );
326311
327312 setClipping (upperLeft.getX (), upperLeft.getY (), width, height);
@@ -333,9 +318,9 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawImageRaw(glcd::Point upper
333318 {
334319 uint8_t byte = data[(r / 8 ) * width + w];
335320 if (byte & bit)
336- this ->writeData (setColor, 2 );
321+ this ->writeData (foregroundColor. color );
337322 else
338- this ->writeData (clearColor, 2 );
323+ this ->writeData (backgroundColor. color );
339324 }
340325 // TODO: optimize, use ROL (rotate left)
341326 bit <<= 1 ;
@@ -351,13 +336,8 @@ Ili9341<Interface, Reset, Backlight, BufferSize>::drawRaw(glcd::Point upperLeft,
351336{
352337 BatchHandle h (*this );
353338
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-
359339 setClipping (upperLeft.getX (), upperLeft.getY (), width, height);
360- this ->writeData (( uint8_t *)buffer , width * height * 2 );
340+ this ->writeData (data , width * height);
361341}
362342
363343template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
@@ -391,13 +371,10 @@ void
391371Ili9341<Interface, Reset, Backlight, BufferSize>::setColoredPixel(
392372 int16_t x, int16_t y, color::Rgb565 const &color)
393373{
394- auto const pixelColor { color };
395- uint8_t const setColor[] { uint8_t ((pixelColor.color >> 8 ) & 0xff ), uint8_t (pixelColor.color & 0xff ) };
396-
397374 BatchHandle h (*this );
398375
399376 this ->setClipping (x, y, 1 , 1 );
400- this ->writeData (setColor, 2 );
377+ this ->writeData (color );
401378}
402379
403380template <class Interface , class Reset , class Backlight , std::size_t BufferSize>
0 commit comments