-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers/soft_i2c: Add bit-banging I2C using GPIO LL #20333
Open
maribu
wants to merge
5
commits into
RIOT-OS:master
Choose a base branch
from
maribu:drivers/soft_i2c
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,416
−30
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maribu
added
State: WIP
State: The PR is still work-in-progress and its code is not in its final presentable form yet
Type: new feature
The issue requests / The PR implemements a new feature for RIOT
State: waiting for other PR
State: The PR requires another PR to be merged first
CI: ready for build
If set, CI server will compile all applications for all available boards for the labeled PR
labels
Feb 2, 2024
maribu
requested review from
leandrolanzieri,
aabadie,
MichelRottleuthner,
MrKevinWeiss,
vincent-d,
benpicco,
dylad,
keestux,
gschorcht,
basilfx and
kYc0o
as code owners
February 2, 2024 13:21
github-actions
bot
added
Platform: ARM
Platform: This PR/issue effects ARM-based platforms
Area: doc
Area: Documentation
Area: tests
Area: tests and testing framework
Area: build system
Area: Build system
Platform: AVR
Platform: This PR/issue effects AVR-based platforms
Area: drivers
Area: Device drivers
Platform: ESP
Platform: This PR/issue effects ESP-based platforms
Area: cpu
Area: CPU/MCU ports
Area: sys
Area: System
labels
Feb 2, 2024
This implements `i2c_pin_sda()` and `i2c_pin_scl()` as regular C functions instead of preprocessor macros.
This implements a bit-banged I2C bus using GPIO LL either using the `periph_gpio_ll_open_drain` feature or ,as fall-back, using the `periph_gpio_ll_switch_dir` feature. The implementation should work with clock-stretching and arbitration. It should also be able to detect a locked bus and recover from it.
With the new feature it should be possible to just use a software I2C bus instead of a `periph_i2c` using the same APIs. I tested this using the following patch using an SHT3X breakout board connected to an nRF52840-DK: ```diff --- a/tests/drivers/sht3x/Makefile +++ b/tests/drivers/sht3x/Makefile @@ -2,4 +2,19 @@ include ../Makefile.drivers_common USEMODULE += sht3x +PIN_SCL ?= GPIO_PIN(0,27) +PIN_SDA ?= GPIO_PIN(0,26) + +ifneq (,$(PIN_SCL)) + CFLAGS += "-DSOFT_I2C_PARAM_SCL=$(PIN_SCL)" +endif +ifneq (,$(PIN_SDA)) + CFLAGS += "-DSOFT_I2C_PARAM_SDA=$(PIN_SDA)" +endif + +USEMODULE += soft_i2c +USEMODULE += soft_i2c_as_periph_i2c + +CFLAGS += "-DSHT3X_PARAM_I2C_ADDR=SHT3X_I2C_ADDR_1" + include $(RIOTBASE)/Makefile.include ```
Just passing the flag `SOFT_I2C=` while building will use the software I2C bus instead of the hardware I2C bus.
maribu
force-pushed
the
drivers/soft_i2c
branch
from
February 5, 2024 14:27
8fd5df7
to
63f7c2d
Compare
github-actions
bot
removed
Platform: AVR
Platform: This PR/issue effects AVR-based platforms
Platform: ESP
Platform: This PR/issue effects ESP-based platforms
labels
Feb 5, 2024
benpicco
removed
the
State: waiting for other PR
State: The PR requires another PR to be merged first
label
Feb 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Area: build system
Area: Build system
Area: cpu
Area: CPU/MCU ports
Area: doc
Area: Documentation
Area: drivers
Area: Device drivers
Area: sys
Area: System
Area: tests
Area: tests and testing framework
CI: ready for build
If set, CI server will compile all applications for all available boards for the labeled PR
Platform: ARM
Platform: This PR/issue effects ARM-based platforms
State: WIP
State: The PR is still work-in-progress and its code is not in its final presentable form yet
Type: new feature
The issue requests / The PR implemements a new feature for RIOT
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution description
This implements a bit-banged I2C bus using GPIO LL either using the
periph_gpio_ll_open_drain
feature or ,as fall-back, using theperiph_gpio_ll_switch_dir
feature.The implementation should work with clock-stretching and arbitration. It should also be able to detect a locked bus and recover from it.
A pseudomodule
soft_i2c_as_periph_i2c
is added to allow thesoft_i2c
providing theperiph_i2c
API.Testing procedure
I tested this using the following patch using an SHT3X breakout board connected to an nRF52840-DK:
Capture with a Logic Analyzer
Console output
Beware: This has not been tested on boards that have no open drain GPIOs but implement
periph_gpio_ll_switch_dir
. I'll add that in time.Issues/PRs references
Depends on and includes: