xref: /openbmc/phosphor-buttons/inc/gpio.hpp (revision 5b98f4db)
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 // this struct has the gpio config for single gpio
25 struct gpioInfo
26 {
27     int fd; // io fd mapped with the gpio
28     uint32_t number;
29     std::string direction;
30 };
31 
32 // this struct represents button interface
33 struct buttonConfig
34 {
35     std::string formFactorName;   // name of the button interface
36     std::vector<gpioInfo> gpios;  // holds single or group gpio config
37     nlohmann::json extraJsonInfo; // corresponding to button interface
38 };
39 
40 /**
41  * @brief iterates over the list of gpios and configures gpios them
42  * config which is set from gpio defs json file.
43  * The fd of the configured gpio is stored in buttonConfig.gpios container
44  * @return int returns 0 on successful config of all gpios
45  */
46 
47 int configGroupGpio(buttonConfig& buttonCfg);
48 
49 /**
50  * @brief  configures and initializes the single gpio
51  * @return int returns 0 on successful config of all gpios
52  */
53 
54 int configGpio(gpioInfo& gpioConfig);
55 
56 uint32_t getGpioNum(const std::string& gpioPin);
57 void closeGpio(int fd);
58 // global json object which holds gpio_defs.json configs
59 extern nlohmann::json gpioDefs;
60