blob: a5b943abfe03a336ab52a64c2ee5cdd4ea0d877a [file] [log] [blame]
Kuiying Wanga9d39e32018-08-14 13:47:32 +08001/*
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
Patrick Venture0d9377d2018-11-01 19:34:59 -070017
Naveen Moses3bd1cfc2022-02-14 18:04:20 +053018#include <nlohmann/json.hpp>
Patrick Venture0d9377d2018-11-01 19:34:59 -070019#include <sdbusplus/bus.hpp>
Naveen Mosesdd5495c2021-12-03 22:40:46 +053020#include <string>
21#include <vector>
Patrick Venture0d9377d2018-11-01 19:34:59 -070022
Naveen Mosesdd5495c2021-12-03 22:40:46 +053023// this struct has the gpio config for single gpio
24struct gpioInfo
Matt Spinler8605bdf2018-11-05 14:55:46 -060025{
Naveen Mosesdd5495c2021-12-03 22:40:46 +053026 int fd; // io fd mapped with the gpio
27 uint32_t number;
28 std::string direction;
29};
30
31// this struct represents button interface
32struct buttonConfig
33{
Naveen Moses3bd1cfc2022-02-14 18:04:20 +053034 std::string formFactorName; // name of the button interface
35 std::vector<gpioInfo> gpios; // holds single or group gpio config
36 nlohmann::json extraJsonInfo; // corresponding to button interface
Naveen Mosesdd5495c2021-12-03 22:40:46 +053037};
38
39/**
40 * @brief iterates over the list of gpios and configures gpios them
41 * config which is set from gpio defs json file.
42 * The fd of the configured gpio is stored in buttonConfig.gpios container
43 * @return int returns 0 on successful config of all gpios
44 */
45
Naveen Mosesa1af3292021-12-15 11:47:01 +053046int configGroupGpio(buttonConfig& buttonCfg);
Naveen Mosesdd5495c2021-12-03 22:40:46 +053047
48/**
49 * @brief configures and initializes the single gpio
50 * @return int returns 0 on successful config of all gpios
51 */
52
Naveen Mosesa1af3292021-12-15 11:47:01 +053053int configGpio(gpioInfo& gpioConfig);
Naveen Mosesdd5495c2021-12-03 22:40:46 +053054
55uint32_t getGpioNum(const std::string& gpioPin);
56void closeGpio(int fd);
Naveen Moses3bd1cfc2022-02-14 18:04:20 +053057// global json object which holds gpio_defs.json configs
58extern nlohmann::json gpioDefs;