Skip to content

Commit

Permalink
dropped stupid pattern. Use lambdas instead!
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Sep 15, 2021
1 parent 2ed0fbb commit 496d898
Show file tree
Hide file tree
Showing 24 changed files with 552 additions and 877 deletions.
75 changes: 15 additions & 60 deletions src/modm/driver/display/ili9341.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ class Ili9341 : public Interface,

public:
using ColorType = Rgb565;
static constexpr Resolution resolution{320, 240};
using BufferLandscape = Buffer<Rgb565, ResolutionVector>;
using BufferPortrait = Buffer<Rgb565, ResolutionVector.swapped()>;

ColorType* colormap;

using BufferLandscape = Buffer<Rgb565, resolution>;
using BufferPortrait = Buffer<Rgb565, resolution.swapped()>;

template<typename... Args>
Ili9341(Args &&...args)
: Interface(std::forward<Args>(args)...),
Expand Down Expand Up @@ -105,33 +103,9 @@ class Ili9341 : public Interface,
modm::ResumableResult<void>
scrollTo(uint16_t row);

// Write from Pattern
template<ColorPattern P>
modm::ResumableResult<void>
write(Rectangle rectangle, P pattern);

// Write BufferInterface
template<class C>
modm::ResumableResult<void>
write(BufferInterface<C> &buffer, Point origin = {0, 0}) {
RF_BEGIN();
RF_END_RETURN_CALL(writeImage(ImageAccessor<C, modm::accessor::Ram>(&buffer), origin));
}

// Write Flash Image
modm::ResumableResult<void>
write(const uint8_t *addr, Point origin = {0, 0}) {
RF_BEGIN();
RF_END_RETURN_CALL(writeImage(
ImageAccessor<Gray2, modm::accessor::Flash>(addr),
origin)
);
}

// Clear whole screen with color
modm::ResumableResult<void>
clear(Rgb565 color = html::Black);

writePattern(Rectangle rectangle, P pattern);
private:
// Static variables for resumable functions
Section section;
Expand All @@ -141,51 +115,34 @@ class Ili9341 : public Interface,
protected:
modm::ResumableResult<void>
updateClipping();
modm::ResumableResult<void>
setClipping(Point point);

/**
* Write Image in Ili9341 colorformat
*
* @param decoder Image with Flash or Ram Accessor
* @param origin Placement for the image
*/
template<template<typename> class Accessor>
modm::ResumableResult<void>
writeImage(ImageAccessor<Rgb565, Accessor> decoder, Point origin = {0, 0});
setClipping(Point point);

/**
* Write colored Image
* Write Image with on-the-fly conversion
*
* @param decoder Image with Flash or Ram Accessor
* @param accessor ImageAccessor with underlying Flash or Ram Accessor
* @param origin Placement for the image
*/
template<Color C, template<typename> class Accessor>
modm::ResumableResult<void>
writeImage(ImageAccessor<C, Accessor> decoder, Point origin = {0, 0});
writeImage(ImageAccessor<C, Accessor> accessor, Point origin = {0, 0});

/**
* Write ColorGrayBase2 Image using color-mapping
* Write Image in same format
*
* @param decoder Image with Flash or Ram Accessor
* @param accessor ImageAccessor with underlying Flash or Ram Accessor
* @param origin Placement for the image
*/
template<ColorGrayBase2 G, template<typename> class Accessor>
template<template<typename> class Accessor>
modm::ResumableResult<void>
writeImage(ImageAccessor<G, Accessor> decoder, Point origin = {0, 0});
writeImage(ImageAccessor<ColorType, Accessor> accessor, Point origin = {0, 0});

inline void
initialize_write_monochrome(Point origin);

// Draw directly on the screen (hardware accelerated)
modm::ResumableResult<void>
drawBlind(const Point& point);
modm::ResumableResult<void>
drawBlind(const HLine& hline);
modm::ResumableResult<void>
drawBlind(const VLine& vline);
modm::ResumableResult<void>
drawBlind(const Section& section);
modm::ResumableResult<void> drawBlind(const Point& point);
modm::ResumableResult<void> drawBlind(const Section& section);
modm::ResumableResult<void> drawBlind(const HLine& hline);
modm::ResumableResult<void> drawBlind(const VLine& vline);

