Skip to content

Correct return values for I2C::write(int, const char*, int, bool) #3827

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

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions drivers/I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class I2C {
* @param repeated Repeated start, true - do not send stop at end
*
* @returns
* 0 or non-zero - written number of bytes,
* negative - I2C_ERROR_XXX status
* 0 on success (ack),
* non-0 on failure (nack)
Copy link
Contributor

Choose a reason for hiding this comment

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

I recall this was updated not that long ago. Is a positive number really a failure?

This came from i2c HAL write that specifies the following:

`/** Blocking sending data
 *
 *  @param obj     The I2C object
 *  @param address 7-bit address (last bit is 0)
 *  @param data    The buffer for sending
 *  @param length  Number of bytes to write
 *  @param stop    Stop to be generated after the transfer is done
 *  @return 
 *      zero or non-zero - Number of written bytes
 *      negative - I2C_ERROR_XXX status
 */
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop);

How many targets do follow this new update? how does it map to the current one?

Copy link
Contributor Author

@betzw betzw Feb 23, 2017

Choose a reason for hiding this comment

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

Well, there a two different methods/functions: one is
method I2C::write(int, const char*, int, bool) declared in drivers/I2C.h,
the other one is
function i2c_write(i2c_t*, int, const char, int, int) declared in hal/i2c_api.h.

Method I2C::write(int, const char*, int, bool) uses function i2c_write(i2c_t*, int, const char, int, int) to implement its functionality (see here, especially line #66).

In particular note that the return value of method I2C::write(int, const char*, int, bool) is computed in this line ... and is different from the return value of function i2c_write(i2c_t*, int, const char, int, int)!

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks, that explains it

*/
int write(int address, const char *data, int length, bool repeated = false);

Expand Down