1 | /*
|
---|
2 | * midi usb driver
|
---|
3 | * usb_midi.h
|
---|
4 | *
|
---|
5 | * Copyright 2006-2011 Haiku Inc. All rights reserved.
|
---|
6 | * Distributed under the terms of the MIT Licence.
|
---|
7 | *
|
---|
8 | * Authors:
|
---|
9 | * Jérôme Duval
|
---|
10 | * Pete Goodeve, pete.goodeve@computer.org
|
---|
11 | *
|
---|
12 | * Some portions of this code were originally derived from
|
---|
13 | * USB Joystick driver for BeOS R5
|
---|
14 | * Copyright 2000 (C) ITO, Takayuki
|
---|
15 | * All rights reserved
|
---|
16 | *
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | #include <Drivers.h>
|
---|
21 | #include <USB.h>
|
---|
22 | #include <usb/USB_midi.h>
|
---|
23 |
|
---|
24 | #include "ring_buffer.h"
|
---|
25 |
|
---|
26 | /* Three levels of printout for convenience: */
|
---|
27 | /* #define DEBUG 1 -- more convenient to define in the code file when needed */
|
---|
28 | #define DEBUG_INFO 1
|
---|
29 | #define DEBUG_ERR 1
|
---|
30 |
|
---|
31 | /* Normally leave this enabled to leave a record in syslog */
|
---|
32 | #if DEBUG_ERR
|
---|
33 | #define DPRINTF_ERR(x) dprintf x
|
---|
34 | #else
|
---|
35 | #define DPRINTF_ERR(x)
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | /* Use this for initialization etc. messages -- nothing repetitive: */
|
---|
39 | #if DEBUG_INFO
|
---|
40 | #define DPRINTF_INFO(x) dprintf x
|
---|
41 | #else
|
---|
42 | #define DPRINTF_INFO(x)
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | /* Enable this to record detailed stuff: */
|
---|
46 | #if DEBUG
|
---|
47 | #define DPRINTF_DEBUG(x) dprintf x
|
---|
48 | #else
|
---|
49 | #define DPRINTF_DEBUG(x)
|
---|
50 | #endif
|
---|
51 |
|
---|
52 |
|
---|
53 | /* driver specific definitions */
|
---|
54 |
|
---|
55 | #define DRIVER_NAME "usb_midi"
|
---|
56 |
|
---|
57 | #define MY_ID "\033[34m" DRIVER_NAME ":\033[m "
|
---|
58 | #define MY_ERR "\033[31merror:\033[m "
|
---|
59 | #define MY_WARN "\033[31mwarning:\033[m "
|
---|
60 | #define assert(x) \
|
---|
61 | ((x) ? 0 : dprintf(MY_ID "assertion failed at " \
|
---|
62 | __FILE__ ", line %d\n", __LINE__))
|
---|
63 |
|
---|
64 | #define DEFAULT_CONFIGURATION 0
|
---|
65 |
|
---|
66 | struct driver_cookie;
|
---|
67 |
|
---|
68 |
|
---|
69 | typedef struct usbmidi_device_info
|
---|
70 | {
|
---|
71 | /* list structure */ /* should not be needed eventually */
|
---|
72 | struct usbmidi_device_info* next;
|
---|
73 |
|
---|
74 | /* Set of actual ports ("cables" -- one or more) */
|
---|
75 | struct usbmidi_port_info* ports[16];
|
---|
76 |
|
---|
77 | /* maintain device (common for all ports) */
|
---|
78 | sem_id sem_lock;
|
---|
79 | sem_id sem_send;
|
---|
80 | area_id buffer_area;
|
---|
81 | usb_midi_event_packet* buffer; /* input buffer & base of area */
|
---|
82 | usb_midi_event_packet* out_buffer; /* above input buffer */
|
---|
83 | size_t buffer_size; /* for each of in and out buffers */
|
---|
84 |
|
---|
85 | const usb_device* dev;
|
---|
86 | uint16 ifno;
|
---|
87 | int devnum; /* unique device number */
|
---|
88 | char name[20];
|
---|
89 | /* = "/dev/midi/usb/n" --port number will be appended to this */
|
---|
90 |
|
---|
91 | bool active;
|
---|
92 |
|
---|
93 | /* work area for transfer */
|
---|
94 | int bus_status;
|
---|
95 | int actual_length;
|
---|
96 | const usb_endpoint_info* ept_in;
|
---|
97 | const usb_endpoint_info* ept_out;
|
---|
98 |
|
---|
99 | bigtime_t timestamp; /* Is this needed? Currently set but never read */
|
---|
100 | uint flags; /* set to 0 but never used */
|
---|
101 | } usbmidi_device_info;
|
---|
102 |
|
---|
103 |
|
---|
104 | typedef struct usbmidi_port_info
|
---|
105 | {
|
---|
106 | /* list structure for manager */
|
---|
107 | struct usbmidi_port_info* next;
|
---|
108 |
|
---|
109 | /* Common device that does the work */
|
---|
110 | usbmidi_device_info* device;
|
---|
111 |
|
---|
112 | /* Port-specific variables */
|
---|
113 | char name[40]; /* complete pathname of this port */
|
---|
114 | struct ring_buffer* rbuf;
|
---|
115 |
|
---|
116 | int cable; /* index of this port */
|
---|
117 | bool has_in, has_out;
|
---|
118 |
|
---|
119 | int open;
|
---|
120 | struct driver_cookie* open_fd;
|
---|
121 |
|
---|
122 | } usbmidi_port_info;
|
---|
123 |
|
---|
124 |
|
---|
125 | /*
|
---|
126 | usb_midi.c
|
---|
127 | */
|
---|
128 |
|
---|
129 | extern usb_module_info* usb;
|
---|
130 | extern const char* usb_midi_base_name;
|
---|
131 |
|
---|
132 | usbmidi_port_info*
|
---|
133 | create_usbmidi_port(usbmidi_device_info* devinfo,
|
---|
134 | int cable, bool has_in, bool has_out);
|
---|
135 |
|
---|
136 | void
|
---|
137 | remove_port(usbmidi_port_info* port);
|
---|
138 |
|
---|
139 | usbmidi_device_info*
|
---|
140 | create_device(const usb_device* dev, uint16 ifno);
|
---|
141 | /* ifno not actually used -- left in for now */
|
---|
142 |
|
---|
143 | void
|
---|
144 | remove_device(usbmidi_device_info* my_dev);
|
---|
145 |
|
---|
146 |
|
---|
147 | /*
|
---|
148 | devlist.c
|
---|
149 | */
|
---|
150 |
|
---|
151 | extern sem_id usbmidi_port_list_lock;
|
---|
152 | extern bool usbmidi_port_list_changed;
|
---|
153 |
|
---|
154 | void
|
---|
155 | add_port_info(usbmidi_port_info* port);
|
---|
156 |
|
---|
157 | void
|
---|
158 | remove_port_info(usbmidi_port_info* port);
|
---|
159 |
|
---|
160 | usbmidi_port_info*
|
---|
161 | search_port_info(const char* name);
|
---|
162 |
|
---|
163 | int
|
---|
164 | find_free_device_number(void);
|
---|
165 |
|
---|
166 | extern char** usbmidi_port_names;
|
---|
167 |
|
---|
168 | void
|
---|
169 | alloc_port_names(void);
|
---|
170 |
|
---|
171 | void
|
---|
172 | free_port_names(void);
|
---|
173 |
|
---|
174 | void
|
---|
175 | rebuild_port_names(void);
|
---|