GCC Code Coverage Report


Directory: src/gate/
File: src/gate/io/cxx_gpiodevices_pwm.cpp
Date: 2026-10-19 17:06:30
Exec Total Coverage
Lines: 6 35 17.1%
Functions: 2 9 22.2%
Branches: 4 22 18.2%

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 1 String PWMDevice::getDefaultDevicePath()
38 {
39 gate_string_t path;
40
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t const result = gate_pwmdevice_default_path(&path);
41
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
42 ✗ return String::createFrom(path);
43 }
44
45 1 PWMDevice::PWMDevice(String const& devicePath, enumint_t flags)
46 {
47 1 result_t const result = gate_pwmdevice_open(devicePath.c_impl(), flags, &this->impl);
48
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
49 ✗ }
50
51 ✗ PWMDevice::~PWMDevice() noexcept
52 {
53 ✗ gate_pwmdevice_close(&this->impl);
54 ✗ }
55
56 ✗ gate_pwmdevice_t* PWMDevice::c_impl()
57 {
58 ✗ return &this->impl;
59 }
60
61 ✗ static gate_bool_t GATE_CALL PWMDeviceListChannelsCallback(intptr_t channel_id, void* param)
62 {
63 ✗ ArrayList<intptr_t>* ptrList = static_cast<ArrayList<intptr_t>*>(param);
64 ✗ ptrList->add(channel_id);
65 ✗ return true;
66 }
67
68 ✗ PWMDevice::ChannelList PWMDevice::listChannels()
69 {
70 ✗ ArrayList<intptr_t> list;
71 ✗ result_t const result = gate_pwmdevice_list_channels(&this->impl, &PWMDeviceListChannelsCallback, &list);
72 ✗ GATEXX_CHECK_EXCEPTION(result);
73 ✗ return list.toArray();
74 }
75
76 ✗ PWMDevice::Config::Config()
77 : PeriodNanoSeconds(0),
78 DutyCycleNanoSeconds(0),
79 ✗ Enabled(false)
80 {
81 ✗ }
82
83 ✗ PWMDevice::Config PWMDevice::readConfig(channel_t channelId)
84 {
85 ✗ Config ret;
86 ✗ result_t const result = gate_pwmdevice_channel_read(&this->impl,
87 channelId, &ret.PeriodNanoSeconds, &ret.DutyCycleNanoSeconds, &ret.Enabled);
88 ✗ GATEXX_CHECK_EXCEPTION(result);
89 ✗ return ret;
90 }
91
92 ✗ void PWMDevice::writeConfig(channel_t channelId, Config const& config)
93 {
94 ✗ result_t const result = gate_pwmdevice_channel_write(&this->impl,
95 ✗ channelId, config.PeriodNanoSeconds, config.DutyCycleNanoSeconds, config.Enabled);
96 ✗ GATEXX_CHECK_EXCEPTION(result);
97 ✗ }
98
99 } // end of namespace io
100 } // end of namespace gate
101