Files
remote-ui/server/gpio/gpio.hpp
T
sani7 84b1ccd7d0 gpio
move configuring to separate function instead of in constructor
2026-02-14 14:31:16 +01:00

69 lines
1.6 KiB
C++

#ifndef GPIO_HPP
#define GPIO_HPP
#include <QObject>
#ifdef __aarch64__
#include <gpiod.h>
#else
struct gpiod_line_request
{
};
struct gpiod_request_config
{
};
struct gpiod_line_settings
{
};
struct gpiod_line_config
{
};
struct gpiod_chip
{
};
enum gpiod_line_value
{
GPIOD_LINE_VALUE_ERROR = -1,
/**< Returned to indicate an error when reading the value. */
GPIOD_LINE_VALUE_INACTIVE = 0,
/**< Line is logically inactive. */
GPIOD_LINE_VALUE_ACTIVE = 1,
/**< Line is logically active. */
};
enum gpiod_line_direction
{
GPIOD_LINE_DIRECTION_AS_IS = 1,
/**< Request the line(s), but don't change direction. */
GPIOD_LINE_DIRECTION_INPUT,
/**< Direction is input - for reading the value of an externally driven
* GPIO line. */
GPIOD_LINE_DIRECTION_OUTPUT,
/**< Direction is output - for driving the GPIO line. */
};
#endif
class GPIO : public QObject
{
Q_OBJECT
public:
enum Direction
{
Input,
Output
};
explicit GPIO(QObject *parent = nullptr);
~GPIO();
void configure_pin(Direction dir, uint8_t gpio, bool state = false);
void set_value(bool val);
bool value();
private:
struct gpiod_line_request *request_output_line(const char *chip_path, unsigned int offset,
enum gpiod_line_value value, const char *consumer);
struct gpiod_line_request *request_input_line(const char *chip_path, unsigned int offset, const char *consumer);
struct gpiod_line_request *m_request;
unsigned int m_offset;
};
#endif // GPIO_HPP