Skip to content

Commit 2d1a689

Browse files
committed
Move implementation from WireBusDevice.h to WireBusDevice.cpp
1 parent 26b562b commit 2d1a689

File tree

2 files changed

+63
-25
lines changed

2 files changed

+63
-25
lines changed

src/wire/WireBusDevice.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* This file is part of the Arduino_ThreadsafeIO library.
3+
* Copyright (c) 2021 Arduino SA.
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2.1 of the License, or (at your option) any later version.
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
/**************************************************************************************
20+
* INCLUDE
21+
**************************************************************************************/
22+
23+
#include "WireBusDevice.h"
24+
25+
/**************************************************************************************
26+
* CTOR/DTOR
27+
**************************************************************************************/
28+
29+
WireBusDevice::WireBusDevice(WireBusDeviceConfig const & config)
30+
: _config{config}
31+
{
32+
33+
}
34+
35+
/**************************************************************************************
36+
* PUBLIC MEMBER FUNCTIONS
37+
**************************************************************************************/
38+
39+
IoResponse WireBusDevice::transfer(IoRequest & req)
40+
{
41+
return WireDispatcher::instance().dispatch(&req, &_config);
42+
}
43+
44+
bool WireBusDevice::write_then_read(const uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, bool stop)
45+
{
46+
/* Copy the Wire parameters from the device and modify only those
47+
* which can be modified via the parameters of this function.
48+
*/
49+
bool const restart = !stop;
50+
WireBusDeviceConfig config(_config.wire(), _config.slave_addr(), restart, _config.stop());
51+
/* Fire off the IO request and await its response. */
52+
IoRequest req(write_buffer, write_len, read_buffer, read_len);
53+
IoResponse rsp = WireDispatcher::instance().dispatch(&req, &config);
54+
rsp->wait();
55+
/* TODO: Introduce error codes within the IoResponse and evaluate
56+
* them here.
57+
*/
58+
return true;
59+
}

src/wire/WireBusDevice.h

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,12 @@ class WireBusDevice : public BusDeviceBase
3939
{
4040
public:
4141

42-
WireBusDevice(WireBusDeviceConfig const & config)
43-
: _config{config}
44-
{ }
42+
WireBusDevice(WireBusDeviceConfig const & config);
43+
virtual ~WireBusDevice() { }
4544

45+
virtual IoResponse transfer(IoRequest & req) override;
4646

47-
virtual IoResponse transfer(IoRequest & req) override
48-
{
49-
return WireDispatcher::instance().dispatch(&req, &_config);
50-
}
51-
52-
53-
bool write_then_read(const uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, bool stop = false)
54-
{
55-
/* Copy the Wire parameters from the device and modify only those
56-
* which can be modified via the parameters of this function.
57-
*/
58-
bool const restart = !stop;
59-
WireBusDeviceConfig config(_config.wire(), _config.slave_addr(), restart, _config.stop());
60-
/* Fire off the IO request and await its response. */
61-
IoRequest req(write_buffer, write_len, read_buffer, read_len);
62-
IoResponse rsp = WireDispatcher::instance().dispatch(&req, &config);
63-
rsp->wait();
64-
/* TODO: Introduce error codes within the IoResponse and evaluate
65-
* them here.
66-
*/
67-
return true;
68-
}
47+
bool write_then_read(const uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, bool stop = false);
6948

7049
private:
7150

0 commit comments

Comments
 (0)