Skip to content

Commit

Permalink
Use PIO IRQ accessors in PIO I2C example (raspberrypi#164)
Browse files Browse the repository at this point in the history
* Use PIO IRQ accessors in PIO I2C example
  • Loading branch information
Wren6991 authored Nov 19, 2021
1 parent fb96fad commit 498caed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions pio/i2c/i2c.pio
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ static inline void i2c_program_init(PIO pio, uint sm, uint offset, uint pin_sda,
gpio_set_oeover(pin_scl, GPIO_OVERRIDE_INVERT);
pio_sm_set_pins_with_mask(pio, sm, 0, both_pins);

// Clear IRQ flag before starting
hw_clear_bits(&pio->inte0, 1u << sm);
hw_clear_bits(&pio->inte1, 1u << sm);
pio->irq = 1u << sm;
// Clear IRQ flag before starting, and make sure flag doesn't actually
// assert a system-level interrupt (we're using it as a status flag)
pio_set_irq0_source_enabled(pio, pis_interrupt0 + sm, false);
pio_set_irq1_source_enabled(pio, pis_interrupt0 + sm, false);
pio_interrupt_clear(pio, sm);

// Configure and start SM
pio_sm_init(pio, sm, offset + i2c_offset_entry_point, &c);
Expand Down
4 changes: 2 additions & 2 deletions pio/i2c/pio_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const int PIO_I2C_NAK_LSB = 0;


bool pio_i2c_check_error(PIO pio, uint sm) {
return !!(pio->irq & (1u << sm));
return pio_interrupt_get(pio, sm);
}

void pio_i2c_resume_after_error(PIO pio, uint sm) {
pio_sm_drain_tx_fifo(pio, sm);
pio_sm_exec(pio, sm, (pio->sm[sm].execctrl & PIO_SM0_EXECCTRL_WRAP_BOTTOM_BITS) >> PIO_SM0_EXECCTRL_WRAP_BOTTOM_LSB);
pio->irq = 1u << sm;
pio_interrupt_clear(pio, sm);
}

void pio_i2c_rx_enable(PIO pio, uint sm, bool en) {
Expand Down

0 comments on commit 498caed

Please sign in to comment.