mirror of
https://github.com/stasenso/rp_pico_display_engine.git
synced 2026-06-27 05:42:41 +03:00
render: add reusable renderer module and wire Thermometr example
This commit is contained in:
@@ -1,34 +1,19 @@
|
||||
#include "pico/stdlib.h"
|
||||
#include "display/display.h"
|
||||
#include "display/renderer.h"
|
||||
|
||||
|
||||
#define WIDTH 240
|
||||
#define WIDTH 320
|
||||
#define HEIGHT 240
|
||||
|
||||
|
||||
static void on_frame_done(void)
|
||||
{
|
||||
// В SAFE режиме swap выполняется внутри submit()
|
||||
// В режиме SAFE смена буферов выполняется внутри submit()
|
||||
display_submit();
|
||||
}
|
||||
|
||||
|
||||
static void render_test_pattern(uint16_t* buf)
|
||||
{
|
||||
for (uint16_t y = 0; y < HEIGHT; y++)
|
||||
{
|
||||
for (uint16_t x = 0; x < WIDTH; x++)
|
||||
{
|
||||
uint16_t r = (x & 0x1F) << 11;
|
||||
uint16_t g = (y & 0x3F) << 5;
|
||||
uint16_t b = (x & 0x1F);
|
||||
|
||||
buf[y * WIDTH + x] = r | g | b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
stdio_init_all();
|
||||
@@ -43,19 +28,27 @@ int main()
|
||||
|
||||
display_init(&cfg);
|
||||
|
||||
// Рисуем первый кадр
|
||||
uint16_t* buf = display_get_draw_buffer();
|
||||
render_test_pattern(buf);
|
||||
display_submit(); /* Запускаем конвейер кадра */
|
||||
|
||||
display_submit();
|
||||
float phase = 0.0f;
|
||||
render_ctx_t rc;
|
||||
|
||||
while (1)
|
||||
{
|
||||
display_poll();
|
||||
|
||||
// Здесь можно обновлять содержимое буфера
|
||||
// SAFE + 1 buffer будет ждать окончания DMA
|
||||
buf = display_get_draw_buffer();
|
||||
render_test_pattern(buf);
|
||||
/* SAFE + 1 буфер: ожидание освобождения внутри display_get_draw_buffer() */
|
||||
uint16_t* buf = display_get_draw_buffer();
|
||||
render_begin(&rc, buf, WIDTH, HEIGHT);
|
||||
|
||||
render_clear(&rc, 0x10A2);
|
||||
render_grid(&rc, 20, 20, 40, 0x5ACB);
|
||||
render_sine_wave(&rc, WIDTH, 50, 2.0f, 0, HEIGHT / 2, phase, 0xF800);
|
||||
|
||||
phase += 0.08f;
|
||||
if (phase > 6.2831853f)
|
||||
{
|
||||
phase -= 6.2831853f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user