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

Fix encoding of IN instruction with bit_count == 32 w/ tests #60

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fixed encoding of IN instruction with `bit_count` == 32

## [0.2.1] [Crates.io](https://crates.io/crates/pio-rs/0.2.1) [Github](https://github.com/rp-rs/pio-rs/releases/tag/v0.2.1)

- Fixed the search path for `pio_file` when using relative paths
Expand Down
32 changes: 30 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,21 @@ impl InstructionOperands {
*index | (if *relative { 0b10000 } else { 0 }),
)
}
InstructionOperands::IN { source, bit_count } => (*source as u8, *bit_count),
InstructionOperands::IN { source, bit_count } => {
if *bit_count > 32 {
panic!("bit_count must be from 1 to 32");
}
(*source as u8, *bit_count & 0b11111)
}
InstructionOperands::OUT {
destination,
bit_count,
} => (*destination as u8, *bit_count & 0b11111),
} => {
if *bit_count > 32 {
panic!("bit_count must be from 1 to 32");
}
(*destination as u8, *bit_count & 0b11111)
}
InstructionOperands::PUSH { if_full, block } => {
((*if_full as u8) << 1 | (*block as u8), 0)
}
Expand Down Expand Up @@ -963,8 +973,26 @@ fn test_wait_relative_not_used_on_irq() {
}

instr_test!(r#in(InSource::Y, 10), 0b010_00000_010_01010);
instr_test!(r#in(InSource::Y, 32), 0b010_00000_010_00000);

instr_test!(out(OutDestination::Y, 10), 0b011_00000_010_01010);
instr_test!(out(OutDestination::Y, 32), 0b011_00000_010_00000);

#[test]
#[should_panic(expected = "bit_count must be from 1 to 32")]
fn test_in_bit_width_exceeds_max_should_panic() {
let mut a = Assembler::<32>::new();
a.r#in(InSource::Y, 33);
a.assemble_program();
}

#[test]
#[should_panic(expected = "bit_count must be from 1 to 32")]
fn test_out_bit_width_exceeds_max_should_panic() {
let mut a = Assembler::<32>::new();
a.out(OutDestination::X, 33);
a.assemble_program();
}

instr_test!(push(true, false), 0b100_00000_010_00000);
instr_test!(push(false, true), 0b100_00000_001_00000);
Expand Down
Loading