Skip to content

Conversation

haukepetersen
Copy link
Contributor

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

@haukepetersen haukepetersen added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 19, 2018
Copy link
Member

@PeterKietzmann PeterKietzmann left a 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


/* 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);
Copy link
Member

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.

Copy link
Contributor Author

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...

/* enable the device */
dev(bus)->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
/* configure bus clock speed */
dev(bus)->FREQUENCY = speed;
Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Member

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 :/ ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:-)


/* start read sequence */
dev(bus)->EVENTS_STOPPED = 0;
dev(bus)->ADDRESS = addr;
Copy link
Member

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?

Copy link
Contributor Author

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.

@haukepetersen
Copy link
Contributor Author

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

I tested this mainly with the lis2dh12 and the bmx280 sensors on the ruuvitag. I will also take a look at the srf02 to see whats wrong...

@haukepetersen
Copy link
Contributor Author

rebased (before I start debugging the srf02...).

@PeterKietzmann
Copy link
Member

Thanks for your feedback!

@haukepetersen
Copy link
Contributor Author

Thanks for your review!

@haukepetersen haukepetersen added the State: waiting for other PR State: The PR requires another PR to be merged first label Jan 31, 2018
@haukepetersen
Copy link
Contributor Author

found the problem: The I2C driver expected the acquire function to be called after the init function, while the srf02 driver expected the order the other way around (see #8446 for this issue). So I now fixed the I2C driver to re-enable the i2c device in the end of init_master(). I also reabsed this PR on top of #8486, so the mutex initialization is fixed.

I will also look at the drivers for lis2dh12 and the bmx280, to make sure they use the correct acquire -> init_master order...

@PeterKietzmann
Copy link
Member

Great, works now. I'm fine with this PR. Let's wait for #8486 and rebase/squash then

@haukepetersen
Copy link
Contributor Author

Perfect. Would you mind to ACK #8486?!

@PeterKietzmann
Copy link
Member

@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).
@haukepetersen
Copy link
Contributor Author

rebased

@haukepetersen
Copy link
Contributor Author

and squashed.

@haukepetersen haukepetersen added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: waiting for other PR State: The PR requires another PR to be merged first labels Feb 2, 2018
@PeterKietzmann PeterKietzmann added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 2, 2018
@PeterKietzmann
Copy link
Member

Travis CI fails due to previously set "Waiting For Other PR" flag. How is this machine restarted, only by a new commit?

@haukepetersen
Copy link
Contributor Author

As Travis is not needed for a final verdict, I'd say we simply ignore it in this case.

@aabadie
Copy link
Contributor

aabadie commented Feb 2, 2018

Travis CI fails due to previously set "Waiting For Other PR" flag. How is this machine restarted, only by a new commit?

This needs to be restarted manually. It would be good to remove this check from travis.

@PeterKietzmann PeterKietzmann merged commit b2c1ca8 into RIOT-OS:master Feb 2, 2018
@haukepetersen haukepetersen deleted the opt_nrf52_i2c branch February 2, 2018 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants