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

Defmt support #171

Closed
theunkn0wn1 opened this issue Aug 26, 2020 · 5 comments
Closed

Defmt support #171

theunkn0wn1 opened this issue Aug 26, 2020 · 5 comments

Comments

@theunkn0wn1
Copy link
Contributor

I recently discovered the defmt library and attempted to integrate it into one of my embedded projects.

Unfortunately it appears that heapless::Vec doesn't implement the defmt::Format trait yet, which blocks defmt integration in my downstream.

Feature request: support for defmt::Format in heapless::Vec

theunkn0wn1 added a commit to theunkn0wn1/heapless that referenced this issue Aug 26, 2020
 - defmt has native support for slices, so utilize that.
theunkn0wn1 added a commit to theunkn0wn1/heapless that referenced this issue Aug 26, 2020
 - to conform with other optional features
theunkn0wn1 added a commit to theunkn0wn1/heapless that referenced this issue Aug 28, 2020
@korken89
Copy link
Contributor

Hi, I have commented on the PR itself.

bors bot added a commit that referenced this issue Sep 24, 2020
172: defmt impl for Vec r=korken89 a=theunkn0wn1

This PR adds support for encoding `heapless::Vec` for usage with `defmt`.
`defmt` can already handle slices, so this impl simply invokes that encoder method.

I chose to use the slice implementation is I did not perceive the difference between a Vec and a Slice to be of specific importance in a log file, but rather the contents of the vec / slice to be of interest. It also appeared to me as the path of least resistance.

I am marking this as a draft as I have yet to be able to validate this against my local hardware, `probe-run` is giving me some grief that I am reasonably sure is unrelated to this change set. 

Relates to #171 

Co-authored-by: joshua salzedo <thHunkn0WNd@gmail.com>
Co-authored-by: Joshua Salzedo <joshuasalzedo@gmail.com>
bors bot added a commit that referenced this issue Sep 24, 2020
172: defmt impl for Vec r=korken89 a=theunkn0wn1

This PR adds support for encoding `heapless::Vec` for usage with `defmt`.
`defmt` can already handle slices, so this impl simply invokes that encoder method.

I chose to use the slice implementation is I did not perceive the difference between a Vec and a Slice to be of specific importance in a log file, but rather the contents of the vec / slice to be of interest. It also appeared to me as the path of least resistance.

I am marking this as a draft as I have yet to be able to validate this against my local hardware, `probe-run` is giving me some grief that I am reasonably sure is unrelated to this change set. 

Relates to #171 

Co-authored-by: joshua salzedo <thHunkn0WNd@gmail.com>
Co-authored-by: Joshua Salzedo <joshuasalzedo@gmail.com>
theunkn0wn1 added a commit to theunkn0wn1/heapless that referenced this issue Dec 9, 2020
 - defmt has native support for slices, so utilize that.
theunkn0wn1 added a commit to theunkn0wn1/heapless that referenced this issue Dec 9, 2020
 - to conform with other optional features
theunkn0wn1 added a commit to theunkn0wn1/heapless that referenced this issue Dec 9, 2020
@korken89
Copy link
Contributor

Available in 0.7.1

@mehmetalianil
Copy link

I get error: unknown display hint: "[u8]" from:

let mut test_vec: Vec<u8, 128> = Vec::new();
   ... 
info!("the vector: {:[u8]}", test_vec);

Am I mistaken with the format specifier?

@korken89
Copy link
Contributor

korken89 commented Jul 2, 2021

Have you enabled the feature flag?

@theunkn0wn1
Copy link
Contributor Author

In my testing i used {:?} and {=[?]}, which both compile.

        let mut data: Vec<u32, 16> = Vec::new();
        data.push(0x42).expect("Failed to push into vec...");
        data.push(0x50).expect("Failed to push into vec...");
        data.push(0x10).expect("Failed to push into vec...");

        defmt::debug!("Writing data....");
        defmt::info!("{=[?]}", data);
        defmt::debug!("populating string...");
        let string: String<32> = String::from("I like pizza");
        defmt::debug!("Emitting string...");
        defmt::info!("{:?}", string);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants