Skip to content
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/periph_i2c: let i2c_acquire return void #17275

Merged
merged 6 commits into from
Nov 29, 2021

Conversation

gschorcht
Copy link
Contributor

Contribution description

As follow-up of PR #15902 and based on the discussion in issue #10673 this PR

  • changes the signature of int i2c_acquire(...) to void i2c_acquire(...) because
    • all I2C implementations just return 0 and don't check for any error situation
    • most driver implementations don't check the return value
  • adds assert() where it is missing to ensure that a correct I2C device identifier is used
  • updates all implementations
  • updates the few driver implementations that used the return value, but mostly only during <driver>_init().

Testing procedure

Compilation and tests in Murdock should work.

Issues/PRs references

Follow-up of #15902
Fixes #10673

@github-actions github-actions bot added Area: arduino API Area: Arduino wrapper API Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: sys Area: System Area: tests Area: tests and testing framework Platform: ARM Platform: This PR/issue effects ARM-based platforms Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: ESP Platform: This PR/issue effects ESP-based platforms Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms labels Nov 25, 2021
@gschorcht gschorcht removed Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: tests Area: tests and testing framework Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Nov 25, 2021
@gschorcht gschorcht added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 26, 2021
@gschorcht gschorcht force-pushed the drivers/periph_i2c_acquire_void branch 6 times, most recently from 0c466ca to 47d4383 Compare November 26, 2021 07:24
@@ -184,9 +184,13 @@ int lis2dh12_init(lis2dh12_t *dev, const lis2dh12_params_t *params)
/* enable all axes, set sampling rate and scale */
LIS2DH12_CTRL_REG1_t reg1 = {0};

/* cppcheck-suppress unreadVariable; (reason: union type is used for read) */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maribu Here we have no volatile variable definitions, but cppcheck complains anyway. So it looks like cppcheck does not recognize the type unit after all. Missing header files are probably not the problem in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maribu I played a bit with cppcheck and the single file that made the problems using command:

cppcheck --std=c99 --enable=style --force --error-exitcode=2 --quiet -j 1 --inline-suppr \
--suppress=unusedStructMember --template '{file}:{line}: {severity} ({id}): {message}' \
drivers/lis2dh12/lis2dh12.c

cppcheck version 1.82 (local Ubuntu 18.04 LTS version) doesn't show any warnings.
cppcheck version 1.90 in RIOT docker shows these 32 warnings as in CI.
cppcheck version 2.6 (newest version from sourgeforge.net) shows only 5 warnings.

Adding the required include pathes

-I drivers/include -I drivers/lis2dh12/include/

doesn't help with cppcheck version 1.90 but solves all warnings with cppcheck version 2.6.

So it seems that we need correct include pathes as well as a newer cppcheck version in CI.

fifo_reg.bit.FM = LIS2DH12_FIFO_MODE_BYPASS;

/* switch to Bypass mode */
_write(dev, REG_FIFO_CTRL_REG, fifo_reg.reg);

/* cppcheck-suppress redundantAssignment; (reason: union type is used for read) */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maribu Here I don't know how to solve the cppcheck error.

If I use cppcheck-suppress redundantAssignment, cppcheck is complaining about unread variable. If I replace cppcheck-suppress redundantAssignment by cppcheck-suppress unreadVariable, it is complaining about redundant assignment.

How can this be solved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved. I just have to use multiple cppcheck-suppress lines for all different warning that are given here.

@gschorcht
Copy link
Contributor Author

Failed run tests are not related to this PR. Therefore, I remove the CI: run tests label.

@gschorcht gschorcht removed the CI: run tests If set, CI server will run tests on hardware for the labeled PR label Nov 27, 2021
@gschorcht gschorcht force-pushed the drivers/periph_i2c_acquire_void branch from 47d4383 to 3f6024c Compare November 27, 2021 13:43
Since all implementations simply return 0 and most drivers do not check the return value, it is better to return void and use an assert to ensure that the given device identifier and given device parameters are correct.
Make all `spi_acquire` implementations return `void` and add assertions to check for valid device identifier where missing.
@gschorcht gschorcht force-pushed the drivers/periph_i2c_acquire_void branch from 3f6024c to b7dda22 Compare November 29, 2021 05:36
@benpicco benpicco merged commit c84a40a into RIOT-OS:master Nov 29, 2021
@gschorcht
Copy link
Contributor Author

Thanks

@gschorcht gschorcht deleted the drivers/periph_i2c_acquire_void branch November 29, 2021 10:49
@fjmolinas fjmolinas added this to the Release 2022.01 milestone Jan 21, 2022
chrysn added a commit to RIOT-OS/rust-riot-sys that referenced this pull request May 31, 2022
gdoffe added a commit to cogip/mcu-firmware that referenced this pull request Jun 9, 2022
See [1].

[1] RIOT-OS/RIOT#17275

Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
gdoffe added a commit to cogip/mcu-firmware that referenced this pull request Jul 3, 2022
See [1].

[1] RIOT-OS/RIOT#17275

Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
gdoffe added a commit to cogip/mcu-firmware that referenced this pull request Jul 4, 2022
See [1].

[1] RIOT-OS/RIOT#17275

Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
gdoffe added a commit to cogip/mcu-firmware that referenced this pull request Jul 4, 2022
See [1].

[1] RIOT-OS/RIOT#17275

Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: arduino API Area: Arduino wrapper API Area: cpu Area: CPU/MCU ports 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 Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: ESP Platform: This PR/issue effects ESP-based platforms Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Process: needs >1 ACK Integration Process: This PR requires more than one ACK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

periph/i2c: return values of i2c_aquire and i2c_release
4 participants