Skip to content

Commit b11b1be

Browse files
committed
Eliminate pointer to read buffer from IO response, therefore making the necessity of keeping the read buffer on the stack in scope more visible.
1 parent 8ef1d71 commit b11b1be

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

ThreadsafeIO/examples/ts_spi/ts_spi.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ byte bmp388_read_reg(byte const reg_addr)
9494

9595
rsp->wait();
9696

97-
return rsp->read_buf[2];
97+
return read_buf[2];
9898
}
9999

100100
void bmp388_thread_func()

ThreadsafeIO/examples/ts_wire/ts_wire.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void setup()
5050

5151
void loop()
5252
{
53-
rtos::ThisThread::sleep_for(10);
53+
5454
}
5555

5656
/**************************************************************************************
@@ -72,7 +72,7 @@ byte lsm6dsox_read_reg(byte const reg_addr)
7272

7373
rsp->wait();
7474

75-
return rsp->read_buf[0];
75+
return read_buf;
7676
}
7777

7878

ThreadsafeIO/src/IoTransaction.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,13 @@ class IoResponse
5252
{
5353
public:
5454

55-
IoResponse(uint8_t * read_buf_)
56-
: read_buf{read_buf_}
57-
, bytes_written{0}
55+
IoResponse()
56+
: bytes_written{0}
5857
, bytes_read{0}
5958
, _cond{_mutex}
6059
, _is_done{false}
6160
{ }
6261

63-
uint8_t * read_buf{nullptr};
6462
size_t bytes_written{0};
6563
size_t bytes_read{0};
6664

ThreadsafeIO/src/spi/SpiDispatcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ IoResponse SpiDispatcher::dispatch(IoRequest * req, SpiBusDeviceConfig * config)
6262
if (!spi_io_transaction)
6363
return nullptr;
6464

65-
IoResponse rsp(new impl::IoResponse{req->read_buf});
65+
IoResponse rsp(new impl::IoResponse());
6666

6767
spi_io_transaction->req = req;
6868
spi_io_transaction->rsp = rsp;

ThreadsafeIO/src/wire/WireDispatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ IoResponse WireDispatcher::dispatch(IoRequest * req, WireBusDeviceConfig * confi
6262
if (!wire_io_transaction)
6363
return nullptr;
6464

65-
IoResponse rsp(new impl::IoResponse{req->read_buf});
65+
IoResponse rsp(new impl::IoResponse());
6666

6767
wire_io_transaction->req = req;
6868
wire_io_transaction->rsp = rsp;
@@ -152,7 +152,7 @@ void WireDispatcher::processWireIoRequest(WireIoTransaction * wire_io_transactio
152152
size_t bytes_read = 0;
153153
for (; bytes_read < io_request->bytes_to_read; bytes_read++)
154154
{
155-
io_response->read_buf[bytes_read] = Wire.read();
155+
io_request->read_buf[bytes_read] = Wire.read();
156156
}
157157
io_response->bytes_read = bytes_read;
158158
}

0 commit comments

Comments
 (0)