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

📄 tsc2046spi.c

📁 TI TCS2046 Toutch PAD IC Driver for WindowsCE
💻 C
字号:
/**************************************************************/
//
// Copyright (c) Texas Instruments 2005. All rights reserved.
//
/***************************************************************
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR 
FITNESS FOR A PARTICULAR PURPOSE.

Module Name:	
		TSC2046SPI.C

Abstract:	
		This module contains the functions to communicate with
		the TSC2046 device through an SPI several bus.

Functions:
  
Revision History:
Rev 0.0		Original Release	WXF	9-30-2005

***************************************************************/

#include    <windows.h>
#include	<TSC2046SPI.H>
#include	<HostSPIComm.H>	// processor dependent functions

//
//--------------------------------------------------------------
// Functions for Initialize SPI Interface
//--------------------------------------------------------------
//
// Initialize Processor for SPI Interface
BOOL InitSPI(BOOL bInPowerHandler)
{	
	RETAILMSG(1, (TEXT("Init Processor SPI ....... \r\n")));

    // Allocate SPI Control Resources.
    if (!HWAllocateSPIResources()){ return(FALSE); }

	// Setup SPI Interface at Host
	HWInitSPI(bInPowerHandler); 

	RETAILMSG(1, (TEXT("InitSPI - done\r\n")));
	return(TRUE);
}

// Deinitialize Processor for SPI Interface
BOOL DeinitSPI(BOOL bInPowerHandler)
{
	RETAILMSG(1,(TEXT("Deinit Processor SPI ......\r\n")));	

	// Stop SPI Interface at Host
	HWDeinitSPI(bInPowerHandler);

	// Deallocate SPI control Resources
    if (!HWDeallocateSPIResources())
    {
	    RETAILMSG(1,(TEXT("HWDeallocate Error ......\r\n")));	
        return(FALSE);
    }

	RETAILMSG(1, (TEXT("DeinitSPI - done\r\n")));
    return(TRUE);
}

//
//--------------------------------------------------------------
// General Function for TSC2046 Control Register R/W 
//    where "Command" is the command byte ; and
//    return R-Adjusted 12 or 8 bit data in [pWords[0] pWord[1]]
//--------------------------------------------------------------
//
UINT16 SPITransaction(UINT8 Command, BOOL bInPowerHandler)
{
	UINT8 iTempData[3] = {0, 0, 0};
	UINT16 iTempD = 0;

	if (!bInPowerHandler)
	{
		HWStartFrame();
		while (HWSPITxBusy()) { HWWait(1); }

		// command byte is written to TSC2046 by SPI
		HWSPIWriteWord(Command);
		HWWait(2);
		while (HWSPITxBusy()) { HWWait(1); }
		while (HWSPIRxBusy()) { HWWait(1); }
		iTempData[0] = HWSPIReadWord(); 
		HWWait(2);

		// read high byte of the ADC data
		HWSPIWriteWord(0);
		HWWait(2);
		while (HWSPITxBusy()) { HWWait(1); }
		while (HWSPIRxBusy()) { HWWait(1); }
		iTempData[1] = HWSPIReadWord(); 
		HWWait(2);

		// read low byte of the ADC data
		HWSPIWriteWord(0);
		HWWait(2);
		while (HWSPITxBusy()) { HWWait(1); }
		while (HWSPIRxBusy()) { HWWait(1); }
		iTempData[2] = HWSPIReadWord(); 
		HWWait(2);
		
		while (HWSPIFIFONotEmpty()) // clean up FIFO to make sure getting latest data 
		{

			iTempData[0] = iTempData[1];
			iTempData[1] = iTempData[2];
			iTempData[2] = HWSPIReadWord();
			HWWait(20);
		}
		HWStopFrame();
		HWWait(2);

		iTempD = ( ( (0x00FF & ((UINT16)iTempData[1]) ) << 8 ) |
			         (0x00FF & ((UINT16)iTempData[2]) ) );
		if (!(Command&0x80))   // if 8-bits
			return(iTempD >> 7);
		else			       // if 12-bits - use only 10 MSB bits
			return(iTempD >> 5);
	}
	else
		return(0);
}

//
//--------------------------------------------------------------
// End of TSC2046SPI.C Functions
//--------------------------------------------------------------
//
//**************************************************************
//
// END of FILE
//
//**************************************************************
////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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