Skip to content

Commit

Permalink
better application of modm::accessor::Ram/FLash
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Aug 9, 2021
1 parent 5f56f51 commit 4ed4ed0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/modm/ui/graphic/accessor_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Image : public Accessor<C>

// DMA2D may be implemented here

modm::shape::Point size;
const modm::shape::Point size;
};

} // namespace modm::graphic
Expand Down
57 changes: 26 additions & 31 deletions src/modm/ui/graphic/accessor_image_bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,53 @@ class Image<bool, Accessor> : public Accessor<uint8_t>
: Accessor<T>(buffer->getBuffer()), size(buffer->getSize())
{}

modm::shape::Point size;

private:
// Optimized Reader for monochrome image-data

T* addr_top;
T bitmask_top;

// State
T* head;
size_t x, i;
T byte;
T bitmask;
const modm::shape::Point size;

public:
#define MODM_LOG_DEBUG_VAR(var) MODM_LOG_DEBUG << #var << ":\t" << var << modm::endl
// Optimized Reader for monochrome image-data

void
initializeReader(const modm::shape::Point origin)
{
x = origin.x < 0 ? -origin.x : 0;
int16_t y = origin.y < 0 ? -origin.y : 0;
addr_top = (uint8_t*)(this->address) + (y / 8) * size.x;
bitmask_top = std::rotl(Bit0, y % 8);

// Prepare first read
head = addr_top + x;
byte = FlashReader<T, sizeof(T)>::read(head);
bitmask = bitmask_top;
const Point topLeft = {
origin.x < 0 ? -origin.x : 0,
origin.y < 0 ? -origin.y : 0
};
addr_top = this->getPointer() + (topLeft.y / 8) * size.x + topLeft.x;
bitmask_top = std::rotl(Bit0, topLeft.y % 8 - 1);
nextRow();
}

inline bool
nextPixel()
{
const bool ret = byte & bitmask;
// Increment y
bitmask = std::rotl(bitmask, 1);
if (bitmask == Bit0)
{
head += size.x;
byte = FlashReader<T, sizeof(T)>::read(head);
Accessor<uint8_t>::operator+=(size.x);
byte = Accessor<uint8_t>::operator *();
}
return ret;
return byte & bitmask;
}

inline void
nextRow()
{
x++;
head = addr_top + x;
byte = FlashReader<T, sizeof(T)>::read(head);
bitmask = bitmask_top;
if(bitmask == Bit7) {
Accessor<uint8_t>::operator=(addr_top++ - size.x);
} else {
Accessor<uint8_t>::operator=(addr_top++);
byte = Accessor<uint8_t>::operator *();
}
}
private:
// config
const T* addr_top;
T bitmask_top;

// cache
T byte;
T bitmask;
};
} // namespace modm::graphic
20 changes: 13 additions & 7 deletions src/modm/ui/graphic/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,30 @@ class Buffer : public BufferInterface<C>, public Painter, public TextPainter<R>
: BufferInterface<C>(other.color)
{ std::copy(other.buffer[0], other.buffer[0] + sizeof(other.buffer) / sizeof(C), buffer[0]); }

// Construct from colored buffer of same size
// Construct from colored buffer with same size
template<Color C_, class Painter_>
constexpr Buffer(const Buffer<C_, R, Painter_> &other)
: BufferInterface<C>(other.color)
{ std::copy(other.buffer[0], other.buffer[0] + sizeof(other.buffer) / sizeof(C), buffer[0]); }

// Construct from colored buffer of different size
// Construct from colored buffer with different size
template<Color C_, class R_, class Painter_>
constexpr Buffer(const Buffer<C_, R_, Painter_> &other)
: BufferInterface<C>(other.color)
{ writeImage(accessor::Image<C_, modm::accessor::Ram>(&other)); }

// Construct from monochrome Buffer of same size
template<class R_, class Painter_>
// Construct from monochrome Buffer with same size
template<class Painter_>
constexpr Buffer(const Buffer<bool, R, Painter_> &other)
: BufferInterface<C>(html::White)
{ writeImage(accessor::Image<bool, modm::accessor::Ram>(&other)); }

// Construct from monochrome Buffer with different size
template<class R_, class Painter_>
constexpr Buffer(const Buffer<bool, R_, Painter_> &other)
: BufferInterface<C>(html::White)
{ writeImage(accessor::Image<bool, modm::accessor::Ram>(&other)); }

Buffer &
operator=(const Buffer<C, R, Painter> &other)
{
Expand All @@ -97,6 +103,9 @@ class Buffer : public BufferInterface<C>, public Painter, public TextPainter<R>
Point getSize() const final
{ return R::asPoint(); }

const uint8_t* getBuffer() const final
{ return (uint8_t*)(buffer); }

// API Fasade: Write BufferInterface
template<Color C_>
void
Expand All @@ -117,9 +126,6 @@ class Buffer : public BufferInterface<C>, public Painter, public TextPainter<R>
protected:
C buffer[R::W][R::H];

uint8_t* getBuffer() const final
{ return (uint8_t*)(buffer); }

/**
* Write colored Image
*
Expand Down
11 changes: 8 additions & 3 deletions src/modm/ui/graphic/buffer_bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Buffer<bool, R, Painter> : public BufferInterface<bool>, public Painter, p
constexpr Buffer(const Buffer<bool, R, Painter_> &other)
{ std::copy(other.buffer[0], other.buffer[0] + sizeof(other.buffer), buffer[0]); }

// Construct from colored Buffer with same size
template <Color C_, class Painter_>
constexpr Buffer(const Buffer<C_, R, Painter_> &other)
{ /*std::copy(other.buffer[0], other.buffer[0] + sizeof(other.buffer), buffer[0]);*/ }

// Assign monochrome Buffer with same size
Buffer &
operator=(const Buffer<bool, R, Painter> &other)
Expand Down Expand Up @@ -89,6 +94,9 @@ class Buffer<bool, R, Painter> : public BufferInterface<bool>, public Painter, p
Point getSize() const final
{ return R::asPoint(); }

const uint8_t* getBuffer() const final
{ return (uint8_t*)(buffer); }

// ##################################
// # Experimental Features
// ##################################
Expand All @@ -109,9 +117,6 @@ class Buffer<bool, R, Painter> : public BufferInterface<bool>, public Painter, p
protected:
uint8_t buffer[HB][R::W];

uint8_t* getBuffer() const final
{ return (uint8_t*)(buffer); }

/**
* Write colored Image
*
Expand Down
3 changes: 1 addition & 2 deletions src/modm/ui/graphic/buffer_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class BufferInterface
virtual shape::Point
getSize() const = 0;

// TODO friend class accessor::Image and protect access
virtual uint8_t*
virtual const uint8_t*
getBuffer() const = 0;

virtual C
Expand Down

0 comments on commit 4ed4ed0

Please sign in to comment.