@@ -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,109 @@ 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 (p.buffer , 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<C> *buffer, Point origin) {
282
277
RF_BEGIN ();
283
278
284
- this ->clipping = this ->getIntersection (Rectangle (origin, R_::asPoint ()));
279
+ this ->layout = buffer->getLayout ();
280
+
281
+ this ->clipping = this ->getIntersection (Rectangle (origin, this ->layout .size ));
285
282
RF_CALL (updateClipping ());
286
283
287
- // FIXME take this->clipping into account
288
- RF_CALL (this ->writeData (buffer.getPlainBuffer (), p.pixels_to_write * 2 ));
284
+ // Add left offset
285
+ if (origin.x < 0 )
286
+ this ->layout .buffer += -origin.x * this ->layout .size .y * 2 ;
287
+
288
+ // Check if we exceed the display vertically
289
+ if (origin.y < 0 or origin.y + this ->layout .size .y != this ->clipping .bottomRight .y )
290
+ {
291
+ // Add top offset
292
+ if (origin.y < 0 )
293
+ this ->layout .buffer += -origin.y * 2 ;
294
+
295
+ // Can't transfer buffer continuously, send row by row
296
+ p.pixels_bulk = this ->clipping .getHeight ();
297
+ while (p.pixels ) {
298
+ RF_CALL (this ->writeData ((C*)(this ->layout .buffer ), p.pixels_bulk ));
299
+ this ->layout .buffer += this ->layout .size .y * 2 ;
300
+ p.pixels -= p.pixels_bulk ;
301
+ }
302
+ } else
303
+ {
304
+ // Transfer buffer continuously in one shot
305
+ RF_CALL (this ->writeData ((C*)(this ->layout .buffer ), p.pixels ));
306
+ }
307
+
289
308
RF_END ();
290
309
}
291
310
292
- // -- Write equal colored BufferInterface -----------------------------
311
+ // -- Write different colored BufferInterface -----------------------------
293
312
template <class Interface , class Reset , size_t BC>
313
+ template <Color C_>
294
314
modm::ResumableResult<void >
295
315
modm::Ili9341<Interface, Reset, BC>::writeBuffer(
296
- const BufferInterface<colorType > *buffer, Point origin) {
316
+ const BufferInterface<C_ > *buffer, Point origin) {
297
317
RF_BEGIN ();
298
318
299
- this ->clipping = this ->getIntersection (Rectangle (origin, buffer-> getResolution () ));
319
+ this ->clipping = this ->getIntersection (Rectangle (origin, this -> layout . size ));
300
320
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
321
307
322
RF_END ();
308
323
}
309
324
310
- // -- Write monochrome Buffer ---------- -------------------
325
+ // -- Write monochrome BufferInterface -------------------
311
326
template <class Interface , class Reset , size_t BC>
312
- template <typename R_, class Painter_ >
313
327
modm::ResumableResult<void >
314
328
modm::Ili9341<Interface, Reset, BC>::writeBuffer(
315
- const Buffer<bool , R_, Painter_> &buffer, Point origin)
316
- {
329
+ const BufferInterface<bool > *buffer, Point origin) {
317
330
RF_BEGIN ();
318
331
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 ()));
332
+ this ->layout = buffer->getLayout ();
333
+ this ->clipping = this ->getIntersection (Rectangle (origin, this ->layout .size ));
324
334
RF_CALL (updateClipping ());
325
335
326
- while (p.pixels_to_write )
336
+ p.mono_reader = MonochromeReader (this ->layout .buffer , this ->layout .size .x , origin);
337
+ p.scanner = this ->clipping .topLeft ;
338
+
339
+ while (p.pixels )
327
340
{
328
- p.temp_color = html::Red;
329
-
330
341
// 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 ;
342
+ for (p. i = 0 ; p. i < std::min<uint32_t >(p.pixels , BC); p. i ++) {
343
+ p. buffer [p. i ] = p. mono_reader () ? color : C (html::Black);
344
+ if (++p. scanner . y == this -> clipping . bottomRight . y ) {
345
+ scannerNextRow ( );
346
+ p. mono_reader . nextRow () ;
347
+ }
337
348
}
338
-
339
349
// Transfer
340
- RF_CALL (this ->writeData (( uint8_t *)( p.buffer ), 2 * p. pixel_bulk ));
341
- p.pixels_to_write -= p.pixel_bulk ;
350
+ RF_CALL (this ->writeData (p.buffer , p. i ));
351
+ p.pixels -= p.i ;
342
352
}
343
- RF_END ();
344
- }
345
353
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
354
RF_END ();
357
355
}
358
356
@@ -363,20 +361,29 @@ modm::Ili9341<Interface, Reset, BC>::writeFlash(modm::accessor::Flash<uint8_t> d
363
361
uint16_t width, uint16_t height, Point origin) {
364
362
RF_BEGIN ();
365
363
366
- this ->clipping = this ->getIntersection (Rectangle (origin, Point ( width, height) ));
364
+ this ->clipping = this ->getIntersection (Rectangle (origin, { width, height} ));
367
365
RF_CALL (updateClipping ());
368
366
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;
367
+ // FIXME MonochromeReader must learn to handle modm::accessor::Flash<uint8_t>
368
+ // p.mono_reader = MonochromeReader(data, width, origin);
369
+ p.scanner = this ->clipping .topLeft ;
370
+
371
+ while (p.pixels )
372
+ {
373
+ // Convert next Bulk
374
+ for (p.i = 0 ; p.i < std::min<uint32_t >(p.pixels , BC); p.i ++) {
375
+ // p.buffer[p.i] = p.mono_reader() ? color : C(html::Black);
376
+ if (++p.scanner .y == this ->clipping .bottomRight .y ) {
377
+ scannerNextRow ();
378
+ // p.mono_reader.nextRow();
379
+ }
380
+ }
381
+ // Transfer
382
+ RF_CALL (this ->writeData (p.buffer , p.i ));
383
+ p.pixels -= p.i ;
384
+ }
378
385
379
- RF_END ();
386
+ RF_END ();
380
387
}
381
388
382
389
// -- Draw primitive Shapes ------------------------------
@@ -421,21 +428,21 @@ modm::Ili9341<Interface, Reset, BC>::drawFast(Section section)
421
428
// See https://github.com/modm-io/modm/issues/666
422
429
423
430
// 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);
431
+ p.pixels_bulk = std::min<size_t >(BC, p.pixels );
432
+ std::fill (p.buffer , p.buffer + p.pixels_bulk , color);
426
433
427
- while (p.pixels_to_write )
434
+ while (p.pixels )
428
435
{
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 );
436
+ p.pixels -= p.pixels_bulk ;
437
+ RF_CALL (this ->writeData (p.buffer , p. pixels_bulk ));
438
+ p.pixels_bulk = std::min<size_t >(BC, p.pixels );
432
439
}
433
440
RF_END ();
434
441
}
435
442
436
443
template <class Interface , class Reset , size_t BC>
437
444
modm::ResumableResult<void >
438
- modm::Ili9341<Interface, Reset, BC>::clear(colorType color)
445
+ modm::Ili9341<Interface, Reset, BC>::clear(C color)
439
446
{
440
447
// OPTIMIZE Make this impossible fast through use of DMA
441
448
// See https://github.com/modm-io/modm/issues/666
0 commit comments