@@ -48,27 +48,24 @@ static int get_bytes_count_for_hex(char *arg)
4848 * https://manpages.debian.org/buster/i2c-tools/i2cdetect.8.en.html
4949 */
5050/* i2c scan <device> */
51- static int cmd_i2c_scan (const struct shell * shell_ctx ,
52- size_t argc , char * * argv )
51+ static int cmd_i2c_scan (const struct shell * sh , size_t argc , char * * argv )
5352{
5453 const struct device * dev ;
5554 uint8_t cnt = 0 , first = 0x04 , last = 0x77 ;
5655
5756 dev = shell_device_get_binding (argv [ARGV_DEV ]);
5857
5958 if (!dev ) {
60- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
61- argv [ARGV_DEV ]);
59+ shell_error (sh , "I2C: Device driver %s not found." , argv [ARGV_DEV ]);
6260 return - ENODEV ;
6361 }
6462
65- shell_print (shell_ctx ,
66- " 0 1 2 3 4 5 6 7 8 9 a b c d e f" );
63+ shell_print (sh , " 0 1 2 3 4 5 6 7 8 9 a b c d e f" );
6764 for (uint8_t i = 0 ; i <= last ; i += 16 ) {
68- shell_fprintf (shell_ctx , SHELL_NORMAL , "%02x: " , i );
65+ shell_fprintf (sh , SHELL_NORMAL , "%02x: " , i );
6966 for (uint8_t j = 0 ; j < 16 ; j ++ ) {
7067 if (i + j < first || i + j > last ) {
71- shell_fprintf (shell_ctx , SHELL_NORMAL , " " );
68+ shell_fprintf (sh , SHELL_NORMAL , " " );
7269 continue ;
7370 }
7471
@@ -80,47 +77,42 @@ static int cmd_i2c_scan(const struct shell *shell_ctx,
8077 msgs [0 ].len = 0U ;
8178 msgs [0 ].flags = I2C_MSG_WRITE | I2C_MSG_STOP ;
8279 if (i2c_transfer (dev , & msgs [0 ], 1 , i + j ) == 0 ) {
83- shell_fprintf (shell_ctx , SHELL_NORMAL ,
84- "%02x " , i + j );
80+ shell_fprintf (sh , SHELL_NORMAL , "%02x " , i + j );
8581 ++ cnt ;
8682 } else {
87- shell_fprintf (shell_ctx , SHELL_NORMAL , "-- " );
83+ shell_fprintf (sh , SHELL_NORMAL , "-- " );
8884 }
8985 }
90- shell_print (shell_ctx , "" );
86+ shell_print (sh , "" );
9187 }
9288
93- shell_print (shell_ctx , "%u devices found on %s" ,
94- cnt , argv [ARGV_DEV ]);
89+ shell_print (sh , "%u devices found on %s" , cnt , argv [ARGV_DEV ]);
9590
9691 return 0 ;
9792}
9893
9994/* i2c recover <device> */
100- static int cmd_i2c_recover (const struct shell * shell_ctx ,
101- size_t argc , char * * argv )
95+ static int cmd_i2c_recover (const struct shell * sh , size_t argc , char * * argv )
10296{
10397 const struct device * dev ;
10498 int err ;
10599
106100 dev = shell_device_get_binding (argv [ARGV_DEV ]);
107101 if (!dev ) {
108- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
109- argv [1 ]);
102+ shell_error (sh , "I2C: Device driver %s not found." , argv [1 ]);
110103 return - ENODEV ;
111104 }
112105
113106 err = i2c_recover_bus (dev );
114107 if (err ) {
115- shell_error (shell_ctx , "I2C: Bus recovery failed (err %d)" ,
116- err );
108+ shell_error (sh , "I2C: Bus recovery failed (err %d)" , err );
117109 return err ;
118110 }
119111
120112 return 0 ;
121113}
122114
123- static int i2c_write_from_buffer (const struct shell * shell_ctx ,
115+ static int i2c_write_from_buffer (const struct shell * sh ,
124116 char * s_dev_name , char * s_dev_addr , char * s_reg_addr ,
125117 char * * data , uint8_t data_length )
126118{
@@ -138,8 +130,7 @@ static int i2c_write_from_buffer(const struct shell *shell_ctx,
138130
139131 dev = shell_device_get_binding (s_dev_name );
140132 if (!dev ) {
141- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
142- s_dev_name );
133+ shell_error (sh , "I2C: Device driver %s not found." , s_dev_name );
143134 return - ENODEV ;
144135 }
145136
@@ -151,7 +142,7 @@ static int i2c_write_from_buffer(const struct shell *shell_ctx,
151142
152143 if (data_length + reg_addr_bytes > MAX_I2C_BYTES ) {
153144 data_length = MAX_I2C_BYTES - reg_addr_bytes ;
154- shell_info (shell_ctx , "Too many bytes provided, limit is %d" ,
145+ shell_info (sh , "Too many bytes provided, limit is %d" ,
155146 MAX_I2C_BYTES - reg_addr_bytes );
156147 }
157148
@@ -164,33 +155,30 @@ static int i2c_write_from_buffer(const struct shell *shell_ctx,
164155 buf + MAX_BYTES_FOR_REGISTER_INDEX - reg_addr_bytes ,
165156 reg_addr_bytes + data_length , dev_addr );
166157 if (ret < 0 ) {
167- shell_error (shell_ctx , "Failed to write to device: %s" ,
168- s_dev_addr );
158+ shell_error (sh , "Failed to write to device: %s" , s_dev_addr );
169159 return - EIO ;
170160 }
171161
172162 return 0 ;
173163}
174164
175165/* i2c write <device> <dev_addr> <reg_addr> [<byte1>, ...] */
176- static int cmd_i2c_write (const struct shell * shell_ctx ,
177- size_t argc , char * * argv )
166+ static int cmd_i2c_write (const struct shell * sh , size_t argc , char * * argv )
178167{
179- return i2c_write_from_buffer (shell_ctx , argv [ARGV_DEV ],
168+ return i2c_write_from_buffer (sh , argv [ARGV_DEV ],
180169 argv [ARGV_ADDR ], argv [ARGV_REG ],
181170 & argv [4 ], argc - 4 );
182171}
183172
184173/* i2c write_byte <device> <dev_addr> <reg_addr> <value> */
185- static int cmd_i2c_write_byte (const struct shell * shell_ctx ,
186- size_t argc , char * * argv )
174+ static int cmd_i2c_write_byte (const struct shell * sh , size_t argc , char * * argv )
187175{
188- return i2c_write_from_buffer (shell_ctx , argv [ARGV_DEV ],
176+ return i2c_write_from_buffer (sh , argv [ARGV_DEV ],
189177 argv [ARGV_ADDR ], argv [ARGV_REG ],
190178 & argv [4 ], 1 );
191179}
192180
193- static int i2c_read_to_buffer (const struct shell * shell_ctx ,
181+ static int i2c_read_to_buffer (const struct shell * sh ,
194182 char * s_dev_name ,
195183 char * s_dev_addr , char * s_reg_addr ,
196184 uint8_t * buf , uint8_t buf_length )
@@ -201,8 +189,7 @@ static int i2c_read_to_buffer(const struct shell *shell_ctx,
201189
202190 dev = shell_device_get_binding (s_dev_name );
203191 if (!dev ) {
204- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
205- s_dev_name );
192+ shell_error (sh , "I2C: Device driver %s not found." , s_dev_name );
206193 return - ENODEV ;
207194 }
208195
@@ -225,33 +212,30 @@ static int i2c_read_to_buffer(const struct shell *shell_ctx,
225212 }
226213
227214 if (ret < 0 ) {
228- shell_error (shell_ctx , "Failed to read from device: %s" ,
229- s_dev_addr );
215+ shell_error (sh , "Failed to read from device: %s" , s_dev_addr );
230216 return - EIO ;
231217 }
232218
233219 return 0 ;
234220}
235221
236222/* i2c read_byte <device> <dev_addr> <reg_addr> */
237- static int cmd_i2c_read_byte (const struct shell * shell_ctx ,
238- size_t argc , char * * argv )
223+ static int cmd_i2c_read_byte (const struct shell * sh , size_t argc , char * * argv )
239224{
240225 uint8_t out ;
241226 int ret ;
242227
243-
244- ret = i2c_read_to_buffer (shell_ctx , argv [ARGV_DEV ],
228+ ret = i2c_read_to_buffer (sh , argv [ARGV_DEV ],
245229 argv [ARGV_ADDR ], argv [ARGV_REG ], & out , 1 );
246230 if (ret == 0 ) {
247- shell_print (shell_ctx , "Output: 0x%x" , out );
231+ shell_print (sh , "Output: 0x%x" , out );
248232 }
249233
250234 return ret ;
251235}
252236
253237/* i2c read <device> <dev_addr> <reg_addr> [<numbytes>] */
254- static int cmd_i2c_read (const struct shell * shell_ctx , size_t argc , char * * argv )
238+ static int cmd_i2c_read (const struct shell * sh , size_t argc , char * * argv )
255239{
256240 uint8_t buf [MAX_I2C_BYTES ];
257241 int num_bytes ;
@@ -266,18 +250,18 @@ static int cmd_i2c_read(const struct shell *shell_ctx, size_t argc, char **argv)
266250 num_bytes = MAX_I2C_BYTES ;
267251 }
268252
269- ret = i2c_read_to_buffer (shell_ctx , argv [ARGV_DEV ],
253+ ret = i2c_read_to_buffer (sh , argv [ARGV_DEV ],
270254 argv [ARGV_ADDR ], argv [ARGV_REG ],
271255 buf , num_bytes );
272256 if (ret == 0 ) {
273- shell_hexdump (shell_ctx , buf , num_bytes );
257+ shell_hexdump (sh , buf , num_bytes );
274258 }
275259
276260 return ret ;
277261}
278262
279263/* i2c direct_read <device> <dev_addr> [<numbytes>] */
280- static int cmd_i2c_direct_read (const struct shell * shell_ctx , size_t argc , char * * argv )
264+ static int cmd_i2c_direct_read (const struct shell * sh , size_t argc , char * * argv )
281265{
282266 uint8_t buf [MAX_I2C_BYTES ];
283267 int num_bytes ;
@@ -292,9 +276,9 @@ static int cmd_i2c_direct_read(const struct shell *shell_ctx, size_t argc, char
292276 num_bytes = MAX_I2C_BYTES ;
293277 }
294278
295- ret = i2c_read_to_buffer (shell_ctx , argv [ARGV_DEV ], argv [ARGV_ADDR ], NULL , buf , num_bytes );
279+ ret = i2c_read_to_buffer (sh , argv [ARGV_DEV ], argv [ARGV_ADDR ], NULL , buf , num_bytes );
296280 if (ret == 0 ) {
297- shell_hexdump (shell_ctx , buf , num_bytes );
281+ shell_hexdump (sh , buf , num_bytes );
298282 }
299283
300284 return ret ;
@@ -303,7 +287,7 @@ static int cmd_i2c_direct_read(const struct shell *shell_ctx, size_t argc, char
303287/* i2c speed <device> <speed>
304288 * For: speed see constants like I2C_SPEED_STANDARD
305289 */
306- static int cmd_i2c_speed (const struct shell * shell_ctx , size_t argc , char * * argv )
290+ static int cmd_i2c_speed (const struct shell * sh , size_t argc , char * * argv )
307291{
308292 char * s_dev_name = argv [ARGV_DEV ];
309293 const struct device * dev ;
@@ -313,8 +297,7 @@ static int cmd_i2c_speed(const struct shell *shell_ctx, size_t argc, char **argv
313297
314298 dev = shell_device_get_binding (s_dev_name );
315299 if (!dev ) {
316- shell_error (shell_ctx , "I2C: Device driver %s not found." ,
317- s_dev_name );
300+ shell_error (sh , "I2C: Device driver %s not found." , s_dev_name );
318301 return - ENODEV ;
319302 }
320303
@@ -330,8 +313,7 @@ static int cmd_i2c_speed(const struct shell *shell_ctx, size_t argc, char **argv
330313
331314 ret = i2c_configure (dev , dev_config );
332315 if (ret < 0 ) {
333- shell_error (shell_ctx , "I2C: Failed to configure device: %s" ,
334- s_dev_name );
316+ shell_error (sh , "I2C: Failed to configure device: %s" , s_dev_name );
335317 return - EIO ;
336318 }
337319 return 0 ;
0 commit comments