@@ -79,10 +79,10 @@ LOG_MODULE_REGISTER(adc_shell);
79
79
#define CMD_HELP_GAIN "Configure gain.\n"
80
80
#define CMD_HELP_PRINT "Print current configuration"
81
81
82
- #define NODE_LABELS (n ) DT_INST_LABEL (n),
83
- #define ADC_HDL_LIST_ENTRY (label ) \
82
+ #define DEVICES (n ) DEVICE_DT_INST_GET (n),
83
+ #define ADC_HDL_LIST_ENTRY (dev_ ) \
84
84
{ \
85
- .device_label = label, \
85
+ .dev = dev_, \
86
86
.channel_config = { \
87
87
.gain = ADC_GAIN_1, \
88
88
.reference = ADC_REF_INTERNAL, \
@@ -92,15 +92,15 @@ LOG_MODULE_REGISTER(adc_shell);
92
92
.resolution = 0, \
93
93
}
94
94
95
- #define INIT_MACRO () DT_INST_FOREACH_STATUS_OKAY(NODE_LABELS) "NA"
95
+ #define INIT_MACRO () DT_INST_FOREACH_STATUS_OKAY(DEVICES) NULL
96
96
97
97
#define CHOSEN_STR_LEN 20
98
98
static char chosen_reference [CHOSEN_STR_LEN + 1 ] = "INTERNAL" ;
99
99
static char chosen_gain [CHOSEN_STR_LEN + 1 ] = "1" ;
100
100
101
101
/* This table size is = ADC devices count + 1 (NA). */
102
102
static struct adc_hdl {
103
- char * device_label ;
103
+ const struct device * dev ;
104
104
struct adc_channel_cfg channel_config ;
105
105
uint8_t resolution ;
106
106
} adc_list [] = {
@@ -110,7 +110,7 @@ static struct adc_hdl {
110
110
static struct adc_hdl * get_adc (const char * device_label )
111
111
{
112
112
for (int i = 0 ; i < ARRAY_SIZE (adc_list ); i ++ ) {
113
- if (!strcmp (device_label , adc_list [i ].device_label )) {
113
+ if (!strcmp (device_label , adc_list [i ].dev -> name )) {
114
114
return & adc_list [i ];
115
115
}
116
116
}
@@ -124,12 +124,10 @@ static int cmd_adc_ch_id(const struct shell *shell, size_t argc, char **argv)
124
124
{
125
125
/* -2: index of ADC label name */
126
126
struct adc_hdl * adc = get_adc (argv [-2 ]);
127
- const struct device * adc_dev ;
128
127
int retval = 0 ;
129
128
130
- adc_dev = device_get_binding (adc -> device_label );
131
- if (adc_dev == NULL ) {
132
- shell_error (shell , "ADC device not found" );
129
+ if (!device_is_ready (adc -> dev )) {
130
+ shell_error (shell , "ADC device not ready" );
133
131
return - ENODEV ;
134
132
}
135
133
@@ -139,7 +137,7 @@ static int cmd_adc_ch_id(const struct shell *shell, size_t argc, char **argv)
139
137
}
140
138
141
139
adc -> channel_config .channel_id = (uint8_t )strtol (argv [1 ], NULL , 10 );
142
- retval = adc_channel_setup (adc_dev , & adc -> channel_config );
140
+ retval = adc_channel_setup (adc -> dev , & adc -> channel_config );
143
141
LOG_DBG ("Channel setup returned %i\n" , retval );
144
142
145
143
return retval ;
@@ -150,12 +148,10 @@ static int cmd_adc_ch_neg(const struct shell *shell, size_t argc, char **argv)
150
148
#if CONFIG_ADC_CONFIGURABLE_INPUTS
151
149
/* -2: index of ADC label name */
152
150
struct adc_hdl * adc = get_adc (argv [-2 ]);
153
- const struct device * adc_dev ;
154
151
int retval = 0 ;
155
152
156
- adc_dev = device_get_binding (adc -> device_label );
157
- if (adc_dev == NULL ) {
158
- shell_error (shell , "ADC device not found" );
153
+ if (!device_is_ready (adc -> dev )) {
154
+ shell_error (shell , "ADC device not ready" );
159
155
return - ENODEV ;
160
156
}
161
157
@@ -165,7 +161,7 @@ static int cmd_adc_ch_neg(const struct shell *shell, size_t argc, char **argv)
165
161
}
166
162
167
163
adc -> channel_config .input_negative = (uint8_t )strtol (argv [1 ], NULL , 10 );
168
- retval = adc_channel_setup (adc_dev , & adc -> channel_config );
164
+ retval = adc_channel_setup (adc -> dev , & adc -> channel_config );
169
165
LOG_DBG ("Channel setup returned %i\n" , retval );
170
166
171
167
return retval ;
@@ -179,12 +175,10 @@ static int cmd_adc_ch_pos(const struct shell *shell, size_t argc, char **argv)
179
175
#if CONFIG_ADC_CONFIGURABLE_INPUTS
180
176
/* -2: index of ADC label name */
181
177
struct adc_hdl * adc = get_adc (argv [-2 ]);
182
- const struct device * adc_dev ;
183
178
int retval = 0 ;
184
179
185
- adc_dev = device_get_binding (adc -> device_label );
186
- if (adc_dev == NULL ) {
187
- shell_error (shell , "ADC device not found" );
180
+ if (!device_is_ready (adc -> dev )) {
181
+ shell_error (shell , "ADC device not ready" );
188
182
return - ENODEV ;
189
183
}
190
184
@@ -194,7 +188,7 @@ static int cmd_adc_ch_pos(const struct shell *shell, size_t argc, char **argv)
194
188
}
195
189
196
190
adc -> channel_config .input_positive = (uint8_t )strtol (argv [1 ], NULL , 10 );
197
- retval = adc_channel_setup (adc_dev , & adc -> channel_config );
191
+ retval = adc_channel_setup (adc -> dev , & adc -> channel_config );
198
192
LOG_DBG ("Channel setup returned %i\n" , retval );
199
193
200
194
return retval ;
@@ -209,12 +203,10 @@ static int cmd_adc_gain(const struct shell *shell, size_t argc, char **argv,
209
203
/* -2: index of ADC label name */
210
204
struct adc_hdl * adc = get_adc (argv [-2 ]);
211
205
enum adc_gain gain = (enum adc_gain )data ;
212
- const struct device * adc_dev ;
213
206
int retval = - EINVAL ;
214
207
215
- adc_dev = device_get_binding (adc -> device_label );
216
- if (adc_dev == NULL ) {
217
- shell_error (shell , "ADC device not found" );
208
+ if (!device_is_ready (adc -> dev )) {
209
+ shell_error (shell , "ADC device not ready" );
218
210
return - ENODEV ;
219
211
}
220
212
@@ -223,7 +215,7 @@ static int cmd_adc_gain(const struct shell *shell, size_t argc, char **argv,
223
215
: strlen (argv [0 ]);
224
216
memcpy (chosen_gain , argv [0 ], len );
225
217
chosen_gain [len ] = '\0' ;
226
- retval = adc_channel_setup (adc_dev , & adc -> channel_config );
218
+ retval = adc_channel_setup (adc -> dev , & adc -> channel_config );
227
219
LOG_DBG ("Channel setup returned %i\n" , retval );
228
220
229
221
return retval ;
@@ -233,13 +225,11 @@ static int cmd_adc_acq(const struct shell *shell, size_t argc, char **argv)
233
225
{
234
226
/* -1 index of ADC label name */
235
227
struct adc_hdl * adc = get_adc (argv [-1 ]);
236
- const struct device * adc_dev ;
237
228
uint16_t acq_time ;
238
229
int retval ;
239
230
240
- adc_dev = device_get_binding (adc -> device_label );
241
- if (adc_dev == NULL ) {
242
- shell_error (shell , "ADC device not found" );
231
+ if (!device_is_ready (adc -> dev )) {
232
+ shell_error (shell , "ADC device not ready" );
243
233
return - ENODEV ;
244
234
}
245
235
@@ -262,7 +252,7 @@ static int cmd_adc_acq(const struct shell *shell, size_t argc, char **argv)
262
252
adc -> channel_config .acquisition_time =
263
253
ADC_ACQ_TIME_DEFAULT ;
264
254
}
265
- retval = adc_channel_setup (adc_dev , & adc -> channel_config );
255
+ retval = adc_channel_setup (adc -> dev , & adc -> channel_config );
266
256
LOG_DBG ("Channel setup returned %i\n" , retval );
267
257
268
258
return retval ;
@@ -271,12 +261,10 @@ static int cmd_adc_reso(const struct shell *shell, size_t argc, char **argv)
271
261
{
272
262
/* -1 index of ADC label name */
273
263
struct adc_hdl * adc = get_adc (argv [-1 ]);
274
- const struct device * adc_dev ;
275
264
int retval ;
276
265
277
- adc_dev = device_get_binding (adc -> device_label );
278
- if (adc_dev == NULL ) {
279
- shell_error (shell , "ADC device not found" );
266
+ if (!device_is_ready (adc -> dev )) {
267
+ shell_error (shell , "ADC device not ready" );
280
268
return - ENODEV ;
281
269
}
282
270
@@ -286,7 +274,7 @@ static int cmd_adc_reso(const struct shell *shell, size_t argc, char **argv)
286
274
}
287
275
288
276
adc -> resolution = (uint8_t )strtol (argv [1 ], NULL , 10 );
289
- retval = adc_channel_setup (adc_dev , & adc -> channel_config );
277
+ retval = adc_channel_setup (adc -> dev , & adc -> channel_config );
290
278
291
279
return retval ;
292
280
}
@@ -297,12 +285,10 @@ static int cmd_adc_ref(const struct shell *shell, size_t argc, char **argv,
297
285
/* -2 index of ADC label name */
298
286
struct adc_hdl * adc = get_adc (argv [-2 ]);
299
287
enum adc_reference reference = (enum adc_reference )data ;
300
- const struct device * adc_dev ;
301
288
int retval = - EINVAL ;
302
289
303
- adc_dev = device_get_binding (adc -> device_label );
304
- if (adc_dev == NULL ) {
305
- shell_error (shell , "ADC device not found" );
290
+ if (!device_is_ready (adc -> dev )) {
291
+ shell_error (shell , "ADC device not ready" );
306
292
return - ENODEV ;
307
293
}
308
294
@@ -312,7 +298,7 @@ static int cmd_adc_ref(const struct shell *shell, size_t argc, char **argv,
312
298
chosen_reference [len ] = '\0' ;
313
299
314
300
adc -> channel_config .reference = reference ;
315
- retval = adc_channel_setup (adc_dev , & adc -> channel_config );
301
+ retval = adc_channel_setup (adc -> dev , & adc -> channel_config );
316
302
LOG_DBG ("Channel setup returned %i\n" , retval );
317
303
318
304
return retval ;
@@ -325,12 +311,10 @@ static int cmd_adc_read(const struct shell *shell, size_t argc, char **argv)
325
311
/* -1 index of adc label name */
326
312
struct adc_hdl * adc = get_adc (argv [-1 ]);
327
313
uint16_t m_sample_buffer [BUFFER_SIZE ];
328
- const struct device * adc_dev ;
329
314
int retval ;
330
315
331
- adc_dev = device_get_binding (adc -> device_label );
332
- if (adc_dev == NULL ) {
333
- shell_error (shell , "adc device not found" );
316
+ if (!device_is_ready (adc -> dev )) {
317
+ shell_error (shell , "ADC device not ready" );
334
318
return - ENODEV ;
335
319
}
336
320
@@ -342,7 +326,7 @@ static int cmd_adc_read(const struct shell *shell, size_t argc, char **argv)
342
326
.resolution = adc -> resolution ,
343
327
};
344
328
345
- retval = adc_read (adc_dev , & sequence );
329
+ retval = adc_read (adc -> dev , & sequence );
346
330
if (retval >= 0 ) {
347
331
shell_print (shell , "read: %i" , m_sample_buffer [0 ]);
348
332
}
@@ -361,7 +345,7 @@ static int cmd_adc_print(const struct shell *shell, size_t argc, char **argv)
361
345
"Acquisition Time: %u\n"
362
346
"Channel ID: %u\n"
363
347
"Resolution: %u" ,
364
- adc -> device_label ,
348
+ adc -> dev -> name ,
365
349
chosen_gain ,
366
350
chosen_reference ,
367
351
adc -> channel_config .acquisition_time ,
@@ -422,7 +406,7 @@ static void cmd_adc_dev_get(size_t idx, struct shell_static_entry *entry)
422
406
{
423
407
/* -1 because the last element in the list is a "list terminator" */
424
408
if (idx < ARRAY_SIZE (adc_list ) - 1 ) {
425
- entry -> syntax = adc_list [idx ].device_label ;
409
+ entry -> syntax = adc_list [idx ].dev -> name ;
426
410
entry -> handler = NULL ;
427
411
entry -> subcmd = & sub_adc_cmds ;
428
412
entry -> help = "Select subcommand for ADC property label.\n" ;
0 commit comments