?? i2ccntl.c
字號:
/* Copyright 1997, ESS Technology, Inc. *//* SCCSID @(#)i2ccntl.c 1.15 11/11/97 */#include <stdio.h>#include "mvd.h"#include "common.h"#include "util.h"#include "ioport.h"#ifdef IIC/* This code is only used to initialize Brooktree *//************************************************************************ * Local defines. * ************************************************************************/#ifdef BROWSER1#define I2cRaiseClock TRISTATE_AUX3 /* Raise the SCL */
#define I2cDropClock CLEAR_AUX3 /* Drop the SCL */#define I2cRaiseData TRISTATE_AUX2 /* Raise the SCL */#define I2cDropData CLEAR_AUX2 /* Drop the SDL */#define I2cClockHigh AUX3_HIGH /* Is SCL high? */#define I2cDataHigh AUX2_HIGH /* Is SDL high? */#define I2cDataLow AUX2_LOW /* Is SDL low? */#else/* MVD board */#define I2cRaiseClock SET_AUX1 /* Raise the SCL */#define I2cDropClock CLEAR_AUX1 /* Drop the SCL */#define I2cRaiseData SET_AUX0 /* Raise the SDL */#define I2cDropData CLEAR_AUX0 /* Drop the SDL */#define I2cClockHigh AUX1_HIGH /* Is SCL high? */#define I2cDataHigh AUX0_HIGH /* Is SDL high? */#define I2cDataLow AUX0_LOW /* Is SDL low? */#endif#define set_I2ctimer do {} while(0) /* now timer check is pending */#define check_I2ctimer do {} while(0) /* now timer check is pending *//******************** IIC Bus spec(normal-mode)*********************/#define tBUF (4700L) /*4.7us*/#define tLOW (4700L) /*4.7us*/#define tHIGH (4000L) /*4.0us*/#define tSU_STA (4700L) /*4.7us*/#define tHD_STA (4000L) /*4.0us*/#define tSU_DAT (0250L) /*250ns*/#define tHD_DAT (0000L) /*0.0us*/#define tSU_STO (4700L) /*4.7us*//************************************************************************ * Functions used in this module only * ************************************************************************/PRIVATE void wait_timer(int);PRIVATE void I2cRaiseClockWait(void);PRIVATE void I2cReadArray(unsigned char, int, unsigned char *);PRIVATE int I2cReadByte(void);PRIVATE unsigned char I2cReadStatus(unsigned char);PRIVATE void I2cWrite(int, int, int);PRIVATE void I2cWriteArray(unsigned char, int, unsigned char *);PRIVATE void I2cWriteByte(unsigned char);PRIVATE void Start_condition();PRIVATE void Stop_condition();PRIVATE void Start_condition(){ I2cRaiseClockWait(); wait_timer(tSU_STA); I2cDropData; wait_timer(tHD_STA); I2cDropClock;}PRIVATE void Stop_condition(){ I2cRaiseClock; wait_timer(tSU_STO); I2cRaiseData;}/* time (nsec order) Max 2msec */PRIVATE void wait_timer(int wait_time) { int count; int starttime, tmp;#if 1 if (wait_time == 0) return; count = wait_time * 80 /1000; /* at 80Mhz*/ starttime = mvd[riface_timer2]; while (1){ tmp = mvd[riface_timer2] - starttime; if (tmp < 0) tmp += -timer2_period; if(tmp >= count) break; }#else printf("temp skip timer\n");#endif}PRIVATE void I2cRaiseClockWait(void){ I2cRaiseClock; /* raise the clock */ set_I2ctimer; while (1) { /* If no one is on bus, then return */ if (I2cClockHigh) return; check_I2ctimer; }}/*** Write a byte to the Phillips IIC,***/PRIVATE void I2cWriteByte(unsigned char c){ int i; /* Send each bit across the data port */ for (i = 0; i < 8; i++) { wait_timer(tLOW); if (c & 0x80) { /*drive SDL */ I2cRaiseData; } else { I2cDropData; } wait_timer(tSU_DAT); /*wait data setup time */ I2cRaiseClockWait(); wait_timer(tHIGH); /* keep SCL high */ I2cDropClock; wait_timer(tHD_DAT); /* keep SDL in data hold time */ c <<= 1; } /* get acknowledge */ wait_timer(tLOW); I2cRaiseData; /* raise the data */ I2cRaiseClockWait(); set_I2ctimer; while (1) { if (I2cDataLow) break; /* Got ack */ check_I2ctimer; } wait_timer(tHIGH); I2cDropClock;}/*** Read a byte from the Philips IIC,
***/PRIVATE int I2cReadByte(void){ int i, b; /* read 8 bits */ b = 0; for (i = 0; i < 8; i++) { b <<= 1; wait_timer(tLOW); I2cRaiseClockWait(); b |= (I2cDataHigh ? 1 : 0); wait_timer(tHIGH); I2cDropClock; } /* send acknowledge */ wait_timer(tLOW); I2cRaiseClockWait(); wait_timer(tHIGH); I2cDropClock; /* read 8 bits */ return(b);}/*** read an array of bytes from the Phillips IIC**** parms: a IIC address** n # bytes to read** s pointer to the array*/PRIVATE void I2cReadArray(unsigned char a, int n, unsigned char *s){ int j; wait_timer(tBUF); Start_condition(); /* Clock out the address */ I2cWriteByte(a); /* Now read in the bytes */ for (j = 0; j < n; j++) { s[j] = I2cReadByte(); } Stop_condition();}/*** write an array of bytes to the Phillips IIC**** parms: a IIC address** n # bytes to write** s pointer to the array*/PRIVATE void I2cWriteArray(unsigned char a, int n, unsigned char *s){ int j; wait_timer(tBUF); Start_condition(); /* Clock out the address */ I2cWriteByte(a); /* Now write out the bytes */ for (j = 0; j < n; j++) { I2cWriteByte(s[j]); } Stop_condition();}/*** Read the Status of the Phillips IIC Bus*/PRIVATE unsigned char I2cReadStatus(unsigned char a){ unsigned char *pByte; I2cReadArray(a, 1, pByte); return(*pByte);}#if 0PRIVATE unsigned char command_7151[20] = { /* 7151 */ 0x00, /* sub-address */ 0x2a, /* 00 delay time */ 0x42, /* 01 hsync begin */ 0x15, /* 02 hsync stop */ 0xfb, /* 03 hor clamp begin */ 0xcb, /* 04 hor clamp stop */ 0x3e, /* 05 horiz sync start */ 0x00, /* 06 cvbs, 4.1mhz, bndfilt active, coring off, aper=0*/ 0x00, /* 07 hue control */ 0xac, /* 08 ntsc-m 60hz, colorkill */ 0x30, /* 09 uv off disabled, agc = medium, */ 0x7f, /* 0A */ 0x7f, /* 0B */ 0xa4, /* 0C b7 */ 0x48, /* 0D */ 0x30, /* 0E */ 0x91, /* (51)(91) 0F */ 0xf0, /* 60 10 */ 0xff, /* 21 11 72 */ 0xc3 /* 12 */};#endif#define BT856 0x88#define BT856Ack 0x89#ifdef BT865#define BT865ADDR 0x8a#endifPRIVATE unsigned char command_856[]={ 0xdc, 0x08, /*0xde*/ 0x00};int InitIIC(){#ifdef BT866 mvd[vid_scn_outputcntl] = 0x8000;#endif#ifdef BT865 int i; mvd[vid_scn_outputcntl] = 0x0800; for(i=0; i < 10000; i++); /* wait for a while */#endif I2cRaiseClock; I2cRaiseData;#ifdef BT865 I2cWrite(BT865ADDR,0xa6,0x80); I2cWrite(BT865ADDR,0xca,0x80); I2cWrite(BT865ADDR,0xce,0x02);#endif#ifdef BT866 I2cWrite(BT856,0xc8,0xcc); I2cWrite(BT856,0xca,0x91); I2cWrite(BT856,0xcc,0x20); I2cWrite(BT856,0xdc,0x40); I2cWrite(BT856,0xde,0x02);#endif#ifndef BT866#ifndef BT865 I2cWrite(BT856,0xdc,0x08); I2cWrite(BT856,0xde,0x00);#endif#endif return(0);}PRIVATE void I2cWrite(int device_address, int sub_address, int data){ unsigned char buf[2]; buf[0] = 0xff & sub_address; buf[1] = 0xff & data; I2cWriteArray(device_address, 2, buf);}void video_encoder_off(){#ifdef BT865 I2cWrite( 0x8a,0xbc,0x08 );#endif}#endif /* ifdef IIC */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -