mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-10 16:25:37 +00:00
move to heapless 0.7
This commit is contained in:
parent
b672967d8a
commit
1752956de2
13 changed files with 40 additions and 38 deletions
|
@ -18,11 +18,14 @@ cortex-m-rtic = "0.5.1"
|
||||||
defmt = "0.2.1"
|
defmt = "0.2.1"
|
||||||
defmt-rtt = "0.2.0"
|
defmt-rtt = "0.2.0"
|
||||||
dk = { path = "../../boards/dk", features = ["advanced"] }
|
dk = { path = "../../boards/dk", features = ["advanced"] }
|
||||||
heapless = "0.5.5"
|
|
||||||
panic-probe = { version = "0.2.0", features = ["print-defmt"] }
|
panic-probe = { version = "0.2.0", features = ["print-defmt"] }
|
||||||
usb = { path = "../common/usb" }
|
usb = { path = "../common/usb" }
|
||||||
usb2 = "0.0.1"
|
usb2 = "0.0.1"
|
||||||
|
|
||||||
|
[dependencies.heapless]
|
||||||
|
version = "0.7.1"
|
||||||
|
features = ["defmt-impl"]
|
||||||
|
|
||||||
# optimize code in both profiles
|
# optimize code in both profiles
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
|
@ -91,7 +91,6 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
defmt::info!("EP0: {:?}", defmt::Debug2Format(&request));
|
defmt::info!("EP0: {:?}", defmt::Debug2Format(&request));
|
||||||
// ^^^^^^^^^^^^^^^^^^^ this adapter is currently needed to log
|
// ^^^^^^^^^^^^^^^^^^^ this adapter is currently needed to log
|
||||||
// `StandardRequest` with `defmt`
|
// `StandardRequest` with `defmt`
|
||||||
|
|
||||||
match request {
|
match request {
|
||||||
// section 9.4.3
|
// section 9.4.3
|
||||||
// this request is valid in any state
|
// this request is valid in any state
|
||||||
|
@ -116,7 +115,7 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
|
|
||||||
Descriptor::Configuration { index } => {
|
Descriptor::Configuration { index } => {
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
let mut resp = heapless::Vec::<u8, heapless::consts::U64>::new();
|
let mut resp = heapless::Vec::<u8, 64>::new();
|
||||||
|
|
||||||
let conf_desc = usb2::configuration::Descriptor {
|
let conf_desc = usb2::configuration::Descriptor {
|
||||||
wTotalLength: (usb2::configuration::Descriptor::SIZE
|
wTotalLength: (usb2::configuration::Descriptor::SIZE
|
||||||
|
|
|
@ -116,7 +116,7 @@ fn ep0setup(usbd: &USBD, ep0in: &mut Ep0In, state: &mut State) -> Result<(), ()>
|
||||||
|
|
||||||
Descriptor::Configuration { index } => {
|
Descriptor::Configuration { index } => {
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
let mut resp = heapless::Vec::<u8, heapless::consts::U64>::new();
|
let mut resp = heapless::Vec::<u8, 64>::new();
|
||||||
|
|
||||||
let conf_desc = usb2::configuration::Descriptor {
|
let conf_desc = usb2::configuration::Descriptor {
|
||||||
wTotalLength: (usb2::configuration::Descriptor::SIZE
|
wTotalLength: (usb2::configuration::Descriptor::SIZE
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use heapless::{consts, Vec};
|
use heapless::Vec;
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use firmware as _;
|
use firmware as _;
|
||||||
|
|
||||||
|
@ -12,21 +12,18 @@ fn main() -> ! {
|
||||||
dk::init().unwrap();
|
dk::init().unwrap();
|
||||||
|
|
||||||
// a stack-allocated `Vec` with capacity for 6 bytes
|
// a stack-allocated `Vec` with capacity for 6 bytes
|
||||||
let mut buffer = Vec::<u8, consts::U6>::new();
|
let mut buffer = Vec::<u8, 6>::new();
|
||||||
// ^^ capacity; this is a type not a value
|
// content type ^^ ^ capacity
|
||||||
|
|
||||||
// `heapless::Vec` exposes the same API surface as `std::Vec` but some of its methods return a
|
// `heapless::Vec` exposes the same API surface as `std::Vec` but some of its methods return a
|
||||||
// `Result` to indicate whether the operation failed due to the `heapless::Vec` being full
|
// `Result` to indicate whether the operation failed due to the `heapless::Vec` being full
|
||||||
defmt::info!("start: {:?}", defmt::Debug2Format(&buffer));
|
defmt::info!("start: {:?}", buffer);
|
||||||
// ^^^^^^^^^^^^^^^^^^^ this adapter is currently needed to log
|
|
||||||
// `heapless` data structures (like `Vec` here)
|
|
||||||
// with `defmt`
|
|
||||||
|
|
||||||
buffer.push(0).expect("buffer full");
|
buffer.push(0).expect("buffer full");
|
||||||
defmt::info!("after `push`: {:?}", defmt::Debug2Format(&buffer));
|
defmt::info!("after `push`: {:?}", buffer);
|
||||||
|
|
||||||
buffer.extend_from_slice(&[1, 2, 3]).expect("buffer full");
|
buffer.extend_from_slice(&[1, 2, 3]).expect("buffer full");
|
||||||
defmt::info!("after `extend`: {:?}", defmt::Debug2Format(&buffer));
|
defmt::info!("after `extend`: {:?}", &buffer);
|
||||||
|
|
||||||
// TODO try this operation
|
// TODO try this operation
|
||||||
// buffer.extend_from_slice(&[4, 5, 6, 7]).expect("buffer full");
|
// buffer.extend_from_slice(&[4, 5, 6, 7]).expect("buffer full");
|
||||||
|
|
|
@ -14,6 +14,10 @@ panic-probe = { version = "0.3.0", features = ["print-defmt"] }
|
||||||
defmt = "0.3.0"
|
defmt = "0.3.0"
|
||||||
defmt-rtt = "0.3.1"
|
defmt-rtt = "0.3.1"
|
||||||
|
|
||||||
|
[dependencies.heapless]
|
||||||
|
version = "0.7.1"
|
||||||
|
features = ["defmt-impl"]
|
||||||
|
|
||||||
# optimize code in both profiles
|
# optimize code in both profiles
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
|
@ -6,7 +6,7 @@ use cortex_m_rt::entry;
|
||||||
// NOTE you can use `FnvIndexMap` instead of `LinearMap`; the former may have better
|
// NOTE you can use `FnvIndexMap` instead of `LinearMap`; the former may have better
|
||||||
// lookup performance when the dictionary contains a large number of items but performance is
|
// lookup performance when the dictionary contains a large number of items but performance is
|
||||||
// not important for this exercise
|
// not important for this exercise
|
||||||
use heapless::{consts, LinearMap};
|
use heapless::LinearMap;
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use apps as _;
|
use apps as _;
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@ fn main() -> ! {
|
||||||
dk::init().unwrap();
|
dk::init().unwrap();
|
||||||
|
|
||||||
// a dictionary with capacity for 2 elements
|
// a dictionary with capacity for 2 elements
|
||||||
let mut dict = LinearMap::<_, _, consts::U2>::new();
|
let mut dict = LinearMap::<_, _, 2>::new();
|
||||||
// ^^ capacity; this is a type not a value
|
// content types ^^ ^^ ^ capacity
|
||||||
|
// (inferred by rust)
|
||||||
|
|
||||||
// do some insertions
|
// do some insertions
|
||||||
dict.insert(b'A', b'*').expect("dictionary full");
|
dict.insert(b'A', b'*').expect("dictionary full");
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use dk::ieee802154::{Channel, Packet};
|
use dk::ieee802154::{Channel, Packet};
|
||||||
use heapless::{consts, LinearMap};
|
use heapless::LinearMap;
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use apps as _;
|
use apps as _;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ fn main() -> ! {
|
||||||
radio.set_channel(Channel::_25);
|
radio.set_channel(Channel::_25);
|
||||||
|
|
||||||
// capacity (128) should be large enough for the ASCII range
|
// capacity (128) should be large enough for the ASCII range
|
||||||
let dict = LinearMap::<u8, u8, consts::U128>::new();
|
let mut dict = LinearMap::<u8, u8, 128>::new();
|
||||||
|
|
||||||
let mut packet = Packet::new();
|
let mut packet = Packet::new();
|
||||||
// TODO do the whole ASCII range [0, 127]
|
// TODO do the whole ASCII range [0, 127]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use core::str;
|
use core::str;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use heapless::{consts, Vec};
|
use heapless::Vec;
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use apps as _;
|
use apps as _;
|
||||||
|
|
||||||
|
@ -14,17 +14,15 @@ fn main() -> ! {
|
||||||
dk::init().unwrap();
|
dk::init().unwrap();
|
||||||
|
|
||||||
// a buffer with capacity for 2 bytes
|
// a buffer with capacity for 2 bytes
|
||||||
let mut buffer = Vec::<u8, consts::U2>::new();
|
let mut buffer = Vec::<u8, 2>::new();
|
||||||
// ^^ capacity; this is a type not a value
|
// content type ^^ ^ capacity
|
||||||
|
|
||||||
// do some insertions
|
// do some insertions
|
||||||
buffer.push(b'H').expect("buffer full");
|
buffer.push(b'H').expect("buffer full");
|
||||||
buffer.push(b'i').expect("buffer full");
|
buffer.push(b'i').expect("buffer full");
|
||||||
|
|
||||||
// look into the contents so far
|
// look into the contents so far
|
||||||
defmt::info!("{:?}", defmt::Debug2Format(&buffer));
|
defmt::info!("{:?}", buffer);
|
||||||
// ^^^^^^^^^^^^^^^^^^^ this adapter is currently needed to log `heapless`
|
|
||||||
// data structures (like `Vec` here) with `defmt`
|
|
||||||
|
|
||||||
// or more readable
|
// or more readable
|
||||||
// NOTE utf-8 conversion works as long as you only push bytes in the ASCII range (0..=127)
|
// NOTE utf-8 conversion works as long as you only push bytes in the ASCII range (0..=127)
|
||||||
|
|
|
@ -6,7 +6,7 @@ use core::str;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use dk::ieee802154::{Channel, Packet};
|
use dk::ieee802154::{Channel, Packet};
|
||||||
use heapless::{consts, Vec};
|
use heapless::Vec;
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use apps as _;
|
use apps as _;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ fn main() -> ! {
|
||||||
);
|
);
|
||||||
|
|
||||||
/* # Decrypt the string */
|
/* # Decrypt the string */
|
||||||
let mut buf = Vec::<u8, consts::U128>::new();
|
let mut buf = Vec::<u8, 128>::new();
|
||||||
|
|
||||||
// iterate over the bytes
|
// iterate over the bytes
|
||||||
for input in packet.iter() {
|
for input in packet.iter() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use core::str;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use dk::ieee802154::{Channel, Packet};
|
use dk::ieee802154::{Channel, Packet};
|
||||||
use heapless::{consts, LinearMap, Vec};
|
use heapless::{LinearMap, Vec};
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use apps as _;
|
use apps as _;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ fn main() -> ! {
|
||||||
radio.set_channel(Channel::_25);
|
radio.set_channel(Channel::_25);
|
||||||
|
|
||||||
/* # Build a dictionary */
|
/* # Build a dictionary */
|
||||||
let dict = LinearMap::<u8, u8, consts::U128>::new();
|
let dict = LinearMap::<u8, u8, 128>::new();
|
||||||
|
|
||||||
let mut packet = Packet::new();
|
let mut packet = Packet::new();
|
||||||
for source in 0..=127 {
|
for source in 0..=127 {
|
||||||
|
@ -62,7 +62,7 @@ fn main() -> ! {
|
||||||
);
|
);
|
||||||
|
|
||||||
/* # Decrypt the string */
|
/* # Decrypt the string */
|
||||||
let mut buffer = Vec::<u8, consts::U128>::new();
|
let mut buffer = Vec::<u8, 128>::new();
|
||||||
|
|
||||||
// iterate over the bytes
|
// iterate over the bytes
|
||||||
for byte in packet.iter() {
|
for byte in packet.iter() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use core::str;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use dk::ieee802154::{Channel, Packet};
|
use dk::ieee802154::{Channel, Packet};
|
||||||
use heapless::{consts, LinearMap, Vec};
|
use heapless::{LinearMap, Vec};
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use apps as _;
|
use apps as _;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ fn main() -> ! {
|
||||||
radio.set_channel(Channel::_25);
|
radio.set_channel(Channel::_25);
|
||||||
|
|
||||||
/* # Build a dictionary */
|
/* # Build a dictionary */
|
||||||
let dict = LinearMap::<u8, u8, consts::U128>::new();
|
let dict = LinearMap::<u8, u8, 128>::new();
|
||||||
|
|
||||||
let mut packet = Packet::new();
|
let mut packet = Packet::new();
|
||||||
for source in 0..=127 {
|
for source in 0..=127 {
|
||||||
|
@ -62,7 +62,7 @@ fn main() -> ! {
|
||||||
);
|
);
|
||||||
|
|
||||||
/* # Decrypt the string */
|
/* # Decrypt the string */
|
||||||
let mut buffer = Vec::<u8, consts::U128>::new();
|
let mut buffer = Vec::<u8, 128>::new();
|
||||||
|
|
||||||
// iterate over the bytes
|
// iterate over the bytes
|
||||||
for byte in packet.iter() {
|
for byte in packet.iter() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use core::str;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use dk::ieee802154::{Channel, Packet};
|
use dk::ieee802154::{Channel, Packet};
|
||||||
use heapless::{consts, LinearMap};
|
use heapless::LinearMap;
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use apps as _;
|
use apps as _;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ fn main() -> ! {
|
||||||
radio.set_channel(Channel::_25);
|
radio.set_channel(Channel::_25);
|
||||||
|
|
||||||
/* # Build a dictionary */
|
/* # Build a dictionary */
|
||||||
let mut dict = LinearMap::<u8, u8, consts::U128>::new();
|
let mut dict = LinearMap::<u8, u8, 128>::new();
|
||||||
|
|
||||||
// the IEEE 802.15.4 packet that will carry our data
|
// the IEEE 802.15.4 packet that will carry our data
|
||||||
let mut packet = Packet::new();
|
let mut packet = Packet::new();
|
||||||
|
|
|
@ -6,7 +6,7 @@ use core::str;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use dk::ieee802154::{Channel, Packet};
|
use dk::ieee802154::{Channel, Packet};
|
||||||
use heapless::{consts, LinearMap, Vec};
|
use heapless::{LinearMap, Vec};
|
||||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||||
use apps as _;
|
use apps as _;
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ fn main() -> ! {
|
||||||
radio.set_channel(Channel::_25);
|
radio.set_channel(Channel::_25);
|
||||||
|
|
||||||
/* # Build a dictionary */
|
/* # Build a dictionary */
|
||||||
let mut dict = LinearMap::<u8, u8, consts::U128>::new();
|
let mut dict = LinearMap::<u8, u8, 128>::new();
|
||||||
// ^^^^^^^^^^^^ NOTE larger capacity
|
// ^^^ NOTE larger capacity
|
||||||
|
|
||||||
// the IEEE 802.15.4 packet that will carry our data
|
// the IEEE 802.15.4 packet that will carry our data
|
||||||
let mut packet = Packet::new();
|
let mut packet = Packet::new();
|
||||||
|
@ -66,7 +66,7 @@ fn main() -> ! {
|
||||||
);
|
);
|
||||||
|
|
||||||
/* # Decrypt the string */
|
/* # Decrypt the string */
|
||||||
let mut buffer = Vec::<u8, consts::U128>::new();
|
let mut buffer = Vec::<u8, 128>::new();
|
||||||
|
|
||||||
// iterate over the bytes
|
// iterate over the bytes
|
||||||
for cipherletter in packet.iter() {
|
for cipherletter in packet.iter() {
|
||||||
|
|
Loading…
Reference in a new issue