1 /* 2 // Copyright (c) 2018 Intel Corporation 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 */ 16 #pragma once 17 18 #include <nlohmann/json.hpp> 19 #include <sdbusplus/bus.hpp> 20 21 #include <string> 22 #include <vector> 23 24 struct ButtonConfig; 25 26 // enum to represent gpio states 27 enum class GpioState 28 { 29 assert, 30 deassert, 31 invalid 32 }; 33 // enum to represent gpio polarity 34 enum class GpioPolarity 35 { 36 activeLow, 37 activeHigh 38 }; 39 40 struct GPIOBufferValue 41 { 42 char assert; 43 char deassert; 44 }; 45 46 // this struct has the gpio config for single gpio 47 struct GpioInfo 48 { 49 int fd; // io fd mapped with the gpio 50 uint32_t number; 51 std::string name; 52 std::string direction; 53 GpioPolarity polarity; 54 }; 55 56 /** 57 * @brief iterates over the list of gpios and configures gpios them 58 * config which is set from gpio defs json file. 59 * The fd of the configured gpio is stored in ButtonConfig.gpios container 60 * @return int returns 0 on successful config of all gpios 61 */ 62 63 int configGroupGpio(ButtonConfig& buttonCfg); 64 65 /** 66 * @brief configures and initializes the single gpio 67 * @return int returns 0 on successful config of all gpios 68 */ 69 70 int configGpio(GpioInfo& gpioConfig, ButtonConfig& buttonIFConfig); 71 72 uint32_t getGpioNum(const std::string& gpioPin); 73 // Set gpio state based on polarity 74 void setGpioState(int fd, GpioPolarity polarity, GpioState state); 75 // Get gpio state based on polarity 76 GpioState getGpioState(int fd, GpioPolarity polarity); 77 78 // global json object which holds gpio_defs.json configs 79 extern nlohmann::json gpioDefs; 80