Skip to content

nrf52/i2c: adapt to new I2C API#9334

Merged
aabadie merged 1 commit intoRIOT-OS:new_i2c_iffrom
dylad:i2c_if_nrf52
Jun 13, 2018
Merged

nrf52/i2c: adapt to new I2C API#9334
aabadie merged 1 commit intoRIOT-OS:new_i2c_iffrom
dylad:i2c_if_nrf52

Conversation

@dylad
Copy link
Copy Markdown
Member

@dylad dylad commented Jun 12, 2018

Contribution description

This PR adapts NRF52 I2C driver to the new API.
it has been tested with ADXL345 and nrf52dk board.

Issues/PRs references

#6577

@dylad dylad added the TF: I2C Marks issues and PRs related to the work of the I²C rework task force label Jun 12, 2018
Copy link
Copy Markdown
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

Good job @dylad! If I find time, I can test on nrf52dk.

#include <errno.h>

#include "cpu.h"
#include "periph_conf.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this include is required

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is, for initialize pins and speed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh I removed this include and this still compiles...
Looks like I can remove it then.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's weird btw. Maybe this include should be added to i2c.h, this is also the case for spi, uart, etc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probably, but I think we can leave it as it right now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The periph_conf.h is usually include indirectly via cpu.h and periph_cpu.h

NRF_TWIM_Type *dev; /**< TWIM hardware device */
uint8_t scl; /**< SCL pin */
uint8_t sda; /**< SDA pin */
i2c_speed_t speed;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not documented


return 0;
bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Enabled;
return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return is not needed

return i2c_read_bytes(bus, addr, data, 1);
assert((dev < I2C_NUMOF) && data && (len > 0) && (len < 255));

if(flags & (I2C_NOSTART | I2C_REG16 | I2C_ADDR10)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

missing space after if and why I2C_NOSTART is not supported ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I2C_NOSTART is NOT supported on this platform because of the way the hardware is designed. Unfortunately, when you give your data pointer and the length to the dedicated register, you cannot change this data pointer without issuing a repeated start.
nRF52 TWI hardware is very limited.

assert((bus < I2C_NUMOF) && data && (len > 0) && (len < 256));
assert((dev < I2C_NUMOF) && data && (len > 0) && (len < 256));

if(flags & (I2C_NOSTART | I2C_REG16 | I2C_ADDR10)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

missing space after if

return finish(bus, len);
}
if (!(flags & I2C_NOSTOP)) {
bus(dev)->SHORTS = TWIM_SHORTS_LASTRX_STOP_Msk;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

extra space after =

assert((bus < I2C_NUMOF) && data && (len > 0) && (len < 256));
assert((dev < I2C_NUMOF) && data && (len > 0) && (len < 256));

if(flags & (I2C_NOSTART | I2C_REG16 | I2C_ADDR10)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

space after if

assert((bus < I2C_NUMOF) && data && (len > 0) && (len < 256));
assert((dev < I2C_NUMOF) && data && (len > 0) && (len < 256));

if(flags & (I2C_NOSTART | I2C_REG16 | I2C_ADDR10)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

space

@dylad
Copy link
Copy Markdown
Member Author

dylad commented Jun 13, 2018

Thanks for the review @aabadie ! I'll fix asap.

@dylad
Copy link
Copy Markdown
Member Author

dylad commented Jun 13, 2018

@aabadie I've addressed your comments

.dev = NRF_TWIM1,
.scl = 28,
.sda = 29
.sda = 29,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it would be better to use P0.27 for scl and P0.28 for sda, at least for nrf52dk. This way I2C is mapped to the Arduino compatible pinout.
Using P0.28 and P0.29 is also conflicting with Arduino Analog pins.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it would be better to use P0.27 for scl and P0.28 for sda

You mean P0.26 & P0.27 right ? Guess this is not harmful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You mean P0.26 & P0.27 right ?

Yes, sorry

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

Tested with hts221 (from #9298) and works.

ACK, please squash

@dylad
Copy link
Copy Markdown
Member Author

dylad commented Jun 13, 2018

Squashed

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Jun 13, 2018

All green, let's move forward.

@aabadie aabadie merged commit 8db612a into RIOT-OS:new_i2c_if Jun 13, 2018
basilfx pushed a commit to basilfx/RIOT that referenced this pull request Jul 10, 2018
dylad pushed a commit to dylad/RIOT that referenced this pull request Jul 10, 2018
dylad pushed a commit that referenced this pull request Jul 11, 2018
nrf52/i2c: adapt to new I2C API
@dylad dylad deleted the i2c_if_nrf52 branch May 8, 2019 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

TF: I2C Marks issues and PRs related to the work of the I²C rework task force

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants