1 #pragma once 2 3 #include <functional> 4 #include <map> 5 #include <string> 6 #include <tuple> 7 #include <vector> 8 9 namespace witherspoon 10 { 11 namespace power 12 { 13 14 class UCD90160; 15 16 namespace ucd90160 17 { 18 19 /** 20 * Defines which extra analysis is required 21 * on failures, if any. 22 */ 23 enum class extraAnalysisType 24 { 25 none, 26 gpuPGOOD, 27 gpuOverTemp 28 }; 29 30 /** 31 * Options for the GPIOs 32 * 33 * Used as a bitmask 34 */ 35 enum class optionFlags 36 { 37 none = 0, 38 shutdownOnFault = 1 39 }; 40 41 constexpr auto gpioNumField = 0; 42 constexpr auto gpioCalloutField = 1; 43 using GPIODefinition = std::tuple<gpio::gpioNum_t, std::string>; 44 using GPIODefinitions = std::vector<GPIODefinition>; 45 46 constexpr auto gpioDevicePathField = 0; 47 constexpr auto gpioPolarityField = 1; 48 constexpr auto errorFunctionField = 2; 49 constexpr auto optionFlagsField = 3; 50 constexpr auto gpioDefinitionField = 4; 51 52 using ErrorFunction = std::function<void(UCD90160&, const std::string&)>; 53 54 using GPIOGroup = std::tuple<std::string, gpio::Value, ErrorFunction, 55 optionFlags, GPIODefinitions>; 56 57 using GPIOAnalysis = std::map<extraAnalysisType, GPIOGroup>; 58 59 constexpr auto gpiNumField = 0; 60 constexpr auto pinIDField = 1; 61 constexpr auto gpiNameField = 2; 62 constexpr auto pollField = 3; 63 constexpr auto extraAnalysisField = 4; 64 65 using GPIConfig = 66 std::tuple<size_t, size_t, std::string, bool, extraAnalysisType>; 67 68 using GPIConfigs = std::vector<GPIConfig>; 69 70 using RailNames = std::vector<std::string>; 71 72 constexpr auto pathField = 0; 73 constexpr auto railNamesField = 1; 74 constexpr auto gpiConfigField = 2; 75 constexpr auto gpioAnalysisField = 3; 76 77 using DeviceDefinition = 78 std::tuple<std::string, RailNames, GPIConfigs, GPIOAnalysis>; 79 80 // Maps a device instance to its definition 81 using DeviceMap = std::map<size_t, DeviceDefinition>; 82 83 } // namespace ucd90160 84 } // namespace power 85 } // namespace witherspoon 86