Refactor block helper

This commit is contained in:
BlackMark 2022-05-28 11:45:42 +02:00
parent 438765511c
commit 9a4193ee75

View File

@ -33,6 +33,31 @@ class Eink {
static io::Pin<DcPin> m_dc; static io::Pin<DcPin> m_dc;
static io::Pin<BusyPin> m_bsy; static io::Pin<BusyPin> m_bsy;
static constexpr auto BLOCK_SIZE = 5;
enum class Color : uint8_t {
BLACK = 0b00,
WHITE = 0b01,
RED = 0b10,
ERROR = 0b11,
};
class ImageBlock {
public:
inline Color &operator[](const size_t idx)
{
return data[idx];
}
inline const Color &operator[](const size_t idx) const
{
return data[idx];
}
private:
Color data[BLOCK_SIZE];
};
public: public:
static void init() static void init()
{ {
@ -113,33 +138,8 @@ class Eink {
template <typename Image> template <typename Image>
static void draw(const Image &image) static void draw(const Image &image)
{ {
constexpr auto BLOCK_SIZE = 5;
enum class Color : uint8_t {
BLACK = 0b00,
WHITE = 0b01,
RED = 0b10,
ERROR = 0b11,
};
class Block {
public:
inline Color &operator[](const size_t idx)
{
return data[idx];
}
inline const Color &operator[](const size_t idx) const
{
return data[idx];
}
private:
Color data[BLOCK_SIZE];
};
constexpr auto lookup = [](uint8_t bits) { constexpr auto lookup = [](uint8_t bits) {
auto block = Block{}; auto block = ImageBlock{};
for_constexpr( for_constexpr(
[&](const auto idx) { [&](const auto idx) {
block[idx.value] = static_cast<Color>(bits % 3); block[idx.value] = static_cast<Color>(bits % 3);