Skip to content

Commit 4ed4ed0

Browse files
committed
better application of modm::accessor::Ram/FLash
1 parent 5f56f51 commit 4ed4ed0

File tree

5 files changed

+49
-44
lines changed

5 files changed

+49
-44
lines changed

src/modm/ui/graphic/accessor_image.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Image : public Accessor<C>
3131

3232
// DMA2D may be implemented here
3333

34-
modm::shape::Point size;
34+
const modm::shape::Point size;
3535
};
3636

3737
} // namespace modm::graphic

src/modm/ui/graphic/accessor_image_bool.hpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,53 @@ class Image<bool, Accessor> : public Accessor<uint8_t>
2020
: Accessor<T>(buffer->getBuffer()), size(buffer->getSize())
2121
{}
2222

23-
modm::shape::Point size;
24-
25-
private:
26-
// Optimized Reader for monochrome image-data
27-
28-
T* addr_top;
29-
T bitmask_top;
30-
31-
// State
32-
T* head;
33-
size_t x, i;
34-
T byte;
35-
T bitmask;
23+
const modm::shape::Point size;
3624

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

4028
void
4129
initializeReader(const modm::shape::Point origin)
4230
{
43-
x = origin.x < 0 ? -origin.x : 0;
44-
int16_t y = origin.y < 0 ? -origin.y : 0;
45-
addr_top = (uint8_t*)(this->address) + (y / 8) * size.x;
46-
bitmask_top = std::rotl(Bit0, y % 8);
47-
48-
// Prepare first read
49-
head = addr_top + x;
50-
byte = FlashReader<T, sizeof(T)>::read(head);
51-
bitmask = bitmask_top;
31+
const Point topLeft = {
32+
origin.x < 0 ? -origin.x : 0,
33+
origin.y < 0 ? -origin.y : 0
34+
};
35+
addr_top = this->getPointer() + (topLeft.y / 8) * size.x + topLeft.x;
36+
bitmask_top = std::rotl(Bit0, topLeft.y % 8 - 1);
37+
nextRow();
5238
}
5339

5440
inline bool
5541
nextPixel()
5642
{
57-
const bool ret = byte & bitmask;
58-
// Increment y
5943
bitmask = std::rotl(bitmask, 1);
6044
if (bitmask == Bit0)
6145
{
62-
head += size.x;
63-
byte = FlashReader<T, sizeof(T)>::read(head);
46+
Accessor<uint8_t>::operator+=(size.x);
47+
byte = Accessor<uint8_t>::operator *();
6448
}
65-
return ret;
49+
return byte & bitmask;
6650
}
6751

6852
inline void
6953
nextRow()
7054
{
71-
x++;
72-
head = addr_top + x;
73-
byte = FlashReader<T, sizeof(T)>::read(head);
7455
bitmask = bitmask_top;
56+
if(bitmask == Bit7) {
57+
Accessor<uint8_t>::operator=(addr_top++ - size.x);
58+
} else {
59+
Accessor<uint8_t>::operator=(addr_top++);
60+
byte = Accessor<uint8_t>::operator *();
61+
}
7562
}
63+
private:
64+
// config
65+
const T* addr_top;
66+
T bitmask_top;
67+
68+
// cache
69+
T byte;
70+
T bitmask;
7671
};
7772
} // namespace modm::graphic

src/modm/ui/graphic/buffer.hpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,30 @@ class Buffer : public BufferInterface<C>, public Painter, public TextPainter<R>
5353
: BufferInterface<C>(other.color)
5454
{ std::copy(other.buffer[0], other.buffer[0] + sizeof(other.buffer) / sizeof(C), buffer[0]); }
5555

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

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

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

74+
// Construct from monochrome Buffer with different size
75+
template<class R_, class Painter_>
76+
constexpr Buffer(const Buffer<bool, R_, Painter_> &other)
77+
: BufferInterface<C>(html::White)
78+
{ writeImage(accessor::Image<bool, modm::accessor::Ram>(&other)); }
79+
7480
Buffer &
7581
operator=(const Buffer<C, R, Painter> &other)
7682
{
@@ -97,6 +103,9 @@ class Buffer : public BufferInterface<C>, public Painter, public TextPainter<R>
97103
Point getSize() const final
98104
{ return R::asPoint(); }
99105

106+
const uint8_t* getBuffer() const final
107+
{ return (uint8_t*)(buffer); }
108+
100109
// API Fasade: Write BufferInterface
101110
template<Color C_>
102111
void
@@ -117,9 +126,6 @@ class Buffer : public BufferInterface<C>, public Painter, public TextPainter<R>
117126
protected:
118127
C buffer[R::W][R::H];
119128

120-
uint8_t* getBuffer() const final
121-
{ return (uint8_t*)(buffer); }
122-
123129
/**
124130
* Write colored Image
125131
*

src/modm/ui/graphic/buffer_bool.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class Buffer<bool, R, Painter> : public BufferInterface<bool>, public Painter, p
4444
constexpr Buffer(const Buffer<bool, R, Painter_> &other)
4545
{ std::copy(other.buffer[0], other.buffer[0] + sizeof(other.buffer), buffer[0]); }
4646

47+
// Construct from colored Buffer with same size
48+
template <Color C_, class Painter_>
49+
constexpr Buffer(const Buffer<C_, R, Painter_> &other)
50+
{ /*std::copy(other.buffer[0], other.buffer[0] + sizeof(other.buffer), buffer[0]);*/ }
51+
4752
// Assign monochrome Buffer with same size
4853
Buffer &
4954
operator=(const Buffer<bool, R, Painter> &other)
@@ -89,6 +94,9 @@ class Buffer<bool, R, Painter> : public BufferInterface<bool>, public Painter, p
8994
Point getSize() const final
9095
{ return R::asPoint(); }
9196

97+
const uint8_t* getBuffer() const final
98+
{ return (uint8_t*)(buffer); }
99+
92100
// ##################################
93101
// # Experimental Features
94102
// ##################################
@@ -109,9 +117,6 @@ class Buffer<bool, R, Painter> : public BufferInterface<bool>, public Painter, p
109117
protected:
110118
uint8_t buffer[HB][R::W];
111119

112-
uint8_t* getBuffer() const final
113-
{ return (uint8_t*)(buffer); }
114-
115120
/**
116121
* Write colored Image
117122
*

src/modm/ui/graphic/buffer_interface.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class BufferInterface
1919
virtual shape::Point
2020
getSize() const = 0;
2121

22-
// TODO friend class accessor::Image and protect access
23-
virtual uint8_t*
22+
virtual const uint8_t*
2423
getBuffer() const = 0;
2524

2625
virtual C

0 commit comments

Comments
 (0)