From afd1d2008f3fb3fa7a837dd1bdf17a6fecbc57fe Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 24 Nov 2021 19:02:20 -0600 Subject: [PATCH] Small doc/example changes * Use PIO IRQ accessors in PIO I2C example * Update pio/ir_nec/README.adoc file links (#183) The "List of Files" now links (only) to files, not to directories (which prevented this example being included in the C SDK databook) --- i2c/bmp280_i2c/bmp280_i2c.c | 6 ++++-- pio/i2c/i2c.pio | 9 +++++---- pio/i2c/pio_i2c.c | 4 ++-- pio/ir_nec/README.adoc | 25 +++++++++++-------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/i2c/bmp280_i2c/bmp280_i2c.c b/i2c/bmp280_i2c/bmp280_i2c.c index 004608d..c056483 100644 --- a/i2c/bmp280_i2c/bmp280_i2c.c +++ b/i2c/bmp280_i2c/bmp280_i2c.c @@ -117,7 +117,8 @@ void bmp280_read_raw(int32_t* temp, int32_t* pressure) { // note: normal mode does not require further ctrl_meas and config register writes uint8_t buf[6]; - i2c_write_blocking(i2c_default, ADDR, (uint8_t*)REG_PRESSURE_MSB, 1, true); // true to keep master control of bus + uint8_t reg = REG_PRESSURE_MSB; + i2c_write_blocking(i2c_default, ADDR, ®, 1, true); // true to keep master control of bus i2c_read_blocking(i2c_default, ADDR, buf, 6, false); // false - finished with bus // store the 20 bit read in a 32 bit signed integer for conversion @@ -184,7 +185,8 @@ void bmp280_get_calib_params(struct bmp280_calib_param* params) { // and MSB register, so we read from 24 registers uint8_t buf[NUM_CALIB_PARAMS] = { 0 }; - i2c_write_blocking(i2c_default, ADDR, (uint8_t*)REG_DIG_T1_LSB, 1, true); // true to keep master control of bus + uint8_t reg = REG_DIG_T1_LSB; + i2c_write_blocking(i2c_default, ADDR, ®, 1, true); // true to keep master control of bus // read in one go as register addresses auto-increment i2c_read_blocking(i2c_default, ADDR, buf, NUM_CALIB_PARAMS, false); // false, we're done reading diff --git a/pio/i2c/i2c.pio b/pio/i2c/i2c.pio index 8e9fae0..65f3e78 100644 --- a/pio/i2c/i2c.pio +++ b/pio/i2c/i2c.pio @@ -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); diff --git a/pio/i2c/pio_i2c.c b/pio/i2c/pio_i2c.c index 35e0530..ef47e4b 100644 --- a/pio/i2c/pio_i2c.c +++ b/pio/i2c/pio_i2c.c @@ -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) { diff --git a/pio/ir_nec/README.adoc b/pio/ir_nec/README.adoc index 1eaa126..957708b 100644 --- a/pio/ir_nec/README.adoc +++ b/pio/ir_nec/README.adoc @@ -26,20 +26,17 @@ After a successful build the executable program can be found in the **build/ir_l == List of Files CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. -ir_loopback:: A directory containing the code for the loopback example. -CMakeLists.txt::: CMake file to incorporate the example in to the examples build tree. -ir_loopback.c::: The code for the loopback example. -nec_receive_library:: A directory containing the code for the IR receive functions. -CMakeLists.txt::: CMake file to incorporate the IR receive library in to the examples build tree. -nec_receive.c::: The source code for the IR receive functions. -nec_receive.h::: The headers for the IR receive functions. -nec_receive.pio::: The PIO assembler code to receive a frame. -nec_transmit_library:: A directory containing the code for the IR transmit functions. -CMakeLists.txt::: CMake file to incorporate the IR transmit library in to the examples build tree. -nec_transmit.c::: The source code for the IR transmit functions. -nec_transmit.h::: The headers for the IR transmit functions. -nec_carrier_burst.pio::: The PIO assembler code to generate a carrier burst. -nec_carrier_control.pio::: The PIO assembler code to transmit a complete frame. +ir_loopback/CMakeLists.txt:: CMake file to incorporate the loopback example in to the examples build tree. +ir_loopback/ir_loopback.c:: The code for the loopback example. +nec_receive_library/CMakeLists.txt:: CMake file to incorporate the IR receive library in to the examples build tree. +nec_receive_library/nec_receive.c:: The source code for the IR receive functions. +nec_receive_library/nec_receive.h:: The headers for the IR receive functions. +nec_receive_library/nec_receive.pio:: The PIO assembler code to receive a frame. +nec_transmit_library/CMakeLists.txt:: CMake file to incorporate the IR transmit library in to the examples build tree. +nec_transmit_library/nec_transmit.c:: The source code for the IR transmit functions. +nec_transmit_library/nec_transmit.h:: The headers for the IR transmit functions. +nec_transmit_library/nec_carrier_burst.pio:: The PIO assembler code to generate a carrier burst. +nec_transmit_library/nec_carrier_control.pio:: The PIO assembler code to transmit a complete frame. == Bill of Materials