@@ -56,9 +56,10 @@ def i2c_smbus_access(file, read_write, command, size, data):
56
56
print '## i2c_smbus_access ## {0}' .format (e )
57
57
return - 1
58
58
59
- def i2c_smbus_write_quick (file , value ):
59
+ def i2c_smbus_write_quick (file , mode ):
60
+ if debug : print '## i2c_smbus_write_byte ##: mode 0x{0:00X}' .format (mode )
60
61
data = i2c_smbus_data (0 )
61
- return i2c_smbus_access (file , value , 0 , I2C_SMBUS_QUICK , pointer (data ))
62
+ return i2c_smbus_access (file , mode , 0 , I2C_SMBUS_QUICK , pointer (data ))
62
63
63
64
def i2c_smbus_read_byte (file ):
64
65
if debug : print '## i2c_smbus_read_byte ##'
@@ -68,35 +69,35 @@ def i2c_smbus_read_byte(file):
68
69
else :
69
70
return - 1
70
71
71
- def i2c_smbus_write_byte (file , value ):
72
- if debug : print '## i2c_smbus_write_byte ##: value 0x{0:00X}' .format (value )
72
+ def i2c_smbus_write_byte (file , daddr ):
73
+ if debug : print '## i2c_smbus_write_byte ##: daddr 0x{0:00X}' .format (daddr )
73
74
data = i2c_smbus_data (0 )
74
- return i2c_smbus_access (file , I2C_SMBUS_WRITE , value , I2C_SMBUS_BYTE , pointer (data ))
75
+ return i2c_smbus_access (file , I2C_SMBUS_WRITE , daddr , I2C_SMBUS_BYTE , pointer (data ))
75
76
76
77
def i2c_smbus_read_byte_data (file , daddr ):
77
- if debug : print '## i2c_smbus_read_byte_data ##: daddr {0 }' .format (daddr )
78
+ if debug : print '## i2c_smbus_read_byte_data ##: daddr 0x{0:00X }' .format (daddr )
78
79
data = i2c_smbus_data (0 )
79
80
if (i2c_smbus_access (file , I2C_SMBUS_READ , daddr , I2C_SMBUS_BYTE_DATA , pointer (data )) == 0 ):
80
81
return 0x0FF & data .byte
81
82
else :
82
83
return - 1
83
84
84
85
def i2c_smbus_write_byte_data (file , daddr , value ):
85
- if debug : print '## i2c_smbus_write_byte_data ##: daddr {0 }, value=0x{1:00X}' .format (daddr , value )
86
+ if debug : print '## i2c_smbus_write_byte_data ##: daddr 0x{0:00X }, value=0x{1:00X}' .format (daddr , value )
86
87
data = i2c_smbus_data (0 )
87
88
data .byte = value
88
89
return i2c_smbus_access (file , I2C_SMBUS_WRITE , daddr , I2C_SMBUS_BYTE_DATA , pointer (data ))
89
90
90
91
def i2c_smbus_read_word_data (file , daddr ):
91
- if debug : print '## i2c_smbus_read_word_data ##: daddr {0 }' .format (daddr )
92
+ if debug : print '## i2c_smbus_read_word_data ##: daddr 0x{0:00X }' .format (daddr )
92
93
data = i2c_smbus_data (0 )
93
94
if (i2c_smbus_access (file , I2C_SMBUS_READ , daddr , I2C_SMBUS_WORD_DATA , pointer (data )) == 0 ):
94
95
return 0x0FFFF & data .word
95
96
else :
96
97
return - 1
97
98
98
99
def i2c_smbus_write_word_data (file , daddr , value ):
99
- if debug : print '## i2c_smbus_write_word_data ##: daddr {0 }, value=0x{1:0000X}' .format (daddr , value )
100
+ if debug : print '## i2c_smbus_write_word_data ##: daddr 0x{0:00X }, value=0x{1:0000X}' .format (daddr , value )
100
101
data = i2c_smbus_data (0 )
101
102
data .word = value
102
103
return i2c_smbus_access (file , I2C_SMBUS_WRITE , daddr , I2C_SMBUS_WORD_DATA , pointer (data ))
@@ -123,7 +124,8 @@ def _i2cRead(addr, reg = 0, size = ''):
123
124
data = - 2
124
125
return data
125
126
126
- def _i2cWrite (addr , reg , value , size ):
127
+ def _i2cWrite (addr , reg , value = '' , size = 'B' ):
128
+ if value == '' : size = 'C' ; value = 0
127
129
if debug : print '## i2cWrite ## addr=0x{0:02x}, reg=0x{1:02x}, value=0x{2:04X}, size={3}' .format (addr , reg , value , size )
128
130
try :
129
131
file = os .open (RASCAL_I2C , os .O_RDWR )
@@ -134,7 +136,7 @@ def _i2cWrite(addr, reg, value, size):
134
136
elif size .upper () == 'B' :
135
137
data = i2c_smbus_write_byte_data (file , reg , value )
136
138
else :
137
- data = i2c_smbus_write_byte (file , value )
139
+ data = i2c_smbus_write_byte (file , reg )
138
140
except Exception , e :
139
141
if debug : print '## i2cWrite ## Can\' t set slave addr {0}' .format (e )
140
142
data = - 1
0 commit comments