Skip to content

Commit 10e93ae

Browse files
committed
drivers: i2c: add i2c controller implementation using rp2040 pio
I2C controller that uses PIO on RP2040. Using this we can drive up to 8 I2C busses in addition to the two supported by the built-in i2c peripheral. This driver is adapted from the pico sdk pio i2c example with some changes to fix identified issues. 1. Resetting the input shift register before reading a byte. Sometimes the shift register might get out of sync. 2. Resetting the SM after handling a NAK, related to shift registers counters getting out of sync. 3. Waiting for possible clock stretching when writing the I2C STOP. This is a blocking driver as I found versions interacting with the PIO via interrupts to perform much worse than simply waiting via `k_yield`. The driver attempts to load the PIO code only once in order to allow multiple driver instances to run the same code. It also uses the `reg` property as the SM, instead of relying on pico sdk to arbitrarily assign one, which seems to be the norm for other PIO-based drivers in the codebase. I'll put up a separate PR to do this on the main pio dts nodes and fix-up drivers if people think this is a good idea. Signed-off-by: Yiding Jia <[email protected]>
1 parent c966eac commit 10e93ae

File tree

6 files changed

+624
-2
lines changed

6 files changed

+624
-2
lines changed

drivers/i2c/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ zephyr_library_sources_ifdef(CONFIG_I2C_STM32_V2
104104
)
105105

106106
zephyr_library_sources_ifdef(CONFIG_RENESAS_RA_I2C_IIC i2c_renesas_ra_iic.c)
107+
zephyr_library_sources_ifdef(CONFIG_I2C_RPI_PICO_PIO i2c_rpi_pico_pio.c)
107108

108109
zephyr_library_sources_ifdef(CONFIG_I2C_TEST i2c_test.c)
109110

drivers/i2c/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ config I2C_RV32M1_LPI2C
248248
help
249249
Enable the RV32M1 LPI2C driver.
250250

251+
config I2C_RPI_PICO_PIO
252+
bool "Raspberry Pi Pico PIO based I2C driver"
253+
default y
254+
depends on DT_HAS_RASPBERRYPI_PICO_PIO_I2C_ENABLED
255+
select PICOSDK_USE_PIO
256+
help
257+
Enable the Raspberry Pi Pico PIO I2C driver.
258+
251259
config GPIO_I2C_SWITCH
252260
bool "GPIO controlled I2C bus switch"
253261
default y

0 commit comments

Comments
 (0)