@@ -236,11 +236,10 @@ modm::Ili9341<Interface, Reset, BC>::updateClipping()
236236 RF_END ();
237237}
238238
239- // -- Write Pattern from Generator ---------------------------
240239template <class Interface , class Reset , size_t BC>
241240template <ColorPattern P>
242241modm::ResumableResult<void >
243- modm::Ili9341<Interface, Reset, BC>::write (Rectangle rectangle, P pattern) {
242+ modm::Ili9341<Interface, Reset, BC>::writePattern (Rectangle rectangle, P pattern) {
244243 RF_BEGIN ();
245244
246245 this ->clipping = this ->getIntersection (rectangle);
@@ -250,77 +249,34 @@ modm::Ili9341<Interface, Reset, BC>::write(Rectangle rectangle, P pattern) {
250249
251250 while (p.pixels )
252251 {
253- // Generate next bulk
252+ // Fill buffer
254253 for (p.i = 0 ; p.i < std::min<uint32_t >(p.pixels , BC); p.i ++) {
255- // OPTIMIZE inefficient, cause pattern recalculates color for each pixel
256- // even when it could already know, under withc conditions the return-value changes!
257- // Need some kind of caching!?
258- p.buffer [p.i ] = pattern (p.scanner );
259-
254+ p.buffer [p.i ] = pattern (p.scanner );
260255 if (++p.scanner .y == this ->clipping .bottomRight .y ) {
261256 scannerincrementRow ();
262257 }
263258 }
264- // Transfer
259+ // Transfer buffer
265260 RF_CALL (this ->writeData (p.buffer , p.i ));
266261 p.pixels -= p.i ;
267262 }
268263
269264 RF_END ();
270265}
271266
272- // -- Write equal colored BufferInterface --------------------
273- template <class Interface , class Reset , size_t BC>
274- template <template <typename > class Accessor >
275- modm::ResumableResult<void >
276- modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<Rgb565, Accessor> decoder, Point origin)
277- {
278- // Found no cast for d share the memory between all of the writeImage()-methods.
279- // This waste of RAM will be history once Resumable Functions become history.
280- static ImageAccessor<Rgb565, Accessor> d;
281-
282- RF_BEGIN ();
283-
284- d = decoder;
285-
286- this ->clipping = this ->getIntersection (Rectangle (origin, d.size ));
287- RF_CALL (updateClipping ());
288-
289- d.initialize (origin);
290-
291- // Check if display is exceeded vertically
292- if (origin.y < 0 or origin.y + d.size .y >= this ->getHeight ())
293- {
294- // Continuous transfer not possible, send row by row
295- p.pixels_bulk = this ->clipping .getHeight ();
296-
297- while (p.pixels >= p.pixels_bulk ) {
298- RF_CALL (this ->writeData (d.getPointer () + 1 , p.pixels_bulk ));
299- d.incrementRow ();
300- p.pixels -= p.pixels_bulk ;
301- }
302- } else
303- {
304- // Transfer buffer in one shot
305- RF_CALL (this ->writeData (d.getPointer () + 1 , p.pixels ));
306- }
307- RF_END ();
308- }
309-
310- // -- Write colored Image -------------------
311267template <class Interface , class Reset , size_t BC>
312- template <Color C_ , template <typename > class Accessor >
268+ template <Color C , template <typename > class Accessor >
313269modm::ResumableResult<void >
314- modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<C_ , Accessor> decoder , Point origin) {
270+ modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<C , Accessor> accessor , Point origin) {
315271 // Found no cast for d share the memory between all of the writeImage()-methods.
316272 // This waste of RAM will be history once Resumable Functions become history.
317- static ImageAccessor<C_ , Accessor> d;
273+ static ImageAccessor<C , Accessor> d;
318274
319275 RF_BEGIN ();
320276
321- d = decoder ;
277+ d = accessor ;
322278
323- this ->clipping = this ->getIntersection (Rectangle (origin, d.size ));
279+ this ->clipping = this ->getIntersection (Rectangle (origin, d.getSize () ));
324280 RF_CALL (updateClipping ());
325281
326282 // FIXME store image locally
@@ -329,66 +285,64 @@ modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<C_, Accessor> deco
329285
330286 while (p.pixels )
331287 {
332- // Convert next Bulk
288+ // Fill buffer
333289 for (p.i = 0 ; p.i < std::min<uint32_t >(p.pixels , BC); p.i ++) {
334- // OPTIMIZE following Line is the only
335- // difference to -- write monochrome Image -- below
336- p.buffer [p.i ] = d.nextPixel ();
290+ if constexpr (ColorGrayBase2<C>)
291+ p.buffer [p.i ] = colormap[d.nextPixel ().getValue ()];
292+ else
293+ p.buffer [p.i ] = d.nextPixel ();
294+
337295 if (++p.scanner .y == this ->clipping .bottomRight .y ) {
338296 scannerincrementRow ();
339297 d.incrementRow ();
340298 }
341299 }
342- // Transfer
300+ // Transfer buffer
343301 RF_CALL (this ->writeData (p.buffer , p.i ));
344302 p.pixels -= p.i ;
345303 }
346304
347305 RF_END ();
348306}
349307
350-
351- // -- Write Gray Image, this supports color-mapping
352308template <class Interface , class Reset , size_t BC>
353- template <ColorGrayBase2 G, template <typename > class Accessor >
309+ template <template <typename > class Accessor >
354310modm::ResumableResult<void >
355- modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<G, Accessor> decoder, Point origin) {
311+ modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<ColorType, Accessor> accessor, Point origin)
312+ {
356313 // Found no cast for d share the memory between all of the writeImage()-methods.
357314 // This waste of RAM will be history once Resumable Functions become history.
358- static ImageAccessor<G , Accessor> d;
315+ static ImageAccessor<ColorType , Accessor> d;
359316
360317 RF_BEGIN ();
361-
362- d = decoder ;
318+
319+ d = accessor ;
363320
364321 this ->clipping = this ->getIntersection (Rectangle (origin, d.size ));
365322 RF_CALL (updateClipping ());
366323
367324 d.initialize (origin);
368- p.scanner = this ->clipping .topLeft ;
369325
370- while (p.pixels )
326+ // Check if display is exceeded vertically
327+ if (origin.y < 0 or origin.y + d.size .y >= this ->getHeight ())
371328 {
372- // Convert next Bulk
373- for (p.i = 0 ; p.i < std::min<uint32_t >(p.pixels , BC); p.i ++) {
374- // OPTIMIZE following Line is the only
375- // difference to -- write colored Image -- above
376- // IMPLEMENT color-mapping
377- p.buffer [p.i ] = colormap[d.nextPixel ().getValue ()];
378- if (++p.scanner .y == this ->clipping .bottomRight .y ) {
379- scannerincrementRow ();
380- d.incrementRow ();
381- }
329+ // Continuous transfer not possible, send row by row
330+ p.pixels_bulk = this ->clipping .getHeight ();
331+
332+ while (p.pixels >= p.pixels_bulk ) {
333+ RF_CALL (this ->writeData (d.getPointer () + 1 , p.pixels_bulk ));
334+ d.incrementRow ();
335+ p.pixels -= p.pixels_bulk ;
382336 }
383- // Transfer
384- RF_CALL (this ->writeData (p.buffer , p.i ));
385- p.pixels -= p.i ;
337+ } else
338+ {
339+ // Transfer buffer in one shot
340+ RF_CALL (this ->writeData (d.getPointer () + 1 , p.pixels ));
386341 }
387-
388342 RF_END ();
389343}
390344
391- // -- Draw primitive Shapes ------------------------------
345+ // Fundamental drawing of shapes
392346template <class Interface , class Reset , size_t BC>
393347modm::ResumableResult<void >
394348modm::Ili9341<Interface, Reset, BC>::drawBlind(const Point& point)
@@ -427,28 +381,10 @@ modm::Ili9341<Interface, Reset, BC>::drawBlind(const Section& section)
427381 // Respect DMAs max bulksize of 2^16-1
428382 while (p.pixels ) {
429383 p.pixels_bulk = std::min<uint32_t >(p.pixels , std::numeric_limits<uint16_t >::max ());
430- RF_CALL (this ->writeData ( color, p.pixels_bulk ));
384+ RF_CALL (this ->writeDataRepeat (& color, p.pixels_bulk ));
431385 p.pixels -= p.pixels_bulk ;
432386 }
433387 // RF_CALL(this->writeData(color, p.pixels));
434388
435- RF_END ();
436- }
437-
438- template <class Interface , class Reset , size_t BC>
439- modm::ResumableResult<void >
440- modm::Ili9341<Interface, Reset, BC>::clear(Rgb565 color)
441- {
442- // OPTIMIZE Make this impossible fast through use of DMA
443- // See https://github.com/modm-io/modm/issues/666
444- RF_BEGIN ();
445-
446- p.temp_color = this ->color ;
447- this ->color = color;
448-
449- RF_CALL (drawBlind (this ->asSection ()));
450-
451- this ->color = p.temp_color ;
452-
453389 RF_END ();
454390}
0 commit comments