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/ads101x: update I2C API #9165

Merged
merged 2 commits into from
Jul 5, 2018

Conversation

ZetaR60
Copy link
Contributor

@ZetaR60 ZetaR60 commented May 23, 2018

This is a WIP update to ads101x's I2C API usage. Currently untested due to lack of API update to atmega_common. See also: #6577 and #9162

@ZetaR60 ZetaR60 mentioned this pull request May 23, 2018
47 tasks
@ZetaR60 ZetaR60 changed the base branch from master to new_i2c_if May 23, 2018 03:18
@ZetaR60 ZetaR60 changed the base branch from new_i2c_if to master May 23, 2018 03:19
@ZetaR60
Copy link
Contributor Author

ZetaR60 commented May 23, 2018

I may need to rebase this on new_i2c_if

@ZetaR60 ZetaR60 mentioned this pull request May 23, 2018
24 tasks
@dylad
Copy link
Member

dylad commented May 23, 2018

Hi @ZetaR60
Thanks for your PR. Unfortunately this PR cannot go to the master branch. It belongs to the new_i2c_if branch.
Once all the job will be done in new_i2c_if branch, the whole branch will be merge to master.
We're doing this way to prevent the CI from complaining.

@ZetaR60 ZetaR60 force-pushed the RIOT_ads101x_i2c_api branch from f2894ab to 27b43dd Compare May 23, 2018 07:40
@ZetaR60 ZetaR60 changed the base branch from master to new_i2c_if May 23, 2018 07:40
@ZetaR60
Copy link
Contributor Author

ZetaR60 commented May 23, 2018

@dylad I just had to rebase this on new_i2c_if, because switching it over brought a bunch of stuff from master with it. Should be good now.

@dylad dylad added the TF: I2C Marks issues and PRs related to the work of the I²C rework task force label May 23, 2018
@dylad
Copy link
Member

dylad commented May 23, 2018

