| 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 "MCP23x17Utils.h" | ||
| 16 | #include "PiFaceUtils.h" | ||
| 17 | |||
| 18 | // PiFace is just a strangely configured MCP23x17 | ||
| 19 | // the first 8 pins on the MCP23x17 are outputs | ||
| 20 | // the second 8 pins are inputs | ||
| 21 | // It's only exposed as 8 GPIO's | ||
| 22 | |||
| 23 | ✗ | PiFacePinCapabilities::PiFacePinCapabilities(const std::string& n, uint32_t kg, int chip, | |
| 24 | const PinCapabilities& read, | ||
| 25 | ✗ | const PinCapabilities& write) : | |
| 26 | PinCapabilitiesFluent(n, kg), | ||
| 27 | ✗ | readPin(read), | |
| 28 | ✗ | writePin(write) { | |
| 29 | ✗ | gpioIdx = chip; | |
| 30 | ✗ | } | |
| 31 | |||
| 32 | ✗ | int PiFacePinCapabilities::configPin(const std::string& mode, | |
| 33 | bool directionOut, | ||
| 34 | const std::string& desc) const { | ||
| 35 | ✗ | if (mode == "pwm" || mode == "uart") { | |
| 36 | ✗ | return 0; | |
| 37 | } | ||
| 38 | ✗ | if (!directionOut) { | |
| 39 | ✗ | readPin.configPin(mode, false, desc); | |
| 40 | } | ||
| 41 | ✗ | return 0; | |
| 42 | } | ||
| 43 | |||
| 44 | ✗ | bool PiFacePinCapabilities::getValue() const { | |
| 45 | ✗ | return readPin.getValue(); | |
| 46 | } | ||
| 47 | |||
| 48 | ✗ | void PiFacePinCapabilities::setValue(bool i) const { | |
| 49 | ✗ | writePin.setValue(i); | |
| 50 | ✗ | } | |
| 51 | |||
| 52 | static std::vector<PiFacePinCapabilities> PIFACE_PINS; | ||
| 53 | static std::vector<PiFacePinCapabilities> PIFACE_PINS_HIDDEN; | ||
| 54 | |||
| 55 | 63 | void PiFacePinCapabilities::Init() { | |
| 56 | // the old wiringPi put the MCP23x17 pins 16 above the PiFace pins | ||
| 57 | 63 | MCP23x17PinCapabilities::Init(101); | |
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
|
63 | if (MCP23x17PinCapabilities::getPinByGPIO(101, 0).ptr()) { |
| 59 | // MCP23x17 detected, add our pins | ||
| 60 | ✗ | for (int x = 0; x < 8; x++) { | |
| 61 | ✗ | const PinCapabilities& write = MCP23x17PinCapabilities::getPinByGPIO(101, x); | |
| 62 | ✗ | const PinCapabilities& read = MCP23x17PinCapabilities::getPinByGPIO(101, 8 + x); | |
| 63 | |||
| 64 | ✗ | write.configPin("gpio", true, "PiFace"); | |
| 65 | ✗ | read.configPin("gpio_pu", false, "PiFace"); | |
| 66 | |||
| 67 | ✗ | std::string name = "PiFace-" + std::to_string(x + 1); | |
| 68 | ✗ | PIFACE_PINS.push_back(PiFacePinCapabilities(name, x, 100, read, write)); | |
| 69 | ✗ | PIFACE_PINS_HIDDEN.push_back(PiFacePinCapabilities(name, 8 + x, 100, read, write)); | |
| 70 | ✗ | } | |
| 71 | } | ||
| 72 | 63 | } | |
| 73 | 56 | void PiFacePinCapabilities::getPinNames(std::vector<std::string>& ret) { | |
| 74 | 56 | MCP23x17PinCapabilities::getPinNames(ret); | |
| 75 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | for (auto& a : PIFACE_PINS) { |
| 76 | ✗ | ret.push_back(a.name); | |
| 77 | } | ||
| 78 | 56 | } | |
| 79 | |||
| 80 | 12 | const PinCapabilities& PiFacePinCapabilities::getPinByName(const std::string& name) { | |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | for (auto& a : PIFACE_PINS) { |
| 82 | ✗ | if (a.name == name) { | |
| 83 | ✗ | return a; | |
| 84 | } | ||
| 85 | } | ||
| 86 | 12 | return MCP23x17PinCapabilities::getPinByName(name); | |
| 87 | } | ||
| 88 | ✗ | const PinCapabilities& PiFacePinCapabilities::getPinByGPIO(int chip, int gpio) { | |
| 89 | ✗ | for (auto& a : PIFACE_PINS) { | |
| 90 | ✗ | if (a.gpio == gpio && a.gpioIdx == chip) { | |
| 91 | ✗ | return a; | |
| 92 | } | ||
| 93 | } | ||
| 94 | ✗ | for (auto& a : PIFACE_PINS_HIDDEN) { | |
| 95 | ✗ | if (a.gpio == gpio && a.gpioIdx == chip) { | |
| 96 | ✗ | return a; | |
| 97 | } | ||
| 98 | } | ||
| 99 | ✗ | return MCP23x17PinCapabilities::getPinByGPIO(chip, gpio); | |
| 100 | } | ||
| 101 | ✗ | const PinCapabilities& PiFacePinCapabilities::getPinByUART(const std::string& n) { | |
| 102 | ✗ | return MCP23x17PinCapabilities::getPinByUART(n); | |
| 103 | } | ||
| 104 |