mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-31 06:15:15 +00:00
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
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* smbusmodule.c - Python bindings for Linux SMBus access through i2c-dev
|
||||
* Copyright (C) 2005,2006 Mark M. Hoffman <mhoffman@lightlink.com>
|
||||
* Copyright (C) 2005-2007 Mark M. Hoffman <mhoffman@lightlink.com>
|
||||
*
|
||||
* 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 <fcntl.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
/*
|
||||
** 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user