static PyObject * i2c_write(PyObject *self, PyObject *args) { /* parameters */ struct as_i2c_device *aDev; uint8_t *aData; int aSize; int ret; /* Get arguments */ if (!PyArg_ParseTuple(args, "ls#", (long *)&aDev, (unsigned char *)&aData, &aSize)) { PyErr_SetString(PyExc_IOError, "Wrong parameters."); return NULL; } ret = as_i2c_write(aDev, aData, aSize); if (ret < 0) { PyErr_SetString(PyExc_IOError, "Can't get slave address"); return NULL; } return Py_BuildValue("i", ret); }
static int32_t as_tcs3472_write8(struct as_tcs3472 *tcs3472, int reg, unsigned char value) { int ret; unsigned char buf[1]; /* Set address of register to access */ buf[0] = 0x80 | ((unsigned char)(reg & 0x1f)); ret = as_i2c_write(tcs3472->i2c_dev, buf, 1); if (ret) return ret; /* write value */ buf[0] = value; ret = as_i2c_write(tcs3472->i2c_dev, buf, 1); if (ret) return ret; return 0; }
long AsI2c::write(unsigned char *aData, size_t aSize) { if (mDev != NULL) { return as_i2c_write(mDev, aData, aSize); } else { std::cerr<<"AsI2c device structure not allocated"<<std::endl; return -1; } }
static int32_t as_tcs3472_read8(struct as_tcs3472 *tcs3472, int reg, unsigned char *value) { int ret; unsigned char buff[1]; /* Set address of register to access */ buff[0] = 0x80 | ((unsigned char)(reg & 0x1f)); ret = as_i2c_write(tcs3472->i2c_dev, buff, 1); if (ret) return ret; /* Read it */ ret = as_i2c_read(tcs3472->i2c_dev, buff, 1); if (ret) return ret; *value = *buff; DBG("read 0x%02x in 0x%02x\n", *value, reg); return 0; }
static int32_t as_tcs3472_read16(struct as_tcs3472 *tcs3472, int reg, unsigned short *value, int size) { int ret; unsigned char buf[2]; /* Set address of register to access */ buf[0] = 0x80 | ((unsigned char)(reg & 0x1f)); ret = as_i2c_write(tcs3472->i2c_dev, buf, 1); if (ret) return ret; /* Read it */ ret = as_i2c_read(tcs3472->i2c_dev, buf, 2); if (ret) return ret; *value = buf[1] << 8 | buf[0]; DBG("read 0x%02x%02x at 0x%02x\n", buf[1], buf[0], reg); return 0; }