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

📄 i2c.h

📁 adi black fin chip connect to cmos sensor
💻 H
字号:
/*****************************************************************************
*	I2C.h
*   
*	Copyright (c) 2007 Analog Devices, Inc.  All Rights Reserved.
*   This software is proprietary to Analog Devices, Inc. and its
*	licensors.
*  
* 	CHANGES:  10/24/2007  1.00  - initial public release
*
*	SOFTWARE: 	VisualDSP++ 5.0 August 2007 Update
* 
* 	HARDWARE: 	BF561 EZ-Kit Lite Board Rev 1.4
*				Micron MTV9022 or MTV9032 Sensor
*
*
*	DESCRIPTION:
* 
*	SCCB Software Interface for Video Device configurations - C Callable
*	
*	This header defines the I2C read and write functions.
*
* 
*	SCCB START SETTINGS:
*	
* 	>> 	Before Calling the SCCB_Interface 
*		the inputs to the SCCB_Taskmanager must be done.
*
* 	>> 	Write to the "SCCB_Control" 
*		a "1" for reading from the Device or
* 		a "2" for writing to the Device.
*	
*	>>	Leave the total number of bytes in "SCCB_Wordcount".
*		Device Addresses and Word Addresses included.
*
* 	>> 	Write all data to the "SCCB_DataIn"
* 		e.g.Writing to the device:
*							
*			SCCB_DataIn 			Device Address	(LSB must be Zero)
*									Word Address
*									Data 1	
*									Data 2
*		e.g.Reading from the device:
*		
*			SCCB_DataIn 			Device Address	(LSB must be zero)
*									Word Address
*									Device Address	(LSB must be one)
*	>> 	The data elements received can be found in the array
*									_SCCB_DataOut[10]
******************************************************************************/

#ifndef _I2C_INCLUDE
#define _I2C_INCLUDE

/* To use the I2C routine, simply call the I2C_wr and I2C_rd	*/
/* to write to or read from the slave device, e.g. the video	*/
/* encoder or decoder. Slave address is the hardware address	*/
/* of the slave device, on receiving the slave address, the 	*/
/* corresponding slave device will acknowledge by pulling		*/
/* the Sdata line(PF0 here) low. The reg_subaddress is the		*/
/* subaddress of the slave device you want to write to or read	*/
/* from. The value is just the value you want to configure.		*/
/* To read from the device, you need to send out the slave 		*/
/* WRITE address first (NOT READ ADDRESS !!!), followed by the	*/
/* subaddress from which you want to read the value and THEN 	*/
/* the slave READ address. You can find examples in the main.c	*/
/* The above description is based on the use of the ADV7185 and	*/
/* ADV7304A, so if other devices are used, the configuration may*/
/* differ.														*/

#define I2C_wr(slave_addr, reg_subaddr, hivalue,lowvalue)\
		asm(".extern _SCCB_DataIn;");\
		asm(".extern _SCCB_Word_Count;");\
		asm(".extern _SCCB_Control;");\
		asm(".extern _SCCB_In_Progress;");\
		asm(".extern _SCCB_Error;");\
		asm(".extern _SCCB_Interface;");\
		asm("p0.l = _SCCB_DataIn;");\
		asm("p0.h = _SCCB_DataIn;");\
		asm("r0=%0;" :: "d"(slave_addr));\
		asm("[p0++]=r0;");\
		asm("r0=%0;" :: "d"(reg_subaddr));\
		asm("[p0++]=r0;");\
		asm("r0=%0;" :: "d"(hivalue));\
		asm("[p0++]=r0;");\
		asm("r0=%0;" :: "d"(lowvalue));\
		asm("[p0++]=r0;");\
		asm("p0.h = _SCCB_Word_Count;");\
		asm("p0.l = _SCCB_Word_Count;");\
		asm("r0=4(z);");\
		asm("[p0]=r0;");\
		asm("p0.l = _SCCB_Control;");\
		asm("p0.h = _SCCB_Control;");\
		asm("r0 = 2 (z);");\
		asm("[p0] = r0;");\
		asm("p0.h = _SCCB_Error;");\
		asm("p0.l = _SCCB_Error;");\
		asm("r0 = 0;");\
		asm("[p0] = r0;");\
		asm("p0.h = _SCCB_In_Progress;");\
		asm("p0.l = _SCCB_In_Progress;");\
		asm("r0 = 1;");\
		asm("[p0] = r0;");\
		asm("CALL _SCCB_Interface;")

#define I2C_rd(slave_addr_wr, reg_subaddr, slave_addr_rd)\
		asm(".extern _SCCB_DataIn;");\
		asm(".extern _SCCB_Word_Count;");\
		asm(".extern _SCCB_Control;");\
		asm(".extern _SCCB_In_Progress;");\
		asm(".extern _SCCB_Error;");\
		asm(".extern _SCCB_Interface;");\
		asm("p0.l = _SCCB_DataIn;");\
		asm("p0.h = _SCCB_DataIn;");\
		asm("r0=%0;" :: "d"(slave_addr_wr));\
		asm("[p0++]=r0;");\
		asm("r0=%0;" :: "d"(reg_subaddr));\
		asm("[p0++]=r0;");\
		asm("r0=%0;" :: "d"(slave_addr_rd));\
		asm("[p0++]=r0;");\
		asm("p0.h = _SCCB_Word_Count;");\
		asm("p0.l = _SCCB_Word_Count;");\
		asm("r0=5(z);");\
		asm("[p0] = r0;");\
		asm("p0.l = _SCCB_Control;");\
		asm("p0.h = _SCCB_Control;");\
		asm("r0 = 1 (z);");\
		asm("[p0] = r0;");\
		asm("p0.h = _SCCB_Error;");\
		asm("p0.l = _SCCB_Error;");\
		asm("r0 = 0;");\
		asm("[p0] = r0;");\
		asm("p0.h = _SCCB_In_Progress;");\
		asm("p0.l = _SCCB_In_Progress;");\
		asm("r0 = 1;");\
		asm("[p0] = r0;");\
		asm("CALL _SCCB_Interface;")		
		
#endif

⌨️ 快捷键说明

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