Skip to content

Commit a2c9795

Browse files
committed
Started with colormap support
1 parent 5b53138 commit a2c9795

28 files changed

+374
-159
lines changed

ext/modm-devices

Submodule modm-devices updated 57 files

src/modm/driver/display/ili9341.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,25 @@ class Ili9341 : public Interface,
114114
write(BufferInterface<C_> &buffer, Point origin = {0, 0}) {
115115
RF_BEGIN();
116116
RF_END_RETURN_CALL(writeImage(
117-
Decoder<C_, modm::accessor::Ram>(&buffer),
117+
ImageAccessor<C_, modm::accessor::Ram>(&buffer),
118118
origin)
119119
);
120120
}
121121

122+
// Write BufferInterface
123+
template<class C_>
124+
modm::ResumableResult<void>
125+
write(BufferInterface<C_> &buffer, ColorType* colormap, Point origin = {0, 0}) {
126+
RF_BEGIN();
127+
RF_END_RETURN_CALL(writeImage(ImageAccessor<C_, modm::accessor::Ram>(&buffer), colormap, origin));
128+
}
129+
122130
// Write Flash Image
123131
modm::ResumableResult<void>
124132
write(const uint8_t *addr, Point origin = {0, 0}) {
125133
RF_BEGIN();
126134
RF_END_RETURN_CALL(writeImage(
127-
Decoder<Monochrome, modm::accessor::Flash>(addr),
135+
ImageAccessor<Monochrome, modm::accessor::Flash>(addr),
128136
origin)
129137
);
130138
}
@@ -153,7 +161,7 @@ class Ili9341 : public Interface,
153161
*/
154162
template<template<typename> class Accessor>
155163
modm::ResumableResult<void>
156-
writeImage(Decoder<Rgb565, Accessor> decoder, Point origin = {0, 0});
164+
writeImage(ImageAccessor<Rgb565, Accessor> decoder, Point origin = {0, 0});
157165

158166
/**
159167
* Write colored Image
@@ -163,7 +171,7 @@ class Ili9341 : public Interface,
163171
*/
164172
template<Color C_, template<typename> class Accessor>
165173
modm::ResumableResult<void>
166-
writeImage(Decoder<C_, Accessor> decoder, Point origin = {0, 0});
174+
writeImage(ImageAccessor<C_, Accessor> decoder, Point origin = {0, 0});
167175

168176
/**
169177
* Write ColorGrayBase2 Image using color-mapping
@@ -173,7 +181,7 @@ class Ili9341 : public Interface,
173181
*/
174182
template<template<typename> class Accessor>
175183
modm::ResumableResult<void>
176-
writeImage(Decoder<Monochrome, Accessor> decoder, Point origin = {0, 0});
184+
writeImage(ImageAccessor<Monochrome, Accessor> decoder, const ColorType colors[Monochrome::max + 1], Point origin = {0, 0});
177185

178186
inline void
179187
initialize_write_monochrome(Point origin);

src/modm/driver/display/ili9341_impl.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
*/
1111

1212
#pragma once
13-
#ifndef MODM_ILI9341_HPP
14-
#error "Don't include this file directly, use 'ili9341.hpp' instead!"
15-
#endif
13+
#include "ili9341.hpp"
1614

