ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
37
38#include <stdint.h>
39
40#include "ra8_board_ek_ra8d2.h"
41#include "ra8_boot_entry.h"
42#include "ra8_cgc.h"
43#include "ra8_display_pal.h"
44#include "ra8_display_pal_lcd.h"
45#include "ra8_err.h"
46#include "ra8_isr.h"
47#include "ra8_mstp.h"
48#include "ra8_panel.h"
49#include "ra8_panel_timing.h"
50#include "ra8_time.h"
51
52/* ===========================================================================
53 * Compile-time configuration -- typed enums per the no-magic-number rule.
54 * =========================================================================== */
55
63typedef enum : uint16_t {
64 k_app_fb_w = 512U,
65 k_app_fb_h = 512U,
67
71typedef enum : uint8_t {
74
82typedef enum : uint16_t {
83 k_app_color_red = 0xF800U,
86 k_app_color_cyan = 0x07FFU,
87 k_app_color_blue = 0x001FU,
90
97typedef enum : uint16_t {
100} app_pace_t;
101
102/* ===========================================================================
103 * Static storage
104 * =========================================================================== */
105
115[[gnu::aligned(k_ra8_board_fb_align_bytes)]] static uint16_t
116 s_framebuffer[(uint32_t)k_app_fb_w * (uint32_t)k_app_fb_h];
117
131 .framebuffer = s_framebuffer,
132 .framebuffer_bytes = sizeof(s_framebuffer),
133 .width_px = (uint16_t)k_app_fb_w,
134 .height_px = (uint16_t)k_app_fb_h,
135 .pixfmt = k_display_pixfmt_rgb565,
136 .panel_timing = &s_ra8_panel_ek_ra8d2_timing,
137};
138
140static display_handle_t* s_display = nullptr;
141
144
147
149static uint32_t s_scroll_offset = 0U;
150
151/* ===========================================================================
152 * Panic helper -- single-purpose, matches the rest of the lcd_* demos.
153 * =========================================================================== */
154
155static const uint16_t s_palette[k_app_bar_count] = {
156 (uint16_t)k_app_color_red,
157 (uint16_t)k_app_color_yellow,
158 (uint16_t)k_app_color_green,
159 (uint16_t)k_app_color_cyan,
160 (uint16_t)k_app_color_blue,
161 (uint16_t)k_app_color_magenta,
162};
163
178static void app_panic_halt(void)
179{
181 while (1) {
182 __asm__ volatile("wfi");
183 }
184}
185
199static void app_bringup_clocks(void)
200{
201 uint32_t cpuclk0_hz = 0U;
202 if (ra8_cgc_init() != k_ra8_ok) {
204 }
207 }
208 if (ra8_mstp_init() != k_ra8_ok) {
210 }
211 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
213 }
216 }
219 }
221}
222
239static void app_bringup_display(void)
240{
243 }
246 }
249 }
250}
251
271static void app_paint_bars(uint32_t scroll_offset)
272{
273 uint16_t* pixels = (uint16_t*)s_fb.pixels;
274 const uint16_t bar_height = (uint16_t)(s_fb.height_px / (uint16_t)k_app_bar_count);
275 for (uint16_t y = 0U; y < s_fb.height_px; ++y) {
276 const uint32_t row = ((uint32_t)y + scroll_offset) / (uint32_t)bar_height;
277 const uint16_t colour = s_palette[row % (uint32_t)k_app_bar_count];
278 const uint32_t row_off = (uint32_t)y * (uint32_t)s_fb.width_px;
279 for (uint16_t x = 0U; x < s_fb.width_px; ++x) {
280 pixels[row_off + (uint32_t)x] = colour;
281 }
282 }
283}
284
285void main(void)
286{
290
291 /* Pick the refresh hint that matches the bound backend. Continuous-
292 * refresh panels (LCD) prefer "fast" because every flush is just a
293 * memory barrier; e-ink picks GC16-like quality only on full
294 * repaints to avoid ghosting. */
295 const display_refresh_hint_t hint =
297
298 /* Clear once with black so the first scroll-in is clean. */
299 (void)display_clear(s_display, 0x0000U);
301
302 while (1) {
306 s_scroll_offset = (s_scroll_offset + 1U) % (uint32_t)s_fb.height_px;
308 }
309}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static display_handle_t * s_display
Definition main.c:78
static uint16_t s_framebuffer[(size_t) k_panel_height_px *(size_t) k_panel_width_px]
1024x600 RGB565 framebuffer in external SDRAM (GLCDC scans this).
Definition main.c:67
static display_caps_t s_caps
Cached backend caps + framebuffer descriptor.
Definition main.c:202
static display_fb_t s_fb
Definition main.c:203
static void app_bringup_clocks(void)
Bring up clocks, MSTP, SysTick, the SCI8 console and both LEDs.
Definition main.c:414
static void app_panic_halt(void)
Halt forever with the red board LED on (visual sign of fatal init).
Definition main.c:405
app_pace_t
Frame pacing in milliseconds.
Definition main.c:97
@ k_app_frame_period_ms
App frame period ms.
Definition main.c:98
@ k_app_powerup_ms
PLL / panel power-on settle.
Definition main.c:99
app_fb_dim_t
Framebuffer dimensions for this demo.
Definition main.c:63
@ k_app_fb_h
Framebuffer height (pixels).
Definition main.c:65
@ k_app_fb_w
Framebuffer width (pixels).
Definition main.c:64
app_color_t
RGB565 palette for the bar colours.
Definition main.c:82
@ k_app_color_red
App color red.
Definition main.c:83
@ k_app_color_cyan
App color cyan.
Definition main.c:86
@ k_app_color_yellow
App color yellow.
Definition main.c:84
@ k_app_color_blue
App color blue.
Definition main.c:87
@ k_app_color_green
App color green.
Definition main.c:85
@ k_app_color_magenta
App color magenta.
Definition main.c:88
static void app_paint_bars(uint32_t scroll_offset)
Paint one frame's worth of scrolling colour bars.
Definition main.c:271
static uint32_t s_scroll_offset
Scroll offset advanced every frame.
Definition main.c:149
static const display_cfg_t k_app_display_cfg
Display PAL config – the one-line backend swap lives here.
Definition main.c:129
static void app_bringup_display(void)
Bring up the display through the PAL and cache caps + FB.
Definition main.c:239
static const uint16_t s_palette[k_app_bar_count]
Definition main.c:155
app_bar_count_t
Number of horizontal colour bars rendered per frame.
Definition main.c:71
@ k_app_bar_count
App bar count.
Definition main.c:72
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
ra8_err_t ra8_board_led_on(ra8_board_led_id_t led)
Drive led HIGH (light it).
@ k_ra8_board_led_blue
Convenience aliases by colour.
@ k_ra8_board_led_red
RA8 board led red.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Display Platform Abstraction Layer for the RA8D2.
@ k_display_pixfmt_rgb565
16 bpp, 5/6/5 packed.
ra8_err_t display_get_caps(const display_handle_t *d, display_caps_t *out)
Query the bound backend's runtime capabilities.
display_rect_t display_full_rect(const display_handle_t *d)
Convenience helper returning the rect covering the whole framebuffer.
ra8_err_t display_get_framebuffer(const display_handle_t *d, display_fb_t *out)
Return the framebuffer descriptor the backend is targeting.
ra8_err_t display_clear(const display_handle_t *d, uint32_t color)
Clear the entire framebuffer to color.
ra8_err_t display_flush(const display_handle_t *d, display_rect_t rect, display_refresh_hint_t hint)
Commit pending framebuffer changes to the panel.
struct display_handle display_handle_t
ra8_err_t display_init(const display_cfg_t *cfg, display_handle_t **out_handle)
Initialise the display PAL and bring the selected backend up to a state where display_flush succeeds.
display_refresh_hint_t
Intent passed into display_flush; backends map this onto whatever waveform/mode their controller offe...
@ k_display_refresh_fast
Prioritise latency.
@ k_display_refresh_init
Full reset of the panel.
@ k_display_refresh_quality
Prioritise final quality.
LCD backend (ra8_glcdc) for the display PAL.
const display_backend_iface_t k_display_backend_lcd_ra8_glcdc
LCD backend vtable – pass its address through display_cfg_t.iface to drive the EK-RA8D2 panel.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Definition ra8_mstp.c:291
Active display-panel descriptor for the EK-RA8D2 (ER-TFT070-6).
@ k_ra8_board_fb_align_bytes
GLCDC AXI burst alignment, in bytes.
Definition ra8_panel.h:108
EK-RA8D2 panel timing as the HAL's ra8_glcdc_timing_t (ER-TFT070-6).
static const ra8_glcdc_timing_t s_ra8_panel_ek_ra8d2_timing
EK-RA8D2 ER-TFT070-6 RGB timing for ra8_glcdc_init / the LCD backend.
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129
Capabilities a backend reports after display_init.
Configuration descriptor passed into display_init.
Framebuffer descriptor returned by display_get_framebuffer.