How can I solve "expected value, found struct `pac::PORTB`"

I'm trying to write the typical "hello world" for a microcontroller, an attiny85 in my case. As a newbie to rust, I'm struggling a bit. This is what I have:


use attiny_hal::{

pub extern fn main() {
    let mut delay = delay::Delay::<clock::MHz20>::new();

    let mut pins = Pins::new(pac::PORTB);
    let mut pb = pins.pb0.into_output();

    loop {

I get this compiler error:

error[E0423]: expected value, found struct `pac::PORTB`
   --> src/
17  |     let mut pins = Pins::new(pac::PORTB);
    |                              ^^^^^^^^^^
   ::: /home/markus/.cargo/registry/src/
235 | pub struct PORTB {
    | ---------------- `pac::PORTB` defined here
help: use struct literal syntax instead
17  |     let mut pins = Pins::new(pac::PORTB { _marker: val });
    |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: consider importing this unit variant instead
4   | use attiny_hal::port::DynamicPort::PORTB;
help: if you import `PORTB`, refer to it directly
17  -     let mut pins = Pins::new(pac::PORTB);
17  +     let mut pins = Pins::new(PORTB);

Unfortunately, I don't get all the help the compiler is offering me :frowning:

I understand that the struct PORTB is not what port::Pins expects as a parameter. But the first help doesn't compile, neither does the second one: attiny_hal::port::DynamicPort::PORTB is an enum, not an instance of the PORTB structure....

It guess it's totally simple and only my rookieness is in my way... It would be great if you could help me.


I’m unfamiliar with the crate, but at a glance, it looks like your entry point should be via Periphals::take, which gives back a struct that contains, among other things a PORTB value.

Huh, isn't it singularly unhelpful to advise passing DynamicPort::PORTB to the function given that the types obviously don't match? Might be worth opening an issue if there isn't one already…

Thanks, that solved it :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.