Skip to content

Commit 5f56f51

Browse files
committed
using std::copy for Buffer<> construct and assignment + some tweaking
1 parent ad53041 commit 5f56f51

15 files changed

+360
-265
lines changed

src/modm/driver/display/ili9341.hpp

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
using namespace modm::shape;
3333
using namespace modm::graphic;
34+
using namespace modm::graphic::accessor;
3435

3536
namespace modm
3637
{
@@ -103,53 +104,31 @@ class Ili9341 : public Interface,
103104
modm::ResumableResult<void>
104105
scrollTo(uint16_t row);
105106

106-
// Write from Pattern (compiletime poly)
107+
// Write from Pattern
107108
template<ColorPattern P>
108-
// FIXME Concept not accepted - but why?
109-
// requires std::derived_from<Pattern, modm::color::Pattern<C>>
110109
modm::ResumableResult<void>
111-
writePattern(Rectangle rectangle, P pattern);
112-
113-
/**
114-
* Write colored Image
115-
*
116-
* @param image Image with Flash or Ram Accessor
117-
* @param origin Placement of the image
118-
*/
119-
/* template<Color C_, template<typename> class Accessor>
120-
modm::ResumableResult<void>
121-
writeImage(Image<C_, Accessor> image, Point origin = {0, 0}); */
122-
123-
/**
124-
* Write equal colored Image
125-
*
126-
* @param image Image with Flash or Ram Accessor
127-
* @param origin Placement of the image
128-
*/
129-
template<template<typename> class Accessor>
130-
modm::ResumableResult<void>
131-
writeImage(Image<C, Accessor> image, Point origin = {0, 0});
132-
133-
/**
134-
* Write monochrome Image
135-
*
136-
* @param image Image with Flash or Ram Accessor
137-
* @param origin Placement of the image
138-
*/
139-
template<template<typename> class Accessor>
140-
modm::ResumableResult<void>
141-
writeImage(Image<bool, Accessor> image, Point origin = {0, 0});
110+
write(Rectangle rectangle, P pattern);
142111

112+
// Write BufferInterface
143113
template<Color C_>
144114
modm::ResumableResult<void>
145-
writeImage(BufferInterface<C_> *buffer, Point origin = {0, 0}) {
115+
write(BufferInterface<C_> &buffer, Point origin = {0, 0}) {
146116
RF_BEGIN();
147-
RF_END_RETURN_CALL(writeImage(modm::graphic::Image<C_, modm::accessor::Ram>(buffer), origin));
117+
RF_END_RETURN_CALL(writeImage(
118+
Image<C_, modm::accessor::Ram>(&buffer),
119+
origin)
120+
);
148121
}
149122

150-
// Write equal colored Image from Accessor
151-
// modm::ResumableResult<void>
152-
// writeImage(Image<C> image) final;
123+
// Write Flash Image
124+
modm::ResumableResult<void>
125+
write(const uint8_t *addr, Point origin = {0, 0}) {
126+
RF_BEGIN();
127+
RF_END_RETURN_CALL(writeImage(
128+
Image<bool, modm::accessor::Flash>(addr),
129+
origin)
130+
);
131+
}
153132

154133
// Clear whole screen with color
155134
modm::ResumableResult<void>
@@ -185,8 +164,38 @@ class Ili9341 : public Interface,
185164
modm::ResumableResult<void>
186165
setClipping(Point point);
187166

167+
/**
168+
* Write Image in Ili9341 colorformat
169+
*
170+
* @param image Image with Flash or Ram Accessor
171+
* @param origin Placement of the image
172+
*/
173+
template<template<typename> class Accessor>
174+
modm::ResumableResult<void>
175+
writeImage(Image<C, Accessor> image, Point origin = {0, 0});
176+
177+
/**
178+
* Write colored Image
179+
*
180+
* @param image Image with Flash or Ram Accessor
181+
* @param origin Placement of the image
182+
*/
183+
template<Color C_, template<typename> class Accessor>
184+
modm::ResumableResult<void>
185+
writeImage(Image<C_, Accessor> image, Point origin = {0, 0});
186+
187+
/**
188+
* Write monochrome Image
189+
*
190+
* @param image Image with Flash or Ram Accessor
191+
* @param origin Placement of the image
192+
*/
193+
template<template<typename> class Accessor>
194+
modm::ResumableResult<void>
195+
writeImage(Image<bool, Accessor> image, Point origin = {0, 0});
196+
188197
inline void
189-
initialize_writeBuffer_monochrome(Point origin);
198+
initialize_write_monochrome(Point origin);
190199

191200
// TODO Add final as soon as RemotePainter is connected
192201
// Hardware accelerated drawing directly on the screen

src/modm/driver/display/ili9341_impl.hpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ modm::Ili9341<Interface, Reset, BC>::updateClipping()
240240
template<class Interface, class Reset, size_t BC>
241241
template<ColorPattern P>
242242
modm::ResumableResult<void>
243-
modm::Ili9341<Interface, Reset, BC>::writePattern(Rectangle rectangle, P pattern) {
243+
modm::Ili9341<Interface, Reset, BC>::write(Rectangle rectangle, P pattern) {
244244
RF_BEGIN();
245245

246246
this->clipping = this->getIntersection(rectangle);
@@ -274,7 +274,7 @@ template<class Interface, class Reset, size_t BC>
274274
template<template<typename> class Accessor>
275275
modm::ResumableResult<void>
276276
modm::Ili9341<Interface, Reset, BC>::writeImage(
277-
modm::graphic::Image<C, Accessor> image, Point origin)
277+
modm::graphic::accessor::Image<C, Accessor> image, Point origin)
278278
{
279279
RF_BEGIN();
280280

@@ -309,12 +309,42 @@ modm::Ili9341<Interface, Reset, BC>::writeImage(
309309
RF_END();
310310
}
311311

312-
// -- Write monochrome BufferInterface -------------------
312+
// -- Write colored Image -------------------
313+
template<class Interface, class Reset, size_t BC>
314+
template<Color C_, template<typename> class Accessor>
315+
modm::ResumableResult<void>
316+
modm::Ili9341<Interface, Reset, BC>::writeImage(
317+
modm::graphic::accessor::Image<C_, Accessor> image, Point origin) {
318+
RF_BEGIN();
319+
320+
this->clipping = this->getIntersection(Rectangle(origin, image.size));
321+
RF_CALL(updateClipping());
322+
323+
while (p.pixels)
324+
{
325+
// Convert next Bulk
326+
for(p.i = 0; p.i < std::min<uint32_t>(p.pixels, BC); p.i++) {
327+
// IMPLEMENT Ili9341 Write colored Image
328+
// p.buffer[p.i] = image();
329+
if (++p.scanner.y == this->clipping.bottomRight.y) {
330+
scannerNextRow();
331+
// image.nextRow();
332+
}
333+
}
334+
// Transfer
335+
RF_CALL(this->writeData(p.buffer, p.i));
336+
p.pixels -= p.i;
337+
}
338+
RF_END();
339+
}
340+
341+
342+
// -- Write monochrome Image -------------------
313343
template<class Interface, class Reset, size_t BC>
314344
template<template<typename> class Accessor>
315345
modm::ResumableResult<void>
316346
modm::Ili9341<Interface, Reset, BC>::writeImage(
317-
modm::graphic::Image<bool, Accessor> image, Point origin) {
347+
modm::graphic::accessor::Image<bool, Accessor> image, Point origin) {
318348
RF_BEGIN();
319349

320350
this->clipping = this->getIntersection(Rectangle(origin, image.size));
@@ -328,7 +358,7 @@ modm::Ili9341<Interface, Reset, BC>::writeImage(
328358
{
329359
// Convert next Bulk
330360
for(p.i = 0; p.i < std::min<uint32_t>(p.pixels, BC); p.i++) {
331-
p.buffer[p.i] = image() ? color : C(html::Black);
361+
p.buffer[p.i] = image.nextPixel() ? color : C(html::Black);
332362
if (++p.scanner.y == this->clipping.bottomRight.y) {
333363
scannerNextRow();
334364
image.nextRow();

src/modm/driver/display/sh1106.hpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "ssd1306.hpp"
1616

1717
using namespace modm::graphic;
18+
using namespace modm::graphic::accessor;
1819

1920
namespace modm
2021
{
@@ -37,18 +38,24 @@ class Sh1106 : public Ssd1306<I2cMaster, H>
3738

3839
Sh1106(uint8_t address = 0x3C) : Ssd1306<I2cMaster, H>(address) {}
3940

40-
// Write monochrome Image
41-
// Caution: origin.y rounds to multiples of 8
42-
template<template<typename> class Accessor>
43-
modm::ResumableResult<bool>
44-
writeImage(Image<bool, Accessor> image, Point origin = {0, 0});
45-
41+
// Write BufferInterface
4642
// FIXME Why is not inherited from Ssd1306?
4743
template<Color C_>
4844
modm::ResumableResult<bool>
49-
writeImage(BufferInterface<C_> *buffer, Point origin = {0, 0}) {
45+
write(BufferInterface<C_> &buffer, Point origin = {0, 0}) {
46+
RF_BEGIN();
47+
RF_END_RETURN_CALL(writeImage(modm::graphic::accessor::Image<C_, modm::accessor::Ram>(&buffer), origin));
48+
}
49+
50+
// Write Flash Image
51+
// FIXME Why is not inherited from Ssd1306?
52+
modm::ResumableResult<void>
53+
write(const uint8_t *addr, Point origin = {0, 0}) {
5054
RF_BEGIN();
51-
RF_END_RETURN_CALL(writeImage(modm::graphic::Image<C_, modm::accessor::Ram>(buffer), origin));
55+
RF_END_RETURN_CALL(writeImage(
56+
Image<bool, modm::accessor::Flash>(addr),
57+
origin)
58+
);
5259
}
5360

5461
protected:
@@ -58,6 +65,12 @@ class Sh1106 : public Ssd1306<I2cMaster, H>
5865
modm::ResumableResult<bool>
5966
updateClipping() final;
6067

68+
// Write monochrome Image
69+
// Caution: origin.y rounds to multiples of 8
70+
template<template<typename> class Accessor>
71+
modm::ResumableResult<bool>
72+
writeImage(Image<bool, Accessor> image, Point origin = {0, 0});
73+
6174
// Static variables for Resumable Functions
6275
size_t yd; // vertical index in display (page)
6376
size_t yd_start; // first vertical index in display

src/modm/driver/display/ssd1306.hpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ssd1306_register.hpp"
2525

2626
using namespace modm::graphic;
27+
using namespace modm::graphic::accessor;
2728

2829
namespace modm
2930
{
@@ -158,17 +159,23 @@ class Ssd1306 : public ssd1306,
158159
return writeCommands(1);
159160
}
160161

161-
// Write monochrome Image
162+
// Write BufferInterface
162163
// Caution: origin.y rounds to multiples of 8
163-
template<template<typename> class Accessor>
164-
modm::ResumableResult<bool>
165-
writeImage(Image<bool, Accessor> image, Point origin = {0, 0});
166-
167164
template<Color C_>
168165
modm::ResumableResult<bool>
169-
writeImage(BufferInterface<C_> *buffer, Point origin = {0, 0}) {
166+
write(BufferInterface<C_> &buffer, Point origin = {0, 0}) {
170167
RF_BEGIN();
171-
RF_END_RETURN_CALL(writeImage(modm::graphic::Image<C_, modm::accessor::Ram>(buffer), origin));
168+
RF_END_RETURN_CALL(writeImage(Image<C_, modm::accessor::Ram>(&buffer), origin));
169+
}
170+
171+
// Write Flash Image
172+
modm::ResumableResult<void>
173+
write(const uint8_t *addr, Point origin = {0, 0}) {
174+
RF_BEGIN();
175+
RF_END_RETURN_CALL(writeImage(
176+
Image<bool, modm::accessor::Flash>(addr),
177+
origin)
178+
);
172179
}
173180

174181
// Clear whole screen with color
@@ -179,6 +186,11 @@ class Ssd1306 : public ssd1306,
179186
virtual modm::ResumableResult<bool>
180187
updateClipping();
181188

189+
// Write monochrome Image
190+
template<template<typename> class Accessor>
191+
modm::ResumableResult<bool>
192+
writeImage(Image<bool, Accessor> image, Point origin = {0, 0});
193+
182194
modm::ResumableResult<bool>
183195
writeCommands(std::size_t length);
184196

0 commit comments

Comments
 (0)