GCC Code Coverage Report


Directory: src/gate/
File: src/gate/io/cxx_gpiodevices_i2c.cpp
Date: 2026-05-04 21:11:01
Exec Total Coverage
Lines: 0 27 0.0%
Functions: 0 9 0.0%
Branches: 0 14 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/io/gpiodevices.hpp"
30 #include "gate/exceptions.hpp"
31
32 namespace gate
33 {
34 namespace io
35 {
36
37 String I2CDevice::getDefaultDevicePath()
38 {
39 gate_string_t device_path;
40 gate_result_t result = gate_i2cdevice_default_path(&device_path);
41 GATEXX_CHECK_EXCEPTION(result);
42 return String::createFrom(device_path);
43 }
44
45 I2CDevice::I2CDevice(String const& devicePath, enumint_t flags)
46 {
47 result_t result = gate_i2cdevice_open(devicePath.c_impl(), flags, &this->impl);
48 GATEXX_CHECK_EXCEPTION(result);
49 }
50
51 I2CDevice::~I2CDevice() noexcept
52 {
53 gate_i2cdevice_close(&this->impl);
54 }
55
56 Result<size_t> I2CDevice::trySend(uint8_t i2cAddress, void const* data, size_t dataLength) noexcept
57 {
58 return this->trySend(i2cAddress, &data, &dataLength, 1);
59 }
60
61 Result<size_t> I2CDevice::trySend(uint8_t i2cAddress, void const* const* blocks, size_t const* blocksLengths, size_t blocksCount) noexcept
62 {
63 size_t bytesSent = 0;
64 result_t result = gate_i2cdevice_send(&this->impl, i2cAddress, blocks, blocksLengths, blocksCount, &bytesSent);
65 return makeResult(result, bytesSent);
66 }
67
68 Result<size_t> I2CDevice::tryReceive(uint8_t i2cAddress, void* buffer, size_t bufferLength) noexcept
69 {
70 size_t bytesReceived = 0;
71 result_t result = gate_i2cdevice_receive(&this->impl, i2cAddress, buffer, bufferLength, &bytesReceived);
72 return makeResult(result, bytesReceived);
73 }
74
75 size_t I2CDevice::send(uint8_t i2cAddress, void const* data, size_t dataLength)
76 {
77 return this->trySend(i2cAddress, data, dataLength).valueOrExcept();
78 }
79 size_t I2CDevice::send(uint8_t i2cAddress, void const* const* blocks, size_t const* blocksLengths, size_t blocksCount)
80 {
81 return this->trySend(i2cAddress, blocks, blocksLengths, blocksCount).valueOrExcept();
82 }
83
84 size_t I2CDevice::receive(uint8_t i2cAddress, void* buffer, size_t bufferLength)
85 {
86 return this->tryReceive(i2cAddress, buffer, bufferLength).valueOrExcept();
87 }
88
89 } // end of namespace io
90 } // end of namespace gate
91