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