21aa13bf408756b7255d10c0f8cdfd51b8f2b2d7
[reactos.git] / reactos / drivers / dd / mpu401 / mpu401.h
1 /*
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/dd/mpu401/mpu401.h
6 * PURPOSE: MPU-401 MIDI device driver header
7 * PROGRAMMER: Andrew Greenwood
8 * UPDATE HISTORY:
9 * Sept 26, 2003: Created
10 */
11
12 #ifndef __INCLUDES_MPU401_H__
13 #define __INCLUDES_MPU401_H__
14
15 //#include <mmsystem.h>
16 //#include <mmddk.h>
17 //#include <winioctl.h>
18 #include "../../../lib/mmdrv/mmdef.h"
19
20 #define DEFAULT_PORT 0x330
21 #define DEFAULT_IRQ 9
22
23 #define DEVICE_SUBKEY L"Devices"
24 #define PARMS_SUBKEY L"Parameters"
25
26 #define REGISTRY_PORT L"Port"
27
28 // At the moment, we just support a single device with fixed parameters:
29 #define MPU401_PORT DEFAULT_PORT
30 #define MPU401_IRQ DEFAULT_IRQ
31
32 #define MPU401_TIMEOUT 10000
33
34 /* OBSOLETE - see mmdef.h instead:
35 #define IOCTL_SOUND_BASE FILE_DEVICE_SOUND
36 // wave base 0
37 #define IOCTL_MIDI_BASE 0x0080
38
39 #define IOCTL_MIDI_GET_CAPABILITIES CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0001, METHOD_BUFFERED, FILE_READ_ACCESS)
40 #define IOCTL_MIDI_SET_STATE CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0002, METHOD_BUFFERED, FILE_WRITE_ACCESS)
41 #define IOCTL_MIDI_GET_STATE CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0003, METHOD_BUFFERED, FILE_WRITE_ACCESS)
42 #define IOCTL_MIDI_SET_VOLUME CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0004, METHOD_BUFFERED, FILE_READ_ACCESS)
43 #define IOCTL_MIDI_GET_VOLUME CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0005, METHOD_BUFFERED, FILE_READ_ACCESS)
44 #define IOCTL_MIDI_PLAY CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0006, METHOD_BUFFERED, FILE_WRITE_ACCESS)
45 #define IOCTL_MIDI_RECORD CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0007, METHOD_BUFFERED, FILE_WRITE_ACCESS)
46 #define IOCTL_MIDI_CACHE_PATCHES CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0008, METHOD_BUFFERED, FILE_WRITE_ACCESS)
47 #define IOCTL_MIDI_CACHE_DRUM_PATCHES CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0009, METHOD_BUFFERED, FILE_WRITE_ACCESS)
48 */
49
50 // The MPU-401 has 2 ports, usually 0x330 and 0x331, which are known as
51 // "data" and "status/command", respectively. These macros deal with
52 // reading from and writing to these ports:
53
54 #define MPU401_WRITE_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp, x)
55 #define MPU401_READ_DATA(bp) READ_PORT_UCHAR((PUCHAR) bp)
56 #define MPU401_WRITE_COMMAND(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+1, x)
57 #define MPU401_READ_STATUS(bp) READ_PORT_UCHAR((PUCHAR) bp+1)
58
59
60 // Flow control
61
62 #define MPU401_READY_TO_SEND(bp) \
63 MPU401_READ_STATUS(bp) & 0x80
64
65 #define MPU401_READY_TO_RECEIVE(bp) \
66 MPU401_READ_STATUS(bp) & 0x40
67
68
69 #define MPU401_WRITE_BYTE(bp, x) \
70 if (WaitToSend(bp)) MPU401_WRITE_DATA(bp, x)
71
72 #define MPU401_WRITE_MESSAGE(bp, status, da, db) \
73 MPU401_WRITE(bp, status); \
74 MPU401_WRITE(bp, da); \
75 MPU401_WRITE(bp, db)
76
77 //#define MPU401_READ(bp)
78 // if (WaitToRead(bp)) ... ???
79
80 /*
81 DEVICE_EXTENSION contains the settings for each individual device
82 */
83
84 typedef struct _DEVICE_EXTENSION
85 {
86 PUNICODE_STRING RegistryPath;
87 PDRIVER_OBJECT DriverObject;
88 UINT Port;
89 UINT IRQ;
90 // KDPC Dpc;
91 // KTIMER Timer;
92 // KEVENT Event;
93 // BOOLEAN BeepOn;
94 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
95
96 /*
97 DEVICE_INSTANCE contains ???
98 */
99
100 typedef struct _DEVICE_INSTANCE
101 {
102 // pPrevGDI
103 PDRIVER_OBJECT DriverObject;
104 } DEVICE_INSTANCE, *PDEVICE_INSTANCE;
105
106 /*
107 CONFIG contains device parameters (port/IRQ)
108 THIS STRUCTURE IS REDUNDANT
109 */
110
111 //typedef struct _CONFIG
112 //{
113 // UINT Port;
114 // UINT IRQ;
115 //} CONFIG, *PCONFIG;
116
117 /*
118 Some callback typedefs
119 */
120
121 typedef NTSTATUS REGISTRY_CALLBACK_ROUTINE(PWSTR RegistryPath, PVOID Context);
122 typedef REGISTRY_CALLBACK_ROUTINE *PREGISTRY_CALLBACK_ROUTINE;
123
124
125 /*
126 Prototypes for functions in portio.c :
127 */
128
129 BOOLEAN WaitToSend(UINT BasePort);
130 BOOLEAN WaitToReceive(UINT BasePort);
131 BOOLEAN InitUARTMode(UINT BasePort);
132
133 /*
134 Prototypes for functions in settings.c :
135 */
136
137 NTSTATUS STDCALL EnumDeviceKeys(
138 IN PUNICODE_STRING RegistryPath,
139 IN PWSTR SubKey,
140 IN PREGISTRY_CALLBACK_ROUTINE Callback,
141 IN PVOID Context);
142
143 NTSTATUS STDCALL LoadSettings(
144 IN PWSTR ValueName,
145 IN ULONG ValueType,
146 IN PVOID ValueData,
147 IN ULONG ValueLength,
148 IN PVOID Context,
149 IN PVOID EntryContext);
150
151 NTSTATUS STDCALL
152 DriverEntry(PDRIVER_OBJECT DriverObject,
153 PUNICODE_STRING RegistryPath);
154
155 #endif