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
29
30#include <stdint.h>
31
32#include "ra8_board_ek_ra8d2.h"
33#include "ra8_boot_entry.h"
34#include "ra8_cgc.h"
35#include "ra8_display_pal.h"
36#include "ra8_display_pal_lcd.h"
37#include "ra8_err.h"
38#include "ra8_isr.h"
39#include "ra8_mstp.h"
40#include "ra8_panel.h"
41#include "ra8_panel_timing.h"
42#include "ra8_time.h"
43
44typedef enum : uint16_t {
45 k_fb_w = 512U,
46 k_fb_h = 512U,
48
49typedef enum : uint16_t {
50 k_color_bg = 0x001FU,
51 k_color_x = 0xFFE0U,
53
54typedef enum : uint8_t {
57
58typedef enum : uint32_t {
62
63/* Static framebuffer in SRAM, 64-byte AXI-burst aligned so the GLCDC
64 * fetches are clean. The display PAL takes a pointer to this and
65 * forwards it to the GLCDC HAL via ``display_init``. */
66[[gnu::aligned(
67 k_ra8_board_fb_align_bytes)]] static uint16_t s_framebuffer[(uint32_t)k_fb_w * (uint32_t)k_fb_h];
68
81 .framebuffer = s_framebuffer,
82 .framebuffer_bytes = sizeof(s_framebuffer),
83 .width_px = (uint16_t)k_fb_w,
84 .height_px = (uint16_t)k_fb_h,
86 .panel_timing = &s_ra8_panel_ek_ra8d2_timing,
87};
88
89static void lcd_panic_halt(void)
90{
92 while (1) {
93 __asm__ volatile("wfi");
94 }
95}
96
97static void lcd_fb_fill(uint16_t color)
98{
99 for (uint32_t i = 0U; i < (uint32_t)k_fb_w * (uint32_t)k_fb_h; i++) {
100 s_framebuffer[i] = color;
101 }
102 __asm__ volatile("dsb" ::: "memory");
103}
104
105static void lcd_draw_x(uint16_t color)
106{
107 for (uint16_t x = 0U; x < (uint16_t)k_fb_w; x++) {
108 const int32_t y_down = ((int32_t)x * (int32_t)k_fb_h) / (int32_t)k_fb_w;
109 const int32_t y_up = ((int32_t)k_fb_h - 1) - y_down;
110 for (int32_t dy = -(int32_t)k_lcd_x_thickness; dy <= (int32_t)k_lcd_x_thickness; dy++) {
111 const int32_t yy_down = y_down + dy;
112 const int32_t yy_up = y_up + dy;
113 if ((yy_down >= 0) && (yy_down < (int32_t)k_fb_h)) {
114 s_framebuffer[((uint32_t)yy_down * (uint32_t)k_fb_w) + (uint32_t)x] = color;
115 }
116 if ((yy_up >= 0) && (yy_up < (int32_t)k_fb_h)) {
117 s_framebuffer[((uint32_t)yy_up * (uint32_t)k_fb_w) + (uint32_t)x] = color;
118 }
119 }
120 }
121 __asm__ volatile("dsb" ::: "memory");
122}
123
140static void lcd_bringup_clocks(void)
141{
142 uint32_t cpuclk0_hz = 0U;
143 if (ra8_cgc_init() != k_ra8_ok) {
145 }
148 }
149 if (ra8_mstp_init() != k_ra8_ok) {
151 }
152 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
154 }
157 }
160 }
162}
163
184{
185 display_handle_t* d = nullptr;
188 }
189 return d;
190}
191
void main(void)
Secure fallback main entry point.
Definition main.c:37
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
lcd_pace_t
Definition main.c:66
static void lcd_fb_fill(uint16_t color)
Definition main.c:97
static void lcd_panic_halt(void)
Definition main.c:89
static void lcd_bringup_clocks(void)
Bring up clocks, MSTP, system tick and the on-board LEDs.
Definition main.c:140
static void lcd_draw_x(uint16_t color)
Definition main.c:105
lcd_fb_dim_t
Definition main.c:44
@ k_fb_w
Fb w.
Definition main.c:45
@ k_fb_h
Fb h.
Definition main.c:46
static display_handle_t * lcd_bringup_panel(void)
Bring up the panel through the display PAL.
Definition main.c:183
lcd_x_param_t
Definition main.c:54
@ k_lcd_x_thickness
LCD x thickness.
Definition main.c:55
lcd_color_t
Definition main.c:49
@ k_color_x
RGB565 yellow.
Definition main.c:51
@ k_color_bg
RGB565 dark blue.
Definition main.c:50
static const display_cfg_t k_lcd_draw_x_display_cfg
Display PAL config selecting the LCD backend.
Definition main.c:79
@ k_lcd_powerup_delay_ms
LCD powerup delay ms.
Definition main.c:59
@ k_lcd_heartbeat_ms
LCD heartbeat ms.
Definition main.c:60
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.
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.
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
Configuration descriptor passed into display_init.