Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add embedded std #467

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions firmware-support/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion firmware-support/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# SPDX-FileCopyrightText: 2022 Google LLC
# SPDX-FileCopyrightText: 2022-2024 Google LLC
#
# SPDX-License-Identifier: CC0-1.0

[workspace]
members = [
"bittide-sys",
"embedded-std",
]
resolver = "2"
30 changes: 30 additions & 0 deletions firmware-support/embedded-std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2024 Google LLC
#
# SPDX-License-Identifier: CC0-1.0

[package]
name = "embedded-std"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
authors = ["Google LLC"]
resolver = "2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
panic-handler = []
default = []

[dependencies]
ufmt = "0.2.0"
heapless = { version = "0.7", default-features = false}

[dev-dependencies]
proptest = "1.0"
object = { version = "0.28", features = ["write"] }
libc = "0.2"
test-strategy = "0.2.0"
rand = "0.8"
lazy_static = "1.0"
tempfile = "3"
7 changes: 7 additions & 0 deletions firmware-support/embedded-std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2024 Google LLC
//
// SPDX-License-Identifier: Apache-2.0

#![no_std]

pub mod string;
31 changes: 31 additions & 0 deletions firmware-support/embedded-std/src/string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2024 Google LLC
//
// SPDX-License-Identifier: Apache-2.0
use ufmt::{uDisplay, uWrite};

#[derive(Clone)]
pub struct String<const SIZE: usize>(pub heapless::String<SIZE>);

impl <const SIZE: usize> String<SIZE> {
pub fn new() -> Self {
String(heapless::String::new())
}
}

impl<const SIZE: usize> uDisplay for String<SIZE> {
#[inline(always)]
fn fmt<W>(&self, f: &mut ufmt::Formatter<'_, W>) -> Result<(), W::Error>
where
W: uWrite + ?Sized,
{
f.write_str(&self.0.as_str())
}
}

impl <const SIZE: usize> ufmt::uWrite for String<SIZE> {
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
self.0.push_str(s)?;
Ok(())
}
type Error = ();
}
Loading