|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Board-view presentation implementation (see emu_view.h). More...
#include "emu_view.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include "board_console.h"#include "board_periph.h"#include "board_periph_sd.h"#include "board_usb.h"#include "emu_exc.h"#include "emu_host_io_internal.h"#include "emu_mmio.h"#include "emu_view_surface_internal.h"Go to the source code of this file.
Functions | |
| static void | internal_fill_status_hw (board_status_t *st, const char *app_name) |
| Snapshot the LED / USB / UART / IRQ / switch / battery / SD state. | |
| static void | internal_fill_console_tabs (board_status_t *st) |
Populate the console tab-bar metadata in st. | |
| static uint32_t | internal_console_advance_scroll (uint32_t avail, uint32_t total) |
| Advance and clamp the console scroll offset, returning where to read. | |
| static void | internal_fill_status_console (board_status_t *st) |
| Perform fill status console for the emu view model. | |
| static void | internal_fill_status (board_status_t *st, const char *app_name) |
| Snapshot the live peripheral state into a board-view status struct. | |
| void | unrotate_click (uint16_t cx, uint16_t cy, uint16_t panel_w, uint16_t panel_h, uint32_t deg, uint16_t *nx, uint16_t *ny) |
| Map a click in the rotated displayed panel back to native panel coords. | |
| void | set_switch (board_overlay_btn_t btn, bool pressed) |
| Toggle a user switch's pressed level (active-low) for an on-screen button. | |
| void | apply_battery_click (board_overlay_btn_t btn, uint16_t cx, uint16_t disp_w) |
| Apply a POWER-section click to the fuel-gauge model. | |
| board_overlay_btn_t | route_click (uint16_t cx, uint16_t cy, uint16_t panel_w, uint16_t panel_h, uint16_t disp_w, uint32_t rotate_deg) |
| Route a composite-space click to the right input model. | |
| bool | build_composite (uc_engine *uc, emu_presentation_workspace_t *presentation, const char *app_name) |
| Stream the panel and status sidebar into a raw-fd surface. | |
| static void | internal_panel_rstrip (char *s) |
| Trim trailing space/tab/CR/LF in place. | |
| static bool | internal_panel_split_kv (char *line, char **key, char **val) |
| Split one config line into a trimmed key / value pair, in place. | |
| static void | internal_panel_set_name (board_panel_t *out, const char *val) |
Copy the panel name value into out, stripping optional quotes. | |
| static void | internal_panel_apply_kv (board_panel_t *out, const char *key, const char *val) |
Apply one recognised key=value pair to out; unknown keys are ignored. | |
| static bool | internal_parse_panel (char *text, board_panel_t *out) |
| Parse bounded panel-config text already loaded into memory. | |
| bool | load_panel (const char *path, board_panel_t *out) |
| Load a panel descriptor (name / width / height) from a TOML-ish file. | |
| void | emu_view_publish (uint32_t pc, uint32_t chunks) |
| Implementation of emu_view_publish() – run-loop telemetry. | |
| void | emu_view_mark_stopped (uint32_t pc) |
| Implementation of emu_view_mark_stopped() – final held frame. | |
| void | emu_view_wheel (int32_t notches) |
| Implementation of emu_view_wheel() – scrollback paging. | |
| void | emu_view_select_console_tab (uint32_t tab_idx) |
| Implementation of emu_view_select_console_tab() – tab switch. | |
| void | emu_view_reset_console (void) |
| Implementation of emu_view_reset_console() – warm-reboot view reset. | |
| board_primary_core_t | emu_primary_core (void) |
| Implementation of emu_primary_core() – plain state read. | |
| void | emu_set_primary_core (board_primary_core_t core) |
| Implementation of emu_set_primary_core() – plain state write. | |
| bool | emu_low_power (void) |
| Implementation of emu_low_power() – plain state read. | |
| void | emu_set_low_power (bool on) |
| Implementation of emu_set_low_power() – plain state write. | |
Variables | |
| static uint32_t | s_view_pc |
| static uint32_t | s_view_chunks |
| static bool | s_view_running = true |
| static uint32_t | s_view_scroll |
| static bool | s_view_autoscroll = true |
| static uint32_t | s_view_log_seen |
| static board_console_ch_t | s_view_console_ch = k_board_console_ch_all |
| static board_primary_core_t | s_primary_core = k_core_m85 |
| static bool | s_low_power = false |
Board-view presentation implementation (see emu_view.h).
Frame building from live GLCDC state, PPM writing, the status-sidebar snapshot, rotation/unrotation, input routing shared by the window and the headless –click, the panel-descriptor loader, and the console-scrollback
Definition in file emu_view.c.
| void apply_battery_click | ( | board_overlay_btn_t | btn, |
| uint16_t | cx, | ||
| uint16_t | disp_w ) |
Apply a POWER-section click to the fuel-gauge model.
Apply a POWER-section click to the fuel-gauge / core model.
A click on the battery slider track maps the click column to a 0..100 percent (board_overlay_battery_pct_at) and writes it while preserving the charge state; a click on the CHG toggle flips charging while preserving SOC. Shared by the live window and the headless --click so both behave alike.
| [in] | btn | The POWER button hit (battery slider or CHG toggle). |
| [in] | cx | Click column in composite pixels (for the slider map). |
| [in] | disp_w | Displayed panel width (the sidebar origin). |
Definition at line 289 of file emu_view.c.
References board_overlay_battery_pct_at(), board_periph_battery_get(), board_periph_battery_set(), k_board_overlay_btn_batt_chg, k_board_overlay_btn_battery, k_board_overlay_btn_lowpower, and s_low_power.
Referenced by internal_run_loop_tick_inputs(), internal_run_loop_view(), and route_click().
| bool build_composite | ( | uc_engine * | uc, |
| emu_presentation_workspace_t * | presentation, | ||
| const char * | app_name ) |
Stream the panel and status sidebar into a raw-fd surface.
Clears and fills the fd-backed composite, copies the live GLCDC layer through bounded rotation tiles, then renders the exact legacy sidebar through its clipped rectangle sink.
| [in,out] | uc | Unicorn engine (read for the GLCDC framebuffer). |
| [in,out] | presentation | Owned fd and caller-owned tile scratch. |
| [in] | app_name | Window / app title for the sidebar caption. |
| true | The exact composite is ready. |
| false | An engine read or raw-fd sink operation failed. |
presentation is active, open, and outlives the operation. Definition at line 371 of file emu_view.c.
References internal_fill_status(), and priv_emu_view_surface_build().
Referenced by internal_run_loop_record(), internal_run_view_maybe_present(), priv_run_hold_view(), and priv_run_write_outputs().
| bool emu_low_power | ( | void | ) |
Implementation of emu_low_power() – plain state read.
Whether the M33 4:1-slower low-power clock model is active.
Definition at line 645 of file emu_view.c.
References s_low_power.
Referenced by internal_main_load_primary(), and internal_run_inner_budget().
| board_primary_core_t emu_primary_core | ( | void | ) |
Implementation of emu_primary_core() – plain state read.
The primary core the firmware targets (label + seam gating).
Definition at line 633 of file emu_view.c.
References s_primary_core.
Referenced by internal_main_install_run_seams(), and internal_main_load_primary().
| void emu_set_low_power | ( | bool | on | ) |
Implementation of emu_set_low_power() – plain state write.
Set the low-power clock model (CLI –low-power / GUI toggle).
Definition at line 651 of file emu_view.c.
References s_low_power.
Referenced by internal_args_try_mode().
| void emu_set_primary_core | ( | board_primary_core_t | core | ) |
Implementation of emu_set_primary_core() – plain state write.
Select the primary core (CLI –primary-core).
Definition at line 639 of file emu_view.c.
References s_primary_core.
Referenced by internal_args_try_mode().
| void emu_view_mark_stopped | ( | uint32_t | pc | ) |
Implementation of emu_view_mark_stopped() – final held frame.
Mark the run ended: the held frame shows "parked" at pc.
Definition at line 591 of file emu_view.c.
References s_view_pc, and s_view_running.
Referenced by priv_run_report().
| void emu_view_publish | ( | uint32_t | pc, |
| uint32_t | chunks ) |
Implementation of emu_view_publish() – run-loop telemetry.
Publish the run-loop telemetry the board view shows.
Definition at line 584 of file emu_view.c.
References s_view_chunks, and s_view_pc.
Referenced by internal_run_loop_prologue().
| void emu_view_reset_console | ( | void | ) |
Implementation of emu_view_reset_console() – warm-reboot view reset.
Reset the console-scrollback view (warm-reboot support).
Definition at line 624 of file emu_view.c.
References k_board_console_ch_all, s_view_autoscroll, s_view_console_ch, s_view_log_seen, and s_view_scroll.
Referenced by warm_reboot().
| void emu_view_select_console_tab | ( | uint32_t | tab_idx | ) |
Implementation of emu_view_select_console_tab() – tab switch.
Switch the visible console channel to tab_idx (tab-bar click).
Definition at line 615 of file emu_view.c.
References board_console_total(), s_view_autoscroll, s_view_console_ch, s_view_log_seen, and s_view_scroll.
Referenced by internal_run_classify_click().
| void emu_view_wheel | ( | int32_t | notches | ) |
Implementation of emu_view_wheel() – scrollback paging.
Page the console scrollback by mouse-wheel notches.
Definition at line 598 of file emu_view.c.
References s_view_autoscroll, and s_view_scroll.
Referenced by internal_run_loop_view().
|
static |
Advance and clamp the console scroll offset, returning where to read.
While autoscroll is on the view follows the live tail. While paused, new lines push the tail forward, so the back-offset advances by the same amount to keep the reader's current lines on screen – capped at the ring depth, because anything older than the ring has already aged out. The result is re-clamped so a shrunken or shallow history cannot scroll past its top.
| [in] | avail | Lines currently held in the active channel's ring. |
| [in] | total | Lines ever pushed to that channel (monotonic). |
total. avail. total.| value | The operation-specific console advance scroll value. |
Definition at line 157 of file emu_view.c.
References k_overlay_console_rows, k_uart_log_max, RA8_INTERNAL, s_view_autoscroll, s_view_log_seen, and s_view_scroll.
Referenced by internal_fill_status_console().
|
static |
Populate the console tab-bar metadata in st.
Each board_console channel (ALL | UART | ITM | SPI | I2C) is a tab. The overlay needs each tab's name and live line count, plus which tab is active, to draw the bar and hit-test clicks on it.
| [out] | st | Status block whose console_ch_* fields are filled. |
st is non-NULL. Definition at line 120 of file emu_view.c.
References board_console_count(), board_console_name(), board_status_t::console_active_ch, board_status_t::console_ch_count, board_status_t::console_ch_count_lines, board_status_t::console_ch_name, k_board_console_ch_count, k_overlay_console_tabs_max, RA8_INTERNAL, and s_view_console_ch.
Referenced by internal_fill_status_console().
|
static |
Snapshot the live peripheral state into a board-view status struct.
Reads the read-only board_periph / board_usb getters – per-LED level + lit colour, the USB device-state string, the last captured UART line, the NVIC IRQ totals, and the last drained touch point – so the overlay can render the status sidebar without reaching into any model's internals.
| [out] | st | Status struct to fill. |
| [in] | app_name | Window / app title to caption the sidebar with. |
Definition at line 235 of file emu_view.c.
References internal_fill_status_console(), internal_fill_status_hw(), and RA8_INTERNAL.
Referenced by build_composite().
|
static |
Perform fill status console for the emu view model.
Perform fill status console for the emu view model; this step is contained within the emu view model and uses bounded caller or module-owned storage.
| [in,out] | st | Board-status snapshot used to render or report state. |
Definition at line 186 of file emu_view.c.
References board_console_count(), board_console_line(), board_console_total(), board_periph_uart_tx_total(), board_status_t::chunks, board_status_t::console, board_status_t::console_autoscroll, board_status_t::console_count, board_status_t::console_scroll, board_status_t::console_total, emu_mmio_reads(), emu_mmio_writes(), internal_console_advance_scroll(), internal_fill_console_tabs(), k_overlay_console_rows, k_overlay_line_cap, board_status_t::mmio_reads, board_status_t::mmio_writes, board_status_t::pc, RA8_INTERNAL, board_status_t::running, s_view_autoscroll, s_view_chunks, s_view_console_ch, s_view_pc, s_view_running, and board_status_t::uart_tx_total.
Referenced by internal_fill_status().
|
static |
Snapshot the LED / USB / UART / IRQ / switch / battery / SD state.
Snapshot the led / usb / uart / irq / switch / battery / sd state; this step is contained within the emu view model and uses bounded caller or module-owned storage.
| [in,out] | st | Board-status snapshot used to render or report state. |
| [in] | app_name | App name input used by the operation. |
Definition at line 76 of file emu_view.c.
References board_status_t::app_name, board_status_t::battery_charging, board_status_t::battery_soc, board_periph_battery_get(), board_periph_gpio_get_input(), board_periph_irq_count(), board_periph_irq_total(), board_periph_led_color_rgb565(), board_periph_led_level(), board_periph_touch_last(), board_periph_uart_last_line(), board_sd_info(), board_usb_state_string(), board_led_status_t::color, board_status_t::core_is_m33, board_status_t::has_touch, board_status_t::irq0, board_status_t::irq1, board_status_t::irq_total, k_core_m33, k_emu_sw1_pin, k_emu_sw2_pin, k_emu_sw_port, k_overlay_led_count, board_led_status_t::label, board_status_t::leds, board_status_t::low_power, board_led_status_t::on, RA8_INTERNAL, s_low_power, s_primary_core, board_status_t::sd_attached, board_status_t::sd_bytes, board_status_t::sd_fat_bits, board_status_t::sd_label, board_status_t::sw1_pressed, board_status_t::sw2_pressed, board_status_t::touch_x, board_status_t::touch_y, board_status_t::uart_line, and board_status_t::usb_state.
Referenced by internal_fill_status().
|
static |
Apply one recognised key=value pair to out; unknown keys are ignored.
| [in,out] | out | Panel description being built. |
| [in] | key | Trimmed key text. |
| [in] | val | Trimmed value text. |
out, key and val are non-NULL. key and val are NUL-terminated. out is written, or none for an unknown key. Apply one recognised key=value pair to out; unknown keys are ignored; this step is contained within the emu view model and uses bounded caller or module-owned storage.
Definition at line 497 of file emu_view.c.
References board_panel_t::height, internal_panel_set_name(), k_strtol_base10, strncmp(), and board_panel_t::width.
Referenced by internal_parse_panel().
|
static |
Trim trailing space/tab/CR/LF in place.
Trim trailing space/tab/cr/lf in place; this step is contained within the emu view model and uses bounded caller or module-owned storage.
| [in,out] | s | Module state instance processed by the operation. |
Definition at line 389 of file emu_view.c.
References RA8_INTERNAL, and strlen().
Referenced by internal_panel_split_kv().
|
static |
Copy the panel name value into out, stripping optional quotes.
| [out] | out | Panel description receiving the name. |
| [in] | val | Raw value text, optionally wrapped in double quotes. |
out and val are non-NULL. val is NUL-terminated. Copy the panel name value into out, stripping optional quotes; this step is contained within the emu view model and uses bounded caller or module-owned storage.
Definition at line 465 of file emu_view.c.
References memcpy(), board_panel_t::name, RA8_INTERNAL, and strlen().
Referenced by internal_panel_apply_kv().
|
static |
Split one config line into a trimmed key / value pair, in place.
Skips leading blanks, ignores comment and blank lines, splits on the first =, then right-trims both halves. The line buffer is modified: the = becomes the key's terminator and key / val point into it.
| [in,out] | line | Mutable line buffer from the config file. |
| [out] | key | Receives a pointer to the trimmed key. |
| [out] | val | Receives a pointer to the trimmed value. |
line, key and val are non-NULL. line is NUL-terminated and writable. line. | true | The panel split kv condition holds or completed successfully; false otherwise. |
Definition at line 425 of file emu_view.c.
References internal_panel_rstrip(), RA8_INTERNAL, and strchr().
Referenced by internal_parse_panel().
|
static |
Parse bounded panel-config text already loaded into memory.
Splits newline-delimited records in place and applies recognised key/value pairs.
| [in,out] | text | Writable NUL-terminated config text. |
| [in,out] | out | Descriptor receiving recognised values. |
| true | All lines were bounded and parsed or ignored. |
| false | At least one line exceeded k_panel_line_max. |
text is non-null, writable, and NUL-terminated. out is non-null and initialised by the caller. out in input order. Definition at line 525 of file emu_view.c.
References internal_panel_apply_kv(), internal_panel_split_kv(), k_panel_line_max, RA8_INTERNAL, strchr(), and strlen().
Referenced by load_panel().
| bool load_panel | ( | const char * | path, |
| board_panel_t * | out ) |
Load a panel descriptor (name / width / height) from a TOML-ish file.
A flat key = value panel descriptor (see tools/ra8_emulator/panels/), so the board emulator becomes whatever display a config describes – not just the EK-RA8D2 1024x600. The raw descriptor backend rejects files over 4096 bytes, reads into a fixed stack buffer, and parses bounded lines without allocation. Blank lines and '#' comments are ignored and quotes are stripped from the name.
| [in] | path | Panel config path. |
| [out] | out | Filled descriptor on success. |
| false | The file was unreadable or the dimensions were out of range. |
out is non-null. path is NUL-terminated. out holds the descriptor; on false a diagnostic printed. < Maximum accepted panel-description byte count.
Definition at line 550 of file emu_view.c.
References board_panel_t::height, internal_parse_panel(), k_emu_io_ok, k_panel_dim_max, memset(), priv_emu_io_close(), priv_emu_io_errf(), priv_emu_io_open_read(), priv_emu_io_read_exact(), emu_io_result_t::status, and board_panel_t::width.
Referenced by internal_main_apply_panel().
| board_overlay_btn_t route_click | ( | uint16_t | cx, |
| uint16_t | cy, | ||
| uint16_t | panel_w, | ||
| uint16_t | panel_h, | ||
| uint16_t | disp_w, | ||
| uint32_t | rotate_deg ) |
Route a composite-space click to the right input model.
An on-screen SW1 / SW2 button toggles that user switch (active-low); any other click is mapped back through unrotate_click and injected as a GT911 touch – the same path the firmware's real ra8_touch_read drains. This is shared by the live window and the headless --click so both behave alike.
| [in] | cx | Click column in composite pixels. |
| [in] | cy | Click row in composite pixels. |
| [in] | panel_w | Native panel width (for the touch unrotate). |
| [in] | panel_h | Native panel height (for the touch unrotate). |
| [in] | disp_w | Displayed panel width (the sidebar origin for buttons). |
| [in] | rotate_deg | Active display rotation. |
Definition at line 326 of file emu_view.c.
References apply_battery_click(), board_console_total(), board_overlay_hit_button(), board_overlay_hit_console_tab(), board_periph_touch_inject(), k_board_console_ch_count, 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, s_view_autoscroll, s_view_console_ch, s_view_log_seen, s_view_scroll, set_switch(), and unrotate_click().
Referenced by internal_run_loop_view().
| void set_switch | ( | board_overlay_btn_t | btn, |
| bool | pressed ) |
Toggle a user switch's pressed level (active-low) for an on-screen button.
SW1/SW2 are momentary push-buttons wired active-low: held down drives the pin LOW, released returns it HIGH. Driving the level directly makes a click behave as a real button (press on mouse-down, release on mouse-up), not a latching switch.
| [in] | btn | The overlay button hit (SW1 or SW2). |
| [in] | pressed | true while held down, false on release. |
btn is one of the switch buttons. pressed. Definition at line 266 of file emu_view.c.
References board_periph_gpio_set_input(), k_board_overlay_btn_sw2, k_emu_sw1_pin, k_emu_sw2_pin, k_emu_sw_port, and pin.
Referenced by internal_run_loop_tick_inputs(), internal_run_loop_view(), and route_click().
| void unrotate_click | ( | uint16_t | cx, |
| uint16_t | cy, | ||
| uint16_t | panel_w, | ||
| uint16_t | panel_h, | ||
| uint32_t | deg, | ||
| uint16_t * | nx, | ||
| uint16_t * | ny ) |
Map a click in the rotated displayed panel back to native panel coords.
| [in] | cx | Click column in displayed-panel pixels. |
| [in] | cy | Click row in displayed-panel pixels. |
| [in] | panel_w | Native panel width. |
| [in] | panel_h | Native panel height. |
| [in] | deg | Active display rotation (0/90/180/270). |
| [out] | nx | Receives the native column. |
| [out] | ny | Receives the native row. |
nx and ny are non-null. deg is one of the panel_rotate_t values. Map a click in the rotated displayed panel back to native panel coords; this step is contained within the emu view model and uses bounded caller or module-owned storage.
Definition at line 242 of file emu_view.c.
References k_rotate_180, k_rotate_270, and k_rotate_90.
Referenced by internal_run_loop_tick_inputs(), and route_click().
|
static |
Definition at line 64 of file emu_view.c.
Referenced by apply_battery_click(), emu_low_power(), emu_set_low_power(), and internal_fill_status_hw().
|
static |
Definition at line 63 of file emu_view.c.
Referenced by emu_primary_core(), emu_set_primary_core(), and internal_fill_status_hw().
|
static |
Definition at line 52 of file emu_view.c.
Referenced by emu_view_reset_console(), emu_view_select_console_tab(), emu_view_wheel(), internal_console_advance_scroll(), internal_fill_status_console(), and route_click().
|
static |
Definition at line 43 of file emu_view.c.
Referenced by emu_view_publish(), and internal_fill_status_console().
|
static |
Definition at line 57 of file emu_view.c.
Referenced by emu_view_reset_console(), emu_view_select_console_tab(), internal_fill_console_tabs(), internal_fill_status_console(), and route_click().
|
static |
Definition at line 53 of file emu_view.c.
Referenced by emu_view_reset_console(), emu_view_select_console_tab(), internal_console_advance_scroll(), and route_click().
|
static |
Definition at line 42 of file emu_view.c.
Referenced by emu_view_mark_stopped(), emu_view_publish(), and internal_fill_status_console().
|
static |
Definition at line 44 of file emu_view.c.
Referenced by emu_view_mark_stopped(), and internal_fill_status_console().
|
static |
Definition at line 51 of file emu_view.c.
Referenced by emu_view_reset_console(), emu_view_select_console_tab(), emu_view_wheel(), internal_console_advance_scroll(), and route_click().