⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vibdrvr_pdd.cpp

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
//
//  Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
//  Use of this source code is subject to the terms of the Microsoft end-user
//  license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
//  If you did not accept the terms of the EULA, you are not authorized to use
//  this source code. For a copy of the EULA, please see the LICENSE.RTF on your
//  install media.
//
//------------------------------------------------------------------------------
//
//  File:  Vibratorpdd.cpp
//
//  Implementation of PDD layer of Vibrator driver
//
//------------------------------------------------------------------------------
//
//  Copyright (C) 2004-2005, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------

#include <windows.h>
#include <vibdrvr.h>
#include <vibrator.h>
#include <types.h>
#include <bsp.h>
#include <bsp_cfg.h>
#include <nkintr.h>
#include <pmic_basic_types.h>
 
//------------------------------------------------------------------------------
// External Functions

//------------------------------------------------------------------------------
// External Variables 

//------------------------------------------------------------------------------
// Defines 
#define     VIB_MAX_LEN     100

//------------------------------------------------------------------------------
// Types
typedef PMIC_STATUS (*PF_PMIC_VOLTAGE_REGULATOR_ON)(PMIC_REGULATOR_VREG regulator);
typedef PMIC_STATUS (*PF_PMIC_VOLTAGE_REGULATOR_OFF)(PMIC_REGULATOR_VREG regulator);
typedef PMIC_STATUS (*PF_PMIC_VOLTAGE_REGULATOR_SET_VOLTAGE_LEVEL)(PMIC_REGULATOR_VREG regulator, PMIC_REGULATOR_VREG_VOLTAGE voltage);

//------------------------------------------------------------------------------
// Global Variables 
static BOOL                         g_bThreadActive;
static BOOL                         g_bVibratorOn;

static HANDLE                   g_hThreadStoppedEvent;
static HANDLE                   g_hStopThreadEvent;

static HINSTANCE                g_hVibratorDriver;      //Handle to PMIC Vibrator Driver module

static PF_PMIC_VOLTAGE_REGULATOR_ON       g_pPmicVoltageRegulatorOn;    //Function pointer to PMIC Vibrator On
static PF_PMIC_VOLTAGE_REGULATOR_OFF    g_pPmicVoltageRegulatorOff; //Function pointer to PMIC Vibrator Off
static PF_PMIC_VOLTAGE_REGULATOR_SET_VOLTAGE_LEVEL g_pPmicVoltageRegulatorSetVoltageLevel;

static VIB_SUPPORTS_INFO        g_VibSupports;
static VIB_SETTINGS_INFO        g_VibSettings;

//------------------------------------------------------------------------------
// Local Variables 

//------------------------------------------------------------------------------
// Local Functions
DWORD WINAPI VibratorDriverSetDeviceThread(LPVOID lParam);
//#ifdef DEBUG
void WINAPI VibratorDriverDebugPrintOut(void);
//#endif  // DEBUG

