forked from nns779/px4_drv
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathitedtv_bus.h
115 lines (96 loc) · 2.46 KB
/
itedtv_bus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// SPDX-License-Identifier: GPL-2.0-only
/*
* ITE IT930x bus driver definitions (itedtv_bus.h)
*
* Copyright (c) 2018-2021 nns779
*/
#ifndef __ITEDTV_BUS_H__
#define __ITEDTV_BUS_H__
#ifdef __linux__
#include <linux/device.h>
#include <linux/usb.h>
#elif defined(_WIN32) || defined(_WIN64)
#include "misc_win.h"
#include "winusb_compat.h"
#endif
enum itedtv_bus_type {
ITEDTV_BUS_NONE = 0,
ITEDTV_BUS_USB,
};
typedef int (*itedtv_bus_stream_handler_t)(void *context, void *buf, u32 len);
struct itedtv_bus;
struct itedtv_bus_operations {
int (*ctrl_tx)(struct itedtv_bus *bus, void *buf, int len);
int (*ctrl_rx)(struct itedtv_bus *bus, void *buf, int *len);
int (*stream_rx)(struct itedtv_bus *bus,
void *buf, int *len,
int timeout);
int (*start_streaming)(struct itedtv_bus *bus,
itedtv_bus_stream_handler_t stream_handler,
void *context);
int (*stop_streaming)(struct itedtv_bus *bus);
};
struct itedtv_bus {
struct device *dev;
enum itedtv_bus_type type;
union {
struct {
struct usb_device *dev;
int ctrl_timeout;
int max_bulk_size;
struct {
u32 urb_buffer_size;
u32 urb_num;
bool no_dma; // for Linux
bool no_raw_io; // for Windows(WinUSB)
} streaming;
void *priv;
} usb;
};
struct itedtv_bus_operations ops;
};
#ifdef __cplusplus
extern "C" {
#endif
int itedtv_bus_init(struct itedtv_bus *bus);
int itedtv_bus_term(struct itedtv_bus *bus);
#ifdef __cplusplus
}
#endif
static inline int itedtv_bus_ctrl_tx(struct itedtv_bus *bus,
void *buf, int len)
{
if (!bus || !bus->ops.ctrl_tx)
return -EINVAL;
return bus->ops.ctrl_tx(bus, buf, len);
}
static inline int itedtv_bus_ctrl_rx(struct itedtv_bus *bus,
void *buf, int *len)
{
if (!bus || !bus->ops.ctrl_rx)
return -EINVAL;
return bus->ops.ctrl_rx(bus, buf, len);
}
static inline int itedtv_bus_stream_rx(struct itedtv_bus *bus,
void *buf, int *len,
int timeout)
{
if (!bus || !bus->ops.stream_rx)
return -EINVAL;
return bus->ops.stream_rx(bus, buf, len, timeout);
}
static inline int itedtv_bus_start_streaming(struct itedtv_bus *bus,
itedtv_bus_stream_handler_t stream_handler,
void *context)
{
if (!bus || !bus->ops.start_streaming)
return -EINVAL;
return bus->ops.start_streaming(bus, stream_handler, context);
}
static inline int itedtv_bus_stop_streaming(struct itedtv_bus *bus)
{
if (!bus || !bus->ops.stop_streaming)
return -EINVAL;
return bus->ops.stop_streaming(bus);
}
#endif