@ZetaR60 After some offline discussions, we update the API a bit.
Now the API is merged so this should not move anymore. (see #9162)

@ZetaR60
Copy link
Contributor Author

ZetaR60 commented May 23, 2018

Should be up to date again.

Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

Changes look good but I'm not convinced by the NOSTOP flag. I don't think they are required.

if (i2c_init_master(i2c, I2C_SPEED) < 0) {

/* Register read test */
if (i2c_read_regs(i2c, addr, ADS101X_CONF_ADDR, &regs, 2, I2C_NOSTOP)
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any reason here to have a NOSTOP flag. (same at other place in the code)
It's not forbidden to read some regs send a STOP and then send data into another register.

@@ -127,22 +134,21 @@ int ads101x_read_raw(const ads101x_t *dev, int16_t *raw)
i2c_acquire(I2C);

/* Read control register */
i2c_read_regs(I2C, ADDR, ADS101X_CONF_ADDR, &regs, 2);
Copy link
Member

Choose a reason for hiding this comment

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

NOSTOP required ?

Copy link
Member

Choose a reason for hiding this comment

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

why should it be required?

@@ -103,7 +110,7 @@ int ads101x_set_mux_gain(const ads101x_t *dev, uint8_t mux_gain)

i2c_acquire(I2C);

i2c_read_regs(I2C, ADDR, ADS101X_CONF_ADDR, &regs, 2);
Copy link
Member

Choose a reason for hiding this comment

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

NOSTOP required ?

i2c_write_regs(i2c, addr, ADS101X_CONF_ADDR, &regs, 2);
i2c_read_regs(i2c, addr, ADS101X_CONF_ADDR, &regs, 2);
/* Register write test */
if (i2c_write_regs(i2c, addr, ADS101X_CONF_ADDR, &regs, 2, I2C_NOSTOP)
Copy link
Member

Choose a reason for hiding this comment

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

same here, is the NOSTOP really useful ?

@ZetaR60
Copy link
Contributor Author

ZetaR60 commented May 24, 2018

NOSTOPs removed.

@mali
Copy link
Contributor

mali commented May 25, 2018

@ZetaR60 , I'll push an atmega_common api update (WIP) soon. So you'll be able to test.

@mali
Copy link
Contributor

mali commented May 29, 2018

@ZetaR60 you can try with this branch https://github.com/mali/RIOT/tree/atmega_new_i2c_if
It's based on the last API changes. It builds but last changes are untested as I'm waiting for an i2c sensor. Keep me informed !

@ZetaR60
Copy link
Contributor Author

ZetaR60 commented May 30, 2018

@mali I am not seeing the changes to periph/i2c.c: https://github.com/mali/RIOT/blob/atmega_new_i2c_if/cpu/atmega_common/periph/i2c.c

@mali
Copy link
Contributor

mali commented May 30, 2018

Oups .. sorry, it seems I've done something wrong :-/

@mali
Copy link
Contributor

mali commented May 30, 2018

It's repaired ! see also #9252

@ZetaR60 ZetaR60 force-pushed the RIOT_ads101x_i2c_api branch from b8dc0a3 to c27f689 Compare May 31, 2018 02:39
@ZetaR60
Copy link
Contributor Author

ZetaR60 commented May 31, 2018

I tried tests/driver_ads101x with #9252 and got this error (debug enabled for ads101x and gpio.c):

[liveuser@localhost-live driver_ads101x]$ make BOARD=mega-xplained term
/home/liveuser/Desktop/RIOT_ads101x_i2c_api_merge/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -b "9600"
No handlers could be found for logger "root"
2018-05-30 23:06:06,059 - INFO # Connect to serial port /dev/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
2018-05-30 23:06:07,891 - INFO # 

2018-05-30 23:06:07,987 - INFO # main(): This is RIOT! (Version: 2018.07-devel-274-gf8bc-localhost-live-RIOT_ads101x_i2c_api)
2018-05-30 23:06:08,035 - INFO # ADS101X analog to digital driver test application
2018-05-30 23:06:08,035 - INFO # 
2018-05-30 23:06:08,131 - INFO # Initializing ADS101x analog to digital at I2C_DEV(0)... START condition transmitted
2018-05-30 23:06:08,147 - INFO # I2C Status is: START
2018-05-30 23:06:08,179 - INFO # ADDRESS and FLAG transmitted
2018-05-30 23:06:08,211 - INFO # NACK has been received for ADDRESS
2018-05-30 23:06:08,243 - INFO # STOP condition transmitted
2018-05-30 23:06:08,291 - INFO # [ads101x] init - error: unable to read reg 1
2018-05-30 23:06:08,291 - INFO # [Failed]
/exit
2018-05-30 23:06:11,546 - INFO # Exiting Pyterm
[liveuser@localhost-live driver_ads101x]$

I will continue investigation tomorrow.

@ZetaR60
Copy link
Contributor Author

ZetaR60 commented Jun 2, 2018

The specific NACK received is 0x20. I have not been able to track down the problem yet. The odd thing is that trunk has almost the same execution path as the new code, but trunk works fine and the new code is failing. The main difference is moving i2c_init, but moving this back to ads101x.c does not fix the problem.

@aabadie aabadie added the Area: drivers Area: Device drivers label Jun 3, 2018
smlng
smlng previously requested changes Jun 28, 2018
if (i2c_init_master(i2c, I2C_SPEED) < 0) {

/* Register read test */
if (i2c_read_regs(i2c, addr, ADS101X_CONF_ADDR, &regs, 2, 0x0)
Copy link
Member

Choose a reason for hiding this comment

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

I mostly saw a simple 0 for the flags in other places, IMHO we should stick to one style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use 0 for defaults that are numerical, 0x0 for bit fields, and NULL for pointers. This is consistent with my prior work. IMO asking for developers to conform to a community standard for such detailed stylistic choices is burdensome without significant benefit.

Copy link
Member

Choose a reason for hiding this comment

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

agreed, maybe the (most) correct way would be to use the I2C_FLAG_NONE to explicitly state that no flag should be set or used here. But we could leave that to a cleanup PR over all drivers and stuff later on.

@smlng smlng dismissed their stale review June 28, 2018 18:04

no valid

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2017 OTA keys S.A.
* 2018 Matthew Blue <[email protected]>
* 2018 Acutam Automation, LLC
Copy link
Member

Choose a reason for hiding this comment

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

unrelated, and unclear why? Here and other files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have transferred my copyrights on RIOT code from myself (Matthew Blue) to my company (Acutam Automation, LLC). I figured it was a minor enough change that it did not require a separate PR, or detailed explanation.

Copy link
Member

Choose a reason for hiding this comment

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

ah okay, sorry was confused by GitHub username vs author name, never mind.

@dylad
Copy link
Member

dylad commented Jul 4, 2018

@ZetaR60 atmega I2C driver has been merge, do you think you can re-test this PR ?

@ZetaR60 ZetaR60 force-pushed the RIOT_ads101x_i2c_api branch from 6a3dd3d to fa183d0 Compare July 4, 2018 16:41
@ZetaR60
Copy link
Contributor Author

ZetaR60 commented Jul 4, 2018

Rebased to pick up ATmega changes.

@ZetaR60
Copy link
Contributor Author

ZetaR60 commented Jul 4, 2018

Everything looks okay. Let me know when to squash.

user@user ~/Desktop/RIOT_ads101x_i2c_api/tests/driver_ads101x $ make BOARD=mega-xplained term
/home/user/Desktop/RIOT_ads101x_i2c_api/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -b "9600"
2018-07-04 13:07:06,775 - INFO # Connect to serial port /dev/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
2018-07-04 13:07:08,696 - INFO #  

2018-07-04 13:07:08,776 - INFO # main(): This is RIOT! (Version: 2018.07-devel-409-gd2631-user-RIOT_ads101x_i2c_api)
2018-07-04 13:07:08,840 - INFO # ADS101X analog to digital driver test application
2018-07-04 13:07:08,840 - INFO # 
2018-07-04 13:07:08,904 - INFO # Initializing ADS101x analog to digital at I2C_DEV(0)... [OK]
2018-07-04 13:07:08,952 - INFO # Initializing ADS101x alert at I2C_DEV(0)... [OK]
2018-07-04 13:07:08,984 - INFO # Enabling alert interrupt: [OK]
2018-07-04 13:07:09,064 - INFO # Raw analog read. CH0: 5456 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:09,192 - INFO # Raw analog read. CH0: 5584 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:09,320 - INFO # Raw analog read. CH0: 5488 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:09,432 - INFO # Raw analog read. CH0: 5536 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:09,560 - INFO # Raw analog read. CH0: 5616 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:09,672 - INFO # Raw analog read. CH0: 5536 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:09,800 - INFO # Raw analog read. CH0: 5472 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:09,928 - INFO # Raw analog read. CH0: 5440 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:10,040 - INFO # Raw analog read. CH0: 5616 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:10,167 - INFO # Raw analog read. CH0: 5520 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:10,279 - INFO # Raw analog read. CH0: 5520 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:10,407 - INFO # Raw analog read. CH0: 5536 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:10,535 - INFO # Raw analog read. CH0: 5584 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:10,647 - INFO # Raw analog read. CH0: 5632 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:10,775 - INFO # Raw analog read. CH0: 5488 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:10,887 - INFO # Raw analog read. CH0: 5600 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:11,034 - INFO # Raw analog read. CH0: 5520 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:11,143 - INFO # Raw analog read. CH0: 5568 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:11,255 - INFO # Raw analog read. CH0: 5488 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:11,383 - INFO # Raw analog read. CH0: 5504 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:11,495 - INFO # Raw analog read. CH0: 5616 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:11,623 - INFO # Raw analog read. CH0: 5488 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:11,751 - INFO # Raw analog read. CH0: 5632 CH1: 18800 CH2: 32752 CH3: 32752
2018-07-04 13:07:11,863 - INFO # Raw analog read. CH0: 5472 CH1: 18800 CH2: 32752 CH3: 32752

Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

ACK
Please squash

@ZetaR60 ZetaR60 force-pushed the RIOT_ads101x_i2c_api branch from d2631ed to 8ab0579 Compare July 5, 2018 16:21
@ZetaR60
Copy link
Contributor Author

ZetaR60 commented Jul 5, 2018

Squashed. Thanks for the help!

@dylad
Copy link
Member

dylad commented Jul 5, 2018

Here we go !

@dylad dylad merged commit 43c4547 into RIOT-OS:new_i2c_if Jul 5, 2018
basilfx pushed a commit to basilfx/RIOT that referenced this pull request Jul 10, 2018
dylad added a commit to dylad/RIOT that referenced this pull request Jul 10, 2018
dylad added a commit that referenced this pull request Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers 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.

5 participants