📄 detc.c
字号:
/*
Copyright G&G Lab Corporation, All Rights Reserved
Module Name:
Detc.c
*/
#include "ntddk.h"
#include "GG.h"
#include "Detc.h"
#include "debug.h"
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE,GGPowerUp)
#pragma alloc_text(PAGE,GGSetReportRate)
#pragma alloc_text(PAGE,GGSetBaudRate)
#pragma alloc_text(PAGE,GGSetProtocol)
#pragma alloc_text(PAGE,GGDremov)
#endif // ALLOC_PRAGMA
//
// Constants.
//
//
// The status command sent to the mouse.
//
#define GG_STATUS_COMMAND 's'
//
// The query number of mouse buttons command sent to the mouse.
//
#define GG_QUERY_BUTTONS_COMMAND 'k'
//
// Status report from a Detc mouse.
//
#define GG_STATUS 0x4F
//
// Timeout value for the status returned by a Detc mouse.
//
// #define GG_STATUS_DELAY (50 * GG_TO_100_NS)
#define GG_STATUS_DELAY 50
//
// Time (in microconds) needed by the mouse to adapt to a new baud rate.
//
#define GG_BAUDRATE_DELAY (2 * GG_TO_100_NS)
//
// Default baud rate and report rate.
//
#define GG_DEFAULT_BAUDRATE 1200
#define GG_DEFAULT_REPORTRATE 150
//
// Button/status definitions.
//
#define GG_SYNCH_BIT 0x80
#define GG_BUTTON_LEFT 0x04
#define GG_BUTTON_RIGHT 0x01
#define GG_BUTTON_MIDDLE 0x02
#define GG_BUTTON_LEFT_SR 2
#define GG_BUTTON_RIGHT_SL 1
#define GG_BUTTON_MIDDLE_SL 1
#define SIGN_X 0x10
#define SIGN_Y 0x08
//
// Macros.
//
#define sizeofel(x) (sizeof(x)/sizeof(*x))
//
// Type definitions.
//
typedef struct _REPORT_RATE {
CHAR Command;
UCHAR ReportRate;
} REPORT_RATE;
typedef struct _PROTOCOL {
CHAR Command;
SERIAL_LINE_CONTROL LineCtrl;
PPROTOCOL_HANDLER Handler;
} PROTOCOL;
typedef struct _GG_BAUDRATE {
CHAR *Command;
ULONG BaudRate;
} GG_BAUDRATE;
//
// Globals.
//
//
// The baud rate at which we try to detect a mouse.
//
static ULONG BaudRateDremov[] = { 1200, 2400, 4800, 9600 };
//
// This list is indexed by protocol values PROTOCOL_*.
//
PROTOCOL Protocol[] = {
{'S',
// ACE_8BW | ACE_PEN | ACE_1SB,
{ STOP_BIT_1, 0, 8 },
GGHandlerMM
},
{'T',
// ACE_8BW | ACE_1SB,
{ STOP_BIT_1, NO_PARITY, 8 },
NULL
},
{'U',
// ACE_8BW | ACE_1SB,
{ STOP_BIT_1, NO_PARITY, 8 },
NULL
},
{'V',
// ACE_7BW | ACE_1SB,
{ STOP_BIT_1, NO_PARITY, 7 },
NULL
},
{'B',
// ACE_7BW | ACE_PEN | ACE_EPS | ACE_1SB,
{ STOP_BIT_1, EVEN_PARITY, 7 },
NULL
},
{'A',
// ACE_7BW | ACE_PEN | ACE_EPS | ACE_1SB,
{ STOP_BIT_1, EVEN_PARITY, 7 },
NULL
}
};
static REPORT_RATE ReportRateTable[] = {
{'D', 0 },
{'J', 10},
{'K', 20},
{'L', 35},
{'R', 50},
{'M', 70},
{'Q', 100},
{'N', 150},
{'O', 151} // Continuous
};
static GG_BAUDRATE GGBaudRateTable[] = {
{ "*n", 1200 },
{ "*o", 2400 },
{ "*p", 4800 },
{ "*q", 9600 }
};
NTSTATUS
GGPowerUp(
PDEVICE_EXTENSION DeviceExtension
)
/*++
Routine Description:
Powers up the mouse by making the RTS and DTR active.
Arguments:
Port - Pointer to the serial port.
Return Value:
TRUE.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
IO_STATUS_BLOCK iosb;
KEVENT event;
ULONG bits;
ULONG rtsDtr = SERIAL_RTS_STATE | SERIAL_DTR_STATE;
PAGED_CODE();
Print(DeviceExtension, DBG_SS_TRACE, ("(c) PowerUp called\n"));
KeInitializeEvent(&event,
NotificationEvent,
FALSE
);
//
// set DTR
//
Print(DeviceExtension, DBG_SS_NOISE, ("(c) Setting DTR...\n"));
status = SerialMouseIoSyncIoctl(IOCTL_SERIAL_SET_DTR,
DeviceExtension->TopOfStack,
&event,
&iosb
);
//
// set RTS
//
Print(DeviceExtension, DBG_SS_NOISE, ("(c) Setting RTS...\n"));
status = SerialMouseIoSyncIoctl(IOCTL_SERIAL_SET_RTS,
DeviceExtension->TopOfStack,
&event,
&iosb
);
//
// If the lines are high, the power is on for at least 500 ms due to the
// GGMdetc detection.
//
status = SerialMouseIoSyncIoctlEx(IOCTL_SERIAL_GET_MODEGGTATUS,
DeviceExtension->TopOfStack,
&event,
&iosb,
NULL,
0,
&bits,
sizeof(ULONG)
);
if (NT_SUCCESS(status) && ((rtsDtr & bits) == rtsDtr)) {
//
// Wait GG_POWER_UP milliseconds for the mouse to power up
// correctly.
//
Print(DeviceExtension, DBG_SS_INFO,
("(c) Waiting awhile for the mouse to power up\n"));
SerialMouseWait(DeviceExtension,
-GG_POWER_UP
);
}
return status;
}
VOID
GGSetReportRate(
PDEVICE_EXTENSION DeviceExtension,
UCHAR ReportRate
)
/*++
Routine Description:
Set the mouse report rate. This can range from 0 (prompt mode) to
continuous report rate.
Arguments:
Port - Pointer to serial port.
ReportRate - The desired report rate.
Return Value:
None.
--*/
{
LONG count;
PAGED_CODE();
Print(DeviceExtension, DBG_SS_TRACE, ("GGSetReportRate called\n"));
for (count = sizeofel(ReportRateTable) - 1; count >= 0; count--) {
//
// Get the character to send from the table.
//
if (ReportRate >= ReportRateTable[count].ReportRate) {
//
// Set the baud rate.
//
Print(DeviceExtension, DBG_SS_INFO,
("New ReportRate: %u\n",
ReportRateTable[count].ReportRate
));
SerialMouseWriteChar(DeviceExtension, ReportRateTable[count].Command);
break;
}
}
return;
}
VOID
GGSetBaudRate(
PDEVICE_EXTENSION DeviceExtension,
ULONG BaudRate
)
/*++
Routine Description:
Set the new mouse baud rate. This will change the serial port baud rate.
Arguments:
Port - Pointer to the serial port.
BaudRate - Desired baud rate.
BaudClock - The external frequency driving the serial chip.
Return Value:
None.
--*/
{
LONG count;
PAGED_CODE();
Print(DeviceExtension, DBG_SS_TRACE, ("GGSetBaudRate called\n"));
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -