xref: /haiku/src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
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 #include "ring_buffer.h"
38 
39 #define DEBUG 1
40 #if DEBUG
41 	#define	DPRINTF_INFO(x)	dprintf x
42 	#define	DPRINTF_ERR(x)	dprintf x
43 #else
44 	#define DPRINTF_INFO(x)
45 	#define DPRINTF_ERR(x)	dprintf x
46 #endif
47 
48 /* driver specific definitions */
49 
50 #define	DRIVER_NAME	"usb_midi"
51 
52 #define	MY_ID	"\033[34m" DRIVER_NAME ":\033[m "
53 #define	MY_ERR	"\033[31merror:\033[m "
54 #define	MY_WARN	"\033[31mwarning:\033[m "
55 #define	assert(x) \
56 	((x) ? 0 : dprintf (MY_ID "assertion failed at " __FILE__ ", line %d\n", __LINE__))
57 
58 /* 0-origin */
59 #define	DEFAULT_CONFIGURATION	0
60 
61 #define	BUF_SIZ	B_PAGE_SIZE
62 
63 struct driver_cookie;
64 
65 typedef struct my_device_info
66 {
67 	/* list structure */
68 	struct my_device_info *next;
69 
70 	/* maintain device */
71 	sem_id sem_cb;
72 	sem_id sem_lock;
73 	area_id buffer_area;
74 	void *buffer;
75 
76 	const usb_device *dev;
77 	uint16 ifno;
78 	char name[30];
79 
80 	struct ring_buffer *rbuf;
81 
82 	bool active;
83 	int open;
84 	struct driver_cookie *open_fds;
85 
86 	/* workarea for transfer */
87 	int usbd_status, bus_status, cmd_status;
88 	int actual_length;
89 	const usb_endpoint_info *ept;
90 
91 	size_t total_report_size;
92 	bigtime_t timestamp;
93 	uint flags;
94 } my_device_info;
95 
96 /* usb_midi.c */
97 
98 extern usb_module_info *usb;
99 extern const char *usb_midi_base_name;
100 
101 my_device_info *
102 create_device (const usb_device *dev, const usb_interface_info *ii, uint16 ifno);
103 
104 void
105 remove_device (my_device_info *my_dev);
106 
107 /* devlist.c */
108 
109 extern sem_id my_device_list_lock;
110 extern bool my_device_list_changed;
111 
112 void add_device_info (my_device_info *my_dev);
113 void remove_device_info (my_device_info *my_dev);
114 my_device_info *search_device_info (const char *name);
115 
116 extern char **my_device_names;
117 
118 void alloc_device_names (void);
119 void free_device_names (void);
120 void rebuild_device_names (void);
121