@@ -231,7 +231,7 @@ modm::Ili9341<Interface, Reset, BC>::updateClipping()
231
231
RF_CALL (this ->writeCommand (Command::ColumnAddressSet, (uint8_t *)(p.buff_cmd_clipping ), 4 ));
232
232
233
233
RF_CALL (this ->writeCommand (Command::MemoryWrite));
234
- p.pixels_to_write = this ->clipping .getPixels ();
234
+ p.pixels = this ->clipping .getPixels ();
235
235
236
236
RF_END ();
237
237
}
@@ -248,111 +248,95 @@ modm::Ili9341<Interface, Reset, BC>::writePattern(Rectangle rectangle, P pattern
248
248
249
249
p.scanner = this ->clipping .topLeft ;
250
250
251
- while (p.pixels_to_write )
251
+ while (p.pixels )
252
252
{
253
253
// 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 ++) {
255
255
// 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
+
260
260
if (++p.scanner .y == this ->clipping .bottomRight .y ) {
261
- p.scanner .x ++;
262
- p.scanner .y = this ->clipping .topLeft .y ;
261
+ scannerNextRow ();
263
262
}
264
263
}
265
-
266
264
// 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 ;
270
267
}
271
268
272
269
RF_END ();
273
270
}
274
271
275
- // -- Write equal colored Buffer ----- -----------------------------
272
+ // -- Write equal colored BufferInterface -----------------------------
276
273
template <class Interface , class Reset , size_t BC>
277
- template <typename R_, class Painter_ >
278
274
modm::ResumableResult<void >
279
275
modm::Ili9341<Interface, Reset, BC>::writeBuffer(
280
- const Buffer<colorType, R_, Painter_> &buffer, Point origin)
281
- {
276
+ const BufferInterface<colorType> *buffer, Point origin) {
282
277
RF_BEGIN ();
283
278
284
- this ->clipping = this ->getIntersection (Rectangle (origin, R_::asPoint ()));
279
+ this ->clipping = this ->getIntersection (Rectangle (origin, buffer-> getSize ()));
285
280
RF_CALL (updateClipping ());
286
281
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
+
289
295
RF_END ();
290
296
}
291
297
292
- // -- Write equal colored BufferInterface -----------------------------
298
+ // -- Write different colored BufferInterface -----------------------------
293
299
template <class Interface , class Reset , size_t BC>
300
+ template <Color C_>
294
301
modm::ResumableResult<void >
295
302
modm::Ili9341<Interface, Reset, BC>::writeBuffer(
296
- const BufferInterface<colorType > *buffer, Point origin) {
303
+ const BufferInterface<C_ > *buffer, Point origin) {
297
304
RF_BEGIN ();
298
305
299
- this ->clipping = this ->getIntersection (Rectangle (origin, buffer->getResolution ()));
306
+ this ->clipping = this ->getIntersection (Rectangle (origin, buffer->getSize ()));
300
307
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 ();
306
308
307
309
RF_END ();
308
310
}
309
311
310
- // -- Write monochrome Buffer ---------- -------------------
312
+ // -- Write monochrome BufferInterface -------------------
311
313
template <class Interface , class Reset , size_t BC>
312
- template <typename R_, class Painter_ >
313
314
modm::ResumableResult<void >
314
315
modm::Ili9341<Interface, Reset, BC>::writeBuffer(
315
- const Buffer<bool , R_, Painter_> &buffer, Point origin)
316
- {
316
+ const BufferInterface<bool > *buffer, Point origin) {
317
317
RF_BEGIN ();
318
318
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 ()));
324
320
RF_CALL (updateClipping ());
325
321
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 )
327
326
{
328
- p.temp_color = html::Red;
329
-
330
327
// 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
+ }
337
334
}
338
-
339
335
// 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 ;
342
338
}
343
- RF_END ();
344
- }
345
339
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
-
356
340
RF_END ();
357
341
}
358
342
@@ -363,20 +347,29 @@ modm::Ili9341<Interface, Reset, BC>::writeFlash(modm::accessor::Flash<uint8_t> d
363
347
uint16_t width, uint16_t height, Point origin) {
364
348
RF_BEGIN ();
365
349
366
- this ->clipping = this ->getIntersection (Rectangle (origin, Point ( width, height) ));
350
+ this ->clipping = this ->getIntersection (Rectangle (origin, { width, height} ));
367
351
RF_CALL (updateClipping ());
368
352
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
+ }
378
371
379
- RF_END ();
372
+ RF_END ();
380
373
}
381
374
382
375
// -- Draw primitive Shapes ------------------------------
@@ -421,14 +414,14 @@ modm::Ili9341<Interface, Reset, BC>::drawFast(Section section)
421
414
// See https://github.com/modm-io/modm/issues/666
422
415
423
416
// 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);
426
419
427
- while (p.pixels_to_write )
420
+ while (p.pixels )
428
421
{
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 );
432
425
}
433
426
RF_END ();
434
427
}
0 commit comments