From 3fd5aba00088dfeb1e78270f0ba658ecd8e66b16 Mon Sep 17 00:00:00 2001 From: "Mark M. Hoffman" Date: Sat, 16 Jun 2007 14:01:05 +0000 Subject: [PATCH] ported r4435 from trunk git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4450 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/py-smbus/smbusmodule.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/prog/py-smbus/smbusmodule.c b/prog/py-smbus/smbusmodule.c index 74fd0afb..f0ca53c5 100644 --- a/prog/py-smbus/smbusmodule.c +++ b/prog/py-smbus/smbusmodule.c @@ -1,6 +1,6 @@ /* * smbusmodule.c - Python bindings for Linux SMBus access through i2c-dev - * Copyright (C) 2005,2006 Mark M. Hoffman + * Copyright (C) 2005-2007 Mark M. Hoffman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,15 @@ #include #include +/* +** These are required to build this module against Linux older than 2.6.23. +*/ +#ifndef I2C_SMBUS_I2C_BLOCK_BROKEN +#undef I2C_SMBUS_I2C_BLOCK_DATA +#define I2C_SMBUS_I2C_BLOCK_BROKEN 6 +#define I2C_SMBUS_I2C_BLOCK_DATA 8 +#endif + PyDoc_STRVAR(SMBus_module_doc, "This module defines an object type that allows SMBus transactions\n" "on Linux hosts. The host kernel must have I2C support, I2C device\n" @@ -486,22 +495,25 @@ SMBus_block_process_call(SMBus *self, PyObject *args) } PyDoc_STRVAR(SMBus_read_i2c_block_data_doc, - "read_i2c_block_data(addr, cmd) -> results\n\n" + "read_i2c_block_data(addr, cmd, len=32) -> results\n\n" "Perform I2C Block Read transaction.\n"); static PyObject * SMBus_read_i2c_block_data(SMBus *self, PyObject *args) { - int addr, cmd; + int addr, cmd, len=32; union i2c_smbus_data data; - if (!PyArg_ParseTuple(args, "ii:read_i2c_block_data", &addr, &cmd)) + if (!PyArg_ParseTuple(args, "ii|i:read_i2c_block_data", &addr, &cmd, + &len)) return NULL; SMBus_SET_ADDR(self, addr); + data.block[0] = len; /* save a bit of code by calling the access function directly */ if (i2c_smbus_access(self->fd, I2C_SMBUS_READ, (__u8)cmd, + len = 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN: I2C_SMBUS_I2C_BLOCK_DATA, &data)) { PyErr_SetFromErrno(PyExc_IOError); return NULL; @@ -529,7 +541,7 @@ SMBus_write_i2c_block_data(SMBus *self, PyObject *args) /* save a bit of code by calling the access function directly */ if (i2c_smbus_access(self->fd, I2C_SMBUS_WRITE, (__u8)cmd, - I2C_SMBUS_I2C_BLOCK_DATA, &data)) { + I2C_SMBUS_I2C_BLOCK_BROKEN, &data)) { PyErr_SetFromErrno(PyExc_IOError); return NULL; }