//-----------------------------------------------------------------------------
//
// Function: VibratorDriverInitialize
//
// This routine initializes the underlying Vibrator hardware as the Vibrator driver is loaded.
//
// Parameters:
//      None
//
// Returns:  
//      This routine should return TRUE if successful. If there's a problem
//      it should return FALSE
//
//-----------------------------------------------------------------------------
BOOL WINAPI VibratorDriverInitialize(VOID)
{
        DEBUGMSG(ZONE_PDD, (_T("+VibratorDriverInitialize\r\n")));
        RETAILMSG(1, (_T("+VibratorDriverInitialize\r\n")));    
        
    BOOL ret = TRUE;
    HKEY   hKey;
    TCHAR DllName[VIB_MAX_LEN];
    TCHAR OnProcName[VIB_MAX_LEN];
    TCHAR OffProcName[VIB_MAX_LEN];
    DWORD Length = sizeof(DllName);

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Drivers\\BuiltIn\\VIBRATOR", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
    {           
        if( RegQueryValueEx( hKey, L"PMICVIBLIBNAME", NULL, NULL, (LPBYTE)&DllName, &Length) != ERROR_SUCCESS ||
                RegQueryValueEx( hKey, L"PMICVIBOFFPROCNAME", NULL, NULL, (LPBYTE)&OffProcName, &Length) != ERROR_SUCCESS ||
                RegQueryValueEx( hKey, L"PMICVIBONPROCNAME", NULL, NULL, (LPBYTE)&OnProcName, &Length) != ERROR_SUCCESS)            
        {   
                DEBUGMSG(ZONE_PDD, (_T("VibratorDriverInitialize: RegQueryValueEx Failed\r\n")));   
                RETAILMSG(1, (_T("VibratorDriverInitialize: RegQueryValueEx Failed\r\n"))); 
            ret = FALSE;
            goto initialize_err;
        }           
    }
    else
    {
            DEBUGMSG(ZONE_PDD, (_T("VibratorDriverInitialize: RegOpenKeyEx Failed\r\n")));  
            RETAILMSG(1, (_T("VibratorDriverInitialize: RegOpenKeyEx Failed\r\n")));    
        ret = FALSE;
        goto initialize_err;
    }
    
        if(g_hVibratorDriver = LoadLibrary(DllName))
       {
        g_pPmicVoltageRegulatorOn = (PF_PMIC_VOLTAGE_REGULATOR_ON) GetProcAddress( g_hVibratorDriver, OnProcName );
        g_pPmicVoltageRegulatorOff = (PF_PMIC_VOLTAGE_REGULATOR_OFF) GetProcAddress( g_hVibratorDriver, OffProcName );

        if(g_pPmicVoltageRegulatorOn == NULL || g_pPmicVoltageRegulatorOff == NULL)
        {   
             DEBUGMSG(ZONE_PDD, (_T("VibratorDriverInitialize: GetProcAddress Failed\r\n")));
             RETAILMSG(1, (_T("VibratorDriverInitialize: GetProcAddress Failed\r\n"))); 
                FreeLibrary(g_hVibratorDriver);  
            ret = FALSE;
            goto initialize_err;
        }   

        if((g_hStopThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) 
        {           
             DEBUGMSG(ZONE_PDD, (_T("VibratorDriverInitialize: CreateEvent Failed\r\n")));
             RETAILMSG(1, (_T("VibratorDriverInitialize: CreateEvent Failed\r\n")));    
            FreeLibrary(g_hVibratorDriver);
            ret = FALSE;
            goto initialize_err;
        }
        
        if((g_hThreadStoppedEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) 
        {
             DEBUGMSG(ZONE_PDD, (_T("VibratorDriverInitialize: CreateEvent Failed\r\n")));
             RETAILMSG(1, (_T("VibratorDriverInitialize: CreateEvent Failed\r\n")));    
            FreeLibrary(g_hVibratorDriver);
            CloseHandle(g_hStopThreadEvent);
            ret = FALSE;
            goto initialize_err;
        }
        
        g_VibSupports.AdjustOffCycleTime =  TRUE;
        g_VibSupports.AdjustOnCyleTime = TRUE;
        g_VibSupports.AdjustTotalCycleTime = FALSE;
        g_VibSupports.MetaCycleOff = FALSE;
        g_VibSupports.MetaCycleOn = FALSE;

              g_VibSettings.OutputVoltage.v_vib = VOLT_VIBRATOR;
              g_VibSettings.OffOnCycles = 0;
        g_VibSettings.MetaCycleOff = 0;
        g_VibSettings.MetaCycleOn = 0;
        g_VibSettings.TotalCycleTime = 0;
        g_VibSettings.OffCyleTime = 1000;   // Default 1000 msec
        g_VibSettings.OnCycleTime = 1000;   // Default 1000 msec

        g_bThreadActive = FALSE;
        g_bVibratorOn = FALSE;
    }
    else
    {
         DEBUGMSG(ZONE_PDD, (_T("VibratorDriverInitialize: LoadLibrary Failed\r\n")));
        RETAILMSG(1, (_T("VibratorDriverInitialize: LoadLibrary Failed\r\n"))); 
        ret = FALSE;
    }
    
#ifdef DEBUG
    VibratorDriverDebugPrintOut();
#endif  // DEBUG  

initialize_err:     
    if(hKey)
        RegCloseKey( hKey );
    RETAILMSG(1, (_T("-VibratorDriverInitialize\r\n")));        
    DEBUGMSG(ZONE_PDD, (_T("-VibratorDriverInitialize\r\n")));
         
    return ret;
}

//-----------------------------------------------------------------------------
//
// Function: VibratorDriverDeInitialize
//
// This routine deinitializes the underlying Vibrator hardware as the Vibrator driver is unloaded.
//
// Parameters:
//      None
//
// Returns:  
//      This routine returns TRUE if successful, or FALSE if there's a problem
//
//-----------------------------------------------------------------------------
BOOL WINAPI VibratorDriverDeInitialize(VOID)
{
        DEBUGMSG(ZONE_PDD, (_T("+VibratorDriverDeInitialize\r\n")));
        RETAILMSG(1, (_T("+VibratorDriverDeInitialize\r\n")));
    
        
    if(g_hVibratorDriver)
        {
            FreeLibrary(g_hVibratorDriver);
    }

        RETAILMSG(1, (_T("-VibratorDriverDeInitialize\r\n")));
        DEBUGMSG(ZONE_PDD, (_T("-VibratorDriverDeInitialize\r\n")));
        
        return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: VibratorDriverGetDeviceInfo
//
// This routine retrieves information about the Vibrator driver.  
// The nInfoId parameter indicates what specific
// information is being queried and pOutput is a buffer to be filled in.
// The size of pOutput depends on the type of data being requested.
//
// Parameters:
//      InputParm 
//          [in] INT     nInfoId
//
//      OutputParm 
//          [out] PVOID   pOutput
//
// Returns:  
//      This routine returns TRUE if successful, or FALSE if there's a problem
//
//-----------------------------------------------------------------------------
BOOL WINAPI VibratorDriverGetDeviceInfo(
                       INT     nInfoId,
                       PVOID   pOutput
                       )
{
        DEBUGMSG(ZONE_PDD, (_T("+VibratorDriverGetDeviceInfo\r\n")));
        RETAILMSG(1, (_T("+VibratorDriverGetDeviceInfo\r\n")));

        BOOL ret = TRUE;    
        SETFNAME(_T("Vibrator: VibratorDriverGetDeviceInfo"));

    if(nInfoId == VIBRATOR_SUPPORTS_INFO_ID)
    {
        struct VIB_SUPPORTS_INFO  *p = (struct VIB_SUPPORTS_INFO*)pOutput;                      
        
            p->AdjustTotalCycleTime = g_VibSupports.AdjustTotalCycleTime;
        p->AdjustOffCycleTime = g_VibSupports.AdjustOffCycleTime;
        p->AdjustOnCyleTime = g_VibSupports.AdjustOnCyleTime;
        p->MetaCycleOff = g_VibSupports.MetaCycleOff;
        p->MetaCycleOn = g_VibSupports.MetaCycleOn;     
    }
    else if(nInfoId == VIBRATOR_SETTINGS_INFO_ID)
    {
        struct VIB_SETTINGS_INFO  *p = (struct VIB_SETTINGS_INFO*)pOutput;                      

        p->OutputVoltage = g_VibSettings.OutputVoltage;
        p->OffOnCycles = g_VibSettings.OffOnCycles;
        p->MetaCycleOff = g_VibSettings.MetaCycleOff;
        p->MetaCycleOn = g_VibSettings.MetaCycleOn;
        p->OffCyleTime = g_VibSettings.OffCyleTime;
        p->OnCycleTime = g_VibSettings.OnCycleTime;
        p->TotalCycleTime = g_VibSettings.TotalCycleTime;
    }
    else
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -