Compare commits

..

1 Commits

Author SHA1 Message Date
75046d1c1a Make use of C++ standard library 2022-05-29 16:13:53 +02:00

View File

@@ -1,6 +1,8 @@
#pragma once
#include <stdint.h>
#include <utility>
#include <cstdint>
#include <avr/pgmspace.h>
@@ -10,11 +12,11 @@
namespace eink {
template <uint16_t Width, uint16_t Height, typename Spi, io::P RstPin, io::P DcPin, io::P BusyPin>
template <std::uint16_t Width, std::uint16_t Height, typename Spi, io::P RstPin, io::P DcPin, io::P BusyPin>
class Eink {
using word_t = typename Spi::word_t;
enum class Cmd : uint8_t {
enum class Cmd : std::uint8_t {
DRIVER_OUTPUT_CONTROL = 0x01,
DEEP_SLEEP_MODE = 0x10,
DATA_ENTRY_MODE = 0x11,
@@ -40,7 +42,7 @@ class Eink {
static constexpr auto BLOCK_SIZE = 5;
enum class Color : uint8_t {
enum class Color : std::uint8_t {
BLACK = 0b00,
WHITE = 0b01,
RED = 0b10,
@@ -49,12 +51,12 @@ class Eink {
class ImageBlock {
public:
inline Color &operator[](const size_t idx)
inline Color &operator[](const std::size_t idx)
{
return data[idx];
}
inline const Color &operator[](const size_t idx) const
inline const Color &operator[](const std::size_t idx) const
{
return data[idx];
}
@@ -147,26 +149,26 @@ class Eink {
template <typename Image>
static void draw(const Image &image)
{
constexpr auto lookup = [](uint8_t bits) {
constexpr auto lookup = [](std::uint8_t bits) {
auto block = ImageBlock{};
for_constexpr(
util::for_constexpr(
[&](const auto idx) {
block[idx.value] = static_cast<Color>(bits % 3);
bits /= 3;
},
util::make_index_sequence<BLOCK_SIZE>{});
std::make_index_sequence<BLOCK_SIZE>{});
return block;
};
constexpr auto sendImageChannel = [lookup](const auto command, const auto image) {
sendCommand(command);
auto buffer = uint8_t{0};
auto bufferPos = uint8_t{0};
for (auto i = uint16_t{0}; i < Width * Height / BLOCK_SIZE; i++) {
auto buffer = std::uint8_t{0};
auto bufferPos = std::uint8_t{0};
for (auto i = std::uint16_t{0}; i < Width * Height / BLOCK_SIZE; i++) {
const auto block = lookup(pgm_read_byte(&image[i]));
for (auto p = uint8_t{0}; p < BLOCK_SIZE; ++p) {
const auto pixel = uint8_t{(command == Cmd::WRITE_RAM_BLACK) ? (block[p] != Color::BLACK)
: (block[p] == Color::RED)};
for (auto p = std::uint8_t{0}; p < BLOCK_SIZE; ++p) {
const auto pixel = std::uint8_t{(command == Cmd::WRITE_RAM_BLACK) ? (block[p] != Color::BLACK)
: (block[p] == Color::RED)};
buffer |= pixel << (7 - bufferPos++);
if (bufferPos == 8) {
sendData(buffer);
@@ -189,11 +191,11 @@ class Eink {
static void clear()
{
sendCommand(Cmd::WRITE_RAM_BLACK);
for (auto i = uint16_t{0}; i < Width * Height / 8; i++) {
for (auto i = std::uint16_t{0}; i < Width * Height / 8; i++) {
sendData(0xff);
}
sendCommand(Cmd::WRITE_RAM_RED);
for (auto i = uint16_t{0}; i < Width * Height / 8; i++) {
for (auto i = std::uint16_t{0}; i < Width * Height / 8; i++) {
sendData(0x00);
}