2021-04-15 13:47:33 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
#ifndef IODEV_H
|
|
|
|
#define IODEV_H
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
2021-05-14 20:47:43 +00:00
|
|
|
typedef enum _iodev_id_t {
|
|
|
|
IODEV_UART,
|
|
|
|
IODEV_FB,
|
|
|
|
IODEV_USB0,
|
|
|
|
IODEV_USB1,
|
|
|
|
IODEV_USB0_SEC,
|
|
|
|
IODEV_USB1_SEC,
|
|
|
|
IODEV_MAX,
|
|
|
|
} iodev_id_t;
|
2021-04-15 13:47:33 +00:00
|
|
|
|
|
|
|
typedef enum _iodev_usage_t {
|
|
|
|
USAGE_CONSOLE = BIT(0),
|
|
|
|
USAGE_UARTPROXY = BIT(1),
|
|
|
|
} iodev_usage_t;
|
|
|
|
|
|
|
|
struct iodev_ops {
|
|
|
|
bool (*can_read)(void *opaque);
|
|
|
|
bool (*can_write)(void *opaque);
|
|
|
|
ssize_t (*read)(void *opaque, void *buf, size_t length);
|
|
|
|
ssize_t (*write)(void *opaque, const void *buf, size_t length);
|
2021-05-16 10:04:04 +00:00
|
|
|
ssize_t (*queue)(void *opaque, const void *buf, size_t length);
|
2021-05-15 12:01:25 +00:00
|
|
|
void (*flush)(void *opaque);
|
2021-04-17 07:29:03 +00:00
|
|
|
void (*handle_events)(void *opaque);
|
2021-04-15 13:47:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct iodev {
|
|
|
|
const struct iodev_ops *ops;
|
|
|
|
|
|
|
|
iodev_usage_t usage;
|
|
|
|
void *opaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct iodev *iodevs[IODEV_MAX];
|
|
|
|
|
|
|
|
bool iodev_can_read(iodev_id_t id);
|
|
|
|
bool iodev_can_write(iodev_id_t id);
|
|
|
|
ssize_t iodev_read(iodev_id_t id, void *buf, size_t length);
|
|
|
|
ssize_t iodev_write(iodev_id_t id, const void *buf, size_t length);
|
2021-05-16 10:04:04 +00:00
|
|
|
ssize_t iodev_queue(iodev_id_t id, const void *buf, size_t length);
|
2021-05-15 12:01:25 +00:00
|
|
|
void iodev_flush(iodev_id_t id);
|
2021-04-17 07:29:03 +00:00
|
|
|
void iodev_handle_events(iodev_id_t id);
|
2021-04-15 13:47:33 +00:00
|
|
|
|
|
|
|
void iodev_console_write(const void *buf, size_t length);
|
2021-05-04 15:25:22 +00:00
|
|
|
void iodev_console_kick(void);
|
2021-05-15 12:01:25 +00:00
|
|
|
void iodev_console_flush(void);
|
2021-04-15 13:47:33 +00:00
|
|
|
|
2021-04-15 14:17:15 +00:00
|
|
|
static inline void iodev_set_usage(iodev_id_t id, iodev_usage_t usage)
|
|
|
|
{
|
|
|
|
iodevs[id]->usage = usage;
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:47:33 +00:00
|
|
|
#endif
|