-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Somewhat similar to chardev API, but for GPIO pins - For controllers: Use gpio_pins_out() to signal about pins state change; Hangle gpio->pins_in() & gpio->pins_read() for setting input pins or reading output pins - For devices: Use gpio_pins_in() to write pins to controller, gpio_pins_read() to read output pins; Handle (optionally) gpio->pins_out() to be notified when output pins change - Request for comments
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
gpio_api.h - General-Purpose IO API | ||
Copyright (C) 2024 LekKit <github.com/LekKit> | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef RVVM_GPIO_API_H | ||
#define RVVM_GPIO_API_H | ||
|
||
typedef struct rvvm_gpio_dev rvvm_gpio_dev_t; | ||
|
||
struct rvvm_gpio_dev { | ||
// IO Dev -> GPIO Dev calls | ||
bool (*pins_out)(rvvm_gpio_dev_t* dev, size_t off, uint32_t pins); | ||
|
||
// GPIO Dev -> IO Dev calls | ||
bool (*pins_in)(rvvm_gpio_dev_t* dev, size_t off, uint32_t pins); | ||
uint32_t (*pins_read)(rvvm_gpio_dev_t* dev, size_t off); | ||
|
||
// Common RVVM API features | ||
void (*update)(rvvm_gpio_dev_t* dev); | ||
void (*remove)(rvvm_gpio_dev_t* dev); | ||
|
||
void* data; | ||
void* io_dev; | ||
}; | ||
|
||
static inline bool gpio_pins_out(rvvm_gpio_dev_t* dev, size_t off, uint32_t pins) | ||
{ | ||
if (dev) return dev->pins_out(dev, off, pins); | ||
return false; | ||
} | ||
|
||
static inline bool gpio_pins_in(rvvm_gpio_dev_t* dev, size_t off, uint32_t pins) | ||
{ | ||
if (dev) return dev->pins_in(dev, off, pins); | ||
return false; | ||
} | ||
|
||
static inline uint32_t gpio_pins_read(rvvm_gpio_dev_t* dev, size_t off) | ||
{ | ||
if (dev) return dev->pins_read(dev, off); | ||
return 0; | ||
} | ||
|
||
static inline void gpio_free(rvvm_gpio_dev_t* dev) | ||
{ | ||
if (dev && dev->remove) dev->remove(dev); | ||
} | ||
|
||
static inline void gpio_update(rvvm_gpio_dev_t* dev) | ||
{ | ||
if (dev && dev->update) dev->update(dev); | ||
} | ||
|
||
#endif |