Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf52acd

Browse files
committed
Fix Wire endTransmission() return convention
Fixes#40
1 parent406ef88 commitbf52acd

File tree

1 file changed

+20
-4
lines changed
  • libraries/Wire/src/utility

1 file changed

+20
-4
lines changed

‎libraries/Wire/src/utility/twi.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,11 @@ uint8_t TWI_MasterRead(uint8_t slave_address,
270270
* \param bytesToWrite Number of bytes to write.
271271
* \param bytesToRead Number of bytes to read.
272272
*
273-
* \retval true If transaction could be started.
274-
* \retval false If transaction could not be started.
273+
* \retval 0:success
274+
* \retval 1:data too long to fit in transmit buffer
275+
* \retval 2:received NACK on transmit of address
276+
* \retval 3:received NACK on transmit of data
277+
* \retval 4:other error
275278
*/
276279
uint8_tTWI_MasterWriteRead(uint8_tslave_address,
277280
uint8_t*write_data,
@@ -335,8 +338,21 @@ uint8_t TWI_MasterWriteRead(uint8_t slave_address,
335338
// return bytes really read
336339
ret=master_bytesRead;
337340
}else {
338-
// return 0 if success, >0 otherwise
339-
ret= (master_result==TWIM_RESULT_OK ?0 :1);
341+
// return 0 if success, >0 otherwise (follow classic AVR conventions)
342+
switch (master_result) {
343+
caseTWIM_RESULT_OK:
344+
ret=0;
345+
break;
346+
caseTWIM_RESULT_BUFFER_OVERFLOW:
347+
ret=1;
348+
break;
349+
caseTWIM_RESULT_NACK_RECEIVED:
350+
ret=3;
351+
break;
352+
default:
353+
ret=4;
354+
break;
355+
}
340356
}
341357

342358
returnret;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp