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

Commitf341755

Browse files
committed
Wire: fix bug on read() backing storage
The ringbuffer backing storage and the read buffer were the same buffer...memcpy over the same location has some nasty implicationsTODO: move to more complex APIs (like i2c_transfer) to properly implement stop bit
1 parenta3fa5b8 commitf341755

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎libraries/Wire/Wire.cpp‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ uint8_t arduino::ZephyrI2C::endTransmission(void) { // TODO for ADS1115
6363

6464
size_tarduino::ZephyrI2C::requestFrom(uint8_t address,size_t len,
6565
bool stopBit) {
66-
int ret =i2c_read(i2c_dev, rxRingBuffer.buffer, len, address);
66+
uint8_t buf[len];
67+
int ret =i2c_read(i2c_dev, buf, len, address);
6768
if (ret !=0)
6869
{
6970
return0;
7071
}
71-
ret =ring_buf_put(&rxRingBuffer.rb,rxRingBuffer.buffer, len);
72+
ret =ring_buf_put(&rxRingBuffer.rb,buf, len);
7273
if (ret ==0)
7374
{
7475
return0;
@@ -96,19 +97,19 @@ size_t arduino::ZephyrI2C::write(const uint8_t *buffer, size_t size) {
9697

9798
intarduino::ZephyrI2C::read() {
9899
uint8_t buf[1];
99-
if (ring_buf_peek(&rxRingBuffer.rb, buf,1) >0) {
100+
if (ring_buf_size_get(&rxRingBuffer.rb)) {
100101
int ret =ring_buf_get(&rxRingBuffer.rb, buf,1);
101102
if (ret ==0) {
102-
return0;
103+
return-1;
103104
}
104105
return (int)buf[0];
105106
}
106-
returnEXIT_FAILURE;
107+
return-1;
107108
}
108109

109-
intarduino::ZephyrI2C::available() {// TODO for ADS1115
110-
returnring_buf_size_get(&rxRingBuffer.rb);// ret 0 if empty
111-
}
110+
intarduino::ZephyrI2C::available() {
111+
returnring_buf_size_get(&rxRingBuffer.rb);
112+
}
112113

113114
intarduino::ZephyrI2C::peek() {
114115
uint8_t buf[1];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp