pio-rs icon indicating copy to clipboard operation
pio-rs copied to clipboard

Encoding of IN with bit_count = 32 is incorrect

Open xeniarose opened this issue 11 months ago • 1 comments

example

use pio::*;
use pio_proc::*;

fn main() {
    let sideset = SideSet::new(false, 0, false);

    let in_example_1 = InstructionOperands::IN {
        source: InSource::Y,
        bit_count: 32,
    }.encode();

    println!("example 1: {:?}", Instruction::decode(in_example_1, sideset));

    let in_example_2 = pio_asm!(
        "in y, 32"
    );

    println!("example 2: {:?}", Instruction::decode(in_example_2.program.code[0], sideset));
}

output

example 1: Some(Instruction { operands: IN { source: NULL, bit_count: 0 }, delay: 0, side_set: None })
example 2: Some(Instruction { operands: IN { source: NULL, bit_count: 0 }, delay: 0, side_set: None })

expected output should contain source: Y instead of source: NULL

the reason is incorrectly encoding the bit_count for IN with the value 32 at https://github.com/rp-rs/pio-rs/blob/42e8c135406ea6fdea51e76076737822a73eea30/src/lib.rs#L236

the correct behavior (*bit_count & 0b11111) is done for OUT, but not for IN

xeniarose avatar Mar 20 '24 22:03 xeniarose

Thanks, @xeniarose, good catch!

jannic avatar Mar 21 '24 07:03 jannic