Skip to content

Commit 8083dc9

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 ba5971e commit 8083dc9

File tree

6 files changed

+659
-2
lines changed

6 files changed

+659
-2
lines changed

drivers/i2c/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ zephyr_library_sources_ifdef(CONFIG_I2C_NUMAKER i2c_numaker.c)
5151
zephyr_library_sources_ifdef(CONFIG_I2C_OMAP i2c_omap.c)
5252
zephyr_library_sources_ifdef(CONFIG_I2C_RCAR i2c_rcar.c)
5353
zephyr_library_sources_ifdef(CONFIG_I2C_RENESAS_RA_IIC i2c_renesas_ra_iic.c)
54+
zephyr_library_sources_ifdef(CONFIG_I2C_RPI_PICO_PIO i2c_rpi_pico_pio.c)
5455
zephyr_library_sources_ifdef(CONFIG_I2C_RV32M1_LPI2C i2c_rv32m1_lpi2c.c)
5556
zephyr_library_sources_ifdef(CONFIG_I2C_SAM0 i2c_sam0.c)
5657
zephyr_library_sources_ifdef(CONFIG_I2C_SAM_TWI i2c_sam_twi.c)

drivers/i2c/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ config I2C_RV32M1_LPI2C
254254
help
255255
Enable the RV32M1 LPI2C driver.
256256

257+
config I2C_RPI_PICO_PIO
258+
bool "Raspberry Pi Pico PIO based I2C driver"
259+
default y
260+
depends on DT_HAS_RASPBERRYPI_PICO_PIO_I2C_ENABLED
261+
select PICOSDK_USE_PIO
262+
help
263+
Enable the Raspberry Pi Pico PIO I2C driver.
264+
257265
config GPIO_I2C_SWITCH
258266
bool "GPIO controlled I2C bus switch"
259267
default y

0 commit comments

Comments
 (0)