modm::ResumableResult<Rgb565>
getBlind(const Point& point) const;
Expand Down Expand Up @@ -216,8 +173,6 @@ class Ili9341 : public Interface,
size_t pixels_bulk; // Pixels of current bulk

uint16_t buff_cmd_clipping[2];

Rgb565 temp_color; // Temporary storage for a color
} p; // p for parallel
};
};
Expand Down
138 changes: 37 additions & 101 deletions src/modm/driver/display/ili9341_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,10 @@ modm::Ili9341<Interface, Reset, BC>::updateClipping()
RF_END();
}

// -- Write Pattern from Generator ---------------------------
template<class Interface, class Reset, size_t BC>
template<ColorPattern P>
modm::ResumableResult<void>
modm::Ili9341<Interface, Reset, BC>::write(Rectangle rectangle, P pattern) {
modm::Ili9341<Interface, Reset, BC>::writePattern(Rectangle rectangle, P pattern) {
RF_BEGIN();

this->clipping = this->getIntersection(rectangle);
Expand All @@ -250,77 +249,34 @@ modm::Ili9341<Interface, Reset, BC>::write(Rectangle rectangle, P pattern) {

while (p.pixels)
{
// Generate next bulk
// Fill buffer
for(p.i = 0; p.i < std::min<uint32_t>(p.pixels, BC); p.i++) {
// OPTIMIZE inefficient, cause pattern recalculates color for each pixel
// even when it could already know, under withc conditions the return-value changes!
// Need some kind of caching!?
p.buffer[p.i] = pattern(p.scanner);

p.buffer[p.i] = pattern(p.scanner);
if (++p.scanner.y == this->clipping.bottomRight.y) {
scannerincrementRow();
}
}
// Transfer
// Transfer buffer
RF_CALL(this->writeData(p.buffer, p.i));
p.pixels-= p.i;
}

RF_END();
}

// -- Write equal colored BufferInterface --------------------
template<class Interface, class Reset, size_t BC>
template<template<typename> class Accessor>
modm::ResumableResult<void>
modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<Rgb565, Accessor> decoder, Point origin)
{
// Found no cast for d share the memory between all of the writeImage()-methods.
// This waste of RAM will be history once Resumable Functions become history.
static ImageAccessor<Rgb565, Accessor> d;

RF_BEGIN();

d = decoder;

this->clipping = this->getIntersection(Rectangle(origin, d.size));
RF_CALL(updateClipping());

d.initialize(origin);

// Check if display is exceeded vertically
if (origin.y < 0 or origin.y + d.size.y >= this->getHeight())
{
// Continuous transfer not possible, send row by row
p.pixels_bulk = this->clipping.getHeight();

while(p.pixels >= p.pixels_bulk) {
RF_CALL(this->writeData(d.getPointer() + 1, p.pixels_bulk));
d.incrementRow();
p.pixels -= p.pixels_bulk;
}
} else
{
// Transfer buffer in one shot
RF_CALL(this->writeData(d.getPointer() + 1, p.pixels));
}
RF_END();
}

// -- Write colored Image -------------------
template<class Interface, class Reset, size_t BC>
template<Color C_, template<typename> class Accessor>
template<Color C, template<typename> class Accessor>
modm::ResumableResult<void>
modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<C_, Accessor> decoder, Point origin) {
modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<C, Accessor> accessor, Point origin) {
// Found no cast for d share the memory between all of the writeImage()-methods.
// This waste of RAM will be history once Resumable Functions become history.
static ImageAccessor<C_, Accessor> d;
static ImageAccessor<C, Accessor> d;

RF_BEGIN();

d = decoder;
d = accessor;

this->clipping = this->getIntersection(Rectangle(origin, d.size));
this->clipping = this->getIntersection(Rectangle(origin, d.getSize()));
RF_CALL(updateClipping());

// FIXME store image locally
Expand All @@ -329,66 +285,64 @@ modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<C_, Accessor> deco

while (p.pixels)
{
// Convert next Bulk
// Fill buffer
for(p.i = 0; p.i < std::min<uint32_t>(p.pixels, BC); p.i++) {
// OPTIMIZE following Line is the only
// difference to -- write monochrome Image -- below
p.buffer[p.i] = d.nextPixel();
if constexpr (ColorGrayBase2<C>)
p.buffer[p.i] = colormap[d.nextPixel().getValue()];
else
p.buffer[p.i] = d.nextPixel();

if (++p.scanner.y == this->clipping.bottomRight.y) {
scannerincrementRow();
d.incrementRow();
}
}
// Transfer
// Transfer buffer
RF_CALL(this->writeData(p.buffer, p.i));
p.pixels -= p.i;
}

RF_END();
}


