@@ -231,7 +231,7 @@ modm::Ili9341<Interface, Reset, BC>::updateClipping()
231231 RF_CALL (this ->writeCommand (Command::ColumnAddressSet, (uint8_t *)(p.buff_cmd_clipping ), 4 ));
232232
233233 RF_CALL (this ->writeCommand (Command::MemoryWrite));
234- p.pixels_to_write = this ->clipping .getPixels ();
234+ p.pixels = this ->clipping .getPixels ();
235235
236236 RF_END ();
237237}
@@ -248,111 +248,95 @@ modm::Ili9341<Interface, Reset, BC>::writePattern(Rectangle rectangle, P pattern
248248
249249 p.scanner = this ->clipping .topLeft ;
250250
251- while (p.pixels_to_write )
251+ while (p.pixels )
252252 {
253253 // Generate next bulk
254- for (p.buffer_i = 0 ; p.buffer_i < std::min<uint32_t >(p.pixels_to_write , BC); p.buffer_i ++) {
254+ for (p.i = 0 ; p.i < std::min<uint32_t >(p.pixels , BC); p.i ++) {
255255 // OPTIMIZE inefficient, cause pattern recalculates color for each pixel
256- // Let's investigate a solution
257- p. buffer [p. buffer_i ] = pattern (p. scanner );
258-
259- // Update scanner
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+
260260 if (++p.scanner .y == this ->clipping .bottomRight .y ) {
261- p.scanner .x ++;
262- p.scanner .y = this ->clipping .topLeft .y ;
261+ scannerNextRow ();
263262 }
264263 }
265-
266264 // Transfer
267- RF_CALL (this ->writeData ((uint8_t *)(p.buffer ), 2 * p.buffer_i ));
268-
269- p.pixels_to_write -= p.buffer_i ;
265+ RF_CALL (this ->writeData ((uint8_t *)(p.buffer ), 2 * p.i ));
266+ p.pixels -= p.i ;
270267 }
271268
272269 RF_END ();
273270}
274271
275- // -- Write equal colored Buffer ----- -----------------------------
272+ // -- Write equal colored BufferInterface -----------------------------
276273template <class Interface , class Reset , size_t BC>
277- template <typename R_, class Painter_ >
278274modm::ResumableResult<void >
279275modm::Ili9341<Interface, Reset, BC>::writeBuffer(
280- const Buffer<colorType, R_, Painter_> &buffer, Point origin)
281- {
276+ const BufferInterface<colorType> *buffer, Point origin) {
282277 RF_BEGIN ();
283278
284- this ->clipping = this ->getIntersection (Rectangle (origin, R_::asPoint ()));
279+ this ->clipping = this ->getIntersection (Rectangle (origin, buffer-> getSize ()));
285280 RF_CALL (updateClipping ());
286281
287- // FIXME take this->clipping into account
288- RF_CALL (this ->writeData (buffer.getPlainBuffer (), p.pixels_to_write * 2 ));
282+ if (yInCanvas (origin.y ) and yInCanvas (origin.y + buffer->getSize ().y ))
283+ {
284+ p.pixels = this ->clipping .getPixels ();
285+ // Calculate left buffer-offset
286+ p.pixels_bulk = origin.x < 0 ? -origin.x * this ->clipping .getHeight () : 0 ;
287+ RF_CALL (this ->writeData (buffer->getPlainBuffer () + p.pixels_bulk , 2 * p.pixels ));
288+ } else
289+ {
290+ // IMPLEMENT Can't transfer buffer continuously
291+ // What's the best strategy? copy to p.buffer (using DMA2D if available) or send row by row?
292+ RF_RETURN ();
293+ }
294+
289295 RF_END ();
290296}
291297
292- // -- Write equal colored BufferInterface -----------------------------
298+ // -- Write different colored BufferInterface -----------------------------
293299template <class Interface , class Reset , size_t BC>
300+ template <Color C_>
294301modm::ResumableResult<void >
295302modm::Ili9341<Interface, Reset, BC>::writeBuffer(
296- const BufferInterface<colorType > *buffer, Point origin) {
303+ const BufferInterface<C_ > *buffer, Point origin) {
297304 RF_BEGIN ();
298305
299- this ->clipping = this ->getIntersection (Rectangle (origin, buffer->getResolution ()));
306+ this ->clipping = this ->getIntersection (Rectangle (origin, buffer->getSize ()));
300307 RF_CALL (updateClipping ());
301-
302- // Reload scanner
303- p.bool_scanner = ScannerBufferBool (origin);
304- p.bool_scanner .print_top ();
305- p.bool_scanner .print_state ();
306308
307309 RF_END ();
308310}
309311
310- // -- Write monochrome Buffer ---------- -------------------
312+ // -- Write monochrome BufferInterface -------------------
311313template <class Interface , class Reset , size_t BC>
312- template <typename R_, class Painter_ >
313314modm::ResumableResult<void >
314315modm::Ili9341<Interface, Reset, BC>::writeBuffer(
315- const Buffer<bool , R_, Painter_> &buffer, Point origin)
316- {
316+ const BufferInterface<bool > *buffer, Point origin) {
317317 RF_BEGIN ();
318318
319- // Reload scanner
320- p.bool_scanner = ScannerBufferBool (buffer.getPlainBuffer (), origin);
321- p.bool_scanner .print_top ();
322-
323- this ->clipping = this ->getIntersection (Rectangle (origin, R_::asPoint ()));
319+ this ->clipping = this ->getIntersection (Rectangle (origin, buffer->getSize ()));
324320 RF_CALL (updateClipping ());
325321
326- while (p.pixels_to_write )
322+ p.mono_reader = MonochromeReader (buffer->getPlainBuffer (), buffer->getSize ().x , origin);
323+ p.scanner = this ->clipping .topLeft ;
324+
325+ while (p.pixels )
327326 {
328- p.temp_color = html::Red;
329-
330327 // Convert next Bulk
331- p. pixel_bulk = std::min<size_t >(p.pixels_to_write , BC);
332- for (p. buffer_i = 0 ; p. buffer_i < p. pixel_bulk ; p. buffer_i ++) {
333- // p.bool_scanner.print_state();
334- // p.buffer[p.buffer_i] = p.bool_scanner() ? color : colorType(html::Black );
335- p. temp_color . color ++ ;
336- p. buffer [p. buffer_i ] = p. temp_color ;
328+ for (p. i = 0 ; p. i < std::min<uint32_t >(p.pixels , BC); p. i ++) {
329+ p. buffer [p. i ] = p. mono_reader () ? color : colorType (html::Black);
330+ if (++p. scanner . y == this -> clipping . bottomRight . y ) {
331+ scannerNextRow ( );
332+ p. mono_reader . nextRow () ;
333+ }
337334 }
338-
339335 // Transfer
340- RF_CALL (this ->writeData ((uint8_t *)(p.buffer ), 2 * p.pixel_bulk ));
341- p.pixels_to_write -= p.pixel_bulk ;
336+ RF_CALL (this ->writeData ((uint8_t *)(p.buffer ), 2 * p.i ));
337+ p.pixels -= p.i ;
342338 }
343- RF_END ();
344- }
345339
346- // -- Write monochrome BufferInterface -------------------
347- template <class Interface , class Reset , size_t BC>
348- modm::ResumableResult<void >
349- modm::Ili9341<Interface, Reset, BC>::writeBuffer(
350- const BufferInterface<bool > *buffer, Point origin) {
351- RF_BEGIN ();
352-
353- MODM_LOG_DEBUG << __FUNCTION__ << modm::endl;
354- MODM_LOG_DEBUG << " origin: " << origin << " , resolution: " << buffer->getResolution () << modm::endl;
355-
356340 RF_END ();
357341}
358342
@@ -363,20 +347,29 @@ modm::Ili9341<Interface, Reset, BC>::writeFlash(modm::accessor::Flash<uint8_t> d
363347 uint16_t width, uint16_t height, Point origin) {
364348 RF_BEGIN ();
365349
366- this ->clipping = this ->getIntersection (Rectangle (origin, Point ( width, height) ));
350+ this ->clipping = this ->getIntersection (Rectangle (origin, { width, height} ));
367351 RF_CALL (updateClipping ());
368352
369- // Reload scanner
370- // p.bool_scanner = ScannerBufferBool(data, origin);
371- // p.bool_scanner.print_top();
372- // p.bool_scanner.print_state();
373-
374- (void )data;
375- (void )width;
376- (void )height;
377- (void )origin;
353+ // FIXME MonochromeReader must learn to handle modm::accessor::Flash<uint8_t>
354+ // p.mono_reader = MonochromeReader(data, width, origin);
355+ p.scanner = this ->clipping .topLeft ;
356+
357+ while (p.pixels )
358+ {
359+ // Convert next Bulk
360+ for (p.i = 0 ; p.i < std::min<uint32_t >(p.pixels , BC); p.i ++) {
361+ // p.buffer[p.i] = p.mono_reader() ? color : colorType(html::Black);
362+ if (++p.scanner .y == this ->clipping .bottomRight .y ) {
363+ scannerNextRow ();
364+ // p.mono_reader.nextRow();
365+ }
366+ }
367+ // Transfer
368+ RF_CALL (this ->writeData ((uint8_t *)(p.buffer ), 2 * p.i ));
369+ p.pixels -= p.i ;
370+ }
378371
379- RF_END ();
372+ RF_END ();
380373}
381374
382375// -- Draw primitive Shapes ------------------------------
@@ -421,14 +414,14 @@ modm::Ili9341<Interface, Reset, BC>::drawFast(Section section)
421414 // See https://github.com/modm-io/modm/issues/666
422415
423416 // Without DMA, at least this could be parallelised to updateClipping(..) above
424- p.pixel_bulk = std::min<size_t >(BC, p.pixels_to_write );
425- std::fill (p.buffer , p.buffer + p.pixel_bulk , color);
417+ p.pixels_bulk = std::min<size_t >(BC, p.pixels );
418+ std::fill (p.buffer , p.buffer + p.pixels_bulk , color);
426419
427- while (p.pixels_to_write )
420+ while (p.pixels )
428421 {
429- p.pixels_to_write -= p.pixel_bulk ;
430- RF_CALL (this ->writeData ((uint8_t *)(p.buffer ), 2 * p.pixel_bulk ));
431- p.pixel_bulk = std::min<size_t >(BC, p.pixels_to_write );
422+ p.pixels -= p.pixels_bulk ;
423+ RF_CALL (this ->writeData ((uint8_t *)(p.buffer ), 2 * p.pixels_bulk ));
424+ p.pixels_bulk = std::min<size_t >(BC, p.pixels );
432425 }
433426 RF_END ();
434427}
0 commit comments