ApraLinuxUtils 1.0.0
C++ utility library for embedded Linux systems
 
Loading...
Searching...
No Matches
GPIO.h
Go to the documentation of this file.
1/*
2 * GPIO.h
3 *
4 * Copyright (c) 2024 Apra Labs
5 *
6 * This file is part of ApraUtils.
7 *
8 * Licensed under the MIT License.
9 * See LICENSE file in the project root for full license information.
10 */
11
12#ifndef INCLUDES_APRA_GPIO_H_
13#define INCLUDES_APRA_GPIO_H_
14
15#include <sys/types.h>
16#include <string>
17
18#define SYS_GPIO_PATH "/sys/class/gpio"
19
24
25namespace apra
26{
27class GPIO
28{
29public:
30 GPIO(uint gpioNo);
31 virtual ~GPIO();
32 bool Init(bool isRead);
33 bool Init4EdgeInterrupt(bool isRead, GPIO_EDGES edge);
34 bool UnInit();
35 int Open();
36 bool Close();
37 int Read();
38 int ReadWithInterrupt(unsigned long uSecTout);
39 bool Write(bool makeHigh);
40 int& GetGPIODescriptor();
41 static int ReadOnce(uint gpioNo);
42 static bool WriteOnce(uint gpioNo, bool makeHigh);
43private:
44 bool Export();
45 bool SetDirection(bool isRead);
46 bool SetGPIOEdgeEvent(GPIO_EDGES edge);
47 bool UnExport();
48 std::string GPIO_EDGES_STR(GPIO_EDGES edge);
49
50 int m_fd;
51 uint m_gpio;
52 bool m_isRead;
53};
54}
55
56#endif /* INCLUDES_APRA_GPIO_H_ */
GPIO_EDGES
Definition GPIO.h:21
@ BOTH
Definition GPIO.h:22
@ NONE
Definition GPIO.h:22
@ FALLING
Definition GPIO.h:22
@ RISING
Definition GPIO.h:22
static int ReadOnce(uint gpioNo)
Definition GPIO.cpp:241
int & GetGPIODescriptor()
Definition GPIO.cpp:267
static bool WriteOnce(uint gpioNo, bool makeHigh)
Definition GPIO.cpp:254
int Open()
Definition GPIO.cpp:77
bool Close()
Definition GPIO.cpp:91
int ReadWithInterrupt(unsigned long uSecTout)
Definition GPIO.cpp:272
bool UnInit()
Definition GPIO.cpp:72
bool Init(bool isRead)
Definition GPIO.cpp:52
virtual ~GPIO()
Definition GPIO.cpp:30
bool Write(bool makeHigh)
Definition GPIO.cpp:226
int Read()
Definition GPIO.cpp:205
bool Init4EdgeInterrupt(bool isRead, GPIO_EDGES edge)
Definition GPIO.cpp:62