| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the GPL v2 as described in the | ||
| 10 | * included LICENSE.GPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include <fcntl.h> | ||
| 16 | |||
| 17 | #include <filesystem> | ||
| 18 | #include <fstream> | ||
| 19 | #include <mutex> | ||
| 20 | #include <map> | ||
| 21 | #include <set> | ||
| 22 | |||
| 23 | #include "PiFaceUtils.h" | ||
| 24 | #include "PiGPIOUtils.h" | ||
| 25 | #include "Warnings.h" | ||
| 26 | #include "common_mini.h" | ||
| 27 | #include "log.h" | ||
| 28 | |||
| 29 | 972 | static bool isPi5() { | |
| 30 | 232 | static bool pi5 = [] { | |
| 31 |
2/4✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
|
116 | std::string model = GetFileContents("/proc/device-tree/model"); |
| 32 |
5/12✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 113 times.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
351 | return startsWith(model, "Raspberry Pi 5") || |
| 33 |
9/16✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 113 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 113 times.
✓ Branch 10 taken 116 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
238 | startsWith(model, "Raspberry Pi Compute Module 5"); |
| 34 |
4/8✓ Branch 0 taken 116 times.
✓ Branch 1 taken 856 times.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1088 | }(); |
| 35 | 972 | return pi5; | |
| 36 | } | ||
| 37 | |||
| 38 | // Kernel 6.18 enabled strict pinmux mode for both pinctrl-rp1 and pinctrl-bcm2835 | ||
| 39 | // (raspberrypi/linux "pinctrl: rp1: enable strict pinmux mode", raspberrypi/linux#5870). | ||
| 40 | // A header pin that a peripheral node claims in the device tree -- i2c1 on P1-3/5, spi0 | ||
| 41 | // on P1-19/21/23, uart0 on P1-8/10, i2s on P1-12/35/38/40 -- is now reported to gpiolib | ||
| 42 | // as in use by the kernel, and every gpiod request against it fails with EINVAL. Through | ||
| 43 | // FPP 9.x (kernel 6.12) those drivers were non-strict, so re-muxing the pad with | ||
| 44 | // "pinctrl set" and then requesting it worked; on 6.18 it does not, because "pinctrl set" | ||
| 45 | // writes FUNCSEL behind the pinctrl driver's back and leaves the kernel's claim in place. | ||
| 46 | // | ||
| 47 | // The supported way to get the pin back is to make the owning device release it, which | ||
| 48 | // unbinding its driver does. That is safe when nothing has attached to the bus (the common | ||
| 49 | // case for buttons wired straight to the header on a board with no cape), and decidedly | ||
| 50 | // unsafe when something has: a child driver's remove path can wedge in the kernel and take | ||
| 51 | // the whole bus with it. So we unbind only when the owner has no child driver bound other | ||
| 52 | // than the ones known to detach cleanly, and warn with the offending driver named otherwise. | ||
| 53 | // | ||
| 54 | // On a non-strict kernel the debugfs format has no "device " prefix, so findPinMuxOwner() | ||
| 55 | // finds nothing and none of this engages -- which is exactly right, since a non-strict | ||
| 56 | // controller hands the pin over without help. | ||
| 57 | static constexpr const char* PINMUX_DEBUG_DIR = "/sys/kernel/debug/pinctrl"; | ||
| 58 | |||
| 59 | struct PinMuxOwner { | ||
| 60 | std::string device; // platform device holding the mux claim, e.g. "1f00074000.i2c" | ||
| 61 | std::string function; // mux function it selected, e.g. "i2c1" | ||
| 62 | bool hog = false; | ||
| 63 | }; | ||
| 64 | |||
| 65 | // The pin controllers that drive the 40-pin header. Other pinctrl instances (the bcm2712 | ||
| 66 | // "aon" controller, expanders) enumerate overlapping pin numbers and must not be consulted. | ||
| 67 | 10 | static bool isHeaderPinctrlDir(const std::string& dir) { | |
| 68 |
6/26✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 10 times.
✓ Branch 14 taken 10 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 10 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
40 | return endsWith(dir, "-pinctrl-rp1") || endsWith(dir, "-pinctrl-bcm2711") || |
| 69 |
3/16✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 10 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
20 | endsWith(dir, "-pinctrl-bcm2835"); |
| 70 | } | ||
| 71 | |||
| 72 | // debugfs files report a size of 0, so they have to be streamed rather than slurped. | ||
| 73 | 116 | static bool findPinMuxOwner(int gpio, PinMuxOwner& owner) { | |
| 74 |
2/4✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
|
116 | const std::string prefix = "pin " + std::to_string(gpio) + " ("; |
| 75 | 116 | std::error_code ec; | |
| 76 |
2/4✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
|
116 | std::filesystem::directory_iterator dir(PINMUX_DEBUG_DIR, ec); |
| 77 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 10 times.
|
116 | if (ec) { |
| 78 | // Without debugfs there is no way to find out which device holds a pin, so a | ||
| 79 | // claimed pin can only be reported as unavailable by the failing request itself. | ||
| 80 | static bool warned = false; | ||
| 81 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 46 times.
|
106 | if (!warned) { |
| 82 | 60 | warned = true; | |
| 83 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
60 | LogWarn(VB_GPIO, "%s is not readable; pins claimed by a kernel driver cannot be freed for GPIO use\n", |
| 84 | PINMUX_DEBUG_DIR); | ||
| 85 | } | ||
| 86 | 106 | return false; | |
| 87 | } | ||
| 88 |
1/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | for (const auto& entry : dir) { |
| 89 |
4/8✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
|
10 | if (!isHeaderPinctrlDir(entry.path().filename().string())) { |
| 90 | ✗ | continue; | |
| 91 | } | ||
| 92 |
3/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | std::ifstream in(entry.path().string() + "/pinmux-pins"); |
| 93 | 10 | std::string line; | |
| 94 |
3/6✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 92 times.
✗ Branch 5 not taken.
|
92 | while (std::getline(in, line)) { |
| 95 |
3/4✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 82 times.
✓ Branch 3 taken 10 times.
|
92 | if (!startsWith(line, prefix)) { |
| 96 | 82 | continue; | |
| 97 | } | ||
| 98 | // strict format: "pin 2 (gpio2): device 1f00074000.i2c function i2c1 group gpio2" | ||
| 99 | 10 | size_t dpos = line.find("): device "); | |
| 100 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
|
10 | if (dpos == std::string::npos) { |
| 101 | 10 | return false; // UNCLAIMED, GPIO-owned, or a non-strict kernel | |
| 102 | } | ||
| 103 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | std::string rest = line.substr(dpos + 10); |
| 104 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | owner.device = rest.substr(0, rest.find(' ')); |
| 105 | 4 | owner.hog = rest.find(" (HOG)") != std::string::npos; | |
| 106 | 4 | size_t fpos = rest.find(" function "); | |
| 107 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (fpos != std::string::npos) { |
| 108 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | std::string fn = rest.substr(fpos + 10); |
| 109 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | owner.function = fn.substr(0, fn.find(' ')); |
| 110 | 4 | } | |
| 111 | 4 | return true; | |
| 112 | 4 | } | |
| 113 |
4/8✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
|
40 | } |
| 114 | ✗ | return false; | |
| 115 | 116 | } | |
| 116 | |||
| 117 | // A child that is still driver-bound means the bus is in use; removing the controller then | ||
| 118 | // runs that driver's remove path, which is where an unbind can hang. spidev is the one | ||
| 119 | // child FPP creates itself and is known to detach cleanly. | ||
| 120 | 3 | static bool findBlockingChildDriver(const std::string& devPath, std::string& blocker) { | |
| 121 |
4/8✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
3 | static const std::set<std::string> safeChildDrivers = { "spidev" }; |
| 122 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | const std::string ownDriver = devPath + "/driver"; |
| 123 | 3 | std::error_code ec; | |
| 124 | 3 | auto end = std::filesystem::recursive_directory_iterator(); | |
| 125 | 3 | for (auto it = std::filesystem::recursive_directory_iterator( | |
| 126 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | devPath, std::filesystem::directory_options::skip_permission_denied, ec); |
| 127 |
2/4✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | it != end; it.increment(ec)) { |
| 128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (ec) { |
| 129 | ✗ | break; | |
| 130 | } | ||
| 131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (it.depth() >= 5) { |
| 132 | ✗ | it.disable_recursion_pending(); | |
| 133 | } | ||
| 134 | 48 | const std::filesystem::path& p = it->path(); | |
| 135 |
12/24✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 45 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 45 times.
✓ Branch 12 taken 48 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 48 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 45 times.
✓ Branch 17 taken 3 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
48 | if (p.filename() != "driver" || p.string() == ownDriver) { |
| 136 | 45 | continue; | |
| 137 | } | ||
| 138 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | std::filesystem::path target = std::filesystem::read_symlink(p, ec); |
| 139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (ec) { |
| 140 | ✗ | ec.clear(); | |
| 141 | ✗ | continue; | |
| 142 | } | ||
| 143 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | std::string driver = target.filename().string(); |
| 144 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | if (!safeChildDrivers.count(driver)) { |
| 145 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | blocker = driver; |
| 146 | 3 | return true; | |
| 147 | } | ||
| 148 |
3/7✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
|
9 | } |
| 149 | ✗ | return false; | |
| 150 | 3 | } | |
| 151 | |||
| 152 | // Hand a pin back from the peripheral that claimed it in the device tree so FPP can | ||
| 153 | // use it itself - as a GPIO, or re-muxed to another function such as DPI (a pixel | ||
| 154 | // string output on the SPI header pins, say, with spi0 still enabled in config.txt). | ||
| 155 | // "use" names what the caller wants the pin for, for the messages. Returns true if | ||
| 156 | // the pin is usable when it returns. | ||
| 157 | 118 | static bool releasePinFromKernelDriver(int gpio, const std::string& pinName, const std::string& use = "GPIO") { | |
| 158 | // configPin() is reachable from the REST API as well as from startup, so the | ||
| 159 | // once-per-pin bookkeeping needs to be serialized. | ||
| 160 | static std::mutex handledLock; | ||
| 161 | // What became of each pin already dealt with this boot: true if it was | ||
| 162 | // freed, false if it couldn't be (and was warned about). A later caller | ||
| 163 | // gets the same answer; this used to say "freed" to every later caller, | ||
| 164 | // even for a pin that is still claimed. | ||
| 165 |
3/4✓ Branch 0 taken 65 times.
✓ Branch 1 taken 53 times.
✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
118 | static std::map<int, bool> handled; |
| 166 |
1/2✓ Branch 0 taken 118 times.
✗ Branch 1 not taken.
|
118 | std::unique_lock<std::mutex> lock(handledLock); |
| 167 |
1/2✓ Branch 0 taken 118 times.
✗ Branch 1 not taken.
|
118 | auto done = handled.find(gpio); |
| 168 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 116 times.
|
118 | if (done != handled.end()) { |
| 169 | 2 | return done->second; | |
| 170 | } | ||
| 171 | |||
| 172 | 116 | PinMuxOwner owner; | |
| 173 |
3/4✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 4 times.
|
116 | if (!findPinMuxOwner(gpio, owner)) { |
| 174 | 112 | return true; // unclaimed, or a kernel that doesn't enforce the claim | |
| 175 | } | ||
| 176 |
4/8✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
|
4 | if (owner.hog || owner.function == "gpio") { |
| 177 | // A hog belongs to the pin controller itself, and a pin muxed as the GPIO | ||
| 178 | // function stays requestable under strict mode via .function_is_gpio. | ||
| 179 | ✗ | return true; | |
| 180 | } | ||
| 181 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | handled[gpio] = false; // until it is shown to be free below |
| 182 | |||
| 183 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | const std::string devPath = "/sys/bus/platform/devices/" + owner.device; |
| 184 | 4 | std::error_code ec; | |
| 185 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | std::filesystem::path driverLink = std::filesystem::read_symlink(devPath + "/driver", ec); |
| 186 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if (ec) { |
| 187 |
5/10✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | std::string w = "Pin " + pinName + " is claimed by " + owner.device + " (" + owner.function + |
| 188 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | ") and cannot be used for " + use + "; no driver to unbind"; |
| 189 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | WarningHolder::AddWarning(51, w); |
| 190 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogWarn(VB_GPIO, "%s\n", w.c_str()); |
| 191 | 1 | return false; | |
| 192 | 1 | } | |
| 193 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | std::string driver = driverLink.filename().string(); |
| 194 | |||
| 195 | 3 | std::string blocker; | |
| 196 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | if (findBlockingChildDriver(devPath, blocker)) { |
| 197 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
|
6 | std::string w = "Pin " + pinName + " is claimed by " + owner.function + " (" + owner.device + |
| 198 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
6 | "), which is in use by the " + blocker + |
| 199 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
|
3 | " driver. Disable " + owner.function + " in config.txt to use this pin for " + use + "."; |
| 200 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | WarningHolder::AddWarning(51, w); |
| 201 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | LogWarn(VB_GPIO, "%s\n", w.c_str()); |
| 202 | 3 | return false; | |
| 203 | 3 | } | |
| 204 | |||
| 205 | ✗ | LogInfo(VB_GPIO, "Pin %s is claimed by %s (%s); unbinding %s to free it for %s use\n", | |
| 206 | pinName.c_str(), owner.function.c_str(), owner.device.c_str(), driver.c_str(), use.c_str()); | ||
| 207 | ✗ | std::ofstream unbind("/sys/bus/platform/drivers/" + driver + "/unbind"); | |
| 208 | ✗ | unbind << owner.device; | |
| 209 | ✗ | unbind.close(); | |
| 210 | |||
| 211 | ✗ | PinMuxOwner check; | |
| 212 | ✗ | if (findPinMuxOwner(gpio, check)) { | |
| 213 | ✗ | std::string w = "Pin " + pinName + " is claimed by " + check.function + " (" + check.device + | |
| 214 | ✗ | ") and could not be freed for " + use + " use"; | |
| 215 | ✗ | WarningHolder::AddWarning(51, w); | |
| 216 | ✗ | LogWarn(VB_GPIO, "%s\n", w.c_str()); | |
| 217 | ✗ | return false; | |
| 218 | ✗ | } | |
| 219 | ✗ | handled[gpio] = true; | |
| 220 | ✗ | return true; | |
| 221 | 118 | } | |
| 222 | |||
| 223 | class PiGPIODCapabilities : public GPIODCapabilities { | ||
| 224 | public: | ||
| 225 | 3248 | PiGPIODCapabilities(const std::string& n, uint32_t kg) : | |
| 226 |
3/6✓ Branch 0 taken 3248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3248 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3248 times.
✗ Branch 5 not taken.
|
16240 | GPIODCapabilities(n, kg) { |
| 227 |
1/2✓ Branch 0 taken 3248 times.
✗ Branch 1 not taken.
|
3248 | gpioIdx = getPinctrlRpiChip(); |
| 228 |
1/2✓ Branch 0 taken 3248 times.
✗ Branch 1 not taken.
|
3248 | gpioName = pinctrlRpiChipName; |
| 229 | 3248 | gpio = kg; | |
| 230 | 3248 | } | |
| 231 | |||
| 232 | 15088 | virtual ~PiGPIODCapabilities() { | |
| 233 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7544 times.
|
15088 | if (dutyFile != nullptr) { |
| 234 | ✗ | fclose(dutyFile); | |
| 235 | } | ||
| 236 | 15088 | } | |
| 237 | |||
| 238 | 2552 | PiGPIODCapabilities& setResetMode(const std::string& mode) { | |
| 239 | 2552 | resetMode = mode; | |
| 240 | 2552 | return *this; | |
| 241 | } | ||
| 242 | // sub is the PWM0 channel the pin carries when muxed to alt | ||
| 243 | 464 | PiGPIODCapabilities& setPwm(int p, int sub, const std::string& alt) { | |
| 244 | 464 | GPIODCapabilities::setPwm(p, sub); | |
| 245 | 464 | pwmMode = alt; | |
| 246 | 464 | return *this; | |
| 247 | } | ||
| 248 | 232 | PiGPIODCapabilities& setUART(const std::string& u, const std::string& um) { | |
| 249 | 232 | uart = u; | |
| 250 | 232 | uartMode = um; | |
| 251 | 232 | return *this; | |
| 252 | } | ||
| 253 | // The pin is a data line (MISO/MOSI/SCLK) of SPI bus b when muxed to alt. Only | ||
| 254 | // for a bus the device tree enables with no pins claimed (fpp-spi1-nopins), the | ||
| 255 | // same way setUART() pairs with fpp-uart0-nopins. | ||
| 256 | 348 | PiGPIODCapabilities& setSPI(int b, const std::string& alt) { | |
| 257 | 348 | spiBus = b; | |
| 258 | 348 | spiMode = alt; | |
| 259 | 348 | return *this; | |
| 260 | } | ||
| 261 | 57 | virtual void releasePin() const override { | |
| 262 | char buf[256]; | ||
| 263 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 13 times.
|
57 | if (dpiConfigured) { |
| 264 | // A pixel data (or latch) line. Returning it to a plain input leaves | ||
| 265 | // it floating - or on the Pi 5, at "function none" with a weak | ||
| 266 | // pull-down - and the hat's buffer then amplifies whatever noise it | ||
| 267 | // picks up into random colours on the string for the rest of the | ||
| 268 | // shutdown/reboot (issue #2895). Park it as a driven-low output | ||
| 269 | // instead: pinctrl writes the pad registers directly, so this | ||
| 270 | // survives fppd exiting, and low is idle for WS281x. It holds until | ||
| 271 | // the next boot resets the pad; fppd's Init() then muxes the pin back | ||
| 272 | // to DPI only after a blank frame is already in the framebuffer. | ||
| 273 | 44 | snprintf(buf, 256, "/usr/bin/pinctrl set %d op dl", gpio); | |
| 274 | 44 | dpiConfigured = false; | |
| 275 | } else { | ||
| 276 | 13 | snprintf(buf, 256, "/usr/bin/pinctrl set %d %s", gpio, resetMode.c_str()); | |
| 277 | } | ||
| 278 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | system(buf); |
| 279 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | GPIODCapabilities::releasePin(); |
| 280 | 57 | } | |
| 281 | 118 | virtual int configPin(const std::string& mode = "gpio", | |
| 282 | bool directionOut = true, | ||
| 283 | const std::string& desc = "") const override { | ||
| 284 | // see https://datasheets.raspberrypi.com/rp1/rp1-peripherals.pdf | ||
| 285 | // 1-3: https://elinux.org/RPi_BCM2835_GPIOs | ||
| 286 | // 4/5: https://elinux.org/RPi_BCM2711_GPIOs | ||
| 287 | |||
| 288 | // A data line of a bus the device tree enables with no pins claimed | ||
| 289 | // (fpp-spi1-nopins), so the spi controller never owns it here. Anything | ||
| 290 | // else holding the pin -- i2s on P1-35/38/40 under an audio overlay, say | ||
| 291 | // -- has to let go before a "pinctrl set" to the SPI alt sticks, and a | ||
| 292 | // pin that cannot be freed is refused rather than half-muxed. | ||
| 293 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 116 times.
|
118 | if (mode == "spi") { |
| 294 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (spiBus == -1) { |
| 295 | ✗ | LogWarn(VB_GPIO, "Pin %s has no SPI function\n", name.c_str()); | |
| 296 | ✗ | return -1; | |
| 297 | } | ||
| 298 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
6 | if (!releasePinFromKernelDriver(gpio, name, "SPI")) { |
| 299 | 2 | return -1; | |
| 300 | } | ||
| 301 | char buf[256]; | ||
| 302 | ✗ | snprintf(buf, 256, "/usr/bin/pinctrl set %d %s", gpio, spiMode.c_str()); | |
| 303 | ✗ | system(buf); | |
| 304 | ✗ | return 0; | |
| 305 | } | ||
| 306 | |||
| 307 | // Under strict pinmux a pin the device tree handed to a peripheral has to be | ||
| 308 | // reclaimed from that driver before any gpiod request on it can succeed, and | ||
| 309 | // before a "pinctrl set" to another alt function sticks: the pinctrl driver | ||
| 310 | // reasserts its claim, so a string output on a pin spi0 owns silently stayed | ||
| 311 | // SPI. See releasePinFromKernelDriver() above. | ||
| 312 |
15/28✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 49 times.
✓ Branch 5 taken 67 times.
✓ Branch 6 taken 49 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✓ Branch 9 taken 44 times.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 3 times.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 116 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 116 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 116 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
348 | if (startsWith(mode, "gpio") || mode == "dpi" || mode == "pwm" || mode == "uart") { |
| 313 |
11/16✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 69 times.
✓ Branch 8 taken 69 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 67 times.
✓ Branch 12 taken 116 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 116 times.
✗ Branch 15 not taken.
|
348 | releasePinFromKernelDriver(gpio, name, mode == "dpi" ? "DPI" : mode == "pwm" ? "PWM" : mode == "uart" ? "UART" : "GPIO"); |
| 314 | } | ||
| 315 | |||
| 316 |
5/6✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 113 times.
|
116 | if (mode == "pwm" && pwm != -1) { |
| 317 | char buf[256]; | ||
| 318 | 3 | snprintf(buf, 256, "/usr/bin/pinctrl set %d %s", gpio, pwmMode.c_str()); | |
| 319 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | system(buf); |
| 320 | 3 | return 0; | |
| 321 | } | ||
| 322 | |||
| 323 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 69 times.
|
113 | if (mode == "dpi") { |
| 324 | // Pi 5 (RP1): DPI is alt1, Pi 4 and earlier (BCM2711/BCM2835): DPI is alt2 | ||
| 325 |
3/4✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 2 times.
|
44 | const char* alt = isPi5() ? "a1" : "a2"; |
| 326 | char buf[256]; | ||
| 327 | 44 | snprintf(buf, 256, "/usr/bin/pinctrl set %d %s", gpio, alt); | |
| 328 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | system(buf); |
| 329 | 44 | dpiConfigured = true; | |
| 330 | 44 | return 0; | |
| 331 | } | ||
| 332 |
6/8✓ Branch 0 taken 2 times.
✓ Branch 1 taken 67 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 67 times.
|
69 | if (mode == "uart" && !uart.empty() && !uartMode.empty()) { |
| 333 | char buf[256]; | ||
| 334 | 2 | snprintf(buf, 256, "/usr/bin/pinctrl set %d %s", gpio, uartMode.c_str()); | |
| 335 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | system(buf); |
| 336 | 2 | return 0; | |
| 337 | } | ||
| 338 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 63 times.
|
67 | if (mode == "gpio_od") { |
| 339 | // Open-drain (bit-banged I2C): set the pad to GPIO function with the | ||
| 340 | // input buffer + pull-up enabled via pinctrl, then create the | ||
| 341 | // open-drain gpiod request that actually drives/senses the line. | ||
| 342 | char buf[256]; | ||
| 343 | 4 | snprintf(buf, 256, "/usr/bin/pinctrl set %d ip pu", gpio); | |
| 344 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | system(buf); |
| 345 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
12 | return GPIODCapabilities::configPin("gpio_od", false, desc); |
| 346 | } | ||
| 347 | // Pins whose resetMode is an alt-function sentinel ("a0"/"a3" -- the | ||
| 348 | // i2c/uart/spi header pins the device tree hands to a peripheral) come out of | ||
| 349 | // reset muxed away from GPIO, so push the pad back to the gpio function with | ||
| 350 | // pinctrl first. (gpio_pu/gpio_pd are left out: pinctrl's bare direction set | ||
| 351 | // carries no bias, and those pins are fine going straight to the request.) | ||
| 352 | // | ||
| 353 | // This must NOT return early. A gpio* mode only becomes usable once | ||
| 354 | // GPIODCapabilities::configPin() has requested the line: without a live | ||
| 355 | // request setValue()/getValue() are silent no-ops and requestEventFile() has | ||
| 356 | // no lastBias/lastDesc to work from. Returning here instead is a bug that has | ||
| 357 | // now surfaced three times -- P1-35/GPIO19 floating on Pi5 (the "no" sentinel, | ||
| 358 | // #2768), pull-up/down inputs coming up floating on any pin left at the | ||
| 359 | // class-default "a0", and a plain "gpio" OUTPUT on P1-10/GPIO15 (uart0 RX, | ||
| 360 | // which some Pi capes use as a port enable pin) muxing correctly but never | ||
| 361 | // driving, leaving that port permanently dark (#2979). | ||
| 362 |
13/24✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 63 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 63 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 33 times.
✓ Branch 9 taken 30 times.
✓ Branch 10 taken 33 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 20 times.
✓ Branch 13 taken 13 times.
✓ Branch 14 taken 63 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 63 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 6 times.
✓ Branch 19 taken 57 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
209 | if (startsWith(mode, "gpio") && mode != "gpio_pu" && mode != "gpio_pd" && |
| 363 |
6/8✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 14 times.
|
20 | (resetMode == "a0" || resetMode == "a3")) { |
| 364 | char buf[256]; | ||
| 365 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
|
6 | snprintf(buf, 256, "/usr/bin/pinctrl set %d %s", gpio, directionOut ? "op" : "ip"); |
| 366 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | system(buf); |
| 367 | } | ||
| 368 | |||
| 369 |
3/6✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 63 times.
|
63 | if (mode == "pwm" || mode == "uart") { |
| 370 | ✗ | return 0; | |
| 371 | } | ||
| 372 | 63 | return GPIODCapabilities::configPin(mode, directionOut, desc); | |
| 373 | } | ||
| 374 | |||
| 375 | 4 | virtual bool supportPWM() const override { return pwm != -1; } | |
| 376 | 3 | virtual bool setupPWM(int maxValue = 25500) const override { | |
| 377 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | if (pwm != -1 && dutyFile != nullptr) { |
| 378 | // Already set up. Each call opened another duty_cycle stream and | ||
| 379 | // leaked the last; reopening instead would close a FILE* that | ||
| 380 | // setPWMValue() on an output thread may be writing to. The pin | ||
| 381 | // itself is muxed again, though: an output reload closes the old | ||
| 382 | // output first, and its releasePin() put the pin back to its reset | ||
| 383 | // mode, so the new output's PWM never reached it. A caller that | ||
| 384 | // wants another period (SetupExtGPIO vs the GPIO output) gets it. | ||
| 385 | ✗ | configPin("pwm", true, "PWM"); | |
| 386 | ✗ | if (maxValue != pwmPeriod) { | |
| 387 | char name[128]; | ||
| 388 | // duty_cycle may not exceed period: zero it before a shorter one | ||
| 389 | ✗ | fprintf(dutyFile, "0"); | |
| 390 | ✗ | fflush(dutyFile); | |
| 391 | ✗ | snprintf(name, sizeof(name), "/sys/class/pwm/pwmchip0/pwm%d/period", subPwm); | |
| 392 | ✗ | FILE* f = fopen(name, "w"); | |
| 393 | ✗ | if (f) { | |
| 394 | ✗ | fprintf(f, "%d", maxValue); | |
| 395 | ✗ | fclose(f); | |
| 396 | ✗ | pwmPeriod = maxValue; | |
| 397 | } | ||
| 398 | } | ||
| 399 | ✗ | return true; | |
| 400 | } | ||
| 401 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (pwm != -1) { |
| 402 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
12 | configPin("pwm", true, "PWM"); |
| 403 | char dir_name[128]; | ||
| 404 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | FILE* dir = fopen("/sys/class/pwm/pwmchip0/export", "w"); |
| 405 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (!dir) { |
| 406 | 1 | return false; | |
| 407 | } | ||
| 408 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | fprintf(dir, "%d", subPwm); |
| 409 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | fclose(dir); |
| 410 | |||
| 411 | 2 | snprintf(dir_name, sizeof(dir_name), "/sys/class/pwm/pwmchip0/pwm%d/period", subPwm); | |
| 412 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | dir = fopen(dir_name, "w"); |
| 413 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!dir) { |
| 414 | ✗ | return false; | |
| 415 | } | ||
| 416 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | fprintf(dir, "%d", maxValue); |
| 417 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | fclose(dir); |
| 418 | 2 | pwmPeriod = maxValue; | |
| 419 | |||
| 420 | 2 | snprintf(dir_name, sizeof(dir_name), "/sys/class/pwm/pwmchip0/pwm%d/duty_cycle", subPwm); | |
| 421 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | dutyFile = fopen(dir_name, "w"); |
| 422 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!dutyFile) { |
| 423 | ✗ | return false; | |
| 424 | } | ||
| 425 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | fprintf(dutyFile, "0"); |
| 426 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | fflush(dutyFile); |
| 427 | |||
| 428 | 2 | snprintf(dir_name, sizeof(dir_name), "/sys/class/pwm/pwmchip0/pwm%d/enable", subPwm); | |
| 429 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | dir = fopen(dir_name, "w"); |
| 430 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!dir) { |
| 431 | ✗ | return false; | |
| 432 | } | ||
| 433 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | fprintf(dir, "1"); |
| 434 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | fclose(dir); |
| 435 | 2 | return true; | |
| 436 | } | ||
| 437 | ✗ | return false; | |
| 438 | } | ||
| 439 | 91 | virtual void setPWMValue(int valueNS) const override { | |
| 440 | // dutyFile is only opened by a setupPWM() that succeeded; every caller | ||
| 441 | // (the GPIO output, the ExtGPIO command) reaches here regardless. | ||
| 442 |
3/4✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 69 times.
|
91 | if (pwm != -1 && dutyFile) { |
| 443 | 22 | fprintf(dutyFile, "%d", valueNS); | |
| 444 | 22 | fflush(dutyFile); | |
| 445 | } | ||
| 446 | 91 | } | |
| 447 | |||
| 448 | 3248 | static int getPinctrlRpiChip() { | |
| 449 |
2/2✓ Branch 0 taken 116 times.
✓ Branch 1 taken 3132 times.
|
3248 | if (pinctrlRpiChip == -1) { |
| 450 | 116 | pinctrlRpiChip = 0; // Default fallback | |
| 451 | #ifdef IS_GPIOD_CXX_V2 | ||
| 452 | 116 | int has54lineChip = -1; | |
| 453 | 116 | std::string has54lineChipName; | |
| 454 |
5/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10525 times.
✓ Branch 7 taken 5 times.
|
10530 | for (const auto& entry : std::filesystem::directory_iterator("/dev/")) { |
| 455 |
6/10✓ Branch 0 taken 10525 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10525 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10525 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10525 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 136 times.
✓ Branch 9 taken 10389 times.
|
31575 | if (startsWith(entry.path().filename().string(), "gpiochip")) { |
| 456 | try { | ||
| 457 |
3/6✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 136 times.
✗ Branch 5 not taken.
|
136 | auto chip = gpiod::chip(entry.path().string()); |
| 458 |
1/2✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
|
136 | auto info = chip.get_info(); |
| 459 |
14/26✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 111 times.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 25 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 25 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 25 times.
✓ Branch 12 taken 25 times.
✓ Branch 13 taken 111 times.
✓ Branch 14 taken 25 times.
✓ Branch 15 taken 111 times.
✓ Branch 16 taken 136 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 111 times.
✓ Branch 19 taken 25 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
136 | if (info.label() == "pinctrl-rp1" || info.label() == "pinctrl-bcm2711" || info.label() == "pinctrl-bcm2835") { |
| 460 |
4/8✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 111 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 111 times.
✗ Branch 7 not taken.
|
111 | pinctrlRpiChip = std::stoi(entry.path().filename().string().substr(8)); |
| 461 | 111 | pinctrlRpiChipName = info.name(); | |
| 462 | 111 | return pinctrlRpiChip; | |
| 463 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | } else if (info.num_lines() == 54) { |
| 464 | ✗ | has54lineChip = std::stoi(entry.path().filename().string().substr(8)); | |
| 465 | ✗ | has54lineChipName = info.name(); | |
| 466 | } | ||
| 467 |
4/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 111 times.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 111 times.
|
247 | } catch (...) { |
| 468 | // Chip doesn't exist, continue | ||
| 469 | ✗ | } | |
| 470 | } | ||
| 471 |
6/6✓ Branch 0 taken 5 times.
✓ Branch 1 taken 111 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 111 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 111 times.
|
338 | } |
| 472 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (has54lineChip != -1) { |
| 473 | ✗ | pinctrlRpiChip = has54lineChip; | |
| 474 | ✗ | pinctrlRpiChipName = has54lineChipName; | |
| 475 | ✗ | return pinctrlRpiChip; | |
| 476 | } | ||
| 477 | #else | ||
| 478 | for (auto& a : gpiod::make_chip_iter()) { | ||
| 479 | std::string label = a.label(); | ||
| 480 | if (label == "pinctrl-rp1" || label == "pinctrl-bcm2711" || label == "pinctrl-bcm2835") { | ||
| 481 | pinctrlRpiChipName = a.name(); | ||
| 482 | return pinctrlRpiChip; | ||
| 483 | } | ||
| 484 | pinctrlRpiChip++; | ||
| 485 | } | ||
| 486 | // didn't find it by name, try finding the chip with 54 lines | ||
| 487 | pinctrlRpiChip = 0; | ||
| 488 | for (auto& a : gpiod::make_chip_iter()) { | ||
| 489 | if (a.num_lines() == 54) { | ||
| 490 | pinctrlRpiChipName = a.name(); | ||
| 491 | return pinctrlRpiChip; | ||
| 492 | } | ||
| 493 | pinctrlRpiChip++; | ||
| 494 | } | ||
| 495 | #endif | ||
| 496 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 111 times.
|
116 | } |
| 497 | 3137 | return pinctrlRpiChip; | |
| 498 | } | ||
| 499 | mutable FILE* dutyFile = nullptr; | ||
| 500 | mutable int pwmPeriod = 0; // ns, as last written to the period file | ||
| 501 | static int pinctrlRpiChip; | ||
| 502 | static std::string pinctrlRpiChipName; | ||
| 503 | std::string resetMode = "a0"; | ||
| 504 | mutable bool dpiConfigured = false; // muxed for DPI; released as output-low, see releasePin() | ||
| 505 | std::string uartMode; | ||
| 506 | int spiBus = -1; // logical SPI bus this pin is a data line of, -1 if none | ||
| 507 | std::string spiMode; | ||
| 508 | std::string pwmMode; // the alt function that puts the pin on its PWM channel | ||
| 509 | }; | ||
| 510 | int PiGPIODCapabilities::pinctrlRpiChip = -1; | ||
| 511 | std::string PiGPIODCapabilities::pinctrlRpiChipName; | ||
| 512 | static std::vector<PiGPIODCapabilities> PI_PINS; | ||
| 513 | |||
| 514 | 116 | void PiGPIOPinProvider::Init() { | |
| 515 |
4/6✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
232 | std::string ipOrNo = isPi5() ? "no" : "ip"; |
| 516 |
4/6✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
232 | std::string i2c = isPi5() ? "a3" : "a0"; |
| 517 | // SPI1 sits on the I2S pins; RP1 puts it on alt0 where the older SoCs use alt4 | ||
| 518 |
4/6✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
232 | std::string spi1 = isPi5() ? "a0" : "a4"; |
| 519 | // PWM0 on the header: GPIO12/13 carry channels 0/1 on alt0 on every Pi. | ||
| 520 | // GPIO18/19 carry RP1's channels 2/3 on alt3 on a Pi 5, but the BCM2711/ | ||
| 521 | // BCM2835's channels 0/1 on alt5 (their alt3 is SPI6/SPI1) | ||
| 522 |
3/4✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✓ Branch 3 taken 1 times.
|
116 | int pwm18 = isPi5() ? 2 : 0; |
| 523 |
3/4✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✓ Branch 3 taken 1 times.
|
116 | int pwm19 = isPi5() ? 3 : 1; |
| 524 |
4/6✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
348 | std::string pwmAlt1819 = isPi5() ? "a3" : "a5"; |
| 525 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-3", 2).setResetMode(i2c)); |
| 526 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-5", 3).setResetMode(i2c)); |
| 527 |
3/6✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-7", 4)); |
| 528 |
9/16✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 115 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 116 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 116 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 116 times.
✗ Branch 15 not taken.
|
696 | PI_PINS.push_back(PiGPIODCapabilities("P1-8", 14).setUART("ttyAMA0-tx", isPi5() ? "a4" : "a0")); |
| 529 |
9/16✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 115 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 116 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 116 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 116 times.
✗ Branch 15 not taken.
|
696 | PI_PINS.push_back(PiGPIODCapabilities("P1-10", 15).setUART("ttyAMA0-rx", isPi5() ? "a4" : "a0")); |
| 530 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-11", 17).setResetMode(ipOrNo)); |
| 531 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-12", 18).setPwm(0, pwm18, pwmAlt1819).setResetMode(ipOrNo)); |
| 532 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-13", 27).setResetMode(ipOrNo)); |
| 533 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-15", 22).setResetMode(ipOrNo)); |
| 534 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-16", 23).setResetMode(ipOrNo)); |
| 535 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-18", 24).setResetMode(ipOrNo)); |
| 536 |
3/6✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-19", 10)); |
| 537 |
3/6✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-21", 9)); |
| 538 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-22", 25).setResetMode(ipOrNo)); |
| 539 |
3/6✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-23", 11)); |
| 540 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
464 | PI_PINS.push_back(PiGPIODCapabilities("P1-24", 8).setResetMode("op")); |
| 541 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
464 | PI_PINS.push_back(PiGPIODCapabilities("P1-26", 7).setResetMode("op")); |
| 542 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
464 | PI_PINS.push_back(PiGPIODCapabilities("P1-27", 0).setResetMode("ip")); |
| 543 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
464 | PI_PINS.push_back(PiGPIODCapabilities("P1-28", 1).setResetMode("ip")); |
| 544 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
464 | PI_PINS.push_back(PiGPIODCapabilities("P1-29", 5).setResetMode("ip")); |
| 545 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
464 | PI_PINS.push_back(PiGPIODCapabilities("P1-31", 6).setResetMode("ip")); |
| 546 |
7/14✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 116 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 116 times.
✗ Branch 13 not taken.
|
696 | PI_PINS.push_back(PiGPIODCapabilities("P1-32", 12).setResetMode("ip").setPwm(0, 0, "a0")); |
| 547 |
7/14✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 116 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 116 times.
✗ Branch 13 not taken.
|
696 | PI_PINS.push_back(PiGPIODCapabilities("P1-33", 13).setResetMode("ip").setPwm(0, 1, "a0")); |
| 548 |
6/12✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 116 times.
✗ Branch 11 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-35", 19).setResetMode(ipOrNo).setPwm(0, pwm19, pwmAlt1819).setSPI(1, spi1)); |
| 549 |
4/8✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-36", 16).setResetMode(ipOrNo)); |
| 550 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
464 | PI_PINS.push_back(PiGPIODCapabilities("P1-37", 26).setResetMode("ip")); |
| 551 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
232 | PI_PINS.push_back(PiGPIODCapabilities("P1-38", 20).setResetMode(ipOrNo).setSPI(1, spi1)); |
| 552 |
5/10✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
|
116 | PI_PINS.push_back(PiGPIODCapabilities("P1-40", 21).setResetMode(ipOrNo).setSPI(1, spi1)); |
| 553 | |||
| 554 |
1/2✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
|
116 | PiFacePinCapabilities::Init(); |
| 555 | 116 | } | |
| 556 | 309 | const PinCapabilities& PiGPIOPinProvider::getPinByName(const std::string& name) { | |
| 557 |
2/2✓ Branch 0 taken 5117 times.
✓ Branch 1 taken 13 times.
|
5130 | for (auto& a : PI_PINS) { |
| 558 |
2/2✓ Branch 0 taken 296 times.
✓ Branch 1 taken 4821 times.
|
5117 | if (a.name == name) { |
| 559 | 296 | return a; | |
| 560 | } | ||
| 561 | } | ||
| 562 | 13 | return PiFacePinCapabilities::getPinByName(name); | |
| 563 | } | ||
| 564 | 4 | const PinCapabilities& PiGPIOPinProvider::getPinByGPIO(int chip, int gpio) { | |
| 565 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (chip == 0) { |
| 566 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 1 times.
|
77 | for (auto& a : PI_PINS) { |
| 567 |
3/4✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 73 times.
|
76 | if (a.gpioIdx == chip && a.gpio == gpio) { |
| 568 | 3 | return a; | |
| 569 | } | ||
| 570 | } | ||
| 571 | } | ||
| 572 | 1 | return PiFacePinCapabilities::getPinByGPIO(chip, gpio); | |
| 573 | } | ||
| 574 | |||
| 575 | 94 | std::vector<std::string> PiGPIOPinProvider::getPinNames() { | |
| 576 | 94 | std::vector<std::string> ret; | |
| 577 |
2/2✓ Branch 0 taken 2632 times.
✓ Branch 1 taken 94 times.
|
2726 | for (auto& a : PI_PINS) { |
| 578 |
1/2✓ Branch 0 taken 2632 times.
✗ Branch 1 not taken.
|
2632 | ret.push_back(a.name); |
| 579 | } | ||
| 580 |
1/2✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
|
94 | PiFacePinCapabilities::getPinNames(ret); |
| 581 | 94 | return ret; | |
| 582 | ✗ | } | |
| 583 | 2 | const PinCapabilities& PiGPIOPinProvider::getPinByUART(const std::string& n) { | |
| 584 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | for (auto& a : PI_PINS) { |
| 585 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
|
8 | if (a.uart == n) { |
| 586 | 2 | return a; | |
| 587 | } | ||
| 588 | } | ||
| 589 | ✗ | return PiFacePinCapabilities::getPinByUART(n); | |
| 590 | } | ||
| 591 |