|
| 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 | +} |
0 commit comments