use std::{net::SocketAddr, time::Duration};
use mnemos_kernel::forth::Params;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct PlatformConfig {
pub tcp_uart: TcpUartConfig,
pub display: DisplayConfig,
pub forth_shell: ForthShell,
pub sleep_cap: Option<Duration>,
}
impl PlatformConfig {
pub const fn default_sleep_cap() -> Duration {
Duration::from_millis(100)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TcpUartConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default = "TcpUartConfig::default_kchannel_depth")]
pub kchannel_depth: usize,
#[serde(default = "TcpUartConfig::default_incoming_size")]
pub incoming_size: usize,
#[serde(default = "TcpUartConfig::default_outgoing_size")]
pub outgoing_size: usize,
#[serde(default = "TcpUartConfig::default_socket_addr")]
pub socket_addr: SocketAddr,
}
impl TcpUartConfig {
pub const DEFAULT_KCHANNEL_DEPTH: usize = 2;
pub const DEFAULT_INCOMING_SIZE: usize = 4096;
pub const DEFAULT_OUTGOING_SIZE: usize = 4096;
pub const DEFAULT_SOCKET_ADDR_STR: &str = "127.0.0.1:9999";
const fn default_kchannel_depth() -> usize {
Self::DEFAULT_KCHANNEL_DEPTH
}
const fn default_incoming_size() -> usize {
Self::DEFAULT_INCOMING_SIZE
}
const fn default_outgoing_size() -> usize {
Self::DEFAULT_OUTGOING_SIZE
}
fn default_socket_addr() -> SocketAddr {
Self::DEFAULT_SOCKET_ADDR_STR.parse().unwrap()
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DisplayConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default = "DisplayConfig::default_kchannel_depth")]
pub kchannel_depth: usize,
#[serde(default = "DisplayConfig::default_frames_per_second")]
pub frames_per_second: usize,
#[serde(default = "DisplayConfig::default_scaling")]
pub scaling: u32,
}
impl DisplayConfig {
pub const DEFAULT_KCHANNEL_DEPTH: usize = 2;
pub const DEFAULT_FRAMES_PER_SECOND: usize = 20;
pub const DEFAULT_SCALING: u32 = 2;
const fn default_kchannel_depth() -> usize {
Self::DEFAULT_KCHANNEL_DEPTH
}
const fn default_frames_per_second() -> usize {
Self::DEFAULT_FRAMES_PER_SECOND
}
const fn default_scaling() -> u32 {
Self::DEFAULT_SCALING
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ForthShell {
#[serde(default)]
pub enabled: bool,
#[serde(default = "ForthShell::default_capacity")]
pub capacity: usize,
#[serde(default = "ForthShell::default_params")]
pub params: Params,
}
impl ForthShell {
pub const DEFAULT_CAPACITY: usize = 1024;
pub const DEFAULT_PARAMS: Params = Params::new();
const fn default_capacity() -> usize {
Self::DEFAULT_CAPACITY
}
const fn default_params() -> Params {
Self::DEFAULT_PARAMS
}
}