ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_overlay.h File Reference

Composite board-view renderer: panel framebuffer + a status sidebar. More...

#include <stdint.h>
#include "ra8_attributes.h"
Include dependency graph for board_overlay.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  board_led_status_t
 One board LED's live state for the status sidebar. More...
struct  board_status_t
 Live peripheral snapshot the status sidebar renders each frame. More...
struct  board_overlay_surface_t
 Non-owning drawing surface used by memory and raw-fd compositors. More...

Typedefs

typedef bool(* board_overlay_fill_fn) (void *context, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
 Rectangle-fill operation supplied by a bounded presentation surface.

Enumerations

enum  board_overlay_dims_t : uint32_t { k_overlay_led_count = 3U }
 Number of board LED indicators shown in the status sidebar. More...
enum  board_overlay_console_t : uint32_t {
  k_overlay_console_rows = 18U ,
  k_overlay_line_cap = 128U ,
  k_overlay_console_tabs_max = 16U
}
 Console-panel sizing for the board view. More...
enum  board_overlay_geometry_t : uint16_t {
  k_board_overlay_sidebar_width_px = 520U ,
  k_board_overlay_min_height_px = 600U
}
 Fixed composite sidebar geometry shared with checked planners. More...
enum  board_overlay_btn_t : uint32_t {
  k_board_overlay_btn_none = 0U ,
  k_board_overlay_btn_sw1 = 1U ,
  k_board_overlay_btn_sw2 = 2U ,
  k_board_overlay_btn_console = 3U ,
  k_board_overlay_btn_battery = 4U ,
  k_board_overlay_btn_batt_chg = 5U ,
  k_board_overlay_btn_lowpower = 6U
}
 On-screen sidebar control a click landed on. More...

Functions

bool board_overlay_draw_sidebar (board_overlay_surface_t *surface, uint16_t panel_w, const board_status_t *st)
 Draw the status sidebar through a bounded rectangle sink.
uint16_t board_overlay_sidebar_width (void)
 Width in pixels the status sidebar adds to the right of the panel.
uint16_t board_overlay_total_width (uint16_t panel_w)
 Total composite width for a panel of width panel_w.
uint16_t board_overlay_total_height (uint16_t panel_h)
 Total composite height for a panel of height panel_h.
void board_overlay_compose (uint16_t *out, const uint16_t *panel, uint16_t panel_w, uint16_t panel_h, const board_status_t *st)
 Render the full composite (panel region + status sidebar) into out.
board_overlay_btn_t board_overlay_hit_button (uint16_t x, uint16_t y, uint16_t panel_w)
 Classify a composite-space click against the sidebar's on-screen buttons.
bool board_overlay_battery_pct_at (uint16_t x, uint16_t panel_w, uint8_t *out_pct)
 Map a click column on the battery slider track to a 0..100 SOC percent.
bool board_overlay_hit_console_tab (uint16_t x, uint16_t y, uint16_t panel_w, uint32_t tab_count, uint32_t *out_idx)
 Map a composite-space click on the console tab bar to a tab index.

Detailed Description

Composite board-view renderer: panel framebuffer + a status sidebar.

Builds the graphical BOARD VIEW the emulator presents: the emulated GLCDC panel framebuffer on the left, plus a Cocoa-blitted status sidebar on the right that makes a NON-display example observable – three LED indicators that light in the real GPIO LED colour, and text lines for the live USB / UART / timer-IRQ / touch state. The whole composite is rendered into one RGB565 buffer in portable C (a tiny embedded 5x7 ASCII font draws the text and filled rectangles draw the LED dots), so the exact same pixels the macOS window shows are what --ppm writes out – the status overlay is therefore verifiable headlessly with a region/pixel check, not just visible on screen.

This module owns no Unicorn engine and no AppKit dependency: main.c reads the peripheral state out of board_periph / board_usb, fills a board_status_t, and calls board_overlay_compose; board_view.m only blits the result. Plain C so it builds and tests on any host.

Since
0.1.0

Definition in file board_overlay.h.

Typedef Documentation

◆ board_overlay_fill_fn

typedef bool(* board_overlay_fill_fn) (void *context, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)

Rectangle-fill operation supplied by a bounded presentation surface.

Definition at line 140 of file board_overlay.h.

Enumeration Type Documentation

◆ board_overlay_btn_t

enum board_overlay_btn_t : uint32_t

On-screen sidebar control a click landed on.

board_overlay_hit_button classifies a composite-space click into one of the sidebar's interactive controls (or none), so the caller can route a window / --click tap to the user-switch model instead of the touch panel.

Enumerator
k_board_overlay_btn_none 

Click did not land on a control.

k_board_overlay_btn_sw1 

On-screen SW1 (P009) push-button.

k_board_overlay_btn_sw2 

On-screen SW2 (P008) push-button.

k_board_overlay_btn_console 

Console panel: toggle autoscroll.

k_board_overlay_btn_battery 

Battery slider track: set SOC.

k_board_overlay_btn_batt_chg 

Battery CHG button: toggle charge.

k_board_overlay_btn_lowpower 

CORE low-power toggle button.

Definition at line 61 of file board_overlay.h.

◆ board_overlay_console_t

enum board_overlay_console_t : uint32_t

Console-panel sizing for the board view.

Enumerator
k_overlay_console_rows 

Console lines shown (newest at bottom).

k_overlay_line_cap 

Max chars copied per console line.

k_overlay_console_tabs_max 

Tab-bar capacity (channels = tabs).

Definition at line 42 of file board_overlay.h.

◆ board_overlay_dims_t

enum board_overlay_dims_t : uint32_t

Number of board LED indicators shown in the status sidebar.

Enumerator
k_overlay_led_count 

LED1 / LED2 / LED3 (mirrors the BSP).

Definition at line 37 of file board_overlay.h.

◆ board_overlay_geometry_t

enum board_overlay_geometry_t : uint16_t

Fixed composite sidebar geometry shared with checked planners.

Enumerator
k_board_overlay_sidebar_width_px 

Pixels added right of panel.

k_board_overlay_min_height_px 

Minimum composite height.

Definition at line 49 of file board_overlay.h.

Function Documentation

◆ board_overlay_battery_pct_at()

bool board_overlay_battery_pct_at ( uint16_t x,
uint16_t panel_w,
uint8_t * out_pct )

Map a click column on the battery slider track to a 0..100 SOC percent.

The POWER section draws a horizontal slider whose fill mirrors the battery SOC. board_overlay_hit_button reports k_board_overlay_btn_battery when a click lands on that track's row; this then converts the click column to the percent the user dragged to, so the caller can drive the fuel-gauge model. The percent is the click's fraction across the track, clamped to 0..100 (a click left of the track yields 0, right of it yields 100), and the same fixed geometry that board_overlay_compose draws the track with is used here so the drawn fill and the drag position stay in lock-step.

Parameters
[in]xClick column in composite pixels (top-left origin).
[in]panel_wPanel width the composite was built with (sidebar origin).
[out]out_pctReceives the mapped state-of-charge percent (0..100).
Returns
True when out_pct was written, false if out_pct is NULL.
Since
0.1.0
Return values
trueThe board overlay battery pct at condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for board overlay battery pct at.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board overlay model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 844 of file board_overlay.c.

References k_pwr_soc_full, k_pwr_track_w, and k_pwr_x_dx.

Referenced by apply_battery_click().

◆ board_overlay_compose()

void board_overlay_compose ( uint16_t * out,
const uint16_t * panel,
uint16_t panel_w,
uint16_t panel_h,
const board_status_t * st )

Render the full composite (panel region + status sidebar) into out.

Clears out to the sidebar background, blits the panel pixels into the top-left region, draws a divider, then paints the three LED indicators and the USB / UART / IRQ / touch text lines from st. The output is exactly what board_view blits and what --ppm writes, so a headless pixel check over a sidebar region verifies the overlay.

Parameters
[out]outComposite RGB565 buffer, board_overlay_total_width by board_overlay_total_height pixels (row-major, no gap).
[in]panelPanel framebuffer (RGB565), or NULL for a blank panel.
[in]panel_wPanel width in pixels.
[in]panel_hPanel height in pixels.
[in]stLive peripheral snapshot to render (NULL draws no status).
Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board overlay compose.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board overlay model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 779 of file board_overlay.c.

References board_overlay_draw_sidebar(), board_overlay_total_height(), board_overlay_total_width(), internal_memory_fill(), and priv_blit_panel().

◆ board_overlay_draw_sidebar()

bool board_overlay_draw_sidebar ( board_overlay_surface_t * surface,
uint16_t panel_w,
const board_status_t * st )

Draw the status sidebar through a bounded rectangle sink.

Parameters
[in,out]surfaceComplete composite surface and sticky write state.
[in]panel_wDisplayed panel width and sidebar origin.
[in]stLive peripheral status, or nullptr for a blank sidebar.
Returns
Whether every clipped rectangle reached the sink.
Return values
trueThe exact sidebar was rendered.
falseSurface validation or a sink operation failed.
Precondition
surface and its fill operation are non-null.
Surface dimensions match overlay totals for panel_w.
Postcondition
A failure remains sticky in surface->ok.
Note
Distinct surface/context pairs are independent and thread-safe.
Since
0.1.0

Draw the status sidebar through a bounded rectangle sink; this step is contained within the board overlay model and uses bounded caller or module-owned storage.

Postcondition
Ownership of caller-supplied storage is unchanged.

Draw the status sidebar through a bounded rectangle sink.

Definition at line 723 of file board_overlay.c.

References board_status_t::app_name, board_overlay_total_height(), board_overlay_total_width(), board_overlay_surface_t::fill, board_overlay_surface_t::height, internal_draw_buttons(), internal_draw_console(), internal_draw_core(), internal_draw_io_block(), internal_draw_leds(), internal_draw_power(), internal_draw_run_stats(), k_io_head_y, k_ovl_accent, k_ovl_bg, k_ovl_bg_alt, k_ovl_divider, k_ovl_heading, k_ovl_sidebar_w, k_pad_x, k_section_gap, k_sidebar_top, k_title_bar_h, k_title_gap, board_overlay_surface_t::ok, priv_draw_text(), priv_fill_rect(), and board_overlay_surface_t::width.

Referenced by board_overlay_compose(), and priv_emu_view_surface_build().

◆ board_overlay_hit_button()

board_overlay_btn_t board_overlay_hit_button ( uint16_t x,
uint16_t y,
uint16_t panel_w )

Classify a composite-space click against the sidebar's on-screen buttons.

The interactive board view draws SW1 / SW2 push-buttons in the status sidebar at a fixed layout (the same constants board_overlay_compose draws them with). Given a click in composite pixels and the panel_w used to compose the frame, this reports which button the click hit so the caller can drive the user-switch model rather than injecting a panel touch. Out-of-band clicks (the panel, sidebar text) return k_board_overlay_btn_none.

Parameters
[in]xClick column in composite pixels (top-left origin).
[in]yClick row in composite pixels (top-left origin).
[in]panel_wPanel width the composite was built with (sidebar origin).
Returns
The button hit, or k_board_overlay_btn_none.
Since
0.1.0
Return values
valueThe operation-specific board overlay hit button value.
Precondition
Arguments satisfy the ranges documented for board overlay hit button.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board overlay model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 800 of file board_overlay.c.

References k_board_overlay_btn_batt_chg, k_board_overlay_btn_battery, k_board_overlay_btn_console, k_board_overlay_btn_lowpower, k_board_overlay_btn_none, k_board_overlay_btn_sw1, k_board_overlay_btn_sw2, k_btn_gap, k_btn_h, k_btn_w, k_btn_x_dx, k_btn_y, k_con_head_y, k_core_lp_off, k_core_lp_w, k_ovl_sidebar_w, k_pwr_chg_off, k_pwr_chg_w, k_pwr_h, k_pwr_track_w, k_pwr_x_dx, and k_pwr_y.

Referenced by internal_run_classify_click(), and route_click().

◆ board_overlay_hit_console_tab()

bool board_overlay_hit_console_tab ( uint16_t x,
uint16_t y,
uint16_t panel_w,
uint32_t tab_count,
uint32_t * out_idx )

Map a composite-space click on the console tab bar to a tab index.

The tabbed console wraps tab_count equal-width tabs into as many rows as the console panel width needs (the same grid geometry the compose path draws them with). Given a click in composite pixels, the panel_w used to compose the frame, and the live tab_count, this reports which tab the click landed on so the caller can switch the active console channel. Clicks outside the tab grid (including the console body below it) return false and leave out_idx untouched, so the caller can fall through to the body's autoscroll toggle.

Parameters
[in]xClick column in composite pixels (top-left origin).
[in]yClick row in composite pixels (top-left origin).
[in]panel_wPanel width the composite was built with (sidebar origin).
[in]tab_countNumber of tabs drawn (1 .. k_overlay_console_tabs_max).
[out]out_idxReceives the hit tab index (0 .. tab_count - 1).
Returns
True when a tab was hit and out_idx written; false otherwise.
Since
0.1.0
Return values
trueThe board overlay hit console tab condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for board overlay hit console tab.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board overlay model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 861 of file board_overlay.c.

References internal_console_tab_rect(), k_overlay_console_tabs_max, k_ovl_sidebar_w, and k_pad_x.

Referenced by internal_run_classify_click(), and route_click().

◆ board_overlay_sidebar_width()

uint16_t board_overlay_sidebar_width ( void )

Width in pixels the status sidebar adds to the right of the panel.

Returns
Fixed sidebar width (the composite width is panel width + this).
Since
0.1.0

Width in pixels the status sidebar adds to the right of the panel; this step is contained within the board overlay model and uses bounded caller or module-owned storage.

Return values
valueThe operation-specific board overlay sidebar width value.
Precondition
Arguments satisfy the ranges documented for board overlay sidebar width.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board overlay model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 119 of file board_overlay_draw.c.

References k_ovl_sidebar_w.

◆ board_overlay_total_height()

uint16_t board_overlay_total_height ( uint16_t panel_h)

Total composite height for a panel of height panel_h.

At least a minimum so the sidebar's text always fits even when the panel is short (a non-display example may have a tiny / blank panel region).

Parameters
[in]panel_hPanel framebuffer height in pixels.
Returns
The larger of panel_h and the sidebar's minimum height.
Since
0.1.0
Return values
valueThe operation-specific board overlay total height value.
Precondition
Arguments satisfy the ranges documented for board overlay total height.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board overlay model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 129 of file board_overlay_draw.c.

References k_ovl_min_h.

Referenced by board_overlay_compose(), and board_overlay_draw_sidebar().

◆ board_overlay_total_width()

uint16_t board_overlay_total_width ( uint16_t panel_w)

Total composite width for a panel of width panel_w.

Parameters
[in]panel_wPanel framebuffer width in pixels.
Returns
panel_w plus the sidebar width.
Since
0.1.0

Total composite width for a panel of width panel_w; this step is contained within the board overlay model and uses bounded caller or module-owned storage.

Return values
valueThe operation-specific board overlay total width value.
Precondition
Arguments satisfy the ranges documented for board overlay total width.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board overlay model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 124 of file board_overlay_draw.c.

References k_ovl_sidebar_w.

Referenced by board_overlay_compose(), and board_overlay_draw_sidebar().