1715
using namespace modm::shape;
1816
using namespace modm::color;
@@ -279,11 +277,11 @@ modm::Ili9341<Interface, Reset, BC>::write(Rectangle rectangle, P pattern) {
279277
template<class Interface, class Reset, size_t BC>
280278
template<template<typename> class Accessor>
281279
modm::ResumableResult<void>
282-
modm::Ili9341<Interface, Reset, BC>::writeImage(Decoder<Rgb565, Accessor> decoder, Point origin)
280+
modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<Rgb565, Accessor> decoder, Point origin)
283281
{
284282
// Found no cast for d share the memory between all of the writeImage()-methods.
285283
// This waste of RAM will be history once Resumable Functions become history.
286-
static Decoder<Rgb565, Accessor> d;
284+
static ImageAccessor<Rgb565, Accessor> d;
287285

288286
RF_BEGIN();
289287

@@ -317,10 +315,10 @@ modm::Ili9341<Interface, Reset, BC>::writeImage(Decoder<Rgb565, Accessor> decode
317315
template<class Interface, class Reset, size_t BC>
318316
template<Color C_, template<typename> class Accessor>
319317
modm::ResumableResult<void>
320-
modm::Ili9341<Interface, Reset, BC>::writeImage(Decoder<C_, Accessor> decoder, Point origin) {
318+
modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<C_, Accessor> decoder, Point origin) {
321319
// Found no cast for d share the memory between all of the writeImage()-methods.
322320
// This waste of RAM will be history once Resumable Functions become history.
323-
static Decoder<C_, Accessor> d;
321+
static ImageAccessor<C_, Accessor> d;
324322

325323
RF_BEGIN();
326324

@@ -358,10 +356,10 @@ modm::Ili9341<Interface, Reset, BC>::writeImage(Decoder<C_, Accessor> decoder, P
358356
template<class Interface, class Reset, size_t BC>
359357
template<template<typename> class Accessor>
360358
modm::ResumableResult<void>
361-
modm::Ili9341<Interface, Reset, BC>::writeImage(Decoder<Monochrome, Accessor> decoder, Point origin) {
359+
modm::Ili9341<Interface, Reset, BC>::writeImage(ImageAccessor<Monochrome, Accessor> decoder, const ColorType colors[Monochrome::max + 1], Point origin) {
362360
// Found no cast for d share the memory between all of the writeImage()-methods.
363361
// This waste of RAM will be history once Resumable Functions become history.
364-
static Decoder<Monochrome, Accessor> d;
362+
static ImageAccessor<Monochrome, Accessor> d;
365363

366364
RF_BEGIN();
367365

@@ -380,7 +378,7 @@ modm::Ili9341<Interface, Reset, BC>::writeImage(Decoder<Monochrome, Accessor> de
380378
// OPTIMIZE following Line is the only
381379
// difference to -- write colored Image -- above
382380
// IMPLEMENT color-mapping
383-
p.buffer[p.i] = d.nextPixel();
381+
p.buffer[p.i] = colors[d.nextPixel().getValue()];
384382
if (++p.scanner.y == this->clipping.bottomRight.y) {
385383
scannerNextRow();
386384
d.nextRow();

src/modm/driver/display/sh1106.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ class Sh1106 : public Ssd1306<I2cMaster, H>
4343
modm::ResumableResult<bool>
4444
write(BufferInterface<Monochrome> &buffer, Point origin = {0, 0}) {
4545
RF_BEGIN();
46-
RF_END_RETURN_CALL(writeImage(Decoder<Monochrome, modm::accessor::Ram>(&buffer), origin));
46+
RF_END_RETURN_CALL(writeImage(ImageAccessor<Monochrome, modm::accessor::Ram>(&buffer), origin));
4747
}
4848

4949
// Write Flash Image
5050
modm::ResumableResult<void>
5151
write(const uint8_t *addr, Point origin = {0, 0}) {
5252
RF_BEGIN();
5353
RF_END_RETURN_CALL(writeImage(
54-
Decoder<Monochrome, modm::accessor::Flash>(addr),
54+
ImageAccessor<Monochrome, modm::accessor::Flash>(addr),
5555
origin)
5656
);
5757
}
@@ -67,7 +67,7 @@ class Sh1106 : public Ssd1306<I2cMaster, H>
6767
// Caution: origin.y rounds to multiples of 8
6868
template<template<typename> class Accessor>
6969
modm::ResumableResult<bool>
70-
writeImage(Decoder<Monochrome, Accessor> decoder, Point origin = {0, 0});
70+
writeImage(ImageAccessor<Monochrome, Accessor> decoder, Point origin = {0, 0});
7171

7272
// Static variables for Resumable Functions
7373
size_t yd; // vertical index in display (page)

src/modm/driver/display/sh1106_impl.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
// ----------------------------------------------------------------------------
1111

1212
#pragma once
13-
#ifndef MODM_SH1106_HPP
14-
#error "Don't include this file directly, use 'sh1106.hpp' instead!"
15-
#endif
13+
#include "sh1106.hpp"
1614

1715
using namespace modm::graphic;
1816

@@ -48,7 +46,7 @@ modm::Sh1106<I2cMaster, H>::updateClipping()
4846
template<class I2cMaster, uint16_t H>
4947
template<template<typename> class Accessor>
5048
modm::ResumableResult<bool>
51-
modm::Sh1106<I2cMaster, H>::writeImage(Decoder<Monochrome, Accessor> decoder, Point origin) {
49+
modm::Sh1106<I2cMaster, H>::writeImage(ImageAccessor<Monochrome, Accessor> decoder, Point origin) {
5250
RF_BEGIN();
5351

5452
// IMPLEMENT method with getIntersection()

src/modm/driver/display/ssd1306.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ class Ssd1306 : public ssd1306,
167167
modm::ResumableResult<bool>
168168
write(BufferInterface<Monochrome> &buffer, Point origin = {0, 0}) {
169169
RF_BEGIN();
170-
RF_END_RETURN_CALL(writeImage(Decoder<Monochrome, modm::accessor::Ram>(&buffer), origin));
170+
RF_END_RETURN_CALL(writeImage(ImageAccessor<Monochrome, modm::accessor::Ram>(&buffer), origin));
171171
}
172172

173173
// Write Flash Image
174174
modm::ResumableResult<void>
175175
write(const uint8_t *addr, Point origin = {0, 0}) {
176176
RF_BEGIN();
177177
RF_END_RETURN_CALL(writeImage(
178-
Decoder<Monochrome, modm::accessor::Flash>(addr),
178+
ImageAccessor<Monochrome, modm::accessor::Flash>(addr),
179179
origin)
180180
);
181181
}
@@ -191,7 +191,7 @@ class Ssd1306 : public ssd1306,
191191
// Write monochrome Image
192192
template<template<typename> class Accessor>
193193
modm::ResumableResult<bool>
194-
writeImage(Decoder<Monochrome, Accessor> decoder, Point origin = {0, 0});
194+
writeImage(ImageAccessor<Monochrome, Accessor> decoder, Point origin = {0, 0});
195195

196196
modm::ResumableResult<bool>
197197
writeCommands(std::size_t length);

src/modm/driver/display/ssd1306_impl.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
// ----------------------------------------------------------------------------
1111

1212
#pragma once
13-
#ifndef MODM_SSD1306_HPP
14-
#error "Don't include this file directly, use 'ssd1306.hpp' instead!"
15-
#endif
13+
#include "ssd1306.hpp"
1614

1715
template<class I2cMaster, uint16_t H>
1816
modm::ResumableResult<bool>
@@ -170,7 +168,7 @@ modm::Ssd1306<I2cMaster, H>::updateClipping()
170168
template<class I2cMaster, uint16_t H>
171169
template<template<typename> class Accessor>
172170
modm::ResumableResult<bool>
173-
modm::Ssd1306<I2cMaster, H>::writeImage(Decoder<Monochrome, Accessor> decoder, Point origin) {
171+
modm::Ssd1306<I2cMaster, H>::writeImage(ImageAccessor<Monochrome, Accessor> decoder, Point origin) {
174172
RF_BEGIN();
175173

176174
this->clipping = Rectangle(origin, decoder.size);

src/modm/ui/color/unsigned_scaling.hpp renamed to src/modm/math/scaling_unsigned.hpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
// ----------------------------------------------------------------------------
1111

12-
// TODO Find a better home for modm::UnsignedScaling
13-
1412
#pragma once
1513

1614
#include <algorithm>
@@ -21,77 +19,80 @@
2119
namespace modm {
2220

2321
/**
24-
* @brief Unsigned integer with arbitrary digits and scaling value conversion
22+
* @brief Unsigned integer with arbitrary digits and scaling value on conversion
2523
* between instances with different digits.
2624
*
2725
* @tparam D Digits
2826
*
2927
* @author Thomas Sommer
3028
*/
3129
template<int D>
32-
class UnsignedScaling {
30+
class ScalingUnsigned {
3331
public:
3432
static constexpr int Digits = D;
3533
using ValueType = uint_t<D>::least;
3634

3735
static constexpr ValueType min = 0;
3836
static constexpr ValueType max = bitmask<D>();
3937

40-
constexpr UnsignedScaling() = default;
38+
constexpr ScalingUnsigned() = default;
4139

4240
// FIXME want both:
4341
// COMPTIME: static_assert(value <= max, "value out of range")
4442
// RUNTIME: std::min(value, max) or modm_assert(value <= max, ...)
45-
constexpr UnsignedScaling(ValueType value) : value(std::min(value, max)) {
43+
constexpr ScalingUnsigned(ValueType value) : value(std::min(value, max)) {
4644
// TODO disable via lbuild option
47-
// modm_assert_continue_fail_debug(value <= max, "UnsignedScaling", "constructor", "value out of range");
45+
// modm_assert_continue_fail_debug(value <= max, "ScalingUnsigned", "constructor", "value out of range");
4846
}
4947

5048
// Construct from bigger or equal ColorGray
5149
template <int E, std::enable_if_t<(D <= E), void*> = nullptr>
52-
constexpr UnsignedScaling(const UnsignedScaling<E>& other)
50+
constexpr ScalingUnsigned(const ScalingUnsigned<E>& other)
5351
: value(other.value >> (E - D)) {}
5452

5553
template <int E, std::enable_if_t<(D <= E), void*> = nullptr>
56-
constexpr UnsignedScaling(UnsignedScaling<E> &&other)
54+
constexpr ScalingUnsigned(ScalingUnsigned<E> &&other)
5755
: value(other.value >> (E - D)) {}
5856

5957
// Construct from smaller ColorGray
6058
template <int E, std::enable_if_t<(D > E), void*> = nullptr>
61-
constexpr UnsignedScaling(const UnsignedScaling<E>& other)
59+
constexpr ScalingUnsigned(const ScalingUnsigned<E>& other)
6260
: value(other.value * max / other.max)
6361
{}
6462

6563
template <int E, std::enable_if_t<(D > E), void*> = nullptr>
66-
constexpr UnsignedScaling(UnsignedScaling<E> &&other)
64+
constexpr ScalingUnsigned(ScalingUnsigned<E> &&other)
6765
: value(other.value * max / other.max)
6866
{}
6967

7068
/* // Faster construction from monochrome
71-
constexpr UnsignedScaling(const UnsignedScaling<1> &other) : value(other.value ? bitmask<D>() : 0){}
69+
constexpr ScalingUnsigned(const ScalingUnsigned<1> &other) : value(other.value ? bitmask<D>() : 0){}
7270
73-
// constexpr UnsignedScaling(UnsignedScaling<1> &&other) : value(other.value ? bitmask<D>() : 0){}
74-
constexpr UnsignedScaling& operator=(const UnsignedScaling<1> &other) {
71+
// constexpr ScalingUnsigned(ScalingUnsigned<1> &&other) : value(other.value ? bitmask<D>() : 0){}
72+
constexpr ScalingUnsigned& operator=(const ScalingUnsigned<1> &other) {
7573
value = other.value ? bitmask<D>() : 0;
7674
return *this;
7775
} */
7876

79-
// Assign UnsignedScaling with more or equal Depth
77+
// Assign ScalingUnsigned with more or equal Depth
8078
template <int E, std::enable_if_t<(D <= E), void*> = nullptr>
81-
void operator=(const UnsignedScaling<E>& other) {
79+
void operator=(const ScalingUnsigned<E>& other) {
8280
value = other.value >> (E - D);
8381
}
8482

85-
// Assign UnsignedScaling with less Depth
83+
// Assign ScalingUnsigned with less Depth
8684
template <int E, std::enable_if_t<(D > E), void*> = nullptr>
87-
void operator=(const UnsignedScaling<E>& other) {
85+
void operator=(const ScalingUnsigned<E>& other) {
8886
value = other.value * max / other.max;
8987
}
9088

89+
// FIXME want both:
90+
// COMPTIME: static_assert(value <= max, "value out of range")
91+
// RUNTIME: std::min(value, max) or modm_assert(value <= max, ...)
9192
void setValue(ValueType value) {
9293
this->value = std::min(value, max);
9394
// TODO disable via lbuild option
94-
// modm_assert_continue_fail_debug(value <= max, "modm::UnsignedScaling", "setValue()", "value out of range");
95+
// modm_assert_continue_fail_debug(value <= max, "modm::ScalingUnsigned", "setValue()", "value out of range");
9596
}
9697

9798
ValueType getValue() const { return value; }
@@ -100,15 +101,15 @@ class UnsignedScaling {
100101
return value == max;
101102
}
102103

103-
constexpr auto operator<=>(const UnsignedScaling<D> &) const = default;
104+
constexpr auto operator<=>(const ScalingUnsigned<D> &) const = default;
104105

105106
protected:
106107
ValueType value = 0;
107108

108109
inline void max_cutoff() { value = std::min(value, max); }
109110
private:
110111
template<int>
111-
friend class UnsignedScaling;
112+
friend class ScalingUnsigned;
112113
};
113114

114115
}

src/modm/math/scaling_unsigned.lb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2021, Thomas Sommer
5+
#
6+
# This file is part of the modm project.
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
# -----------------------------------------------------------------------------
12+
13+
def init(module):
14+
module.name = ":math:scaling_unsigned"
15+
module.description = """
16+
# Scaling Unsigned
17+
18+
Unsigned integer with arbitrary digits and scaling value on conversion between
19+
instances with different digits. F.e. a 2bit scaling unsigned of 0b11 becomes
20+
0b1111 when converted to a 4bit scaling unsigned.
21+
22+
It's the baseclass to all in modm::color::* but may have wider applications.
23+
24+
"""
25+
26+
def prepare(module, options):
27+
module.depends(":utils")
28+
return True
29+
30+
def build(env):
31+
env.outbasepath = "modm/src/modm/math"
32+
env.copy("scaling_unsigned.hpp")

src/modm/ui/color/color.lb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Color containers and converters in various formats: RGB, HSV, Brightness, Rgb565
2222
def prepare(module, options):
2323
module.depends(
2424
":math:utils",
25+
":math:scaling_unsigned",
2526
":math:saturation"
2627
)
2728
return True

0 commit comments

Comments
 (0)