@@ -47,27 +47,24 @@ static int get_bytes_count_for_hex(char *arg)
4747 * https://manpages.debian.org/buster/i2c-tools/i2cdetect.8.en.html
4848 */
4949/* i2c scan <device> */
50- static int cmd_i2c_scan (const struct shell * shell_ctx ,
51- size_t argc , char * * argv )
50+ static int cmd_i2c_scan (const struct shell * sh , size_t argc , char * * argv )
5251{
5352 const struct device * dev ;
5453 uint8_t cnt = 0 , first = 0x04 , last = 0x77 ;
5554
5655 dev = shell_device_get_binding (argv [ARGV_DEV ]);
5756
5857 if (!dev ) {
59- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
60- argv [ARGV_DEV ]);
58+ shell_error (sh , "I2C: Device driver %s not found." , argv [ARGV_DEV ]);
6159 return - ENODEV ;
6260 }
6361
64- shell_print (shell_ctx ,
65- " 0 1 2 3 4 5 6 7 8 9 a b c d e f" );
62+ shell_print (sh , " 0 1 2 3 4 5 6 7 8 9 a b c d e f" );
6663 for (uint8_t i = 0 ; i <= last ; i += 16 ) {
67- shell_fprintf (shell_ctx , SHELL_NORMAL , "%02x: " , i );
64+ shell_fprintf (sh , SHELL_NORMAL , "%02x: " , i );
6865 for (uint8_t j = 0 ; j < 16 ; j ++ ) {
6966 if (i + j < first || i + j > last ) {
70- shell_fprintf (shell_ctx , SHELL_NORMAL , " " );
67+ shell_fprintf (sh , SHELL_NORMAL , " " );
7168 continue ;
7269 }
7370
@@ -79,47 +76,42 @@ static int cmd_i2c_scan(const struct shell *shell_ctx,
7976 msgs [0 ].len = 0U ;
8077 msgs [0 ].flags = I2C_MSG_WRITE | I2C_MSG_STOP ;
8178 if (i2c_transfer (dev , & msgs [0 ], 1 , i + j ) == 0 ) {
82- shell_fprintf (shell_ctx , SHELL_NORMAL ,
83- "%02x " , i + j );
79+ shell_fprintf (sh , SHELL_NORMAL , "%02x " , i + j );
8480 ++ cnt ;
8581 } else {
86- shell_fprintf (shell_ctx , SHELL_NORMAL , "-- " );
82+ shell_fprintf (sh , SHELL_NORMAL , "-- " );
8783 }
8884 }
89- shell_print (shell_ctx , "" );
85+ shell_print (sh , "" );
9086 }
9187
92- shell_print (shell_ctx , "%u devices found on %s" ,
93- cnt , argv [ARGV_DEV ]);
88+ shell_print (sh , "%u devices found on %s" , cnt , argv [ARGV_DEV ]);
9489
9590 return 0 ;
9691}
9792
9893/* i2c recover <device> */
99- static int cmd_i2c_recover (const struct shell * shell_ctx ,
100- size_t argc , char * * argv )
94+ static int cmd_i2c_recover (const struct shell * sh , size_t argc , char * * argv )
10195{
10296 const struct device * dev ;
10397 int err ;
10498
10599 dev = shell_device_get_binding (argv [ARGV_DEV ]);
106100 if (!dev ) {
107- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
108- argv [1 ]);
101+ shell_error (sh , "I2C: Device driver %s not found." , argv [1 ]);
109102 return - ENODEV ;
110103 }
111104
112105 err = i2c_recover_bus (dev );
113106 if (err ) {
114- shell_error (shell_ctx , "I2C: Bus recovery failed (err %d)" ,
115- err );
107+ shell_error (sh , "I2C: Bus recovery failed (err %d)" , err );
116108 return err ;
117109 }
118110
119111 return 0 ;
120112}
121113
122- static int i2c_write_from_buffer (const struct shell * shell_ctx ,
114+ static int i2c_write_from_buffer (const struct shell * sh ,
123115 char * s_dev_name , char * s_dev_addr , char * s_reg_addr ,
124116 char * * data , uint8_t data_length )
125117{
@@ -137,8 +129,7 @@ static int i2c_write_from_buffer(const struct shell *shell_ctx,
137129
138130 dev = shell_device_get_binding (s_dev_name );
139131 if (!dev ) {
140- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
141- s_dev_name );
132+ shell_error (sh , "I2C: Device driver %s not found." , s_dev_name );
142133 return - ENODEV ;
143134 }
144135
@@ -150,7 +141,7 @@ static int i2c_write_from_buffer(const struct shell *shell_ctx,
150141
151142 if (data_length + reg_addr_bytes > MAX_I2C_BYTES ) {
152143 data_length = MAX_I2C_BYTES - reg_addr_bytes ;
153- shell_info (shell_ctx , "Too many bytes provided, limit is %d" ,
144+ shell_info (sh , "Too many bytes provided, limit is %d" ,
154145 MAX_I2C_BYTES - reg_addr_bytes );
155146 }
156147
@@ -163,33 +154,30 @@ static int i2c_write_from_buffer(const struct shell *shell_ctx,
163154 buf + MAX_BYTES_FOR_REGISTER_INDEX - reg_addr_bytes ,
164155 reg_addr_bytes + data_length , dev_addr );
165156 if (ret < 0 ) {
166- shell_error (shell_ctx , "Failed to write to device: %s" ,
167- s_dev_addr );
157+ shell_error (sh , "Failed to write to device: %s" , s_dev_addr );
168158 return - EIO ;
169159 }
170160
171161 return 0 ;
172162}
173163
174164/* i2c write <device> <dev_addr> <reg_addr> [<byte1>, ...] */
175- static int cmd_i2c_write (const struct shell * shell_ctx ,
176- size_t argc , char * * argv )
165+ static int cmd_i2c_write (const struct shell * sh , size_t argc , char * * argv )
177166{
178- return i2c_write_from_buffer (shell_ctx , argv [ARGV_DEV ],
167+ return i2c_write_from_buffer (sh , argv [ARGV_DEV ],
179168 argv [ARGV_ADDR ], argv [ARGV_REG ],
180169 & argv [4 ], argc - 4 );
181170}
182171
183172/* i2c write_byte <device> <dev_addr> <reg_addr> <value> */
184- static int cmd_i2c_write_byte (const struct shell * shell_ctx ,
185- size_t argc , char * * argv )
173+ static int cmd_i2c_write_byte (const struct shell * sh , size_t argc , char * * argv )
186174{
187- return i2c_write_from_buffer (shell_ctx , argv [ARGV_DEV ],
175+ return i2c_write_from_buffer (sh , argv [ARGV_DEV ],
188176 argv [ARGV_ADDR ], argv [ARGV_REG ],
189177 & argv [4 ], 1 );
190178}
191179
192- static int i2c_read_to_buffer (const struct shell * shell_ctx ,
180+ static int i2c_read_to_buffer (const struct shell * sh ,
193181 char * s_dev_name ,
194182 char * s_dev_addr , char * s_reg_addr ,
195183 uint8_t * buf , uint8_t buf_length )
@@ -200,8 +188,7 @@ static int i2c_read_to_buffer(const struct shell *shell_ctx,
200188
201189 dev = shell_device_get_binding (s_dev_name );
202190 if (!dev ) {
203- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
204- s_dev_name );
191+ shell_error (sh , "I2C: Device driver %s not found." , s_dev_name );
205192 return - ENODEV ;
206193 }
207194
@@ -224,33 +211,30 @@ static int i2c_read_to_buffer(const struct shell *shell_ctx,
224211 }
225212
226213 if (ret < 0 ) {
227- shell_error (shell_ctx , "Failed to read from device: %s" ,
228- s_dev_addr );
214+ shell_error (sh , "Failed to read from device: %s" , s_dev_addr );
229215 return - EIO ;
230216 }
231217
232218 return 0 ;
233219}
234220
235221/* i2c read_byte <device> <dev_addr> <reg_addr> */
236- static int cmd_i2c_read_byte (const struct shell * shell_ctx ,
237- size_t argc , char * * argv )
222+ static int cmd_i2c_read_byte (const struct shell * sh , size_t argc , char * * argv )
238223{
239224 uint8_t out ;
240225 int ret ;
241226
242-
243- ret = i2c_read_to_buffer (shell_ctx , argv [ARGV_DEV ],
227+ ret = i2c_read_to_buffer (sh , argv [ARGV_DEV ],
244228 argv [ARGV_ADDR ], argv [ARGV_REG ], & out , 1 );
245229 if (ret == 0 ) {
246- shell_print (shell_ctx , "Output: 0x%x" , out );
230+ shell_print (sh , "Output: 0x%x" , out );
247231 }
248232
249233 return ret ;
250234}
251235
252236/* i2c read <device> <dev_addr> <reg_addr> [<numbytes>] */
253- static int cmd_i2c_read (const struct shell * shell_ctx , size_t argc , char * * argv )
237+ static int cmd_i2c_read (const struct shell * sh , size_t argc , char * * argv )
254238{
255239 uint8_t buf [MAX_I2C_BYTES ];
256240 int num_bytes ;
@@ -265,18 +249,18 @@ static int cmd_i2c_read(const struct shell *shell_ctx, size_t argc, char **argv)
265249 num_bytes = MAX_I2C_BYTES ;
266250 }
267251
268- ret = i2c_read_to_buffer (shell_ctx , argv [ARGV_DEV ],
252+ ret = i2c_read_to_buffer (sh , argv [ARGV_DEV ],
269253 argv [ARGV_ADDR ], argv [ARGV_REG ],
270254 buf , num_bytes );
271255 if (ret == 0 ) {
272- shell_hexdump (shell_ctx , buf , num_bytes );
256+ shell_hexdump (sh , buf , num_bytes );
273257 }
274258
275259 return ret ;
276260}
277261
278262/* i2c direct_read <device> <dev_addr> [<numbytes>] */
279- static int cmd_i2c_direct_read (const struct shell * shell_ctx , size_t argc , char * * argv )
263+ static int cmd_i2c_direct_read (const struct shell * sh , size_t argc , char * * argv )
280264{
281265 uint8_t buf [MAX_I2C_BYTES ];
282266 int num_bytes ;
@@ -291,9 +275,9 @@ static int cmd_i2c_direct_read(const struct shell *shell_ctx, size_t argc, char
291275 num_bytes = MAX_I2C_BYTES ;
292276 }
293277
294- ret = i2c_read_to_buffer (shell_ctx , argv [ARGV_DEV ], argv [ARGV_ADDR ], NULL , buf , num_bytes );
278+ ret = i2c_read_to_buffer (sh , argv [ARGV_DEV ], argv [ARGV_ADDR ], NULL , buf , num_bytes );
295279 if (ret == 0 ) {
296- shell_hexdump (shell_ctx , buf , num_bytes );
280+ shell_hexdump (sh , buf , num_bytes );
297281 }
298282
299283 return ret ;
@@ -302,7 +286,7 @@ static int cmd_i2c_direct_read(const struct shell *shell_ctx, size_t argc, char
302286/* i2c speed <device> <speed>
303287 * For: speed see constants like I2C_SPEED_STANDARD
304288 */
305- static int cmd_i2c_speed (const struct shell * shell_ctx , size_t argc , char * * argv )
289+ static int cmd_i2c_speed (const struct shell * sh , size_t argc , char * * argv )
306290{
307291 char * s_dev_name = argv [ARGV_DEV ];
308292 const struct device * dev ;
@@ -312,8 +296,7 @@ static int cmd_i2c_speed(const struct shell *shell_ctx, size_t argc, char **argv
312296
313297 dev = shell_device_get_binding (s_dev_name );
314298 if (!dev ) {
315- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
316- s_dev_name );
299+ shell_error (sh , "I2C: Device driver %s not found." , s_dev_name );
317300 return - ENODEV ;
318301 }
319302
@@ -329,8 +312,7 @@ static int cmd_i2c_speed(const struct shell *shell_ctx, size_t argc, char **argv
329312
330313 ret = i2c_configure (dev , dev_config );
331314 if (ret < 0 ) {
332- shell_error (shell_ctx , "I2C: Failed to configure device: %s" ,
333- s_dev_name );
315+ shell_error (sh , "I2C: Failed to configure device: %s" , s_dev_name );
334316 return - EIO ;
335317 }
336318 return 0 ;
0 commit comments