xref: /haiku/src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 /*****************************************************************************/
2 // midi usb driver
3 // Written by Jérôme Duval
4 //
5 // usb_midi.h
6 //
7 // Copyright (c) 2006 Haiku Project
8 //
9 // 	Some portions of code are copyrighted by
10 //	USB Joystick driver for BeOS R5
11 //	Copyright 2000 (C) ITO, Takayuki
12 //	All rights reserved
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 /*****************************************************************************/
32 
33 #include <Drivers.h>
34 #include <USB.h>
35 #include <usb/USB_midi.h>
36 
37 /* Undocumented kernel cbuf_* functions */
38 struct cbuffer_t;
39 typedef struct cbuffer_t cbuffer;
40 
41 size_t cbuf_getn_no_lock(cbuffer *, char *, size_t);
42 size_t cbuf_putn_no_lock(cbuffer *, char *, size_t);
43 cbuffer *cbuf_init(size_t size);
44 void cbuf_delete(cbuffer *buffer);
45 char cbuf_get(cbuffer *);
46 bool cbuf_mt(cbuffer *);
47 bool cbuf_full(cbuffer *);
48 status_t cbuf_put(cbuffer *, char);
49 status_t cbuf_unput(cbuffer *);
50 void cbuf_flush(cbuffer *);
51 size_t cbuf_size(cbuffer *);
52 size_t cbuf_avail(cbuffer *);
53 size_t cbuf_free(cbuffer *);
54 size_t cbuf_putn(cbuffer *, void *, size_t num_bytes);
55 size_t cbuf_getn(cbuffer *, void *, size_t num_bytes);
56 cpu_status cbuf_lock(cbuffer *);
57 void cbuf_unlock(cbuffer *, cpu_status);
58 
59 #define DEBUG 1
60 #if DEBUG
61 	#define	DPRINTF_INFO(x)	dprintf x
62 	#define	DPRINTF_ERR(x)	dprintf x
63 #else
64 	#define DPRINTF_INFO(x)
65 	#define DPRINTF_ERR(x)	dprintf x
66 #endif
67 
68 /* driver specific definitions */
69 
70 #define	DRIVER_NAME	"usb_midi"
71 
72 #define	MY_ID	"\033[34m" DRIVER_NAME ":\033[m "
73 #define	MY_ERR	"\033[31merror:\033[m "
74 #define	MY_WARN	"\033[31mwarning:\033[m "
75 #define	assert(x) \
76 	((x) ? 0 : dprintf (MY_ID "assertion failed at " __FILE__ ", line %d\n", __LINE__))
77 
78 /* 0-origin */
79 #define	DEFAULT_CONFIGURATION	0
80 
81 #define	BUF_SIZ	B_PAGE_SIZE
82 
83 struct driver_cookie;
84 
85 typedef struct my_device_info
86 {
87 	/* list structure */
88 	struct my_device_info *next;
89 
90 	/* maintain device */
91 	sem_id sem_cb;
92 	sem_id sem_lock;
93 	area_id buffer_area;
94 	void *buffer;
95 
96 	const usb_device *dev;
97 	uint16 ifno;
98 	char name[30];
99 
100 	cbuffer *cbuf;
101 
102 	bool active;
103 	int open;
104 	struct driver_cookie *open_fds;
105 
106 	/* workarea for transfer */
107 	int usbd_status, bus_status, cmd_status;
108 	int actual_length;
109 	const usb_endpoint_info *ept;
110 
111 	size_t total_report_size;
112 	bigtime_t timestamp;
113 	uint flags;
114 } my_device_info;
115 
116 /* usb_midi.c */
117 
118 extern usb_module_info *usb;
119 extern const char *usb_midi_base_name;
120 
121 my_device_info *
122 create_device (const usb_device *dev, const usb_interface_info *ii, uint16 ifno);
123 
124 void
125 remove_device (my_device_info *my_dev);
126 
127 /* devlist.c */
128 
129 extern sem_id my_device_list_lock;
130 extern bool my_device_list_changed;
131 
132 void add_device_info (my_device_info *my_dev);
133 void remove_device_info (my_device_info *my_dev);
134 my_device_info *search_device_info (const char *name);
135 
136 extern char **my_device_names;
137 
138 void alloc_device_names (void);
139 void free_device_names (void);
140 void rebuild_device_names (void);
141