// -- Write Gray Image, this supports color-mapping
template<class Interface, class Reset, size_t BC>
template<ColorGrayBase2 G, template<typename> class Accessor>
template<template<typename> class Accessor>
modm::ResumableResult<void>
modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<G, Accessor> decoder, Point origin) {
modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<ColorType, Accessor> accessor, Point origin)
{
// Found no cast for d share the memory between all of the writeImage()-methods.
// This waste of RAM will be history once Resumable Functions become history.
static ImageAccessor<G, Accessor> d;
static ImageAccessor<ColorType, Accessor> d;

RF_BEGIN();

d = decoder;
d = accessor;

this->clipping = this->getIntersection(Rectangle(origin, d.size));
RF_CALL(updateClipping());

d.initialize(origin);
p.scanner = this->clipping.topLeft;

while (p.pixels)
// Check if display is exceeded vertically
if (origin.y < 0 or origin.y + d.size.y >= this->getHeight())
{
// Convert next Bulk
for(p.i = 0; p.i < std::min<uint32_t>(p.pixels, BC); p.i++) {
// OPTIMIZE following Line is the only
// difference to -- write colored Image -- above
// IMPLEMENT color-mapping
p.buffer[p.i] = colormap[d.nextPixel().getValue()];
if (++p.scanner.y == this->clipping.bottomRight.y) {
scannerincrementRow();
d.incrementRow();
}
// Continuous transfer not possible, send row by row
p.pixels_bulk = this->clipping.getHeight();

while(p.pixels >= p.pixels_bulk) {
RF_CALL(this->writeData(d.getPointer() + 1, p.pixels_bulk));
d.incrementRow();
p.pixels -= p.pixels_bulk;
}
// Transfer
RF_CALL(this->writeData(p.buffer, p.i));
p.pixels -= p.i;
} else
{
// Transfer buffer in one shot
RF_CALL(this->writeData(d.getPointer() + 1, p.pixels));
}

RF_END();
}

// -- Draw primitive Shapes ------------------------------
// Fundamental drawing of shapes
template<class Interface, class Reset, size_t BC>
modm::ResumableResult<void>
modm::Ili9341<Interface, Reset, BC>::drawBlind(const Point& point)
Expand Down Expand Up @@ -427,28 +381,10 @@ modm::Ili9341<Interface, Reset, BC>::drawBlind(const Section& section)
// Respect DMAs max bulksize of 2^16-1
while(p.pixels) {
p.pixels_bulk = std::min<uint32_t>(p.pixels, std::numeric_limits<uint16_t>::max());
RF_CALL(this->writeData(color, p.pixels_bulk));
RF_CALL(this->writeDataRepeat(&color, p.pixels_bulk));
p.pixels -= p.pixels_bulk;
}
// RF_CALL(this->writeData(color, p.pixels));

RF_END();
}

template<class Interface, class Reset, size_t BC>
modm::ResumableResult<void>
modm::Ili9341<Interface, Reset, BC>::clear(Rgb565 color)
{
// OPTIMIZE Make this impossible fast through use of DMA
// See https://github.com/modm-io/modm/issues/666
RF_BEGIN();

p.temp_color = this->color;
this->color = color;

RF_CALL(drawBlind(this->asSection()));

this->color = p.temp_color;

RF_END();
}
Loading

0 comments on commit 496d898

Please sign in to comment.