Skip to content

Commit afd1d20

Browse files
authored
Small doc/example changes
* Use PIO IRQ accessors in PIO I2C example * Update pio/ir_nec/README.adoc file links (raspberrypi#183) The "List of Files" now links (only) to files, not to directories (which prevented this example being included in the C SDK databook)
1 parent 188d849 commit afd1d20

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

i2c/bmp280_i2c/bmp280_i2c.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ void bmp280_read_raw(int32_t* temp, int32_t* pressure) {
117117
// note: normal mode does not require further ctrl_meas and config register writes
118118

119119
uint8_t buf[6];
120-
i2c_write_blocking(i2c_default, ADDR, (uint8_t*)REG_PRESSURE_MSB, 1, true); // true to keep master control of bus
120+
uint8_t reg = REG_PRESSURE_MSB;
121+
i2c_write_blocking(i2c_default, ADDR, &reg, 1, true); // true to keep master control of bus
121122
i2c_read_blocking(i2c_default, ADDR, buf, 6, false); // false - finished with bus
122123

123124
// 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) {
184185
// and MSB register, so we read from 24 registers
185186

186187
uint8_t buf[NUM_CALIB_PARAMS] = { 0 };
187-
i2c_write_blocking(i2c_default, ADDR, (uint8_t*)REG_DIG_T1_LSB, 1, true); // true to keep master control of bus
188+
uint8_t reg = REG_DIG_T1_LSB;
189+
i2c_write_blocking(i2c_default, ADDR, &reg, 1, true); // true to keep master control of bus
188190
// read in one go as register addresses auto-increment
189191
i2c_read_blocking(i2c_default, ADDR, buf, NUM_CALIB_PARAMS, false); // false, we're done reading
190192

pio/i2c/i2c.pio

+5-4
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ static inline void i2c_program_init(PIO pio, uint sm, uint offset, uint pin_sda,
108108
gpio_set_oeover(pin_scl, GPIO_OVERRIDE_INVERT);
109109
pio_sm_set_pins_with_mask(pio, sm, 0, both_pins);
110110

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

116117
// Configure and start SM
117118
pio_sm_init(pio, sm, offset + i2c_offset_entry_point, &c);

pio/i2c/pio_i2c.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ const int PIO_I2C_NAK_LSB = 0;
1313

1414

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

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

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

pio/ir_nec/README.adoc

+11-14
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@ After a successful build the executable program can be found in the **build/ir_l
2626
== List of Files
2727

2828
CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree.
29-
ir_loopback:: A directory containing the code for the loopback example.
30-
CMakeLists.txt::: CMake file to incorporate the example in to the examples build tree.
31-
ir_loopback.c::: The code for the loopback example.
32-
nec_receive_library:: A directory containing the code for the IR receive functions.
33-
CMakeLists.txt::: CMake file to incorporate the IR receive library in to the examples build tree.
34-
nec_receive.c::: The source code for the IR receive functions.
35-
nec_receive.h::: The headers for the IR receive functions.
36-
nec_receive.pio::: The PIO assembler code to receive a frame.
37-
nec_transmit_library:: A directory containing the code for the IR transmit functions.
38-
CMakeLists.txt::: CMake file to incorporate the IR transmit library in to the examples build tree.
39-
nec_transmit.c::: The source code for the IR transmit functions.
40-
nec_transmit.h::: The headers for the IR transmit functions.
41-
nec_carrier_burst.pio::: The PIO assembler code to generate a carrier burst.
42-
nec_carrier_control.pio::: The PIO assembler code to transmit a complete frame.
29+
ir_loopback/CMakeLists.txt:: CMake file to incorporate the loopback example in to the examples build tree.
30+
ir_loopback/ir_loopback.c:: The code for the loopback example.
31+
nec_receive_library/CMakeLists.txt:: CMake file to incorporate the IR receive library in to the examples build tree.
32+
nec_receive_library/nec_receive.c:: The source code for the IR receive functions.
33+
nec_receive_library/nec_receive.h:: The headers for the IR receive functions.
34+
nec_receive_library/nec_receive.pio:: The PIO assembler code to receive a frame.
35+
nec_transmit_library/CMakeLists.txt:: CMake file to incorporate the IR transmit library in to the examples build tree.
36+
nec_transmit_library/nec_transmit.c:: The source code for the IR transmit functions.
37+
nec_transmit_library/nec_transmit.h:: The headers for the IR transmit functions.
38+
nec_transmit_library/nec_carrier_burst.pio:: The PIO assembler code to generate a carrier burst.
39+
nec_transmit_library/nec_carrier_control.pio:: The PIO assembler code to transmit a complete frame.
4340

4441
== Bill of Materials
4542

0 commit comments

Comments
 (0)