Use PIO IRQ accessors in PIO I2C example (#164)

* Use PIO IRQ accessors in PIO I2C example
This commit is contained in:
Luke Wren 2021-11-19 20:22:52 +00:00 committed by GitHub
parent fb96fad5a5
commit 498caedd1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -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); gpio_set_oeover(pin_scl, GPIO_OVERRIDE_INVERT);
pio_sm_set_pins_with_mask(pio, sm, 0, both_pins); pio_sm_set_pins_with_mask(pio, sm, 0, both_pins);
// Clear IRQ flag before starting // Clear IRQ flag before starting, and make sure flag doesn't actually
hw_clear_bits(&pio->inte0, 1u << sm); // assert a system-level interrupt (we're using it as a status flag)
hw_clear_bits(&pio->inte1, 1u << sm); pio_set_irq0_source_enabled(pio, pis_interrupt0 + sm, false);
pio->irq = 1u << sm; pio_set_irq1_source_enabled(pio, pis_interrupt0 + sm, false);
pio_interrupt_clear(pio, sm);
// Configure and start SM // Configure and start SM
pio_sm_init(pio, sm, offset + i2c_offset_entry_point, &c); pio_sm_init(pio, sm, offset + i2c_offset_entry_point, &c);

View File

@ -13,13 +13,13 @@ const int PIO_I2C_NAK_LSB = 0;
bool pio_i2c_check_error(PIO pio, uint sm) { 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) { void pio_i2c_resume_after_error(PIO pio, uint sm) {
pio_sm_drain_tx_fifo(pio, 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_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) { void pio_i2c_rx_enable(PIO pio, uint sm, bool en) {