embedded-trainings-2020/beginner/apps/src/bin/radio-puzzle-4.rs

36 lines
837 B
Rust
Raw Normal View History

2020-06-22 13:23:59 +00:00
#![deny(unused_must_use)]
#![no_main]
#![no_std]
use core::str;
use cortex_m_rt::entry;
2021-06-04 11:41:31 +00:00
use heapless::Vec;
2021-04-12 09:51:44 +00:00
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
use apps as _;
2020-06-22 13:23:59 +00:00
#[entry]
fn main() -> ! {
dk::init().unwrap();
// a buffer with capacity for 2 bytes
2021-06-04 11:41:31 +00:00
let mut buffer = Vec::<u8, 2>::new();
// content type ^^ ^ capacity
2020-06-22 13:23:59 +00:00
// do some insertions
buffer.push(b'H').expect("buffer full");
buffer.push(b'i').expect("buffer full");
// look into the contents so far
2022-01-07 16:24:21 +00:00
defmt::println!("{:?}", buffer);
2021-04-12 09:51:44 +00:00
2020-06-22 13:23:59 +00:00
// or more readable
2021-04-12 09:51:44 +00:00
// NOTE utf-8 conversion works as long as you only push bytes in the ASCII range (0..=127)
2022-01-07 16:24:21 +00:00
defmt::println!(
2020-06-22 13:23:59 +00:00
"{}",
str::from_utf8(&buffer).expect("content was not UTF-8")
);
dk::exit()
}