Exemplo n.º 1
0
static int hmc5883HWInit(int devFD)
{   
    int ret = 0;
    if (I2CWriteByte(devFD, WriteAddress, 6) == -1) {
        ret = -1;
    }
    if (I2CWriteByteTo(devFD, 0x00, 0x70, 6) == -1) {
        ret = -1;
    }
    if (I2CWriteByte(devFD, WriteAddress, 6) == -1) {
        ret = -1;
    }
    // continued reading mode
    if (I2CWriteByteTo(devFD, 0x02, 0x00, 6) == -1) {
        ret = -1;
    }
    // read command to check the mode
    if (I2CWriteByte(devFD, ReadAddress, 6) == -1) {
        ret = -1;
    }
    // printf("A=%d\n",I2CReadByteFrom(devFD, 0x00, 6));
    // printf("B=%d\n",I2CReadByteFrom(devFD, 0x02, 6));
    usleep(1000*100);
    return ret;
}
/****************************************************************************\  
//****************************************************************************\  
*  Function: Gainmanual
*
*  Detailed Description:
*  Sets Gain control to serial interface control.
*
\****************************************************************************/
int Gainmanual(TUNER_MODULE *pTuner)
{
	unsigned char writearray[5];
	int status;

	writearray[0]=0;
	status=I2CWriteByte(pTuner, 200,26,writearray[0]);
	//printf("\nRegister 1a=%d", writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	writearray[0] = 0;
	status=I2CWriteByte (pTuner, 200,9,writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}
 
	writearray[0] = 0;
	status=I2CWriteByte (pTuner, 200,5,writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	return E4000_1_SUCCESS; 
}
Exemplo n.º 3
0
void tda731xSetSpeakers(void)
{
	int8_t spFrontLeft = 0;
	int8_t spFrontRight = 0;

	int8_t spRearLeft = 0;
	int8_t spRearRight = 0;

	if (sndPar[MODE_SND_BALANCE].value > 0) {
		spFrontLeft -= sndPar[MODE_SND_BALANCE].value;
		spRearLeft -= sndPar[MODE_SND_BALANCE].value;
	} else {
		spFrontRight += sndPar[MODE_SND_BALANCE].value;
		spRearRight += sndPar[MODE_SND_BALANCE].value;
	}
	if (sndPar[MODE_SND_FRONTREAR].value > 0) {
		spRearLeft -= sndPar[MODE_SND_FRONTREAR].value;
		spRearRight -= sndPar[MODE_SND_FRONTREAR].value;
	} else {
		spFrontLeft += sndPar[MODE_SND_FRONTREAR].value;
		spFrontRight += sndPar[MODE_SND_FRONTREAR].value;
	}

	I2CStart(TDA731X_I2C_ADDR);
	I2CWriteByte(TDA731X_SP_REAR_LEFT | -spRearLeft);
	I2CWriteByte(TDA731X_SP_REAR_RIGHT | -spRearRight);
	I2CWriteByte(TDA731X_SP_FRONT_LEFT | -spFrontLeft);
	I2CWriteByte(TDA731X_SP_FRONT_RIGHT | -spFrontRight);
	I2CStop();

	return;
}
Exemplo n.º 4
0
static void ks0066WriteStrob()
{
	I2CWriteByte(i2cData | PCF8574_E_LINE);
	I2CWriteByte(i2cData);

	return;
}
Exemplo n.º 5
0
uint8_t DS1307Write(uint8_t address,uint8_t data)
{
	uint8_t res;	//result
	
	//Start
	I2CStart();
	
	//SLA+W
	res=I2CWriteByte(0b11010000);	//DS1307 address + W
	
	//Error
	if(!res)	return FALSE;
	
	//Now send the address of required register
	res=I2CWriteByte(address);
	
	//Error
	if(!res)	return FALSE;
	
	//Now write the value
	res=I2CWriteByte(data);
	
	//Error
	if(!res)	return FALSE;
	
	//STOP
	I2CStop();
	
	return TRUE;
}
Exemplo n.º 6
0
void tea63x0SetInputMute(void)
{
    I2CStart(TEA63X0_I2C_ADDR);
    I2CWriteByte(TEA63X0_AUDIO_SW);
    I2CWriteByte((aproc.mute ? TEA63X0_GMU : 0) | (1 << aproc.input));
    I2CStop();

    return;
}
Exemplo n.º 7
0
void tea63x0SetBT()
{
    I2CStart(TEA63X0_I2C_ADDR);
    I2CWriteByte(TEA63X0_BASS);
    I2CWriteByte(sndPar[MODE_SND_BASS].value + 7);		// -4..5 grid => 3..12 raw
    I2CWriteByte(sndPar[MODE_SND_TREBLE].value + 7);	// -4..4 grid => 3..11 raw
    I2CStop();

    return;
}
Exemplo n.º 8
0
Arquivo: 24c32.c Projeto: gerbert/ws2
uint8_t AT24_format(void) {
	/*
	 * Declare a pointer for 1-byte write over i2c bus.
	 * It will point to an address of our structure and
	 * we will shift it to one byte until we reach the
	 * endpoint of our structure.
	 */
	uint8_t *p;
	uint8_t counter = 0;
	uint8_t at24_waddress = 0;
	uint16_t at24_paddress = 0;
	/*
	 * If any error during write - we will return error
	 * number, otherwise - 0.
	 */
	uint8_t ret = ESUCCESS;

	memset(&eepd, 0, EEPROM_MU_WR_SIZE);

	eepd.counter = 1;
	eepd.last_sync = 2;
	eepd.next_sync = 3;
	eepd.next_page = 4;

	// Set AT24C32 i2c address and raise write flag
	at24_waddress = (at24_addr | TW_WRITE);

	for (uint8_t i = 0; i < EEPROM_PAGE_CNT; i++) {
		p = (uint8_t *)&eepd; // We set start addres
		if (p != NULL) {
			// Start transmission. Connect to the device
			ret = I2CStart(at24_waddress);
			if (ret > 0)
				return ret;

			ret = I2CWriteByte(at24_paddress >> 8);
			if (ret > 0)
				return EEEPADDRMSB;
			ret = I2CWriteByte(at24_paddress & 0xFF);
			if (ret > 0)
				return EEEPADDRLSB;

			for (uint8_t k = 0; k < sizeof(eepd); k++) {
				ret = I2CWriteByte(*p);
				if (ret > 0)
					return ret;
				p++;
			}
			// Stop transmission
			I2CStop();
			at24_paddress += EEPROM_MU_ADDR_STEP;
		} else
			return ENULLPOINTER;
Exemplo n.º 9
0
static int pulseEnable(int devFD, unsigned char data)
{
    clearLastError();
    if (I2CWriteByte(devFD, (data | En), 0) == -1) {
        return -1;
    }
    usleep(1);
    if (I2CWriteByte(devFD, (data & ~En), 0) == -1) {
        return -1;
    }
    return 0;
}
Exemplo n.º 10
0
static void writeAlarm(void)
{
	uint8_t i;

	I2CStart(DS1307_ADDR);
	I2CWriteByte(DS1307_A0_HOUR);
	for (i = DS1307_A0_HOUR; i <= DS1307_A0_WDAY; i++)
		I2CWriteByte(alarm[i - DS1307_A0_HOUR]);
	I2CStop();

	return;
}
Exemplo n.º 11
0
void tda731xSetBT(void)
{
	int8_t val;

	I2CStart(TDA731X_I2C_ADDR);
	val = sndPar[MODE_SND_BASS].value;
	I2CWriteByte(TDA731X_BASS | (val > 0 ? 15 - val : 7 + val));
	val = sndPar[MODE_SND_TREBLE].value;
	I2CWriteByte(TDA731X_TREBLE | (val > 0 ? 15 - val : 7 + val));
	I2CStop();

	return;
}
/****************************************************************************\  
*  Function: freqband
*
*  Detailed Description:
*  Configures the E4000 frequency band. (Registers 0x07, 0x78).
*
\****************************************************************************/
int freqband(TUNER_MODULE *pTuner, int Freq)
{      
	unsigned char writearray[5];
	int status;

	if (Freq<=140000)
	{
		writearray[0] = 3;
		status=I2CWriteByte(pTuner, 200,120,writearray[0]);
		if(status != E4000_I2C_SUCCESS)
		{
			return E4000_1_FAIL;
		}
	}
	else if (Freq<=350000)
	{
		writearray[0] = 3;
		status=I2CWriteByte(pTuner, 200,120,writearray[0]);
		if(status != E4000_I2C_SUCCESS)
		{
			return E4000_1_FAIL;
		}
	}
	else if (Freq<=1000000)
	{
		writearray[0] = 3;
		status=I2CWriteByte(pTuner, 200,120,writearray[0]);
		if(status != E4000_I2C_SUCCESS)
		{
			return E4000_1_FAIL;
		}
	}
	else 
	{
		writearray[0] = 7;
		status=I2CWriteByte(pTuner, 200,7,writearray[0]);
		if(status != E4000_I2C_SUCCESS)
		{
			return E4000_1_FAIL;
		}

		writearray[0] = 0;
		status=I2CWriteByte(pTuner, 200,120,writearray[0]);
		if(status != E4000_I2C_SUCCESS)
		{
			return E4000_1_FAIL;
		}
	}

	return E4000_1_SUCCESS;  
}
Exemplo n.º 13
0
void tda731xSetMute(void)
{
	I2CStart(TDA731X_I2C_ADDR);
	if (aproc.mute) {
		I2CWriteByte(TDA731X_SP_REAR_LEFT | TDA731X_MUTE);
		I2CWriteByte(TDA731X_SP_REAR_RIGHT | TDA731X_MUTE);
		I2CWriteByte(TDA731X_SP_FRONT_LEFT | TDA731X_MUTE);
		I2CWriteByte(TDA731X_SP_FRONT_RIGHT | TDA731X_MUTE);
	} else {
		tda731xSetSpeakers();
	}
	I2CStop();

	return;
}
/****************************************************************************\  
*  Function: DCoffloop
*
*  Detailed Description:
*  Populates DC offset LUT. (Registers 0x2d, 0x70, 0x71).
*  Turns on DC offset LUT and time varying DC offset.
\****************************************************************************/
int DCoffloop(TUNER_MODULE *pTuner)
{
	unsigned char writearray[5];
	int status;

	//writearray[0]=0;
	//I2CWriteByte(pTuner, 200,115,writearray[0]);
	//printf("\nRegister 73=%d", writearray[0]);
	writearray[0] = 31;
	status=I2CWriteByte(pTuner, 200,45,writearray[0]);
	//printf("\nRegister 2d=%d", writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	writearray[0] = 1;
	writearray[1] = 1;
	status=I2CWriteArray(pTuner, 200,112,2,writearray);
	//printf("\nRegister 70=%d", writearray[0]);
	//printf("\nRegister 71=%d", writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	return E4000_1_SUCCESS;
}
Exemplo n.º 15
0
EXPORT double hmc5883Read(int devFD) 
{
    int x,x1,x2,y,y1,y2,z,z1,z2;
    double angle;

    I2CWriteByte(devFD, ReadAddress, 6);            // read command
    x1 = I2CReadByteFrom(devFD, 0x03, 6);
    x2 = I2CReadByteFrom(devFD, 0x04, 6);
    x = x1 << 8 | x2;                               // Combine MSB and LSB of X Data output register

    z1 = I2CReadByteFrom(devFD, 0x05, 6);
    z2 = I2CReadByteFrom(devFD, 0x06, 6);
    z = z1 << 8 | z2;                               // Combine MSB and LSB of Z Data output register  

    y1 = I2CReadByteFrom(devFD, 0x07, 6);
    y2 = I2CReadByteFrom(devFD, 0x08, 6);
    y = y1 << 8 | y2;                               // Combine MSB and LSB of Y Data output register
    if (x > 32768)
        x = -(0xFFFF - x + 1);
    if (z > 32768)
        z = -(0xFFFF - z + 1);
    if (y>32768)
        y = -(0xFFFF - y + 1);

    // printf("x=%d,y=%d,z=%d\n",x,y,z);
    angle = atan2((double)y,(double)x) * (180 / PI) + 180; // angle in degrees
    if(angle >=0 && angle <=360) {
        return angle;
    } else {
        return -1;
    }

}
Exemplo n.º 16
0
void tda731xSetInput(void)
{
	I2CStart(TDA731X_I2C_ADDR);
	I2CWriteByte(TDA731X_SW | (3 - sndPar[MODE_SND_GAIN0 + aproc.input].value) << 3 | !(aproc.extra & APROC_EXTRA_LOUDNESS) << 2 | aproc.input);
	I2CStop();

	return;
}
Exemplo n.º 17
0
void tda731xSetVolume(void)
{
	I2CStart(TDA731X_I2C_ADDR);
	I2CWriteByte(TDA731X_VOLUME | -sndPar[MODE_SND_VOLUME].value);
	I2CStop();

	return;
}
Exemplo n.º 18
0
void tea63x0SetSpeakers()
{
    int8_t spFR = sndPar[MODE_SND_FRONTREAR].value;

    // Front channels
    I2CStart(TEA63X0_I2C_ADDR);
    I2CWriteByte(TEA63X0_FADER);
    I2CWriteByte(TEA63X0_MFN | TEA63X0_FCH | (spFR < 0 ? 15 + spFR : 15));
    I2CStop();

    // Rear channels
    I2CStart(TEA63X0_I2C_ADDR);
    I2CWriteByte(TEA63X0_FADER);
    I2CWriteByte(TEA63X0_MFN | (spFR < 0 ? 15 : 15 - spFR));
    I2CStop();

    return;
}
Exemplo n.º 19
0
void I2CWriteBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t value) {
	uint8_t b;
	uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1);
	I2CReadByte(devAddr, regAddr, &b);
	value <<= (bitStart - length + 1);
	value &= mask;
	b &= ~(mask);
	b |= value;
	I2CWriteByte(devAddr, regAddr, b);	
}
/** @brief I2CWriteBytes: Write one Byte to the PCA9685
 *  @param data:The frist byte must be the address of the 'CHIP', then the data to the chip.
 *  @param len : data size
 */
void I2CWriteBytes(uint8_t *data, uint8_t len){
	uint8_t i = 0;

	I2CStart();
	for (; i < len; ++i){
		I2CWriteByte(*data++);
	}
	I2CStop();
	delay(3);
}
Exemplo n.º 21
0
// 写四位数据
EXPORT int pcf8574WriteData4(int devFD, unsigned char data)
{
    clearLastError();
    if (I2CWriteByte(devFD, (data | RS | BL), 0) == -1) {
        return -1;
    }
    if (pulseEnable(devFD, (data | RS | BL)) == -1) {
        return -1;
    }
    return 0;
}
Exemplo n.º 22
0
static int write_regs(unsigned char* pdevdata,   unsigned long datalen)
{
    int i = 0;

    while (i < datalen)
    {
        I2CWriteByte(I2C_ADV7179, pdevdata[i], pdevdata[i + 1]);
        i += 2;
    }
    return 0;
}
int Qpeak(TUNER_MODULE *pTuner)
{
	unsigned char writearray[5];
	int status;

	writearray[0] = 1;
	writearray[1] = 254;
	status=I2CWriteArray(pTuner, 200,126,2,writearray);
	//printf("\nRegister 7e=%d", writearray[0]);
	//printf("\nRegister 7f=%d", writearray[1]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	status=I2CWriteByte (pTuner, 200,130,0);
	//printf("\nRegister 82=0");
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	status=I2CWriteByte (pTuner, 200,36,5);
	//printf("\nRegister 24=5");
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	writearray[0] = 32;
	writearray[1] = 1;
	status=I2CWriteArray(pTuner, 200,135,2,writearray);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	//printf("\nRegister 87=%d", writearray[0]);
	//printf("\nRegister 88=%d", writearray[1]);
	return E4000_1_SUCCESS;
}
Exemplo n.º 24
0
// 写四位指令
EXPORT int pcf8574WriteCmd4(int devFD, unsigned char command)
{
    clearLastError();
    if (I2CWriteByte(devFD, command | BL, 0) == -1) {
        return -1;
    }
    if (pulseEnable(devFD, command | BL) == -1) {
        setLastError("Fail to pulseEnable");
        return -1;
    }
    return 0;
}
int tunerreset(TUNER_MODULE *pTuner)
{
	unsigned char writearray[5];
	int status;

	writearray[0] = 64;
	// For dummy I2C command, don't check executing status.
	status=I2CWriteByte (pTuner, 200,2,writearray[0]);
	status=I2CWriteByte (pTuner, 200,2,writearray[0]);
	//printf("\nRegister 0=%d", writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	writearray[0] = 0;
	status=I2CWriteByte (pTuner, 200,9,writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	writearray[0] = 0;
	status=I2CWriteByte (pTuner, 200,5,writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	writearray[0] = 7;
	status=I2CWriteByte (pTuner, 200,0,writearray[0]);
	//printf("\nRegister 0=%d", writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	return E4000_1_SUCCESS;
}
Exemplo n.º 26
0
uint8_t DS1307Read(uint8_t address,uint8_t *data)
{
	uint8_t res;	//result
	
	//Start
	I2CStart();
	
	//SLA+W (for dummy write to set register pointer)
	res=I2CWriteByte(0b11010000);	//DS1307 address + W
	
	//Error
	if(!res)	return FALSE;
	
	//Now send the address of required register
	res=I2CWriteByte(address);
	
	//Error
	if(!res)	return FALSE;
	
	//Repeat Start
	I2CStart();
	
	//SLA + R
	res=I2CWriteByte(0b11010001);	//DS1307 Address + R
	
	//Error
	if(!res)	return FALSE;
	
	//Now read the value with NACK
	res=I2CReadByte(data,0);
	
	//Error
	if(!res)	return FALSE;
	
	//STOP
	I2CStop();
	
	return TRUE;
}
/****************************************************************************\  
*  Function: GainControlinit
*
*  Detailed Description:
*  Configures gain control mode. (Registers 0x1a)
*
\****************************************************************************/
int GainControlauto(TUNER_MODULE *pTuner)
{
	unsigned char writearray[5];
	int status;

	writearray[0] = 23;
	status=I2CWriteByte(pTuner, 200,26,writearray[0]);
	if(status != E4000_I2C_SUCCESS)
	{
		return E4000_1_FAIL;
	}

	return E4000_1_SUCCESS; 
}
Exemplo n.º 28
0
boolean_t writeToCompass( boolean_t sendStart, boolean_t sendStop, Byte data )
{
    Byte numberOfFailedAttempts = 0;
    while ( I2CWriteByte( sendStart, sendStop, data ) == 0 )
    {
        numberOfFailedAttempts++;
        if ( numberOfFailedAttempts == MaxNumberOfFailedAttempts )
        {
            TurnOnErrorLight();
            return False;
        }
    }
    return True;
}
Exemplo n.º 29
0
static int adv7179_device_init(void)
{
    unsigned char regvalue1, regvalue2;
    regvalue1 = I2CReadByte(I2C_ADV7179, 0x07);
    I2CWriteByte(I2C_ADV7179, 0x07, 0xa5);
    regvalue2 = I2CReadByte(I2C_ADV7179, 0x07);
    if (regvalue2 != 0xa5)
    {
        printk("read adv7179 register is %x\n", regvalue2);
        printk("check adv7179 error.\n");
        return -EFAULT;
    }
    I2CWriteByte(I2C_ADV7179, 0x07, regvalue1);
    if (norm_mode == VIDEO_NORM_NTSC)
    {
        if (init_vda(VIDEO_MODE_CCIR656, VIDEO_NORM_NTSC, VIDEO_MODE_MASTER) == 0)
        {
            return 0;
        }
        else
        {
            return -EFAULT;
        }
    }
    else
    {
        if (init_vda(VIDEO_MODE_CCIR656, VIDEO_NORM_PAL, VIDEO_MODE_MASTER) == 0)
        {
            return 0;
        }
        else
        {
            return -EFAULT;
        }
    }

}
Exemplo n.º 30
0
void tea63x0SetVolume()
{
    int8_t spLeft = sndPar[MODE_SND_VOLUME].value;
    int8_t spRight = sndPar[MODE_SND_VOLUME].value;
    int8_t volMin = pgm_read_byte(&sndPar[MODE_SND_VOLUME].grid->min);

    if (sndPar[MODE_SND_BALANCE].value > 0) {
        spLeft -= sndPar[MODE_SND_BALANCE].value;
        if (spLeft < volMin)
            spLeft = volMin;
    } else {
        spRight += sndPar[MODE_SND_BALANCE].value;
        if (spRight < volMin)
            spRight = volMin;
    }

    I2CStart(TEA63X0_I2C_ADDR);
    I2CWriteByte(TEA63X0_VOLUME_LEFT);
    I2CWriteByte(spRight + 53);							// -66dB..20dB => -33..10 grid => 20..53 raw
    I2CWriteByte(spLeft + 53);
    I2CStop();

    return;
}