Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ static inline uint _pio_major_instr_bits(uint instr) {
return instr & 0xe000u;
}

static inline uint _pio_arg1(uint instr) {
return (instr >> 5) & 0x7u;
}

static inline uint _pio_encode_instr_and_args(enum pio_instr_bits instr_bits, uint arg1, uint arg2) {
valid_params_if(PIO_INSTRUCTIONS, arg1 <= 0x7);
#if PARAM_ASSERTIONS_ENABLED(PIO_INSTRUCTIONS)
Expand Down
9 changes: 9 additions & 0 deletions src/rp2_common/hardware_pio/pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ static int add_program_at_offset(PIO pio, const pio_program_t *program, uint off
if (rc != 0) return rc;
for (uint i = 0; i < program->length; ++i) {
uint16_t instr = program->instructions[i];
#if PICO_PIO_USE_GPIO_BASE
if (pio_instr_bits_wait == _pio_major_instr_bits(instr) && !((_pio_arg1(instr) & 3u))) {
// wait GIO will include only the 5 lower bits of the GPIO number, so if the GPIO
// base is 16 we need to flip bit 4 (which is equivalent to subtracting 16 from
// the original number 16-47 stored as 16-31 and 0-15)
static_assert(PIO_GPIOBASE_BITS == 16, ""); // only works for gpio base being 0 or 16
instr ^= pio_get_gpio_base(pio);
}
#endif
pio->instr_mem[offset + i] = pio_instr_bits_jmp != _pio_major_instr_bits(instr) ? instr : instr + offset;
}
uint32_t program_mask = (1u << program->length) - 1;
Expand Down
2 changes: 1 addition & 1 deletion tools/pioasm/pio_assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ uint instruction::encode(program &program) {
}
}
// note we store the 6th bit of arg2 above the 16 bits of instruction
return (((uint) raw.type) << 13u) | (((uint) _delay | (uint) _sideset) << 8u) | (raw.arg1 << 5u) | raw.arg2 | ((raw.arg2 >> 5) << 16);
return (((uint) raw.type) << 13u) | (((uint) _delay | (uint) _sideset) << 8u) | (raw.arg1 << 5u) | (raw.arg2 & 0x1fu) | ((raw.arg2 >> 5) << 16);
}

raw_encoding instruction::raw_encode(program& program) {
Expand Down
Loading