Skip to content

Commit 6061aae

Browse files
committed
feat(iface/gpio): Introduce GPIO interface
1 parent 18ffdd9 commit 6061aae

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

services/interfaces/gpio.h

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later
2+
*
3+
* GPIO interface
4+
*
5+
* Copyright (c) 2024, Marek Koza (qyx@krtko.org)
6+
* All rights reserved.
7+
*/
8+
9+
#pragma once
10+
11+
#include <stdint.h>
12+
#include <stdbool.h>
13+
#include <stddef.h>
14+
15+
typedef enum {
16+
GPIO_RET_OK = 0,
17+
GPIO_RET_FAILED,
18+
} gpio_ret_t;
19+
20+
enum gpio_mode {
21+
MODE_INPUT,
22+
MODE_OUTPUT,
23+
MODE_ALTERNATE,
24+
MODE_ANALOG,
25+
};
26+
27+
enum gpio_pull {
28+
PULL_NONE,
29+
PULL_WEAK,
30+
PULL_STRONG,
31+
};
32+
33+
enum gpio_otype {
34+
OTYPE_PP,
35+
OTYPE_OD,
36+
};
37+
38+
typedef struct gpio Gpio;
39+
40+
struct gpio_vmt {
41+
gpio_ret_t (*set)(Gpio *self, bool state);
42+
gpio_ret_t (*get)(Gpio *self, bool *state);
43+
gpio_ret_t (*toggle)(Gpio *self);
44+
gpio_ret_t (*set_mode)(Gpio *self, enum gpio_mode mode);
45+
gpio_ret_t (*set_pinmux)(Gpio *self, uint32_t mux);
46+
gpio_ret_t (*set_pull)(Gpio *self, enum gpio_pull pull);
47+
gpio_ret_t (*set_otype)(Gpio *self, enum gpio_otype otype);
48+
};
49+
50+
51+
typedef struct gpio {
52+
const struct gpio_vmt *vmt;
53+
void *parent;
54+
} Gpio;
55+

0 commit comments

Comments
 (0)