ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_drw.c
Go to the documentation of this file.
1
45
46#include "ra8_drw.h"
47
48#include <stdint.h>
49
50#include "ra8_attributes.h"
51#include "ra8_check.h"
52#include "ra8_drw_internal.h"
53#include "ra8_drw_regs.h"
54#include "ra8_err.h"
55#include "ra8_log.h"
56#include "ra8_lpm.h"
57#include "ra8_mstp.h"
58
75bool priv_ra8_drw_internal_rect_below_min(uint16_t min_dim, uint16_t width, uint16_t height)
76{
77 return (width < min_dim) || (height < min_dim);
78}
79
98 uint16_t max_h,
99 uint16_t width,
100 uint16_t height)
101{
102 return (width > max_w) || (height > max_h);
103}
104
105/* =============================================================================
106 * Driver-private state
107 * =============================================================================
108 */
109
122static const char* s_tag = "DRW";
123
129
134static void* s_drw_ctx;
135
150static uint32_t s_drw_origin;
151
166static uint32_t s_drw_control2;
167
182static uint32_t s_drw_color1;
183
199static uint32_t s_drw_pitch_px;
200
209static uint32_t s_drw_bytes_px;
210
213{
214 return s_drw_origin;
215}
216
218{
219 const uint32_t x = (uint32_t)(int32_t)rect->x;
220 const uint32_t y = (uint32_t)(int32_t)rect->y;
221 const uint32_t off = ((y * s_drw_pitch_px) + x) * s_drw_bytes_px;
222 return s_drw_origin + off;
223}
224
226{
227 bool off = false;
228 if ((rect->x < 0) || (rect->y < 0)) {
229 off = true;
230 } else {
231 const uint32_t right = (uint32_t)(int32_t)rect->x + (uint32_t)rect->width_px;
232 off = (right > s_drw_pitch_px);
233 }
234 return off;
235}
236
239{
240 /* HUM Ch 62.2.7 "COLOR1: Base Color Register", p 3697 */
242 s_drw_color1 = argb8888;
243}
244
245/* =============================================================================
246 * Internal helpers
247 * =============================================================================
248 */
249
271{
272 const uint32_t low = ((uint32_t)fmt & 0x3U) << k_ra8_drw_control2_writeformat_pos;
273 uint32_t high = 0UL;
274 if (((uint32_t)fmt & 0x4UL) != 0UL) {
276 }
277 return low | high;
278}
279
299{
300 const uint32_t code = (uint32_t)fmt;
301 const uint32_t lo = (code & 0x3U) << k_ra8_drw_control2_readformatl_pos;
302 const uint32_t hi = ((code >> 2U) & 0x3U) << k_ra8_drw_control2_readformath_pos;
303 return lo | hi;
304}
305
330{
331 /* RGB565 / ARGB4444 default to 16 bpp; the two exclusive overrides below
332 * pick 8 or 32 bpp when they match. */
333 uint32_t bytes = (uint32_t)k_ra8_drw_bytes_px_16bpp;
334 if (fmt == k_ra8_drw_writefmt_a8) {
335 bytes = (uint32_t)k_ra8_drw_bytes_px_8bpp;
336 }
337 if (fmt == k_ra8_drw_writefmt_argb8888) {
338 bytes = (uint32_t)k_ra8_drw_bytes_px_32bpp;
339 }
340 return bytes;
341}
342
385
405static inline uint32_t internal_control2_rmw(uint32_t clear_mask, uint32_t set_mask)
406{
407 /* CONTROL2 is write-only on silicon (HUM Ch 62.2.2, R/W column "W"), so the
408 * read-modify-write MUST source the software shadow, never the register. */
409 const uint32_t nxt = (s_drw_control2 & ~clear_mask) | set_mask;
410 /* HUM Ch 62.2.2 "CONTROL2: Surface Control Register", p 3691 */
412 s_drw_control2 = nxt;
413 return nxt;
414}
415
417{
418 /* HUM Ch 62.2.29 "SIZE: Bounding Box Dimension Register", p 3704 */
419 /* The bounding box IS the rectangle: HUM Ch 62.6.2 p 3716 has the engine
420 * scan "the whole bounding box" anchored at ORIGIN, so an axis-aligned
421 * solid rectangle needs no spatial limiter at all -- the scan produces
422 * exactly the requested extent. */
424 ((uint32_t)rect->height_px << k_ra8_drw_size_height_pos) | (uint32_t)rect->width_px;
425
426 /* HUM Ch 62.2.10 "LnSTART: Limiter n Start Value Register", p 3698 */
427 /* Clear the six spatial limiters so a previous line/triangle primitive
428 * cannot leak an edge into this box. CONTROL disables them, but leaving
429 * live values behind makes a mis-set CONTROL fail silently instead of
430 * loudly. */
435
436 /* HUM Ch 62.2.11 "LnXADD: Limiter n X-Axis Increment Register", p 3698 */
441
442 /* HUM Ch 62.2.12 "LnYADD: Limiter n Y-Axis Increment Register", p 3699 */
447}
448
470{
471 /* HUM Ch 62.2.4 "CACHECTL: Cache Control Register", p 3694 */
472 if (cfg->enable_caches) {
474 } else {
476 }
477
478 /* HUM Ch 62.2.35 "DBWER: DRW Bufferable Write Enable", p 3707 */
479 if (cfg->enable_buffered_writes) {
481 } else {
483 }
484}
485
486/* =============================================================================
487 * Lifecycle
488 * =============================================================================
489 */
490
491[[nodiscard]] ra8_err_t ra8_drw_init(const ra8_drw_config_t* cfg)
492{
493 RA8_CHECK_NULL_PTR(cfg, s_tag, "cfg must not be nullptr");
494
495 /* The DRW lives in the GRAPHICS POWER DOMAIN, which is gated OFF out of
496 * reset (PDCTRGD = 0x81: PDPGSF = 1, PDDE = 1 -- HUM Ch 11.2.14 p 452;
497 * domain contents in HUM Ch 11.5.1 Table 11.7 p 480). Cancelling
498 * module-stop is NOT sufficient: with the domain dark every DRW register
499 * reads 0 and every write is lost, which is exactly why the engine never
500 * rasterised a pixel on silicon (#247) while ra8_emulator -- modelling no
501 * power domain -- rendered happily. Power the domain first.
502 * Bench evidence: HWREVISION reads 0x00000000 before this call and
503 * 0x0FBE0107 after it. */
505 /* GCOVR_EXCL_BR_START -- HW power-up ack */
506 RA8_RETURN_ON_ERROR(pd_err, s_tag, "drw_init: graphics power");
507 /* GCOVR_EXCL_BR_STOP */
508
509 /* HUM Ch 11.2.8 "MSTPCRC: Module Stop Control Register C", p 446 */
511 /* GCOVR_EXCL_BR_START -- MSTP HW readback */
512 RA8_RETURN_ON_ERROR(mst_err, s_tag, "drw_init: mstp enable");
513 /* GCOVR_EXCL_BR_STOP */
514
515 /* HUM Ch 62.2.3 "IRQCTL: Interrupt Control Register", p 3693 */
516 /* Clear all pending IRQs and leave them masked. */
518
519 /* HUM Ch 62.2.31 "ORIGIN: Framebuffer Base Address Register", p 3705 */
520 /* Cache the framebuffer base: writing ORIGIN is the render TRIGGER, so
521 * every primitive re-writes it as its final step (see ra8_drw_draw.c).
522 * This init write fires a trigger too, but the limiters/SIZE are still
523 * zero so no pixel is produced. */
524 s_drw_origin = (uint32_t)cfg->framebuffer_addr;
526
527 s_drw_pitch_px = (uint32_t)cfg->pitch_px;
529
530 /* HUM Ch 62.2.30 "PITCH: Framebuffer Pitch and Spanstore Delay
531 * Register", p 3705. Spanstore delay (SSD) field [31:16] kept 0. */
532 *ra8_drw_reg32(k_ra8_drw_off_pitch) = (uint32_t)cfg->pitch_px;
533
534 /* HUM Ch 62.2.2 "CONTROL2: Surface Control Register", p 3690 */
537 s_drw_color1 = 0U;
538
540
541 ra8_log_info_val(s_tag, "drw_init fb", (uint32_t)cfg->framebuffer_addr);
542 return k_ra8_ok;
543}
544
545[[nodiscard]] ra8_err_t ra8_drw_deinit(void)
546{
547 /* HUM Ch 62.2.3 "IRQCTL: Interrupt Control Register", p 3693 */
548 /* Clear and disable every interrupt before dropping the clock. */
550
551 /* HUM Ch 62.2.4 "CACHECTL: Cache Control Register", p 3694 */
553
554 /* HUM Ch 62.2.35 "DBWER: DRW Bufferable Write Enable", p 3707 */
556
557 s_drw_fn = nullptr;
558 s_drw_ctx = nullptr;
559 s_drw_origin = 0U;
560 s_drw_pitch_px = 0U;
561 s_drw_bytes_px = 0U;
562 s_drw_control2 = 0U;
563 s_drw_color1 = 0U;
565}
566
567/* =============================================================================
568 * Status / IRQ
569 * =============================================================================
570 */
571
572[[nodiscard]] ra8_err_t ra8_drw_get_status(uint32_t* out_mask)
573{
574 RA8_CHECK_NULL_PTR(out_mask, s_tag, "out_mask must not be nullptr");
575 /* HUM Ch 62.2.5 "STATUS: Status Control Register", p 3695 */
576 /* STATUS aliases CONTROL: a read returns engine status bits. */
578 return k_ra8_ok;
579}
580
581[[nodiscard]] ra8_err_t ra8_drw_get_hwrevision(uint32_t* out)
582{
583 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
584 /* HUM Ch 62.2.6 "HWREVISION: Hardware Revision Register", p 3696 */
586 return k_ra8_ok;
587}
588
589[[nodiscard]] ra8_err_t ra8_drw_clear_status(uint32_t mask)
590{
591 /* HUM Ch 62.2.3 "IRQCTL: Interrupt Control Register", p 3693 */
592 /* Write-1-to-clear semantics for ENUMIRQCLR/DLISTIRQCLR/BUSIRQCLR. */
594 return k_ra8_ok;
595}
596
597[[nodiscard]] ra8_err_t ra8_drw_set_irq_enables(uint32_t enable_mask)
598{
599 /* HUM Ch 62.2.3 "IRQCTL: Interrupt Control Register", p 3693 */
600 /* Combine caller's enable bits with an unconditional W1C of every
601 * pending flag so we never re-enable while a stale flag is latched. */
602 const uint32_t value = (enable_mask | k_ra8_drw_irqctl_all_clr);
604 return k_ra8_ok;
605}
606
608{
609 s_drw_fn = fn;
610 s_drw_ctx = ctx;
611 return k_ra8_ok;
612}
613
616{
617 /* HUM Ch 62.2.5 "STATUS: Status Control Register", p 3695 */
618 const uint32_t status = *ra8_drw_reg32(k_ra8_drw_off_status);
619
620 /* HUM Ch 62.2.3 "IRQCTL: Interrupt Control Register", p 3693 */
621 /* Acknowledge all pending IRQ flags (write-1-to-clear). */
623
624 const ra8_drw_event_fn_t fn = s_drw_fn;
625 void* const ctx = s_drw_ctx;
626 if (fn != nullptr) {
627 fn(ctx, status);
628 }
629}
630
631[[nodiscard]] ra8_err_t ra8_drw_wait_idle(uint32_t poll_budget)
632{
633 if (poll_budget == 0UL) {
635 }
636 /* NASA Rule 2: bounded loop. */
637 for (uint32_t i = 0UL; i < poll_budget; ++i) {
638 /* HUM Ch 62.2.5 "STATUS: Status Control Register", p 3695 */
639 const uint32_t s = *ra8_drw_reg32(k_ra8_drw_off_status);
640 if ((s & k_ra8_drw_status_busy_mask) == 0UL) {
641 return k_ra8_ok;
642 }
643 }
644 ra8_log_error(s_tag, "drw_wait_idle: timeout");
646}
647
648/* =============================================================================
649 * Power transition
650 * =============================================================================
651 */
652
653[[nodiscard]] ra8_err_t ra8_drw_enter_stop(void)
654{
655 /* HUM Ch 62.2.3 "IRQCTL: Interrupt Control Register", p 3693 */
656 /* Quiesce IRQs before removing the clock, otherwise a pending bit
657 * could latch and surprise us when we power back up. */
660}
661
662[[nodiscard]] ra8_err_t ra8_drw_exit_stop(void)
663{
665}
666
667[[nodiscard]] ra8_err_t ra8_drw_reset(void)
668{
669 /* HUM Ch 62.2.3 "IRQCTL: Interrupt Control Register", p 3693 */
671
672 /* HUM Ch 62.2.4 "CACHECTL: Cache Control Register", p 3694 */
673 /* Pulse both cache flushes while preserving enable bits. */
674 const uint32_t cur_cc = *ra8_drw_reg32(k_ra8_drw_off_cachectl);
676
677 /* HUM Ch 62.2.34 "PERFCOUNTk: Performance Counter k", p 3706 */
680 return k_ra8_ok;
681}
682
683/* =============================================================================
684 * Cache control
685 * =============================================================================
686 */
687
688[[nodiscard]] ra8_err_t ra8_drw_cache_flush(bool flush_fb, bool flush_texture)
689{
690 if (!flush_fb && !flush_texture) {
691 ra8_log_warn(s_tag, "cache_flush: nothing to flush");
692 } else {
693 /* HUM Ch 62.2.4 "CACHECTL: Cache Control Register", p 3694 */
694 /* Preserve enable bits, OR in the requested flush pulses. */
695 const uint32_t cur = *ra8_drw_reg32(k_ra8_drw_off_cachectl);
696 uint32_t nxt = cur;
697 if (flush_fb) {
699 }
700 if (flush_texture) {
702 }
704 }
705 return k_ra8_ok;
706}
707
708/* =============================================================================
709 * Surface / blend / colour
710 * =============================================================================
711 */
712
714{
715 RA8_CHECK_NULL_PTR(grad, s_tag, "grad must not be nullptr");
716 /* COLOR1 goes through the shadowed writer (write-only register). */
718 /* HUM Ch 62.2.8 "COLOR2: Secondary Color Register", p 3697 */
720 return k_ra8_ok;
721}
722
723[[nodiscard]] ra8_err_t ra8_drw_set_pattern(uint8_t pattern_byte)
724{
725 /* HUM Ch 62.2.9 "PATTERN: Pattern Register", p 3698 */
726 /* Only PATTERN[7:0] is writable; bits 31:8 must be zero. */
728 (uint32_t)pattern_byte & (uint32_t)k_ra8_drw_internal_byte_mask;
729 return k_ra8_ok;
730}
731
732[[nodiscard]] ra8_err_t ra8_drw_set_pattern_enable(bool enable, bool source_from_l5)
733{
734 uint32_t set_bits = 0UL;
735 if (enable) {
737 }
738 if (source_from_l5) {
740 }
742 (void)internal_control2_rmw(clr_mask, set_bits);
743 return k_ra8_ok;
744}
745
769static uint32_t internal_pack_blend_bits(const ra8_drw_blend_t* blend)
770{
771 uint32_t set_bits = 0UL;
772 if (blend->use_alpha_channel) {
773 set_bits |= k_ra8_drw_control2_useacb;
774 }
775 if (blend->src_factor) {
776 set_bits |= k_ra8_drw_control2_bsf;
777 }
778 if (blend->dst_factor) {
779 set_bits |= k_ra8_drw_control2_bdf;
780 }
781 if (blend->src_invert) {
782 set_bits |= k_ra8_drw_control2_bsi;
783 }
784 if (blend->dst_invert) {
785 set_bits |= k_ra8_drw_control2_bdi;
786 }
787 if (blend->src_factor_alpha) {
788 set_bits |= k_ra8_drw_control2_bsfa;
789 }
790 if (blend->dst_factor_alpha) {
791 set_bits |= k_ra8_drw_control2_bdfa;
792 }
793 if (blend->src_invert_alpha) {
794 set_bits |= k_ra8_drw_control2_bsia;
795 }
796 if (blend->dst_invert_alpha) {
797 set_bits |= k_ra8_drw_control2_bdia;
798 }
799 if (blend->use_color2_dst) {
800 set_bits |= k_ra8_drw_control2_bc2;
801 }
802 return set_bits;
803}
804
805[[nodiscard]] ra8_err_t ra8_drw_set_blend(const ra8_drw_blend_t* blend)
806{
807 RA8_CHECK_NULL_PTR(blend, s_tag, "blend must not be nullptr");
808
809 /* HUM Ch 62.2.2 "CONTROL2: Surface Control Register", p 3691 */
810 const uint32_t set_bits = internal_pack_blend_bits(blend);
811 const uint32_t clr_mask =
816 (void)internal_control2_rmw(clr_mask, set_bits);
817
818 /* Update only the alpha byte; preserve RGB to avoid surprise drift.
819 * COLOR1 is write-only on silicon, so the current value comes from the
820 * software shadow, and the write goes through the shadowed writer. */
821 const uint32_t new_color1 = (s_drw_color1 & k_ra8_drw_internal_color_alpha_mask) |
822 ((uint32_t)blend->global_alpha << k_ra8_drw_color_a_pos);
824
825 return k_ra8_ok;
826}
827
828[[nodiscard]] ra8_err_t ra8_drw_set_color_key(uint32_t key_rgb, bool enable)
829{
830 /* HUM Ch 62.2.28 "COLKEY: Color Key Register", p 3704 */
831 /* Bits 31:24 must be zero per the HUM table. */
833
834 uint32_t set_bits = 0UL;
835 if (enable) {
837 }
839 return k_ra8_ok;
840}
841
842/* =============================================================================
843 * Texture
844 * =============================================================================
845 */
846
869{
870 uint32_t set_bits = k_ra8_drw_control2_textureenable;
871 set_bits |= internal_pack_readformat(tex->format);
872 if (tex->clamp_x) {
874 }
875 if (tex->clamp_y) {
877 }
878 if (tex->filter_x) {
880 }
881 if (tex->filter_y) {
883 }
884 if (tex->enable_clut) {
886 }
887 if (tex->clut_565) {
889 }
890 if (tex->enable_color_key) {
892 }
893 if (tex->enable_rle) {
895 }
896 set_bits |= ((uint32_t)tex->rle_pixel_width & 0x3U) << k_ra8_drw_control2_rlepixel_pos;
897 return set_bits;
898}
899
901{
902 RA8_CHECK_NULL_PTR(tex, s_tag, "tex must not be nullptr");
903 if ((uint16_t)tex->pitch_px > k_ra8_drw_max_texpitch_tx) {
905 }
906
907 /* HUM Ch 62.2.17 "TEXORIGIN: Texture Base Address Register", p 3700 */
909
910 /* HUM Ch 62.2.15 "TEXPITCH: Texels Per Texture Line Register", p 3700 */
912
913 /* HUM Ch 62.2.16 "TEXMASK: Texture U/V Mask Register", p 3700.
914 * U mask in [15:0], V mask in [31:16]. */
915 *ra8_drw_reg32(k_ra8_drw_off_texmask) = ((uint32_t)tex->v_mask << 16U) | (uint32_t)tex->u_mask;
916
917 /* HUM Ch 62.2.27 "TEXCLOFFSET: CLUT Offset Register", p 3704 */
919 (uint32_t)tex->clut_offset & (uint32_t)k_ra8_drw_internal_byte_mask;
920
921 const uint32_t set_bits = internal_pack_texture_bits(tex);
922 const uint32_t clr_mask =
929 (void)internal_control2_rmw(clr_mask, set_bits);
930
931 if (tex->enable_color_key) {
932 /* HUM Ch 62.2.28 "COLKEY: Color Key Register", p 3704 */
934 }
935 return k_ra8_ok;
936}
937
946
947[[nodiscard]] ra8_err_t
948ra8_drw_load_clut(uint8_t start_index, const uint32_t* entries, uint32_t count)
949{
950 RA8_CHECK_NULL_PTR(entries, s_tag, "entries must not be nullptr");
951 if (count == 0UL) {
953 }
954 if (((uint32_t)start_index + count) > (uint32_t)k_ra8_drw_internal_clut_max) {
956 }
957
958 /* HUM Ch 62.2.25 "TEXCLADDR: CLUT Start Address Register", p 3703 */
959 *ra8_drw_reg32(k_ra8_drw_off_texcladdr) = (uint32_t)start_index;
960
961 /* HUM Ch 62.2.26 "TEXCLDATA: CLUT Data Register", p 3703 */
962 /* The DRW auto-increments CLADDR after each TEXCLDATA write per
963 * HUM Ch 62.5.4 "CLUT setup", p 3717. NASA Rule 2: bounded loop. */
964 for (uint32_t i = 0UL; i < count; ++i) {
966 }
967 return k_ra8_ok;
968}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
Definition ra8_check.h:184
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
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
static uint32_t s_drw_color1
Software shadow of the write-only COLOR1 register.
Definition ra8_drw.c:182
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
bool priv_ra8_drw_internal_rect_off_surface(const ra8_drw_rect_t *rect)
Reject a rectangle that would rasterize outside the framebuffer.
Definition ra8_drw.c:225
static uint32_t internal_control2_rmw(uint32_t clear_mask, uint32_t set_mask)
Read-modify-write a CONTROL2 mask; preserve unrelated bits.
Definition ra8_drw.c:405
static uint32_t s_drw_bytes_px
Cached framebuffer bytes per pixel for the configured WRITEFORMAT.
Definition ra8_drw.c:209
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_cache_flush(bool flush_fb, bool flush_texture)
Pulse FB and/or texture cache flush bits in CACHECTL.
Definition ra8_drw.c:688
static ra8_drw_event_fn_t s_drw_fn
Currently registered DRW event callback (or nullptr).
Definition ra8_drw.c:128
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
static uint32_t s_drw_origin
Cached ORIGIN (framebuffer base) for the per-primitive render trigger.
Definition ra8_drw.c:150
bool priv_ra8_drw_internal_rect_above_max(uint16_t max_w, uint16_t max_h, uint16_t width, uint16_t height)
Pure rect-above-max predicate – see header for full contract.
Definition ra8_drw.c:97
uint32_t priv_ra8_drw_internal_origin(void)
Implementation of priv_ra8_drw_internal_origin() – shadow read.
Definition ra8_drw.c:212
void priv_program_rect_bbox(const ra8_drw_rect_t *rect)
Programme the bounding box that describes an axis-aligned rect.
Definition ra8_drw.c:416
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
static uint32_t internal_pack_blend_bits(const ra8_drw_blend_t *blend)
Pack ra8_drw_blend_t into a CONTROL2 set-bit slab.
Definition ra8_drw.c:769
static uint32_t internal_pack_readformat(ra8_drw_readformat_t fmt)
Pack a 4-bit READFORMAT value into CONTROL2.READFORMAT_H+L.
Definition ra8_drw.c:298
static void * s_drw_ctx
Opaque context paired with s_drw_fn.
Definition ra8_drw.c:134
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
static void internal_drw_program_cache_options(const ra8_drw_config_t *cfg)
Program the optional CACHECTL and DBWER features from the config.
Definition ra8_drw.c:469
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
uint32_t priv_ra8_drw_internal_rect_origin(const ra8_drw_rect_t *rect)
Framebuffer byte address of a rectangle's top-left pixel.
Definition ra8_drw.c:217
bool priv_ra8_drw_internal_rect_below_min(uint16_t min_dim, uint16_t width, uint16_t height)
Pure rect-below-min predicate – see header for full contract.
Definition ra8_drw.c:75
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
void priv_ra8_drw_internal_color1_write(uint32_t argb8888)
Implementation of priv_ra8_drw_internal_color1_write() – MMIO + shadow.
Definition ra8_drw.c:238
static uint32_t internal_pack_surface_defaults(ra8_drw_writeformat_t fmt)
Build the CONTROL2 value a plain solid-fill surface needs at init.
Definition ra8_drw.c:379
static uint32_t s_drw_pitch_px
Cached framebuffer pitch in pixels.
Definition ra8_drw.c:199
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
static uint32_t s_drw_control2
Software shadow of the write-only CONTROL2 register.
Definition ra8_drw.c:166
static uint32_t internal_pack_writeformat(ra8_drw_writeformat_t fmt)
Fold the three-bit WRITEFORMAT field into a 32-bit CONTROL2 value (WRITEFORMAT2 lives at bit 8,...
Definition ra8_drw.c:270
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
static uint32_t internal_pack_texture_bits(const ra8_drw_texture_t *tex)
Pack ra8_drw_texture_t into a CONTROL2 set-bit slab.
Definition ra8_drw.c:868
ra8_err_t ra8_drw_set_pattern_enable(bool enable, bool source_from_l5)
Toggle CONTROL2.PATTERNENABLE / PATTERNSOURCEL5.
Definition ra8_drw.c:732
static uint32_t internal_bytes_per_px(ra8_drw_writeformat_t fmt)
Map a WRITEFORMAT code to its framebuffer pixel stride in bytes.
Definition ra8_drw.c:329
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) HAL driver – public API
void(* ra8_drw_event_fn_t)(void *ctx, uint32_t status_mask)
DRW asynchronous event callback signature.
Definition ra8_drw.h:257
Test-access surface for ra8_drw internal helpers (MC/DC).
@ k_ra8_drw_internal_byte_mask
8-bit channel mask.
@ k_ra8_drw_internal_clut_max
CLUT entries (HUM 62.5.4).
@ k_ra8_drw_internal_color_alpha_mask
0x00RRGGBB low bits.
2D Drawing Engine (DRW / D/AVE 2D) register layout for the RA8D2
@ k_ra8_drw_off_color1
W: Base color RGBA.
@ k_ra8_drw_off_origin
W: Framebuffer base address.
@ k_ra8_drw_off_l1start
W: Limiter 1 start.
@ k_ra8_drw_off_texpitch
W: Texels per texture line.
@ k_ra8_drw_off_color2
W: Secondary color RGBA.
@ k_ra8_drw_off_l3xadd
W: Limiter 3 X-axis increment.
@ k_ra8_drw_off_l1yadd
W: Limiter 1 Y-axis increment.
@ k_ra8_drw_off_dbwer
RW: DRW bufferable write en.
@ k_ra8_drw_off_l4yadd
W: Limiter 4 Y-axis increment.
@ k_ra8_drw_off_pattern
W: Pattern bitmap.
@ k_ra8_drw_off_irqctl
W: Interrupt control.
@ k_ra8_drw_off_hwrevision
R: HW revision (alias).
@ k_ra8_drw_off_status
R: Engine status (alias).
@ k_ra8_drw_off_texcldata
W: CLUT entry data.
@ k_ra8_drw_off_l4start
W: Limiter 4 start.
@ k_ra8_drw_off_texcloffset
W: CLUT index offset.
@ k_ra8_drw_off_cachectl
W: Cache enable / flush.
@ k_ra8_drw_off_perfcount2
RW: Performance counter 2.
@ k_ra8_drw_off_l3start
W: Limiter 3 start.
@ k_ra8_drw_off_texorigin
W: Texture base address.
@ k_ra8_drw_off_size
W: Bounding box (W,H).
@ k_ra8_drw_off_texcladdr
W: CLUT start address.
@ k_ra8_drw_off_l2xadd
W: Limiter 2 X-axis increment.
@ k_ra8_drw_off_l2yadd
W: Limiter 2 Y-axis increment.
@ k_ra8_drw_off_texmask
W: Texture U/V mask.
@ k_ra8_drw_off_perfcount1
RW: Performance counter 1.
@ k_ra8_drw_off_l1xadd
W: Limiter 1 X-axis increment.
@ k_ra8_drw_off_pitch
W: FB pitch + spanstore delay.
@ k_ra8_drw_off_colkey
W: Color key value.
@ k_ra8_drw_off_l2start
W: Limiter 2 start.
@ k_ra8_drw_off_l4xadd
W: Limiter 4 X-axis increment.
@ k_ra8_drw_off_control2
W: Surface control.
@ k_ra8_drw_off_l3yadd
W: Limiter 3 Y-axis increment.
@ k_ra8_drw_size_height_pos
SIZEY in upper half-word.
@ k_ra8_drw_color_a_pos
COLORnA[7:0].
@ k_ra8_drw_writealpha_pixel_cov
Use source coverage.
ra8_drw_writeformat_t
Framebuffer pixel format codes (3-bit field).
@ k_ra8_drw_writefmt_argb8888
32 bpp ARGB8888.
@ k_ra8_drw_writefmt_a8
8 bpp A(8).
static volatile uint32_t * ra8_drw_reg32(ra8_drw_off_t off)
Pointer to a 32-bit register inside the DRW block.
ra8_drw_readformat_t
Texture pixel format codes (4-bit field).
@ k_ra8_drw_control2_bsf
Blend src factor.
@ k_ra8_drw_control2_textureenable
Texture source.
@ k_ra8_drw_control2_textureclampx
Texture clamp X.
@ k_ra8_drw_control2_clutenable
CLUT enable.
@ k_ra8_drw_control2_patternenable
Pattern source.
@ k_ra8_drw_control2_rleenable
RLE source.
@ k_ra8_drw_control2_readformatl_mask
READFORMAT_L mask.
@ k_ra8_drw_control2_bsi
Blend src inverted.
@ k_ra8_drw_control2_colkeyenable
Color key enable.
@ k_ra8_drw_control2_texturefilterx
Bilinear X.
@ k_ra8_drw_control2_writeformat_pos
WRITEFORMAT[1:0] @20.
@ k_ra8_drw_control2_writealpha_pos
WRITEALPHA[1:0] @22.
@ k_ra8_drw_control2_bdi
Blend dst inverted.
@ k_ra8_drw_control2_texturefiltery
Bilinear Y.
@ k_ra8_drw_control2_bdf
Blend dst factor.
@ k_ra8_drw_control2_textureclampy
Texture clamp Y.
@ k_ra8_drw_control2_bdfa
Blend dst fac alpha.
@ k_ra8_drw_control2_useacb
Alpha channel blend.
@ k_ra8_drw_control2_bc2
Use COLOR2 as DST.
@ k_ra8_drw_control2_readformath_pos
READFORMAT_H[3:2] @4.
@ k_ra8_drw_control2_writeformat2_bit
WRITEFORMAT[2].
@ k_ra8_drw_control2_readformatl_pos
READFORMAT_L[1:0] @18.
@ k_ra8_drw_control2_readformath_mask
READFORMAT_H mask.
@ k_ra8_drw_control2_bsfa
Blend src fac alpha.
@ k_ra8_drw_control2_patternsourcel5
Use L5 as pat index.
@ k_ra8_drw_control2_clutformat_565
CLUT in RGB565 mode.
@ k_ra8_drw_control2_bdia
Blend dst alpha inv.
@ k_ra8_drw_control2_bsia
Blend src alpha inv.
@ k_ra8_drw_control2_rlepixel_pos
RLEPIXELWIDTH @30.
@ k_ra8_drw_control2_rlepixel_mask
RLEPIXELWIDTH mask.
@ k_ra8_drw_dbwer_bwe
Enable bufferable writes.
@ k_ra8_drw_max_texpitch_tx
HUM 62.2.15 TEXPITCH max.
@ k_ra8_drw_cachectl_all_flush
RA8 DRW cachectl all flush.
@ k_ra8_drw_cachectl_all_en
RA8 DRW cachectl all en.
@ k_ra8_drw_cachectl_cflushtx
Texture cache flush.
@ k_ra8_drw_cachectl_cflushfx
FB cache flush.
@ k_ra8_drw_bytes_px_8bpp
A8.
@ k_ra8_drw_bytes_px_32bpp
ARGB8888.
@ k_ra8_drw_bytes_px_16bpp
RGB565 / ARGB4444.
@ k_ra8_drw_status_busy_mask
RA8 DRW status busy mask.
@ k_ra8_drw_irqctl_all_clr
RA8 DRW irqctl all clr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
Definition ra8_err.h:304
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_warn(tag, message)
RA8 log warn.
Definition ra8_log.h:347
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Definition ra8_log.h:366
#define ra8_log_error(tag, message)
RA8 log error.
Definition ra8_log.h:335
Low Power Mode (LPM) HAL driver – public API.
@ k_ra8_lpm_pd_timeout_default
Default power-gate poll bound.
Definition ra8_lpm.h:145
ra8_err_t ra8_lpm_graphics_power_on(uint32_t timeout_iters)
Power the graphics domain on (DRW / GLCDC / MIPI DSI+CSI / VIN).
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
Definition ra8_mstp.c:343
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
Definition ra8_mstp.c:382
@ k_ra8_mstp_drw
MSTPC6 2D Drawing.
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
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
Rectangle parameters for ra8_drw_fill_rect.
Definition ra8_drw.h:96
uint16_t height_px
Height in pixels.
Definition ra8_drw.h:100
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