ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_drw.h
Go to the documentation of this file.
1
36
37#pragma once
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#include <stdint.h>
44
45#include "ra8_drw_regs.h"
46#include "ra8_err.h"
47
48/* =============================================================================
49 * Configuration / runtime data structures
50 * =============================================================================
51 */
52
86
96typedef struct {
97 int16_t x;
98 int16_t y;
99 uint16_t width_px;
100 uint16_t height_px;
101 uint32_t color_argb8888;
103
127
158
168typedef struct {
169 int16_t x0;
170 int16_t y0;
171 int16_t x1;
172 int16_t y1;
173 uint16_t width_px;
174 uint32_t color_argb8888;
176
185typedef struct {
186 int16_t x0;
187 int16_t y0;
188 int16_t x1;
189 int16_t y1;
190 int16_t x2;
191 int16_t y2;
192 uint32_t color_argb8888;
194
204typedef struct {
208
238typedef struct {
239 uint32_t* buf;
240 uint32_t cap_words;
241 uint32_t count;
242 bool overflow;
245
257typedef void (*ra8_drw_event_fn_t)(void* ctx, uint32_t status_mask);
258
259/* =============================================================================
260 * Lifecycle
261 * =============================================================================
262 */
263
297[[nodiscard]] ra8_err_t ra8_drw_init(const ra8_drw_config_t* cfg);
298
317[[nodiscard]] ra8_err_t ra8_drw_deinit(void);
318
319/* =============================================================================
320 * Status / IRQ
321 * =============================================================================
322 */
323
344[[nodiscard]] ra8_err_t ra8_drw_get_status(uint32_t* out_mask);
345
363[[nodiscard]] ra8_err_t ra8_drw_get_hwrevision(uint32_t* out);
364
390[[nodiscard]] ra8_err_t ra8_drw_clear_status(uint32_t mask);
391
416[[nodiscard]] ra8_err_t ra8_drw_set_irq_enables(uint32_t enable_mask);
417
439[[nodiscard]] ra8_err_t ra8_drw_attach_handler(ra8_drw_event_fn_t fn, void* ctx);
440
459void ra8_drw_dispatch(void);
460
481[[nodiscard]] ra8_err_t ra8_drw_wait_idle(uint32_t poll_budget);
482
483/* =============================================================================
484 * Power transition
485 * =============================================================================
486 */
487
505[[nodiscard]] ra8_err_t ra8_drw_enter_stop(void);
506
524[[nodiscard]] ra8_err_t ra8_drw_exit_stop(void);
525
538[[nodiscard]] ra8_err_t ra8_drw_reset(void);
539
540/* =============================================================================
541 * Cache control
542 * =============================================================================
543 */
544
561[[nodiscard]] ra8_err_t ra8_drw_cache_flush(bool flush_fb, bool flush_texture);
562
563/* =============================================================================
564 * Surface / blend / colour
565 * =============================================================================
566 */
567
584[[nodiscard]] ra8_err_t ra8_drw_set_gradient(const ra8_drw_gradient_t* grad);
585
600[[nodiscard]] ra8_err_t ra8_drw_set_pattern(uint8_t pattern_byte);
601
618[[nodiscard]] ra8_err_t ra8_drw_set_pattern_enable(bool enable, bool source_from_l5);
619
639[[nodiscard]] ra8_err_t ra8_drw_set_blend(const ra8_drw_blend_t* blend);
640
657[[nodiscard]] ra8_err_t ra8_drw_set_color_key(uint32_t key_rgb, bool enable);
658
659/* =============================================================================
660 * Texture
661 * =============================================================================
662 */
663
685[[nodiscard]] ra8_err_t ra8_drw_set_texture(const ra8_drw_texture_t* tex);
686
699[[nodiscard]] ra8_err_t ra8_drw_clear_texture(void);
700
726[[nodiscard]] ra8_err_t
727ra8_drw_load_clut(uint8_t start_index, const uint32_t* entries, uint32_t count);
728
729/* =============================================================================
730 * Drawing primitives
731 * =============================================================================
732 */
733
760[[nodiscard]] ra8_err_t ra8_drw_fill_rect(const ra8_drw_rect_t* rect);
761
785[[nodiscard]] ra8_err_t ra8_drw_blit_textured_rect(const ra8_drw_rect_t* rect);
786
809[[nodiscard]] ra8_err_t ra8_drw_draw_line(const ra8_drw_line_t* line);
810
831[[nodiscard]] ra8_err_t ra8_drw_draw_triangle(const ra8_drw_triangle_t* tri);
832
833/* =============================================================================
834 * Display list mode
835 * =============================================================================
836 */
837
862[[nodiscard]] ra8_err_t ra8_drw_run_dlist(const uint32_t* dlist_addr);
863
864/* =============================================================================
865 * Performance counters
866 * =============================================================================
867 */
868
889[[nodiscard]] ra8_err_t ra8_drw_perf_arm(ra8_drw_perftrigger_t event_ctr1,
890 ra8_drw_perftrigger_t event_ctr2);
891
910[[nodiscard]] ra8_err_t ra8_drw_perf_read(ra8_drw_perfcounter_id_t id, uint32_t* out);
911
929
930#ifdef __cplusplus
931}
932#endif
ra8_err_t ra8_drw_run_dlist(const uint32_t *dlist_addr)
Trigger execution of a display list.
ra8_err_t ra8_drw_get_status(uint32_t *out_mask)
Read the DRW STATUS register into *out_mask.
Definition ra8_drw.c:572
void ra8_drw_dispatch(void)
Snapshot STATUS, ack pending DRW IRQs, and fire callback.
Definition ra8_drw.c:615
ra8_err_t ra8_drw_clear_status(uint32_t mask)
Acknowledge a subset of pending DRW interrupts via IRQCTL.
Definition ra8_drw.c:589
ra8_err_t ra8_drw_attach_handler(ra8_drw_event_fn_t fn, void *ctx)
Register a software callback for DRW IRQ events.
Definition ra8_drw.c:607
ra8_err_t ra8_drw_draw_line(const ra8_drw_line_t *line)
Issue an anti-aliased line stroke between two points.
ra8_err_t ra8_drw_set_pattern(uint8_t pattern_byte)
Set the per-byte PATTERN bitmap (HUM Ch 62.2.9 p 3698).
Definition ra8_drw.c:723
ra8_err_t ra8_drw_fill_rect(const ra8_drw_rect_t *rect)
Issue a solid-fill rectangle blit into the framebuffer.
ra8_err_t ra8_drw_cache_flush(bool flush_fb, bool flush_texture)
Pulse FB and/or texture cache flush bits in CACHECTL.
Definition ra8_drw.c:688
ra8_err_t ra8_drw_perf_read(ra8_drw_perfcounter_id_t id, uint32_t *out)
Read one PERFCOUNTk register.
ra8_err_t ra8_drw_get_hwrevision(uint32_t *out)
Read the read-only HWREVISION register into *out.
Definition ra8_drw.c:581
ra8_err_t ra8_drw_reset(void)
Software reset: drain pipeline, ack IRQs, reset PERFCOUNTers.
Definition ra8_drw.c:667
ra8_err_t ra8_drw_clear_texture(void)
Disable the texture unit (clear CONTROL2.TEXTUREENABLE / RLE / CLUT).
Definition ra8_drw.c:938
ra8_err_t ra8_drw_blit_textured_rect(const ra8_drw_rect_t *rect)
Blit a textured rectangle (texture must be programmed first).
ra8_err_t ra8_drw_perf_reset(ra8_drw_perfcounter_id_t id)
Reset one PERFCOUNTk register to zero.
ra8_err_t ra8_drw_init(const ra8_drw_config_t *cfg)
Power on the DRW block, install the supplied configuration, and arm the IRQ control register.
Definition ra8_drw.c:491
ra8_err_t ra8_drw_enter_stop(void)
Drop the DRW into MSTP-gated stop (clock removed).
Definition ra8_drw.c:653
ra8_err_t ra8_drw_load_clut(uint8_t start_index, const uint32_t *entries, uint32_t count)
Load a CLUT entry pair (TEXCLADDR, TEXCLDATA, TEXCLOFFSET).
Definition ra8_drw.c:948
ra8_err_t ra8_drw_wait_idle(uint32_t poll_budget)
Poll STATUS until all "busy" bits clear or budget runs out.
Definition ra8_drw.c:631
ra8_err_t ra8_drw_set_color_key(uint32_t key_rgb, bool enable)
Programme the COLKEY register and toggle COLKEYENABLE.
Definition ra8_drw.c:828
ra8_err_t ra8_drw_set_gradient(const ra8_drw_gradient_t *grad)
Programme the COLOR1 and COLOR2 registers from a 2-stop gradient.
Definition ra8_drw.c:713
ra8_err_t ra8_drw_exit_stop(void)
Re-enable the DRW MSTP gate (clock restored).
Definition ra8_drw.c:662
ra8_err_t ra8_drw_deinit(void)
Tear down the DRW block: disable IRQs, drop the registered callback, and request MSTP gate.
Definition ra8_drw.c:545
ra8_err_t ra8_drw_set_irq_enables(uint32_t enable_mask)
Set the IRQCTL enable bits (ENUMIRQEN, DLISTIRQEN, BUSIRQEN).
Definition ra8_drw.c:597
void(* ra8_drw_event_fn_t)(void *ctx, uint32_t status_mask)
DRW asynchronous event callback signature.
Definition ra8_drw.h:257
ra8_err_t ra8_drw_perf_arm(ra8_drw_perftrigger_t event_ctr1, ra8_drw_perftrigger_t event_ctr2)
Programme PERFTRIGGER for the two performance counters and reset both PERFCOUNTk registers.
ra8_err_t ra8_drw_set_texture(const ra8_drw_texture_t *tex)
Programme TEXORIGIN, TEXPITCH, TEXMASK, U/V limiters and the CONTROL2 texture / CLUT / RLE / colour-k...
Definition ra8_drw.c:900
ra8_err_t ra8_drw_draw_triangle(const ra8_drw_triangle_t *tri)
Issue an anti-aliased filled triangle.
ra8_err_t ra8_drw_set_pattern_enable(bool enable, bool source_from_l5)
Toggle CONTROL2.PATTERNENABLE / PATTERNSOURCEL5.
Definition ra8_drw.c:732
ra8_err_t ra8_drw_set_blend(const ra8_drw_blend_t *blend)
Configure the alpha-blend unit using ra8_drw_blend_t fields.
Definition ra8_drw.c:805
2D Drawing Engine (DRW / D/AVE 2D) register layout for the RA8D2
ra8_drw_writeformat_t
Framebuffer pixel format codes (3-bit field).
ra8_drw_readformat_t
Texture pixel format codes (4-bit field).
ra8_drw_perfcounter_id_t
Selector for the two PERFCOUNTk registers.
ra8_drw_perftrigger_t
Internal events that increment a PERFCOUNT register.
ra8_drw_rlepixel_t
RLEPIXELWIDTH[1:0] – bytes per RLE-encoded texel.
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Per-pixel + global alpha blending parameters.
Definition ra8_drw.h:114
bool dst_invert
CONTROL2.BDI.
Definition ra8_drw.h:119
bool dst_factor
CONTROL2.BDF (use DST alpha).
Definition ra8_drw.h:117
bool src_invert
CONTROL2.BSI.
Definition ra8_drw.h:118
bool use_color2_dst
CONTROL2.BC2 (COLOR2 as dst).
Definition ra8_drw.h:124
bool dst_factor_alpha
CONTROL2.BDFA.
Definition ra8_drw.h:121
bool dst_invert_alpha
CONTROL2.BDIA.
Definition ra8_drw.h:123
bool use_alpha_channel
CONTROL2.USEACB.
Definition ra8_drw.h:115
bool src_invert_alpha
CONTROL2.BSIA.
Definition ra8_drw.h:122
uint8_t global_alpha
COLOR1.A (0=fully transparent).
Definition ra8_drw.h:125
bool src_factor_alpha
CONTROL2.BSFA.
Definition ra8_drw.h:120
bool src_factor
CONTROL2.BSF (use SRC alpha).
Definition ra8_drw.h:116
Minimal DRW configuration captured by ra8_drw_init.
Definition ra8_drw.h:79
bool enable_caches
Enable FB + texture caches.
Definition ra8_drw.h:83
ra8_drw_writeformat_t format
FB pixel format.
Definition ra8_drw.h:82
uint16_t pitch_px
FB pitch in pixels.
Definition ra8_drw.h:81
uintptr_t framebuffer_addr
FB base addr (target ARGB).
Definition ra8_drw.h:80
bool enable_buffered_writes
Set DBWER.BWE on init.
Definition ra8_drw.h:84
Builder state for composing a DRW display list in a caller buffer.
Definition ra8_drw.h:238
uint32_t cap_words
Buffer capacity in 32-bit words.
Definition ra8_drw.h:240
uint32_t * buf
Caller word buffer, 4-byte aligned, in SRAM.
Definition ra8_drw.h:239
bool overflow
A request exceeded the buffer capacity.
Definition ra8_drw.h:242
bool terminated
ra8_drw_dlist_end has closed the list.
Definition ra8_drw.h:243
uint32_t count
Words emitted so far (<= cap_words).
Definition ra8_drw.h:241
COLOR1 + COLOR2 two-stop gradient.
Definition ra8_drw.h:204
uint32_t color2_argb8888
COLOR2 ARGB stop.
Definition ra8_drw.h:206
uint32_t color1_argb8888
COLOR1 ARGB stop.
Definition ra8_drw.h:205
Anti-aliased line parameters.
Definition ra8_drw.h:168
int16_t y1
End-point 1 Y in pixels.
Definition ra8_drw.h:172
uint16_t width_px
Stroke width in pixels.
Definition ra8_drw.h:173
uint32_t color_argb8888
0xAARRGGBB stroke colour.
Definition ra8_drw.h:174
int16_t y0
End-point 0 Y in pixels.
Definition ra8_drw.h:170
int16_t x0
End-point 0 X in pixels.
Definition ra8_drw.h:169
int16_t x1
End-point 1 X in pixels.
Definition ra8_drw.h:171
Rectangle parameters for ra8_drw_fill_rect.
Definition ra8_drw.h:96
uint16_t height_px
Height in pixels.
Definition ra8_drw.h:100
uint32_t color_argb8888
0xAARRGGBB fill colour.
Definition ra8_drw.h:101
int16_t x
Top-left X in pixels.
Definition ra8_drw.h:97
int16_t y
Top-left Y in pixels.
Definition ra8_drw.h:98
uint16_t width_px
Width in pixels.
Definition ra8_drw.h:99
Texture parameters for ra8_drw_blit_textured_rect.
Definition ra8_drw.h:140
bool clut_565
CONTROL2.CLUTFORMAT (RGB565).
Definition ra8_drw.h:151
bool clamp_y
CONTROL2.TEXTURECLAMPY.
Definition ra8_drw.h:147
bool enable_color_key
CONTROL2.COLKEYENABLE.
Definition ra8_drw.h:152
bool clamp_x
CONTROL2.TEXTURECLAMPX.
Definition ra8_drw.h:146
uint16_t pitch_px
TEXPITCH (texels per line).
Definition ra8_drw.h:142
uint8_t clut_offset
TEXCLOFFSET CLOFFSET[7:0].
Definition ra8_drw.h:156
ra8_drw_readformat_t format
READFORMAT_H+L 4-bit value.
Definition ra8_drw.h:145
bool filter_y
CONTROL2.TEXTUREFILTERY.
Definition ra8_drw.h:149
uintptr_t base_addr
TEXORIGIN – texel base.
Definition ra8_drw.h:141
bool enable_rle
CONTROL2.RLEENABLE.
Definition ra8_drw.h:154
uint32_t color_key_rgb
COLKEY value (0x00RRGGBB).
Definition ra8_drw.h:153
uint16_t u_mask
TEXMASK[15:0] (U mask).
Definition ra8_drw.h:143
bool filter_x
CONTROL2.TEXTUREFILTERX.
Definition ra8_drw.h:148
ra8_drw_rlepixel_t rle_pixel_width
CONTROL2.RLEPIXELWIDTH.
Definition ra8_drw.h:155
bool enable_clut
CONTROL2.CLUTENABLE.
Definition ra8_drw.h:150
uint16_t v_mask
TEXMASK[31:16] (V mask).
Definition ra8_drw.h:144
Anti-aliased filled triangle parameters.
Definition ra8_drw.h:185
int16_t y0
Vertex 0 Y.
Definition ra8_drw.h:187
int16_t y1
Vertex 1 Y.
Definition ra8_drw.h:189
int16_t y2
Vertex 2 Y.
Definition ra8_drw.h:191
int16_t x2
Vertex 2 X.
Definition ra8_drw.h:190
uint32_t color_argb8888
Fill colour.
Definition ra8_drw.h:192
int16_t x1
Vertex 1 X.
Definition ra8_drw.h:188
int16_t x0
Vertex 0 X.
Definition ra8_drw.h:186