示例#1
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_close(xsMachine *the)
{
    DBG_I2C("xs_i2c_close\n");

    xs_i2c(xsGetHostData(xsThis));
    xsSetHostData(xsThis, NULL);
}
示例#2
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_readBlock(xsMachine *the)
{
	FskErr err;
	xsI2C i2c = xsGetHostData(xsThis);
	int argc = xsToInteger(xsArgc), i;
	int format = 2;
    SInt32 dataSize = xsToInteger(xsArg(0)), readCount;
	UInt8 data[32];

	xsThrowIfNULL(i2c);

    DBG_I2C("xs_i2c_readBlock\n");

	if ((dataSize > 32) || (dataSize <= 0))
		xsThrowDiagnosticIfFskErr(kFskErrInvalidParameter, "I2C readBlock invalid size %d. %s", (int)dataSize, i2c->diagnosticID);

	FskPinI2CSetAddress(i2c->pin, i2c->address);
	err = FskPinI2CReadBytes(i2c->pin, dataSize, &readCount, data);
    if (err) {
        xsTraceDiagnostic("I2C readBlock failed with error %s %s.", FskInstrumentationGetErrorString(err), i2c->diagnosticID);
        goto bail;
    }

    if (argc > 1) {
        int t = xsTypeOf(xsArg(1));
        if ((xsNumberType == t) || (t == xsIntegerType))
            format = xsToInteger(xsArg(1));
        else {
            char *formatString = xsToString(xsArg(1));
            if (0 == FskStrCompare(formatString, "Buffer"))
                format = 2;
            else if (0 == FskStrCompare(formatString, "Chunk"))
                format = 0;
            else if (0 == FskStrCompare(formatString, "Array"))
                format = 1;
        }
    }
    
    if (2 == format) {
        xsResult = xsArrayBuffer(data, readCount);
    }
    else if (0 == format) {
        xsResult = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(readCount));
        FskMemMove(xsGetHostData(xsResult), data, readCount);
    }
    else if (1 == format) {
        xsResult = xsNew1(xsGlobal, xsID("Array"), xsInteger(readCount));
        for (i = 0; i < readCount; i++)
            xsSet(xsResult, i, xsInteger(data[i]));
    }
    
