@@ -31,21 +31,22 @@ struct sbs_gauge_emul_cfg {
31
31
uint16_t addr ;
32
32
};
33
33
34
- static void reg_write (const struct emul * target , int reg , int val )
34
+ static int reg_write (const struct emul * target , int reg , int val )
35
35
{
36
36
ARG_UNUSED (target );
37
37
38
38
LOG_INF ("write %x = %x" , reg , val );
39
39
switch (reg ) {
40
40
default :
41
41
LOG_INF ("Unknown write %x" , reg );
42
+ return - EIO ;
42
43
}
44
+
45
+ return 0 ;
43
46
}
44
47
45
- static int reg_read (const struct emul * target , int reg )
48
+ static int reg_read (const struct emul * target , int reg , int * val )
46
49
{
47
- int val ;
48
-
49
50
ARG_UNUSED (target );
50
51
51
52
switch (reg ) {
@@ -61,15 +62,15 @@ static int reg_read(const struct emul *target, int reg)
61
62
case SBS_GAUGE_CMD_CYCLE_COUNT :
62
63
case SBS_GAUGE_CMD_DESIGN_VOLTAGE :
63
64
/* Arbitrary stub value. */
64
- val = 1 ;
65
+ * val = 1 ;
65
66
break ;
66
67
default :
67
68
LOG_ERR ("Unknown register 0x%x read" , reg );
68
69
return - EIO ;
69
70
}
70
- LOG_INF ("read 0x%x = 0x%x" , reg , val );
71
+ LOG_INF ("read 0x%x = 0x%x" , reg , * val );
71
72
72
- return val ;
73
+ return 0 ;
73
74
}
74
75
75
76
static int sbs_gauge_emul_transfer_i2c (const struct emul * target , struct i2c_msg * msgs ,
@@ -79,6 +80,7 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg
79
80
struct sbs_gauge_emul_data * data ;
80
81
unsigned int val ;
81
82
int reg ;
83
+ int rc ;
82
84
83
85
data = target -> data ;
84
86
@@ -102,7 +104,7 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg
102
104
if (msgs -> flags & I2C_MSG_READ ) {
103
105
switch (msgs -> len - 1 ) {
104
106
case 1 :
105
- val = reg_read (target , reg );
107
+ rc = reg_read (target , reg , & val );
106
108
msgs -> buf [0 ] = val ;
107
109
break ;
108
110
default :
@@ -113,15 +115,15 @@ static int sbs_gauge_emul_transfer_i2c(const struct emul *target, struct i2c_msg
113
115
if (msgs -> len != 1 ) {
114
116
LOG_ERR ("Unexpected msg1 length %d" , msgs -> len );
115
117
}
116
- reg_write (target , reg , msgs -> buf [0 ]);
118
+ rc = reg_write (target , reg , msgs -> buf [0 ]);
117
119
}
118
120
break ;
119
121
default :
120
122
LOG_ERR ("Invalid number of messages: %d" , num_msgs );
121
123
return - EIO ;
122
124
}
123
125
124
- return 0 ;
126
+ return rc ;
125
127
}
126
128
127
129
static const struct i2c_emul_api sbs_gauge_emul_api_i2c = {
0 commit comments