Changeset 4450

Show
Ignore:
Timestamp:
06/16/07 16:01:05 (8 years ago)
Author:
mmh
Message:

ported r4435 from trunk

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/prog/py-smbus/smbusmodule.c

    r4445 r4450  
    11/* 
    22 * smbusmodule.c - Python bindings for Linux SMBus access through i2c-dev 
    3  * Copyright (C) 2005,2006 Mark M. Hoffman <mhoffman@lightlink.com> 
     3 * Copyright (C) 2005-2007 Mark M. Hoffman <mhoffman@lightlink.com> 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    2424#include <linux/i2c-dev.h> 
    2525 
     26/* 
     27** These are required to build this module against Linux older than 2.6.23. 
     28*/ 
     29#ifndef I2C_SMBUS_I2C_BLOCK_BROKEN 
     30#undef I2C_SMBUS_I2C_BLOCK_DATA 
     31#define I2C_SMBUS_I2C_BLOCK_BROKEN      6 
     32#define I2C_SMBUS_I2C_BLOCK_DATA        8 
     33#endif 
     34 
    2635PyDoc_STRVAR(SMBus_module_doc, 
    2736        "This module defines an object type that allows SMBus transactions\n" 
     
    487496 
    488497PyDoc_STRVAR(SMBus_read_i2c_block_data_doc, 
    489         "read_i2c_block_data(addr, cmd) -> results\n\n" 
     498        "read_i2c_block_data(addr, cmd, len=32) -> results\n\n" 
    490499        "Perform I2C Block Read transaction.\n"); 
    491500 
     
    493502SMBus_read_i2c_block_data(SMBus *self, PyObject *args) 
    494503{ 
    495         int addr, cmd; 
     504        int addr, cmd, len=32; 
    496505        union i2c_smbus_data data; 
    497506 
    498         if (!PyArg_ParseTuple(args, "ii:read_i2c_block_data", &addr, &cmd)) 
    499                 return NULL; 
    500  
    501         SMBus_SET_ADDR(self, addr); 
    502  
     507        if (!PyArg_ParseTuple(args, "ii|i:read_i2c_block_data", &addr, &cmd, 
     508                        &len)) 
     509                return NULL; 
     510 
     511        SMBus_SET_ADDR(self, addr); 
     512 
     513        data.block[0] = len; 
    503514        /* save a bit of code by calling the access function directly */ 
    504515        if (i2c_smbus_access(self->fd, I2C_SMBUS_READ, (__u8)cmd, 
     516                                len = 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN: 
    505517                                I2C_SMBUS_I2C_BLOCK_DATA, &data)) { 
    506518                PyErr_SetFromErrno(PyExc_IOError); 
     
    530542        /* save a bit of code by calling the access function directly */ 
    531543        if (i2c_smbus_access(self->fd, I2C_SMBUS_WRITE, (__u8)cmd, 
    532                                 I2C_SMBUS_I2C_BLOCK_DATA, &data)) { 
     544                                I2C_SMBUS_I2C_BLOCK_BROKEN, &data)) { 
    533545                PyErr_SetFromErrno(PyExc_IOError); 
    534546                return NULL;