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

📄 csdproximity.c

📁  PSoC(可编程片上系统)是Cypress半导体公司生产的包含有8位微处理器核和数字与模拟混合的信号阵列芯片
💻 C
字号:
//*****************************************************************************
//*****************************************************************************
//  FILENAME:  `@LIB_NAME`_CSDPROXIMITY.c
//  Version: 1.0.0.4, Updated on 2007/06/20 at 17:14:09
//  Application: PSoC Express 2.0
//
//  DESCRIPTION:  This Driver senses a capacitive proximity and provides
//				  means for outputting "tuning" values
//
//-----------------------------------------------------------------------------
//      Copyright (c) Cypress MicroSystems 2007. All Rights Reserved.
//*****************************************************************************
//*****************************************************************************
#include "m8c.h"
#include "`@LIB_NAME`_CSDPROXIMITY.h"
#include "cmx.h"
// channel type header file
#include "CMX_CSD_CHAN.h"

int iCSDPROXIMITYPrev[CMX_CSDPROXIMITY_COUNT];

//-----------------------------------------------------------------------------
//  FUNCTION NAME: CSDPROXIMITY_Instantiate(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
//
//  DESCRIPTION:
//	  CSDPROXIMITY Initialization.
//
//-----------------------------------------------------------------------------
//
//  ARGUMENTS: parameter block
//
//  RETURNS:
//
//  SIDE EFFECTS: 
//
//  THEORY of OPERATION or PROCEDURE: Sets the initial status of the button.
//	 Initializes UM properties 
//
////////////////////////////////////////////////////////////////////////////////
void `@LIB_NAME`_CSDPROXIMITY_Instantiate(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
{
	BYTE bInstanceID;
	BYTE bBaseInstanceID;
	
	bInstanceID = pPBlock->ID;
	bBaseInstanceID = pPBlock->CSDButtBaseBLK->bInstanceID;
	// We do not use this parameter
	CSD_baBtnFThreshold[bBaseInstanceID] = 10;
	iCSDPROXIMITYPrev[bInstanceID] = 0;
	CSD_SetScanMode(pPBlock->pCSDProximityThresholds->ScanSpeed, pPBlock->pCSDProximityThresholds->Resolution);	// Set Scan Mode
	CSD_SetRefValue(pPBlock->pCSDProximityThresholds->RefValue); 						// Set Ref Value
	CSD_InitializeSensorBaseline(bBaseInstanceID);					// Initialize baseline for the sensor
}

//-----------------------------------------------------------------------------
//  FUNCTION NAME: CSDPROXIMITY_GetValue(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
//
//  DESCRIPTION:
//    Get current button status.
//
//-----------------------------------------------------------------------------
//
//  ARGUMENTS: parameter block
//
//  RETURNS: BYTE
//
//  THEORY of OPERATION or PROCEDURE: Sets the appropriate Scan Mode and
//   Ref Value and initiates a single sensor scan. Then updates the baseline
//	 and determines the current button status. Status is set to 0 than  
//       Difference value lower than DetectionThreshold minus Hysteresis property value and set to 
//     Difference value  value otherwise.
///////////////////////////////////////////////////////////////////////////////
int `@LIB_NAME`_CSDPROXIMITY_GetValue(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
{
	BYTE bScanSpeed = pPBlock->pCSDProximityThresholds->ScanSpeed;
	BYTE bInstanceID = pPBlock->ID;
	BYTE bBaseInstanceID = pPBlock->CSDButtBaseBLK->bInstanceID;
	BYTE bResolution = pPBlock->pCSDProximityThresholds->Resolution;
	BYTE bRefValue = pPBlock->pCSDProximityThresholds->RefValue;
	
	BYTE bHysteresis = pPBlock->pCSDProximityThresholds->Hysteresis;
	int iRetValue,iDetectionThreshold;
	
	CSD_SetScanMode(bScanSpeed, bResolution);	// Set Scan Mode
	CSD_SetRefValue(bRefValue); 						// Set Ref Value
	CSD_ScanSensor(bBaseInstanceID); 								// Scan one sensor[bBaseInstanceID]
	CSD_UpdateSensorBaseline(bBaseInstanceID);						// Update baseline for the sensor

	iDetectionThreshold = pPBlock->pCSDProximityThresholds->DetectionThreshold;	
		
	iRetValue = `@LIB_NAME`_CSDPROXIMITY_GetDifference(pPBlock);	
	//if difference greater distance threshold than simply return defference
	if (iRetValue >= (iDetectionThreshold + bHysteresis))
	{
		iCSDPROXIMITYPrev[bInstanceID] = iRetValue;			
	}
	// else return zero
	else if (iRetValue < (iDetectionThreshold - bHysteresis ))
	{
		iRetValue = 0;
		iCSDPROXIMITYPrev[bInstanceID] = iRetValue;
	}
	// else return previous value
	else if(iCSDPROXIMITYPrev[bInstanceID] != 0)
	{
		iCSDPROXIMITYPrev[bInstanceID] = iRetValue;
	}
	// else return zero
	else
	{
		iRetValue = 0;
		iCSDPROXIMITYPrev[bInstanceID] = iRetValue;
	}
	
	return iRetValue;	
}

//-----------------------------------------------------------------------------
//  FUNCTION NAME: CSDPROXIMITY_GetBaseline(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
//
//  DESCRIPTION:
//    Get current Baseline count from the base driver.
//
//-----------------------------------------------------------------------------
//
//  ARGUMENTS: parameter block
//
//  RETURNS: int
//
//  THEORY of OPERATION or PROCEDURE: The functions gets the CapSense button
//	 Baseline count
//
///////////////////////////////////////////////////////////////////////////////
int `@LIB_NAME`_CSDPROXIMITY_GetBaseline(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
{
	return CSD_waSnsBaseline[pPBlock->CSDButtBaseBLK->bInstanceID];
}

//-----------------------------------------------------------------------------
//  FUNCTION NAME: CSDPROXIMITY_GetRawCount(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
//
//  DESCRIPTION:
//    Get current Raw count from the base driver.
//
//-----------------------------------------------------------------------------
//
//  ARGUMENTS: parameter block
//
//  RETURNS: int
//
//  THEORY of OPERATION or PROCEDURE: The functions gets the CapSense button
//	 Raw count
//
///////////////////////////////////////////////////////////////////////////////
int `@LIB_NAME`_CSDPROXIMITY_GetRawCount(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
{
	return CSD_waSnsResult[pPBlock->CSDButtBaseBLK->bInstanceID];
}

//-----------------------------------------------------------------------------
//  FUNCTION NAME: CSDPROXIMITY_GetDifference(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
//
//  DESCRIPTION:
//    Get current Difference count from the base driver.
//
//-----------------------------------------------------------------------------
//
//  ARGUMENTS: parameter block
//
//  RETURNS: int
//
//  THEORY of OPERATION or PROCEDURE: The functions gets the CapSense button
//	 Difference count
//
///////////////////////////////////////////////////////////////////////////////
int `@LIB_NAME`_CSDPROXIMITY_GetDifference(const `@LIB_NAME`_CSDPROXIMITY_ParameterBlock * pPBlock)
{	
	BYTE bInstanceID = pPBlock->CSDButtBaseBLK->bInstanceID;
	return CSD_waSnsDiff[bInstanceID];
}

⌨️ 快捷键说明

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