| /* |
| // Copyright (c) 2018 Intel Corporation |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| */ |
| #pragma once |
| |
| #include <nlohmann/json.hpp> |
| #include <sdbusplus/bus.hpp> |
| |
| #include <string> |
| #include <vector> |
| |
| struct ButtonConfig; |
| |
| // enum to represent gpio states |
| enum class GpioState |
| { |
| assert, |
| deassert, |
| invalid |
| }; |
| // enum to represent gpio polarity |
| enum class GpioPolarity |
| { |
| activeLow, |
| activeHigh |
| }; |
| |
| struct GPIOBufferValue |
| { |
| char assert; |
| char deassert; |
| }; |
| |
| // this struct has the gpio config for single gpio |
| struct GpioInfo |
| { |
| int fd; // io fd mapped with the gpio |
| uint32_t number; |
| std::string name; |
| std::string direction; |
| GpioPolarity polarity; |
| }; |
| |
| /** |
| * @brief iterates over the list of gpios and configures gpios them |
| * config which is set from gpio defs json file. |
| * The fd of the configured gpio is stored in ButtonConfig.gpios container |
| * @return int returns 0 on successful config of all gpios |
| */ |
| |
| int configGroupGpio(ButtonConfig& buttonCfg); |
| |
| /** |
| * @brief configures and initializes the single gpio |
| * @return int returns 0 on successful config of all gpios |
| */ |
| |
| int configGpio(GpioInfo& gpioConfig, ButtonConfig& buttonIFConfig); |
| |
| uint32_t getGpioNum(const std::string& gpioPin); |
| // Set gpio state based on polarity |
| void setGpioState(int fd, GpioPolarity polarity, GpioState state); |
| // Get gpio state based on polarity |
| GpioState getGpioState(int fd, GpioPolarity polarity); |
| |
| // global json object which holds gpio_defs.json configs |
| extern nlohmann::json gpioDefs; |