?? cseries.c
字號:
/*++
Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved
Copyright (c) 1993 Logitech Inc.
Module Name:
cseries.c
Abstract:
Environment:
Kernel mode only.
Notes:
Revision History:
--*/
//
// Includes.
//
#include "ntddk.h"
#include "mouser.h"
#include "cseries.h"
#include "debug.h"
//
// Use the alloc_text pragma to specify the driver initialization routines
// (they can be paged out).
//
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE,CSerPowerUp)
#pragma alloc_text(PAGE,CSerSetReportRate)
#pragma alloc_text(PAGE,CSerSetBaudRate)
#pragma alloc_text(PAGE,CSerSetProtocol)
#pragma alloc_text(PAGE,CSerDetect)
#endif // ALLOC_PRAGMA
//
// Constants.
//
//
// The status command sent to the mouse.
//
#define CSER_STATUS_COMMAND 's'
//
// The query number of mouse buttons command sent to the mouse.
//
#define CSER_QUERY_BUTTONS_COMMAND 'k'
//
// Status report from a CSeries mouse.
//
#define CSER_STATUS 0x4F
//
// Timeout value for the status returned by a CSeries mouse.
//
// #define CSER_STATUS_DELAY (50 * MS_TO_100_NS)
#define CSER_STATUS_DELAY 50
//
// Time (in microconds) needed by the mouse to adapt to a new baud rate.
//
#define CSER_BAUDRATE_DELAY (2 * MS_TO_100_NS)
//
// Default baud rate and report rate.
//
#define CSER_DEFAULT_BAUDRATE 1200
#define CSER_DEFAULT_REPORTRATE 150
//
// Button/status definitions.
//
#define CSER_SYNCH_BIT 0x80
#define CSER_BUTTON_LEFT 0x04
#define CSER_BUTTON_RIGHT 0x01
#define CSER_BUTTON_MIDDLE 0x02
#define CSER_BUTTON_LEFT_SR 2
#define CSER_BUTTON_RIGHT_SL 1
#define CSER_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 _CSER_BAUDRATE {
CHAR *Command;
ULONG BaudRate;
} CSER_BAUDRATE;
//
// Globals.
//
//
// The baud rate at which we try to detect a mouse.
//
static ULONG BaudRateDetect[] = { 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 },
CSerHandlerMM
},
{'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 CSER_BAUDRATE CserBaudRateTable[] = {
{ "*n", 1200 },
{ "*o", 2400 },
{ "*p", 4800 },
{ "*q", 9600 }
};
NTSTATUS
CSerPowerUp(
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
// MSeries detection.
//
status = SerialMouseIoSyncIoctlEx(IOCTL_SERIAL_GET_MODEMSTATUS,
DeviceExtension->TopOfStack,
&event,
&iosb,
NULL,
0,
&bits,
sizeof(ULONG)
);
if (NT_SUCCESS(status) && ((rtsDtr & bits) == rtsDtr)) {
//
// Wait CSER_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,
-CSER_POWER_UP
);
}
return status;
}
VOID
CSerSetReportRate(
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, ("CSerSetReportRate 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
CSerSetBaudRate(
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.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -