Browse Source

update device_type_str

Rbb666 2 years ago
parent
commit
f37455cbf3
1 changed files with 23 additions and 10 deletions
  1. 23 10
      components/finsh/cmd.c

+ 23 - 10
components/finsh/cmd.c

@@ -787,7 +787,7 @@ long list_timer(void)
 MSH_CMD_EXPORT(list_timer, list timer in system);
 
 #ifdef RT_USING_DEVICE
-static char *const device_type_str[] =
+static char *const device_type_str[RT_Device_Class_Unknown] =
 {
     "Character Device",
     "Block Device",
@@ -800,6 +800,7 @@ static char *const device_type_str[] =
     "I2C Bus",
     "USB Slave Device",
     "USB Host Bus",
+    "USB OTG Bus",
     "SPI Bus",
     "SPI Device",
     "SDIO Bus",
@@ -811,8 +812,14 @@ static char *const device_type_str[] =
     "Sensor Device",
     "Touch Device",
     "Phy Device",
-    "Bus Device",
-    "Unknown"
+    "Security Device",
+    "WLAN Device",
+    "Pin Device",
+    "ADC Device",
+    "DAC Device",
+    "WDT Device",
+    "PWM Device",    
+    "Bus Device"
 };
 
 long list_device(void)
@@ -821,6 +828,7 @@ long list_device(void)
     list_get_next_t find_arg;
     rt_list_t *obj_list[LIST_FIND_OBJ_NR];
     rt_list_t *next = (rt_list_t*)RT_NULL;
+    const char *device_type;
 
     int maxlen;
     const char *item_title = "device";
@@ -829,7 +837,8 @@ long list_device(void)
 
     maxlen = RT_NAME_MAX;
 
-    rt_kprintf("%-*.s         type         ref count\n", maxlen, item_title); object_split(maxlen);
+    rt_kprintf("%-*.s         type         ref count\n", maxlen, item_title); 
+    object_split(maxlen);
     rt_kprintf(     " -------------------- ----------\n");
     do
     {
@@ -852,13 +861,17 @@ long list_device(void)
                 rt_hw_interrupt_enable(level);
 
                 device = (struct rt_device *)obj;
+                device_type = "Unknown";
+                if (device->type < RT_Device_Class_Unknown &&
+                    device_type_str[device->type] != RT_NULL)
+                {
+                    device_type = device_type_str[device->type];
+                }
                 rt_kprintf("%-*.*s %-20s %-8d\n",
-                        maxlen, RT_NAME_MAX,
-                        device->parent.name,
-                        (device->type <= RT_Device_Class_Unknown) ?
-                        device_type_str[device->type] :
-                        device_type_str[RT_Device_Class_Unknown],
-                        device->ref_count);
+                           maxlen, RT_NAME_MAX,
+                           device->parent.name,
+                           device_type,
+                           device->ref_count);
 
             }
         }