Rishka
RISC-V virtual runtime in C/C++ made for ESP32-WROVER
gpio.h
Go to the documentation of this file.
1/*
2 * This file is part of the Rishka distribution (https://github.com/nthnn/rishka).
3 * Copyright (c) 2024 Nathanne Isip.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
27#ifndef LIBRISHKA_GPIO_H
28#define LIBRISHKA_GPIO_H
29
30#include <librishka/types.h>
31
40typedef enum {
41 GPIO_INPUT = 0x01,
42 GPIO_OUTPUT = 0x03,
43 GPIO_INPUT_PULLUP = 0x05
45
53typedef enum {
54 GPIO_LOW = 0x0,
55 GPIO_HIGH = 0x1
57
67class Gpio final {
68public:
77 static void pin_mode(u8 pin, gpio_pin_mode_t mode);
78
87 static gpio_mode_t digital_read(u8 pin);
88
97 static void digital_write(u8 pin, gpio_mode_t mode);
98
107 static u16 analog_read(u8 pin);
108
117 static void analog_write(u8 pin, u16 value);
118
130 static u64 pulse_in(u8 pin, u8 state, u64 timeout);
131
143 static u64 pulse_in_long(u8 pin, u8 state, u64 timeout);
144
156 static u8 shift_in(u8 data, u8 clock, u8 bit_order);
157
169 static void shift_out(u8 data, u8 clock, u8 bit_order, u8 value);
170
180 static void tone(u32 frequency, u64 duration);
181
187 static void no_tone();
188};
189
190#endif /* LIBRISHKA_GPIO_H */
Class for handling GPIO operations in Rishka applications.
Definition: gpio.h:67
static u64 pulse_in_long(u8 pin, u8 state, u64 timeout)
Measure the duration of a long pulse on a GPIO pin.
Definition: librishka_gpio.cpp:45
static u8 shift_in(u8 data, u8 clock, u8 bit_order)
Shift in data from a digital input pin.
Definition: librishka_gpio.cpp:49
static void shift_out(u8 data, u8 clock, u8 bit_order, u8 value)
Shift out data to a digital output pin.
Definition: librishka_gpio.cpp:53
static u64 pulse_in(u8 pin, u8 state, u64 timeout)
Measure the duration of a pulse on a GPIO pin.
Definition: librishka_gpio.cpp:41
static gpio_mode_t digital_read(u8 pin)
Read the digital value of a GPIO pin.
Definition: librishka_gpio.cpp:25
static void digital_write(u8 pin, gpio_mode_t mode)
Write a digital value to a GPIO pin.
Definition: librishka_gpio.cpp:29
static u16 analog_read(u8 pin)
Read the analog value of a GPIO pin.
Definition: librishka_gpio.cpp:33
static void tone(u32 frequency, u64 duration)
Generate a tone of the specified frequency and duration on GPIO25.
Definition: librishka_gpio.cpp:57
static void pin_mode(u8 pin, gpio_pin_mode_t mode)
Set the mode of a GPIO pin.
Definition: librishka_gpio.cpp:21
static void no_tone()
Stop generating a tone on GPIO25.
Definition: librishka_gpio.cpp:61
static void analog_write(u8 pin, u16 value)
Write an analog value to a GPIO pin.
Definition: librishka_gpio.cpp:37
gpio_mode_t
Enum representing the digital modes for GPIO pins.
Definition: gpio.h:53
@ GPIO_HIGH
Definition: gpio.h:55
@ GPIO_LOW
Definition: gpio.h:54
gpio_pin_mode_t
Enum representing the pin modes for GPIO pins.
Definition: gpio.h:40
@ GPIO_INPUT
Definition: gpio.h:41
@ GPIO_OUTPUT
Definition: gpio.h:42
@ GPIO_INPUT_PULLUP
Definition: gpio.h:43
Header file for common data types used in Rishka applications.
unsigned int u32
Alias for the unsigned 32-bit integer type.
Definition: types.h:82
unsigned short int u16
Alias for the unsigned 16-bit integer type.
Definition: types.h:76
unsigned char u8
Alias for the unsigned 8-bit integer type.
Definition: types.h:70
unsigned long int u64
Alias for the unsigned 64-bit integer type.
Definition: types.h:88