19#include <Library/BaseMemoryLib.h>
20#include <Library/DebugLib.h>
22#include <Library/UefiBootServicesTableLib.h>
36 return (UINT8)(Value < 0 ? -Value : Value);
49 }
else if (Value < Min) {
69 }
else if (*AbsX <= 2) {
70 for (Index = 0; Index < 5; Index++) {
86 }
else if (*AbsY <= 2) {
87 for (Index = 0; Index < 5; Index++) {
104#ifdef AMI_SHIM_POINTER_AMI_SMOOTHING
106STATIC UINT8
gAbsRange[8] = { 42, 36, 30, 24, 18, 12, 6, 1 };
107STATIC INT32
gMultipliers[8] = { 8, 7, 6, 5, 4, 3, 2, 1 };
108STATIC INT32 gIndices[8] = { 2, 2, 2, 2, 2, 2, 2, 0 };
118 for (TmpIndex = 0; TmpIndex < 8; TmpIndex++) {
126 Value = gIndices[TmpIndex] + Value *
gMultipliers[TmpIndex];
128 Value = Value *
gMultipliers[TmpIndex] - gIndices[TmpIndex];
145 *X = Clamp (*X, -16, 16);
146 *Y = Clamp (*Y, -16, 16);
152 if ((*X == 0) && (*Y == 0)) {
158 *X = AmiShimPointerScale (*X, AbsX);
159 *Y = AmiShimPointerScale (*Y, AbsY);
179 for (Index = 0; Index < 4; Index++) {
204 if ((*X == 0) && (*Y == 0)) {
240 if (PositionState.
Changed == 1) {
244 "Position: %d %d %d %d\n",
269 OUT EFI_SIMPLE_POINTER_STATE *State
280 Pointer->EfiPointer->GetButtonState (Pointer->EfiPointer, &ButtonState);
282 if ((ButtonState.
Changed == 0) && (Pointer->PositionChanged == 0)) {
283 return EFI_NOT_READY;
288 "Button: %d %d %d %d, Position: %d %d %d %d\n",
293 Pointer->PositionChanged,
303 State->LeftButton = State->RightButton = FALSE;
306 if (Pointer->PositionChanged) {
307 State->RelativeMovementX = Pointer->PositionX;
308 State->RelativeMovementY = Pointer->PositionY;
309 State->RelativeMovementZ = Pointer->PositionZ;
311 State->RelativeMovementX = State->RelativeMovementY = State->RelativeMovementZ = 0;
314 Pointer->PositionChanged = 0;
315 Pointer->PositionX = Pointer->PositionY = Pointer->PositionZ = 0;
323 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
324 IN OUT EFI_SIMPLE_POINTER_STATE *State
331 if ((This == NULL) || (State == NULL)) {
332 return EFI_INVALID_PARAMETER;
344 if (!EFI_ERROR (Status)) {
345 if ((State->RelativeMovementX != 0) ||
346 (State->RelativeMovementY != 0) ||
347 (State->RelativeMovementZ != 0))
351 "Received[%p] %d %d %d <%d, %d>\n",
353 State->RelativeMovementX,
354 State->RelativeMovementY,
355 State->RelativeMovementZ,
360 DEBUG ((DEBUG_VERBOSE,
"Received[%p] %d %d %d\n", This, State->RelativeMovementX, State->RelativeMovementY, State->RelativeMovementZ));
364 DEBUG ((DEBUG_VERBOSE,
"Received unknown this %p\n", This));
365 Status = EFI_INVALID_PARAMETER;
380 return EFI_ALREADY_STARTED;
385 if (EFI_ERROR (Status)) {
386 DEBUG ((DEBUG_INFO,
"AmiShimPointerPositionHandler event creation failed %d\n", Status));
392 if (EFI_ERROR (Status)) {
393 DEBUG ((DEBUG_INFO,
"AmiShimPointerPositionHandler timer setting failed %d\n", Status));
417 if (!EFI_ERROR (Status)) {
421 DEBUG ((DEBUG_INFO,
"AmiShimPointerPositionHandler timer unsetting failed %d\n", Status));
433 IN EFI_HANDLE DeviceHandle,
435 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
446 if ((Pointer->
DeviceHandle == NULL) && (FreePointer == NULL)) {
447 FreePointer = Pointer;
449 return EFI_ALREADY_STARTED;
453 if (FreePointer == NULL) {
454 return EFI_OUT_OF_RESOURCES;
457 DEBUG ((DEBUG_INFO,
"Installed onto %X\n", DeviceHandle));
463 DEBUG ((DEBUG_INFO,
"Function is already hooked\n"));
484 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
487 if (EFI_ERROR (Status)) {
488 return EFI_NOT_FOUND;
491 DEBUG ((DEBUG_INFO,
"Found %d Handles located by protocol\n", NoHandles));
495 for (Index = 0; Index < NoHandles; Index++) {
497 if (EFI_ERROR (Status)) {
498 DEBUG ((DEBUG_INFO,
"Handle %d has no AmiEfiPointerl %d\n", Index, Status));
503 if (EFI_ERROR (Status)) {
504 DEBUG ((DEBUG_INFO,
"Handle %d has no EfiSimplePointer %d\n", Index, Status));
509 if (EFI_ERROR (Status)) {
510 DEBUG ((DEBUG_INFO,
"Handle %d failed to get installed %d\n", Index, Status));
517 gBS->FreePool (Handles);
520 return EFI_NOT_FOUND;
578 if (EFI_ERROR (Status)) {
579 DEBUG ((DEBUG_INFO,
"AmiShimPointerArriveHandler event creation failed %d\n", Status));
586 if (EFI_ERROR (Status)) {
587 DEBUG ((DEBUG_INFO,
"AmiShimProtocolArriveHandler protocol registration failed %d\n", Status));
VOID EFIAPI AmiShimPointerArriveHandler(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI AmiShimPointerUpdateState(IN AMI_SHIM_POINTER_INSTANCE *Pointer, OUT EFI_SIMPLE_POINTER_STATE *State)
EFI_STATUS EFIAPI AmiShimPointerTimerSetup(VOID)
VOID EFIAPI AmiShimPointerSmooth(IN OUT INT32 *X, IN OUT INT32 *Y, IN OUT INT32 *Z)
INT32 EFIAPI InternalClamp(IN INT32 Value, IN INT32 Min, IN INT32 Max)
VOID EFIAPI AmiShimPointerFilterOut(IN OUT UINT8 *AbsX, IN OUT UINT8 *AbsY, IN OUT INT32 *X, IN OUT INT32 *Y)
UINT8 EFIAPI Abs(IN INT32 Value)
VOID EFIAPI AmiShimPointerPositionHandler(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI AmiShimPointerInstall(VOID)
STATIC AMI_SHIM_POINTER mAmiShimPointer
EFI_STATUS OcAppleGenericInputPointerExit(VOID)
EFI_STATUS EFIAPI AmiShimPointerGetState(IN EFI_SIMPLE_POINTER_PROTOCOL *This, IN OUT EFI_SIMPLE_POINTER_STATE *State)
STATIC UINT8 gAbsRange[4]
STATIC INT32 gMultipliers[4]
EFI_STATUS OcAppleGenericInputPointerInit(IN OC_INPUT_POINTER_MODE Mode)
EFI_STATUS EFIAPI AmiShimPointerTimerUninstall(VOID)
EFI_STATUS EFIAPI AmiShimPointerInstallOnHandle(IN EFI_HANDLE DeviceHandle, IN AMI_EFIPOINTER_PROTOCOL *EfiPointer, IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer)
VOID EFIAPI AmiShimPointerBoostValue(IN OUT INT32 *Value, IN INT32 AbsValue)
EFI_STATUS EFIAPI AmiShimPointerUninstall(VOID)
#define AIM_POSITION_POLL_INTERVAL
EFI_GUID gAmiEfiPointerProtocolGuid
EFI_GUID gEfiSimplePointerProtocolGuid
AMI_EFIPOINTER_GET_POSITION_STATE GetPositionState
AMI_EFIPOINTER_PROTOCOL * EfiPointer
EFI_SIMPLE_POINTER_PROTOCOL * SimplePointer
EFI_SIMPLE_POINTER_GET_STATE OriginalGetState
EFI_EVENT ProtocolArriveEvent
AMI_SHIM_POINTER_INSTANCE PointerMap[AIM_MAX_POINTERS]
BOOLEAN TimersInitialised