-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/nrf52: optimized I2C driver #8385
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which setup did you test this? I only gave it a quick try without logic analyzer (nrf52dk + srf02 with tests/driver_srf02). Initialization of the device seems successful. Single shot or periodic sampling directly hangs
cpu/nrf52/periph/i2c.c
Outdated
|
||
/* shortcuts configuration */ | ||
dev(bus)->SHORTS = (TWIM_SHORTS_LASTTX_STOP_Enabled << TWIM_SHORTS_LASTTX_STOP_Pos) | | ||
(TWIM_SHORTS_LASTRX_STOP_Enabled << TWIM_SHORTS_LASTRX_STOP_Pos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't understand why you remove this initialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shorts are set on-demand in the transfer functions...
cpu/nrf52/periph/i2c.c
Outdated
/* enable the device */ | ||
dev(bus)->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos); | ||
/* configure bus clock speed */ | ||
dev(bus)->FREQUENCY = speed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed the shift because TWIM_ENABLE_ENABLE_Pos
is 0
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
si
|
||
return 0; | ||
} | ||
|
||
int i2c_acquire(i2c_t bus) | ||
{ | ||
assert(bus <= I2C_NUMOF); | ||
assert(bus < I2C_NUMOF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have seen this before :/ ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-)
cpu/nrf52/periph/i2c.c
Outdated
|
||
/* start read sequence */ | ||
dev(bus)->EVENTS_STOPPED = 0; | ||
dev(bus)->ADDRESS = addr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the 7-bit-address mask?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because this way we save one redundant instruction. The ADRESS register does only use the 7 LSB anyway, so no need for manual masking the address.
I tested this mainly with the |
0028118
to
27479aa
Compare
rebased (before I start debugging the |
Thanks for your feedback! |
Thanks for your review! |
27479aa
to
ef6bed1
Compare
found the problem: The I2C driver expected the I will also look at the drivers for |
Great, works now. I'm fine with this PR. Let's wait for #8486 and rebase/squash then |
Perfect. Would you mind to ACK #8486?! |
@haukepetersen please rebase |
This function is supposed to be used for putting the CPU into sleep mode for short amounts of time (e.g. in typical polling loops used in periph drivers).
rebased |
ef6bed1
to
3813f88
Compare
3813f88
to
2b2accf
Compare
and squashed. |
Travis CI fails due to previously set "Waiting For Other PR" flag. How is this machine restarted, only by a new commit? |
As Travis is not needed for a final verdict, I'd say we simply ignore it in this case. |
This needs to be restarted manually. It would be good to remove this check from travis. |
Contribution description
This PR applies some enhancements to the I2C driver for the
nrf52
. It mainly consists of some minor fixes and a little re-structuring for better code re-usage. Further the driver is now using assertions for all API functions.If I saw it correctly, the previous version of the driver had also a problem as it was not using a repeated start condition when reading register(s), this is also fixed now.
Issues/PRs references
none