CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
MonoSurface.cpp
Go to the documentation of this file.
1
5
7
8#include "esp_heap_caps.h"
9
10#include <cstring>
11
12namespace cdc::ui {
13
14MonoSurface::MonoSurface(uint16_t w, uint16_t h)
15 : Adafruit_GFX(static_cast<int16_t>(w), static_cast<int16_t>(h)),
16 stride_(static_cast<uint16_t>((w + 7) / 8)) {
17 const size_t bytes = static_cast<size_t>(stride_) * h;
18 if (bytes == 0) return;
19 bits_ = static_cast<uint8_t*>(heap_caps_malloc(bytes, MALLOC_CAP_SPIRAM));
20 if (bits_) std::memset(bits_, 0, bytes);
21}
22
24 if (bits_) heap_caps_free(bits_);
25}
26
27void MonoSurface::drawPixel(int16_t x, int16_t y, uint16_t color) {
28 if (!bits_ || x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT) return;
29 uint8_t& cell = bits_[static_cast<size_t>(y) * stride_ + (x >> 3)];
30 const uint8_t mask = static_cast<uint8_t>(0x80u >> (x & 7));
31 if (color) cell |= mask;
32 else cell &= static_cast<uint8_t>(~mask);
33}
34
36 if (bits_) std::memset(bits_, 0, byteSize());
37}
38
39} // namespace cdc::ui
Offscreen 1-bpp Adafruit_GFX render target in PSRAM.
void clear()
Clears the surface to white.
MonoSurface(uint16_t w, uint16_t h)
Allocates a w x h 1-bpp surface in PSRAM, cleared to white.
size_t byteSize() const
Total packed byte size.
Definition MonoSurface.h:48
void drawPixel(int16_t x, int16_t y, uint16_t color) override
Centralized key-code constants for cdc_views.
Definition IModule.h:8