bail:
    if (err)
		xsError(err);
}
示例#3
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_writeByte(xsMachine *the)
{
    xsI2C i2c = xsGetHostData(xsThis);
    FskErr err;
    UInt8 byte = (UInt8)xsToInteger(xsArg(0));

    DBG_I2C("xs_i2c_writeByte: %#x\n", byte);

	xsThrowIfNULL(i2c);

    FskPinI2CSetAddress(i2c->pin, i2c->address);

    err = FskPinI2CWriteByte(i2c->pin, byte);
    xsThrowDiagnosticIfFskErr(err, "I2C writeByte failed with error %s %s.", FskInstrumentationGetErrorString(err), i2c->diagnosticID);
}
示例#4
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_writeWordDataSMB(xsMachine *the)
{
    xsI2C i2c = xsGetHostData(xsThis);
    FskErr err;
    UInt8 command = (UInt8)xsToInteger(xsArg(0));
    UInt16 word = (uint16_t)xsToInteger(xsArg(1));

	DBG_I2C("xs_i2c_writeWordDataSMB write word %u from %u\n", word, command);

	xsThrowIfNULL(i2c);

    FskPinI2CSetAddress(i2c->pin, i2c->address);

    err = FskPinI2CWriteDataWord(i2c->pin, command, word);
    xsThrowDiagnosticIfFskErr(err, "I2C writeWordDataSMB register %d failed with error %s %s.", (int)command, FskInstrumentationGetErrorString(err), i2c->diagnosticID);
}
示例#5
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_writeQuickSMB(xsMachine *the)
{
    xsI2C i2c = xsGetHostData(xsThis);
    FskErr err;
    uint8_t byte = (uint8_t)xsToInteger(xsArg(0));

	DBG_I2C("xs_i2c_writeQuickSMB Writing quick byte SMB %u\n", byte);

	xsThrowIfNULL(i2c);

    FskPinI2CSetAddress(i2c->pin, i2c->address);

//@@    err = FskI2CWriteQuickSMB(i2c->bus, byte);
err = kFskErrOperationFailed;		//@@
    xsThrowDiagnosticIfFskErr(err, "I2C writeQuickSMB failed with error %s %s.", FskInstrumentationGetErrorString(err), i2c->diagnosticID);
}
示例#6
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_readByte(xsMachine *the)
{
    xsI2C i2c = xsGetHostData(xsThis);
	FskErr err;
    UInt8 byte;

    DBG_I2C("xs_i2c_readByte\n");

	xsThrowIfNULL(i2c);

	FskPinI2CSetAddress(i2c->pin, i2c->address);

    err = FskPinI2CReadByte(i2c->pin, &byte);
	xsThrowDiagnosticIfFskErr(err, "I2C readByte failed %s.", i2c->diagnosticID);
    xsResult = xsInteger(byte);
}
示例#7
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_readByteDataSMB(xsMachine *the)
{
    xsI2C i2c = xsGetHostData(xsThis);
	FskErr err;
	UInt8 command = (UInt8)xsToInteger(xsArg(0));
	UInt8 byte;

	DBG_I2C("xs_i2c_readByteDataSMB Reading byte from %u\n", reg);

	xsThrowIfNULL(i2c);

    FskPinI2CSetAddress(i2c->pin, i2c->address);

	err = FskPinI2CReadDataByte(i2c->pin, command, &byte);
	xsThrowDiagnosticIfFskErr(err, "I2C readByteDataSMB register %d failed %s.", (int)command, i2c->diagnosticID);

    xsResult = xsInteger(byte);
}
示例#8
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_writeBlock(xsMachine* the)
{
	FskErr err;
	xsI2C i2c = xsGetHostData(xsThis);
	int argc = xsToInteger(xsArgc), i;
	UInt8 buffer[32], *bufPtr = buffer;

	xsThrowIfNULL(i2c);

    DBG_I2C("xs_i2c_writeBlock\n");

	for (i = 0; i < argc; i++)
		bufPtr = writeOne(the, i2c, &xsArg(i), bufPtr, buffer + sizeof(buffer));

	FskPinI2CSetAddress(i2c->pin, i2c->address);

	err = FskPinI2CWriteBytes(i2c->pin, bufPtr - buffer, buffer);
    xsThrowDiagnosticIfFskErr(err, "I2C FskI2CWriteBlock failed with error %s %s.", FskInstrumentationGetErrorString(err), i2c->diagnosticID);
}
示例#9
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_readWordDataSMB(xsMachine *the)
{
    xsI2C i2c = xsGetHostData(xsThis);
    UInt8 command = (UInt8)xsToInteger(xsArg(0));
	FskErr err;
    UInt16 val;
  
    DBG_I2C("xs_i2c_readWordDataSMB Call SMB to register %d\n", command);

	xsThrowIfNULL(i2c);

    FskPinI2CSetAddress(i2c->pin, i2c->address);

    err = FskPinI2CReadDataWord(i2c->pin, command, &val);
//@@        if (! (i2c->address == 0x36) ) xsTraceDiagnostic("I2C readWordDataSMB register %d failed %s.", (int)reg, i2c->diagnosticID);
	xsThrowDiagnosticIfFskErr(err, "I2C readWordDataSMB register %d failed %s.", (int)command, i2c->diagnosticID);

    xsResult = xsInteger(val);
}
示例#10
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_processCallSMB(xsMachine *the)
{
    xsI2C i2c = xsGetHostData(xsThis);
	FskErr err;
	UInt8 command = (UInt8)xsToInteger(xsArg(0));
    UInt16 value = (UInt16)xsToInteger(xsArg(1));
    UInt16 result;

    DBG_I2C("xs_i2c_processCallSMB Process Call SMB to register %d, value %d\n", command, value);

	xsThrowIfNULL(i2c);

    FskPinI2CSetAddress(i2c->pin, i2c->address);

	err = FskPinI2CProcessCall(i2c->pin, command, value, &result);
	xsThrowDiagnosticIfFskErr(err, "I2C processCallSMB register %d failed %s.", (int)command, i2c->diagnosticID);

    xsResult = xsInteger(result);
}
示例#11
0
/*!
 \param i2c_msg
 \return zero on success, else negative errno
*/
int i2c_transfer(u8 i2c_addr, u8 reg, u8 *buf, u8 len, unsigned short flags)
{
	DBG_FUNC();

	#ifdef CAMERA_FOR_SCANNER
	return 0;
	#endif

	struct i2c_msg msg[2];
	msg[0].addr = i2c_addr;
	msg[0].flags = 0;
	msg[0].len = sizeof(reg);
	msg[0].buf = (char *)&reg;

	msg[1].addr = i2c_addr;
	msg[1].flags = flags;
	msg[1].len = len;
	msg[1].buf = (char *)buf;

	i2c_rdwr_ioctl_data data;
	data.msgs = &msg[0];
	data.nmsgs = 1;
	int ret = camera_ioctl(HSM_IIC_TRANSFER, &data);
	KIL_ERR("camera_ioctl(HSM_IIC_TRANSFER, &data):%d\n",ret);
	//if( ret == 1 )//modify by zhaozuzhao 2014.04.29
	{
		usleep(5000);
		data.msgs = &msg[1];
		data.nmsgs = 1;
		ret = camera_ioctl(HSM_IIC_TRANSFER, &data);
		ret = (ret==1) ? 0 : ret;
	}

	DBG_I2C(!(flags & I2C_M_RD), i2c_addr, reg, buf, len);

	if ( ret )
	{
		KIL_ERR("Error I2C transfer, Reg=%02X, ret=%d, (%d) %s\n", (unsigned int)reg, ret, errno, strerror(errno));
	}

	return ret;
}
示例#12
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_writeBlockDataSMB(xsMachine* the)
{
    FskErr err;
    xsI2C i2c = xsGetHostData(xsThis);
    int argc = xsToInteger(xsArgc), i;
    UInt8 command = (UInt8)xsToInteger(xsArg(0));
    unsigned char buffer[32], *bufPtr = buffer;

	xsThrowIfNULL(i2c);

    DBG_I2C("xs_i2c_writeBlockDataSMB\n");

	FskPinI2CSetAddress(i2c->pin, i2c->address);

    for (i = 1; i < argc; i++)
        bufPtr = writeOne(the, i2c, &xsArg(i), bufPtr, buffer + sizeof(buffer));

    err = FskPinI2CWriteDataBytes(i2c->pin, command, (SInt32)(bufPtr - buffer), buffer);
    xsThrowDiagnosticIfFskErr(err, "I2C writeBlockDataSMB register %d failed with error %s %s.", (int)command, FskInstrumentationGetErrorString(err), i2c->diagnosticID);
}
示例#13
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_readBlockDataSMB(xsMachine* the)
{
    xsI2C i2c = xsGetHostData(xsThis);
	FskErr err;
	char* formatString;
	int format = 2, i;
	SInt32 dataSize = 0;
    UInt8 command = (UInt8)xsToInteger(xsArg(0));
    UInt8 data[34]; //needs to be 34 because we're using I2C_SMBUS_I2C_BLOCK_BROKEN in i2cdev.c		//@@ WTF - not at this layer, at least
    SInt32 length = (SInt32)xsToInteger(xsArg(1));

    DBG_I2C("xs_i2c_readBlockDataSMB\n");

	xsThrowIfNULL(i2c);

    if ((length < 0) || (length > 32))
        xsThrowDiagnosticIfFskErr(kFskErrInvalidParameter, "I2C readBlockDataSMB bad length %d %s.", length, i2c->diagnosticID);

	FskPinI2CSetAddress(i2c->pin, i2c->address);

    formatString = xsToString(xsArg(2));
    if (!FskStrCompare(formatString, "Buffer")) format = 2;
    else if (!FskStrCompare(formatString, "Chunk")) format = 0;
    else if (!FskStrCompare(formatString, "Array")) format = 1;

	err = FskPinI2CReadDataBytes(i2c->pin, command, length, &dataSize, data);
	xsThrowDiagnosticIfFskErr(err, "I2C readBlockDataSMB register %d failed %s.", (int)command, i2c->diagnosticID);

    if (2 == format) {
		xsResult = xsArrayBuffer(data, dataSize);
	}
    else if (0 == format) {
        xsResult = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(dataSize));
        FskMemMove(xsGetHostData(xsResult), data, dataSize);
    }
    else if (1 == format) {
        xsResult = xsNew1(xsGlobal, xsID("Array"), xsInteger(dataSize));
        for (i = 0; i < dataSize; i++)
            xsSet(xsResult, i, xsInteger(data[i]));
    }
}
示例#14
0
/*! 
 \param i2c_addr 
 \param reg 
 \param buf 
 \param len 
 \return 0 on success 
*/
int i2c_read_reg(u8 i2c_addr, u8 reg, u8 *buf, u8 len)
{
	DBG_FUNC();
	long ret;
	struct hsm_iic_data data;

	if (!buf || !len)
		return -EINVAL;

	data.i2c_addr = i2c_addr;
	data.reg = reg;
	data.len = len;
	data.buf = buf;
	ret = camera_ioctl(HSM_IIC_READ, &data);

	DBG_I2C(false, i2c_addr, reg, buf, len);

	if( ret )
	{
		KIL_ERR("Error READ_IIC return = %d, err=%d\n", ret, errno);
	}

	return ret;
}
示例#15
0
/*! 
 \param i2c_addr 
 \param reg 
 \param buf 
 \param len 
 \return 0 on success 
*/
int i2c_write_reg(u8 i2c_addr, u8 reg, const u8 *buf, u8 len)
{
	DBG_FUNC();
	long ret;
	struct hsm_iic_data data;

	if (!buf || !len)
		return -EINVAL;

	DBG_I2C(true, i2c_addr, reg, buf, len);

	data.i2c_addr = i2c_addr;
	data.reg = reg;
	data.buf = const_cast<unsigned char *>(buf);	// casting away the consts is reall poor style, we need to fixme:
	data.len = len;
	ret = camera_ioctl(HSM_IIC_WRITE, &data);

	if( ret )
	{
		KIL_ERR("Error WRITE_IIC return = %d, err=%d\n", ret, errno);
	}

	return ret;
}