ove/
board.rs

1// Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4//
5// This file is part of oveRTOS.
6
7//! Board initialization and identification for oveRTOS.
8//!
9//! Provides [`init`] to bring up all board peripherals and [`name`] to retrieve
10//! the board identifier string at runtime.
11
12use crate::bindings;
13use crate::error::{Error, Result};
14
15/// Initialize the board (clocks, pinmux, and core peripherals).
16///
17/// Must be called once at startup before using any peripheral APIs.
18///
19/// # Errors
20/// Returns an error if any hardware peripheral fails to initialize.
21pub fn init() -> Result<()> {
22    let rc = unsafe { bindings::ove_board_init() };
23    Error::from_code(rc)
24}
25
26/// Return the board name as a static string (e.g. `"stm32f4-disco"`).
27///
28/// Returns `"unknown"` if the board name is unavailable or not valid UTF-8.
29pub fn name() -> &'static str {
30    let ptr = unsafe { bindings::ove_board_name() };
31    if ptr.is_null() {
32        "unknown"
33    } else {
34        unsafe { core::ffi::CStr::from_ptr(ptr) }
35            .to_str()
36            .unwrap_or("unknown")
37    }
38}