CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
host_api_display.cpp
Go to the documentation of this file.
1
9
12#include "cdc_hal/IDisplay.h"
14#include "host_str_conv.h"
15#include <goodisplay/gdey029T94.h>
16#include <string>
17
18extern "C" void* plg_get_active_plugin(void);
19
20namespace {
21
24}
25
26bool allowed() {
27 auto* p = active();
28 return p && p->manifest().capabilities.display_lowlevel;
29}
30
32
33} // namespace
34
35extern "C" {
36
37uint16_t host_display_width(void)
38{
39 auto* d = disp();
40 return (allowed() && d) ? d->getWidth() : 0;
41}
42
43uint16_t host_display_height(void)
44{
45 auto* d = disp();
46 return (allowed() && d) ? d->getHeight() : 0;
47}
48
50{
51 if (!allowed()) return HOST_ERR_NO_CAPABILITY;
52 auto* d = disp();
53 if (!d) return HOST_ERR_GENERIC;
54 d->clear();
55 return HOST_OK;
56}
57
58int host_display_draw_pixel(int16_t x, int16_t y, uint16_t color)
59{
60 if (!allowed()) return HOST_ERR_NO_CAPABILITY;
61 auto* d = disp();
62 if (!d) return HOST_ERR_GENERIC;
63 d->drawPixel(x, y, color);
64 return HOST_OK;
65}
66
67int host_display_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
68{
69 if (!allowed()) return HOST_ERR_NO_CAPABILITY;
70 auto* d = disp();
71 if (!d) return HOST_ERR_GENERIC;
72 d->drawLine(x0, y0, x1, y1, color);
73 return HOST_OK;
74}
75
76int host_display_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
77{
78 if (!allowed()) return HOST_ERR_NO_CAPABILITY;
79 auto* d = disp();
80 if (!d) return HOST_ERR_GENERIC;
81 d->drawRect(x, y, w, h, color);
82 return HOST_OK;
83}
84
85int host_display_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
86{
87 if (!allowed()) return HOST_ERR_NO_CAPABILITY;
88 auto* d = disp();
89 if (!d) return HOST_ERR_GENERIC;
90 d->fillRect(x, y, w, h, color);
91 return HOST_OK;
92}
93
94int host_display_draw_text(int16_t x, int16_t y, const char* text, uint8_t size, uint16_t color)
95{
96 if (!allowed()) return HOST_ERR_NO_CAPABILITY;
97 if (!text) return HOST_ERR_INVALID_ARG;
98 auto* d = disp();
99 if (!d) return HOST_ERR_GENERIC;
100 auto* gfx = static_cast<Gdey029T94*>(d->getNativeHandle());
101 if (!gfx) return HOST_ERR_GENERIC;
102 d->setTextSize(size ? size : 1);
103 d->setTextColor(color);
104 d->setCursor(x, y);
106 return HOST_OK;
107}
108
109int host_display_flush(uint8_t refresh_mode)
110{
111 if (!allowed()) return HOST_ERR_NO_CAPABILITY;
112 auto* d = disp();
113 if (!d) return HOST_ERR_GENERIC;
114 d->flush(refresh_mode == 1 ? cdc::hal::RefreshMode::PARTIAL : cdc::hal::RefreshMode::FULL);
115 return HOST_OK;
116}
117
119{
120 auto* d = disp();
121 return (allowed() && d) ? d->isBusy() : false;
122}
123
124} // extern "C"
Owned WAMR module instance + per-plugin state.
int host_display_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a rectangle outline.
bool host_display_is_busy(void)
True while the panel is processing a previous refresh.
int host_display_draw_pixel(int16_t x, int16_t y, uint16_t color)
Set a single pixel.
int host_display_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Draw a line between two points.
uint16_t host_display_width(void)
Display width in pixels.
int host_display_flush(uint8_t refresh_mode)
Push the framebuffer to the panel using the given refresh mode.
int host_display_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a filled rectangle.
int host_display_draw_text(int16_t x, int16_t y, const char *text, uint8_t size, uint16_t color)
Draw text using the default GFX font.
uint16_t host_display_height(void)
Display height in pixels.
int host_display_clear(void)
Clear the framebuffer to background.
CDC Badge OS plugin host API - canonical C ABI contract.
#define HOST_ERR_NO_CAPABILITY
Definition host_api.h:40
#define HOST_OK
Definition host_api.h:37
#define HOST_ERR_INVALID_ARG
Definition host_api.h:39
#define HOST_ERR_GENERIC
Definition host_api.h:38
void * plg_get_active_plugin(void)
Internal UTF-8 <-> CP437 helpers for the plugin host API boundary.
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
std::string toDisplay(const char *utf8)
Decode a UTF-8 (with optional HTML entities) string into CP437 bytes.
void printText(Gdey029T94 *gfx, const char *text)
Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.